diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 232e19a7..a0fed19f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,17 +1,79 @@ lib_xua Change Log ================== +1.2.0 +----- + + * ADDED: Updates for xcore.ai/XS3 compatibility + * ADDED: Makefile.Win32 for xmosdfu on Windows + * FIXED: Bump default BCD device number to v1.2.0 + * FIXED: xmosdfu now fails with an error when given a directory (#119) + * FIXED: Compilation errors related to HID code + * FIXED: Runtime error when using mic array interface + * CHANGED: Use XMOS Public Licence Version 1 + * FIXED: Automate HID Report Descriptor length in AC1 HID Descriptor + +1.1.1 +----- + + * RESOLVED: Zero length input packets generated before enumeration causing I2S + timing pushout at startup + * CHANGED: Pin Python package versions + * REMOVED: not necessary cpanfile + +1.1.0 +----- + + * ADDED: Ability to read or modify serial number string + +1.0.1 +----- + + * FIXED: Wrong size of vendor and product strings + +1.0.0 +----- + + * ADDED: UAC1 HID support with simulated Voice Command detection reported + every 10 seconds + * ADDED: Support for USB HID Set Idle request + * ADDED: Pre-processor symbols to enable single-threaded, dual-PDM + microphone operation + * FIXED: Descriptors for XUA_ADAPTIVE incorrectly defined for IN endpoint + * ADDED: Guards to user_hid.h and xua_hid.h + * ADDED: UAC1 HID support for AC Stop (End Call), Volume Increment and + Volume Decrement + * CHANGE: UAC1 HID to report function keys f21 through f24 as specified by + customer + * CHANGE: HID interface for user to set and clear events from global + variable to function + * CHANGE HID report descriptor to use generic events instead of GPI + events, to report Key-phrase detection as AC Search, and to report end-call + detection as AC Stop + * ADDED: Ability to read or modify vendor and product IDs and strings + * ADDED: Ability to read or modify bcdDevice + * ADDED: Override USB descriptor with sampling frequency and + bit-resolution set at boot time. + * ADDED: Global pointer to allow external access to masterClockFreq + +0.2.1 +----- + + * HOTFIX: Fix descriptors for XUA_ADAPTIVE + 0.2.0 ----- * ADDED: Initial library documentation * ADDED: Application note AN00247: Using lib_xua with lib_spdif (transmit) + * ADDED: Separate callbacks for input/output audio stream start/stop * CHANGE: I2S hardware resources no longer used globally and must be passed to XUA_AudioHub() * CHANGE: XUA_AudioHub() no longer pars S/PDIF transmitter task * CHANGE: Moved to lib_spdif (from module_spdif_tx & module_spdif_rx) * CHANGE: Define NUM_PDM_MICS renamed to XUA_NUM_PDM_MICS * CHANGE: Define NO_USB renamed to XUA_USB_EN + * CHANGE: Build files updated to support new "xcommon" behaviour in xwaf. * RESOLVED: wChannelConfig in UAC1 descriptor set according to output channel count * RESOLVED: Indexing of ADAT channel strings (#18059) @@ -19,6 +81,10 @@ lib_xua Change Log * Changes to dependencies: + - lib_dsp: Added dependency 5.0.0 + + - lib_mic_array: Added dependency 4.0.0 + - lib_spdif: Added dependency 3.1.0 - lib_xassert: Added dependency 3.0.1 diff --git a/Jenkinsfile b/Jenkinsfile index 5e404793..092948c7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,4 @@ -@Library('xmos_jenkins_shared_library@develop') _ +@Library('xmos_jenkins_shared_library@v0.16.2') _ getApproval() @@ -6,45 +6,7 @@ pipeline { agent none environment { REPO = 'lib_xua' - VIEW = "${env.JOB_NAME.contains('PR-') ? REPO+'_'+env.CHANGE_TARGET : REPO+'_'+env.BRANCH_NAME}" - } - triggers { - /* Trigger this Pipeline on changes to the repos dependencies - * - * If this Pipeline is running in a pull request, the triggers are set - * on the base branch the PR is set to merge in to. - * - * Otherwise the triggers are set on the branch of a matching name to the - * one this Pipeline is on. - */ - upstream( - upstreamProjects: - (env.JOB_NAME.contains('PR-') ? - "../lib_device_control/${env.CHANGE_TARGET}," + - "../lib_dsp/${env.CHANGE_TARGET}," + - "../lib_i2c/${env.CHANGE_TARGET}," + - "../lib_logging/${env.CHANGE_TARGET}," + - "../lib_mic_array/${env.CHANGE_TARGET}," + - "../lib_spdif/${env.CHANGE_TARGET}," + - "../lib_xassert/${env.CHANGE_TARGET}," + - "../lib_xud/${env.CHANGE_TARGET}," + - "../tools_released/${env.CHANGE_TARGET}," + - "../tools_xmostest/${env.CHANGE_TARGET}," + - "../xdoc_released/${env.CHANGE_TARGET}" - : - "../lib_device_control/${env.BRANCH_NAME}," + - "../lib_dsp/${env.BRANCH_NAME}," + - "../lib_i2c/${env.BRANCH_NAME}," + - "../lib_logging/${env.BRANCH_NAME}," + - "../lib_mic_array/${env.BRANCH_NAME}," + - "../lib_spdif/${env.BRANCH_NAME}," + - "../lib_xassert/${env.BRANCH_NAME}," + - "../lib_xud/${env.BRANCH_NAME}," + - "../tools_released/${env.BRANCH_NAME}," + - "../tools_xmostest/${env.BRANCH_NAME}," + - "../xdoc_released/${env.BRANCH_NAME}"), - threshold: hudson.model.Result.SUCCESS - ) + VIEW = getViewName(REPO) } options { skipDefaultCheckout() @@ -122,6 +84,42 @@ pipeline { } } } + stage('Build Pi host app') { + agent { + label 'pi' + } + steps { + dir("${REPO}") { + checkout scm + dir("${REPO}/host/xmosdfu") { + sh 'make -f Makefile.Pi' + } + } + } + post { + cleanup { + xcoreCleanSandbox() + } + } + } + stage('Build Windows host app') { + agent { + label 'x86_64&&windows' + } + steps { + dir("${REPO}") { + checkout scm + dir("${REPO}/host/xmosdfu") { + runVS('nmake /f Makefile.Win32') + } + } + } + post { + cleanup { + xcoreCleanSandbox() + } + } + } } } stage('Update') { @@ -133,7 +131,7 @@ pipeline { } post { cleanup { - cleanWs() + xcoreCleanSandbox() } } } diff --git a/LICENSE.rst b/LICENSE.rst new file mode 100644 index 00000000..ca48f20f --- /dev/null +++ b/LICENSE.rst @@ -0,0 +1,84 @@ +******************************* +XMOS PUBLIC LICENCE: Version 1 +******************************* + +Subject to the conditions and limitations below, permission is hereby granted by XMOS LIMITED (“XMOS”), free of charge, to any person or entity obtaining a copy of the XMOS Software. + +**1. Definitions** + +**“Applicable Patent Rights”** means: (a) where XMOS is the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to XMOS and (ii) that cover subject matter contained in the Software, but only to the extent it is necessary to use, reproduce or distribute the Software without infringement; and (b) where you are the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to you and (ii) that cover the subject matter contained in your Derivatives, taken alone or in combination with the Software. + +**“Compiled Code”** means any compiled, binary, machine readable or executable version of the Source Code. + +**“Contributor”** means any person or entity that creates or contributes to the creation of Derivatives. + +**“Derivatives”** means any addition to, deletion from and/or change to the substance, structure of the Software, any previous Derivatives, the combination of the Derivatives and the Software and/or any respective portions thereof. + +**“Source Code”** means the human readable code that is suitable for making modifications but excluding any Compiled Code. + +**“Software”** means the software and associated documentation files which XMOS makes available and which contain a notice identifying the software as original XMOS software and referring to the software being subject to the terms of this XMOS Public Licence. + +This Licence refers to XMOS Software and does not relate to any XMOS hardware or devices which are protected by intellectual property rights (including patent and trade marks) which may be sold to you under a separate agreement. + + +**2. Licence** + +**Permitted Uses, Conditions and Restrictions.** Subject to the conditions below, XMOS grants you a worldwide, royalty free, non-exclusive licence, to the extent of any Patent Rights to do the following: + +2.1 **Unmodified Software.** You may use, copy, display, publish, distribute and make available unmodified copies of the Software: + +2.1.1 for personal or academic, non-commercial purposes; or + +2.1.2 for commercial purposes provided the Software is at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.1.1 and 2.1.2): + +(a) you must retain and reproduce in all copies of the Software the copyright and proprietary notices and disclaimers of XMOS as they appear in the Software, and keep intact all notices and disclaimers in the Software files that refer to this Licence; and + +(b) you must include a copy of this Licence with every copy of the Software and documentation you publish, distribute and make available and you may not offer or impose any terms on such Software that alter or restrict this Licence or the intent of such Licence, except as permitted below (Additional Terms). + +The licence above does not include any Compiled Code which XMOS may make available under a separate support and licence agreement. + +2.2 **Derivatives.** You may create and modify Derivatives and use, copy, display, publish, distribute and make available Derivatives: + +2.2.1 for personal or academic, non-commercial purposes; or + +2.2.2 for commercial purposes, provided the Derivatives are at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.2.1 and 2.2.2): + +(a) you must comply with the terms of clause 2.1 with respect to the Derivatives; + +(b) you must copy (to the extent it doesn’t already exist) the notice below in each file of the Derivatives, and ensure all the modified files carry prominent notices stating that you have changed the files and the date of any change; and + +(c) if you sublicence, distribute or otherwise make the Software and/or the Derivatives available for commercial purposes, you must provide that the Software and Derivatives are at all times used on a device designed, licensed or developed by XMOS. + +Without limitation to these terms and clause 3 below, the Source Code and Compiled Code to your Derivatives may at your discretion (but without obligation) be released, copied, displayed, published, distributed and made available; and if you elect to do so, it must be under the terms of this Licence including the terms of the licence at clauses 2.2.1, 2.2.2 and clause 3 below. + +2.3 **Distribution of Executable Versions.** If you distribute or make available Derivatives, you must include a prominent notice in the code itself as well as in all related documentation, stating that the Source Code of the Software from which the Derivatives are based is available under the terms of this Licence, with information on how and where to obtain such Source Code. + +**3. Your Grant of Rights.** In consideration and as a condition to this Licence, you grant to any person or entity receiving or distributing any Derivatives, a non-exclusive, royalty free, perpetual, irrevocable license under your Applicable Patent Rights and all other intellectual property rights owned or controlled by you, to use, copy, display, publish, distribute and make available your Derivatives of the same scope and extent as XMOS’s licence under clause 2.2 above. + +**4. Combined Products.** You may create a combined product by combining Software, Derivatives and other code not covered by this Licence as a single application or product. In such instance, you must comply with the requirements of this Licence for any portion of the Software and/or Derivatives. + +**5. Additional Terms.** You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations and/or other rights consistent with the term of this Licence (“Additional Terms”) to any legitimate recipients of the Software and/or Derivatives. The terms on which you provide such Additional Terms are on your sole responsibility and you shall indemnify, defend and hold XMOS harmless against any claims asserted against XMOS. + +**6. New Versions.** XMOS may publish revised and/or new versions of this Licence from time to time to accommodate changes to the Licence terms, new versions, updates and bug fixes of the Software. Each version will be given a distinguishing version number. Once Software has been published under a particular version of this Licence, you may continue to use it under the terms of that version. You may also choose to use the latest version of the Software under any subsequent version published by XMOS. Only XMOS shall have the right to modify these terms. + +**7. IPR and Ownership** +Any rights, including all intellectual property rights and all trademarks not expressly granted herein are reserved in full by the authors or copyright holders. Any requests for additional permissions by XMOS including any rights to use XMOS trademarks, should be made (without obligation) to XMOS at **support@xmos.com** + +Nothing herein shall limit any rights that XMOS is otherwise entitled to under the doctrines of patent exhaustion, implied license, or legal estoppel. Neither the name of the authors, the copyright holders or any contributors may be used to endorse or promote any Derivatives from this Software without specific written permission. Any attempt to deal with the Software which does not comply with this Licence shall be void and shall automatically terminate any rights granted under this licence (including any licence of any intellectual property rights granted herein). +Subject to the licences granted under this Licence any Contributor retains all rights, title and interest in and to any Derivatives made by Contributor subject to the underlying rights of XMOS in the Software. XMOS shall retain all rights, title and interest in the Software and any Derivatives made by XMOS (“XMOS Derivatives”). XMOS Derivatives will not automatically be subject to this Licence and XMOS shall be entitled to licence such rights on any terms (without obligation) as it sees fit. + +**8. Termination** + +8.1 This Licence will automatically terminate immediately, without notice to you, if: + +(a) you fail to comply with the terms of this Licence; and/or + +(b) you directly or indirectly commence any action for patent or intellectual property right infringement against XMOS, or any parent, group, affiliate or subsidiary of XMOS; provided XMOS did not first commence an action or patent infringement against you in that instance; and/or + +(c) the terms of this Licence are held by any court of competent jurisdiction to be unenforceable in whole or in part. + +**9. Critical Applications.** Unless XMOS has agreed in writing with you an agreement specifically governing use of the Goods in military, aerospace, automotive or medically related functions (collectively and individually hereinafter referred to as "Special Use"), any permitted use of the Software excludes Special Use. Notwithstanding any agreement between XMOS and you for Special Use, Special Use shall be at your own risk, and you shall fully indemnify XMOS against any damages, losses, costs and claims (direct and indirect) arising out of any Special Use. + +**10. NO WARRANTY OR SUPPORT.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL XMOS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, WARRANTY, CIVIL TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE INCLUDING GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES EVEN IF SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND NOT WITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE. IN SOME JURISDICTIONS PARTIES ARE UNABLE TO LIMIT LIABILTY IN THIS WAY, IF THIS APPLIES TO YOUR JURISDICTION THIS LIABILITY CLAUSE ABOVE MAY NOT APPLY. NOTWITHSTANDING THE ABOVE, IN NO EVENT SHALL XMOS’s TOTAL LIABILITY TO YOU FOR ALL DAMAGES, LOSS OR OTHERWISE EXCEED $50. + +**11. Governing Law and Jurisdiction.** This Licence constitutes the entire agreement between the parties with respect to the subject matter hereof. The Licence shall be governed by the laws of England and the conflict of laws and UN Convention on Contracts for the International Sale of Goods, shall not apply. diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 19f8e7cc..00000000 --- a/LICENSE.txt +++ /dev/null @@ -1,135 +0,0 @@ -Software Release License Agreement - -Copyright (c) 2011-2019, XMOS, All rights reserved. - -BY ACCESSING, USING, INSTALLING OR DOWNLOADING THE XMOS SOFTWARE, YOU AGREE TO BE BOUND BY THE FOLLOWING TERMS. IF YOU DO NOT AGREE TO THESE, DO NOT ATTEMPT TO DOWNLOAD, ACCESS OR USE THE XMOS Software. - -Parties: - -(1) XMOS Limited, incorporated and registered in England and Wales with company number 5494985 whose registered office is 107 Cheapside, London, EC2V 6DN (XMOS). - -(2) An individual or legal entity exercising permissions granted by this License (Customer). - -If you are entering into this Agreement on behalf of another legal entity such as a company, partnership, university, college etc. (for example, as an employee, student or consultant), you warrant that you have authority to bind that entity. - -1. Definitions - -"License" means this Software License and any schedules or annexes to it. - -"License Fee" means the fee for the XMOS Software as detailed in any schedules or annexes to this Software License - -"Licensee Modifications" means all developments and modifications of the XMOS Software developed independently by the Customer. - -"XMOS Modifications" means all developments and modifications of the XMOS Software developed or co-developed by XMOS. - -"XMOS Hardware" means any XMOS hardware devices supplied by XMOS from time to time and/or the particular XMOS devices detailed in any schedules or annexes to this Software License. - -"XMOS Software" comprises the XMOS owned circuit designs, schematics, source code, object code, reference designs, (including related programmer comments and documentation, if any), error corrections, improvements, modifications (including XMOS Modifications) and updates. - -The headings in this License do not affect its interpretation. Save where the context otherwise requires, references to clauses and schedules are to clauses and schedules of this License. - -Unless the context otherwise requires: - -- references to XMOS and the Customer include their permitted successors and assigns; -- references to statutory provisions include those statutory provisions as amended or re-enacted; and -- references to any gender include all genders. - -Words in the singular include the plural and in the plural include the singular. - -2. License - -XMOS grants the Customer a non-exclusive license to use, develop, modify and distribute the XMOS Software with, or for the purpose of being used with, XMOS Hardware. - -Open Source Software (OSS) must be used and dealt with in accordance with any license terms under which OSS is distributed. - -3. Consideration - -In consideration of the mutual obligations contained in this License, the parties agree to its terms. - -4. Term - -Subject to clause 12 below, this License shall be perpetual. - -5. Restrictions on Use - -The Customer will adhere to all applicable import and export laws and regulations of the country in which it resides and of the United States and United Kingdom, without limitation. The Customer agrees that it is its responsibility to obtain copies of and to familiarise itself fully with these laws and regulations to avoid violation. - -6. Modifications - -The Customer will own all intellectual property rights in the Licensee Modifications but will undertake to provide XMOS with any fixes made to correct any bugs found in the XMOS Software on a non-exclusive, perpetual and royalty free license basis. - -XMOS will own all intellectual property rights in the XMOS Modifications. -The Customer may only use the Licensee Modifications and XMOS Modifications on, or in relation to, XMOS Hardware. - -7. Support - -Support of the XMOS Software may be provided by XMOS pursuant to a separate support agreement. - -8. Warranty and Disclaimer - -The XMOS Software is provided "AS IS" without a warranty of any kind. XMOS and its licensors' entire liability and Customer's exclusive remedy under this warranty to be determined in XMOS's sole and absolute discretion, will be either (a) the corrections of defects in media or replacement of the media, or (b) the refund of the license fee paid (if any). - -Whilst XMOS gives the Customer the ability to load their own software and applications onto XMOS devices, the security of such software and applications when on the XMOS devices is the Customer's own responsibility and any breach of security shall not be deemed a defect or failure of the hardware. XMOS shall have no liability whatsoever in relation to any costs, damages or other losses Customer may incur as a result of any breaches of security in relation to your software or applications. - -XMOS AND ITS LICENSORS DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY/ SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID UNDER APPLICABLE LAW. - -9. High Risk Activities - -The XMOS Software is not designed or intended for use in conjunction with on-line control equipment in hazardous environments requiring fail-safe performance, including without limitation the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, life support machines, or weapons systems (collectively "High Risk Activities") in which the failure of the XMOS Software could lead directly to death, personal injury, or severe physical or environmental damage. XMOS and its licensors specifically disclaim any express or implied warranties relating to use of the XMOS Software in connection with High Risk Activities. - -10. Liability - -TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, NEITHER XMOS NOR ITS LICENSORS SHALL BE LIABLE FOR ANY LOST REVENUE, BUSINESS, PROFIT, CONTRACTS OR DATA, ADMINISTRATIVE OR OVERHEAD EXPENSES, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THEORY OF LIABILITY ARISING OUT OF THIS LICENSE, EVEN IF XMOS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event shall XMOS's liability to the Customer whether in contract, tort (including negligence), or otherwise exceed the License Fee. - -Customer agrees to indemnify, hold harmless, and defend XMOS and its licensors from and against any claims or lawsuits, including attorneys' fees and any other liabilities, demands, proceedings, damages, losses, costs, expenses fines and charges which are made or brought against or incurred by XMOS as a result of your use or distribution of the Licensee Modifications or your use or distribution of XMOS Software, or any development of it, other than in accordance with the terms of this License. - -11. Ownership - -The copyrights and all other intellectual and industrial property rights for the protection of information with respect to the XMOS Software (including the methods and techniques on which they are based) are retained by XMOS and/or its licensors. Nothing in this Agreement serves to transfer such rights. Customer may not sell, mortgage, underlet, sublease, sublicense, lend or transfer possession of the XMOS Software in any way whatsoever to any third party who is not bound by this Agreement. - -12. Termination - -Either party may terminate this License at any time on written notice to the other if the other: - -- is in material or persistent breach of any of the terms of this License and either that breach is incapable of remedy, or the other party fails to remedy that breach within 30 days after receiving written notice requiring it to remedy that breach; or - -- is unable to pay its debts (within the meaning of section 123 of the Insolvency Act 1986), or becomes insolvent, or is subject to an order or a resolution for its liquidation, administration, winding-up or dissolution (otherwise than for the purposes of a solvent amalgamation or reconstruction), or has an administrative or other receiver, manager, trustee, liquidator, administrator or similar officer appointed over all or any substantial part of its assets, or enters into or proposes any composition or arrangement with its creditors generally, or is subject to any analogous event or proceeding in any applicable jurisdiction. - -Termination by either party in accordance with the rights contained in clause 12 shall be without prejudice to any other rights or remedies of that party accrued prior to termination. - -On termination for any reason: - -- all rights granted to the Customer under this License shall cease; -- the Customer shall cease all activities authorised by this License; -- the Customer shall immediately pay any sums due to XMOS under this License; and -- the Customer shall immediately destroy or return to the XMOS (at the XMOS's option) all copies of the XMOS Software then in its possession, custody or control and, in the case of destruction, certify to XMOS that it has done so. - -Clauses 5, 8, 9, 10 and 11 shall survive any effective termination of this Agreement. - -13. Third party rights - -No term of this License is intended to confer a benefit on, or to be enforceable by, any person who is not a party to this license. - -14. Confidentiality and publicity - -Each party shall, during the term of this License and thereafter, keep confidential all, and shall not use for its own purposes nor without the prior written consent of the other disclose to any third party any, information of a confidential nature (including, without limitation, trade secrets and information of commercial value) which may become known to such party from the other party and which relates to the other party, unless such information is public knowledge or already known to such party at the time of disclosure, or subsequently becomes public knowledge other than by breach of this license, or subsequently comes lawfully into the possession of such party from a third party. - -The terms of this license are confidential and may not be disclosed by the Customer without the prior written consent of XMOS. -The provisions of clause 14 shall remain in full force and effect notwithstanding termination of this license for any reason. - -15. Entire agreement - -This License and the documents annexed as appendices to this License or otherwise referred to herein contain the whole agreement between the parties relating to the subject matter hereof and supersede all prior agreements, arrangements and understandings between the parties relating to that subject matter. - -16. Assignment - -The Customer shall not assign this License or any of the rights granted under it without XMOS's prior written consent. - -17. Governing law and jurisdiction - -This License shall be governed by and construed in accordance with English law and each party hereby submits to the non-exclusive jurisdiction of the English courts. - -This License has been entered into on the date stated at the beginning of it. - -Schedule -XMOS lib_xua software diff --git a/Pipfile b/Pipfile deleted file mode 100644 index 6d52bfd2..00000000 --- a/Pipfile +++ /dev/null @@ -1,7 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] -flake8 = "*" diff --git a/README.rst b/README.rst index a569b661..78c6145c 100644 --- a/README.rst +++ b/README.rst @@ -49,7 +49,8 @@ Note, not all features may be supported at all sample frequencies, simultaneousl Software version and dependencies ................................. -.. libdeps:: +The CHANGELOG contains information about the current and previous versions. +For a list of direct dependencies, look for DEPENDENT_MODULES in lib_xua/module_build_info. Related Application Notes ......................... diff --git a/cpanfile b/cpanfile deleted file mode 100644 index 071f5e6a..00000000 --- a/cpanfile +++ /dev/null @@ -1,2 +0,0 @@ -requires 'File::Copy::Recursive'; -requires 'LWP::Simple' diff --git a/doc_dfu/LICENSE.rst b/doc_dfu/LICENSE.rst new file mode 100644 index 00000000..ca48f20f --- /dev/null +++ b/doc_dfu/LICENSE.rst @@ -0,0 +1,84 @@ +******************************* +XMOS PUBLIC LICENCE: Version 1 +******************************* + +Subject to the conditions and limitations below, permission is hereby granted by XMOS LIMITED (“XMOS”), free of charge, to any person or entity obtaining a copy of the XMOS Software. + +**1. Definitions** + +**“Applicable Patent Rights”** means: (a) where XMOS is the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to XMOS and (ii) that cover subject matter contained in the Software, but only to the extent it is necessary to use, reproduce or distribute the Software without infringement; and (b) where you are the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to you and (ii) that cover the subject matter contained in your Derivatives, taken alone or in combination with the Software. + +**“Compiled Code”** means any compiled, binary, machine readable or executable version of the Source Code. + +**“Contributor”** means any person or entity that creates or contributes to the creation of Derivatives. + +**“Derivatives”** means any addition to, deletion from and/or change to the substance, structure of the Software, any previous Derivatives, the combination of the Derivatives and the Software and/or any respective portions thereof. + +**“Source Code”** means the human readable code that is suitable for making modifications but excluding any Compiled Code. + +**“Software”** means the software and associated documentation files which XMOS makes available and which contain a notice identifying the software as original XMOS software and referring to the software being subject to the terms of this XMOS Public Licence. + +This Licence refers to XMOS Software and does not relate to any XMOS hardware or devices which are protected by intellectual property rights (including patent and trade marks) which may be sold to you under a separate agreement. + + +**2. Licence** + +**Permitted Uses, Conditions and Restrictions.** Subject to the conditions below, XMOS grants you a worldwide, royalty free, non-exclusive licence, to the extent of any Patent Rights to do the following: + +2.1 **Unmodified Software.** You may use, copy, display, publish, distribute and make available unmodified copies of the Software: + +2.1.1 for personal or academic, non-commercial purposes; or + +2.1.2 for commercial purposes provided the Software is at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.1.1 and 2.1.2): + +(a) you must retain and reproduce in all copies of the Software the copyright and proprietary notices and disclaimers of XMOS as they appear in the Software, and keep intact all notices and disclaimers in the Software files that refer to this Licence; and + +(b) you must include a copy of this Licence with every copy of the Software and documentation you publish, distribute and make available and you may not offer or impose any terms on such Software that alter or restrict this Licence or the intent of such Licence, except as permitted below (Additional Terms). + +The licence above does not include any Compiled Code which XMOS may make available under a separate support and licence agreement. + +2.2 **Derivatives.** You may create and modify Derivatives and use, copy, display, publish, distribute and make available Derivatives: + +2.2.1 for personal or academic, non-commercial purposes; or + +2.2.2 for commercial purposes, provided the Derivatives are at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.2.1 and 2.2.2): + +(a) you must comply with the terms of clause 2.1 with respect to the Derivatives; + +(b) you must copy (to the extent it doesn’t already exist) the notice below in each file of the Derivatives, and ensure all the modified files carry prominent notices stating that you have changed the files and the date of any change; and + +(c) if you sublicence, distribute or otherwise make the Software and/or the Derivatives available for commercial purposes, you must provide that the Software and Derivatives are at all times used on a device designed, licensed or developed by XMOS. + +Without limitation to these terms and clause 3 below, the Source Code and Compiled Code to your Derivatives may at your discretion (but without obligation) be released, copied, displayed, published, distributed and made available; and if you elect to do so, it must be under the terms of this Licence including the terms of the licence at clauses 2.2.1, 2.2.2 and clause 3 below. + +2.3 **Distribution of Executable Versions.** If you distribute or make available Derivatives, you must include a prominent notice in the code itself as well as in all related documentation, stating that the Source Code of the Software from which the Derivatives are based is available under the terms of this Licence, with information on how and where to obtain such Source Code. + +**3. Your Grant of Rights.** In consideration and as a condition to this Licence, you grant to any person or entity receiving or distributing any Derivatives, a non-exclusive, royalty free, perpetual, irrevocable license under your Applicable Patent Rights and all other intellectual property rights owned or controlled by you, to use, copy, display, publish, distribute and make available your Derivatives of the same scope and extent as XMOS’s licence under clause 2.2 above. + +**4. Combined Products.** You may create a combined product by combining Software, Derivatives and other code not covered by this Licence as a single application or product. In such instance, you must comply with the requirements of this Licence for any portion of the Software and/or Derivatives. + +**5. Additional Terms.** You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations and/or other rights consistent with the term of this Licence (“Additional Terms”) to any legitimate recipients of the Software and/or Derivatives. The terms on which you provide such Additional Terms are on your sole responsibility and you shall indemnify, defend and hold XMOS harmless against any claims asserted against XMOS. + +**6. New Versions.** XMOS may publish revised and/or new versions of this Licence from time to time to accommodate changes to the Licence terms, new versions, updates and bug fixes of the Software. Each version will be given a distinguishing version number. Once Software has been published under a particular version of this Licence, you may continue to use it under the terms of that version. You may also choose to use the latest version of the Software under any subsequent version published by XMOS. Only XMOS shall have the right to modify these terms. + +**7. IPR and Ownership** +Any rights, including all intellectual property rights and all trademarks not expressly granted herein are reserved in full by the authors or copyright holders. Any requests for additional permissions by XMOS including any rights to use XMOS trademarks, should be made (without obligation) to XMOS at **support@xmos.com** + +Nothing herein shall limit any rights that XMOS is otherwise entitled to under the doctrines of patent exhaustion, implied license, or legal estoppel. Neither the name of the authors, the copyright holders or any contributors may be used to endorse or promote any Derivatives from this Software without specific written permission. Any attempt to deal with the Software which does not comply with this Licence shall be void and shall automatically terminate any rights granted under this licence (including any licence of any intellectual property rights granted herein). +Subject to the licences granted under this Licence any Contributor retains all rights, title and interest in and to any Derivatives made by Contributor subject to the underlying rights of XMOS in the Software. XMOS shall retain all rights, title and interest in the Software and any Derivatives made by XMOS (“XMOS Derivatives”). XMOS Derivatives will not automatically be subject to this Licence and XMOS shall be entitled to licence such rights on any terms (without obligation) as it sees fit. + +**8. Termination** + +8.1 This Licence will automatically terminate immediately, without notice to you, if: + +(a) you fail to comply with the terms of this Licence; and/or + +(b) you directly or indirectly commence any action for patent or intellectual property right infringement against XMOS, or any parent, group, affiliate or subsidiary of XMOS; provided XMOS did not first commence an action or patent infringement against you in that instance; and/or + +(c) the terms of this Licence are held by any court of competent jurisdiction to be unenforceable in whole or in part. + +**9. Critical Applications.** Unless XMOS has agreed in writing with you an agreement specifically governing use of the Goods in military, aerospace, automotive or medically related functions (collectively and individually hereinafter referred to as "Special Use"), any permitted use of the Software excludes Special Use. Notwithstanding any agreement between XMOS and you for Special Use, Special Use shall be at your own risk, and you shall fully indemnify XMOS against any damages, losses, costs and claims (direct and indirect) arising out of any Special Use. + +**10. NO WARRANTY OR SUPPORT.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL XMOS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, WARRANTY, CIVIL TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE INCLUDING GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES EVEN IF SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND NOT WITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE. IN SOME JURISDICTIONS PARTIES ARE UNABLE TO LIMIT LIABILTY IN THIS WAY, IF THIS APPLIES TO YOUR JURISDICTION THIS LIABILITY CLAUSE ABOVE MAY NOT APPLY. NOTWITHSTANDING THE ABOVE, IN NO EVENT SHALL XMOS’s TOTAL LIABILITY TO YOU FOR ALL DAMAGES, LOSS OR OTHERWISE EXCEED $50. + +**11. Governing Law and Jurisdiction.** This Licence constitutes the entire agreement between the parties with respect to the subject matter hereof. The Licence shall be governed by the laws of England and the conflict of laws and UN Convention on Contracts for the International Sale of Goods, shall not apply. diff --git a/doc_dfu/LICENSE.txt b/doc_dfu/LICENSE.txt deleted file mode 100644 index 9f9fc466..00000000 --- a/doc_dfu/LICENSE.txt +++ /dev/null @@ -1,135 +0,0 @@ -Software Release License Agreement - -Copyright (c) 2017-2018, XMOS, All rights reserved. - -BY ACCESSING, USING, INSTALLING OR DOWNLOADING THE XMOS SOFTWARE, YOU AGREE TO BE BOUND BY THE FOLLOWING TERMS. IF YOU DO NOT AGREE TO THESE, DO NOT ATTEMPT TO DOWNLOAD, ACCESS OR USE THE XMOS Software. - -Parties: - -(1) XMOS Limited, incorporated and registered in England and Wales with company number 5494985 whose registered office is 107 Cheapside, London, EC2V 6DN (XMOS). - -(2) An individual or legal entity exercising permissions granted by this License (Customer). - -If you are entering into this Agreement on behalf of another legal entity such as a company, partnership, university, college etc. (for example, as an employee, student or consultant), you warrant that you have authority to bind that entity. - -1. Definitions - -"License" means this Software License and any schedules or annexes to it. - -"License Fee" means the fee for the XMOS Software as detailed in any schedules or annexes to this Software License - -"Licensee Modifications" means all developments and modifications of the XMOS Software developed independently by the Customer. - -"XMOS Modifications" means all developments and modifications of the XMOS Software developed or co-developed by XMOS. - -"XMOS Hardware" means any XMOS hardware devices supplied by XMOS from time to time and/or the particular XMOS devices detailed in any schedules or annexes to this Software License. - -"XMOS Software" comprises the XMOS owned circuit designs, schematics, source code, object code, reference designs, (including related programmer comments and documentation, if any), error corrections, improvements, modifications (including XMOS Modifications) and updates. - -The headings in this License do not affect its interpretation. Save where the context otherwise requires, references to clauses and schedules are to clauses and schedules of this License. - -Unless the context otherwise requires: - -- references to XMOS and the Customer include their permitted successors and assigns; -- references to statutory provisions include those statutory provisions as amended or re-enacted; and -- references to any gender include all genders. - -Words in the singular include the plural and in the plural include the singular. - -2. License - -XMOS grants the Customer a non-exclusive license to use, develop, modify and distribute the XMOS Software with, or for the purpose of being used with, XMOS Hardware. - -Open Source Software (OSS) must be used and dealt with in accordance with any license terms under which OSS is distributed. - -3. Consideration - -In consideration of the mutual obligations contained in this License, the parties agree to its terms. - -4. Term - -Subject to clause 12 below, this License shall be perpetual. - -5. Restrictions on Use - -The Customer will adhere to all applicable import and export laws and regulations of the country in which it resides and of the United States and United Kingdom, without limitation. The Customer agrees that it is its responsibility to obtain copies of and to familiarise itself fully with these laws and regulations to avoid violation. - -6. Modifications - -The Customer will own all intellectual property rights in the Licensee Modifications but will undertake to provide XMOS with any fixes made to correct any bugs found in the XMOS Software on a non-exclusive, perpetual and royalty free license basis. - -XMOS will own all intellectual property rights in the XMOS Modifications. -The Customer may only use the Licensee Modifications and XMOS Modifications on, or in relation to, XMOS Hardware. - -7. Support - -Support of the XMOS Software may be provided by XMOS pursuant to a separate support agreement. - -8. Warranty and Disclaimer - -The XMOS Software is provided "AS IS" without a warranty of any kind. XMOS and its licensors' entire liability and Customer's exclusive remedy under this warranty to be determined in XMOS's sole and absolute discretion, will be either (a) the corrections of defects in media or replacement of the media, or (b) the refund of the license fee paid (if any). - -Whilst XMOS gives the Customer the ability to load their own software and applications onto XMOS devices, the security of such software and applications when on the XMOS devices is the Customer's own responsibility and any breach of security shall not be deemed a defect or failure of the hardware. XMOS shall have no liability whatsoever in relation to any costs, damages or other losses Customer may incur as a result of any breaches of security in relation to your software or applications. - -XMOS AND ITS LICENSORS DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY/ SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID UNDER APPLICABLE LAW. - -9. High Risk Activities - -The XMOS Software is not designed or intended for use in conjunction with on-line control equipment in hazardous environments requiring fail-safe performance, including without limitation the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, life support machines, or weapons systems (collectively "High Risk Activities") in which the failure of the XMOS Software could lead directly to death, personal injury, or severe physical or environmental damage. XMOS and its licensors specifically disclaim any express or implied warranties relating to use of the XMOS Software in connection with High Risk Activities. - -10. Liability - -TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, NEITHER XMOS NOR ITS LICENSORS SHALL BE LIABLE FOR ANY LOST REVENUE, BUSINESS, PROFIT, CONTRACTS OR DATA, ADMINISTRATIVE OR OVERHEAD EXPENSES, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THEORY OF LIABILITY ARISING OUT OF THIS LICENSE, EVEN IF XMOS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event shall XMOS's liability to the Customer whether in contract, tort (including negligence), or otherwise exceed the License Fee. - -Customer agrees to indemnify, hold harmless, and defend XMOS and its licensors from and against any claims or lawsuits, including attorneys' fees and any other liabilities, demands, proceedings, damages, losses, costs, expenses fines and charges which are made or brought against or incurred by XMOS as a result of your use or distribution of the Licensee Modifications or your use or distribution of XMOS Software, or any development of it, other than in accordance with the terms of this License. - -11. Ownership - -The copyrights and all other intellectual and industrial property rights for the protection of information with respect to the XMOS Software (including the methods and techniques on which they are based) are retained by XMOS and/or its licensors. Nothing in this Agreement serves to transfer such rights. Customer may not sell, mortgage, underlet, sublease, sublicense, lend or transfer possession of the XMOS Software in any way whatsoever to any third party who is not bound by this Agreement. - -12. Termination - -Either party may terminate this License at any time on written notice to the other if the other: - -- is in material or persistent breach of any of the terms of this License and either that breach is incapable of remedy, or the other party fails to remedy that breach within 30 days after receiving written notice requiring it to remedy that breach; or - -- is unable to pay its debts (within the meaning of section 123 of the Insolvency Act 1986), or becomes insolvent, or is subject to an order or a resolution for its liquidation, administration, winding-up or dissolution (otherwise than for the purposes of a solvent amalgamation or reconstruction), or has an administrative or other receiver, manager, trustee, liquidator, administrator or similar officer appointed over all or any substantial part of its assets, or enters into or proposes any composition or arrangement with its creditors generally, or is subject to any analogous event or proceeding in any applicable jurisdiction. - -Termination by either party in accordance with the rights contained in clause 12 shall be without prejudice to any other rights or remedies of that party accrued prior to termination. - -On termination for any reason: - -- all rights granted to the Customer under this License shall cease; -- the Customer shall cease all activities authorised by this License; -- the Customer shall immediately pay any sums due to XMOS under this License; and -- the Customer shall immediately destroy or return to the XMOS (at the XMOS's option) all copies of the XMOS Software then in its possession, custody or control and, in the case of destruction, certify to XMOS that it has done so. - -Clauses 5, 8, 9, 10 and 11 shall survive any effective termination of this Agreement. - -13. Third party rights - -No term of this License is intended to confer a benefit on, or to be enforceable by, any person who is not a party to this license. - -14. Confidentiality and publicity - -Each party shall, during the term of this License and thereafter, keep confidential all, and shall not use for its own purposes nor without the prior written consent of the other disclose to any third party any, information of a confidential nature (including, without limitation, trade secrets and information of commercial value) which may become known to such party from the other party and which relates to the other party, unless such information is public knowledge or already known to such party at the time of disclosure, or subsequently becomes public knowledge other than by breach of this license, or subsequently comes lawfully into the possession of such party from a third party. - -The terms of this license are confidential and may not be disclosed by the Customer without the prior written consent of XMOS. -The provisions of clause 14 shall remain in full force and effect notwithstanding termination of this license for any reason. - -15. Entire agreement - -This License and the documents annexed as appendices to this License or otherwise referred to herein contain the whole agreement between the parties relating to the subject matter hereof and supersede all prior agreements, arrangements and understandings between the parties relating to that subject matter. - -16. Assignment - -The Customer shall not assign this License or any of the rights granted under it without XMOS's prior written consent. - -17. Governing law and jurisdiction - -This License shall be governed by and construed in accordance with English law and each party hereby submits to the non-exclusive jurisdiction of the English courts. - -This License has been entered into on the date stated at the beginning of it. - -Schedule -XMOS lib_xua software diff --git a/doc_dfu/building_xmos_dfu.rst b/doc_dfu/building_xmos_dfu.rst index 3ca54fdd..132c04d2 100644 --- a/doc_dfu/building_xmos_dfu.rst +++ b/doc_dfu/building_xmos_dfu.rst @@ -39,3 +39,18 @@ Raspberry Pi A makefile is provided for Raspbian. libusb is required and can be installed using the ``apt-get`` command from previous Linux section. .. literalinclude:: Makefile.Pi + +Windows +------- + +To build on Windows, you must first install Visual Studio 2019 Build Tools with +C++ support. `This is available from Microsoft's website. `_ + +To build, open a Developer Command Prompt via the start menu and navigate to the +xmosdfu folder. The command to build is as follows: + + ``nmake /f Makefile.Win32`` + +This Makefile contains the following: + +.. literalinclude:: Makefile.Win32 diff --git a/doc_dfu/xmos_dfu.rst b/doc_dfu/xmos_dfu.rst index 17f58662..750c206c 100644 --- a/doc_dfu/xmos_dfu.rst +++ b/doc_dfu/xmos_dfu.rst @@ -4,6 +4,9 @@ Using the DFU loader - macOS (via the XMOS DFU loader) The XMOS DFU loader is provided as source as part of the XMOS USB Audio software framework, see :ref:`usb_audiosec_building_xmos_dfu`. +NOTE: Windows requires the installation of libusbK drivers on the DFU endpoint. +We recommend using `Zadig `_. + Set up the image loader ----------------------- @@ -18,7 +21,7 @@ Download new firmware To program the new firmware run the command: - ``./xmosdfu XMOS_L2_AUDIO2_PID --download new_firmware.bin`` + ``./bin/xmosdfu XMOS_L2_AUDIO2_PID --download new_firmware.bin`` Replace ``XMOS_L2_AUDIO2_PID`` with product ID of your target device. Invoke ``xmosdfu`` with no arguments to get a list of all supported product IDs. @@ -35,7 +38,7 @@ present. Run the command: - ``./xmosdfu XMOS_L2_AUDIO2_PID --upload currentfirmware.bin`` + ``./bin/xmosdfu XMOS_L2_AUDIO2_PID --upload currentfirmware.bin`` The file ``currentfirmware.bin`` contains the latest upgrade image. This file is an exact copy of the data from the flash and can be downloaded to the device @@ -47,6 +50,6 @@ Reverting firmware to factory image To revert the device back to its factory (i.e XFLASH) installed state from the new firmware, run the command: - ``./xmosdfu XMOS_L2_AUDIO2_PID --revertfactory`` + ``./bin/xmosdfu XMOS_L2_AUDIO2_PID --revertfactory`` The device will now be running, and only contain the factory firmware. diff --git a/examples/AN00246_xua_example/LICENSE.rst b/examples/AN00246_xua_example/LICENSE.rst new file mode 100644 index 00000000..ca48f20f --- /dev/null +++ b/examples/AN00246_xua_example/LICENSE.rst @@ -0,0 +1,84 @@ +******************************* +XMOS PUBLIC LICENCE: Version 1 +******************************* + +Subject to the conditions and limitations below, permission is hereby granted by XMOS LIMITED (“XMOS”), free of charge, to any person or entity obtaining a copy of the XMOS Software. + +**1. Definitions** + +**“Applicable Patent Rights”** means: (a) where XMOS is the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to XMOS and (ii) that cover subject matter contained in the Software, but only to the extent it is necessary to use, reproduce or distribute the Software without infringement; and (b) where you are the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to you and (ii) that cover the subject matter contained in your Derivatives, taken alone or in combination with the Software. + +**“Compiled Code”** means any compiled, binary, machine readable or executable version of the Source Code. + +**“Contributor”** means any person or entity that creates or contributes to the creation of Derivatives. + +**“Derivatives”** means any addition to, deletion from and/or change to the substance, structure of the Software, any previous Derivatives, the combination of the Derivatives and the Software and/or any respective portions thereof. + +**“Source Code”** means the human readable code that is suitable for making modifications but excluding any Compiled Code. + +**“Software”** means the software and associated documentation files which XMOS makes available and which contain a notice identifying the software as original XMOS software and referring to the software being subject to the terms of this XMOS Public Licence. + +This Licence refers to XMOS Software and does not relate to any XMOS hardware or devices which are protected by intellectual property rights (including patent and trade marks) which may be sold to you under a separate agreement. + + +**2. Licence** + +**Permitted Uses, Conditions and Restrictions.** Subject to the conditions below, XMOS grants you a worldwide, royalty free, non-exclusive licence, to the extent of any Patent Rights to do the following: + +2.1 **Unmodified Software.** You may use, copy, display, publish, distribute and make available unmodified copies of the Software: + +2.1.1 for personal or academic, non-commercial purposes; or + +2.1.2 for commercial purposes provided the Software is at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.1.1 and 2.1.2): + +(a) you must retain and reproduce in all copies of the Software the copyright and proprietary notices and disclaimers of XMOS as they appear in the Software, and keep intact all notices and disclaimers in the Software files that refer to this Licence; and + +(b) you must include a copy of this Licence with every copy of the Software and documentation you publish, distribute and make available and you may not offer or impose any terms on such Software that alter or restrict this Licence or the intent of such Licence, except as permitted below (Additional Terms). + +The licence above does not include any Compiled Code which XMOS may make available under a separate support and licence agreement. + +2.2 **Derivatives.** You may create and modify Derivatives and use, copy, display, publish, distribute and make available Derivatives: + +2.2.1 for personal or academic, non-commercial purposes; or + +2.2.2 for commercial purposes, provided the Derivatives are at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.2.1 and 2.2.2): + +(a) you must comply with the terms of clause 2.1 with respect to the Derivatives; + +(b) you must copy (to the extent it doesn’t already exist) the notice below in each file of the Derivatives, and ensure all the modified files carry prominent notices stating that you have changed the files and the date of any change; and + +(c) if you sublicence, distribute or otherwise make the Software and/or the Derivatives available for commercial purposes, you must provide that the Software and Derivatives are at all times used on a device designed, licensed or developed by XMOS. + +Without limitation to these terms and clause 3 below, the Source Code and Compiled Code to your Derivatives may at your discretion (but without obligation) be released, copied, displayed, published, distributed and made available; and if you elect to do so, it must be under the terms of this Licence including the terms of the licence at clauses 2.2.1, 2.2.2 and clause 3 below. + +2.3 **Distribution of Executable Versions.** If you distribute or make available Derivatives, you must include a prominent notice in the code itself as well as in all related documentation, stating that the Source Code of the Software from which the Derivatives are based is available under the terms of this Licence, with information on how and where to obtain such Source Code. + +**3. Your Grant of Rights.** In consideration and as a condition to this Licence, you grant to any person or entity receiving or distributing any Derivatives, a non-exclusive, royalty free, perpetual, irrevocable license under your Applicable Patent Rights and all other intellectual property rights owned or controlled by you, to use, copy, display, publish, distribute and make available your Derivatives of the same scope and extent as XMOS’s licence under clause 2.2 above. + +**4. Combined Products.** You may create a combined product by combining Software, Derivatives and other code not covered by this Licence as a single application or product. In such instance, you must comply with the requirements of this Licence for any portion of the Software and/or Derivatives. + +**5. Additional Terms.** You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations and/or other rights consistent with the term of this Licence (“Additional Terms”) to any legitimate recipients of the Software and/or Derivatives. The terms on which you provide such Additional Terms are on your sole responsibility and you shall indemnify, defend and hold XMOS harmless against any claims asserted against XMOS. + +**6. New Versions.** XMOS may publish revised and/or new versions of this Licence from time to time to accommodate changes to the Licence terms, new versions, updates and bug fixes of the Software. Each version will be given a distinguishing version number. Once Software has been published under a particular version of this Licence, you may continue to use it under the terms of that version. You may also choose to use the latest version of the Software under any subsequent version published by XMOS. Only XMOS shall have the right to modify these terms. + +**7. IPR and Ownership** +Any rights, including all intellectual property rights and all trademarks not expressly granted herein are reserved in full by the authors or copyright holders. Any requests for additional permissions by XMOS including any rights to use XMOS trademarks, should be made (without obligation) to XMOS at **support@xmos.com** + +Nothing herein shall limit any rights that XMOS is otherwise entitled to under the doctrines of patent exhaustion, implied license, or legal estoppel. Neither the name of the authors, the copyright holders or any contributors may be used to endorse or promote any Derivatives from this Software without specific written permission. Any attempt to deal with the Software which does not comply with this Licence shall be void and shall automatically terminate any rights granted under this licence (including any licence of any intellectual property rights granted herein). +Subject to the licences granted under this Licence any Contributor retains all rights, title and interest in and to any Derivatives made by Contributor subject to the underlying rights of XMOS in the Software. XMOS shall retain all rights, title and interest in the Software and any Derivatives made by XMOS (“XMOS Derivatives”). XMOS Derivatives will not automatically be subject to this Licence and XMOS shall be entitled to licence such rights on any terms (without obligation) as it sees fit. + +**8. Termination** + +8.1 This Licence will automatically terminate immediately, without notice to you, if: + +(a) you fail to comply with the terms of this Licence; and/or + +(b) you directly or indirectly commence any action for patent or intellectual property right infringement against XMOS, or any parent, group, affiliate or subsidiary of XMOS; provided XMOS did not first commence an action or patent infringement against you in that instance; and/or + +(c) the terms of this Licence are held by any court of competent jurisdiction to be unenforceable in whole or in part. + +**9. Critical Applications.** Unless XMOS has agreed in writing with you an agreement specifically governing use of the Goods in military, aerospace, automotive or medically related functions (collectively and individually hereinafter referred to as "Special Use"), any permitted use of the Software excludes Special Use. Notwithstanding any agreement between XMOS and you for Special Use, Special Use shall be at your own risk, and you shall fully indemnify XMOS against any damages, losses, costs and claims (direct and indirect) arising out of any Special Use. + +**10. NO WARRANTY OR SUPPORT.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL XMOS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, WARRANTY, CIVIL TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE INCLUDING GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES EVEN IF SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND NOT WITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE. IN SOME JURISDICTIONS PARTIES ARE UNABLE TO LIMIT LIABILTY IN THIS WAY, IF THIS APPLIES TO YOUR JURISDICTION THIS LIABILITY CLAUSE ABOVE MAY NOT APPLY. NOTWITHSTANDING THE ABOVE, IN NO EVENT SHALL XMOS’s TOTAL LIABILITY TO YOU FOR ALL DAMAGES, LOSS OR OTHERWISE EXCEED $50. + +**11. Governing Law and Jurisdiction.** This Licence constitutes the entire agreement between the parties with respect to the subject matter hereof. The Licence shall be governed by the laws of England and the conflict of laws and UN Convention on Contracts for the International Sale of Goods, shall not apply. diff --git a/examples/AN00246_xua_example/LICENSE.txt b/examples/AN00246_xua_example/LICENSE.txt deleted file mode 100644 index 82cfb860..00000000 --- a/examples/AN00246_xua_example/LICENSE.txt +++ /dev/null @@ -1,135 +0,0 @@ -Software Release License Agreement - -Copyright (c) 2018, XMOS, All rights reserved. - -BY ACCESSING, USING, INSTALLING OR DOWNLOADING THE XMOS SOFTWARE, YOU AGREE TO BE BOUND BY THE FOLLOWING TERMS. IF YOU DO NOT AGREE TO THESE, DO NOT ATTEMPT TO DOWNLOAD, ACCESS OR USE THE XMOS Software. - -Parties: - -(1) XMOS Limited, incorporated and registered in England and Wales with company number 5494985 whose registered office is 107 Cheapside, London, EC2V 6DN (XMOS). - -(2) An individual or legal entity exercising permissions granted by this License (Customer). - -If you are entering into this Agreement on behalf of another legal entity such as a company, partnership, university, college etc. (for example, as an employee, student or consultant), you warrant that you have authority to bind that entity. - -1. Definitions - -"License" means this Software License and any schedules or annexes to it. - -"License Fee" means the fee for the XMOS Software as detailed in any schedules or annexes to this Software License - -"Licensee Modifications" means all developments and modifications of the XMOS Software developed independently by the Customer. - -"XMOS Modifications" means all developments and modifications of the XMOS Software developed or co-developed by XMOS. - -"XMOS Hardware" means any XMOS hardware devices supplied by XMOS from time to time and/or the particular XMOS devices detailed in any schedules or annexes to this Software License. - -"XMOS Software" comprises the XMOS owned circuit designs, schematics, source code, object code, reference designs, (including related programmer comments and documentation, if any), error corrections, improvements, modifications (including XMOS Modifications) and updates. - -The headings in this License do not affect its interpretation. Save where the context otherwise requires, references to clauses and schedules are to clauses and schedules of this License. - -Unless the context otherwise requires: - -- references to XMOS and the Customer include their permitted successors and assigns; -- references to statutory provisions include those statutory provisions as amended or re-enacted; and -- references to any gender include all genders. - -Words in the singular include the plural and in the plural include the singular. - -2. License - -XMOS grants the Customer a non-exclusive license to use, develop, modify and distribute the XMOS Software with, or for the purpose of being used with, XMOS Hardware. - -Open Source Software (OSS) must be used and dealt with in accordance with any license terms under which OSS is distributed. - -3. Consideration - -In consideration of the mutual obligations contained in this License, the parties agree to its terms. - -4. Term - -Subject to clause 12 below, this License shall be perpetual. - -5. Restrictions on Use - -The Customer will adhere to all applicable import and export laws and regulations of the country in which it resides and of the United States and United Kingdom, without limitation. The Customer agrees that it is its responsibility to obtain copies of and to familiarise itself fully with these laws and regulations to avoid violation. - -6. Modifications - -The Customer will own all intellectual property rights in the Licensee Modifications but will undertake to provide XMOS with any fixes made to correct any bugs found in the XMOS Software on a non-exclusive, perpetual and royalty free license basis. - -XMOS will own all intellectual property rights in the XMOS Modifications. -The Customer may only use the Licensee Modifications and XMOS Modifications on, or in relation to, XMOS Hardware. - -7. Support - -Support of the XMOS Software may be provided by XMOS pursuant to a separate support agreement. - -8. Warranty and Disclaimer - -The XMOS Software is provided "AS IS" without a warranty of any kind. XMOS and its licensors' entire liability and Customer's exclusive remedy under this warranty to be determined in XMOS's sole and absolute discretion, will be either (a) the corrections of defects in media or replacement of the media, or (b) the refund of the license fee paid (if any). - -Whilst XMOS gives the Customer the ability to load their own software and applications onto XMOS devices, the security of such software and applications when on the XMOS devices is the Customer's own responsibility and any breach of security shall not be deemed a defect or failure of the hardware. XMOS shall have no liability whatsoever in relation to any costs, damages or other losses Customer may incur as a result of any breaches of security in relation to your software or applications. - -XMOS AND ITS LICENSORS DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY/ SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID UNDER APPLICABLE LAW. - -9. High Risk Activities - -The XMOS Software is not designed or intended for use in conjunction with on-line control equipment in hazardous environments requiring fail-safe performance, including without limitation the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, life support machines, or weapons systems (collectively "High Risk Activities") in which the failure of the XMOS Software could lead directly to death, personal injury, or severe physical or environmental damage. XMOS and its licensors specifically disclaim any express or implied warranties relating to use of the XMOS Software in connection with High Risk Activities. - -10. Liability - -TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, NEITHER XMOS NOR ITS LICENSORS SHALL BE LIABLE FOR ANY LOST REVENUE, BUSINESS, PROFIT, CONTRACTS OR DATA, ADMINISTRATIVE OR OVERHEAD EXPENSES, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THEORY OF LIABILITY ARISING OUT OF THIS LICENSE, EVEN IF XMOS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event shall XMOS's liability to the Customer whether in contract, tort (including negligence), or otherwise exceed the License Fee. - -Customer agrees to indemnify, hold harmless, and defend XMOS and its licensors from and against any claims or lawsuits, including attorneys' fees and any other liabilities, demands, proceedings, damages, losses, costs, expenses fines and charges which are made or brought against or incurred by XMOS as a result of your use or distribution of the Licensee Modifications or your use or distribution of XMOS Software, or any development of it, other than in accordance with the terms of this License. - -11. Ownership - -The copyrights and all other intellectual and industrial property rights for the protection of information with respect to the XMOS Software (including the methods and techniques on which they are based) are retained by XMOS and/or its licensors. Nothing in this Agreement serves to transfer such rights. Customer may not sell, mortgage, underlet, sublease, sublicense, lend or transfer possession of the XMOS Software in any way whatsoever to any third party who is not bound by this Agreement. - -12. Termination - -Either party may terminate this License at any time on written notice to the other if the other: - -- is in material or persistent breach of any of the terms of this License and either that breach is incapable of remedy, or the other party fails to remedy that breach within 30 days after receiving written notice requiring it to remedy that breach; or - -- is unable to pay its debts (within the meaning of section 123 of the Insolvency Act 1986), or becomes insolvent, or is subject to an order or a resolution for its liquidation, administration, winding-up or dissolution (otherwise than for the purposes of a solvent amalgamation or reconstruction), or has an administrative or other receiver, manager, trustee, liquidator, administrator or similar officer appointed over all or any substantial part of its assets, or enters into or proposes any composition or arrangement with its creditors generally, or is subject to any analogous event or proceeding in any applicable jurisdiction. - -Termination by either party in accordance with the rights contained in clause 12 shall be without prejudice to any other rights or remedies of that party accrued prior to termination. - -On termination for any reason: - -- all rights granted to the Customer under this License shall cease; -- the Customer shall cease all activities authorised by this License; -- the Customer shall immediately pay any sums due to XMOS under this License; and -- the Customer shall immediately destroy or return to the XMOS (at the XMOS's option) all copies of the XMOS Software then in its possession, custody or control and, in the case of destruction, certify to XMOS that it has done so. - -Clauses 5, 8, 9, 10 and 11 shall survive any effective termination of this Agreement. - -13. Third party rights - -No term of this License is intended to confer a benefit on, or to be enforceable by, any person who is not a party to this license. - -14. Confidentiality and publicity - -Each party shall, during the term of this License and thereafter, keep confidential all, and shall not use for its own purposes nor without the prior written consent of the other disclose to any third party any, information of a confidential nature (including, without limitation, trade secrets and information of commercial value) which may become known to such party from the other party and which relates to the other party, unless such information is public knowledge or already known to such party at the time of disclosure, or subsequently becomes public knowledge other than by breach of this license, or subsequently comes lawfully into the possession of such party from a third party. - -The terms of this license are confidential and may not be disclosed by the Customer without the prior written consent of XMOS. -The provisions of clause 14 shall remain in full force and effect notwithstanding termination of this license for any reason. - -15. Entire agreement - -This License and the documents annexed as appendices to this License or otherwise referred to herein contain the whole agreement between the parties relating to the subject matter hereof and supersede all prior agreements, arrangements and understandings between the parties relating to that subject matter. - -16. Assignment - -The Customer shall not assign this License or any of the rights granted under it without XMOS's prior written consent. - -17. Governing law and jurisdiction - -This License shall be governed by and construed in accordance with English law and each party hereby submits to the non-exclusive jurisdiction of the English courts. - -This License has been entered into on the date stated at the beginning of it. - -Schedule -XMOS application note AN00246 software diff --git a/examples/AN00246_xua_example/README.rst b/examples/AN00246_xua_example/README.rst index ef159ebf..abe685d4 100644 --- a/examples/AN00246_xua_example/README.rst +++ b/examples/AN00246_xua_example/README.rst @@ -2,15 +2,13 @@ Simple USB Audio Device using lib_xua ===================================== -.. version:: 0.1.0 - Summary ------- -Required tools and libraries -............................ +Software dependencies +..................... -.. appdeps:: +For a list of direct dependencies, look for USED_MODULES in the Makefile. Required hardware ................. diff --git a/examples/AN00246_xua_example/src/app_xua_simple.xc b/examples/AN00246_xua_example/src/app_xua_simple.xc index e53f0778..131a04db 100644 --- a/examples/AN00246_xua_example/src/app_xua_simple.xc +++ b/examples/AN00246_xua_example/src/app_xua_simple.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /* A very simple *example* of a USB audio application (and as such is un-verified for production) * diff --git a/examples/AN00246_xua_example/src/cs4384.h b/examples/AN00246_xua_example/src/cs4384.h index 98defbe3..6de83e81 100644 --- a/examples/AN00246_xua_example/src/cs4384.h +++ b/examples/AN00246_xua_example/src/cs4384.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef CS4384_H_ #define CS4384_H_ diff --git a/examples/AN00246_xua_example/src/cs5368.h b/examples/AN00246_xua_example/src/cs5368.h index 945ae536..d2de278d 100644 --- a/examples/AN00246_xua_example/src/cs5368.h +++ b/examples/AN00246_xua_example/src/cs5368.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _CS5368_H_ #define _CS5368_H_ diff --git a/examples/AN00246_xua_example/src/hwsupport.xc b/examples/AN00246_xua_example/src/hwsupport.xc index f9ed5af7..7507ed8c 100644 --- a/examples/AN00246_xua_example/src/hwsupport.xc +++ b/examples/AN00246_xua_example/src/hwsupport.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include diff --git a/examples/AN00246_xua_example/src/xua_conf.h b/examples/AN00246_xua_example/src/xua_conf.h index d879e272..e0a0c36b 100644 --- a/examples/AN00246_xua_example/src/xua_conf.h +++ b/examples/AN00246_xua_example/src/xua_conf.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _XUA_CONF_H_ #define _XUA_CONF_H_ @@ -21,5 +22,6 @@ #define PID_AUDIO_1 1 #define PID_AUDIO_2 2 #define XUA_DFU_EN 0 /* Disable DFU (for simplicity of example */ +#define MIC_DUAL_ENABLED 0 // Use multi-threaded design #endif diff --git a/examples/AN00246_xua_example/src/xud_conf.h b/examples/AN00246_xua_example/src/xud_conf.h index c14d64a8..3fc13baf 100644 --- a/examples/AN00246_xua_example/src/xud_conf.h +++ b/examples/AN00246_xua_example/src/xud_conf.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua_conf.h" diff --git a/examples/AN00247_xua_example_spdif_tx/LICENSE.rst b/examples/AN00247_xua_example_spdif_tx/LICENSE.rst new file mode 100644 index 00000000..ca48f20f --- /dev/null +++ b/examples/AN00247_xua_example_spdif_tx/LICENSE.rst @@ -0,0 +1,84 @@ +******************************* +XMOS PUBLIC LICENCE: Version 1 +******************************* + +Subject to the conditions and limitations below, permission is hereby granted by XMOS LIMITED (“XMOS”), free of charge, to any person or entity obtaining a copy of the XMOS Software. + +**1. Definitions** + +**“Applicable Patent Rights”** means: (a) where XMOS is the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to XMOS and (ii) that cover subject matter contained in the Software, but only to the extent it is necessary to use, reproduce or distribute the Software without infringement; and (b) where you are the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to you and (ii) that cover the subject matter contained in your Derivatives, taken alone or in combination with the Software. + +**“Compiled Code”** means any compiled, binary, machine readable or executable version of the Source Code. + +**“Contributor”** means any person or entity that creates or contributes to the creation of Derivatives. + +**“Derivatives”** means any addition to, deletion from and/or change to the substance, structure of the Software, any previous Derivatives, the combination of the Derivatives and the Software and/or any respective portions thereof. + +**“Source Code”** means the human readable code that is suitable for making modifications but excluding any Compiled Code. + +**“Software”** means the software and associated documentation files which XMOS makes available and which contain a notice identifying the software as original XMOS software and referring to the software being subject to the terms of this XMOS Public Licence. + +This Licence refers to XMOS Software and does not relate to any XMOS hardware or devices which are protected by intellectual property rights (including patent and trade marks) which may be sold to you under a separate agreement. + + +**2. Licence** + +**Permitted Uses, Conditions and Restrictions.** Subject to the conditions below, XMOS grants you a worldwide, royalty free, non-exclusive licence, to the extent of any Patent Rights to do the following: + +2.1 **Unmodified Software.** You may use, copy, display, publish, distribute and make available unmodified copies of the Software: + +2.1.1 for personal or academic, non-commercial purposes; or + +2.1.2 for commercial purposes provided the Software is at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.1.1 and 2.1.2): + +(a) you must retain and reproduce in all copies of the Software the copyright and proprietary notices and disclaimers of XMOS as they appear in the Software, and keep intact all notices and disclaimers in the Software files that refer to this Licence; and + +(b) you must include a copy of this Licence with every copy of the Software and documentation you publish, distribute and make available and you may not offer or impose any terms on such Software that alter or restrict this Licence or the intent of such Licence, except as permitted below (Additional Terms). + +The licence above does not include any Compiled Code which XMOS may make available under a separate support and licence agreement. + +2.2 **Derivatives.** You may create and modify Derivatives and use, copy, display, publish, distribute and make available Derivatives: + +2.2.1 for personal or academic, non-commercial purposes; or + +2.2.2 for commercial purposes, provided the Derivatives are at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.2.1 and 2.2.2): + +(a) you must comply with the terms of clause 2.1 with respect to the Derivatives; + +(b) you must copy (to the extent it doesn’t already exist) the notice below in each file of the Derivatives, and ensure all the modified files carry prominent notices stating that you have changed the files and the date of any change; and + +(c) if you sublicence, distribute or otherwise make the Software and/or the Derivatives available for commercial purposes, you must provide that the Software and Derivatives are at all times used on a device designed, licensed or developed by XMOS. + +Without limitation to these terms and clause 3 below, the Source Code and Compiled Code to your Derivatives may at your discretion (but without obligation) be released, copied, displayed, published, distributed and made available; and if you elect to do so, it must be under the terms of this Licence including the terms of the licence at clauses 2.2.1, 2.2.2 and clause 3 below. + +2.3 **Distribution of Executable Versions.** If you distribute or make available Derivatives, you must include a prominent notice in the code itself as well as in all related documentation, stating that the Source Code of the Software from which the Derivatives are based is available under the terms of this Licence, with information on how and where to obtain such Source Code. + +**3. Your Grant of Rights.** In consideration and as a condition to this Licence, you grant to any person or entity receiving or distributing any Derivatives, a non-exclusive, royalty free, perpetual, irrevocable license under your Applicable Patent Rights and all other intellectual property rights owned or controlled by you, to use, copy, display, publish, distribute and make available your Derivatives of the same scope and extent as XMOS’s licence under clause 2.2 above. + +**4. Combined Products.** You may create a combined product by combining Software, Derivatives and other code not covered by this Licence as a single application or product. In such instance, you must comply with the requirements of this Licence for any portion of the Software and/or Derivatives. + +**5. Additional Terms.** You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations and/or other rights consistent with the term of this Licence (“Additional Terms”) to any legitimate recipients of the Software and/or Derivatives. The terms on which you provide such Additional Terms are on your sole responsibility and you shall indemnify, defend and hold XMOS harmless against any claims asserted against XMOS. + +**6. New Versions.** XMOS may publish revised and/or new versions of this Licence from time to time to accommodate changes to the Licence terms, new versions, updates and bug fixes of the Software. Each version will be given a distinguishing version number. Once Software has been published under a particular version of this Licence, you may continue to use it under the terms of that version. You may also choose to use the latest version of the Software under any subsequent version published by XMOS. Only XMOS shall have the right to modify these terms. + +**7. IPR and Ownership** +Any rights, including all intellectual property rights and all trademarks not expressly granted herein are reserved in full by the authors or copyright holders. Any requests for additional permissions by XMOS including any rights to use XMOS trademarks, should be made (without obligation) to XMOS at **support@xmos.com** + +Nothing herein shall limit any rights that XMOS is otherwise entitled to under the doctrines of patent exhaustion, implied license, or legal estoppel. Neither the name of the authors, the copyright holders or any contributors may be used to endorse or promote any Derivatives from this Software without specific written permission. Any attempt to deal with the Software which does not comply with this Licence shall be void and shall automatically terminate any rights granted under this licence (including any licence of any intellectual property rights granted herein). +Subject to the licences granted under this Licence any Contributor retains all rights, title and interest in and to any Derivatives made by Contributor subject to the underlying rights of XMOS in the Software. XMOS shall retain all rights, title and interest in the Software and any Derivatives made by XMOS (“XMOS Derivatives”). XMOS Derivatives will not automatically be subject to this Licence and XMOS shall be entitled to licence such rights on any terms (without obligation) as it sees fit. + +**8. Termination** + +8.1 This Licence will automatically terminate immediately, without notice to you, if: + +(a) you fail to comply with the terms of this Licence; and/or + +(b) you directly or indirectly commence any action for patent or intellectual property right infringement against XMOS, or any parent, group, affiliate or subsidiary of XMOS; provided XMOS did not first commence an action or patent infringement against you in that instance; and/or + +(c) the terms of this Licence are held by any court of competent jurisdiction to be unenforceable in whole or in part. + +**9. Critical Applications.** Unless XMOS has agreed in writing with you an agreement specifically governing use of the Goods in military, aerospace, automotive or medically related functions (collectively and individually hereinafter referred to as "Special Use"), any permitted use of the Software excludes Special Use. Notwithstanding any agreement between XMOS and you for Special Use, Special Use shall be at your own risk, and you shall fully indemnify XMOS against any damages, losses, costs and claims (direct and indirect) arising out of any Special Use. + +**10. NO WARRANTY OR SUPPORT.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL XMOS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, WARRANTY, CIVIL TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE INCLUDING GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES EVEN IF SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND NOT WITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE. IN SOME JURISDICTIONS PARTIES ARE UNABLE TO LIMIT LIABILTY IN THIS WAY, IF THIS APPLIES TO YOUR JURISDICTION THIS LIABILITY CLAUSE ABOVE MAY NOT APPLY. NOTWITHSTANDING THE ABOVE, IN NO EVENT SHALL XMOS’s TOTAL LIABILITY TO YOU FOR ALL DAMAGES, LOSS OR OTHERWISE EXCEED $50. + +**11. Governing Law and Jurisdiction.** This Licence constitutes the entire agreement between the parties with respect to the subject matter hereof. The Licence shall be governed by the laws of England and the conflict of laws and UN Convention on Contracts for the International Sale of Goods, shall not apply. diff --git a/examples/AN00247_xua_example_spdif_tx/LICENSE.txt b/examples/AN00247_xua_example_spdif_tx/LICENSE.txt deleted file mode 100644 index 236b6d1a..00000000 --- a/examples/AN00247_xua_example_spdif_tx/LICENSE.txt +++ /dev/null @@ -1,135 +0,0 @@ -Software Release License Agreement - -Copyright (c) 2018, XMOS, All rights reserved. - -BY ACCESSING, USING, INSTALLING OR DOWNLOADING THE XMOS SOFTWARE, YOU AGREE TO BE BOUND BY THE FOLLOWING TERMS. IF YOU DO NOT AGREE TO THESE, DO NOT ATTEMPT TO DOWNLOAD, ACCESS OR USE THE XMOS Software. - -Parties: - -(1) XMOS Limited, incorporated and registered in England and Wales with company number 5494985 whose registered office is 107 Cheapside, London, EC2V 6DN (XMOS). - -(2) An individual or legal entity exercising permissions granted by this License (Customer). - -If you are entering into this Agreement on behalf of another legal entity such as a company, partnership, university, college etc. (for example, as an employee, student or consultant), you warrant that you have authority to bind that entity. - -1. Definitions - -"License" means this Software License and any schedules or annexes to it. - -"License Fee" means the fee for the XMOS Software as detailed in any schedules or annexes to this Software License - -"Licensee Modifications" means all developments and modifications of the XMOS Software developed independently by the Customer. - -"XMOS Modifications" means all developments and modifications of the XMOS Software developed or co-developed by XMOS. - -"XMOS Hardware" means any XMOS hardware devices supplied by XMOS from time to time and/or the particular XMOS devices detailed in any schedules or annexes to this Software License. - -"XMOS Software" comprises the XMOS owned circuit designs, schematics, source code, object code, reference designs, (including related programmer comments and documentation, if any), error corrections, improvements, modifications (including XMOS Modifications) and updates. - -The headings in this License do not affect its interpretation. Save where the context otherwise requires, references to clauses and schedules are to clauses and schedules of this License. - -Unless the context otherwise requires: - -- references to XMOS and the Customer include their permitted successors and assigns; -- references to statutory provisions include those statutory provisions as amended or re-enacted; and -- references to any gender include all genders. - -Words in the singular include the plural and in the plural include the singular. - -2. License - -XMOS grants the Customer a non-exclusive license to use, develop, modify and distribute the XMOS Software with, or for the purpose of being used with, XMOS Hardware. - -Open Source Software (OSS) must be used and dealt with in accordance with any license terms under which OSS is distributed. - -3. Consideration - -In consideration of the mutual obligations contained in this License, the parties agree to its terms. - -4. Term - -Subject to clause 12 below, this License shall be perpetual. - -5. Restrictions on Use - -The Customer will adhere to all applicable import and export laws and regulations of the country in which it resides and of the United States and United Kingdom, without limitation. The Customer agrees that it is its responsibility to obtain copies of and to familiarise itself fully with these laws and regulations to avoid violation. - -6. Modifications - -The Customer will own all intellectual property rights in the Licensee Modifications but will undertake to provide XMOS with any fixes made to correct any bugs found in the XMOS Software on a non-exclusive, perpetual and royalty free license basis. - -XMOS will own all intellectual property rights in the XMOS Modifications. -The Customer may only use the Licensee Modifications and XMOS Modifications on, or in relation to, XMOS Hardware. - -7. Support - -Support of the XMOS Software may be provided by XMOS pursuant to a separate support agreement. - -8. Warranty and Disclaimer - -The XMOS Software is provided "AS IS" without a warranty of any kind. XMOS and its licensors' entire liability and Customer's exclusive remedy under this warranty to be determined in XMOS's sole and absolute discretion, will be either (a) the corrections of defects in media or replacement of the media, or (b) the refund of the license fee paid (if any). - -Whilst XMOS gives the Customer the ability to load their own software and applications onto XMOS devices, the security of such software and applications when on the XMOS devices is the Customer's own responsibility and any breach of security shall not be deemed a defect or failure of the hardware. XMOS shall have no liability whatsoever in relation to any costs, damages or other losses Customer may incur as a result of any breaches of security in relation to your software or applications. - -XMOS AND ITS LICENSORS DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY/ SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID UNDER APPLICABLE LAW. - -9. High Risk Activities - -The XMOS Software is not designed or intended for use in conjunction with on-line control equipment in hazardous environments requiring fail-safe performance, including without limitation the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, life support machines, or weapons systems (collectively "High Risk Activities") in which the failure of the XMOS Software could lead directly to death, personal injury, or severe physical or environmental damage. XMOS and its licensors specifically disclaim any express or implied warranties relating to use of the XMOS Software in connection with High Risk Activities. - -10. Liability - -TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, NEITHER XMOS NOR ITS LICENSORS SHALL BE LIABLE FOR ANY LOST REVENUE, BUSINESS, PROFIT, CONTRACTS OR DATA, ADMINISTRATIVE OR OVERHEAD EXPENSES, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THEORY OF LIABILITY ARISING OUT OF THIS LICENSE, EVEN IF XMOS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event shall XMOS's liability to the Customer whether in contract, tort (including negligence), or otherwise exceed the License Fee. - -Customer agrees to indemnify, hold harmless, and defend XMOS and its licensors from and against any claims or lawsuits, including attorneys' fees and any other liabilities, demands, proceedings, damages, losses, costs, expenses fines and charges which are made or brought against or incurred by XMOS as a result of your use or distribution of the Licensee Modifications or your use or distribution of XMOS Software, or any development of it, other than in accordance with the terms of this License. - -11. Ownership - -The copyrights and all other intellectual and industrial property rights for the protection of information with respect to the XMOS Software (including the methods and techniques on which they are based) are retained by XMOS and/or its licensors. Nothing in this Agreement serves to transfer such rights. Customer may not sell, mortgage, underlet, sublease, sublicense, lend or transfer possession of the XMOS Software in any way whatsoever to any third party who is not bound by this Agreement. - -12. Termination - -Either party may terminate this License at any time on written notice to the other if the other: - -- is in material or persistent breach of any of the terms of this License and either that breach is incapable of remedy, or the other party fails to remedy that breach within 30 days after receiving written notice requiring it to remedy that breach; or - -- is unable to pay its debts (within the meaning of section 123 of the Insolvency Act 1986), or becomes insolvent, or is subject to an order or a resolution for its liquidation, administration, winding-up or dissolution (otherwise than for the purposes of a solvent amalgamation or reconstruction), or has an administrative or other receiver, manager, trustee, liquidator, administrator or similar officer appointed over all or any substantial part of its assets, or enters into or proposes any composition or arrangement with its creditors generally, or is subject to any analogous event or proceeding in any applicable jurisdiction. - -Termination by either party in accordance with the rights contained in clause 12 shall be without prejudice to any other rights or remedies of that party accrued prior to termination. - -On termination for any reason: - -- all rights granted to the Customer under this License shall cease; -- the Customer shall cease all activities authorised by this License; -- the Customer shall immediately pay any sums due to XMOS under this License; and -- the Customer shall immediately destroy or return to the XMOS (at the XMOS's option) all copies of the XMOS Software then in its possession, custody or control and, in the case of destruction, certify to XMOS that it has done so. - -Clauses 5, 8, 9, 10 and 11 shall survive any effective termination of this Agreement. - -13. Third party rights - -No term of this License is intended to confer a benefit on, or to be enforceable by, any person who is not a party to this license. - -14. Confidentiality and publicity - -Each party shall, during the term of this License and thereafter, keep confidential all, and shall not use for its own purposes nor without the prior written consent of the other disclose to any third party any, information of a confidential nature (including, without limitation, trade secrets and information of commercial value) which may become known to such party from the other party and which relates to the other party, unless such information is public knowledge or already known to such party at the time of disclosure, or subsequently becomes public knowledge other than by breach of this license, or subsequently comes lawfully into the possession of such party from a third party. - -The terms of this license are confidential and may not be disclosed by the Customer without the prior written consent of XMOS. -The provisions of clause 14 shall remain in full force and effect notwithstanding termination of this license for any reason. - -15. Entire agreement - -This License and the documents annexed as appendices to this License or otherwise referred to herein contain the whole agreement between the parties relating to the subject matter hereof and supersede all prior agreements, arrangements and understandings between the parties relating to that subject matter. - -16. Assignment - -The Customer shall not assign this License or any of the rights granted under it without XMOS's prior written consent. - -17. Governing law and jurisdiction - -This License shall be governed by and construed in accordance with English law and each party hereby submits to the non-exclusive jurisdiction of the English courts. - -This License has been entered into on the date stated at the beginning of it. - -Schedule -XMOS application note AN00247 software diff --git a/examples/AN00247_xua_example_spdif_tx/README.rst b/examples/AN00247_xua_example_spdif_tx/README.rst index 2026272a..509e5fee 100644 --- a/examples/AN00247_xua_example_spdif_tx/README.rst +++ b/examples/AN00247_xua_example_spdif_tx/README.rst @@ -2,15 +2,13 @@ Using lib_xua with lib_spdif (transmit) ======================================= -.. version:: 0.1.0 - Summary ------- -Required tools and libraries -............................ +Software dependencies +..................... -.. appdeps:: +For a list of direct dependencies, look for USED_MODULES in the Makefile. Required hardware ................. diff --git a/examples/AN00247_xua_example_spdif_tx/src/app_xua_simple.xc b/examples/AN00247_xua_example_spdif_tx/src/app_xua_simple.xc index 9c9e3703..704479b8 100644 --- a/examples/AN00247_xua_example_spdif_tx/src/app_xua_simple.xc +++ b/examples/AN00247_xua_example_spdif_tx/src/app_xua_simple.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /* A very simple *example* of a USB audio application (and as such is un-verified for production) * diff --git a/examples/AN00247_xua_example_spdif_tx/src/hwsupport.xc b/examples/AN00247_xua_example_spdif_tx/src/hwsupport.xc index 33fc5bca..203fa38e 100644 --- a/examples/AN00247_xua_example_spdif_tx/src/hwsupport.xc +++ b/examples/AN00247_xua_example_spdif_tx/src/hwsupport.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include diff --git a/examples/AN00247_xua_example_spdif_tx/src/xua_conf.h b/examples/AN00247_xua_example_spdif_tx/src/xua_conf.h index d83f5a2e..8fee8c82 100644 --- a/examples/AN00247_xua_example_spdif_tx/src/xua_conf.h +++ b/examples/AN00247_xua_example_spdif_tx/src/xua_conf.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _XUA_CONF_H_ #define _XUA_CONF_H_ @@ -26,5 +27,6 @@ #define AUDIO_CLASS_FALLBACK 0 #define BCD_DEVICE 0x1234 #define XUA_DFU_EN 0 +#define MIC_DUAL_ENABLED 0 // Use multi-threaded design #endif diff --git a/examples/AN00247_xua_example_spdif_tx/src/xud_conf.h b/examples/AN00247_xua_example_spdif_tx/src/xud_conf.h index c14d64a8..3fc13baf 100644 --- a/examples/AN00247_xua_example_spdif_tx/src/xud_conf.h +++ b/examples/AN00247_xua_example_spdif_tx/src/xud_conf.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua_conf.h" diff --git a/examples/AN00248_xua_example_pdm_mics/LICENSE.rst b/examples/AN00248_xua_example_pdm_mics/LICENSE.rst new file mode 100644 index 00000000..ca48f20f --- /dev/null +++ b/examples/AN00248_xua_example_pdm_mics/LICENSE.rst @@ -0,0 +1,84 @@ +******************************* +XMOS PUBLIC LICENCE: Version 1 +******************************* + +Subject to the conditions and limitations below, permission is hereby granted by XMOS LIMITED (“XMOS”), free of charge, to any person or entity obtaining a copy of the XMOS Software. + +**1. Definitions** + +**“Applicable Patent Rights”** means: (a) where XMOS is the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to XMOS and (ii) that cover subject matter contained in the Software, but only to the extent it is necessary to use, reproduce or distribute the Software without infringement; and (b) where you are the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to you and (ii) that cover the subject matter contained in your Derivatives, taken alone or in combination with the Software. + +**“Compiled Code”** means any compiled, binary, machine readable or executable version of the Source Code. + +**“Contributor”** means any person or entity that creates or contributes to the creation of Derivatives. + +**“Derivatives”** means any addition to, deletion from and/or change to the substance, structure of the Software, any previous Derivatives, the combination of the Derivatives and the Software and/or any respective portions thereof. + +**“Source Code”** means the human readable code that is suitable for making modifications but excluding any Compiled Code. + +**“Software”** means the software and associated documentation files which XMOS makes available and which contain a notice identifying the software as original XMOS software and referring to the software being subject to the terms of this XMOS Public Licence. + +This Licence refers to XMOS Software and does not relate to any XMOS hardware or devices which are protected by intellectual property rights (including patent and trade marks) which may be sold to you under a separate agreement. + + +**2. Licence** + +**Permitted Uses, Conditions and Restrictions.** Subject to the conditions below, XMOS grants you a worldwide, royalty free, non-exclusive licence, to the extent of any Patent Rights to do the following: + +2.1 **Unmodified Software.** You may use, copy, display, publish, distribute and make available unmodified copies of the Software: + +2.1.1 for personal or academic, non-commercial purposes; or + +2.1.2 for commercial purposes provided the Software is at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.1.1 and 2.1.2): + +(a) you must retain and reproduce in all copies of the Software the copyright and proprietary notices and disclaimers of XMOS as they appear in the Software, and keep intact all notices and disclaimers in the Software files that refer to this Licence; and + +(b) you must include a copy of this Licence with every copy of the Software and documentation you publish, distribute and make available and you may not offer or impose any terms on such Software that alter or restrict this Licence or the intent of such Licence, except as permitted below (Additional Terms). + +The licence above does not include any Compiled Code which XMOS may make available under a separate support and licence agreement. + +2.2 **Derivatives.** You may create and modify Derivatives and use, copy, display, publish, distribute and make available Derivatives: + +2.2.1 for personal or academic, non-commercial purposes; or + +2.2.2 for commercial purposes, provided the Derivatives are at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.2.1 and 2.2.2): + +(a) you must comply with the terms of clause 2.1 with respect to the Derivatives; + +(b) you must copy (to the extent it doesn’t already exist) the notice below in each file of the Derivatives, and ensure all the modified files carry prominent notices stating that you have changed the files and the date of any change; and + +(c) if you sublicence, distribute or otherwise make the Software and/or the Derivatives available for commercial purposes, you must provide that the Software and Derivatives are at all times used on a device designed, licensed or developed by XMOS. + +Without limitation to these terms and clause 3 below, the Source Code and Compiled Code to your Derivatives may at your discretion (but without obligation) be released, copied, displayed, published, distributed and made available; and if you elect to do so, it must be under the terms of this Licence including the terms of the licence at clauses 2.2.1, 2.2.2 and clause 3 below. + +2.3 **Distribution of Executable Versions.** If you distribute or make available Derivatives, you must include a prominent notice in the code itself as well as in all related documentation, stating that the Source Code of the Software from which the Derivatives are based is available under the terms of this Licence, with information on how and where to obtain such Source Code. + +**3. Your Grant of Rights.** In consideration and as a condition to this Licence, you grant to any person or entity receiving or distributing any Derivatives, a non-exclusive, royalty free, perpetual, irrevocable license under your Applicable Patent Rights and all other intellectual property rights owned or controlled by you, to use, copy, display, publish, distribute and make available your Derivatives of the same scope and extent as XMOS’s licence under clause 2.2 above. + +**4. Combined Products.** You may create a combined product by combining Software, Derivatives and other code not covered by this Licence as a single application or product. In such instance, you must comply with the requirements of this Licence for any portion of the Software and/or Derivatives. + +**5. Additional Terms.** You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations and/or other rights consistent with the term of this Licence (“Additional Terms”) to any legitimate recipients of the Software and/or Derivatives. The terms on which you provide such Additional Terms are on your sole responsibility and you shall indemnify, defend and hold XMOS harmless against any claims asserted against XMOS. + +**6. New Versions.** XMOS may publish revised and/or new versions of this Licence from time to time to accommodate changes to the Licence terms, new versions, updates and bug fixes of the Software. Each version will be given a distinguishing version number. Once Software has been published under a particular version of this Licence, you may continue to use it under the terms of that version. You may also choose to use the latest version of the Software under any subsequent version published by XMOS. Only XMOS shall have the right to modify these terms. + +**7. IPR and Ownership** +Any rights, including all intellectual property rights and all trademarks not expressly granted herein are reserved in full by the authors or copyright holders. Any requests for additional permissions by XMOS including any rights to use XMOS trademarks, should be made (without obligation) to XMOS at **support@xmos.com** + +Nothing herein shall limit any rights that XMOS is otherwise entitled to under the doctrines of patent exhaustion, implied license, or legal estoppel. Neither the name of the authors, the copyright holders or any contributors may be used to endorse or promote any Derivatives from this Software without specific written permission. Any attempt to deal with the Software which does not comply with this Licence shall be void and shall automatically terminate any rights granted under this licence (including any licence of any intellectual property rights granted herein). +Subject to the licences granted under this Licence any Contributor retains all rights, title and interest in and to any Derivatives made by Contributor subject to the underlying rights of XMOS in the Software. XMOS shall retain all rights, title and interest in the Software and any Derivatives made by XMOS (“XMOS Derivatives”). XMOS Derivatives will not automatically be subject to this Licence and XMOS shall be entitled to licence such rights on any terms (without obligation) as it sees fit. + +**8. Termination** + +8.1 This Licence will automatically terminate immediately, without notice to you, if: + +(a) you fail to comply with the terms of this Licence; and/or + +(b) you directly or indirectly commence any action for patent or intellectual property right infringement against XMOS, or any parent, group, affiliate or subsidiary of XMOS; provided XMOS did not first commence an action or patent infringement against you in that instance; and/or + +(c) the terms of this Licence are held by any court of competent jurisdiction to be unenforceable in whole or in part. + +**9. Critical Applications.** Unless XMOS has agreed in writing with you an agreement specifically governing use of the Goods in military, aerospace, automotive or medically related functions (collectively and individually hereinafter referred to as "Special Use"), any permitted use of the Software excludes Special Use. Notwithstanding any agreement between XMOS and you for Special Use, Special Use shall be at your own risk, and you shall fully indemnify XMOS against any damages, losses, costs and claims (direct and indirect) arising out of any Special Use. + +**10. NO WARRANTY OR SUPPORT.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL XMOS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, WARRANTY, CIVIL TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE INCLUDING GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES EVEN IF SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND NOT WITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE. IN SOME JURISDICTIONS PARTIES ARE UNABLE TO LIMIT LIABILTY IN THIS WAY, IF THIS APPLIES TO YOUR JURISDICTION THIS LIABILITY CLAUSE ABOVE MAY NOT APPLY. NOTWITHSTANDING THE ABOVE, IN NO EVENT SHALL XMOS’s TOTAL LIABILITY TO YOU FOR ALL DAMAGES, LOSS OR OTHERWISE EXCEED $50. + +**11. Governing Law and Jurisdiction.** This Licence constitutes the entire agreement between the parties with respect to the subject matter hereof. The Licence shall be governed by the laws of England and the conflict of laws and UN Convention on Contracts for the International Sale of Goods, shall not apply. diff --git a/examples/AN00248_xua_example_pdm_mics/LICENSE.txt b/examples/AN00248_xua_example_pdm_mics/LICENSE.txt deleted file mode 100644 index dd731b32..00000000 --- a/examples/AN00248_xua_example_pdm_mics/LICENSE.txt +++ /dev/null @@ -1,135 +0,0 @@ -Software Release License Agreement - -Copyright (c) 2018, XMOS, All rights reserved. - -BY ACCESSING, USING, INSTALLING OR DOWNLOADING THE XMOS SOFTWARE, YOU AGREE TO BE BOUND BY THE FOLLOWING TERMS. IF YOU DO NOT AGREE TO THESE, DO NOT ATTEMPT TO DOWNLOAD, ACCESS OR USE THE XMOS Software. - -Parties: - -(1) XMOS Limited, incorporated and registered in England and Wales with company number 5494985 whose registered office is 107 Cheapside, London, EC2V 6DN (XMOS). - -(2) An individual or legal entity exercising permissions granted by this License (Customer). - -If you are entering into this Agreement on behalf of another legal entity such as a company, partnership, university, college etc. (for example, as an employee, student or consultant), you warrant that you have authority to bind that entity. - -1. Definitions - -"License" means this Software License and any schedules or annexes to it. - -"License Fee" means the fee for the XMOS Software as detailed in any schedules or annexes to this Software License - -"Licensee Modifications" means all developments and modifications of the XMOS Software developed independently by the Customer. - -"XMOS Modifications" means all developments and modifications of the XMOS Software developed or co-developed by XMOS. - -"XMOS Hardware" means any XMOS hardware devices supplied by XMOS from time to time and/or the particular XMOS devices detailed in any schedules or annexes to this Software License. - -"XMOS Software" comprises the XMOS owned circuit designs, schematics, source code, object code, reference designs, (including related programmer comments and documentation, if any), error corrections, improvements, modifications (including XMOS Modifications) and updates. - -The headings in this License do not affect its interpretation. Save where the context otherwise requires, references to clauses and schedules are to clauses and schedules of this License. - -Unless the context otherwise requires: - -- references to XMOS and the Customer include their permitted successors and assigns; -- references to statutory provisions include those statutory provisions as amended or re-enacted; and -- references to any gender include all genders. - -Words in the singular include the plural and in the plural include the singular. - -2. License - -XMOS grants the Customer a non-exclusive license to use, develop, modify and distribute the XMOS Software with, or for the purpose of being used with, XMOS Hardware. - -Open Source Software (OSS) must be used and dealt with in accordance with any license terms under which OSS is distributed. - -3. Consideration - -In consideration of the mutual obligations contained in this License, the parties agree to its terms. - -4. Term - -Subject to clause 12 below, this License shall be perpetual. - -5. Restrictions on Use - -The Customer will adhere to all applicable import and export laws and regulations of the country in which it resides and of the United States and United Kingdom, without limitation. The Customer agrees that it is its responsibility to obtain copies of and to familiarise itself fully with these laws and regulations to avoid violation. - -6. Modifications - -The Customer will own all intellectual property rights in the Licensee Modifications but will undertake to provide XMOS with any fixes made to correct any bugs found in the XMOS Software on a non-exclusive, perpetual and royalty free license basis. - -XMOS will own all intellectual property rights in the XMOS Modifications. -The Customer may only use the Licensee Modifications and XMOS Modifications on, or in relation to, XMOS Hardware. - -7. Support - -Support of the XMOS Software may be provided by XMOS pursuant to a separate support agreement. - -8. Warranty and Disclaimer - -The XMOS Software is provided "AS IS" without a warranty of any kind. XMOS and its licensors' entire liability and Customer's exclusive remedy under this warranty to be determined in XMOS's sole and absolute discretion, will be either (a) the corrections of defects in media or replacement of the media, or (b) the refund of the license fee paid (if any). - -Whilst XMOS gives the Customer the ability to load their own software and applications onto XMOS devices, the security of such software and applications when on the XMOS devices is the Customer's own responsibility and any breach of security shall not be deemed a defect or failure of the hardware. XMOS shall have no liability whatsoever in relation to any costs, damages or other losses Customer may incur as a result of any breaches of security in relation to your software or applications. - -XMOS AND ITS LICENSORS DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY/ SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID UNDER APPLICABLE LAW. - -9. High Risk Activities - -The XMOS Software is not designed or intended for use in conjunction with on-line control equipment in hazardous environments requiring fail-safe performance, including without limitation the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, life support machines, or weapons systems (collectively "High Risk Activities") in which the failure of the XMOS Software could lead directly to death, personal injury, or severe physical or environmental damage. XMOS and its licensors specifically disclaim any express or implied warranties relating to use of the XMOS Software in connection with High Risk Activities. - -10. Liability - -TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, NEITHER XMOS NOR ITS LICENSORS SHALL BE LIABLE FOR ANY LOST REVENUE, BUSINESS, PROFIT, CONTRACTS OR DATA, ADMINISTRATIVE OR OVERHEAD EXPENSES, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THEORY OF LIABILITY ARISING OUT OF THIS LICENSE, EVEN IF XMOS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event shall XMOS's liability to the Customer whether in contract, tort (including negligence), or otherwise exceed the License Fee. - -Customer agrees to indemnify, hold harmless, and defend XMOS and its licensors from and against any claims or lawsuits, including attorneys' fees and any other liabilities, demands, proceedings, damages, losses, costs, expenses fines and charges which are made or brought against or incurred by XMOS as a result of your use or distribution of the Licensee Modifications or your use or distribution of XMOS Software, or any development of it, other than in accordance with the terms of this License. - -11. Ownership - -The copyrights and all other intellectual and industrial property rights for the protection of information with respect to the XMOS Software (including the methods and techniques on which they are based) are retained by XMOS and/or its licensors. Nothing in this Agreement serves to transfer such rights. Customer may not sell, mortgage, underlet, sublease, sublicense, lend or transfer possession of the XMOS Software in any way whatsoever to any third party who is not bound by this Agreement. - -12. Termination - -Either party may terminate this License at any time on written notice to the other if the other: - -- is in material or persistent breach of any of the terms of this License and either that breach is incapable of remedy, or the other party fails to remedy that breach within 30 days after receiving written notice requiring it to remedy that breach; or - -- is unable to pay its debts (within the meaning of section 123 of the Insolvency Act 1986), or becomes insolvent, or is subject to an order or a resolution for its liquidation, administration, winding-up or dissolution (otherwise than for the purposes of a solvent amalgamation or reconstruction), or has an administrative or other receiver, manager, trustee, liquidator, administrator or similar officer appointed over all or any substantial part of its assets, or enters into or proposes any composition or arrangement with its creditors generally, or is subject to any analogous event or proceeding in any applicable jurisdiction. - -Termination by either party in accordance with the rights contained in clause 12 shall be without prejudice to any other rights or remedies of that party accrued prior to termination. - -On termination for any reason: - -- all rights granted to the Customer under this License shall cease; -- the Customer shall cease all activities authorised by this License; -- the Customer shall immediately pay any sums due to XMOS under this License; and -- the Customer shall immediately destroy or return to the XMOS (at the XMOS's option) all copies of the XMOS Software then in its possession, custody or control and, in the case of destruction, certify to XMOS that it has done so. - -Clauses 5, 8, 9, 10 and 11 shall survive any effective termination of this Agreement. - -13. Third party rights - -No term of this License is intended to confer a benefit on, or to be enforceable by, any person who is not a party to this license. - -14. Confidentiality and publicity - -Each party shall, during the term of this License and thereafter, keep confidential all, and shall not use for its own purposes nor without the prior written consent of the other disclose to any third party any, information of a confidential nature (including, without limitation, trade secrets and information of commercial value) which may become known to such party from the other party and which relates to the other party, unless such information is public knowledge or already known to such party at the time of disclosure, or subsequently becomes public knowledge other than by breach of this license, or subsequently comes lawfully into the possession of such party from a third party. - -The terms of this license are confidential and may not be disclosed by the Customer without the prior written consent of XMOS. -The provisions of clause 14 shall remain in full force and effect notwithstanding termination of this license for any reason. - -15. Entire agreement - -This License and the documents annexed as appendices to this License or otherwise referred to herein contain the whole agreement between the parties relating to the subject matter hereof and supersede all prior agreements, arrangements and understandings between the parties relating to that subject matter. - -16. Assignment - -The Customer shall not assign this License or any of the rights granted under it without XMOS's prior written consent. - -17. Governing law and jurisdiction - -This License shall be governed by and construed in accordance with English law and each party hereby submits to the non-exclusive jurisdiction of the English courts. - -This License has been entered into on the date stated at the beginning of it. - -Schedule -XMOS application note AN00248 software diff --git a/examples/AN00248_xua_example_pdm_mics/README.rst b/examples/AN00248_xua_example_pdm_mics/README.rst index 22e3776e..391cadde 100644 --- a/examples/AN00248_xua_example_pdm_mics/README.rst +++ b/examples/AN00248_xua_example_pdm_mics/README.rst @@ -2,18 +2,16 @@ Using lib_xua with lib_mic_array ================================ -.. version:: 0.1.0 - Summary ------- This applicaition note describes how to use ``lib_mic_array`` in conjunction with ``lib_xua`` to implement a USB Audio device with the ability to record from multiple PDM microphones. -Required tools and libraries -............................ +Software dependencies +..................... -.. appdeps:: +For a list of direct dependencies, look for USED_MODULES in the Makefile. Required hardware ................. diff --git a/examples/AN00248_xua_example_pdm_mics/src/app_xua_simple.xc b/examples/AN00248_xua_example_pdm_mics/src/app_xua_simple.xc index 93ee258d..6b7b299e 100644 --- a/examples/AN00248_xua_example_pdm_mics/src/app_xua_simple.xc +++ b/examples/AN00248_xua_example_pdm_mics/src/app_xua_simple.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /* A very simple *example* of a USB audio application (and as such is un-verified for production) * diff --git a/examples/AN00248_xua_example_pdm_mics/src/audiohw.xc b/examples/AN00248_xua_example_pdm_mics/src/audiohw.xc index 27325027..288b2d0b 100644 --- a/examples/AN00248_xua_example_pdm_mics/src/audiohw.xc +++ b/examples/AN00248_xua_example_pdm_mics/src/audiohw.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include diff --git a/examples/AN00248_xua_example_pdm_mics/src/xua_conf.h b/examples/AN00248_xua_example_pdm_mics/src/xua_conf.h index 8cdf256e..191d8953 100644 --- a/examples/AN00248_xua_example_pdm_mics/src/xua_conf.h +++ b/examples/AN00248_xua_example_pdm_mics/src/xua_conf.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _XUA_CONF_H_ #define _XUA_CONF_H_ @@ -25,5 +26,6 @@ #define AUDIO_CLASS_FALLBACK 0 #define BCD_DEVICE 0x1234 #define XUA_DFU_EN 0 +#define MIC_DUAL_ENABLED 0 // Use multi-threaded design #endif diff --git a/examples/AN00248_xua_example_pdm_mics/src/xud_conf.h b/examples/AN00248_xua_example_pdm_mics/src/xud_conf.h index c14d64a8..3fc13baf 100644 --- a/examples/AN00248_xua_example_pdm_mics/src/xud_conf.h +++ b/examples/AN00248_xua_example_pdm_mics/src/xud_conf.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua_conf.h" diff --git a/examples/xua_lite_example/Makefile b/examples/xua_lite_example/Makefile deleted file mode 100644 index daa7dc5f..00000000 --- a/examples/xua_lite_example/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -APP_NAME = - -TARGET = RPI_HAT_60QFN.xn - -# The flags passed to xcc when building the application -XCC_FLAGS = -fcomment-asm -Xmapper --map -Xmapper MAPFILE -Os -report \ - -g -Wno-unused-function -Wno-timing -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[1] \ - -D MIC_ARRAY_CH0=PIN0 -D MIC_ARRAY_CH1=PIN4 - -# The USED_MODULES variable lists other module used by the application. These -# modules will extend the SOURCE_DIRS, INCLUDE_DIRS and LIB_DIRS variables. -# Modules are expected to be in the directory above the BASE_DIR directory. -USED_MODULES = lib_xua lib_i2s lib_xud lib_i2c lib_mic_array - -#============================================================================= -# The following part of the Makefile includes the common build infrastructure -# for compiling XMOS applications. You should not need to edit below here. - -XMOS_MAKE_PATH ?= ../.. -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common - diff --git a/examples/xua_lite_example/config.xscope b/examples/xua_lite_example/config.xscope deleted file mode 100644 index f336ddac..00000000 --- a/examples/xua_lite_example/config.xscope +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/examples/xua_lite_example/config/RPI_HAT_60QFN.xn b/examples/xua_lite_example/config/RPI_HAT_60QFN.xn deleted file mode 100644 index c0c3f85c..00000000 --- a/examples/xua_lite_example/config/RPI_HAT_60QFN.xn +++ /dev/null @@ -1,66 +0,0 @@ - - - Device - XVF3510 Device - - - tileref tile[2] - tileref usb_tile - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/xua_lite_example/config/xua_conf.h b/examples/xua_lite_example/config/xua_conf.h deleted file mode 100644 index ae9de112..00000000 --- a/examples/xua_lite_example/config/xua_conf.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved - -#ifndef _XUA_CONF_H_ -#define _XUA_CONF_H_ - -#define NUM_USB_CHAN_OUT 2 /* Number of channels from host to device */ -#define NUM_USB_CHAN_IN 2 /* Number of channels from device to host */ -#define I2S_CHANS_DAC 2 /* Number of I2S channels out of xCORE */ -#define I2S_CHANS_ADC 2 /* Number of I2S channels in to xCORE */ -#define MCLK_441 (512 * 44100) /* 44.1kHz family master clock frequency */ -#define MCLK_48 (512 * 48000) /* 48kHz family master clock frequency */ -#define MIN_FREQ 48000 /* Minimum sample rate */ -#define MAX_FREQ 48000 /* Maximum sample rate */ - -#define EXCLUDE_USB_AUDIO_MAIN - -#define VENDOR_STR "XMOS" -#define VENDOR_ID 0x20B1 -#define PRODUCT_STR_A2 "XUA Lite Class 2" -#define PRODUCT_STR_A1 "XUA Lite Class 1" -#define PID_AUDIO_1 1 -#define PID_AUDIO_2 2 -#define XUA_DFU_EN 0 /* Disable DFU (for simplicity of example) */ - -#define INPUT_FORMAT_COUNT 1 -#define STREAM_FORMAT_INPUT_1_RESOLUTION_BITS 16 -#define OUTPUT_FORMAT_COUNT 1 -#define STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS 16 - -#define OUTPUT_VOLUME_CONTROL 0 -#define INPUT_VOLUME_CONTROL 0 - -#define UAC_FORCE_FEEDBACK_EP 0 -#define XUA_ADAPTIVE 1 -#define XUA_LITE 1 // Use simple/optimised USB buffer tasks -#define AUDIO_CLASS 1 - -#define XUA_NUM_PDM_MICS 4 // It's actually 2 but we run 4ch and ignore 2 -#define PDM_MAX_DECIMATION (96000/(MIN_FREQ)) - -#endif diff --git a/examples/xua_lite_example/config/xud_conf.h b/examples/xua_lite_example/config/xud_conf.h deleted file mode 100644 index c14d64a8..00000000 --- a/examples/xua_lite_example/config/xud_conf.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved - -#include "xua_conf.h" - -/* TODO */ -#define XUD_UAC_NUM_USB_CHAN_OUT NUM_USB_CHAN_OUT -#define XUD_UAC_NUM_USB_CHAN_IN NUM_USB_CHAN_IN diff --git a/examples/xua_lite_example/plot_fill_level.sh b/examples/xua_lite_example/plot_fill_level.sh deleted file mode 100644 index bb2ad5a3..00000000 --- a/examples/xua_lite_example/plot_fill_level.sh +++ /dev/null @@ -1 +0,0 @@ -grep pid: dump.txt | grep -Eo "\-?\d+" > proc.txt && gnuplot -p -e 'set term png; plot "proc.txt" with lines' > plot.png && open plot.png \ No newline at end of file diff --git a/examples/xua_lite_example/src/app_xua_lite.xc b/examples/xua_lite_example/src/app_xua_lite.xc deleted file mode 100644 index 64830667..00000000 --- a/examples/xua_lite_example/src/app_xua_lite.xc +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved - -// A very simple *example* of a USB audio application (and as such is un-verified for production) -#include - -#include -#include - -#include "xua.h" -#include "xud.h" -#include "i2s.h" -#include "i2c.h" -#include "mic_array.h" -#include "xua_buffer_lite.h" -#include "xua_ep0_wrapper.h" -#include "pdm_mic.h" -#include "audio_config.h" -#include "audio_hub.h" - -#define DEBUG_UNIT XUA_APP -#define DEBUG_PRINT_ENABLE_XUA_APP 1 -#include "debug_print.h" - -// Port declarations. Note, the defines come from the xn file -on tile[0]: buffered out port:32 p_i2s_dac[] = {XS1_PORT_1N}; //DAC -on tile[0]: buffered in port:32 p_i2s_adc[] = {XS1_PORT_1F}; //Unused currently -on tile[0]: buffered out port:32 p_lrclk = XS1_PORT_1O; //I2S Bit-clock -on tile[0]: out port p_bclk = XS1_PORT_1P; //I2S L/R-clock - -// Master clock for the audio IO tile -on tile[0]: in port p_mclk_in = XS1_PORT_1K; - -// [0] : DAC_RESET_N -// [1] : I2C_INTERRUPT_N -// [2] : MUTE_EN -// [3] : LED -on tile[0]: out port p_gpio = XS1_PORT_4D; - -on tile[1]: port p_scl = XS1_PORT_1C; -on tile[1]: port p_sda = XS1_PORT_1D; -on tile[1]: in port p_mclk_in_usb = XS1_PORT_1A; -on tile[1]: in port p_for_mclk_count= XS1_PORT_16A; // Extra port for counting master clock ticks -on tile[1]: clock clk_usb_mclk = XS1_CLKBLK_3; // Master clock - -// Clock-block declarations -on tile[0]: clock clk_audio_bclk = XS1_CLKBLK_2; // Bit clock -on tile[0]: clock clk_audio_mclk = XS1_CLKBLK_3; // Master clock -//XUD uses XS1_CLKBLK_4, XS1_CLKBLK_5 on tile[1] - -//Mic array resources -on tile[0]: out port p_pdm_clk = XS1_PORT_1L; -on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_4E; - -on tile[0]: clock pdmclk = XS1_CLKBLK_4; -on tile[0]: clock pdmclk6 = XS1_CLKBLK_5; - - -// Endpoint type tables - informs XUD what the transfer types for each Endpoint in use and also -// if the endpoint wishes to be informed of USB bus resets - -XUD_EpType epTypeTableOut[] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_ISO}; -XUD_EpType epTypeTableIn[] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO}; - -void burn_normal_priority(void){ - while(1); -} - -void burn_high_priority(void){ - set_core_high_priority_on(); - while(1); -} - -int main() -{ - // Channels for lib_xud - chan c_ep_out[XUA_ENDPOINT_COUNT_OUT]; - chan c_ep_in[XUA_ENDPOINT_COUNT_IN]; - - // Channel for communicating SOF notifications from XUD to the Buffering cores - chan c_sof; - - interface i2s_frame_callback_if i_i2s; - interface i2c_master_if i_i2c[1]; - - streaming chan c_audio; //We use the channel buffering (48B across switch each way) - streaming chan c_ds_output[1]; - - interface ep0_control_if i_ep0_ctl; - - par - { - on tile[0]: { - //Set the GPIOs needed for audio (reset and mute) - setup_audio_gpio(p_gpio); - c_audio <: 0; //Signal that we can now do i2c setup - c_audio :> int _; //Now wait until i2c has finished mclk setup - - const unsigned micDiv = MCLK_48/3072000; - mic_array_setup_ddr(pdmclk, pdmclk6, p_mclk_in, p_pdm_clk, p_pdm_mics, micDiv); - - par { - i2s_frame_master(i_i2s, p_i2s_dac, 1, p_i2s_adc, 1, p_bclk, p_lrclk, p_mclk_in, clk_audio_bclk); - [[distribute]] AudioHub(i_i2s, c_audio, c_ds_output); - pdm_mic(c_ds_output[0], p_pdm_mics); - - par (int i = 0; i < 5; i++) burn_normal_priority(); - par (int i = 0; i < 0; i++) burn_high_priority(); - } - } - on tile[1]:unsafe{ - // Connect master-clock input clock-block to clock-block pin for asnch feedback calculation - set_clock_src(clk_usb_mclk, p_mclk_in_usb); // Clock clock-block from mclk pin - set_port_clock(p_for_mclk_count, clk_usb_mclk); // Clock the "count" port from the clock block - start_clock(clk_usb_mclk); // Set the clock off running - - //Setup DAC over i2c and then return so we do not use a thread - c_audio :> int _; //Wait for reset to be asserted/deasserted by other tile - par{ - i2c_master(i_i2c, 1, p_scl, p_sda, 100); - AudioHwConfigure(DEFAULT_FREQ, i_i2c[0]); - } - c_audio <: 0; //Signal to tile[0] that mclk is now good - - par { - // Low level USB device layer core - XUD_Main(c_ep_out, XUA_ENDPOINT_COUNT_OUT, c_ep_in, XUA_ENDPOINT_COUNT_IN, - c_sof, epTypeTableOut, epTypeTableIn, - null, null, -1 , - (AUDIO_CLASS == 1) ? XUD_SPEED_FS : XUD_SPEED_HS, XUD_PWR_BUS); - - // // Buffering core - handles audio and control data to/from EP's and gives/gets data to/from the audio I/O core - // XUA_Buffer_lite(c_ep_out[0], - // c_ep_in[0], - // c_ep_out[1], - // null, //c_ep_in[XUA_ENDPOINT_COUNT_IN - 2],/*feedback*/ - // c_ep_in[XUA_ENDPOINT_COUNT_IN - 1], - // c_sof, p_for_mclk_count, c_audio); - - //[[combine]] - par{ - XUA_Buffer_lite2(i_ep0_ctl, - c_ep_out[1], - null, //c_ep_in[XUA_ENDPOINT_COUNT_IN - 2],/*feedback*/ - c_ep_in[XUA_ENDPOINT_COUNT_IN - 1], - c_sof, p_for_mclk_count, c_audio); - XUA_Endpoint0_select(c_ep_out[0], c_ep_in[0], i_ep0_ctl, null VENDOR_REQUESTS_PARAMS_DEC_); - } - par (int i = 0; i < 3; i++) burn_normal_priority(); - par (int i = 0; i < 2; i++) burn_high_priority(); - } - }//Tile[1] par - }//Top level par - - return 0; -} - - diff --git a/examples/xua_lite_example/src/audio_config.h b/examples/xua_lite_example/src/audio_config.h deleted file mode 100755 index 6b7c079b..00000000 --- a/examples/xua_lite_example/src/audio_config.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _AUDIO_CONFIG_ -#define _AUDIO_CONFIG_ - -void AudioHwConfigure(unsigned samFreq, client i2c_master_if i_i2c); -void pll_nudge(int nudge); -void setup_audio_gpio(out port p_gpio); - -#endif diff --git a/examples/xua_lite_example/src/audio_config.xc b/examples/xua_lite_example/src/audio_config.xc deleted file mode 100755 index 3235387d..00000000 --- a/examples/xua_lite_example/src/audio_config.xc +++ /dev/null @@ -1,279 +0,0 @@ -#include -#include -#include -#include -#include -#include "i2c.h" -#include "xua.h" -#define DEBUG_UNIT AUDIO_CFG -#define DEBUG_PRINT_ENABLE_AUDIO_CFG 1 -#include "debug_print.h" - - -// TLV320DAC3101 Device I2C Address -#define DAC3101_I2C_DEVICE_ADDR 0x18 - -// TLV320DAC3101 Register Addresses -// Page 0 -#define DAC3101_PAGE_CTRL 0x00 // Register 0 - Page Control -#define DAC3101_SW_RST 0x01 // Register 1 - Software Reset -#define DAC3101_CLK_GEN_MUX 0x04 // Register 4 - Clock-Gen Muxing -#define DAC3101_PLL_P_R 0x05 // Register 5 - PLL P and R Values -#define DAC3101_PLL_J 0x06 // Register 6 - PLL J Value -#define DAC3101_PLL_D_MSB 0x07 // Register 7 - PLL D Value (MSB) -#define DAC3101_PLL_D_LSB 0x08 // Register 8 - PLL D Value (LSB) -#define DAC3101_NDAC_VAL 0x0B // Register 11 - NDAC Divider Value -#define DAC3101_MDAC_VAL 0x0C // Register 12 - MDAC Divider Value -#define DAC3101_DOSR_VAL_LSB 0x0E // Register 14 - DOSR Divider Value (LS Byte) -#define DAC3101_CLKOUT_MUX 0x19 // Register 25 - CLKOUT MUX -#define DAC3101_CLKOUT_M_VAL 0x1A // Register 26 - CLKOUT M_VAL -#define DAC3101_CODEC_IF 0x1B // Register 27 - CODEC Interface Control -#define DAC3101_DAC_DAT_PATH 0x3F // Register 63 - DAC Data Path Setup -#define DAC3101_DAC_VOL 0x40 // Register 64 - DAC Vol Control -#define DAC3101_DACL_VOL_D 0x41 // Register 65 - DAC Left Digital Vol Control -#define DAC3101_DACR_VOL_D 0x42 // Register 66 - DAC Right Digital Vol Control -#define DAC3101_GPIO1_IO 0x33 // Register 51 - GPIO1 In/Out Pin Control -// Page 1 -#define DAC3101_HP_DRVR 0x1F // Register 31 - Headphone Drivers -#define DAC3101_SPK_AMP 0x20 // Register 32 - Class-D Speaker Amp -#define DAC3101_HP_DEPOP 0x21 // Register 33 - Headphone Driver De-pop -#define DAC3101_DAC_OP_MIX 0x23 // Register 35 - DAC_L and DAC_R Output Mixer Routing -#define DAC3101_HPL_VOL_A 0x24 // Register 36 - Analog Volume to HPL -#define DAC3101_HPR_VOL_A 0x25 // Register 37 - Analog Volume to HPR -#define DAC3101_SPKL_VOL_A 0x26 // Register 38 - Analog Volume to Left Speaker -#define DAC3101_SPKR_VOL_A 0x27 // Register 39 - Analog Volume to Right Speaker -#define DAC3101_HPL_DRVR 0x28 // Register 40 - Headphone Left Driver -#define DAC3101_HPR_DRVR 0x29 // Register 41 - Headphone Right Driver -#define DAC3101_SPKL_DRVR 0x2A // Register 42 - Left Class-D Speaker Driver -#define DAC3101_SPKR_DRVR 0x2B // Register 43 - Right Class-D Speaker Driver - -// TLV320DAC3101 easy register access defines -#define DAC3101_REGWRITE(reg, val) {i_i2c.write_reg(DAC3101_I2C_DEVICE_ADDR, reg, val);} - - -// Nominal setting is ref div = 25, fb_div = 1024, op_div = 2 -// PCF Freq 0.96MHz - -enum clock_nudge{ - PLL_SLOWER = -1, - PLL_NOMINAL = 0, - PLL_FASTER = 1 -}; - -//These steps provide just under +-0.1% frequency jumps -#define PLL_LOW 0xC003FE18 // This is 3.069MHz -#define PLL_NOM 0xC003FF18 // This is 3.072MHz -#define PLL_HIGH 0xC0040018 // This is 3.075MHz - -on tile[0]: out port p_leds = XS1_PORT_4F; - -//Note use of no_ack write to prevent backpressure. There is enough buffering to -//store both writes so we can move on without blocking -void pll_nudge(int nudge) { - if (nudge > 0){ - write_sswitch_reg_no_ack(get_tile_id(tile[0]), XS1_SSWITCH_PLL_CTL_NUM, PLL_HIGH); - p_leds <: 0x02; //LED B - } - else if (nudge < 0){ - write_sswitch_reg_no_ack(get_tile_id(tile[0]), XS1_SSWITCH_PLL_CTL_NUM, PLL_LOW); - p_leds <: 0x01; //LED A - - } - else { - p_leds <: 0x0; - } - write_sswitch_reg_no_ack(get_tile_id(tile[0]), XS1_SSWITCH_PLL_CTL_NUM, PLL_NOM); -} - -void setup_audio_gpio(out port p_gpio){ - // Reset DAC and disable MUTE - p_gpio <: 0x0; - delay_milliseconds(1); - p_gpio <: 0x1; - delay_milliseconds(1); -} - -void AudioHwConfigure(unsigned samFreq, client i2c_master_if i_i2c) -{ - - // Wait for 2ms because we apply reset for 1ms from other tile - delay_milliseconds(2); - - // Set register page to 0 - DAC3101_REGWRITE(DAC3101_PAGE_CTRL, 0x00); - // Initiate SW reset (PLL is powered off as part of reset) - DAC3101_REGWRITE(DAC3101_SW_RST, 0x01); - - // so I've got 24MHz in to PLL, I want 24.576MHz or 22.5792MHz out. - - // I will always be using fractional-N (D != 0) so we must set R = 1 - // PLL_CLKIN/P must be between 10 and 20MHz so we must set P = 2 - - // PLL_CLK = CLKIN * ((RxJ.D)/P) - // We know R = 1, P = 2. - // PLL_CLK = CLKIN * (J.D / 2) - - // For 24.576MHz: - // J = 8 - // D = 1920 - // So PLL_CLK = 24 * (8.192/2) = 24 x 4.096 = 98.304MHz - // Then: - // NDAC = 4 - // MDAC = 4 - // DOSR = 128 - // So: - // DAC_CLK = PLL_CLK / 4 = 24.576MHz. - // DAC_MOD_CLK = DAC_CLK / 4 = 6.144MHz. - // DAC_FS = DAC_MOD_CLK / 128 = 48kHz. - - // For 22.5792MHz: - // J = 7 - // D = 5264 - // So PLL_CLK = 24 * (7.5264/2) = 24 x 3.7632 = 90.3168MHz - // Then: - // NDAC = 4 - // MDAC = 4 - // DOSR = 128 - // So: - // DAC_CLK = PLL_CLK / 4 = 22.5792MHz. - // DAC_MOD_CLK = DAC_CLK / 4 = 5.6448MHz. - // DAC_FS = DAC_MOD_CLK / 128 = 44.1kHz. - -#if XUA_ADAPTIVE - //Set nominal clock speed on PLL - write_sswitch_reg(get_tile_id(tile[0]), XS1_SSWITCH_PLL_CTL_NUM, PLL_NOM); - - // We are assuming 48kHz family only and we generate MCLK in the DAC from BLCK supplied by XCORE - // Set PLL J Value to 8 - DAC3101_REGWRITE(DAC3101_PLL_J, 0x08); - // Set PLL D to 0 ... - // Set PLL D MSB Value to 0x00 - DAC3101_REGWRITE(DAC3101_PLL_D_MSB, 0x00); - // Set PLL D LSB Value to 0x00 - DAC3101_REGWRITE(DAC3101_PLL_D_LSB, 0x00); - - delay_milliseconds(1); - - // Set PLL_CLKIN = BCLK (device pin), CODEC_CLKIN = PLL_CLK (generated on-chip) - DAC3101_REGWRITE(DAC3101_CLK_GEN_MUX, 0x07); - - // Set PLL P=1 and R=4 values and power up. - DAC3101_REGWRITE(DAC3101_PLL_P_R, 0x94); - // Set NDAC clock divider to 4 and power up. - DAC3101_REGWRITE(DAC3101_NDAC_VAL, 0x84); - // Set MDAC clock divider to 4 and power up. - DAC3101_REGWRITE(DAC3101_MDAC_VAL, 0x84); - // Set OSR clock divider to 128. - DAC3101_REGWRITE(DAC3101_DOSR_VAL_LSB, 0x80); - -#else - /* Sample frequency dependent register settings */ - if ((samFreq % 11025) == 0) - { - // MCLK = 22.5792MHz (44.1,88.2,176.4kHz) - // Set PLL J Value to 7 - DAC3101_REGWRITE(DAC3101_PLL_J, 0x07); - // Set PLL D to 5264 ... (0x1490) - // Set PLL D MSB Value to 0x14 - DAC3101_REGWRITE(DAC3101_PLL_D_MSB, 0x14); - // Set PLL D LSB Value to 0x90 - DAC3101_REGWRITE(DAC3101_PLL_D_LSB, 0x90); - - } - else if ((samFreq % 8000) == 0) - { - // MCLK = 24.576MHz (48,96,192kHz) - // Set PLL J Value to 8 - DAC3101_REGWRITE(DAC3101_PLL_J, 0x08); - // Set PLL D to 1920 ... (0x780) - // Set PLL D MSB Value to 0x07 - DAC3101_REGWRITE(DAC3101_PLL_D_MSB, 0x07); - // Set PLL D LSB Value to 0x80 - DAC3101_REGWRITE(DAC3101_PLL_D_LSB, 0x80); - } - else - { - //debug_printf("Unrecognised sample freq of %d in ConfigCodec\n", samFreq); - } - - delay_milliseconds(1); - - // Set PLL_CLKIN = MCLK (device pin), CODEC_CLKIN = PLL_CLK (generated on-chip) - DAC3101_REGWRITE(DAC3101_CLK_GEN_MUX, 0x03); - - // Set PLL P and R values and power up. - DAC3101_REGWRITE(DAC3101_PLL_P_R, 0xA1); - // Set NDAC clock divider to 4 and power up. - DAC3101_REGWRITE(DAC3101_NDAC_VAL, 0x84); - // Set MDAC clock divider to 4 and power up. - DAC3101_REGWRITE(DAC3101_MDAC_VAL, 0x84); - // Set OSR clock divider to 128. - DAC3101_REGWRITE(DAC3101_DOSR_VAL_LSB, 0x80); - -#endif - - // Set CLKOUT Mux to DAC_CLK - DAC3101_REGWRITE(DAC3101_CLKOUT_MUX, 0x04); - // Set CLKOUT M divider to 1 and power up. - DAC3101_REGWRITE(DAC3101_CLKOUT_M_VAL, 0x81); - // Set GPIO1 output to come from CLKOUT output. - DAC3101_REGWRITE(DAC3101_GPIO1_IO, 0x10); - - // Set CODEC interface mode: I2S, 24 bit, slave mode (BCLK, WCLK both inputs). - DAC3101_REGWRITE(DAC3101_CODEC_IF, 0x20); - // Set register page to 1 - DAC3101_REGWRITE(DAC3101_PAGE_CTRL, 0x01); - // Program common-mode voltage to mid scale 1.65V. - DAC3101_REGWRITE(DAC3101_HP_DRVR, 0x14); - // Program headphone-specific depop settings. - // De-pop, Power on = 800 ms, Step time = 4 ms - DAC3101_REGWRITE(DAC3101_HP_DEPOP, 0x4E); - // Program routing of DAC output to the output amplifier (headphone/lineout or speaker) - // LDAC routed to left channel mixer amp, RDAC routed to right channel mixer amp - DAC3101_REGWRITE(DAC3101_DAC_OP_MIX, 0x44); - // Unmute and set gain of output driver - // Unmute HPL, set gain = 0 db - DAC3101_REGWRITE(DAC3101_HPL_DRVR, 0x06); - // Unmute HPR, set gain = 0 dB - DAC3101_REGWRITE(DAC3101_HPR_DRVR, 0x06); - // Unmute Left Class-D, set gain = 12 dB - DAC3101_REGWRITE(DAC3101_SPKL_DRVR, 0x0C); - // Unmute Right Class-D, set gain = 12 dB - DAC3101_REGWRITE(DAC3101_SPKR_DRVR, 0x0C); - // Power up output drivers - // HPL and HPR powered up - DAC3101_REGWRITE(DAC3101_HP_DRVR, 0xD4); - // Power-up L and R Class-D drivers - DAC3101_REGWRITE(DAC3101_SPK_AMP, 0xC6); - // Enable HPL output analog volume, set = -9 dB - DAC3101_REGWRITE(DAC3101_HPL_VOL_A, 0x92); - // Enable HPR output analog volume, set = -9 dB - DAC3101_REGWRITE(DAC3101_HPR_VOL_A, 0x92); - // Enable Left Class-D output analog volume, set = -9 dB - DAC3101_REGWRITE(DAC3101_SPKL_VOL_A, 0x92); - // Enable Right Class-D output analog volume, set = -9 dB - DAC3101_REGWRITE(DAC3101_SPKR_VOL_A, 0x92); - - delay_milliseconds(100); - - // Power up DAC - // Set register page to 0 - DAC3101_REGWRITE(DAC3101_PAGE_CTRL, 0x00); - // Power up DAC channels and set digital gain - // Powerup DAC left and right channels (soft step enabled) - DAC3101_REGWRITE(DAC3101_DAC_DAT_PATH, 0xD4); - // DAC Left gain = 0dB - DAC3101_REGWRITE(DAC3101_DACL_VOL_D, 0x00); - // DAC Right gain = 0dB - DAC3101_REGWRITE(DAC3101_DACR_VOL_D, 0x00); - // Unmute digital volume control - // Unmute DAC left and right channels - DAC3101_REGWRITE(DAC3101_DAC_VOL, 0x00); - - i_i2c.shutdown(); -} - - -//These are here just to silence compiler warnings about unimplemented xua callbacks (not needed in xua lite) -void AudioHwInit(){} -void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, unsigned sampRes_DAC, unsigned sampRes_ADC){} diff --git a/examples/xua_lite_example/src/audio_hub.h b/examples/xua_lite_example/src/audio_hub.h deleted file mode 100644 index b7f1b7f9..00000000 --- a/examples/xua_lite_example/src/audio_hub.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "i2s.h" - -[[distributable]] -void AudioHub(server i2s_frame_callback_if i2s, streaming chanend c_audio, streaming chanend (&?c_ds_output)[1]); \ No newline at end of file diff --git a/examples/xua_lite_example/src/audio_hub.xc b/examples/xua_lite_example/src/audio_hub.xc deleted file mode 100644 index bec765a1..00000000 --- a/examples/xua_lite_example/src/audio_hub.xc +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include "i2s.h" -#include "i2c.h" -#include "xua.h" -#define DEBUG_UNIT XUA_AUDIO_HUB -#define DEBUG_PRINT_ENABLE_XUA_AUDIO_HUB 1 -#include "debug_print.h" -#include "mic_array.h" -#include "audio_config.h" -#include "pdm_mic.h" -#include "xua_buffer_lite.h" - -//Globally declared for 64b alignment -int mic_decimator_fir_data_array[8][THIRD_STAGE_COEFS_PER_STAGE * PDM_MAX_DECIMATION] = {{0}}; -mic_array_frame_time_domain mic_audio_frame[2]; - -[[distributable]] -void AudioHub(server i2s_frame_callback_if i2s, - streaming chanend c_audio, - streaming chanend (&?c_ds_output)[1]) -{ - int32_t samples_out[NUM_USB_CHAN_OUT] = {0}; - int32_t samples_in[NUM_USB_CHAN_IN] = {0}; - - int32_t clock_nudge = 0; - - //PDM mic and decimator - unsigned buffer; - int raw_mics[XUA_NUM_PDM_MICS] = {0}; - const unsigned decimatorCount = 1; // Supports up to 4 mics - mic_array_decimator_conf_common_t dcc; - mic_array_decimator_config_t dc[1]; - mic_array_frame_time_domain * unsafe current; - - mic_array_decimator_set_samprate(DEFAULT_FREQ, mic_decimator_fir_data_array[0], &dcc, dc); - mic_array_decimator_configure(c_ds_output, decimatorCount, dc); - mic_array_init_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio_frame, dc); - - // Used for debug - //int saw = 0; - - while (1) { - select { - case i2s.init(i2s_config_t &?i2s_config, tdm_config_t &?tdm_config): - i2s_config.mode = I2S_MODE_I2S; - i2s_config.mclk_bclk_ratio = (MCLK_48/DEFAULT_FREQ)/64; - debug_printf("I2S init\n"); - delay_milliseconds(500); //Work around to ensure I2S does not start until enumeration complete so timing does not break for exchange - //This should be ideally done by set config by the host (via xua_buffer) to know we are enumerated - break; - - case i2s.receive(size_t n_chans, int32_t in_samps[n_chans]): - for (int i = 0; i < n_chans; i++) samples_in[i] = in_samps[i]; - break; - - case i2s.send(size_t n_chans, int32_t out_samps[n_chans]): - for (int i = 0; i < n_chans; i++) out_samps[i] = samples_out[i]; - break; - - //Exchange samples with mics & host - case i2s.restart_check() -> i2s_restart_t restart: - restart = I2S_NO_RESTART; // Keep on looping - timer tmr; int t0, t1; tmr :> t0; - - XUA_transfer_samples(c_audio, (unsigned *) samples_out, (unsigned *) raw_mics, (clock_nudge, int)); - - //Grab mics. Takes about 200 ticks currently - current = mic_array_get_next_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio_frame, dc); - //50 ticks - unsafe { - for (int i = 0; i < XUA_NUM_PDM_MICS; i++) raw_mics[i] = current->data[i][0]; - } - - //memset(raw_mics, saw, sizeof(int) * XUA_NUM_PDM_MICS); - //saw += 500; - - //Taking about 160 ticks when adjusting, 100 when not - tmr :> t0; - pll_nudge(clock_nudge); - tmr :> t1; - if (t1-t0 > 500) debug_printf("*%d\n", t1 - t0); - //delay_microseconds(10); //Test backpressure tolerance - break; - } - } -} diff --git a/examples/xua_lite_example/src/pdm_mic.h b/examples/xua_lite_example/src/pdm_mic.h deleted file mode 100644 index 04b13c3f..00000000 --- a/examples/xua_lite_example/src/pdm_mic.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _PDM_MIC_H_ -#define _PDM_MIC_H_ - -#include "mic_array.h" - -void mic_array_decimator_set_samprate(const unsigned samplerate, int mic_decimator_fir_data_array[], mic_array_decimator_conf_common_t *dcc, mic_array_decimator_config_t dc[]); -void pdm_mic(streaming chanend c_ds_output, in buffered port:32 p_pdm_mics); -void mic_array_setup_ddr(clock pdmclk, clock pdmclk6, in port p_mclk, - out port p_pdm_clk, buffered in port:32 p_pdm_data, - int divide); - -#endif diff --git a/examples/xua_lite_example/src/pdm_mic.xc b/examples/xua_lite_example/src/pdm_mic.xc deleted file mode 100644 index 59d506be..00000000 --- a/examples/xua_lite_example/src/pdm_mic.xc +++ /dev/null @@ -1,112 +0,0 @@ -#include "xua.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#include "mic_array.h" - - -void mic_array_decimator_set_samprate(const unsigned samplerate, int mic_decimator_fir_data_array[], mic_array_decimator_conf_common_t *dcc, mic_array_decimator_config_t dc[]) -{ - unsigned decimationfactor = 96000/samplerate; - int fir_gain_compen[7]; - int * unsafe fir_coefs[7]; - unsafe - { - fir_gain_compen[0] = 0; - fir_gain_compen[1] = FIR_COMPENSATOR_DIV_2; //48kHz - fir_gain_compen[2] = FIR_COMPENSATOR_DIV_4; - fir_gain_compen[3] = FIR_COMPENSATOR_DIV_6; //16kHz - fir_gain_compen[4] = FIR_COMPENSATOR_DIV_8; - fir_gain_compen[5] = 0; - fir_gain_compen[6] = FIR_COMPENSATOR_DIV_12; - - fir_coefs[0] = 0; - fir_coefs[1] = (int * unsafe)g_third_stage_div_2_fir; - fir_coefs[2] = (int * unsafe)g_third_stage_div_4_fir; - fir_coefs[3] = (int * unsafe)g_third_stage_div_6_fir; - fir_coefs[4] = (int * unsafe)g_third_stage_div_8_fir; - fir_coefs[5] = 0; - fir_coefs[6] = (int * unsafe)g_third_stage_div_12_fir; - - //dcc = {MIC_ARRAY_MAX_FRAME_SIZE_LOG2, 1, 0, 0, decimationfactor, fir_coefs[decimationfactor/2], 0, 0, DECIMATOR_NO_FRAME_OVERLAP, 2}; - dcc->len = MIC_ARRAY_MAX_FRAME_SIZE_LOG2; - dcc->apply_dc_offset_removal = 1; - dcc->index_bit_reversal = 0; - dcc->windowing_function = null; - dcc->output_decimation_factor = decimationfactor; - dcc->coefs = fir_coefs[decimationfactor/2]; - dcc->apply_mic_gain_compensation = 0; - dcc->fir_gain_compensation = fir_gain_compen[decimationfactor/2]; - dcc->buffering_type = DECIMATOR_NO_FRAME_OVERLAP; - dcc->number_of_frame_buffers = 2; - - //dc[0] = {&dcc, mic_decimator_fir_data[0], {0, 0, 0, 0}, 4}; - dc[0].dcc = dcc; - dc[0].data = mic_decimator_fir_data_array; - dc[0].mic_gain_compensation[0]=0; - dc[0].mic_gain_compensation[1]=0; - dc[0].mic_gain_compensation[2]=0; - dc[0].mic_gain_compensation[3]=0; - dc[0].channel_count = 4; - } -} - -#if MAX_FREQ > 48000 -#error MAX_FREQ > 48000 NOT CURRENTLY SUPPORTED -#endif - -void pdm_mic(streaming chanend c_ds_output, in buffered port:32 p_pdm_mics) -{ - streaming chan c_4x_pdm_mic_0; - assert((MCLK_48 / 3072000) == (MCLK_441 / 2822400)); //Make sure mic clock is achievable from MCLK - par - { - mic_array_pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, null); - mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic_0, c_ds_output, MIC_ARRAY_NO_INTERNAL_CHANS); - - } -} - -void mic_array_setup_ddr(clock pdmclk, - clock pdmclk6, - in port p_mclk, /*used only in I2S slave case*/ - out port p_pdm_clk, - buffered in port:32 p_pdm_data, - int divide) { - - -#if !XUA_ADAPTIVE //i2s slave - //p_mclk coming from the Pi is 24.576 MHz - configure_clock_src_divide(pdmclk, p_mclk, 4); //3.072 = 24.576 / 8 - configure_clock_src_divide(pdmclk6, p_mclk, 2); //6.144 = 24.576 / 4 - -#else - configure_clock_xcore(pdmclk, 80); // 3.072 - configure_clock_xcore(pdmclk6, 40); // 6.144 -#endif - - configure_port_clock_output(p_pdm_clk, pdmclk); - configure_in_port(p_pdm_data, pdmclk6); - - /* start the faster capture clock */ - start_clock(pdmclk6); - /* wait for a rising edge on the capture clock */ - partin(p_pdm_data, 4); - /* start the slower output clock */ - start_clock(pdmclk); - - /* - * this results in the rising edge of the capture clock - * leading the rising edge of the output clock by one period - * of p_mclk, which is about 40.7 ns for the typical frequency - * of 24.576 megahertz. - * This should fall within the data valid window. - */ - -} diff --git a/examples/xua_lite_example/test/Makefile b/examples/xua_lite_example/test/Makefile deleted file mode 100644 index b3bbbe69..00000000 --- a/examples/xua_lite_example/test/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 2018, XMOS Ltd, All rights reserved - -#Note no xcommon included - we are going bareback here because xcommon not good -#at dealing excluding/including source directories out of normal structure. -#We want to have a test app here using some source files from sw_vocalfusion (delay estimator) - - -BUILD_FLAGS = -O3 -g -XCC_FLAGS = $(BUILD_FLAGS) - -INCLUDE_DIRS = \ - -I ../src/ \ - -I . \ - -COMMON = \ - -O2 -g -report \ - -target=XCORE-200-EXPLORER \ - -SOURCES = \ - ./test_fifo.xc \ - -BINARY=bin/test_fifo.xe \ - - -all: - mkdir -p bin; \ - mv test_fifoxc test_fifo.xc; \ - xcc $(SOURCES) $(COMMON) $(INCLUDE_DIRS) -D AUDIO_DELAY_SAMPLES=$$DELAY -o $(BINARY); \ - mv test_fifo.xc test_fifoxc; \ - -sim: - xsim $(BINARY) - -clean: - rm -rf bin/* diff --git a/examples/xua_lite_example/test/test_fifoxc b/examples/xua_lite_example/test/test_fifoxc deleted file mode 100644 index befb966b..00000000 --- a/examples/xua_lite_example/test/test_fifoxc +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include "fifo_impl.h" - -typedef enum test_t{ - FAIL=0, - PASS=1 -}test_t; - -#define FIFO_SIZE 4 - -unsafe test_t test_is_empty(mem_fifo_short_t * unsafe fifo){ - unsigned fill = fifo_get_fill_short(fifo); - short data[1]; - fifo_ret_t ret = fifo_block_pop_short(fifo, data, 1); - if (fill == 0 && ret == FIFO_EMPTY) return PASS; - return FAIL; -} - -unsafe test_t test_push_one(mem_fifo_short_t * unsafe fifo){ - unsigned fill_0 = fifo_get_fill_short(fifo); - short data[] = {123}; - fifo_ret_t ret = fifo_block_push_short(fifo, data, 1); - unsigned fill_1 = fifo_get_fill_short(fifo); - - if (ret != FIFO_SUCCESS || fill_0 + 1 != fill_1) return FAIL; - return PASS; -} - -unsafe test_t test_partial_fill(mem_fifo_short_t * unsafe fifo){ - unsigned fill_0 = fifo_get_fill_short(fifo); - short data[] = {80, 90, 100}; - fifo_ret_t ret = fifo_block_push_short(fifo, data, 3); - unsigned fill_1 = fifo_get_fill_short(fifo); - - if (ret != FIFO_SUCCESS || fill_0 != 0 || fill_1 != 3) return FAIL; - return PASS; -} - -unsafe test_t test_fill_level(mem_fifo_short_t * unsafe fifo){ - unsigned fill = fifo_get_fill_short(fifo); - if (fill != 3) return FAIL; - return PASS; -} - -unsafe test_t test_pop_one(mem_fifo_short_t * unsafe fifo, short expect){ - unsigned fill_0 = fifo_get_fill_short(fifo); - short data[1] = {0xffff}; - fifo_ret_t ret = fifo_block_pop_short(fifo, data, 1); - unsigned fill_1 = fifo_get_fill_short(fifo); - if (ret != FIFO_SUCCESS || fill_0 != fill_1 + 1 || data[0] != expect) { - printf("grr %d\n", data[0]); - return FAIL; - } - return PASS; -} - -unsafe test_t test_pop_three_fail(mem_fifo_short_t * unsafe fifo){ - unsigned fill_0 = fifo_get_fill_short(fifo); - short data[3] = {0xffff, 0xffff, 0xffff}; - fifo_ret_t ret = fifo_block_pop_short(fifo, data, 3); - unsigned fill_1 = fifo_get_fill_short(fifo); - if (ret == FIFO_SUCCESS || fill_0 != 2 || fill_1 != 2) return FAIL; - return PASS; -} - -unsafe test_t test_partial_fill_fast(mem_fifo_short_t * unsafe fifo){ - unsigned fill_0 = fifo_get_fill_short(fifo); - short data[] = {20, 30, 40}; - fifo_ret_t ret = fifo_block_push_short_fast(fifo, data, 3); - unsigned fill_1 = fifo_get_fill_short(fifo); - - if (ret != FIFO_SUCCESS || fill_0 != 0 || fill_1 != 3) return FAIL; - return PASS; -} - -unsafe test_t test_pop_block_fast(mem_fifo_short_t * unsafe fifo, short expect[], unsigned n){ - unsigned fill_0 = fifo_get_fill_short(fifo); - short data[10] = {0xffff}; - fifo_ret_t ret = fifo_block_pop_short_fast(fifo, data, n); - unsigned fill_1 = fifo_get_fill_short(fifo); - unsigned data_ok = memcmp(data, expect, n * sizeof(short)) == 0; - if (ret != FIFO_SUCCESS || fill_0 != fill_1 + n || !data_ok) return FAIL; - return PASS; -} - -unsafe void print_fifo(mem_fifo_short_t * unsafe fifo){ - for (int i = fifo->size - 1; i >= 0; i--){ - printf("FIFO[%d]: %hd %s %s\n", i, fifo->data_base_ptr[i], fifo->read_idx == i ? "RD" : "", fifo->write_idx == i ? "WR" : ""); - } -} - - -int main(void){ - unsafe{ - short test_fifo_storage[FIFO_SIZE]; - mem_fifo_short_t test_fifo = {sizeof(test_fifo_storage)/sizeof(test_fifo_storage[0]), test_fifo_storage, 0, 0}; - volatile mem_fifo_short_t * unsafe test_fifo_ptr = &test_fifo; - - // print_fifo(test_fifo_ptr); - printf("test_is_empty: %d\n", test_is_empty(test_fifo_ptr)); - printf("test_partial_fill: %d\n", test_partial_fill(test_fifo_ptr)); - // print_fifo(test_fifo_ptr); - - printf("test_fill_level: %d\n", test_fill_level(test_fifo_ptr)); - printf("test_pop_one: %d\n", test_pop_one(test_fifo_ptr, 80)); - printf("test_pop_three_fail: %d\n", test_pop_three_fail(test_fifo_ptr)); - printf("test_pop_one: %d\n", test_pop_one(test_fifo_ptr, 90)); - printf("test_pop_one: %d\n", test_pop_one(test_fifo_ptr, 100)); - printf("test_is_empty: %d\n", test_is_empty(test_fifo_ptr)); - - printf("test_partial_fill_fast: %d\n", test_partial_fill_fast(test_fifo_ptr)); - - printf("test_pop_one: %d\n", test_pop_one(test_fifo_ptr, 20)); - // print_fifo(test_fifo_ptr); - - short td[] = {30, 40}; - - printf("test_pop_block_fast: %d\n", test_pop_block_fast(test_fifo_ptr, td, 2)); //no wrap - - printf("test_is_empty: %d\n", test_is_empty(test_fifo_ptr)); - printf("test_push_one: %d\n", test_push_one(test_fifo_ptr)); - printf("test_push_one: %d\n", test_push_one(test_fifo_ptr)); - printf("test_pop_three_fail: %d\n", test_pop_three_fail(test_fifo_ptr)); - printf("test_pop_one: %d\n", test_pop_one(test_fifo_ptr, 123)); - printf("test_pop_one: %d\n", test_pop_one(test_fifo_ptr, 123)); - - printf("test_partial_fill_fast: %d\n", test_partial_fill_fast(test_fifo_ptr)); //no wrap - short te[] = {20, 30, 40}; - printf("test_pop_block_fast: %d\n", test_pop_block_fast(test_fifo_ptr, te, 3));// no wrap - printf("test_partial_fill_fast: %d\n", test_partial_fill_fast(test_fifo_ptr)); //wrap - printf("test_pop_block_fast: %d\n", test_pop_block_fast(test_fifo_ptr, te, 3));// wrap - // print_fifo(test_fifo_ptr); - - - - - return 0; - } -} \ No newline at end of file diff --git a/examples/xua_lite_example/todo.txt b/examples/xua_lite_example/todo.txt deleted file mode 100644 index 4d0ab456..00000000 --- a/examples/xua_lite_example/todo.txt +++ /dev/null @@ -1,22 +0,0 @@ -- Bring ep0 serivice into xua_buffer select (make control mem) (DONE) -- Tidy feedback endpoint (DONE) -- Input path + FIFO (DONE) -- Function prototypes into includes (DONE) -- Single input/ouput format (DONE) -- Get UAC1 / FS working (DONE) -- Optimised EP buffer (either triple block or block FIFO) (DONE) -- Fix output gain issue (IN PROGRESS) -- Add timer to xua_buffer to prepare for exchange with audio (remove backpressure to audio) (WONT DO - use port buffer and reduce case overhead) -- Adaptive endpoint EP and descriptors (DONE) -- Adpative clock control (IN PROGRESS) -- Proper control loop w/filtering (IN PROGRESS) -- Switchable MICS using define (WONT DO - separate app) -- DFU -- Combinable EP0 (DONE) -- Interrupt EP0 option -- Control processing -- Fix cast warning (DONE) -- Work out why no clock drift on Android / OSX (drift seen on Linux and Win) (DONE) -- Tidy/cut down EP0 handling -- Broader host testing (Android, W10, MAC) (IN PROGRESS) -- Peer review diff --git a/examples/xua_lite_example/wscript b/examples/xua_lite_example/wscript deleted file mode 100644 index 5d6de68c..00000000 --- a/examples/xua_lite_example/wscript +++ /dev/null @@ -1,26 +0,0 @@ -def options(ctx): - ctx.add_option('--target', action='store', default='xua_lite_example.xe') - ctx.add_option('--debug', action='store_true') - - -def configure(conf): - conf.load('xwaf.compiler_xcc') - conf.env.PROJECT_ROOT = '../../..' - -def build(bld): - target_path = 'bin/' + bld.options.target - bld.env.TARGET_ARCH ='config/RPI_HAT_60QFN.xn' - bld.env.XSCOPE = bld.path.find_resource('config.xscope') - depends_on = ['lib_xua','lib_i2s','lib_xud','lib_mic_array', 'lib_i2c'] - #bld.env.XCC_FLAGS = ['-O2', '-g', '-Wall', '-fcmdline-buffer-bytes=512', '-report', '-DDISABLE_STAGE_C'] - bld.env.XCC_FLAGS = ['-fcomment-asm','-Xmapper','--map','-Xmapper','MAPFILE', - '-Os','-report','-g','-Wno-unused-function','-Wno-timing', - '-DXUD_SERIES_SUPPORT=XUD_X200_SERIES','-DUSB_TILE=tile[1]', - '-DMIC_ARRAY_CH0=PIN0','-DMIC_ARRAY_CH1=PIN4', '-DDEBUG_PRINT_ENABLE=1'] - if bld.options.debug: - bld.env.XCC_FLAGS.append('-DDEBUG') - - source = bld.path.ant_glob(['src/**/*.xc', 'src/**/*.c', - 'xua_lite/**/*.xc', 'xua_lite/**/*.c']) - includes = ['config'] - bld.program(source=source, includes=includes, depends_on=depends_on,target=target_path) diff --git a/examples/xua_lite_example/xua_lite/rate_control/fifo_impl.h b/examples/xua_lite_example/xua_lite/rate_control/fifo_impl.h deleted file mode 100644 index 080f3c95..00000000 --- a/examples/xua_lite_example/xua_lite/rate_control/fifo_impl.h +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef __FIFO__ -#define __FIFO__ -#include //memcpy -#include "fifo_types.h" - -//Asynch FIFO implementaion -//Note these are in the include file to allow the compiler to inline for performance - -/////////////////////////////////////// -//Shared memory FIFO (sample by sample) -//Can be any size -/////////////////////////////////////// - - -static inline unsigned fifo_get_fill(volatile mem_fifo_t * unsafe fifo) { - unsafe{ - unsigned fifo_fill = 0; - if (fifo->write_idx >= fifo->read_idx){ - fifo_fill = fifo->write_idx - fifo->read_idx; - } - else{ - fifo_fill = (fifo->size + fifo->write_idx) - fifo->read_idx; - } - return fifo_fill; - } -} - -static inline unsigned fifo_get_fill_short(volatile mem_fifo_short_t * unsafe fifo) { - unsafe{ - unsigned fifo_fill = 0; - if (fifo->write_idx >= fifo->read_idx){ - fifo_fill = fifo->write_idx - fifo->read_idx; - } - else{ - fifo_fill = (fifo->size + fifo->write_idx) - fifo->read_idx; - } - return fifo_fill; - } -} - -static inline void fifo_init_short(volatile mem_fifo_short_t * unsafe fifo) { - unsafe{ - fifo->write_idx = 0; - fifo->read_idx = (fifo->size * 2) / 4; - memset(fifo->data_base_ptr , 0, fifo->size * sizeof(short)); - } -} - -#pragma unsafe arrays -static inline fifo_ret_t fifo_block_push(volatile mem_fifo_t * unsafe fifo, int data[], unsigned n) { - unsafe{ - //check there is a block of space large enough - unsigned space_remaining = fifo->size - fifo_get_fill(fifo) - 1; - if (n > space_remaining) { - return FIFO_FULL; - } - for (int i = 0; i < n; i++){ - unsigned next_idx = fifo->write_idx + 1; - if (next_idx == fifo->size) next_idx = 0; //Check for wrap - fifo->data_base_ptr[fifo->write_idx] = data[i]; - fifo->write_idx = next_idx; - } - return FIFO_SUCCESS; - } -} - -#pragma unsafe arrays -static inline fifo_ret_t fifo_block_push_short(volatile mem_fifo_short_t * unsafe fifo, short data[], unsigned n) { - unsafe{ - //check there is a block of space large enough - unsigned space_remaining = fifo->size - fifo_get_fill_short(fifo) - 1; - if (n > space_remaining) { - return FIFO_FULL; - } - for (int i = 0; i < n; i++){ - unsigned next_idx = fifo->write_idx + 1; - if (next_idx == fifo->size) next_idx = 0; //Check for wrap - fifo->data_base_ptr[fifo->write_idx] = data[i]; - fifo->write_idx = next_idx; - } - return FIFO_SUCCESS; - } -} - -#pragma unsafe arrays -static inline fifo_ret_t fifo_block_push_short_fast(volatile mem_fifo_short_t * unsafe fifo, short data[], unsigned n) { - unsafe{ - //check there is a block of space large enough - unsigned space_remaining = fifo->size - fifo_get_fill_short(fifo) - 1; - if (n > space_remaining) { - return FIFO_FULL; - } - //We will write either one or two blocks depending on wrap - unsigned first_block_size = 0; - unsigned second_block_size = 0; - - //See if we need to wrap during block writes - unsigned space_left_at_top = fifo->size - fifo->write_idx; - //printf("space_left_at_top %d\n", space_left_at_top); - //Yes, we do need to wrap - if (n > space_left_at_top){ - first_block_size = space_left_at_top; - second_block_size = n - space_left_at_top; - memcpy(&fifo->data_base_ptr[fifo->write_idx], &data[0], first_block_size * sizeof(short)); - memcpy(&fifo->data_base_ptr[0], &data[first_block_size], second_block_size * sizeof(short)); - fifo->write_idx = second_block_size; - } - //No wrap, do all in one go - else{ - first_block_size = n; - second_block_size = 0; - memcpy(&fifo->data_base_ptr[fifo->write_idx], &data[0], first_block_size * sizeof(short)); - fifo->write_idx += first_block_size; - } - - return FIFO_SUCCESS; - } -} - -#pragma unsafe arrays -static inline fifo_ret_t fifo_block_pop(volatile mem_fifo_t * unsafe fifo, int data[], unsigned n) { - unsafe{ - //Check we have a block big enough to send - if (n > fifo_get_fill(fifo)){ - return FIFO_EMPTY; - } - for (int i = 0; i < n; i++){ - data[i] = fifo->data_base_ptr[fifo->read_idx]; - fifo->read_idx++; - if (fifo->read_idx == fifo->size) fifo->read_idx = 0; //Check for wrap - } - return FIFO_SUCCESS; - } -} - -#pragma unsafe arrays -static inline fifo_ret_t fifo_block_pop_short(volatile mem_fifo_short_t * unsafe fifo, short data[], unsigned n) { - unsafe{ - //Check we have a block big enough to send - if (n > fifo_get_fill_short(fifo)){ - return FIFO_EMPTY; - } - for (int i = 0; i < n; i++){ - data[i] = fifo->data_base_ptr[fifo->read_idx]; - fifo->read_idx++; - if (fifo->read_idx == fifo->size) fifo->read_idx = 0; //Check for wrap - } - return FIFO_SUCCESS; - } -} - -#pragma unsafe arrays -static inline fifo_ret_t fifo_block_pop_short_fast(volatile mem_fifo_short_t * unsafe fifo, short data[], unsigned n) { - unsafe{ - //Check we have a block big enough to send - if (n > fifo_get_fill_short(fifo)){ - return FIFO_EMPTY; - } - //We will read either one or two blocks depending on wrap - unsigned first_block_size = 0; - unsigned second_block_size = 0; - - //See if we need to wrap during block read - unsigned num_read_at_top = fifo->size - fifo->read_idx; - // printf("num_read_at_top %d\n", num_read_at_top); - //Yes, we do need to wrap - if (n > num_read_at_top){ - first_block_size = num_read_at_top; - second_block_size = n - num_read_at_top; - memcpy(&data[0], &fifo->data_base_ptr[fifo->read_idx], first_block_size * sizeof(short)); - memcpy( &data[first_block_size], &fifo->data_base_ptr[0], second_block_size * sizeof(short)); - fifo->read_idx = second_block_size; - // printf("wrap\n"); - } - //No wrap, do all in one go - else{ - first_block_size = n; - second_block_size = 0; - memcpy(&data[0], &fifo->data_base_ptr[fifo->read_idx], first_block_size * sizeof(short)); - fifo->read_idx += first_block_size; - // printf("no wrap\n"); - - } - - return FIFO_SUCCESS; - } -} - -//Version of above that returns fill level relative to half full -static inline int fifo_get_fill_relative_half(volatile mem_fifo_t * unsafe fifo){ - unsafe{ - int fifo_fill = (int)fifo_get_fill(fifo); - fifo_fill -= (fifo->size / 2); - return fifo_fill; - } -} - -//Version of above that returns fill level relative to half full -static inline int fifo_get_fill_relative_half_short(volatile mem_fifo_short_t * unsafe fifo){ - unsafe{ - int fifo_fill = (int)fifo_get_fill_short(fifo); - fifo_fill -= (fifo->size / 2); - return fifo_fill; - } -} -#endif diff --git a/examples/xua_lite_example/xua_lite/rate_control/fifo_types.h b/examples/xua_lite_example/xua_lite/rate_control/fifo_types.h deleted file mode 100644 index af7994e7..00000000 --- a/examples/xua_lite_example/xua_lite/rate_control/fifo_types.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __ASRC_FIFO_TYPES__ -#define __ASRC_FIFO_TYPES__ -#include - -//Shared FIFO return types -typedef enum fifo_ret_t { - FIFO_SUCCESS = 0, - FIFO_FULL, - FIFO_EMPTY -} fifo_ret_t; - -///////////////////////////////////////////////////////////////////////// -//Shared memory FIFO (sample by sample or block) -//Can be any size -// -//Note that the actual storage for the FIFO is declared externally -//and a reference to the base address of the storage is passed in along -//with the size of the storage. This way, multiple instances may be -//different sizes. -// -///////////////////////////////////////////////////////////////////////// - -typedef struct mem_fifo_t { - const unsigned size; //Size in INTs - int * const unsafe data_base_ptr; //Base of the data array - declared externally so we can have differnt sized FIFOs - unsigned write_idx; - unsigned read_idx; -} mem_fifo_t; - -typedef struct mem_fifo_short_t { - const unsigned size; //Size in SHORTs - short * const unsafe data_base_ptr; //Base of the data array - declared externally so we can have differnt sized FIFOs - unsigned write_idx; - unsigned read_idx; -} mem_fifo_short_t; - -#endif diff --git a/examples/xua_lite_example/xua_lite/rate_control/rate_controller.h b/examples/xua_lite_example/xua_lite/rate_control/rate_controller.h deleted file mode 100644 index 8dee3f75..00000000 --- a/examples/xua_lite_example/xua_lite/rate_control/rate_controller.h +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -typedef int32_t xua_lite_fixed_point_t; - -typedef struct pid_state_t{ - xua_lite_fixed_point_t fifo_level_filtered_old; - xua_lite_fixed_point_t fifo_level_accum; -} pid_state_t; - - -//USB Adaptive mode helper -xua_lite_fixed_point_t do_rate_control(int fill_level, pid_state_t *pid_state); - -//PDM modulator for clock control -void do_clock_nudge_pdm(xua_lite_fixed_point_t controller_out, int *clock_nudge); - - -//USB Asynch mode helper -void do_feedback_calculation(unsigned &sof_count, const unsigned mclk_hz, unsigned mclk_port_counter,unsigned &mclk_port_counter_old - ,long long &feedback_value, unsigned &mod_from_last_time, unsigned fb_clocks[1]); \ No newline at end of file diff --git a/examples/xua_lite_example/xua_lite/rate_control/rate_controller.xc b/examples/xua_lite_example/xua_lite/rate_control/rate_controller.xc deleted file mode 100644 index 58fddf48..00000000 --- a/examples/xua_lite_example/xua_lite/rate_control/rate_controller.xc +++ /dev/null @@ -1,201 +0,0 @@ -#include -#include "xua_buffer_lite.h" -#include "rate_controller.h" -#define DEBUG_UNIT XUA_RATE_CONTROL -#define DEBUG_PRINT_ENABLE_XUA_RATE_CONTROL 1 -#include "debug_print.h" - -#define XUA_LIGHT_FIXED_POINT_Q_BITS 10 //Including sign bit. 10b gets us to +511.999999 to -512.000000 -#define XUA_LIGHT_FIXED_POINT_TOTAL_BITS (sizeof(xua_lite_fixed_point_t) * 8) -#define XUA_LIGHT_FIXED_POINT_FRAC_BITS (XUA_LIGHT_FIXED_POINT_TOTAL_BITS - XUA_LIGHT_FIXED_POINT_Q_BITS) -#define XUA_LIGHT_FIXED_POINT_ONE (1 << XUA_LIGHT_FIXED_POINT_FRAC_BITS) -#define XUA_LIGHT_FIXED_POINT_MINUS_ONE (-XUA_LIGHT_FIXED_POINT_ONE) - -#define FIFO_LEVEL_EMA_COEFF 0.939 //Proportion of signal from y[-1]. - //0.939 gives ~10Hz 3db cutoff low pass filter for filter rate of 1kHz - //dsp.stackexchange.com/questions/40462/exponential-moving-average-cut-off-frequency/40465 -#define FIFO_LEVEL_A_COEFF ((int32_t)(INT_MAX * FIFO_LEVEL_EMA_COEFF)) //Scale to signed 1.31 format -#define FIFO_LEVEL_B_COEFF (INT_MAX - FIFO_LEVEL_A_COEFF) - -#define RANDOMISATION_PERCENT 20 //How much radnom noise to inject in percent of existing signal amplitude -#define RANDOMISATION_COEFF_A ((INT_MAX / 100) * RANDOMISATION_PERCENT) - -#define PID_CALC_OVERHEAD_BITS 2 //Allow large P,I or D constants, up to 2^(this number) - - -#define PID_CONTROL_P_TERM 10.0 -#define PID_CONTROL_I_TERM 150.0 -#define PID_CONTROL_D_TERM 1.0 - -#define PID_RATE_MULTIPLIER SOF_FREQ_HZ - -#define PID_CONTROL_P_TERM_COEFF ((xua_lite_fixed_point_t)((XUA_LIGHT_FIXED_POINT_ONE >> PID_CALC_OVERHEAD_BITS) * (float)PID_CONTROL_P_TERM)) //scale to fixed point -#define PID_CONTROL_I_TERM_COEFF ((xua_lite_fixed_point_t)((XUA_LIGHT_FIXED_POINT_ONE >> PID_CALC_OVERHEAD_BITS) * (float)PID_CONTROL_I_TERM / PID_RATE_MULTIPLIER)) //scale to fixed point -#define PID_CONTROL_D_TERM_COEFF ((xua_lite_fixed_point_t)((XUA_LIGHT_FIXED_POINT_ONE >> PID_CALC_OVERHEAD_BITS) * (float)PID_CONTROL_D_TERM * PID_RATE_MULTIPLIER)) //scale to fixed point - - -static inline xua_lite_fixed_point_t do_fifo_depth_lowpass_filter(xua_lite_fixed_point_t old, int fifo_depth){ - //we grow from 32b to 64b for intermediate - int64_t intermediate = ((int64_t)(fifo_depth << XUA_LIGHT_FIXED_POINT_FRAC_BITS) * (int64_t)FIFO_LEVEL_B_COEFF) + ((int64_t)old * (int64_t)FIFO_LEVEL_A_COEFF); - xua_lite_fixed_point_t new_fifo_depth = (xua_lite_fixed_point_t)( intermediate >> (64 - XUA_LIGHT_FIXED_POINT_TOTAL_BITS - 1)); //-1 because signed int - return new_fifo_depth; -} - -static inline int32_t get_random_number(void) -{ - static const unsigned random_poly = 0xEDB88320; - static unsigned random = 0x12345678; - crc32(random, -1, random_poly); - return (int32_t) random; -} - -static inline xua_lite_fixed_point_t add_noise(xua_lite_fixed_point_t input){ - //Note the input number cannot be bigger than 2 ^ (FIXED_POINT_Q_BITS - 1) * (1 + PERCENT) else we could oveflow - //Eg. if Q bits = 10 then biggest input value is 255.9999 - int32_t random = get_random_number(); - int32_t input_fraction = ((int64_t)input * (int64_t)RANDOMISATION_COEFF_A) >> (XUA_LIGHT_FIXED_POINT_TOTAL_BITS - 1); - int64_t output_64 = ((int64_t)input << (XUA_LIGHT_FIXED_POINT_TOTAL_BITS - 1)) + ((int64_t)input_fraction * (int64_t)random); - return (xua_lite_fixed_point_t)( output_64 >> (64 - XUA_LIGHT_FIXED_POINT_TOTAL_BITS - 1)); -} - -//Convert the control input into a pdm output (dither) with optional noise -void do_clock_nudge_pdm(xua_lite_fixed_point_t controller_out, int *clock_nudge){ - - //Randomise - add a proportion of rectangular probability distribution noise to spread the spectrum - controller_out = add_noise(controller_out); - - //Convert to pulse density modulation (sigma-delta) - static xua_lite_fixed_point_t nudge_accumulator = 0; - nudge_accumulator += controller_out; //Note no overflow check as if we reach XUA_LIGHT_FIXED_POINT_Q_BITS - //something is very wrong - //printf("co: %d ratio: %f \n", controller_out, (float)controller_out/XUA_LIGHT_FIXED_POINT_ONE); - if (nudge_accumulator >= XUA_LIGHT_FIXED_POINT_ONE){ - *clock_nudge = 1; - nudge_accumulator -= XUA_LIGHT_FIXED_POINT_ONE; - } - else if (nudge_accumulator <= XUA_LIGHT_FIXED_POINT_MINUS_ONE){ - nudge_accumulator -= XUA_LIGHT_FIXED_POINT_MINUS_ONE; - *clock_nudge = -1; - } - else{ - *clock_nudge = 0; - } -} - - -//Do PI control and modulation for adaptive USB audio -xua_lite_fixed_point_t do_rate_control(int fill_level, pid_state_t *pid_state){ - - //We always check the FIFO level after USB has produced a block, and total FIFO size is 2x max, so half full is at 3/4 - const int half_full = ((MAX_OUT_SAMPLES_PER_SOF_PERIOD * 2) * 3) / 4; - int fill_level_wrt_half = fill_level - half_full; //Will be +ve for more than half full and negative for less than half full - - //Low pass filter fill level and get error w.r.t. to set point which is depth = 0 (relative to half full) - xua_lite_fixed_point_t fifo_level_filtered = do_fifo_depth_lowpass_filter(pid_state->fifo_level_filtered_old , fill_level_wrt_half); - //printf("old fill_level: %f fill_level: %f\n", (float)pid_state->fifo_level_filtered_old/(1<fifo_level_accum + fifo_level_filtered; - - //clip the I term (which can wind up) to maximum fixed point representation. Check to see if overflow (which will change sign) - if (fifo_level_filtered >= 0){ //If it was positive before, ensure it still is else clip to positive - if (i_term_pre_clip >= pid_state->fifo_level_accum){ - //debug_printf("grow %d %d\n", (int32_t)i_term_pre_clip, (int32_t)pid_state->fifo_level_accum); - pid_state->fifo_level_accum = i_term_pre_clip; - } - else{ - pid_state->fifo_level_accum = INT_MAX; - //debug_printf("clip+ %d\n", pid_state->fifo_level_accum); - } - } - else{ //Value was negative so ensure it still is else clip negative - if (i_term_pre_clip <= pid_state->fifo_level_accum){ - pid_state->fifo_level_accum = i_term_pre_clip; - } - else{ - pid_state->fifo_level_accum = INT_MIN; - //debug_printf("clip- %d %d\n", pid_state->fifo_level_accum, fifo_level_filtered); - } - } - - //Calculate D term. No clipping required because it can never be larger than the D term, - //which is already scaled to fit within the fixed point representation - xua_lite_fixed_point_t fifo_level_delta = fifo_level_filtered - pid_state->fifo_level_filtered_old; - - //Save to struct for next iteration - pid_state->fifo_level_filtered_old = fifo_level_filtered; - - //Do PID calculation. Note there is an implicit cast back to xua_lite_fixed_point_t before assignment - xua_lite_fixed_point_t p_term = (((int64_t) fifo_level_filtered * (int64_t)PID_CONTROL_P_TERM_COEFF)) >> XUA_LIGHT_FIXED_POINT_FRAC_BITS; - xua_lite_fixed_point_t i_term = (((int64_t) pid_state->fifo_level_accum * (int64_t)PID_CONTROL_I_TERM_COEFF)) >> XUA_LIGHT_FIXED_POINT_FRAC_BITS; - xua_lite_fixed_point_t d_term = (((int64_t) fifo_level_delta * (int64_t)PID_CONTROL_D_TERM_COEFF)) >> XUA_LIGHT_FIXED_POINT_FRAC_BITS; - - //debug_printf("p: %d i: %d f: %d\n", p_term >> XUA_LIGHT_FIXED_POINT_Q_BITS, i_term >> XUA_LIGHT_FIXED_POINT_Q_BITS, fifo_level_filtered >> (XUA_LIGHT_FIXED_POINT_FRAC_BITS - 10)); - //printf("p: %f i: %f d: %f filtered: %f integrated: %f\n", (float)p_term / (1<<(XUA_LIGHT_FIXED_POINT_FRAC_BITS-PID_CALC_OVERHEAD_BITS)), (float)i_term / (1<<(XUA_LIGHT_FIXED_POINT_FRAC_BITS-PID_CALC_OVERHEAD_BITS)), (float)d_term / (1<<(XUA_LIGHT_FIXED_POINT_FRAC_BITS-PID_CALC_OVERHEAD_BITS)), (float)fifo_level_filtered/(1<fifo_level_accum/(1<> (XUA_LIGHT_FIXED_POINT_Q_BITS - 1 - PID_CALC_OVERHEAD_BITS); - - - //debug_printf("filtered: %d raw: %d\n", fifo_level_filtered >> 22, fill_level_wrt_half); - - //static unsigned counter; counter++; if (counter>100){counter = 0; debug_printf("pid: %d\n",i_term >> (XUA_LIGHT_FIXED_POINT_FRAC_BITS - 10));} - debug_printf("co: %d\n", controller_out >> XUA_LIGHT_FIXED_POINT_FRAC_BITS); - return controller_out; -} - - -//Calculate feedback for asynchronous USB audio -void do_feedback_calculation(unsigned &sof_count - ,const unsigned mclk_hz - ,unsigned mclk_port_counter - ,unsigned &mclk_port_counter_old - ,long long &feedback_value - ,unsigned &mod_from_last_time - ,unsigned fb_clocks[1]){ - // 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. - // Average over 128 SOFs - 128 x 3072 = 0x60000. - - unsigned long long feedbackMul = 64ULL; - if(AUDIO_CLASS == 1) feedbackMul = 8ULL; // TODO Use 4 instead of 8 to avoid windows LSB issues? - - // Number of MCLK ticks in this SOF period (E.g = 125 * 24.576 = 3072) - int mclk_ticks_this_sof_period = (int) ((short)(mclk_port_counter - mclk_port_counter_old)); - unsigned long long full_result = mclk_ticks_this_sof_period * feedbackMul * DEFAULT_FREQ; - feedback_value += full_result; - - // Store MCLK for next time around... - mclk_port_counter_old = mclk_port_counter; - - // Reset counts based on SOF counting. Expect 16ms (128 HS SOFs/16 FS SOFS) per feedback poll - // We always count 128 SOFs, so 16ms @ HS, 128ms @ FS - if(sof_count == 128){ - //debug_printf("fb\n"); - sof_count = 0; - - feedback_value += mod_from_last_time; - unsigned clocks = feedback_value / mclk_hz; - mod_from_last_time = feedback_value % mclk_hz; - feedback_value = 0; - - //Scale for working out number of samps to take from device for input - if(AUDIO_CLASS == 2){ - clocks <<= 3; - } - else{ - clocks <<= 6; - } - asm volatile("stw %0, dp[g_speed]"::"r"(clocks)); // g_speed = clocks - - //Write to feedback EP buffer - if (AUDIO_CLASS == 2){ - fb_clocks[0] = clocks; - } - else{ - fb_clocks[0] = clocks >> 2; - } - } -} - diff --git a/examples/xua_lite_example/xua_lite/xua_buffer_lite.h b/examples/xua_lite_example/xua_lite/xua_buffer_lite.h deleted file mode 100644 index 8ac52765..00000000 --- a/examples/xua_lite_example/xua_lite/xua_buffer_lite.h +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include "xua_ep0_wrapper.h" -#include "xua.h" - -//Currently only single frequency supported -#define NOMINAL_SR_DEVICE DEFAULT_FREQ -#define NOMINAL_SR_HOST DEFAULT_FREQ - -#define DIV_ROUND_UP(n, d) (n / d + 1) //Always rounds up to the next integer. Needed for 48001Hz case etc. -#define BIGGEST(a, b) (a > b ? a : b) - -#define SOF_FREQ_HZ (8000 - ((2 - AUDIO_CLASS) * 7000) ) //1000 for FS or 8000 for HS - -//Defines for endpoint buffer sizes. Samples is total number of samples across all channels -#define MAX_OUT_SAMPLES_PER_SOF_PERIOD (DIV_ROUND_UP(MAX_FREQ, SOF_FREQ_HZ) * NUM_USB_CHAN_OUT) -#define MAX_IN_SAMPLES_PER_SOF_PERIOD (DIV_ROUND_UP(MAX_FREQ, SOF_FREQ_HZ) * NUM_USB_CHAN_IN) -#define MAX_OUTPUT_SLOT_SIZE 4 -#define MAX_INPUT_SLOT_SIZE 4 - -#define OUT_AUDIO_BUFFER_SIZE_BYTES (MAX_OUT_SAMPLES_PER_SOF_PERIOD * MAX_OUTPUT_SLOT_SIZE) -#define IN_AUDIO_BUFFER_SIZE_BYTES (MAX_IN_SAMPLES_PER_SOF_PERIOD * MAX_INPUT_SLOT_SIZE) - -unsafe void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, chanend ?c_feedback, chanend c_aud_in, chanend c_sof, in port p_for_mclk_count, streaming chanend c_audio_hub); -[[combinable]] -unsafe void XUA_Buffer_lite2(server ep0_control_if i_ep0_ctl, chanend c_aud_out, chanend ?c_feedback, chanend c_aud_in, chanend c_sof, in port p_for_mclk_count, streaming chanend c_audio_hub); - -/** Transfer samples to/from XUA. Should be called at the current USB rate. - * This function is non-blocking. - * - * \param[in,out] c_audio Channel to XUA. - * - * \param[out] sampsFromUsbToAudio Samples sent from host to device. - * - * \param[in] sampsFromAudioToUsb Samples to send from device to host. - * - * \param[out] clock_nudge Notification that the device is running - * too slowly/quickly. Only used when in - * adaptive endpoint mode. - */ -static inline void XUA_transfer_samples(streaming chanend c_audio, - unsigned sampsFromUsbToAudio[], - unsigned sampsFromAudioToUsb[], - int &clock_nudge) { - //Transfer samples. Takes about 25 ticks - for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio :> sampsFromUsbToAudio[i]; - if (XUA_ADAPTIVE) c_audio :> clock_nudge; - for (int i = 0; i < NUM_USB_CHAN_IN; i++) c_audio <: sampsFromAudioToUsb[i]; -} diff --git a/examples/xua_lite_example/xua_lite/xua_buffer_lite.xc b/examples/xua_lite_example/xua_lite/xua_buffer_lite.xc deleted file mode 100644 index 597cb938..00000000 --- a/examples/xua_lite_example/xua_lite/xua_buffer_lite.xc +++ /dev/null @@ -1,384 +0,0 @@ -#include -#include -#include - -#include "xua_commands.h" -#include "xud.h" -#include "testct_byref.h" -#define DEBUG_UNIT XUA_LITE_BUFFER -#define DEBUG_PRINT_ENABLE_XUA_LITE_BUFFER 1 -#include "debug_print.h" -#include "xua.h" -#include "fifo_impl.h" -#include "xua_ep0_wrapper.h" -#include "rate_controller.h" -#include "xua_buffer_lite.h" - - -extern "C"{ -void XUA_Endpoint0_lite_init(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, - chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_); -void XUA_Endpoint0_lite_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, - chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_, unsigned *input_interface_num, unsigned *output_interface_num); -} -#pragma select handler -void XUD_GetSetupData_Select(chanend c, XUD_ep e_out, unsigned &length, XUD_Result_t &result); - -extern XUD_ep ep0_out; -extern XUD_ep ep0_in; - -#if 0 -//Unsafe to allow us to use fifo API without local unsafe scope -unsafe void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, chanend ?c_feedback, chanend c_aud_in, chanend c_sof, in port p_for_mclk_count, streaming chanend c_audio_hub) { - - debug_printf("%d\n", MAX_OUT_SAMPLES_PER_SOF_PERIOD); - - //These buffers are unions so we can access them as different types - union buffer_aud_out{ - unsigned char bytes[OUT_AUDIO_BUFFER_SIZE_BYTES]; - short short_words[OUT_AUDIO_BUFFER_SIZE_BYTES / 2]; - long long_words[OUT_AUDIO_BUFFER_SIZE_BYTES / 4]; - }buffer_aud_out; - union buffer_aud_in{ - unsigned char bytes[IN_AUDIO_BUFFER_SIZE_BYTES]; - short short_words[IN_AUDIO_BUFFER_SIZE_BYTES / 2]; - unsigned long long_words[IN_AUDIO_BUFFER_SIZE_BYTES / 4]; - }buffer_aud_in; - - unsigned in_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES; - unsigned out_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES; - - //Asynch feedback calculation - unsigned sof_count = 0; - unsigned mclk_port_counter_old = 0; - long long feedback_value = 0; - unsigned mod_from_last_time = 0; - const unsigned mclk_hz = MCLK_48; - unsigned int fb_clocks[1] = {0}; - - //Adapative device clock control - int clock_nudge = 0; - pid_state_t pid_state = {0, 0}; - - //Endpoints - XUD_ep ep_aud_out = XUD_InitEp(c_aud_out); - XUD_ep ep_aud_in = XUD_InitEp(c_aud_in); - XUD_ep ep_feedback = 0; - if (!isnull(c_feedback)) ep_feedback = XUD_InitEp(c_feedback); - - unsigned num_samples_received_from_host = 0; - unsigned num_samples_to_send_to_host = 0; - - short samples_in_short[NUM_USB_CHAN_IN] = {0}; - short samples_out_short[NUM_USB_CHAN_OUT] = {0}; - - #define c_audioControl null - #define dfuInterface null - XUA_Endpoint0_lite_init(c_ep0_out, c_ep0_in, c_audioControl, null, null, null, dfuInterface); - unsigned char sbuffer[120]; //Raw buffer for EP0 data - USB_SetupPacket_t sp; //Parsed setup packet from EP0 - - unsigned input_interface_num = 0; - unsigned output_interface_num = 0; - - //Enable all EPs - XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out.long_words); - XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in.long_words, num_samples_to_send_to_host); - XUD_SetReady_Out(ep0_out, sbuffer); - if (!isnull(c_feedback)) XUD_SetReady_InPtr(ep_feedback, (unsigned)fb_clocks, (AUDIO_CLASS == 2) ? 4 : 3); - - - //Send initial samples so audiohub is not blocked - for (int i = 0; i < 2 * (NUM_USB_CHAN_OUT + (XUA_ADAPTIVE != 0 ? 1 : 0)); i++) c_audio_hub <: 0; - - //FIFOs from EP buffers to audio - short host_to_device_fifo_storage[MAX_OUT_SAMPLES_PER_SOF_PERIOD * 2]; - short device_to_host_fifo_storage[MAX_IN_SAMPLES_PER_SOF_PERIOD * 2]; - mem_fifo_short_t host_to_device_fifo = {sizeof(host_to_device_fifo_storage)/sizeof(host_to_device_fifo_storage[0]), host_to_device_fifo_storage, 0, 0}; - mem_fifo_short_t device_to_host_fifo = {sizeof(device_to_host_fifo_storage)/sizeof(device_to_host_fifo_storage[0]), device_to_host_fifo_storage, 0, 0}; - volatile mem_fifo_short_t * unsafe host_to_device_fifo_ptr = &host_to_device_fifo; - volatile mem_fifo_short_t * unsafe device_to_host_fifo_ptr = &device_to_host_fifo; - - //XUD transaction variables passed in by reference - XUD_Result_t result; - unsigned length = 0; - unsigned u_tmp; //For select channel input by ref on EP0 - int s_tmp; //For select on channel from audiohub - while(1){ - #pragma ordered - select{ - //Handle EP0 requests - case XUD_GetSetupData_Select(c_ep0_out, ep0_out, length, result): - timer tmr; int t0, t1; tmr :> t0; - - debug_printf("ep0, result: %d, length: %d\n", result, length); //-1 reset, 0 ok, 1 error - USB_ParseSetupPacket(sbuffer, sp); //Parse data buffer end populate SetupPacket struct - - XUA_Endpoint0_lite_loop(result, sp, c_ep0_out, c_ep0_in, c_audioControl, null/*mix*/, null/*clk*/, null/*EA*/, dfuInterface, &input_interface_num, &output_interface_num); - XUD_SetReady_Out(ep0_out, sbuffer); - tmr :> t1; debug_printf("c%d\n", t1 - t0); - - break; - - //SOF handling - case inuint_byref(c_sof, u_tmp): - timer tmr; int t0, t1; tmr :> t0; - unsigned mclk_port_counter = 0; - asm volatile(" getts %0, res[%1]" : "=r" (mclk_port_counter) : "r" (p_for_mclk_count)); - if (!isnull(c_feedback)) do_feedback_calculation(sof_count, mclk_hz, mclk_port_counter, mclk_port_counter_old, feedback_value, mod_from_last_time, fb_clocks); - sof_count++; - tmr :> t1; debug_printf("s%d\n", t1 - t0); - - break; - - //Receive samples from host - case XUD_GetData_Select(c_aud_out, ep_aud_out, length, result): - timer tmr; int t0, t1; tmr :> t0; - - num_samples_received_from_host = length / out_subslot_size; - - fifo_ret_t ret = fifo_block_push_short(host_to_device_fifo_ptr, buffer_aud_out.short_words, num_samples_received_from_host); - if (ret != FIFO_SUCCESS) debug_printf("h2d full\n"); - num_samples_to_send_to_host = num_samples_received_from_host; - - int fill_level = fifo_get_fill_short(host_to_device_fifo_ptr); - if (isnull(c_feedback)) do_clock_nudge_pdm(do_rate_control(fill_level, &pid_state), &clock_nudge); - - //Mark EP as ready for next frame from host - XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out.long_words); - tmr :> t1; debug_printf("o%d\n", t1 - t0); - break; - - //Send asynch explicit feedback value, but only if enabled - case !isnull(c_feedback) => XUD_SetData_Select(c_feedback, ep_feedback, result): - timer tmr; int t0, t1; tmr :> t0; - - XUD_SetReady_In(ep_feedback, (fb_clocks, unsigned char[]), (AUDIO_CLASS == 2) ? 4 : 3); - //debug_printf("0x%x\n", fb_clocks[0]); - tmr :> t1; debug_printf("f%d\n", t1 - t0); - - break; - - //Send samples to host - case XUD_SetData_Select(c_aud_in, ep_aud_in, result): - timer tmr; int t0, t1; tmr :> t0; - - if (output_interface_num == 0) num_samples_to_send_to_host = (DEFAULT_FREQ / SOF_FREQ_HZ) * NUM_USB_CHAN_IN; - - fifo_ret_t ret = fifo_block_pop_short(device_to_host_fifo_ptr, buffer_aud_in.short_words, num_samples_received_from_host); - if (ret != FIFO_SUCCESS) debug_printf("d2h empty\n"); - - //Populate the input buffer ready for the next read - //pack_samples_to_buff(loopback_samples, num_samples_to_send_to_host, in_subslot_size, buffer_aud_in); - //Use the number of samples we received last time so we are always balanced (assumes same in/out count) - - unsigned input_buffer_size = num_samples_to_send_to_host * in_subslot_size; - XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in.long_words, input_buffer_size); //loopback - num_samples_to_send_to_host = 0; - tmr :> t1; debug_printf("i%d\n", t1 - t0); - - break; - - //Exchange samples with audiohub. Note we are using channel buffering here to act as a FIFO - case c_audio_hub :> s_tmp: - timer tmr; int t0, t1; tmr :> t0; - samples_in_short[0] = s_tmp >> 16; - for (int i = 1; i < NUM_USB_CHAN_IN; i++){ - c_audio_hub :> s_tmp; - samples_in_short[i] = s_tmp >> 16; - } - fifo_ret_t ret = fifo_block_pop_short(host_to_device_fifo_ptr, samples_out_short, NUM_USB_CHAN_OUT); - if (ret != FIFO_SUCCESS && output_interface_num != 0) debug_printf("h2d empty\n"); - for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: (int)samples_out_short[i] << 16; - if (XUA_ADAPTIVE) c_audio_hub <: clock_nudge; - ret = fifo_block_push_short(device_to_host_fifo_ptr, samples_in_short, NUM_USB_CHAN_IN); - if (ret != FIFO_SUCCESS && input_interface_num != 0) debug_printf("d2h full\n"); - tmr :> t1; debug_printf("a%d\n", t1 - t0); - break; - } - } -} -#endif -extern port p_sda; - -[[combinable]] -//Unsafe to allow us to use fifo API without local unsafe scope -unsafe void XUA_Buffer_lite2(server ep0_control_if i_ep0_ctl, chanend c_aud_out, chanend ?c_feedback, chanend c_aud_in, chanend c_sof, in port p_for_mclk_count, streaming chanend c_audio_hub) { - - debug_printf("%d\n", MAX_OUT_SAMPLES_PER_SOF_PERIOD); - - //These buffers are unions so we can access them as different types - union buffer_aud_out{ - unsigned char bytes[OUT_AUDIO_BUFFER_SIZE_BYTES]; - short short_words[OUT_AUDIO_BUFFER_SIZE_BYTES / 2]; - long long_words[OUT_AUDIO_BUFFER_SIZE_BYTES / 4]; - }buffer_aud_out; - union buffer_aud_in{ - unsigned char bytes[IN_AUDIO_BUFFER_SIZE_BYTES]; - short short_words[IN_AUDIO_BUFFER_SIZE_BYTES / 2]; - unsigned long long_words[IN_AUDIO_BUFFER_SIZE_BYTES / 4]; - }buffer_aud_in; - - unsigned in_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES; - unsigned out_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES; - - //Asynch feedback calculation - unsigned sof_count = 0; - unsigned mclk_port_counter_old = 0; - long long feedback_value = 0; - unsigned mod_from_last_time = 0; - const unsigned mclk_hz = MCLK_48; - unsigned int fb_clocks[1] = {0}; - - //Adapative device clock control - int clock_nudge = 0; - pid_state_t pid_state = {0, 0}; - - - //Endpoints - XUD_ep ep_aud_out = XUD_InitEp(c_aud_out); - XUD_ep ep_aud_in = XUD_InitEp(c_aud_in); - XUD_ep ep_feedback = 0; - if (!isnull(c_feedback)) ep_feedback = XUD_InitEp(c_feedback); - - unsigned num_samples_received_from_host = 0; - unsigned num_samples_to_send_to_host = 0; - - unsigned input_interface_num = 0; - unsigned output_interface_num = 0; - - //Enable all EPs - XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out.long_words); - XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in.long_words, num_samples_to_send_to_host); - if (!isnull(c_feedback)) XUD_SetReady_InPtr(ep_feedback, (unsigned)fb_clocks, (AUDIO_CLASS == 2) ? 4 : 3); - - short samples_in_short[NUM_USB_CHAN_IN] = {0}; - short samples_out_short[NUM_USB_CHAN_OUT] = {0}; - - - //Send initial samples so audiohub is not blocked - const unsigned n_sample_periods_to_preload = 2; - for (int i = 0; i < n_sample_periods_to_preload * (NUM_USB_CHAN_OUT + (XUA_ADAPTIVE != 0 ? 1 : 0)); i++) c_audio_hub <: 0; - - //FIFOs from EP buffers to audio - short host_to_device_fifo_storage[MAX_OUT_SAMPLES_PER_SOF_PERIOD * 2]; - short device_to_host_fifo_storage[MAX_IN_SAMPLES_PER_SOF_PERIOD * 2]; - mem_fifo_short_t host_to_device_fifo = {sizeof(host_to_device_fifo_storage)/sizeof(host_to_device_fifo_storage[0]), host_to_device_fifo_storage, 0, 0}; - mem_fifo_short_t device_to_host_fifo = {sizeof(device_to_host_fifo_storage)/sizeof(device_to_host_fifo_storage[0]), device_to_host_fifo_storage, 0, 0}; - volatile mem_fifo_short_t * unsafe host_to_device_fifo_ptr = &host_to_device_fifo; - volatile mem_fifo_short_t * unsafe device_to_host_fifo_ptr = &device_to_host_fifo; - - //XUD transaction variables passed in by reference - XUD_Result_t result; - unsigned length = 0; - unsigned u_tmp; //For select channel input by ref on EP0 - int s_tmp; //For select on channel from audiohub - while(1){ - select{ - //Handle EP0 requests - case i_ep0_ctl.set_output_interface(unsigned num): - //Reset output FIFO if moving from idle to streaming - if (num != 0 && output_interface_num == 0) fifo_init_short(host_to_device_fifo_ptr); - output_interface_num = num; - debug_printf("output_interface_num: %d\n", num); - break; - - case i_ep0_ctl.set_input_interface(unsigned num): - input_interface_num = num; - debug_printf("input_interface_num: %d\n", num); - break; - - case i_ep0_ctl.set_host_active(unsigned active): - break; - - //SOF handling - case inuint_byref(c_sof, u_tmp): - timer tmr; int t0, t1; tmr :> t0; - unsigned mclk_port_counter = 0; - asm volatile(" getts %0, res[%1]" : "=r" (mclk_port_counter) : "r" (p_for_mclk_count)); - if (!isnull(c_feedback)) do_feedback_calculation(sof_count, mclk_hz, mclk_port_counter, mclk_port_counter_old, feedback_value, mod_from_last_time, fb_clocks); - sof_count++; - //tmr :> t1; debug_printf("s%d\n", t1 - t0); - uint16_t port_counter; - p_sda <: 1 @ port_counter; - p_sda @ port_counter + 100 <: 0; - break; - - //Receive samples from host - case XUD_GetData_Select(c_aud_out, ep_aud_out, length, result): - timer tmr; int t0, t1; tmr :> t0; - - num_samples_received_from_host = length / out_subslot_size; - - if (num_samples_received_from_host != 96) debug_printf("hs: %d\n", num_samples_received_from_host); - - fifo_ret_t ret = fifo_block_push_short_fast(host_to_device_fifo_ptr, buffer_aud_out.short_words, num_samples_received_from_host); - if (ret != FIFO_SUCCESS) debug_printf("h2d full\n"); - num_samples_to_send_to_host = num_samples_received_from_host; - - int fill_level = fifo_get_fill_short(host_to_device_fifo_ptr); - if (isnull(c_feedback)) do_clock_nudge_pdm(do_rate_control(fill_level, &pid_state), &clock_nudge); - - //Mark EP as ready for next frame from host - XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out.long_words); - //tmr :> t1; debug_printf("o%d\n", t1 - t0); - break; - - //Send asynch explicit feedback value, but only if enabled - case !isnull(c_feedback) => XUD_SetData_Select(c_feedback, ep_feedback, result): - timer tmr; int t0, t1; tmr :> t0; - - XUD_SetReady_In(ep_feedback, (fb_clocks, unsigned char[]), (AUDIO_CLASS == 2) ? 4 : 3); - //debug_printf("0x%x\n", fb_clocks[0]); - //tmr :> t1; debug_printf("f%d\n", t1 - t0); - break; - - //Send samples to host - case XUD_SetData_Select(c_aud_in, ep_aud_in, result): - timer tmr; int t0, t1; tmr :> t0; - - //If host is not streaming out, then send a fixed number of samples to host - if (output_interface_num == 0) { - num_samples_to_send_to_host = (DEFAULT_FREQ / SOF_FREQ_HZ) * NUM_USB_CHAN_IN; - int fill_level = fifo_get_fill_short(device_to_host_fifo_ptr); - if (isnull(c_feedback)) do_clock_nudge_pdm(-do_rate_control(fill_level, &pid_state), &clock_nudge); - } - - fifo_ret_t ret = fifo_block_pop_short_fast(device_to_host_fifo_ptr, buffer_aud_in.short_words, num_samples_received_from_host); - if (ret != FIFO_SUCCESS) { - memset(buffer_aud_in.short_words, 0, sizeof(buffer_aud_in.short_words)); - debug_printf("d2h empty\n"); - } - - //Populate the input buffer ready for the next read - //pack_samples_to_buff(loopback_samples, num_samples_to_send_to_host, in_subslot_size, buffer_aud_in); - //Use the number of samples we received last time so we are always balanced (assumes same in/out count) - - unsigned input_buffer_size = num_samples_to_send_to_host * in_subslot_size; - XUD_SetReady_InPtr(ep_aud_in, (unsigned) buffer_aud_in.long_words, input_buffer_size); //loopback - num_samples_to_send_to_host = 0; - //tmr :> t1; debug_printf("i%d\n", t1 - t0); - break; - - //Exchange samples with audiohub. Note we are using channel buffering here to act as a FIFO - case c_audio_hub :> s_tmp: - timer tmr; int t0, t1; tmr :> t0; - samples_in_short[0] = s_tmp >> 16; - for (int i = 1; i < NUM_USB_CHAN_IN; i++){ - c_audio_hub :> s_tmp; - samples_in_short[i] = s_tmp >> 16; - } - fifo_ret_t ret = fifo_block_pop_short(host_to_device_fifo_ptr, samples_out_short, NUM_USB_CHAN_OUT); - if (ret != FIFO_SUCCESS && output_interface_num != 0) { - memset(samples_out_short, 0, sizeof(samples_out_short)); - debug_printf("h2d empty\n"); - } - for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: (int)samples_out_short[i] << 16; - if (XUA_ADAPTIVE) c_audio_hub <: clock_nudge; - ret = fifo_block_push_short(device_to_host_fifo_ptr, samples_in_short, NUM_USB_CHAN_IN); - if (ret != FIFO_SUCCESS && input_interface_num != 0) debug_printf("d2h full\n"); - //tmr :> t1; debug_printf("a%d\n", t1 - t0); - break; - } - } -} diff --git a/examples/xua_lite_example/xua_lite/xua_buffer_pack.h b/examples/xua_lite_example/xua_lite/xua_buffer_pack.h deleted file mode 100644 index 36fc2f33..00000000 --- a/examples/xua_lite_example/xua_lite/xua_buffer_pack.h +++ /dev/null @@ -1,65 +0,0 @@ -//Helper to disassemble USB packets into 32b left aligned audio samples -#pragma unsafe arrays -static inline void unpack_buff_to_samples(unsigned char input[], const unsigned n_samples, const unsigned slot_size, int output[]){ - switch(slot_size){ - case 4: - for (int i = 0; i < n_samples; i++){ - unsigned base = i * 4; - output[i] = (input[base + 3] << 24) | (input[base + 2] << 16) | (input[base + 1] << 8) | input[base + 0]; - } - break; - case 3: - for (int i = 0; i < n_samples; i++){ - unsigned base = i * 3; - output[i] = (input[base + 2] << 24) | (input[base + 1] << 16) | (input[base + 0] << 8); - } - break; - case 2: - for (int i = 0; i < n_samples; i++){ - unsigned base = i * 2; - output[i] = (input[base + 1] << 24) | (input[base + 0] << 16); - } - break; - default: - debug_printf("Invalid slot_size\n"); - break; - } -} - -//Helper to assemble USB packets from 32b left aligned audio samples -#pragma unsafe arrays -static inline void pack_samples_to_buff(int input[], const unsigned n_samples, const unsigned slot_size, unsigned char output[]){ - switch(slot_size){ - case 4: - for (int i = 0; i < n_samples; i++){ - unsigned base = i * 4; - unsigned in_word = (unsigned)input[i]; - output[base + 0] = in_word & 0xff; - output[base + 1] = (in_word & 0xff00) >> 8; - output[base + 2] = (in_word & 0xff0000) >> 16; - output[base + 3] = (in_word) >> 24; - } - break; - case 3: - for (int i = 0; i < n_samples; i++){ - unsigned base = i * 3; - unsigned in_word = (unsigned)input[i]; - output[base + 0] = (in_word & 0xff00) >> 8; - output[base + 1] = (in_word & 0xff0000) >> 16; - output[base + 2] = (in_word) >> 24; - } - break; - case 2: - for (int i = 0; i < n_samples; i++){ - unsigned base = i * 2; - unsigned in_word = (unsigned)input[i]; - output[base + 0] = (in_word & 0xff0000) >> 16; - output[base + 1] = (in_word) >> 24; - } - break; - default: - debug_printf("Invalid slot_size\n"); - break; - } -} - diff --git a/lib_xua/LICENSE.rst b/lib_xua/LICENSE.rst new file mode 100644 index 00000000..ca48f20f --- /dev/null +++ b/lib_xua/LICENSE.rst @@ -0,0 +1,84 @@ +******************************* +XMOS PUBLIC LICENCE: Version 1 +******************************* + +Subject to the conditions and limitations below, permission is hereby granted by XMOS LIMITED (“XMOS”), free of charge, to any person or entity obtaining a copy of the XMOS Software. + +**1. Definitions** + +**“Applicable Patent Rights”** means: (a) where XMOS is the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to XMOS and (ii) that cover subject matter contained in the Software, but only to the extent it is necessary to use, reproduce or distribute the Software without infringement; and (b) where you are the grantor of the rights, (i) claims of patents that are now or in future owned by or assigned to you and (ii) that cover the subject matter contained in your Derivatives, taken alone or in combination with the Software. + +**“Compiled Code”** means any compiled, binary, machine readable or executable version of the Source Code. + +**“Contributor”** means any person or entity that creates or contributes to the creation of Derivatives. + +**“Derivatives”** means any addition to, deletion from and/or change to the substance, structure of the Software, any previous Derivatives, the combination of the Derivatives and the Software and/or any respective portions thereof. + +**“Source Code”** means the human readable code that is suitable for making modifications but excluding any Compiled Code. + +**“Software”** means the software and associated documentation files which XMOS makes available and which contain a notice identifying the software as original XMOS software and referring to the software being subject to the terms of this XMOS Public Licence. + +This Licence refers to XMOS Software and does not relate to any XMOS hardware or devices which are protected by intellectual property rights (including patent and trade marks) which may be sold to you under a separate agreement. + + +**2. Licence** + +**Permitted Uses, Conditions and Restrictions.** Subject to the conditions below, XMOS grants you a worldwide, royalty free, non-exclusive licence, to the extent of any Patent Rights to do the following: + +2.1 **Unmodified Software.** You may use, copy, display, publish, distribute and make available unmodified copies of the Software: + +2.1.1 for personal or academic, non-commercial purposes; or + +2.1.2 for commercial purposes provided the Software is at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.1.1 and 2.1.2): + +(a) you must retain and reproduce in all copies of the Software the copyright and proprietary notices and disclaimers of XMOS as they appear in the Software, and keep intact all notices and disclaimers in the Software files that refer to this Licence; and + +(b) you must include a copy of this Licence with every copy of the Software and documentation you publish, distribute and make available and you may not offer or impose any terms on such Software that alter or restrict this Licence or the intent of such Licence, except as permitted below (Additional Terms). + +The licence above does not include any Compiled Code which XMOS may make available under a separate support and licence agreement. + +2.2 **Derivatives.** You may create and modify Derivatives and use, copy, display, publish, distribute and make available Derivatives: + +2.2.1 for personal or academic, non-commercial purposes; or + +2.2.2 for commercial purposes, provided the Derivatives are at all times used on a device designed, licensed or developed by XMOS and, provided that in each instance (2.2.1 and 2.2.2): + +(a) you must comply with the terms of clause 2.1 with respect to the Derivatives; + +(b) you must copy (to the extent it doesn’t already exist) the notice below in each file of the Derivatives, and ensure all the modified files carry prominent notices stating that you have changed the files and the date of any change; and + +(c) if you sublicence, distribute or otherwise make the Software and/or the Derivatives available for commercial purposes, you must provide that the Software and Derivatives are at all times used on a device designed, licensed or developed by XMOS. + +Without limitation to these terms and clause 3 below, the Source Code and Compiled Code to your Derivatives may at your discretion (but without obligation) be released, copied, displayed, published, distributed and made available; and if you elect to do so, it must be under the terms of this Licence including the terms of the licence at clauses 2.2.1, 2.2.2 and clause 3 below. + +2.3 **Distribution of Executable Versions.** If you distribute or make available Derivatives, you must include a prominent notice in the code itself as well as in all related documentation, stating that the Source Code of the Software from which the Derivatives are based is available under the terms of this Licence, with information on how and where to obtain such Source Code. + +**3. Your Grant of Rights.** In consideration and as a condition to this Licence, you grant to any person or entity receiving or distributing any Derivatives, a non-exclusive, royalty free, perpetual, irrevocable license under your Applicable Patent Rights and all other intellectual property rights owned or controlled by you, to use, copy, display, publish, distribute and make available your Derivatives of the same scope and extent as XMOS’s licence under clause 2.2 above. + +**4. Combined Products.** You may create a combined product by combining Software, Derivatives and other code not covered by this Licence as a single application or product. In such instance, you must comply with the requirements of this Licence for any portion of the Software and/or Derivatives. + +**5. Additional Terms.** You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations and/or other rights consistent with the term of this Licence (“Additional Terms”) to any legitimate recipients of the Software and/or Derivatives. The terms on which you provide such Additional Terms are on your sole responsibility and you shall indemnify, defend and hold XMOS harmless against any claims asserted against XMOS. + +**6. New Versions.** XMOS may publish revised and/or new versions of this Licence from time to time to accommodate changes to the Licence terms, new versions, updates and bug fixes of the Software. Each version will be given a distinguishing version number. Once Software has been published under a particular version of this Licence, you may continue to use it under the terms of that version. You may also choose to use the latest version of the Software under any subsequent version published by XMOS. Only XMOS shall have the right to modify these terms. + +**7. IPR and Ownership** +Any rights, including all intellectual property rights and all trademarks not expressly granted herein are reserved in full by the authors or copyright holders. Any requests for additional permissions by XMOS including any rights to use XMOS trademarks, should be made (without obligation) to XMOS at **support@xmos.com** + +Nothing herein shall limit any rights that XMOS is otherwise entitled to under the doctrines of patent exhaustion, implied license, or legal estoppel. Neither the name of the authors, the copyright holders or any contributors may be used to endorse or promote any Derivatives from this Software without specific written permission. Any attempt to deal with the Software which does not comply with this Licence shall be void and shall automatically terminate any rights granted under this licence (including any licence of any intellectual property rights granted herein). +Subject to the licences granted under this Licence any Contributor retains all rights, title and interest in and to any Derivatives made by Contributor subject to the underlying rights of XMOS in the Software. XMOS shall retain all rights, title and interest in the Software and any Derivatives made by XMOS (“XMOS Derivatives”). XMOS Derivatives will not automatically be subject to this Licence and XMOS shall be entitled to licence such rights on any terms (without obligation) as it sees fit. + +**8. Termination** + +8.1 This Licence will automatically terminate immediately, without notice to you, if: + +(a) you fail to comply with the terms of this Licence; and/or + +(b) you directly or indirectly commence any action for patent or intellectual property right infringement against XMOS, or any parent, group, affiliate or subsidiary of XMOS; provided XMOS did not first commence an action or patent infringement against you in that instance; and/or + +(c) the terms of this Licence are held by any court of competent jurisdiction to be unenforceable in whole or in part. + +**9. Critical Applications.** Unless XMOS has agreed in writing with you an agreement specifically governing use of the Goods in military, aerospace, automotive or medically related functions (collectively and individually hereinafter referred to as "Special Use"), any permitted use of the Software excludes Special Use. Notwithstanding any agreement between XMOS and you for Special Use, Special Use shall be at your own risk, and you shall fully indemnify XMOS against any damages, losses, costs and claims (direct and indirect) arising out of any Special Use. + +**10. NO WARRANTY OR SUPPORT.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL XMOS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, WARRANTY, CIVIL TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE INCLUDING GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES EVEN IF SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND NOT WITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE. IN SOME JURISDICTIONS PARTIES ARE UNABLE TO LIMIT LIABILTY IN THIS WAY, IF THIS APPLIES TO YOUR JURISDICTION THIS LIABILITY CLAUSE ABOVE MAY NOT APPLY. NOTWITHSTANDING THE ABOVE, IN NO EVENT SHALL XMOS’s TOTAL LIABILITY TO YOU FOR ALL DAMAGES, LOSS OR OTHERWISE EXCEED $50. + +**11. Governing Law and Jurisdiction.** This Licence constitutes the entire agreement between the parties with respect to the subject matter hereof. The Licence shall be governed by the laws of England and the conflict of laws and UN Convention on Contracts for the International Sale of Goods, shall not apply. diff --git a/lib_xua/LICENSE.txt b/lib_xua/LICENSE.txt deleted file mode 100644 index 3932a9ae..00000000 --- a/lib_xua/LICENSE.txt +++ /dev/null @@ -1,135 +0,0 @@ -Software Release License Agreement - -Copyright (c) 2017-2019, XMOS, All rights reserved. - -BY ACCESSING, USING, INSTALLING OR DOWNLOADING THE XMOS SOFTWARE, YOU AGREE TO BE BOUND BY THE FOLLOWING TERMS. IF YOU DO NOT AGREE TO THESE, DO NOT ATTEMPT TO DOWNLOAD, ACCESS OR USE THE XMOS Software. - -Parties: - -(1) XMOS Limited, incorporated and registered in England and Wales with company number 5494985 whose registered office is 107 Cheapside, London, EC2V 6DN (XMOS). - -(2) An individual or legal entity exercising permissions granted by this License (Customer). - -If you are entering into this Agreement on behalf of another legal entity such as a company, partnership, university, college etc. (for example, as an employee, student or consultant), you warrant that you have authority to bind that entity. - -1. Definitions - -"License" means this Software License and any schedules or annexes to it. - -"License Fee" means the fee for the XMOS Software as detailed in any schedules or annexes to this Software License - -"Licensee Modifications" means all developments and modifications of the XMOS Software developed independently by the Customer. - -"XMOS Modifications" means all developments and modifications of the XMOS Software developed or co-developed by XMOS. - -"XMOS Hardware" means any XMOS hardware devices supplied by XMOS from time to time and/or the particular XMOS devices detailed in any schedules or annexes to this Software License. - -"XMOS Software" comprises the XMOS owned circuit designs, schematics, source code, object code, reference designs, (including related programmer comments and documentation, if any), error corrections, improvements, modifications (including XMOS Modifications) and updates. - -The headings in this License do not affect its interpretation. Save where the context otherwise requires, references to clauses and schedules are to clauses and schedules of this License. - -Unless the context otherwise requires: - -- references to XMOS and the Customer include their permitted successors and assigns; -- references to statutory provisions include those statutory provisions as amended or re-enacted; and -- references to any gender include all genders. - -Words in the singular include the plural and in the plural include the singular. - -2. License - -XMOS grants the Customer a non-exclusive license to use, develop, modify and distribute the XMOS Software with, or for the purpose of being used with, XMOS Hardware. - -Open Source Software (OSS) must be used and dealt with in accordance with any license terms under which OSS is distributed. - -3. Consideration - -In consideration of the mutual obligations contained in this License, the parties agree to its terms. - -4. Term - -Subject to clause 12 below, this License shall be perpetual. - -5. Restrictions on Use - -The Customer will adhere to all applicable import and export laws and regulations of the country in which it resides and of the United States and United Kingdom, without limitation. The Customer agrees that it is its responsibility to obtain copies of and to familiarise itself fully with these laws and regulations to avoid violation. - -6. Modifications - -The Customer will own all intellectual property rights in the Licensee Modifications but will undertake to provide XMOS with any fixes made to correct any bugs found in the XMOS Software on a non-exclusive, perpetual and royalty free license basis. - -XMOS will own all intellectual property rights in the XMOS Modifications. -The Customer may only use the Licensee Modifications and XMOS Modifications on, or in relation to, XMOS Hardware. - -7. Support - -Support of the XMOS Software may be provided by XMOS pursuant to a separate support agreement. - -8. Warranty and Disclaimer - -The XMOS Software is provided "AS IS" without a warranty of any kind. XMOS and its licensors' entire liability and Customer's exclusive remedy under this warranty to be determined in XMOS's sole and absolute discretion, will be either (a) the corrections of defects in media or replacement of the media, or (b) the refund of the license fee paid (if any). - -Whilst XMOS gives the Customer the ability to load their own software and applications onto XMOS devices, the security of such software and applications when on the XMOS devices is the Customer's own responsibility and any breach of security shall not be deemed a defect or failure of the hardware. XMOS shall have no liability whatsoever in relation to any costs, damages or other losses Customer may incur as a result of any breaches of security in relation to your software or applications. - -XMOS AND ITS LICENSORS DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY/ SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID UNDER APPLICABLE LAW. - -9. High Risk Activities - -The XMOS Software is not designed or intended for use in conjunction with on-line control equipment in hazardous environments requiring fail-safe performance, including without limitation the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, life support machines, or weapons systems (collectively "High Risk Activities") in which the failure of the XMOS Software could lead directly to death, personal injury, or severe physical or environmental damage. XMOS and its licensors specifically disclaim any express or implied warranties relating to use of the XMOS Software in connection with High Risk Activities. - -10. Liability - -TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, NEITHER XMOS NOR ITS LICENSORS SHALL BE LIABLE FOR ANY LOST REVENUE, BUSINESS, PROFIT, CONTRACTS OR DATA, ADMINISTRATIVE OR OVERHEAD EXPENSES, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THEORY OF LIABILITY ARISING OUT OF THIS LICENSE, EVEN IF XMOS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event shall XMOS's liability to the Customer whether in contract, tort (including negligence), or otherwise exceed the License Fee. - -Customer agrees to indemnify, hold harmless, and defend XMOS and its licensors from and against any claims or lawsuits, including attorneys' fees and any other liabilities, demands, proceedings, damages, losses, costs, expenses fines and charges which are made or brought against or incurred by XMOS as a result of your use or distribution of the Licensee Modifications or your use or distribution of XMOS Software, or any development of it, other than in accordance with the terms of this License. - -11. Ownership - -The copyrights and all other intellectual and industrial property rights for the protection of information with respect to the XMOS Software (including the methods and techniques on which they are based) are retained by XMOS and/or its licensors. Nothing in this Agreement serves to transfer such rights. Customer may not sell, mortgage, underlet, sublease, sublicense, lend or transfer possession of the XMOS Software in any way whatsoever to any third party who is not bound by this Agreement. - -12. Termination - -Either party may terminate this License at any time on written notice to the other if the other: - -- is in material or persistent breach of any of the terms of this License and either that breach is incapable of remedy, or the other party fails to remedy that breach within 30 days after receiving written notice requiring it to remedy that breach; or - -- is unable to pay its debts (within the meaning of section 123 of the Insolvency Act 1986), or becomes insolvent, or is subject to an order or a resolution for its liquidation, administration, winding-up or dissolution (otherwise than for the purposes of a solvent amalgamation or reconstruction), or has an administrative or other receiver, manager, trustee, liquidator, administrator or similar officer appointed over all or any substantial part of its assets, or enters into or proposes any composition or arrangement with its creditors generally, or is subject to any analogous event or proceeding in any applicable jurisdiction. - -Termination by either party in accordance with the rights contained in clause 12 shall be without prejudice to any other rights or remedies of that party accrued prior to termination. - -On termination for any reason: - -- all rights granted to the Customer under this License shall cease; -- the Customer shall cease all activities authorised by this License; -- the Customer shall immediately pay any sums due to XMOS under this License; and -- the Customer shall immediately destroy or return to the XMOS (at the XMOS's option) all copies of the XMOS Software then in its possession, custody or control and, in the case of destruction, certify to XMOS that it has done so. - -Clauses 5, 8, 9, 10 and 11 shall survive any effective termination of this Agreement. - -13. Third party rights - -No term of this License is intended to confer a benefit on, or to be enforceable by, any person who is not a party to this license. - -14. Confidentiality and publicity - -Each party shall, during the term of this License and thereafter, keep confidential all, and shall not use for its own purposes nor without the prior written consent of the other disclose to any third party any, information of a confidential nature (including, without limitation, trade secrets and information of commercial value) which may become known to such party from the other party and which relates to the other party, unless such information is public knowledge or already known to such party at the time of disclosure, or subsequently becomes public knowledge other than by breach of this license, or subsequently comes lawfully into the possession of such party from a third party. - -The terms of this license are confidential and may not be disclosed by the Customer without the prior written consent of XMOS. -The provisions of clause 14 shall remain in full force and effect notwithstanding termination of this license for any reason. - -15. Entire agreement - -This License and the documents annexed as appendices to this License or otherwise referred to herein contain the whole agreement between the parties relating to the subject matter hereof and supersede all prior agreements, arrangements and understandings between the parties relating to that subject matter. - -16. Assignment - -The Customer shall not assign this License or any of the rights granted under it without XMOS's prior written consent. - -17. Governing law and jurisdiction - -This License shall be governed by and construed in accordance with English law and each party hereby submits to the non-exclusive jurisdiction of the English courts. - -This License has been entered into on the date stated at the beginning of it. - -Schedule -XMOS lib_xua software diff --git a/lib_xua/api/xua.h b/lib_xua/api/xua.h index 92cdbe6f..c52ff1a7 100644 --- a/lib_xua/api/xua.h +++ b/lib_xua/api/xua.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __XUA_H__ #define __XUA_H__ diff --git a/lib_xua/api/xua_audiohub.h b/lib_xua/api/xua_audiohub.h index 9694cc10..e66296cb 100644 --- a/lib_xua/api/xua_audiohub.h +++ b/lib_xua/api/xua_audiohub.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __XUA_AUDIOHUB_H__ #define __XUA_AUDIOHUB_H__ diff --git a/lib_xua/api/xua_buffer.h b/lib_xua/api/xua_buffer.h index eaaef881..302e3f67 100644 --- a/lib_xua/api/xua_buffer.h +++ b/lib_xua/api/xua_buffer.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __XUA_BUFFER_H__ #define __XUA_BUFFER_H__ @@ -58,7 +59,7 @@ void XUA_Buffer( chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , chanend c_hid #endif , chanend c_aud @@ -97,7 +98,7 @@ void XUA_Buffer_Ep(chanend c_aud_out, chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , chanend c_hid #endif #ifdef CHAN_BUFF_CTRL diff --git a/lib_xua/api/xua_conf_default.h b/lib_xua/api/xua_conf_default.h index 677fad9e..38db0d98 100644 --- a/lib_xua/api/xua_conf_default.h +++ b/lib_xua/api/xua_conf_default.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 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 * @author Ross Owen, XMOS Limited @@ -288,6 +289,13 @@ #define PDM_MIC_INDEX (0) #endif +/** + * @brief Size of a frame of microphone data samples. Default: 1 + */ +#ifndef XUA_MIC_FRAME_SIZE +#define XUA_MIC_FRAME_SIZE (1) +#endif + /** * @brief Enable MIDI functionality including buffering, descriptors etc. Default: DISABLED */ @@ -425,10 +433,6 @@ #define HID_CONTROLS (0) #endif -#if defined(HID_CONTROLS) && (HID_CONTROLS == 0) -#undef HID_CONTROLS -#endif - /* @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. @@ -439,6 +443,16 @@ #define CODEC_MASTER (0) #endif +/** + * @brief Serial Number String used by the device + * + * Default: "" + */ +#ifndef SERIAL_STR +#define SERIAL_STR "" +#endif + + /** * @brief Vendor String used by the device. This is also pre-pended to various strings used by the design. * @@ -513,21 +527,21 @@ * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_J -#define BCD_DEVICE_J (0) +#define BCD_DEVICE_J (1) #endif /** * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_M -#define BCD_DEVICE_M (1) +#define BCD_DEVICE_M (2) #endif /** * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_N -#define BCD_DEVICE_N (1) +#define BCD_DEVICE_N (0) #endif /** @@ -1177,7 +1191,7 @@ enum USBEndpointNumber_In #ifdef MIDI ENDPOINT_NUMBER_IN_MIDI, #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) ENDPOINT_NUMBER_IN_HID, #endif #ifdef IAP @@ -1442,6 +1456,12 @@ enum USBEndpointNumber_Out #error Bad DEFAULT_MCLK_FREQ #endif +/* DFU functional descriptor wDetachTimeOut field (milliseconds) + * Time for device to wait for bus reset after DETACH request before reverting to idle state */ +#ifndef DFU_DETACH_TIME_OUT +#define DFU_DETACH_TIME_OUT 250 +#endif + #if ((MCLK_441 % MIN_FREQ) == 0) #define MIN_FREQ_44 MIN_FREQ #define MIN_FREQ_48 ((48000 * 512)/((44100 * 512)/MIN_FREQ)) @@ -1463,4 +1483,3 @@ enum USBEndpointNumber_Out #if (CODEC_MASTER == 1) && (DSD_CHANS_DAC != 0) #error CODEC_MASTER with DSD is currently unsupported #endif - diff --git a/lib_xua/api/xua_conf_full.h b/lib_xua/api/xua_conf_full.h index e3696a6d..ff4bfd0b 100644 --- a/lib_xua/api/xua_conf_full.h +++ b/lib_xua/api/xua_conf_full.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 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__ diff --git a/lib_xua/api/xua_endpoint0.h b/lib_xua/api/xua_endpoint0.h index ed3ffda2..b7cfdfc6 100644 --- a/lib_xua/api/xua_endpoint0.h +++ b/lib_xua/api/xua_endpoint0.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _XUA_ENDPOINT0_H_ #define _XUA_ENDPOINT0_H_ @@ -28,5 +29,105 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioCtrl, chanend ?c_mix_ctl,chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctr, client interface i_dfu ?dfuInterface VENDOR_REQUESTS_PARAMS_DEC_); +/** Function to set the Vendor ID value + * + * \param vid vendor ID value to set +*/ +void XUA_Endpoint0_setVendorId(unsigned short vid); + +/** Function to set the Product ID value + * + * \param pid Product ID value to set +*/ +void XUA_Endpoint0_setProductId(unsigned short pid); + + +/** Function to set the Vendor string + * + * \param vendor_str Vendor string to set +*/ +#ifdef __XC__ +void XUA_Endpoint0_setVendorStr(char * unsafe vendor_str); +#else +void XUA_Endpoint0_setVendorStr(char * vendor_str); +#endif + +/** Function to set the Product string + * + * \param product_str Product string to set +*/ + +#ifdef __XC__ +void XUA_Endpoint0_setProductStr(char * unsafe product_str); +#else +void XUA_Endpoint0_setProductStr(char * product_str); +#endif + +/** Function to set the Serial string + * + * \param serial_str Serial string to set +*/ +#ifdef __XC__ +void XUA_Endpoint0_setSerialStr(char * unsafe serial_str); +#else +void XUA_Endpoint0_setSerialStr(char * serial_str); +#endif + +/** Function to set the BCD device + * + * \param bcdDevice BCD device to set + +*/ + +void XUA_Endpoint0_setBcdDevice(unsigned short bcdDevice); + +/** Function to get the Vendor string + * + * \return vendor string +*/ +#ifdef __XC__ +char * unsafe XUA_Endpoint0_getVendorStr(); +#else +char * XUA_Endpoint0_getVendorStr(); +#endif + +/** Function to get the Product string + * + * \return Product string +*/ +#ifdef __XC__ +char * unsafe XUA_Endpoint0_getProductStr(); +#else +char * XUA_Endpoint0_getProductStr(); +#endif + +/** Function to get the Serial Number string + * + * \return Serial string +*/ +#ifdef __XC__ +char * unsafe XUA_Endpoint0_getSerialStr(); +#else +char * XUA_Endpoint0_getSerialStr(); +#endif + +/** Function to get the Vendor ID + * + * \return Vendor ID +*/ +unsigned short XUA_Endpoint0_getVendorId(); + +/** Function to get the Product ID + * + * \return Product ID +*/ +unsigned short XUA_Endpoint0_getProductId(); + +/** Function to get the BCD device + * + * \return BCD device +*/ +unsigned short XUA_Endpoint0_getBcdDevice(); + #endif #endif diff --git a/lib_xua/api/xua_pdm_mic.h b/lib_xua/api/xua_pdm_mic.h index 4b7704b6..a68dd142 100644 --- a/lib_xua/api/xua_pdm_mic.h +++ b/lib_xua/api/xua_pdm_mic.h @@ -1,4 +1,5 @@ -// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +// Copyright 2015-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef XUA_PDM_MIC_H #define XUA_PDM_MIC_H diff --git a/lib_xua/api/xua_usb_params_funcs.h b/lib_xua/api/xua_usb_params_funcs.h new file mode 100644 index 00000000..dcc018db --- /dev/null +++ b/lib_xua/api/xua_usb_params_funcs.h @@ -0,0 +1,19 @@ +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef __XUA_API_H__ +#define __XUA_API_H__ + +#include + +void set_usb_to_device_rate(uint32_t rate); +void set_device_to_usb_rate(uint32_t rate); +void set_usb_to_device_bit_res(uint32_t rate); +void set_device_to_usb_bit_res(uint32_t rate); + +uint32_t get_usb_to_device_rate(); +uint32_t get_device_to_usb_rate(); +uint32_t get_usb_to_device_bit_res(); +uint32_t get_device_to_usb_bit_res(); + +#endif //__XUA_API_H__ diff --git a/lib_xua/host/xmosdfu/Makefile.Linux32 b/lib_xua/host/xmosdfu/Makefile.Linux32 index 3800d4ab..891d1a57 100644 --- a/lib_xua/host/xmosdfu/Makefile.Linux32 +++ b/lib_xua/host/xmosdfu/Makefile.Linux32 @@ -1,2 +1,3 @@ all: - g++ -m32 -Wall -g -o xmosdfu xmosdfu.cpp -Ilibusb/Linux32 -lusb-1.0 + mkdir -p bin + g++ -m32 -Wall -g -o bin/xmosdfu xmosdfu.cpp -Ilibusb/Linux32 -lusb-1.0 diff --git a/lib_xua/host/xmosdfu/Makefile.Linux64 b/lib_xua/host/xmosdfu/Makefile.Linux64 index dad6c9d8..e9ce426a 100644 --- a/lib_xua/host/xmosdfu/Makefile.Linux64 +++ b/lib_xua/host/xmosdfu/Makefile.Linux64 @@ -1,2 +1,3 @@ all: - g++ -Wall -g -o xmosdfu xmosdfu.cpp -Ilibusb/Linux32 -lusb-1.0 + mkdir -p bin + g++ -Wall -g -o bin/xmosdfu xmosdfu.cpp -Ilibusb/Linux32 -lusb-1.0 diff --git a/lib_xua/host/xmosdfu/Makefile.OSX32 b/lib_xua/host/xmosdfu/Makefile.OSX32 index a9c738a6..0ad48b0d 100644 --- a/lib_xua/host/xmosdfu/Makefile.OSX32 +++ b/lib_xua/host/xmosdfu/Makefile.OSX32 @@ -1,2 +1,3 @@ all: - g++ -g -o xmosdfu xmosdfu.cpp -Ilibusb/OSX32 libusb/OSX32/libusb-1.0.0.dylib -m32 -Wall + mkdir -p bin + g++ -g -o bin/xmosdfu xmosdfu.cpp -Ilibusb/OSX32 libusb/OSX32/libusb-1.0.0.dylib -m32 -Wall diff --git a/lib_xua/host/xmosdfu/Makefile.OSX64 b/lib_xua/host/xmosdfu/Makefile.OSX64 index 07966069..54860178 100644 --- a/lib_xua/host/xmosdfu/Makefile.OSX64 +++ b/lib_xua/host/xmosdfu/Makefile.OSX64 @@ -1,2 +1,3 @@ all: - g++ -g -o xmosdfu xmosdfu.cpp -Ilibusb/OSX64 libusb/OSX64/libusb-1.0.0.dylib -Wall + mkdir -p bin + g++ -g -o bin/xmosdfu xmosdfu.cpp -Ilibusb/OSX64 libusb/OSX64/libusb-1.0.0.dylib -Wall diff --git a/lib_xua/host/xmosdfu/Makefile.Pi b/lib_xua/host/xmosdfu/Makefile.Pi index 6141746e..6996caa0 100644 --- a/lib_xua/host/xmosdfu/Makefile.Pi +++ b/lib_xua/host/xmosdfu/Makefile.Pi @@ -5,4 +5,5 @@ # vendor and product IDs xmosdfu: xmosdfu.cpp - g++ -D_GNU_SOURCE -Wall -g -o xmosdfu -Ilibusb/Rasp -lusb-1.0 -x c xmosdfu.cpp -std=c99 + mkdir -p bin + g++ -D_GNU_SOURCE -Wall -g -o bin/xmosdfu -Ilibusb/Rasp -lusb-1.0 -x c xmosdfu.cpp -std=c99 diff --git a/lib_xua/host/xmosdfu/Makefile.Win32 b/lib_xua/host/xmosdfu/Makefile.Win32 new file mode 100644 index 00000000..2cf6b661 --- /dev/null +++ b/lib_xua/host/xmosdfu/Makefile.Win32 @@ -0,0 +1,31 @@ +# Build tested with Visual Studio 2017 command prompt +# +# Run: nmake /f Makefile.Win32 +# +# NOTE: To run xmosdfu on Windows, libusbK drivers must be installed on the DFU endpoint +# We recommend using the third-party Zadig tool for this. + +COMMON_FLAGS = \ + /D BECLEAR_HOST=1 \ + /I libusb\Win32 \ + /nologo \ + /W4 \ + /WX- \ + /O2 \ + /EHa \ + /D _CRT_SECURE_NO_WARNINGS \ + xmosdfu.cpp \ + +all: xmosdfu + +xmosdfu: + if not exist bin mkdir bin + CL.exe \ + $(COMMON_FLAGS) \ + /Fe"bin\xmosdfu.exe" \ + /link "libusb\Win32\libusb-1.0.lib"" + copy libusb-1.0.dll bin + del *.obj + +clean: + rmdir /s /q bin diff --git a/lib_xua/host/xmosdfu/libusb-1.0.dll b/lib_xua/host/xmosdfu/libusb-1.0.dll new file mode 100644 index 00000000..d58c4be3 Binary files /dev/null and b/lib_xua/host/xmosdfu/libusb-1.0.dll differ diff --git a/lib_xua/host/xmosdfu/libusb/Win32/libusb-1.0.lib b/lib_xua/host/xmosdfu/libusb/Win32/libusb-1.0.lib new file mode 100644 index 00000000..760f13d1 Binary files /dev/null and b/lib_xua/host/xmosdfu/libusb/Win32/libusb-1.0.lib differ diff --git a/lib_xua/host/xmosdfu/libusb/Win32/libusb.h b/lib_xua/host/xmosdfu/libusb/Win32/libusb.h new file mode 100644 index 00000000..430136b2 --- /dev/null +++ b/lib_xua/host/xmosdfu/libusb/Win32/libusb.h @@ -0,0 +1,2039 @@ +/* + * Public libusb header file + * Copyright © 2001 Johannes Erdfelt + * Copyright © 2007-2008 Daniel Drake + * Copyright © 2012 Pete Batard + * Copyright © 2012 Nathan Hjelm + * For more information, please visit: http://libusb.info + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef LIBUSB_H +#define LIBUSB_H + +#ifdef _MSC_VER +/* on MS environments, the inline keyword is available in C++ only */ +#if !defined(__cplusplus) +#define inline __inline +#endif +/* ssize_t is also not available (copy/paste from MinGW) */ +#ifndef _SSIZE_T_DEFINED +#define _SSIZE_T_DEFINED +#undef ssize_t +#ifdef _WIN64 + typedef __int64 ssize_t; +#else + typedef int ssize_t; +#endif /* _WIN64 */ +#endif /* _SSIZE_T_DEFINED */ +#endif /* _MSC_VER */ + +/* stdint.h is not available on older MSVC */ +#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H)) +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +#else +#include +#endif + +#if !defined(_WIN32_WCE) +#include +#endif + +#if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__HAIKU__) +#include +#endif + +#include +#include + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#define ZERO_SIZED_ARRAY /* [] - valid C99 code */ +#else +#define ZERO_SIZED_ARRAY 0 /* [0] - non-standard, but usually working code */ +#endif + +/* 'interface' might be defined as a macro on Windows, so we need to + * undefine it so as not to break the current libusb API, because + * libusb_config_descriptor has an 'interface' member + * As this can be problematic if you include windows.h after libusb.h + * in your sources, we force windows.h to be included first. */ +#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) +#include +#if defined(interface) +#undef interface +#endif +#if !defined(__CYGWIN__) +#include +#endif +#endif + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) +#define LIBUSB_DEPRECATED_FOR(f) \ + __attribute__((deprecated("Use " #f " instead"))) +#elif __GNUC__ >= 3 +#define LIBUSB_DEPRECATED_FOR(f) __attribute__((deprecated)) +#else +#define LIBUSB_DEPRECATED_FOR(f) +#endif /* __GNUC__ */ + +/** \def LIBUSB_CALL + * \ingroup libusb_misc + * libusb's Windows calling convention. + * + * Under Windows, the selection of available compilers and configurations + * means that, unlike other platforms, there is not one true calling + * convention (calling convention: the manner in which parameters are + * passed to functions in the generated assembly code). + * + * Matching the Windows API itself, libusb uses the WINAPI convention (which + * translates to the stdcall convention) and guarantees that the + * library is compiled in this way. The public header file also includes + * appropriate annotations so that your own software will use the right + * convention, even if another convention is being used by default within + * your codebase. + * + * The one consideration that you must apply in your software is to mark + * all functions which you use as libusb callbacks with this LIBUSB_CALL + * annotation, so that they too get compiled for the correct calling + * convention. + * + * On non-Windows operating systems, this macro is defined as nothing. This + * means that you can apply it to your code without worrying about + * cross-platform compatibility. + */ +/* LIBUSB_CALL must be defined on both definition and declaration of libusb + * functions. You'd think that declaration would be enough, but cygwin will + * complain about conflicting types unless both are marked this way. + * The placement of this macro is important too; it must appear after the + * return type, before the function name. See internal documentation for + * API_EXPORTED. + */ +#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) +#define LIBUSB_CALL WINAPI +#else +#define LIBUSB_CALL +#endif + +/** \def LIBUSB_API_VERSION + * \ingroup libusb_misc + * libusb's API version. + * + * Since version 1.0.13, to help with feature detection, libusb defines + * a LIBUSB_API_VERSION macro that gets increased every time there is a + * significant change to the API, such as the introduction of a new call, + * the definition of a new macro/enum member, or any other element that + * libusb applications may want to detect at compilation time. + * + * The macro is typically used in an application as follows: + * \code + * #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01001234) + * // Use one of the newer features from the libusb API + * #endif + * \endcode + * + * Internally, LIBUSB_API_VERSION is defined as follows: + * (libusb major << 24) | (libusb minor << 16) | (16 bit incremental) + */ +#define LIBUSB_API_VERSION 0x01000106 + +/* The following is kept for compatibility, but will be deprecated in the future */ +#define LIBUSBX_API_VERSION LIBUSB_API_VERSION + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \ingroup libusb_misc + * Convert a 16-bit value from host-endian to little-endian format. On + * little endian systems, this function does nothing. On big endian systems, + * the bytes are swapped. + * \param x the host-endian value to convert + * \returns the value in little-endian byte order + */ +static inline uint16_t libusb_cpu_to_le16(const uint16_t x) +{ + union { + uint8_t b8[2]; + uint16_t b16; + } _tmp; + _tmp.b8[1] = (uint8_t) (x >> 8); + _tmp.b8[0] = (uint8_t) (x & 0xff); + return _tmp.b16; +} + +/** \def libusb_le16_to_cpu + * \ingroup libusb_misc + * Convert a 16-bit value from little-endian to host-endian format. On + * little endian systems, this function does nothing. On big endian systems, + * the bytes are swapped. + * \param x the little-endian value to convert + * \returns the value in host-endian byte order + */ +#define libusb_le16_to_cpu libusb_cpu_to_le16 + +/* standard USB stuff */ + +/** \ingroup libusb_desc + * Device and/or Interface Class codes */ +enum libusb_class_code { + /** In the context of a \ref libusb_device_descriptor "device descriptor", + * this bDeviceClass value indicates that each interface specifies its + * own class information and all interfaces operate independently. + */ + LIBUSB_CLASS_PER_INTERFACE = 0, + + /** Audio class */ + LIBUSB_CLASS_AUDIO = 1, + + /** Communications class */ + LIBUSB_CLASS_COMM = 2, + + /** Human Interface Device class */ + LIBUSB_CLASS_HID = 3, + + /** Physical */ + LIBUSB_CLASS_PHYSICAL = 5, + + /** Printer class */ + LIBUSB_CLASS_PRINTER = 7, + + /** Image class */ + LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */ + LIBUSB_CLASS_IMAGE = 6, + + /** Mass storage class */ + LIBUSB_CLASS_MASS_STORAGE = 8, + + /** Hub class */ + LIBUSB_CLASS_HUB = 9, + + /** Data class */ + LIBUSB_CLASS_DATA = 10, + + /** Smart Card */ + LIBUSB_CLASS_SMART_CARD = 0x0b, + + /** Content Security */ + LIBUSB_CLASS_CONTENT_SECURITY = 0x0d, + + /** Video */ + LIBUSB_CLASS_VIDEO = 0x0e, + + /** Personal Healthcare */ + LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f, + + /** Diagnostic Device */ + LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc, + + /** Wireless class */ + LIBUSB_CLASS_WIRELESS = 0xe0, + + /** Application class */ + LIBUSB_CLASS_APPLICATION = 0xfe, + + /** Class is vendor-specific */ + LIBUSB_CLASS_VENDOR_SPEC = 0xff +}; + +/** \ingroup libusb_desc + * Descriptor types as defined by the USB specification. */ +enum libusb_descriptor_type { + /** Device descriptor. See libusb_device_descriptor. */ + LIBUSB_DT_DEVICE = 0x01, + + /** Configuration descriptor. See libusb_config_descriptor. */ + LIBUSB_DT_CONFIG = 0x02, + + /** String descriptor */ + LIBUSB_DT_STRING = 0x03, + + /** Interface descriptor. See libusb_interface_descriptor. */ + LIBUSB_DT_INTERFACE = 0x04, + + /** Endpoint descriptor. See libusb_endpoint_descriptor. */ + LIBUSB_DT_ENDPOINT = 0x05, + + /** BOS descriptor */ + LIBUSB_DT_BOS = 0x0f, + + /** Device Capability descriptor */ + LIBUSB_DT_DEVICE_CAPABILITY = 0x10, + + /** HID descriptor */ + LIBUSB_DT_HID = 0x21, + + /** HID report descriptor */ + LIBUSB_DT_REPORT = 0x22, + + /** Physical descriptor */ + LIBUSB_DT_PHYSICAL = 0x23, + + /** Hub descriptor */ + LIBUSB_DT_HUB = 0x29, + + /** SuperSpeed Hub descriptor */ + LIBUSB_DT_SUPERSPEED_HUB = 0x2a, + + /** SuperSpeed Endpoint Companion descriptor */ + LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30 +}; + +/* Descriptor sizes per descriptor type */ +#define LIBUSB_DT_DEVICE_SIZE 18 +#define LIBUSB_DT_CONFIG_SIZE 9 +#define LIBUSB_DT_INTERFACE_SIZE 9 +#define LIBUSB_DT_ENDPOINT_SIZE 7 +#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ +#define LIBUSB_DT_HUB_NONVAR_SIZE 7 +#define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6 +#define LIBUSB_DT_BOS_SIZE 5 +#define LIBUSB_DT_DEVICE_CAPABILITY_SIZE 3 + +/* BOS descriptor sizes */ +#define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7 +#define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10 +#define LIBUSB_BT_CONTAINER_ID_SIZE 20 + +/* We unwrap the BOS => define its max size */ +#define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\ + (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\ + (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\ + (LIBUSB_BT_CONTAINER_ID_SIZE)) + +#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ +#define LIBUSB_ENDPOINT_DIR_MASK 0x80 + +/** \ingroup libusb_desc + * Endpoint direction. Values for bit 7 of the + * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme. + */ +enum libusb_endpoint_direction { + /** In: device-to-host */ + LIBUSB_ENDPOINT_IN = 0x80, + + /** Out: host-to-device */ + LIBUSB_ENDPOINT_OUT = 0x00 +}; + +#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */ + +/** \ingroup libusb_desc + * Endpoint transfer type. Values for bits 0:1 of the + * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field. + */ +enum libusb_transfer_type { + /** Control endpoint */ + LIBUSB_TRANSFER_TYPE_CONTROL = 0, + + /** Isochronous endpoint */ + LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1, + + /** Bulk endpoint */ + LIBUSB_TRANSFER_TYPE_BULK = 2, + + /** Interrupt endpoint */ + LIBUSB_TRANSFER_TYPE_INTERRUPT = 3, + + /** Stream endpoint */ + LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4, +}; + +/** \ingroup libusb_misc + * Standard requests, as defined in table 9-5 of the USB 3.0 specifications */ +enum libusb_standard_request { + /** Request status of the specific recipient */ + LIBUSB_REQUEST_GET_STATUS = 0x00, + + /** Clear or disable a specific feature */ + LIBUSB_REQUEST_CLEAR_FEATURE = 0x01, + + /* 0x02 is reserved */ + + /** Set or enable a specific feature */ + LIBUSB_REQUEST_SET_FEATURE = 0x03, + + /* 0x04 is reserved */ + + /** Set device address for all future accesses */ + LIBUSB_REQUEST_SET_ADDRESS = 0x05, + + /** Get the specified descriptor */ + LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06, + + /** Used to update existing descriptors or add new descriptors */ + LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07, + + /** Get the current device configuration value */ + LIBUSB_REQUEST_GET_CONFIGURATION = 0x08, + + /** Set device configuration */ + LIBUSB_REQUEST_SET_CONFIGURATION = 0x09, + + /** Return the selected alternate setting for the specified interface */ + LIBUSB_REQUEST_GET_INTERFACE = 0x0A, + + /** Select an alternate interface for the specified interface */ + LIBUSB_REQUEST_SET_INTERFACE = 0x0B, + + /** Set then report an endpoint's synchronization frame */ + LIBUSB_REQUEST_SYNCH_FRAME = 0x0C, + + /** Sets both the U1 and U2 Exit Latency */ + LIBUSB_REQUEST_SET_SEL = 0x30, + + /** Delay from the time a host transmits a packet to the time it is + * received by the device. */ + LIBUSB_SET_ISOCH_DELAY = 0x31, +}; + +/** \ingroup libusb_misc + * Request type bits of the + * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control + * transfers. */ +enum libusb_request_type { + /** Standard */ + LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5), + + /** Class */ + LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5), + + /** Vendor */ + LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5), + + /** Reserved */ + LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5) +}; + +/** \ingroup libusb_misc + * Recipient bits of the + * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control + * transfers. Values 4 through 31 are reserved. */ +enum libusb_request_recipient { + /** Device */ + LIBUSB_RECIPIENT_DEVICE = 0x00, + + /** Interface */ + LIBUSB_RECIPIENT_INTERFACE = 0x01, + + /** Endpoint */ + LIBUSB_RECIPIENT_ENDPOINT = 0x02, + + /** Other */ + LIBUSB_RECIPIENT_OTHER = 0x03, +}; + +#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C + +/** \ingroup libusb_desc + * Synchronization type for isochronous endpoints. Values for bits 2:3 of the + * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in + * libusb_endpoint_descriptor. + */ +enum libusb_iso_sync_type { + /** No synchronization */ + LIBUSB_ISO_SYNC_TYPE_NONE = 0, + + /** Asynchronous */ + LIBUSB_ISO_SYNC_TYPE_ASYNC = 1, + + /** Adaptive */ + LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2, + + /** Synchronous */ + LIBUSB_ISO_SYNC_TYPE_SYNC = 3 +}; + +#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30 + +/** \ingroup libusb_desc + * Usage type for isochronous endpoints. Values for bits 4:5 of the + * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in + * libusb_endpoint_descriptor. + */ +enum libusb_iso_usage_type { + /** Data endpoint */ + LIBUSB_ISO_USAGE_TYPE_DATA = 0, + + /** Feedback endpoint */ + LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1, + + /** Implicit feedback Data endpoint */ + LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2, +}; + +/** \ingroup libusb_desc + * A structure representing the standard USB device descriptor. This + * descriptor is documented in section 9.6.1 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_device_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this + * context. */ + uint8_t bDescriptorType; + + /** USB specification release number in binary-coded decimal. A value of + * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */ + uint16_t bcdUSB; + + /** USB-IF class code for the device. See \ref libusb_class_code. */ + uint8_t bDeviceClass; + + /** USB-IF subclass code for the device, qualified by the bDeviceClass + * value */ + uint8_t bDeviceSubClass; + + /** USB-IF protocol code for the device, qualified by the bDeviceClass and + * bDeviceSubClass values */ + uint8_t bDeviceProtocol; + + /** Maximum packet size for endpoint 0 */ + uint8_t bMaxPacketSize0; + + /** USB-IF vendor ID */ + uint16_t idVendor; + + /** USB-IF product ID */ + uint16_t idProduct; + + /** Device release number in binary-coded decimal */ + uint16_t bcdDevice; + + /** Index of string descriptor describing manufacturer */ + uint8_t iManufacturer; + + /** Index of string descriptor describing product */ + uint8_t iProduct; + + /** Index of string descriptor containing device serial number */ + uint8_t iSerialNumber; + + /** Number of possible configurations */ + uint8_t bNumConfigurations; +}; + +/** \ingroup libusb_desc + * A structure representing the standard USB endpoint descriptor. This + * descriptor is documented in section 9.6.6 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_endpoint_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in + * this context. */ + uint8_t bDescriptorType; + + /** The address of the endpoint described by this descriptor. Bits 0:3 are + * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction, + * see \ref libusb_endpoint_direction. + */ + uint8_t bEndpointAddress; + + /** Attributes which apply to the endpoint when it is configured using + * the bConfigurationValue. Bits 0:1 determine the transfer type and + * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for + * isochronous endpoints and correspond to \ref libusb_iso_sync_type. + * Bits 4:5 are also only used for isochronous endpoints and correspond to + * \ref libusb_iso_usage_type. Bits 6:7 are reserved. + */ + uint8_t bmAttributes; + + /** Maximum packet size this endpoint is capable of sending/receiving. */ + uint16_t wMaxPacketSize; + + /** Interval for polling endpoint for data transfers. */ + uint8_t bInterval; + + /** For audio devices only: the rate at which synchronization feedback + * is provided. */ + uint8_t bRefresh; + + /** For audio devices only: the address if the synch endpoint */ + uint8_t bSynchAddress; + + /** Extra descriptors. If libusb encounters unknown endpoint descriptors, + * it will store them here, should you wish to parse them. */ + const unsigned char *extra; + + /** Length of the extra descriptors, in bytes. */ + int extra_length; +}; + +/** \ingroup libusb_desc + * A structure representing the standard USB interface descriptor. This + * descriptor is documented in section 9.6.5 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_interface_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE + * in this context. */ + uint8_t bDescriptorType; + + /** Number of this interface */ + uint8_t bInterfaceNumber; + + /** Value used to select this alternate setting for this interface */ + uint8_t bAlternateSetting; + + /** Number of endpoints used by this interface (excluding the control + * endpoint). */ + uint8_t bNumEndpoints; + + /** USB-IF class code for this interface. See \ref libusb_class_code. */ + uint8_t bInterfaceClass; + + /** USB-IF subclass code for this interface, qualified by the + * bInterfaceClass value */ + uint8_t bInterfaceSubClass; + + /** USB-IF protocol code for this interface, qualified by the + * bInterfaceClass and bInterfaceSubClass values */ + uint8_t bInterfaceProtocol; + + /** Index of string descriptor describing this interface */ + uint8_t iInterface; + + /** Array of endpoint descriptors. This length of this array is determined + * by the bNumEndpoints field. */ + const struct libusb_endpoint_descriptor *endpoint; + + /** Extra descriptors. If libusb encounters unknown interface descriptors, + * it will store them here, should you wish to parse them. */ + const unsigned char *extra; + + /** Length of the extra descriptors, in bytes. */ + int extra_length; +}; + +/** \ingroup libusb_desc + * A collection of alternate settings for a particular USB interface. + */ +struct libusb_interface { + /** Array of interface descriptors. The length of this array is determined + * by the num_altsetting field. */ + const struct libusb_interface_descriptor *altsetting; + + /** The number of alternate settings that belong to this interface */ + int num_altsetting; +}; + +/** \ingroup libusb_desc + * A structure representing the standard USB configuration descriptor. This + * descriptor is documented in section 9.6.3 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_config_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG + * in this context. */ + uint8_t bDescriptorType; + + /** Total length of data returned for this configuration */ + uint16_t wTotalLength; + + /** Number of interfaces supported by this configuration */ + uint8_t bNumInterfaces; + + /** Identifier value for this configuration */ + uint8_t bConfigurationValue; + + /** Index of string descriptor describing this configuration */ + uint8_t iConfiguration; + + /** Configuration characteristics */ + uint8_t bmAttributes; + + /** Maximum power consumption of the USB device from this bus in this + * configuration when the device is fully operation. Expressed in units + * of 2 mA when the device is operating in high-speed mode and in units + * of 8 mA when the device is operating in super-speed mode. */ + uint8_t MaxPower; + + /** Array of interfaces supported by this configuration. The length of + * this array is determined by the bNumInterfaces field. */ + const struct libusb_interface *interface; + + /** Extra descriptors. If libusb encounters unknown configuration + * descriptors, it will store them here, should you wish to parse them. */ + const unsigned char *extra; + + /** Length of the extra descriptors, in bytes. */ + int extra_length; +}; + +/** \ingroup libusb_desc + * A structure representing the superspeed endpoint companion + * descriptor. This descriptor is documented in section 9.6.7 of + * the USB 3.0 specification. All multiple-byte fields are represented in + * host-endian format. + */ +struct libusb_ss_endpoint_companion_descriptor { + + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_SS_ENDPOINT_COMPANION in + * this context. */ + uint8_t bDescriptorType; + + + /** The maximum number of packets the endpoint can send or + * receive as part of a burst. */ + uint8_t bMaxBurst; + + /** In bulk EP: bits 4:0 represents the maximum number of + * streams the EP supports. In isochronous EP: bits 1:0 + * represents the Mult - a zero based value that determines + * the maximum number of packets within a service interval */ + uint8_t bmAttributes; + + /** The total number of bytes this EP will transfer every + * service interval. valid only for periodic EPs. */ + uint16_t wBytesPerInterval; +}; + +/** \ingroup libusb_desc + * A generic representation of a BOS Device Capability descriptor. It is + * advised to check bDevCapabilityType and call the matching + * libusb_get_*_descriptor function to get a structure fully matching the type. + */ +struct libusb_bos_dev_capability_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY + * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ + uint8_t bDescriptorType; + /** Device Capability type */ + uint8_t bDevCapabilityType; + /** Device Capability data (bLength - 3 bytes) */ + uint8_t dev_capability_data[ZERO_SIZED_ARRAY]; +}; + +/** \ingroup libusb_desc + * A structure representing the Binary Device Object Store (BOS) descriptor. + * This descriptor is documented in section 9.6.2 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_bos_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_BOS LIBUSB_DT_BOS + * in this context. */ + uint8_t bDescriptorType; + + /** Length of this descriptor and all of its sub descriptors */ + uint16_t wTotalLength; + + /** The number of separate device capability descriptors in + * the BOS */ + uint8_t bNumDeviceCaps; + + /** bNumDeviceCap Device Capability Descriptors */ + struct libusb_bos_dev_capability_descriptor *dev_capability[ZERO_SIZED_ARRAY]; +}; + +/** \ingroup libusb_desc + * A structure representing the USB 2.0 Extension descriptor + * This descriptor is documented in section 9.6.2.1 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_usb_2_0_extension_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY + * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ + uint8_t bDescriptorType; + + /** Capability type. Will have value + * \ref libusb_capability_type::LIBUSB_BT_USB_2_0_EXTENSION + * LIBUSB_BT_USB_2_0_EXTENSION in this context. */ + uint8_t bDevCapabilityType; + + /** Bitmap encoding of supported device level features. + * A value of one in a bit location indicates a feature is + * supported; a value of zero indicates it is not supported. + * See \ref libusb_usb_2_0_extension_attributes. */ + uint32_t bmAttributes; +}; + +/** \ingroup libusb_desc + * A structure representing the SuperSpeed USB Device Capability descriptor + * This descriptor is documented in section 9.6.2.2 of the USB 3.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_ss_usb_device_capability_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY + * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ + uint8_t bDescriptorType; + + /** Capability type. Will have value + * \ref libusb_capability_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY + * LIBUSB_BT_SS_USB_DEVICE_CAPABILITY in this context. */ + uint8_t bDevCapabilityType; + + /** Bitmap encoding of supported device level features. + * A value of one in a bit location indicates a feature is + * supported; a value of zero indicates it is not supported. + * See \ref libusb_ss_usb_device_capability_attributes. */ + uint8_t bmAttributes; + + /** Bitmap encoding of the speed supported by this device when + * operating in SuperSpeed mode. See \ref libusb_supported_speed. */ + uint16_t wSpeedSupported; + + /** The lowest speed at which all the functionality supported + * by the device is available to the user. For example if the + * device supports all its functionality when connected at + * full speed and above then it sets this value to 1. */ + uint8_t bFunctionalitySupport; + + /** U1 Device Exit Latency. */ + uint8_t bU1DevExitLat; + + /** U2 Device Exit Latency. */ + uint16_t bU2DevExitLat; +}; + +/** \ingroup libusb_desc + * A structure representing the Container ID descriptor. + * This descriptor is documented in section 9.6.2.3 of the USB 3.0 specification. + * All multiple-byte fields, except UUIDs, are represented in host-endian format. + */ +struct libusb_container_id_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY + * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ + uint8_t bDescriptorType; + + /** Capability type. Will have value + * \ref libusb_capability_type::LIBUSB_BT_CONTAINER_ID + * LIBUSB_BT_CONTAINER_ID in this context. */ + uint8_t bDevCapabilityType; + + /** Reserved field */ + uint8_t bReserved; + + /** 128 bit UUID */ + uint8_t ContainerID[16]; +}; + +/** \ingroup libusb_asyncio + * Setup packet for control transfers. */ +struct libusb_control_setup { + /** Request type. Bits 0:4 determine recipient, see + * \ref libusb_request_recipient. Bits 5:6 determine type, see + * \ref libusb_request_type. Bit 7 determines data transfer direction, see + * \ref libusb_endpoint_direction. + */ + uint8_t bmRequestType; + + /** Request. If the type bits of bmRequestType are equal to + * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD + * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to + * \ref libusb_standard_request. For other cases, use of this field is + * application-specific. */ + uint8_t bRequest; + + /** Value. Varies according to request */ + uint16_t wValue; + + /** Index. Varies according to request, typically used to pass an index + * or offset */ + uint16_t wIndex; + + /** Number of bytes to transfer */ + uint16_t wLength; +}; + +#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup)) + +/* libusb */ + +struct libusb_context; +struct libusb_device; +struct libusb_device_handle; + +/** \ingroup libusb_lib + * Structure providing the version of the libusb runtime + */ +struct libusb_version { + /** Library major version. */ + const uint16_t major; + + /** Library minor version. */ + const uint16_t minor; + + /** Library micro version. */ + const uint16_t micro; + + /** Library nano version. */ + const uint16_t nano; + + /** Library release candidate suffix string, e.g. "-rc4". */ + const char *rc; + + /** For ABI compatibility only. */ + const char* describe; +}; + +/** \ingroup libusb_lib + * Structure representing a libusb session. The concept of individual libusb + * sessions allows for your program to use two libraries (or dynamically + * load two modules) which both independently use libusb. This will prevent + * interference between the individual libusb users - for example + * libusb_set_option() will not affect the other user of the library, and + * libusb_exit() will not destroy resources that the other user is still + * using. + * + * Sessions are created by libusb_init() and destroyed through libusb_exit(). + * If your application is guaranteed to only ever include a single libusb + * user (i.e. you), you do not have to worry about contexts: pass NULL in + * every function call where a context is required. The default context + * will be used. + * + * For more information, see \ref libusb_contexts. + */ +typedef struct libusb_context libusb_context; + +/** \ingroup libusb_dev + * Structure representing a USB device detected on the system. This is an + * opaque type for which you are only ever provided with a pointer, usually + * originating from libusb_get_device_list(). + * + * Certain operations can be performed on a device, but in order to do any + * I/O you will have to first obtain a device handle using libusb_open(). + * + * Devices are reference counted with libusb_ref_device() and + * libusb_unref_device(), and are freed when the reference count reaches 0. + * New devices presented by libusb_get_device_list() have a reference count of + * 1, and libusb_free_device_list() can optionally decrease the reference count + * on all devices in the list. libusb_open() adds another reference which is + * later destroyed by libusb_close(). + */ +typedef struct libusb_device libusb_device; + + +/** \ingroup libusb_dev + * Structure representing a handle on a USB device. This is an opaque type for + * which you are only ever provided with a pointer, usually originating from + * libusb_open(). + * + * A device handle is used to perform I/O and other operations. When finished + * with a device handle, you should call libusb_close(). + */ +typedef struct libusb_device_handle libusb_device_handle; + +/** \ingroup libusb_dev + * Speed codes. Indicates the speed at which the device is operating. + */ +enum libusb_speed { + /** The OS doesn't report or know the device speed. */ + LIBUSB_SPEED_UNKNOWN = 0, + + /** The device is operating at low speed (1.5MBit/s). */ + LIBUSB_SPEED_LOW = 1, + + /** The device is operating at full speed (12MBit/s). */ + LIBUSB_SPEED_FULL = 2, + + /** The device is operating at high speed (480MBit/s). */ + LIBUSB_SPEED_HIGH = 3, + + /** The device is operating at super speed (5000MBit/s). */ + LIBUSB_SPEED_SUPER = 4, + + /** The device is operating at super speed plus (10000MBit/s). */ + LIBUSB_SPEED_SUPER_PLUS = 5, +}; + +/** \ingroup libusb_dev + * Supported speeds (wSpeedSupported) bitfield. Indicates what + * speeds the device supports. + */ +enum libusb_supported_speed { + /** Low speed operation supported (1.5MBit/s). */ + LIBUSB_LOW_SPEED_OPERATION = 1, + + /** Full speed operation supported (12MBit/s). */ + LIBUSB_FULL_SPEED_OPERATION = 2, + + /** High speed operation supported (480MBit/s). */ + LIBUSB_HIGH_SPEED_OPERATION = 4, + + /** Superspeed operation supported (5000MBit/s). */ + LIBUSB_SUPER_SPEED_OPERATION = 8, +}; + +/** \ingroup libusb_dev + * Masks for the bits of the + * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field + * of the USB 2.0 Extension descriptor. + */ +enum libusb_usb_2_0_extension_attributes { + /** Supports Link Power Management (LPM) */ + LIBUSB_BM_LPM_SUPPORT = 2, +}; + +/** \ingroup libusb_dev + * Masks for the bits of the + * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field + * field of the SuperSpeed USB Device Capability descriptor. + */ +enum libusb_ss_usb_device_capability_attributes { + /** Supports Latency Tolerance Messages (LTM) */ + LIBUSB_BM_LTM_SUPPORT = 2, +}; + +/** \ingroup libusb_dev + * USB capability types + */ +enum libusb_bos_type { + /** Wireless USB device capability */ + LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1, + + /** USB 2.0 extensions */ + LIBUSB_BT_USB_2_0_EXTENSION = 2, + + /** SuperSpeed USB device capability */ + LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3, + + /** Container ID type */ + LIBUSB_BT_CONTAINER_ID = 4, +}; + +/** \ingroup libusb_misc + * Error codes. Most libusb functions return 0 on success or one of these + * codes on failure. + * You can call libusb_error_name() to retrieve a string representation of an + * error code or libusb_strerror() to get an end-user suitable description of + * an error code. + */ +enum libusb_error { + /** Success (no error) */ + LIBUSB_SUCCESS = 0, + + /** Input/output error */ + LIBUSB_ERROR_IO = -1, + + /** Invalid parameter */ + LIBUSB_ERROR_INVALID_PARAM = -2, + + /** Access denied (insufficient permissions) */ + LIBUSB_ERROR_ACCESS = -3, + + /** No such device (it may have been disconnected) */ + LIBUSB_ERROR_NO_DEVICE = -4, + + /** Entity not found */ + LIBUSB_ERROR_NOT_FOUND = -5, + + /** Resource busy */ + LIBUSB_ERROR_BUSY = -6, + + /** Operation timed out */ + LIBUSB_ERROR_TIMEOUT = -7, + + /** Overflow */ + LIBUSB_ERROR_OVERFLOW = -8, + + /** Pipe error */ + LIBUSB_ERROR_PIPE = -9, + + /** System call interrupted (perhaps due to signal) */ + LIBUSB_ERROR_INTERRUPTED = -10, + + /** Insufficient memory */ + LIBUSB_ERROR_NO_MEM = -11, + + /** Operation not supported or unimplemented on this platform */ + LIBUSB_ERROR_NOT_SUPPORTED = -12, + + /* NB: Remember to update LIBUSB_ERROR_COUNT below as well as the + message strings in strerror.c when adding new error codes here. */ + + /** Other error */ + LIBUSB_ERROR_OTHER = -99, +}; + +/* Total number of error codes in enum libusb_error */ +#define LIBUSB_ERROR_COUNT 14 + +/** \ingroup libusb_asyncio + * Transfer status codes */ +enum libusb_transfer_status { + /** Transfer completed without error. Note that this does not indicate + * that the entire amount of requested data was transferred. */ + LIBUSB_TRANSFER_COMPLETED, + + /** Transfer failed */ + LIBUSB_TRANSFER_ERROR, + + /** Transfer timed out */ + LIBUSB_TRANSFER_TIMED_OUT, + + /** Transfer was cancelled */ + LIBUSB_TRANSFER_CANCELLED, + + /** For bulk/interrupt endpoints: halt condition detected (endpoint + * stalled). For control endpoints: control request not supported. */ + LIBUSB_TRANSFER_STALL, + + /** Device was disconnected */ + LIBUSB_TRANSFER_NO_DEVICE, + + /** Device sent more data than requested */ + LIBUSB_TRANSFER_OVERFLOW, + + /* NB! Remember to update libusb_error_name() + when adding new status codes here. */ +}; + +/** \ingroup libusb_asyncio + * libusb_transfer.flags values */ +enum libusb_transfer_flags { + /** Report short frames as errors */ + LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0, + + /** Automatically free() transfer buffer during libusb_free_transfer(). + * Note that buffers allocated with libusb_dev_mem_alloc() should not + * be attempted freed in this way, since free() is not an appropriate + * way to release such memory. */ + LIBUSB_TRANSFER_FREE_BUFFER = 1<<1, + + /** Automatically call libusb_free_transfer() after callback returns. + * If this flag is set, it is illegal to call libusb_free_transfer() + * from your transfer callback, as this will result in a double-free + * when this flag is acted upon. */ + LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2, + + /** Terminate transfers that are a multiple of the endpoint's + * wMaxPacketSize with an extra zero length packet. This is useful + * when a device protocol mandates that each logical request is + * terminated by an incomplete packet (i.e. the logical requests are + * not separated by other means). + * + * This flag only affects host-to-device transfers to bulk and interrupt + * endpoints. In other situations, it is ignored. + * + * This flag only affects transfers with a length that is a multiple of + * the endpoint's wMaxPacketSize. On transfers of other lengths, this + * flag has no effect. Therefore, if you are working with a device that + * needs a ZLP whenever the end of the logical request falls on a packet + * boundary, then it is sensible to set this flag on every + * transfer (you do not have to worry about only setting it on transfers + * that end on the boundary). + * + * This flag is currently only supported on Linux. + * On other systems, libusb_submit_transfer() will return + * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set. + * + * Available since libusb-1.0.9. + */ + LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3, +}; + +/** \ingroup libusb_asyncio + * Isochronous packet descriptor. */ +struct libusb_iso_packet_descriptor { + /** Length of data to request in this packet */ + unsigned int length; + + /** Amount of data that was actually transferred */ + unsigned int actual_length; + + /** Status code for this packet */ + enum libusb_transfer_status status; +}; + +struct libusb_transfer; + +/** \ingroup libusb_asyncio + * Asynchronous transfer callback function type. When submitting asynchronous + * transfers, you pass a pointer to a callback function of this type via the + * \ref libusb_transfer::callback "callback" member of the libusb_transfer + * structure. libusb will call this function later, when the transfer has + * completed or failed. See \ref libusb_asyncio for more information. + * \param transfer The libusb_transfer struct the callback function is being + * notified about. + */ +typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer); + +/** \ingroup libusb_asyncio + * The generic USB transfer structure. The user populates this structure and + * then submits it in order to request a transfer. After the transfer has + * completed, the library populates the transfer with the results and passes + * it back to the user. + */ +struct libusb_transfer { + /** Handle of the device that this transfer will be submitted to */ + libusb_device_handle *dev_handle; + + /** A bitwise OR combination of \ref libusb_transfer_flags. */ + uint8_t flags; + + /** Address of the endpoint where this transfer will be sent. */ + unsigned char endpoint; + + /** Type of the endpoint from \ref libusb_transfer_type */ + unsigned char type; + + /** Timeout for this transfer in milliseconds. A value of 0 indicates no + * timeout. */ + unsigned int timeout; + + /** The status of the transfer. Read-only, and only for use within + * transfer callback function. + * + * If this is an isochronous transfer, this field may read COMPLETED even + * if there were errors in the frames. Use the + * \ref libusb_iso_packet_descriptor::status "status" field in each packet + * to determine if errors occurred. */ + enum libusb_transfer_status status; + + /** Length of the data buffer */ + int length; + + /** Actual length of data that was transferred. Read-only, and only for + * use within transfer callback function. Not valid for isochronous + * endpoint transfers. */ + int actual_length; + + /** Callback function. This will be invoked when the transfer completes, + * fails, or is cancelled. */ + libusb_transfer_cb_fn callback; + + /** User context data to pass to the callback function. */ + void *user_data; + + /** Data buffer */ + unsigned char *buffer; + + /** Number of isochronous packets. Only used for I/O with isochronous + * endpoints. */ + int num_iso_packets; + + /** Isochronous packet descriptors, for isochronous transfers only. */ + struct libusb_iso_packet_descriptor iso_packet_desc[ZERO_SIZED_ARRAY]; +}; + +/** \ingroup libusb_misc + * Capabilities supported by an instance of libusb on the current running + * platform. Test if the loaded library supports a given capability by calling + * \ref libusb_has_capability(). + */ +enum libusb_capability { + /** The libusb_has_capability() API is available. */ + LIBUSB_CAP_HAS_CAPABILITY = 0x0000, + /** Hotplug support is available on this platform. */ + LIBUSB_CAP_HAS_HOTPLUG = 0x0001, + /** The library can access HID devices without requiring user intervention. + * Note that before being able to actually access an HID device, you may + * still have to call additional libusb functions such as + * \ref libusb_detach_kernel_driver(). */ + LIBUSB_CAP_HAS_HID_ACCESS = 0x0100, + /** The library supports detaching of the default USB driver, using + * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */ + LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101 +}; + +/** \ingroup libusb_lib + * Log message levels. + * - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default) + * - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr + * - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr + * - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stderr + * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stderr + */ +enum libusb_log_level { + LIBUSB_LOG_LEVEL_NONE = 0, + LIBUSB_LOG_LEVEL_ERROR = 1, + LIBUSB_LOG_LEVEL_WARNING = 2, + LIBUSB_LOG_LEVEL_INFO = 3, + LIBUSB_LOG_LEVEL_DEBUG = 4, +}; + +int LIBUSB_CALL libusb_init(libusb_context **ctx); +void LIBUSB_CALL libusb_exit(libusb_context *ctx); +LIBUSB_DEPRECATED_FOR(libusb_set_option) +void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level); +const struct libusb_version * LIBUSB_CALL libusb_get_version(void); +int LIBUSB_CALL libusb_has_capability(uint32_t capability); +const char * LIBUSB_CALL libusb_error_name(int errcode); +int LIBUSB_CALL libusb_setlocale(const char *locale); +const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode); + +ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx, + libusb_device ***list); +void LIBUSB_CALL libusb_free_device_list(libusb_device **list, + int unref_devices); +libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev); +void LIBUSB_CALL libusb_unref_device(libusb_device *dev); + +int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev, + int *config); +int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev, + struct libusb_device_descriptor *desc); +int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev, + struct libusb_config_descriptor **config); +int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev, + uint8_t config_index, struct libusb_config_descriptor **config); +int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev, + uint8_t bConfigurationValue, struct libusb_config_descriptor **config); +void LIBUSB_CALL libusb_free_config_descriptor( + struct libusb_config_descriptor *config); +int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor( + struct libusb_context *ctx, + const struct libusb_endpoint_descriptor *endpoint, + struct libusb_ss_endpoint_companion_descriptor **ep_comp); +void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor( + struct libusb_ss_endpoint_companion_descriptor *ep_comp); +int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *dev_handle, + struct libusb_bos_descriptor **bos); +void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos); +int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor( + struct libusb_context *ctx, + struct libusb_bos_dev_capability_descriptor *dev_cap, + struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension); +void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor( + struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension); +int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor( + struct libusb_context *ctx, + struct libusb_bos_dev_capability_descriptor *dev_cap, + struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap); +void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor( + struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap); +int LIBUSB_CALL libusb_get_container_id_descriptor(struct libusb_context *ctx, + struct libusb_bos_dev_capability_descriptor *dev_cap, + struct libusb_container_id_descriptor **container_id); +void LIBUSB_CALL libusb_free_container_id_descriptor( + struct libusb_container_id_descriptor *container_id); +uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev); +uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev); +int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len); +LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers) +int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length); +libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev); +uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev); +int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev); +int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev, + unsigned char endpoint); +int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev, + unsigned char endpoint); + +int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **dev_handle); +void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle); +libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle); + +int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev_handle, + int configuration); +int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev_handle, + int interface_number); +int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev_handle, + int interface_number); + +libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid( + libusb_context *ctx, uint16_t vendor_id, uint16_t product_id); + +int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev_handle, + int interface_number, int alternate_setting); +int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev_handle, + unsigned char endpoint); +int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev_handle); + +int LIBUSB_CALL libusb_alloc_streams(libusb_device_handle *dev_handle, + uint32_t num_streams, unsigned char *endpoints, int num_endpoints); +int LIBUSB_CALL libusb_free_streams(libusb_device_handle *dev_handle, + unsigned char *endpoints, int num_endpoints); + +unsigned char * LIBUSB_CALL libusb_dev_mem_alloc(libusb_device_handle *dev_handle, + size_t length); +int LIBUSB_CALL libusb_dev_mem_free(libusb_device_handle *dev_handle, + unsigned char *buffer, size_t length); + +int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev_handle, + int interface_number); +int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev_handle, + int interface_number); +int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev_handle, + int interface_number); +int LIBUSB_CALL libusb_set_auto_detach_kernel_driver( + libusb_device_handle *dev_handle, int enable); + +/* async I/O */ + +/** \ingroup libusb_asyncio + * Get the data section of a control transfer. This convenience function is here + * to remind you that the data does not start until 8 bytes into the actual + * buffer, as the setup packet comes first. + * + * Calling this function only makes sense from a transfer callback function, + * or situations where you have already allocated a suitably sized buffer at + * transfer->buffer. + * + * \param transfer a transfer + * \returns pointer to the first byte of the data section + */ +static inline unsigned char *libusb_control_transfer_get_data( + struct libusb_transfer *transfer) +{ + return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE; +} + +/** \ingroup libusb_asyncio + * Get the control setup packet of a control transfer. This convenience + * function is here to remind you that the control setup occupies the first + * 8 bytes of the transfer data buffer. + * + * Calling this function only makes sense from a transfer callback function, + * or situations where you have already allocated a suitably sized buffer at + * transfer->buffer. + * + * \param transfer a transfer + * \returns a casted pointer to the start of the transfer data buffer + */ +static inline struct libusb_control_setup *libusb_control_transfer_get_setup( + struct libusb_transfer *transfer) +{ + return (struct libusb_control_setup *)(void *) transfer->buffer; +} + +/** \ingroup libusb_asyncio + * Helper function to populate the setup packet (first 8 bytes of the data + * buffer) for a control transfer. The wIndex, wValue and wLength values should + * be given in host-endian byte order. + * + * \param buffer buffer to output the setup packet into + * This pointer must be aligned to at least 2 bytes boundary. + * \param bmRequestType see the + * \ref libusb_control_setup::bmRequestType "bmRequestType" field of + * \ref libusb_control_setup + * \param bRequest see the + * \ref libusb_control_setup::bRequest "bRequest" field of + * \ref libusb_control_setup + * \param wValue see the + * \ref libusb_control_setup::wValue "wValue" field of + * \ref libusb_control_setup + * \param wIndex see the + * \ref libusb_control_setup::wIndex "wIndex" field of + * \ref libusb_control_setup + * \param wLength see the + * \ref libusb_control_setup::wLength "wLength" field of + * \ref libusb_control_setup + */ +static inline void libusb_fill_control_setup(unsigned char *buffer, + uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, + uint16_t wLength) +{ + struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer; + setup->bmRequestType = bmRequestType; + setup->bRequest = bRequest; + setup->wValue = libusb_cpu_to_le16(wValue); + setup->wIndex = libusb_cpu_to_le16(wIndex); + setup->wLength = libusb_cpu_to_le16(wLength); +} + +struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets); +int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer); +int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer); +void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer); +void LIBUSB_CALL libusb_transfer_set_stream_id( + struct libusb_transfer *transfer, uint32_t stream_id); +uint32_t LIBUSB_CALL libusb_transfer_get_stream_id( + struct libusb_transfer *transfer); + +/** \ingroup libusb_asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for a control transfer. + * + * If you pass a transfer buffer to this function, the first 8 bytes will + * be interpreted as a control setup packet, and the wLength field will be + * used to automatically populate the \ref libusb_transfer::length "length" + * field of the transfer. Therefore the recommended approach is: + * -# Allocate a suitably sized data buffer (including space for control setup) + * -# Call libusb_fill_control_setup() + * -# If this is a host-to-device transfer with a data stage, put the data + * in place after the setup packet + * -# Call this function + * -# Call libusb_submit_transfer() + * + * It is also legal to pass a NULL buffer to this function, in which case this + * function will not attempt to populate the length field. Remember that you + * must then populate the buffer and length fields later. + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param buffer data buffer. If provided, this function will interpret the + * first 8 bytes as a setup packet and infer the transfer length from that. + * This pointer must be aligned to at least 2 bytes boundary. + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_control_transfer( + struct libusb_transfer *transfer, libusb_device_handle *dev_handle, + unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data, + unsigned int timeout) +{ + struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer; + transfer->dev_handle = dev_handle; + transfer->endpoint = 0; + transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL; + transfer->timeout = timeout; + transfer->buffer = buffer; + if (setup) + transfer->length = (int) (LIBUSB_CONTROL_SETUP_SIZE + + libusb_le16_to_cpu(setup->wLength)); + transfer->user_data = user_data; + transfer->callback = callback; +} + +/** \ingroup libusb_asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for a bulk transfer. + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param endpoint address of the endpoint where this transfer will be sent + * \param buffer data buffer + * \param length length of data buffer + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer, + libusb_device_handle *dev_handle, unsigned char endpoint, + unsigned char *buffer, int length, libusb_transfer_cb_fn callback, + void *user_data, unsigned int timeout) +{ + transfer->dev_handle = dev_handle; + transfer->endpoint = endpoint; + transfer->type = LIBUSB_TRANSFER_TYPE_BULK; + transfer->timeout = timeout; + transfer->buffer = buffer; + transfer->length = length; + transfer->user_data = user_data; + transfer->callback = callback; +} + +/** \ingroup libusb_asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for a bulk transfer using bulk streams. + * + * Since version 1.0.19, \ref LIBUSB_API_VERSION >= 0x01000103 + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param endpoint address of the endpoint where this transfer will be sent + * \param stream_id bulk stream id for this transfer + * \param buffer data buffer + * \param length length of data buffer + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_bulk_stream_transfer( + struct libusb_transfer *transfer, libusb_device_handle *dev_handle, + unsigned char endpoint, uint32_t stream_id, + unsigned char *buffer, int length, libusb_transfer_cb_fn callback, + void *user_data, unsigned int timeout) +{ + libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, + length, callback, user_data, timeout); + transfer->type = LIBUSB_TRANSFER_TYPE_BULK_STREAM; + libusb_transfer_set_stream_id(transfer, stream_id); +} + +/** \ingroup libusb_asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for an interrupt transfer. + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param endpoint address of the endpoint where this transfer will be sent + * \param buffer data buffer + * \param length length of data buffer + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_interrupt_transfer( + struct libusb_transfer *transfer, libusb_device_handle *dev_handle, + unsigned char endpoint, unsigned char *buffer, int length, + libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) +{ + transfer->dev_handle = dev_handle; + transfer->endpoint = endpoint; + transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT; + transfer->timeout = timeout; + transfer->buffer = buffer; + transfer->length = length; + transfer->user_data = user_data; + transfer->callback = callback; +} + +/** \ingroup libusb_asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for an isochronous transfer. + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param endpoint address of the endpoint where this transfer will be sent + * \param buffer data buffer + * \param length length of data buffer + * \param num_iso_packets the number of isochronous packets + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer, + libusb_device_handle *dev_handle, unsigned char endpoint, + unsigned char *buffer, int length, int num_iso_packets, + libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) +{ + transfer->dev_handle = dev_handle; + transfer->endpoint = endpoint; + transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS; + transfer->timeout = timeout; + transfer->buffer = buffer; + transfer->length = length; + transfer->num_iso_packets = num_iso_packets; + transfer->user_data = user_data; + transfer->callback = callback; +} + +/** \ingroup libusb_asyncio + * Convenience function to set the length of all packets in an isochronous + * transfer, based on the num_iso_packets field in the transfer structure. + * + * \param transfer a transfer + * \param length the length to set in each isochronous packet descriptor + * \see libusb_get_max_packet_size() + */ +static inline void libusb_set_iso_packet_lengths( + struct libusb_transfer *transfer, unsigned int length) +{ + int i; + for (i = 0; i < transfer->num_iso_packets; i++) + transfer->iso_packet_desc[i].length = length; +} + +/** \ingroup libusb_asyncio + * Convenience function to locate the position of an isochronous packet + * within the buffer of an isochronous transfer. + * + * This is a thorough function which loops through all preceding packets, + * accumulating their lengths to find the position of the specified packet. + * Typically you will assign equal lengths to each packet in the transfer, + * and hence the above method is sub-optimal. You may wish to use + * libusb_get_iso_packet_buffer_simple() instead. + * + * \param transfer a transfer + * \param packet the packet to return the address of + * \returns the base address of the packet buffer inside the transfer buffer, + * or NULL if the packet does not exist. + * \see libusb_get_iso_packet_buffer_simple() + */ +static inline unsigned char *libusb_get_iso_packet_buffer( + struct libusb_transfer *transfer, unsigned int packet) +{ + int i; + size_t offset = 0; + int _packet; + + /* oops..slight bug in the API. packet is an unsigned int, but we use + * signed integers almost everywhere else. range-check and convert to + * signed to avoid compiler warnings. FIXME for libusb-2. */ + if (packet > INT_MAX) + return NULL; + _packet = (int) packet; + + if (_packet >= transfer->num_iso_packets) + return NULL; + + for (i = 0; i < _packet; i++) + offset += transfer->iso_packet_desc[i].length; + + return transfer->buffer + offset; +} + +/** \ingroup libusb_asyncio + * Convenience function to locate the position of an isochronous packet + * within the buffer of an isochronous transfer, for transfers where each + * packet is of identical size. + * + * This function relies on the assumption that every packet within the transfer + * is of identical size to the first packet. Calculating the location of + * the packet buffer is then just a simple calculation: + * buffer + (packet_size * packet) + * + * Do not use this function on transfers other than those that have identical + * packet lengths for each packet. + * + * \param transfer a transfer + * \param packet the packet to return the address of + * \returns the base address of the packet buffer inside the transfer buffer, + * or NULL if the packet does not exist. + * \see libusb_get_iso_packet_buffer() + */ +static inline unsigned char *libusb_get_iso_packet_buffer_simple( + struct libusb_transfer *transfer, unsigned int packet) +{ + int _packet; + + /* oops..slight bug in the API. packet is an unsigned int, but we use + * signed integers almost everywhere else. range-check and convert to + * signed to avoid compiler warnings. FIXME for libusb-2. */ + if (packet > INT_MAX) + return NULL; + _packet = (int) packet; + + if (_packet >= transfer->num_iso_packets) + return NULL; + + return transfer->buffer + ((int) transfer->iso_packet_desc[0].length * _packet); +} + +/* sync I/O */ + +int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle, + uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, + unsigned char *data, uint16_t wLength, unsigned int timeout); + +int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle, + unsigned char endpoint, unsigned char *data, int length, + int *actual_length, unsigned int timeout); + +int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle, + unsigned char endpoint, unsigned char *data, int length, + int *actual_length, unsigned int timeout); + +/** \ingroup libusb_desc + * Retrieve a descriptor from the default control pipe. + * This is a convenience function which formulates the appropriate control + * message to retrieve the descriptor. + * + * \param dev_handle a device handle + * \param desc_type the descriptor type, see \ref libusb_descriptor_type + * \param desc_index the index of the descriptor to retrieve + * \param data output buffer for descriptor + * \param length size of data buffer + * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure + */ +static inline int libusb_get_descriptor(libusb_device_handle *dev_handle, + uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length) +{ + return libusb_control_transfer(dev_handle, LIBUSB_ENDPOINT_IN, + LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t) ((desc_type << 8) | desc_index), + 0, data, (uint16_t) length, 1000); +} + +/** \ingroup libusb_desc + * Retrieve a descriptor from a device. + * This is a convenience function which formulates the appropriate control + * message to retrieve the descriptor. The string returned is Unicode, as + * detailed in the USB specifications. + * + * \param dev_handle a device handle + * \param desc_index the index of the descriptor to retrieve + * \param langid the language ID for the string descriptor + * \param data output buffer for descriptor + * \param length size of data buffer + * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure + * \see libusb_get_string_descriptor_ascii() + */ +static inline int libusb_get_string_descriptor(libusb_device_handle *dev_handle, + uint8_t desc_index, uint16_t langid, unsigned char *data, int length) +{ + return libusb_control_transfer(dev_handle, LIBUSB_ENDPOINT_IN, + LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index), + langid, data, (uint16_t) length, 1000); +} + +int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev_handle, + uint8_t desc_index, unsigned char *data, int length); + +/* polling and timeouts */ + +int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx); +void LIBUSB_CALL libusb_lock_events(libusb_context *ctx); +void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx); +int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx); +int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx); +void LIBUSB_CALL libusb_interrupt_event_handler(libusb_context *ctx); +void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx); +void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx); +int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv); + +int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx, + struct timeval *tv); +int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx, + struct timeval *tv, int *completed); +int LIBUSB_CALL libusb_handle_events(libusb_context *ctx); +int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed); +int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx, + struct timeval *tv); +int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx); +int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx, + struct timeval *tv); + +/** \ingroup libusb_poll + * File descriptor for polling + */ +struct libusb_pollfd { + /** Numeric file descriptor */ + int fd; + + /** Event flags to poll for from . POLLIN indicates that you + * should monitor this file descriptor for becoming ready to read from, + * and POLLOUT indicates that you should monitor this file descriptor for + * nonblocking write readiness. */ + short events; +}; + +/** \ingroup libusb_poll + * Callback function, invoked when a new file descriptor should be added + * to the set of file descriptors monitored for events. + * \param fd the new file descriptor + * \param events events to monitor for, see \ref libusb_pollfd for a + * description + * \param user_data User data pointer specified in + * libusb_set_pollfd_notifiers() call + * \see libusb_set_pollfd_notifiers() + */ +typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events, + void *user_data); + +/** \ingroup libusb_poll + * Callback function, invoked when a file descriptor should be removed from + * the set of file descriptors being monitored for events. After returning + * from this callback, do not use that file descriptor again. + * \param fd the file descriptor to stop monitoring + * \param user_data User data pointer specified in + * libusb_set_pollfd_notifiers() call + * \see libusb_set_pollfd_notifiers() + */ +typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data); + +const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds( + libusb_context *ctx); +void LIBUSB_CALL libusb_free_pollfds(const struct libusb_pollfd **pollfds); +void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx, + libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, + void *user_data); + +/** \ingroup libusb_hotplug + * Callback handle. + * + * Callbacks handles are generated by libusb_hotplug_register_callback() + * and can be used to deregister callbacks. Callback handles are unique + * per libusb_context and it is safe to call libusb_hotplug_deregister_callback() + * on an already deregisted callback. + * + * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 + * + * For more information, see \ref libusb_hotplug. + */ +typedef int libusb_hotplug_callback_handle; + +/** \ingroup libusb_hotplug + * + * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 + * + * Flags for hotplug events */ +typedef enum { + /** Default value when not using any flags. */ + LIBUSB_HOTPLUG_NO_FLAGS = 0, + + /** Arm the callback and fire it for all matching currently attached devices. */ + LIBUSB_HOTPLUG_ENUMERATE = 1<<0, +} libusb_hotplug_flag; + +/** \ingroup libusb_hotplug + * + * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 + * + * Hotplug events */ +typedef enum { + /** A device has been plugged in and is ready to use */ + LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01, + + /** A device has left and is no longer available. + * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device. + * It is safe to call libusb_get_device_descriptor on a device that has left */ + LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02, +} libusb_hotplug_event; + +/** \ingroup libusb_hotplug + * Wildcard matching for hotplug events */ +#define LIBUSB_HOTPLUG_MATCH_ANY -1 + +/** \ingroup libusb_hotplug + * Hotplug callback function type. When requesting hotplug event notifications, + * you pass a pointer to a callback function of this type. + * + * This callback may be called by an internal event thread and as such it is + * recommended the callback do minimal processing before returning. + * + * libusb will call this function later, when a matching event had happened on + * a matching device. See \ref libusb_hotplug for more information. + * + * It is safe to call either libusb_hotplug_register_callback() or + * libusb_hotplug_deregister_callback() from within a callback function. + * + * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 + * + * \param ctx context of this notification + * \param device libusb_device this event occurred on + * \param event event that occurred + * \param user_data user data provided when this callback was registered + * \returns bool whether this callback is finished processing events. + * returning 1 will cause this callback to be deregistered + */ +typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx, + libusb_device *device, + libusb_hotplug_event event, + void *user_data); + +/** \ingroup libusb_hotplug + * Register a hotplug callback function + * + * Register a callback with the libusb_context. The callback will fire + * when a matching event occurs on a matching device. The callback is + * armed until either it is deregistered with libusb_hotplug_deregister_callback() + * or the supplied callback returns 1 to indicate it is finished processing events. + * + * If the \ref LIBUSB_HOTPLUG_ENUMERATE is passed the callback will be + * called with a \ref LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED for all devices + * already plugged into the machine. Note that libusb modifies its internal + * device list from a separate thread, while calling hotplug callbacks from + * libusb_handle_events(), so it is possible for a device to already be present + * on, or removed from, its internal device list, while the hotplug callbacks + * still need to be dispatched. This means that when using \ref + * LIBUSB_HOTPLUG_ENUMERATE, your callback may be called twice for the arrival + * of the same device, once from libusb_hotplug_register_callback() and once + * from libusb_handle_events(); and/or your callback may be called for the + * removal of a device for which an arrived call was never made. + * + * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 + * + * \param[in] ctx context to register this callback with + * \param[in] events bitwise or of events that will trigger this callback. See \ref + * libusb_hotplug_event + * \param[in] flags hotplug callback flags. See \ref libusb_hotplug_flag + * \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY + * \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY + * \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY + * \param[in] cb_fn the function to be invoked on a matching event/device + * \param[in] user_data user data to pass to the callback function + * \param[out] callback_handle pointer to store the handle of the allocated callback (can be NULL) + * \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure + */ +int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx, + libusb_hotplug_event events, + libusb_hotplug_flag flags, + int vendor_id, int product_id, + int dev_class, + libusb_hotplug_callback_fn cb_fn, + void *user_data, + libusb_hotplug_callback_handle *callback_handle); + +/** \ingroup libusb_hotplug + * Deregisters a hotplug callback. + * + * Deregister a callback from a libusb_context. This function is safe to call from within + * a hotplug callback. + * + * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 + * + * \param[in] ctx context this callback is registered with + * \param[in] callback_handle the handle of the callback to deregister + */ +void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx, + libusb_hotplug_callback_handle callback_handle); + +/** \ingroup libusb_lib + * Available option values for libusb_set_option(). + */ +enum libusb_option { + /** Set the log message verbosity. + * + * The default level is LIBUSB_LOG_LEVEL_NONE, which means no messages are ever + * printed. If you choose to increase the message verbosity level, ensure + * that your application does not close the stderr file descriptor. + * + * You are advised to use level LIBUSB_LOG_LEVEL_WARNING. libusb is conservative + * with its message logging and most of the time, will only log messages that + * explain error conditions and other oddities. This will help you debug + * your software. + * + * If the LIBUSB_DEBUG environment variable was set when libusb was + * initialized, this function does nothing: the message verbosity is fixed + * to the value in the environment variable. + * + * If libusb was compiled without any message logging, this function does + * nothing: you'll never get any messages. + * + * If libusb was compiled with verbose debug message logging, this function + * does nothing: you'll always get messages from all levels. + */ + LIBUSB_OPTION_LOG_LEVEL, + + /** Use the UsbDk backend for a specific context, if available. + * + * This option should be set immediately after calling libusb_init(), otherwise + * unspecified behavior may occur. + * + * Only valid on Windows. + */ + LIBUSB_OPTION_USE_USBDK, +}; + +int LIBUSB_CALL libusb_set_option(libusb_context *ctx, enum libusb_option option, ...); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib_xua/host/xmosdfu/testdfu.sh b/lib_xua/host/xmosdfu/testdfu.sh index 0fb53427..65a578a5 100755 --- a/lib_xua/host/xmosdfu/testdfu.sh +++ b/lib_xua/host/xmosdfu/testdfu.sh @@ -73,42 +73,42 @@ system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version echo "" echo "*** DFU download new firmware 1 ***" -$PROGDIR/xmosdfu $device_pid --download $update1 +$PROGDIR/bin/xmosdfu $device_pid --download $update1 sleep 2 echo "Version Read:" system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version echo "" echo "*** DFU download new firmware 2 ***" -$PROGDIR/xmosdfu $device_pid --download $update2 +$PROGDIR/bin/xmosdfu $device_pid --download $update2 sleep 2 echo "Version Read:" system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version echo "" echo "*** DFU upload existing firmware ***" -$PROGDIR/xmosdfu $device_pid --upload upload.bin +$PROGDIR/bin/xmosdfu $device_pid --upload upload.bin sleep 2 echo "Version Read:" system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version echo "" echo "*** DFU revert to factory ***" -$PROGDIR/xmosdfu $device_pid --revertfactory +$PROGDIR/bin/xmosdfu $device_pid --revertfactory sleep 2 echo "Version Read:" system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version echo "" echo "*** DFU download uploaded firmware ***" -$PROGDIR/xmosdfu $device_pid --download upload.bin +$PROGDIR/bin/xmosdfu $device_pid --download upload.bin sleep 2 echo "Version Read:" system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version echo "" echo "*** DFU revert to factory ***" -$PROGDIR/xmosdfu $device_pid --revertfactory +$PROGDIR/bin/xmosdfu $device_pid --revertfactory sleep 2 echo "Version Read:" system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version diff --git a/lib_xua/host/xmosdfu/xmosdfu.cpp b/lib_xua/host/xmosdfu/xmosdfu.cpp index a9f86f81..04c1a21a 100644 --- a/lib_xua/host/xmosdfu/xmosdfu.cpp +++ b/lib_xua/host/xmosdfu/xmosdfu.cpp @@ -1,7 +1,29 @@ -// Copyright (c) 2012-2018, XMOS Ltd, All rights reserved +// Copyright 2012-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include #include +#include +#ifdef _WIN32 +#include + +// Used for checking if a file is a directory +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif +// Aliases for Windows +#define stat _stat +#define fstat _fstat +#define fileno _fileno + +#else +#include + +void Sleep(unsigned milliseconds) { + usleep(milliseconds * 1000); +} +#endif + #include "libusb.h" /* the device's vendor and product id */ @@ -51,7 +73,7 @@ static int find_xmos_device(unsigned int id, unsigned int pid, unsigned int list libusb_device *dev; libusb_device **devs; int i = 0; - int found = 0; + unsigned int found = 0; size_t count = libusb_get_device_list(NULL, &devs); if ((int)count < 0) @@ -195,7 +217,7 @@ int xmos_dfu_restore_state(unsigned int interface) return 0; } -int dfu_download(unsigned int interface, unsigned int block_num, unsigned int size, unsigned char *data) +unsigned int dfu_download(unsigned int interface, unsigned int block_num, unsigned int size, unsigned char *data) { //printf("... Downloading block number %d size %d\r", block_num, size); /* Returns actual data size transferred */ @@ -212,7 +234,7 @@ int dfu_upload(unsigned int interface, unsigned int block_num, unsigned int size int write_dfu_image(char *file) { - int i = 0; + unsigned int i = 0; FILE* inFile = NULL; int image_size = 0; unsigned int num_blocks = 0; @@ -225,6 +247,7 @@ int write_dfu_image(char *file) unsigned int timeout = 0; unsigned char strIndex = 0; unsigned int dfuBlockCount = 0; + struct stat statbuf; inFile = fopen( file, "rb" ); if( inFile == NULL ) @@ -233,6 +256,19 @@ int write_dfu_image(char *file) return -1; } + /* Check if file is a directory */ + int status = fstat(fileno(inFile), &statbuf); + if (status != 0) + { + fprintf(stderr,"Error: Failed to get info on file.\n"); + return -1; + } + if ( S_ISDIR(statbuf.st_mode) ) + { + fprintf(stderr,"Error: Specified path is a directory.\n"); + return -1; + } + /* Discover the size of the image. */ if( 0 != fseek( inFile, 0, SEEK_END ) ) { @@ -259,7 +295,7 @@ int write_dfu_image(char *file) { memset(block_data, 0x0, block_size); fread(block_data, 1, block_size, inFile); - int transferred = dfu_download(0, dfuBlockCount, block_size, block_data); + unsigned int transferred = dfu_download(0, dfuBlockCount, block_size, block_data); if(transferred != block_size) { /* Error */ @@ -334,7 +370,7 @@ int read_dfu_image(char *file) static void print_device_list(FILE *file, const char *indent) { - for (int i = 0; i < sizeof(pidList)/sizeof(pidList[0]); i++) + for (long unsigned int i = 0; i < sizeof(pidList)/sizeof(pidList[0]); i++) { fprintf(file, "%s%-30s (0x%0x)\n", indent, pidList[i].device_name, pidList[i].pid); } @@ -371,7 +407,7 @@ static unsigned int select_pid(char *device_pid) } // Otherwise do a lookup of names - for (int i = 0; i < sizeof(pidList)/sizeof(pidList[0]); i++) + for (long unsigned int i = 0; i < sizeof(pidList)/sizeof(pidList[0]); i++) { if (strcmp(device_pid, pidList[i].device_name) == 0) { @@ -501,7 +537,7 @@ int main(int argc, char **argv) printf("Waiting for device to restart and enter DFU mode...\n"); // Wait for device to enter dfu mode and restart - system("sleep 20"); + Sleep(20 * 1000); #endif // NOW IN DFU APPLICATION MODE @@ -556,7 +592,7 @@ int main(int argc, char **argv) printf("... Reverting device to factory image\n"); xmos_dfu_revertfactory(); // Give device time to revert firmware - system("sleep 2"); + Sleep(2 * 1000); xmos_dfu_resetfromdfu(XMOS_DFU_IF); } else @@ -572,5 +608,5 @@ int main(int argc, char **argv) libusb_close(devh); libusb_exit(NULL); - return 1; + return 0; } diff --git a/lib_xua/module_build_info b/lib_xua/module_build_info index 2a36dedf..67df655e 100644 --- a/lib_xua/module_build_info +++ b/lib_xua/module_build_info @@ -1,37 +1,69 @@ -# You can set flags specifically for your module by using the MODULE_XCC_FLAGS -# variable. So the following -# -# MODULE_XCC_FLAGS = $(XCC_FLAGS) -O3 -# -# specifies that everything in the modules should have the application -# build flags with -O3 appended (so the files will build at -# optimization level -O3). -# -# You can also set MODULE_XCC_C_FLAGS, MODULE_XCC_XC_FLAGS etc.. +VERSION = 1.2.0 -MODULE_XCC_FLAGS = $(XCC_FLAGS) -O3 -DREF_CLK_FREQ=100 -fasm-linenum -fcomment-asm +DEPENDENT_MODULES = lib_logging(>=3.0.0) \ + lib_xassert(>=4.0.0) \ + lib_xud(>=1.0.0) \ + lib_spdif(>=4.0.0) \ + lib_mic_array(>=4.0.0) + +MODULE_XCC_FLAGS = $(XCC_FLAGS) \ + -O3 \ + -DREF_CLK_FREQ=100 \ + -fasm-linenum \ + -fcomment-asm + +# Core +XCC_FLAGS_xua_endpoint0.c = $(MODULE_XCC_FLAGS) -Os -mno-dual-issue +XCC_FLAGS_xua_ep0_uacreqs.xc = $(MODULE_XCC_FLAGS) -Os -mno-dual-issue +XCC_FLAGS_dbcalc.xc = $(MODULE_XCC_FLAGS) -Os -mno-dual-issue +XCC_FLAGS_audioports.c = $(MODULE_XCC_FLAGS) -Os -mno-dual-issue +XCC_FLAGS_audioports.xc = $(MODULE_XCC_FLAGS) -Os -mno-dual-issue + +# DFU +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 -VERSION = 0.2.0 +EXPORT_INCLUDE_DIRS = api \ + src/core \ + src/core/audiohub \ + src/core/buffer/ep \ + src/core/endpoint0 \ + src/dfu -DEPENDENT_MODULES = lib_logging(>=2.1.0) lib_xassert(>=2.0.0) lib_xud(>=0.1.0) lib_spdif(>=3.0.0) +INCLUDE_DIRS = $(EXPORT_INCLUDE_DIRS) \ + src/core/buffer/decouple \ + src/core/clocking \ + src/core/mixer \ + src/core/pdm_mics \ + src/core/ports \ + src/core/support \ + src/core/support/powersave \ + src/core/user \ + src/core/user/audiostream \ + src/core/user/hid \ + src/core/user/hostactive \ + src/hid \ + src/midi -INCLUDE_DIRS = api src/* +SOURCE_DIRS = src/core \ + src/core/audiohub \ + src/core/buffer/decouple \ + src/core/buffer/ep \ + src/core/clocking \ + src/core/endpoint0 \ + src/core/mixer \ + src/core/pdm_mics \ + src/core/ports \ + src/core/support \ + src/core/support/powersave \ + src/core/user/audiostream \ + src/core/user/hostactive \ + src/core/xuduser \ + src/dfu \ + src/hid \ + src/midi -#ignore host dir -SOURCE_DIRS = src/* - -# The following file specific flags are not automatically kept in sync with the wscript file -# Core EXCLUDE_FILES += descriptors_2.rst -XCC_FLAGS_xua_endpoint0.c = -Os -mno-dual-issue $(XCC_FLAGS) -XCC_FLAGS_xua_ep0_uacreqs.xc = -Os -mno-dual-issue $(XCC_FLAGS) -XCC_FLAGS_dbcalc.xc = -Os -mno-dual-issue $(XCC_FLAGS) -XCC_FLAGS_audioports.c = -Os -mno-dual-issue $(XCC_FLAGS) -XCC_FLAGS_audioports.xc = -Os -mno-dual-issue $(XCC_FLAGS) - -# DFU -XCC_FLAGS_dfu.xc = -Os -mno-dual-issue $(XCC_FLAGS) -XCC_FLAGS_flash_interface.c = -Os -mno-dual-issue $(XCC_FLAGS) -XCC_FLAGS_flashlib_user.c = -Os -mno-dual-issue $(XCC_FLAGS) diff --git a/lib_xua/src/core/audiohub/audiohub_adat.h b/lib_xua/src/core/audiohub/audiohub_adat.h index 41cd5a45..dd51e3ec 100644 --- a/lib_xua/src/core/audiohub/audiohub_adat.h +++ b/lib_xua/src/core/audiohub/audiohub_adat.h @@ -1,4 +1,5 @@ -// Copyright (c) 2018, XMOS Ltd, All rights reserved +// Copyright 2018-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. unsigned adatCounter = 0; unsigned adatSamples[8]; diff --git a/lib_xua/src/core/audiohub/audiohub_dsd.h b/lib_xua/src/core/audiohub/audiohub_dsd.h index bea386bb..f101160b 100644 --- a/lib_xua/src/core/audiohub/audiohub_dsd.h +++ b/lib_xua/src/core/audiohub/audiohub_dsd.h @@ -1,4 +1,5 @@ -// Copyright (c) 2018, XMOS Ltd, All rights reserved +// Copyright 2018-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #if (DSD_CHANS_DAC != 0) extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC]; diff --git a/lib_xua/src/core/audiohub/audiohub_initport.xc b/lib_xua/src/core/audiohub/audiohub_initport.xc index a2783519..116ae38a 100644 --- a/lib_xua/src/core/audiohub/audiohub_initport.xc +++ b/lib_xua/src/core/audiohub/audiohub_initport.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2018, XMOS Ltd, All rights reserved +// Copyright 2018-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" #include "dsd_support.h" diff --git a/lib_xua/src/core/audiohub/dsd_support.h b/lib_xua/src/core/audiohub/dsd_support.h index 97b126db..a5f750c8 100644 --- a/lib_xua/src/core/audiohub/dsd_support.h +++ b/lib_xua/src/core/audiohub/dsd_support.h @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _DSD_H_ #define _DSD_H_ diff --git a/lib_xua/src/core/audiohub/xua_audiohub.xc b/lib_xua/src/core/audiohub/xua_audiohub.xc index 8eead3c0..8062b59b 100755 --- a/lib_xua/src/core/audiohub/xua_audiohub.xc +++ b/lib_xua/src/core/audiohub/xua_audiohub.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /** * @file xua_audiohub.xc * @brief XMOS USB 2.0 Audio Reference Design. Audio Functions. diff --git a/lib_xua/src/core/audiohub/xua_buffman_default.c b/lib_xua/src/core/audiohub/xua_buffman_default.c index eea225ce..20651682 100644 --- a/lib_xua/src/core/audiohub/xua_buffman_default.c +++ b/lib_xua/src/core/audiohub/xua_buffman_default.c @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xccompat.h" #include "xua_audiohub.h" diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index e503ab71..f22f9582 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" #if XUA_USB_EN @@ -7,16 +8,18 @@ #include "interrupt.h" #include "xua_commands.h" #include "xud.h" +#include "xua_usb_params_funcs.h" #ifdef NATIVE_DSD #include "usbaudio20.h" /* Defines from the USB Audio 2.0 Specifications */ #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) #include "user_hid.h" #endif #define MAX(x,y) ((x)>(y) ? (x) : (y)) + /* TODO use SLOTSIZE to potentially save memory */ /* Note we could improve on this, for one subslot is set to 4 */ /* The *4 is conversion to bytes, note we're assuming a slotsize of 4 here whic is potentially as waste */ @@ -136,6 +139,7 @@ unsigned unpackData = 0; unsigned packState = 0; unsigned packData = 0; + /* Default to something sensible but the following are setup at stream start (unless UAC1 only..) */ #if (AUDIO_CLASS == 2) unsigned g_curSubSlot_Out = HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES; @@ -145,7 +149,6 @@ unsigned g_curSubSlot_Out = FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES; unsigned g_curSubSlot_In = FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES; #endif - /* IN packet size. Init to something sensible, but expect to be re-set before stream start */ #if (AUDIO_CLASS==2) int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_IN_HS; @@ -158,6 +161,10 @@ int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_IN_FS; void handle_audio_request(chanend c_mix_out) { int space_left; +#if(defined XUA_USB_DESCRIPTOR_OVERWRITE_RATE_RES) + g_curSubSlot_Out = get_usb_to_device_bit_res() >> 3; + g_curSubSlot_In = get_device_to_usb_bit_res() >> 3; +#endif /* Input word that triggered interrupt and handshake back */ unsigned underflowSample = inuint(c_mix_out); diff --git a/lib_xua/src/core/buffer/decouple/decouple_interrupt.c b/lib_xua/src/core/buffer/decouple/decouple_interrupt.c index e91351dc..3344caea 100644 --- a/lib_xua/src/core/buffer/decouple/decouple_interrupt.c +++ b/lib_xua/src/core/buffer/decouple/decouple_interrupt.c @@ -1,4 +1,5 @@ -// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +// Copyright 2015-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" #if XUA_USB_EN #include "interrupt.h" diff --git a/lib_xua/src/core/buffer/decouple/get_adc_counts.c b/lib_xua/src/core/buffer/decouple/get_adc_counts.c index 96680b43..85767a21 100644 --- a/lib_xua/src/core/buffer/decouple/get_adc_counts.c +++ b/lib_xua/src/core/buffer/decouple/get_adc_counts.c @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" #if XUA_USB_EN #include "xud.h" diff --git a/lib_xua/src/core/buffer/decouple/interrupt.h b/lib_xua/src/core/buffer/decouple/interrupt.h index ed000b75..1aec8cd9 100644 --- a/lib_xua/src/core/buffer/decouple/interrupt.h +++ b/lib_xua/src/core/buffer/decouple/interrupt.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __interrupt_h__ #define __interrupt_h__ @@ -71,7 +72,7 @@ //int ksp_enter, ksp_exit, r11_store; -#ifdef __XS2A__ +#if defined(__XS2A__) || defined(__XS3A__) #define ISSUE_MODE_SINGLE ".issue_mode single\n" #define ISSUE_MODE_DUAL ".issue_mode dual\n" #else diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index e510d37a..50f475bd 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" #if XUA_USB_EN #include @@ -19,9 +20,9 @@ #include "xud.h" #include "testct_byref.h" -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) #include "user_hid.h" -unsigned char g_hidData[1] = {0}; +unsigned char g_hidData[HID_DATA_BYTES] = {0}; #endif void GetADCCounts(unsigned samFreq, int &min, int &mid, int &max); @@ -36,9 +37,10 @@ extern unsigned int g_curSamFreqMultiplier; #define SET_SHARED_GLOBAL0(x,y) SET_SHARED_GLOBAL(x,y) #endif - -/* Global var for speed. Related to feedback. Used by input stream to determine IN packet size */ -unsigned g_speed; +/* Initialise g_speed now so we get a sensible packet size until we start properly calculating feedback in the SoF case */ +/* Without this, zero size input packets fill the input FIFO and it takes a long time to clear out when feedback starts */ +/* This can cause a delay to the decouple ISR being serviced pushing our I2S timing. Initialising solves this */ +unsigned g_speed = (AUDIO_CLASS == 2) ? (DEFAULT_FREQ/8000) << 16 : (DEFAULT_FREQ/1000) << 16; unsigned g_freqChange = 0; unsigned feedbackValid = 0; @@ -120,7 +122,7 @@ void XUA_Buffer( chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , chanend c_hid #endif , chanend c_aud @@ -164,7 +166,7 @@ void XUA_Buffer( c_clk_int, #endif c_sof, c_aud_ctl, p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , c_hid #endif #ifdef CHAN_BUFF_CTRL @@ -182,6 +184,8 @@ void XUA_Buffer( } } +// Allows us to externally modify masterClockFreq +unsafe{volatile unsigned * unsafe masterClockFreq_ptr;} /** * Buffers data from audio endpoints @@ -223,7 +227,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , chanend c_hid #endif #ifdef CHAN_BUFF_CTRL @@ -260,7 +264,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, XUD_ep ep_int = XUD_InitEp(c_ep_int); #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) XUD_ep ep_hid = XUD_InitEp(c_hid); #endif unsigned u_tmp; @@ -268,6 +272,8 @@ void XUA_Buffer_Ep(register chanend c_aud_out, unsigned masterClockFreq = DEFAULT_MCLK_FREQ; unsigned lastClock = 0; + unsafe{masterClockFreq_ptr = &masterClockFreq;} + unsigned clocks = 0; long long clockcounter = 0; @@ -364,7 +370,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) XUD_SetReady_In(ep_hid, g_hidData, 1); #endif @@ -875,12 +881,12 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) /* HID Report Data */ case XUD_SetData_Select(c_hid, ep_hid, result): { g_hidData[0]=0; - UserReadHIDButtons(g_hidData); + UserHIDGetData(g_hidData); XUD_SetReady_In(ep_hid, g_hidData, 1); } break; diff --git a/lib_xua/src/core/buffer/ep/testct_byref.h b/lib_xua/src/core/buffer/ep/testct_byref.h index b3b82c1d..cb37b999 100644 --- a/lib_xua/src/core/buffer/ep/testct_byref.h +++ b/lib_xua/src/core/buffer/ep/testct_byref.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. //#pragma select handler #include diff --git a/lib_xua/src/core/buffer/ep/testct_byref.xc b/lib_xua/src/core/buffer/ep/testct_byref.xc index a48d3f86..0269998e 100644 --- a/lib_xua/src/core/buffer/ep/testct_byref.xc +++ b/lib_xua/src/core/buffer/ep/testct_byref.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include /* TODO Currently complier does not support inline select functions, hense this is in a seperate file to ensure this is not the case */ diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index 7c5da305..eb294057 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include diff --git a/lib_xua/src/core/clocking/clocking.h b/lib_xua/src/core/clocking/clocking.h index 39db3796..10dff9ee 100644 --- a/lib_xua/src/core/clocking/clocking.h +++ b/lib_xua/src/core/clocking/clocking.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _CLOCKING_H_ #define _CLOCKING_H_ diff --git a/lib_xua/src/core/endpoint0/chanstringgen.py b/lib_xua/src/core/endpoint0/chanstringgen.py index 49249f8a..de74c9d0 100644 --- a/lib_xua/src/core/endpoint0/chanstringgen.py +++ b/lib_xua/src/core/endpoint0/chanstringgen.py @@ -1,4 +1,5 @@ -# Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +# Copyright 2015-2021 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. def genstrings(outputChanCount, chanString, portString, structureString, adc_dac): diff --git a/lib_xua/src/core/endpoint0/chanstrings.h b/lib_xua/src/core/endpoint0/chanstrings.h index 24b75bd2..68be3481 100644 --- a/lib_xua/src/core/endpoint0/chanstrings.h +++ b/lib_xua/src/core/endpoint0/chanstrings.h @@ -1,4 +1,5 @@ -// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +// Copyright 2015-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /* AUTOGENERATED using chanstringgen.py */ /* Not very nice looking but the standard preprocessor is not very powerful diff --git a/lib_xua/src/core/endpoint0/dbcalc.h b/lib_xua/src/core/endpoint0/dbcalc.h index df2f3099..73a2875d 100644 --- a/lib_xua/src/core/endpoint0/dbcalc.h +++ b/lib_xua/src/core/endpoint0/dbcalc.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __dbcalc_h__ #define __dbcalc_h__ diff --git a/lib_xua/src/core/endpoint0/dbcalc.xc b/lib_xua/src/core/endpoint0/dbcalc.xc index 24e1e903..1967f35d 100644 --- a/lib_xua/src/core/endpoint0/dbcalc.xc +++ b/lib_xua/src/core/endpoint0/dbcalc.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include /* The coefficients of the chebychev polynomial to approximate 10^x in the interval [-1,1]. diff --git a/lib_xua/src/core/endpoint0/descriptor_defs.h b/lib_xua/src/core/endpoint0/descriptor_defs.h index 1985d910..b4dc692b 100644 --- a/lib_xua/src/core/endpoint0/descriptor_defs.h +++ b/lib_xua/src/core/endpoint0/descriptor_defs.h @@ -1,8 +1,14 @@ -// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +// Copyright 2015-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __DESCRIPTOR_DEFS_H__ #define __DESCRIPTOR_DEFS_H__ +/* + Include xua.h to pick up the #defines of NUM_USB_CHAN_IN and NUM_USB_CHAN_OUT. + */ +#include "xua.h" + #if (NUM_USB_CHAN_IN > 0) && (NUM_USB_CHAN_OUT > 0) #define AUDIO_INTERFACE_COUNT 3 #elif (NUM_USB_CHAN_IN > 0) || (NUM_USB_CHAN_OUT > 0) @@ -54,10 +60,14 @@ enum USBInterfaceNumber INTERFACE_NUMBER_IAP_EA_NATIVE_TRANS, #endif #endif -#if defined(HID_CONTROLS) && (HID_CONTROLS != 0) +#if( 0 < HID_CONTROLS ) INTERFACE_NUMBER_HID, #endif INTERFACE_COUNT /* End marker */ }; +#if( 0 < HID_CONTROLS ) +#define ENDPOINT_INT_INTERVAL_IN_HID 0x08 +#endif + #endif diff --git a/lib_xua/src/core/endpoint0/vendorrequests.c b/lib_xua/src/core/endpoint0/vendorrequests.c index 0eae49a1..66a1ac09 100644 --- a/lib_xua/src/core/endpoint0/vendorrequests.c +++ b/lib_xua/src/core/endpoint0/vendorrequests.c @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" #if XUA_USB_EN diff --git a/lib_xua/src/core/endpoint0/vendorrequests.h b/lib_xua/src/core/endpoint0/vendorrequests.h index 396ceef3..c241011d 100644 --- a/lib_xua/src/core/endpoint0/vendorrequests.h +++ b/lib_xua/src/core/endpoint0/vendorrequests.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _VENDORREQUESTS_H_ #define _VENDORREQUESTS_H_ diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index 11833693..40064918 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 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 * @author Ross Owen, XMOS Semiconductor @@ -7,10 +8,11 @@ #include #include #include - +#include +#include #include "xua.h" -#if XUA_USB_EN +#if XUA_USB_EN #include "xud_device.h" /* Standard descriptor requests */ #include "dfu_types.h" #include "usbaudio20.h" /* Defines from USB Audio 2.0 spec */ @@ -21,12 +23,19 @@ #include "vendorrequests.h" #include "xc_ptr.h" #include "xua_ep0_uacreqs.h" -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) #include "hid.h" #endif #if DSD_CHANS_DAC > 0 #include "dsd_support.h" #endif +#define DEBUG_UNIT XUA_EP0 +#ifndef DEBUG_PRINT_ENABLE_XUA_EP0 + #define DEBUG_PRINT_ENABLE_XUA_EP0 0 +#endif // DEBUG_PRINT_ENABLE_XUA_EP0 +#include "debug_print.h" + +#include "xua_usb_params_funcs.h" #ifndef __XC__ /* Support for xCORE channels in C */ @@ -58,6 +67,29 @@ #include "xua_dfu.h" #define DFU_IF_NUM INPUT_INTERFACES + OUTPUT_INTERFACES + MIDI_INTERFACES + 1 extern void device_reboot(void); + +/* Windows core USB/device driver stack may not like device coming off bus for + * a very short period of less than 500ms. Enforce at least 500ms by stalling. + * This may not have the desired effect depending on whether 'off the bus' + * requires device terminations disabled (PHY off). In that case we would be + * better off doing the reboot to DFU and then delaying PHY initialisation + * instead. Suggest revisiting. + */ +#define DELAY_BEFORE_REBOOT_TO_DFU_MS 500 + +/* Similarly to the delay before reboot to DFU mode, this delay is meant to + * avoid shocking the Windows software stack. Suggest revisiting to establish + * if 50 or 500 is needed. + */ +#define DELAY_BEFORE_REBOOT_FROM_DFU_MS 50 + +#endif + +#if( 0 < HID_CONTROLS ) +#include "xua_hid.h" +#endif +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) #endif unsigned int DFU_mode_active = 0; // 0 - App active, 1 - DFU active @@ -95,6 +127,16 @@ unsigned g_curStreamAlt_In = 0; /* Global variable for current USB bus speed (i.e. FS/HS) */ XUD_BusSpeed_t g_curUsbSpeed = 0; +/* Global variables for current USB Vendor and Product strings */ +char g_vendor_str[XUA_MAX_STR_LEN] = VENDOR_STR; +#if (AUDIO_CLASS == 2) +char g_product_str[XUA_MAX_STR_LEN] = PRODUCT_STR_A2; +#else +char g_product_str[XUA_MAX_STR_LEN] = PRODUCT_STR_A1; +#endif + +/* Global variable for current USB Serial Number strings */ +char g_serial_str[XUA_MAX_STR_LEN] = SERIAL_STR; /* Subslot */ const unsigned g_subSlot_Out_HS[OUTPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES, @@ -203,12 +245,160 @@ const unsigned g_chanCount_In_HS[INPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_I XUD_ep ep0_out; XUD_ep ep0_in; +void XUA_Endpoint0_setVendorId(unsigned short vid) { +#if (AUDIO_CLASS == 1) + devDesc_Audio1.idVendor = vid; +#else + devDesc_Audio2.idVendor = vid; +#endif // AUDIO_CLASS == 1} +} + +void concatenateAndCopyStrings(char* string1, char* string2, char* string_buffer) { + debug_printf("concatenateAndCopyStrings() for \"%s\" and \"%s\"\n", string1, string2); + + memset(string_buffer, '\0', strlen(string_buffer)); + + uint32_t remaining_buffer_size = MIN(strlen(string1), XUA_MAX_STR_LEN-1); + strncpy(string_buffer, string1, remaining_buffer_size); + uint32_t total_string_size = MIN(strlen(string1)+strlen(string2), XUA_MAX_STR_LEN-1); + if (total_string_size==XUA_MAX_STR_LEN-1) { + remaining_buffer_size = XUA_MAX_STR_LEN-1-strlen(string1); + } else { + remaining_buffer_size = strlen(string2); + } + + strncat(string_buffer, string2, remaining_buffer_size); + debug_printf("concatenateAndCopyStrings() creates \"%s\"\n", string_buffer); +} + +void XUA_Endpoint0_setStrTable() { + + // update Vendor strings + concatenateAndCopyStrings(g_vendor_str, "", g_strTable.vendorStr); +#if (AUDIO_CLASS == 2) + concatenateAndCopyStrings(g_vendor_str, " Clock Selector", g_strTable.clockSelectorStr); + concatenateAndCopyStrings(g_vendor_str, " Internal Clock", g_strTable.internalClockSourceStr); +#endif +#if SPDIF_RX + concatenateAndCopyStrings(g_vendor_str, " S/PDIF Clock", g_strTable.spdifClockSourceStr); +#endif +#if ADAT_RX + concatenateAndCopyStrings(g_vendor_str, " ADAT Clock", g_strTable.adatClockSourceStr); +#endif +#if (XUA_DFU_EN == 1) + concatenateAndCopyStrings(g_vendor_str, " DFU", g_strTable.dfuStr); +#endif +#ifdef USB_CONTROL_DESCS + concatenateAndCopyStrings(g_vendor_str, " Control", g_strTable.ctrlStr); +#endif +#ifdef MIDI + concatenateAndCopyStrings(g_vendor_str, " MIDI Out", g_strTable.midiOutStr); + concatenateAndCopyStrings(g_vendor_str, " MIDI In", g_strTable.midiInStr); +#endif + // update product strings +#if (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) + concatenateAndCopyStrings(g_product_str, "", g_strTable.productStr_Audio1); + concatenateAndCopyStrings(g_product_str, "", g_strTable.outputInterfaceStr_Audio1); + concatenateAndCopyStrings(g_product_str, "", g_strTable.inputInterfaceStr_Audio1); + concatenateAndCopyStrings(g_product_str, "", g_strTable.usbInputTermStr_Audio1); + concatenateAndCopyStrings(g_product_str, "", g_strTable.usbOutputTermStr_Audio1); +#elif (AUDIO_CLASS == 2) + concatenateAndCopyStrings(g_product_str, "", g_strTable.productStr_Audio2); + concatenateAndCopyStrings(g_product_str, "", g_strTable.outputInterfaceStr_Audio2); + concatenateAndCopyStrings(g_product_str, "", g_strTable.inputInterfaceStr_Audio2); + concatenateAndCopyStrings(g_product_str, "", g_strTable.usbInputTermStr_Audio2); + concatenateAndCopyStrings(g_product_str, "", g_strTable.usbOutputTermStr_Audio2); +#endif + + // update Serial strings + concatenateAndCopyStrings(g_serial_str, "", g_strTable.serialStr); +} + +void XUA_Endpoint0_setVendorStr(char* vendor_str) { + debug_printf("XUA_Endpoint0_setVendorStr() with string %s\n", vendor_str); + concatenateAndCopyStrings(vendor_str, "", g_vendor_str); +} + +void XUA_Endpoint0_setProductStr(char* product_str) { + debug_printf("XUA_Endpoint0_setProductStr() with string %s\n", product_str); + concatenateAndCopyStrings(product_str, "", g_product_str); +} + +void XUA_Endpoint0_setSerialStr(char* serial_str) { + debug_printf("XUA_Endpoint0_setSerialStr() with string %s\n", serial_str); + concatenateAndCopyStrings(serial_str, "", g_serial_str); +} + +char* XUA_Endpoint0_getVendorStr() { + return g_strTable.vendorStr; +} + +char* XUA_Endpoint0_getProductStr() { + #if (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) + return g_strTable.productStr_Audio1; + #elif (AUDIO_CLASS == 2) + return g_strTable.productStr_Audio2; + #endif +} + +char* XUA_Endpoint0_getSerialStr() { + return g_strTable.serialStr; +} + +void XUA_Endpoint0_setProductId(unsigned short pid) { +#if (AUDIO_CLASS == 1) + devDesc_Audio1.idProduct = pid; +#else + devDesc_Audio2.idProduct = pid; +#endif // AUDIO_CLASS == 1} +} + +unsigned short XUA_Endpoint0_getVendorId() { + unsigned short vid; +#if (AUDIO_CLASS == 1) + vid = devDesc_Audio1.idVendor; +#else + vid = devDesc_Audio2.idVendor; +#endif // AUDIO_CLASS == 1} + return vid; +} + +unsigned short XUA_Endpoint0_getProductId() { + unsigned short pid; +#if (AUDIO_CLASS == 1) + pid = devDesc_Audio1.idProduct; +#else + pid = devDesc_Audio2.idProduct; +#endif // AUDIO_CLASS == 1} + return pid; +} + +unsigned short XUA_Endpoint0_getBcdDevice() { + unsigned short bcd; +#if (AUDIO_CLASS == 1) + bcd = devDesc_Audio1.bcdDevice; +#else + bcd = devDesc_Audio2.bcdDevice; +#endif // AUDIO_CLASS == 1} + return bcd; +} + +void XUA_Endpoint0_setBcdDevice(unsigned short bcd) { +#if (AUDIO_CLASS == 1) + devDesc_Audio1.bcdDevice = bcd; +#else + devDesc_Audio2.bcdDevice = bcd; +#endif // AUDIO_CLASS == 1} +} + void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_) { ep0_out = XUD_InitEp(c_ep0_out); ep0_in = XUD_InitEp(c_ep0_in); + XUA_Endpoint0_setStrTable(); + #if 0 /* Dont need to init globals.. */ /* Init tables for volumes (+ 1 for master) */ @@ -296,30 +486,36 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioCont } #endif -} +#ifdef XUA_USB_DESCRIPTOR_OVERWRITE_RATE_RES //change USB descriptor frequencies and bit resolution values here -void XUA_Endpoint0_lite_init(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, - chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_) -{ - ep0_out = XUD_InitEp(c_ep0_out); - ep0_in = XUD_InitEp(c_ep0_in); + cfgDesc_Audio1[USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME] = get_device_to_usb_bit_res() >> 3; //sub frame rate = bit rate /8 + cfgDesc_Audio1[USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME + 1] = (get_device_to_usb_bit_res() & 0xff); //bit resolution - VendorRequests_Init(VENDOR_REQUESTS_PARAMS); + cfgDesc_Audio1[USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME] = get_usb_to_device_bit_res() >> 3; //sub frame rate = bit rate /8 + cfgDesc_Audio1[USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME + 1] = (get_usb_to_device_bit_res() & 0xff); //bit resolution -#ifdef VENDOR_AUDIO_REQS - VendorAudioRequestsInit(c_audioControl, c_mix_ctl, c_clk_ctl); -#endif - -#if (XUA_DFU_EN == 1) - /* Check if device has started in DFU mode */ - if (DFUReportResetState(null)) + const unsigned num_of_usb_descriptor_freq=3; //This should be =3 according to the comments "using a value of <=2 or > 7 for num_freqs_a1 causes enumeration issues on Windows" in xua_ep0_descriptors.h + int i=0; + for(i=0;i> 8; + cfgDesc_Audio1[USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_FREQ + 3*i + 2] = (get_device_to_usb_rate() & 0xff0000)>> 16; } + + for(i=0;i> 8; + cfgDesc_Audio1[USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_FREQ + 3*i + 2] = (get_usb_to_device_rate() & 0xff0000)>> 16; + } + + cfgDesc_Audio1[USB_AS_IN_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE] = ((get_device_to_usb_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_IN_FS) & 0xff; //max packet size + cfgDesc_Audio1[USB_AS_IN_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE + 1] = (((get_device_to_usb_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_IN_FS) & 0xff00) >> 8; //max packet size + + 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 } @@ -436,23 +632,48 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 } #if (NUM_USB_CHAN_OUT > 0) && (NUM_USB_CHAN_IN > 0) - if ((sp.wIndex == INTERFACE_NUMBER_AUDIO_OUTPUT) || (sp.wIndex == INTERFACE_NUMBER_AUDIO_INPUT)) + unsigned num_input_interfaces = g_interfaceAlt[INTERFACE_NUMBER_AUDIO_INPUT]; + unsigned num_output_interfaces = g_interfaceAlt[INTERFACE_NUMBER_AUDIO_OUTPUT]; + if (sp.wIndex == INTERFACE_NUMBER_AUDIO_INPUT) { - /* Check for stream start stop on output and input audio interfaces */ - if(sp.wValue && !g_interfaceAlt[INTERFACE_NUMBER_AUDIO_OUTPUT] && !g_interfaceAlt[INTERFACE_NUMBER_AUDIO_INPUT]) + // in: 0 -> 1 + if (sp.wValue && !num_input_interfaces) { - /* If start and input AND output not currently running */ - UserAudioStreamStart(); + UserAudioInputStreamStart(); + if (!num_output_interfaces) + { + UserAudioStreamStart(); + } } - else if(((sp.wIndex == 1) && (!sp.wValue)) && g_interfaceAlt[INTERFACE_NUMBER_AUDIO_OUTPUT] && (!g_interfaceAlt[INTERFACE_NUMBER_AUDIO_INPUT])) + // in: 1 -> 0 + else if (!sp.wValue && num_input_interfaces) { - /* if output stop and output running and input not running */ - UserAudioStreamStop(); + UserAudioInputStreamStop(); + if (!num_output_interfaces) + { + UserAudioStreamStop(); + } } - else if(((sp.wIndex == 2) && (!sp.wValue)) && g_interfaceAlt[INTERFACE_NUMBER_AUDIO_INPUT] && (!g_interfaceAlt[INTERFACE_NUMBER_AUDIO_OUTPUT])) + } + else if (sp.wIndex == INTERFACE_NUMBER_AUDIO_OUTPUT) + { + // out: 0 -> 1 + if (sp.wValue && !num_output_interfaces) { - /* if input stop and input running and output not running */ - UserAudioStreamStop(); + UserAudioOutputStreamStart(); + if (!num_input_interfaces) + { + UserAudioStreamStart(); + } + } + // out: 1 -> 0 + else if (!sp.wValue && num_output_interfaces) + { + UserAudioOutputStreamStop(); + if (!num_input_interfaces) + { + UserAudioStreamStop(); + } } } #elif (NUM_USB_CHAN_OUT > 0) @@ -462,11 +683,13 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 { /* if start and not currently running */ UserAudioStreamStart(); + UserAudioOutputStreamStart(); } else if (!sp.wValue && g_interfaceAlt[INTERFACE_NUMBER_AUDIO_OUTPUT]) { /* if stop and currently running */ UserAudioStreamStop(); + UserAudioOutputStreamStop(); } } #elif (NUM_USB_CHAN_IN > 0) @@ -476,11 +699,13 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 { /* if start and not currently running */ UserAudioStreamStart(); + UserAudioInputStreamStart(); } else if (!sp.wValue && g_interfaceAlt[INTERFACE_NUMBER_AUDIO_INPUT]) { /* if stop and currently running */ UserAudioStreamStop(); + UserAudioInputStreamStop(); } } #endif @@ -492,7 +717,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 switch(sp.bRequest) { -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) case USB_GET_DESCRIPTOR: /* Check what inteface request is for */ @@ -606,10 +831,16 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 if(reset) { - DFUDelay(50000000); + DFUDelay(DELAY_BEFORE_REBOOT_TO_DFU_MS * 100000); device_reboot(); } } +#endif +#if( 0 < HID_CONTROLS ) + if (interfaceNum == INTERFACE_NUMBER_HID) + { + result = HidInterfaceClassRequests(ep0_out, ep0_in, &sp); + } #endif /* Check for: - Audio CONTROL interface request - always 0, note we check for DFU first * - Audio STREAMING interface request (In or Out) @@ -668,7 +899,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 if(result == XUD_RES_ERR) { -#if (XUA_DFU_EN == 1) +#if (XUA_DFU_EN == 1) if (!DFU_mode_active) { #endif @@ -821,386 +1052,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 DFU_mode_active = 0; /* Send reboot command */ - DFUDelay(5000000); - device_reboot(); - } - } -#endif - } -} - -void XUA_Endpoint0_lite_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, - chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_ - , unsigned *input_interface_num, unsigned *output_interface_num) -{ - if (result == XUD_RES_OKAY) - { - result = XUD_RES_ERR; - - /* Inspect Request type and Receipient and direction */ - switch( (sp.bmRequestType.Direction << 7) | (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5) ) - { - case USB_BMREQ_H2D_STANDARD_INT: - - /* Over-riding USB_StandardRequests implementation */ - if(sp.bRequest == USB_SET_INTERFACE) - { - switch (sp.wIndex) - { - /* Check for audio stream from host start/stop */ -#if (NUM_USB_CHAN_OUT > 0) - case INTERFACE_NUMBER_AUDIO_OUTPUT: - *output_interface_num = sp.wValue; - break; -#endif - -#if (NUM_USB_CHAN_IN > 0) - case INTERFACE_NUMBER_AUDIO_INPUT: - *input_interface_num = sp.wValue; - break; -#endif - default: - /* Unhandled interface */ - break; - } - } /* if(sp.bRequest == SET_INTERFACE) */ - - break; /* BMREQ_H2D_STANDARD_INT */ - - case USB_BMREQ_D2H_STANDARD_INT: - - switch(sp.bRequest) - { -#ifdef HID_CONTROLS - case USB_GET_DESCRIPTOR: - - /* Check what inteface request is for */ - if(sp.wIndex == INTERFACE_NUMBER_HID) - { - /* High byte of wValue is descriptor type */ - unsigned descriptorType = sp.wValue & 0xff00; - - switch (descriptorType) - { - case HID_HID: - /* Return HID Descriptor */ - result = XUD_DoGetRequest(ep0_out, ep0_in, hidDescriptor, - sizeof(hidDescriptor), sp.wLength); - break; - case HID_REPORT: - /* Return HID report descriptor */ - result = XUD_DoGetRequest(ep0_out, ep0_in, hidReportDescriptor, - sizeof(hidReportDescriptor), sp.wLength); - break; - } - } - break; -#endif - default: - break; - } - break; - - /* Recipient: Device */ - case USB_BMREQ_H2D_STANDARD_DEV: - - /* Inspect for actual request */ - switch( sp.bRequest ) - { - /* Standard request: SetConfiguration */ - /* Overriding implementation in USB_StandardRequests */ - case USB_SET_CONFIGURATION: - - //if(g_current_config == 1) - { - /* Consider host active with valid driver at this point */ - UserHostActive(1); - } - - /* We want to run USB_StandardsRequests() implementation also. Don't modify result - * and don't call XUD_DoSetRequestStatus() */ - break; - - default: - //Unknown device request" - break; - } - break; - - /* Audio Class 1.0 Sampling Freqency Requests go to Endpoint */ - case USB_BMREQ_H2D_CLASS_EP: - case USB_BMREQ_D2H_CLASS_EP: - { - unsigned epNum = sp.wIndex & 0xff; - - if ((epNum == ENDPOINT_ADDRESS_OUT_AUDIO) || (epNum == ENDPOINT_ADDRESS_IN_AUDIO)) - { -#if (AUDIO_CLASS == 2) && (AUDIO_CLASS_FALLBACK) - if(g_curUsbSpeed == XUD_SPEED_FS) - { - result = AudioEndpointRequests_1(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl); - } -#elif (AUDIO_CLASS==1) - result = AudioEndpointRequests_1(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl); -#endif - } - - } - break; - - case USB_BMREQ_H2D_CLASS_INT: - case USB_BMREQ_D2H_CLASS_INT: - { - unsigned interfaceNum = sp.wIndex & 0xff; - //unsigned request = (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5); - - /* TODO Check on return value retval = */ -#if (XUA_DFU_EN == 1) - unsigned DFU_IF = INTERFACE_NUMBER_DFU; - - /* DFU interface number changes based on which mode we are currently running in */ - if (DFU_mode_active) - { - DFU_IF = 0; - } - - if (interfaceNum == DFU_IF) - { - int reset = 0; - - /* If running in application mode stop audio */ - /* Don't interupt audio for save and restore cmds */ - if ((DFU_IF == INTERFACE_NUMBER_DFU) && (sp.bRequest != XMOS_DFU_SAVESTATE) && - (sp.bRequest != XMOS_DFU_RESTORESTATE)) - { - // Stop audio - outuint(c_audioControl, SET_SAMPLE_FREQ); - outuint(c_audioControl, AUDIO_STOP_FOR_DFU); - // Handshake - chkct(c_audioControl, XS1_CT_END); - } - - /* This will return 1 if reset requested */ - result = DFUDeviceRequests(ep0_out, &ep0_in, &sp, null, g_interfaceAlt[sp.wIndex], dfuInterface, &reset); - - if(reset) - { - DFUDelay(50000000); - device_reboot(); - } - } -#endif - /* 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) - */ - if(((interfaceNum == 0) || (interfaceNum == 1) || (interfaceNum == 2)) -#if (XUA_DFU_EN == 1) - && !DFU_mode_active -#endif - ) - { -#if (AUDIO_CLASS == 2) && (AUDIO_CLASS_FALLBACK) - if(g_curUsbSpeed == XUD_SPEED_HS) - { - result = AudioClassRequests_2(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl); - } - else - { - result = AudioClassRequests_1(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl); - } -#elif (AUDIO_CLASS==2) - result = AudioClassRequests_2(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl); -#else - result = AudioClassRequests_1(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl); -#endif - -#ifdef VENDOR_AUDIO_REQS - /* If result is ERR at this point, then request to audio interface not handled - handle vendor audio reqs */ - if(result == XUD_RES_ERR) - { - result = VendorAudioRequests(ep0_out, ep0_in, sp.bRequest, - sp.wValue >> 8, sp.wValue & 0xff, - sp.wIndex >> 8, sp.bmRequestType.Direction, - c_audioControl, c_mix_ctl, c_clk_ctl); - } -#endif - } - } - break; - - default: - break; - } - - } /* if(result == XUD_RES_OKAY) */ - - { - if(result == XUD_RES_ERR) - { - /* Run vendor defined parsing/processing */ - /* Note, an interface might seem ideal here but this *must* be executed on the same - * core sure to shared memory depandancy */ - result = VendorRequests(ep0_out, ep0_in, &sp VENDOR_REQUESTS_PARAMS_); - } - } - - if(result == XUD_RES_ERR) - { -#if (XUA_DFU_EN == 1) - if (!DFU_mode_active) - { -#endif -#if (AUDIO_CLASS_FALLBACK) && (AUDIO_CLASS != 1) - /* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */ - result = USB_StandardRequests(ep0_out, ep0_in, - (unsigned char*)&devDesc_Audio2, sizeof(devDesc_Audio2), - (unsigned char*)&cfgDesc_Audio2, sizeof(cfgDesc_Audio2), - (unsigned char*)&devDesc_Audio1, sizeof(devDesc_Audio1), - cfgDesc_Audio1, sizeof(cfgDesc_Audio1), - (char**)&g_strTable, sizeof(g_strTable)/sizeof(char *), - &sp, g_curUsbSpeed); -#elif FULL_SPEED_AUDIO_2 - /* Return Audio 2.0 Descriptors for high_speed and full-speed */ - - /* Unfortunately we need to munge the descriptors a bit between full and high-speed */ - if(g_curUsbSpeed == XUD_SPEED_HS) - { - /* Modify Audio Class 2.0 Config descriptor for High-speed operation */ -#if (NUM_USB_CHAN_OUT > 0) - cfgDesc_Audio2.Audio_CS_Control_Int.Audio_Out_InputTerminal.bNrChannels = NUM_USB_CHAN_OUT; -#if (NUM_USB_CHAN_OUT > 0) - 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; -#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; -#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; -#endif -#endif -#if (NUM_USB_CHAN_IN > 0) - cfgDesc_Audio2.Audio_CS_Control_Int.Audio_In_InputTerminal.bNrChannels = NUM_USB_CHAN_IN; - cfgDesc_Audio2.Audio_In_Format.bSubslotSize = HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES; - cfgDesc_Audio2.Audio_In_Format.bBitResolution = HS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS; - cfgDesc_Audio2.Audio_In_Endpoint.wMaxPacketSize = HS_STREAM_FORMAT_INPUT_1_MAXPACKETSIZE; - cfgDesc_Audio2.Audio_In_ClassStreamInterface.bNrChannels = NUM_USB_CHAN_IN; -#endif - } - else - { - /* Modify Audio Class 2.0 Config descriptor for Full-speed operation */ -#if (NUM_USB_CHAN_OUT > 0) - cfgDesc_Audio2.Audio_CS_Control_Int.Audio_Out_InputTerminal.bNrChannels = NUM_USB_CHAN_OUT_FS; -#if (NUM_USB_CHAN_OUT > 0) - cfgDesc_Audio2.Audio_Out_Format.bSubslotSize = FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES; - cfgDesc_Audio2.Audio_Out_Format.bBitResolution = FS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS; - cfgDesc_Audio2.Audio_Out_Endpoint.wMaxPacketSize = FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE; - cfgDesc_Audio2.Audio_Out_ClassStreamInterface.bNrChannels = NUM_USB_CHAN_OUT_FS; -#endif -#if (OUTPUT_FORMAT_COUNT > 1) - cfgDesc_Audio2.Audio_Out_Format_2.bSubslotSize = FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES; - cfgDesc_Audio2.Audio_Out_Format_2.bBitResolution = FS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS; - cfgDesc_Audio2.Audio_Out_Endpoint_2.wMaxPacketSize = FS_STREAM_FORMAT_OUTPUT_2_MAXPACKETSIZE; - cfgDesc_Audio2.Audio_Out_ClassStreamInterface_2.bNrChannels = NUM_USB_CHAN_OUT_FS; -#endif - -#if (OUTPUT_FORMAT_COUNT > 2) - cfgDesc_Audio2.Audio_Out_Format_3.bSubslotSize = FS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES; - cfgDesc_Audio2.Audio_Out_Format_3.bBitResolution = FS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS; - cfgDesc_Audio2.Audio_Out_Endpoint_3.wMaxPacketSize = FS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE; - cfgDesc_Audio2.Audio_Out_ClassStreamInterface_3.bNrChannels = NUM_USB_CHAN_OUT_FS; -#endif -#endif -#if (NUM_USB_CHAN_IN > 0) - cfgDesc_Audio2.Audio_CS_Control_Int.Audio_In_InputTerminal.bNrChannels = NUM_USB_CHAN_IN_FS; - cfgDesc_Audio2.Audio_In_Format.bSubslotSize = FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES; - cfgDesc_Audio2.Audio_In_Format.bBitResolution = FS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS; - cfgDesc_Audio2.Audio_In_Endpoint.wMaxPacketSize = FS_STREAM_FORMAT_INPUT_1_MAXPACKETSIZE; - cfgDesc_Audio2.Audio_In_ClassStreamInterface.bNrChannels = NUM_USB_CHAN_IN_FS; -#endif - } - - result = USB_StandardRequests(ep0_out, ep0_in, - (unsigned char*)&devDesc_Audio2, sizeof(devDesc_Audio2), - (unsigned char*)&cfgDesc_Audio2, sizeof(cfgDesc_Audio2), - null, 0, - null, 0, -#ifdef __XC__ - g_strTable, sizeof(g_strTable), sp, null, g_curUsbSpeed); -#else - (char**)&g_strTable, sizeof(g_strTable)/sizeof(char *), &sp, g_curUsbSpeed); -#endif -#elif (AUDIO_CLASS == 1) - /* Return Audio 1.0 Descriptors in FS, should never be in HS! */ - result = USB_StandardRequests(ep0_out, ep0_in, - null, 0, - null, 0, - (unsigned char*)&devDesc_Audio1, sizeof(devDesc_Audio1), - cfgDesc_Audio1, sizeof(cfgDesc_Audio1), - (char**)&g_strTable, sizeof(g_strTable)/sizeof(char *), &sp, g_curUsbSpeed); -#else - /* Return Audio 2.0 Descriptors with Null device as fallback */ - result = USB_StandardRequests(ep0_out, ep0_in, - (unsigned char*)&devDesc_Audio2, sizeof(devDesc_Audio2), - (unsigned char*)&cfgDesc_Audio2, sizeof(cfgDesc_Audio2), - devDesc_Null, sizeof(devDesc_Null), - cfgDesc_Null, sizeof(cfgDesc_Null), - (char**)&g_strTable, sizeof(g_strTable)/sizeof(char *), &sp, g_curUsbSpeed); -#endif -#if (XUA_DFU_EN == 1) - } - - else - { - /* Running in DFU mode - always return same descs for DFU whether HS or FS */ - result = USB_StandardRequests(ep0_out, ep0_in, - DFUdevDesc, sizeof(DFUdevDesc), - DFUcfgDesc, sizeof(DFUcfgDesc), - null, 0, /* Used same descriptors for full and high-speed */ - null, 0, - (char**)&g_strTable, sizeof(g_strTable)/sizeof(char *), &sp, g_curUsbSpeed); - } -#endif - } - - if (result == XUD_RES_RST) - { -#ifdef __XC__ - g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in); -#else - g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, &ep0_in); -#endif - g_currentConfig = 0; - g_curStreamAlt_Out = 0; - g_curStreamAlt_In = 0; - -#if (XUA_DFU_EN == 1) - if (DFUReportResetState(null)) - { - if (!DFU_mode_active) - { - DFU_mode_active = 1; - } - } - else - { - if (DFU_mode_active) - { - DFU_mode_active = 0; - - /* Send reboot command */ - DFUDelay(5000000); + DFUDelay(DELAY_BEFORE_REBOOT_FROM_DFU_MS * 100000); device_reboot(); } } diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index 570bc1b8..4e219a58 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2019, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /** * @file xua_ep0_descriptors.h * @brief Device Descriptors @@ -26,7 +27,24 @@ #define APPEND_PRODUCT_STR_A1(x) PRODUCT_STR_A1 " "#x -#define STR_TABLE_ENTRY(name) char *name +#define STR_TABLE_ENTRY(name) char * name + +// The empty strings below are used in the g_strTable to set the maximum size of the table entries +// The last char of the strings are different, so that the compiler allocates separate memory spaces +#define XUA_VENDOR_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01" +#define XUA_PRODUCT_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\02" +#define XUA_CLOCK_SELECTOR_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\03" +#define XUA_INTERNAL_CLOCK_SELECTOR_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\04" +#define XUA_SPDIF_CLOCK_SOURCE_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\05" +#define XUA_ADAT_CLOCK_SOURCE_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\06" +#define XUA_DFU_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\07" +#define XUA_CTRL_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\08" +#define XUA_MIDI_OUT_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\09" +#define XUA_MIDI_IN_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0a" +#define XUA_SERIAL_EMPTY_STRING "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0b" + +// The value below must match the length of XUA_DESCR_EMPTY_STRING. +#define XUA_MAX_STR_LEN (32) #define ISO_EP_ATTRIBUTES_ASYNCH 0x05 //ISO, ASYNCH, DATA EP #define ISO_EP_ATTRIBUTES_ADAPTIVE 0x09 //ISO, ADAPTIVE, DATA EP @@ -69,7 +87,7 @@ typedef struct #if ADAT_RX STR_TABLE_ENTRY(adatClockSourceStr); /* iClockSource for external S/PDIF clock */ #endif -#endif +#endif // AUDIO_CLASS == 2 #if (XUA_DFU_EN == 1) STR_TABLE_ENTRY(dfuStr); /* iInterface for DFU interface */ #endif @@ -317,41 +335,42 @@ typedef struct StringDescTable_t g_strTable = { .langID = "\x09\x04", /* US English */ - .vendorStr = VENDOR_STR, - .serialStr = "", + .vendorStr = XUA_VENDOR_EMPTY_STRING, + .serialStr = XUA_SERIAL_EMPTY_STRING, #if (AUDIO_CLASS == 2) - .productStr_Audio2 = PRODUCT_STR_A2, - .outputInterfaceStr_Audio2 = APPEND_PRODUCT_STR_A2(), - .inputInterfaceStr_Audio2 = APPEND_PRODUCT_STR_A2(), - .usbInputTermStr_Audio2 = APPEND_PRODUCT_STR_A2(), - .usbOutputTermStr_Audio2 = APPEND_PRODUCT_STR_A2(), + .productStr_Audio2 = XUA_PRODUCT_EMPTY_STRING, + .outputInterfaceStr_Audio2 = XUA_PRODUCT_EMPTY_STRING, + .inputInterfaceStr_Audio2 = XUA_PRODUCT_EMPTY_STRING, + .usbInputTermStr_Audio2 = XUA_PRODUCT_EMPTY_STRING, + .usbOutputTermStr_Audio2 = XUA_PRODUCT_EMPTY_STRING, #endif #if (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) - .productStr_Audio1 = PRODUCT_STR_A1, - .outputInterfaceStr_Audio1 = APPEND_PRODUCT_STR_A1(), - .inputInterfaceStr_Audio1 = APPEND_PRODUCT_STR_A1(), - .usbInputTermStr_Audio1 = APPEND_PRODUCT_STR_A1(), - .usbOutputTermStr_Audio1 = APPEND_PRODUCT_STR_A1(), + + .productStr_Audio1 = XUA_PRODUCT_EMPTY_STRING, + .outputInterfaceStr_Audio1 = XUA_PRODUCT_EMPTY_STRING, + .inputInterfaceStr_Audio1 = XUA_PRODUCT_EMPTY_STRING, + .usbInputTermStr_Audio1 = XUA_PRODUCT_EMPTY_STRING, + .usbOutputTermStr_Audio1 = XUA_PRODUCT_EMPTY_STRING, #endif #if (AUDIO_CLASS == 2) - .clockSelectorStr = APPEND_VENDOR_STR(Clock Selector), - .internalClockSourceStr = APPEND_VENDOR_STR(Internal Clock), + .clockSelectorStr = XUA_CLOCK_SELECTOR_EMPTY_STRING, + .internalClockSourceStr = XUA_INTERNAL_CLOCK_SELECTOR_EMPTY_STRING, #if SPDIF_RX - .spdifClockSourceStr = APPEND_VENDOR_STR(S/PDIF Clock), + .spdifClockSourceStr = XUA_SPDIF_CLOCK_SOURCE_EMPTY_STRING, #endif #if ADAT_RX - .adatClockSourceStr = APPEND_VENDOR_STR(ADAT Clock), -#endif + .adatClockSourceStr = XUA_ADAT_CLOCK_SOURCE_EMPTY_STRING, #endif +#endif // AUDIO_CLASS == 2 #if (XUA_DFU_EN == 1) - .dfuStr = APPEND_VENDOR_STR(DFU), + .dfuStr = XUA_DFU_EMPTY_STRING, #endif #ifdef USB_CONTROL_DESCS - .ctrlStr = APPEND_VENDOR_STR(Control), + .ctrlStr = XUA_CTRL_EMPTY_STRING, #endif #ifdef MIDI - .midiOutStr = APPEND_VENDOR_STR(MIDI Out), - .midiInStr = APPEND_VENDOR_STR(MIDI In), + .midiOutStr = XUA_MIDI_OUT_EMPTY_STRING, + .midiInStr = XUA_MIDI_IN_EMPTY_STRING, #endif #include "chanstrings.h" @@ -417,7 +436,7 @@ USB_Descriptor_Device_t devDesc_Audio1 = .bcdDevice = BCD_DEVICE, .iManufacturer = offsetof(StringDescTable_t, vendorStr)/sizeof(char *), .iProduct = offsetof(StringDescTable_t, productStr_Audio1)/sizeof(char *), - .iSerialNumber = 0, + .iSerialNumber = offsetof(StringDescTable_t, serialStr)/sizeof(char *), .bNumConfigurations = 1 }; #endif @@ -453,7 +472,7 @@ USB_Descriptor_Device_t devDesc_Audio2 = .bcdDevice = BCD_DEVICE, .iManufacturer = offsetof(StringDescTable_t, vendorStr)/sizeof(char *), .iProduct = offsetof(StringDescTable_t, productStr_Audio2)/sizeof(char *), - .iSerialNumber = 0, + .iSerialNumber = offsetof(StringDescTable_t, serialStr)/sizeof(char *), .bNumConfigurations = 0x02 /* Set to 2 such that windows does not load composite driver */ }; @@ -476,7 +495,7 @@ unsigned char devDesc_Null[] = (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ offsetof(StringDescTable_t, vendorStr)/sizeof(char *), offsetof(StringDescTable_t, productStr_Audio2)/sizeof(char *), - 0, /* 16 iSerialNumber : Index of serial number decriptor */ + offsetof(StringDescTable_t, serialStr)/sizeof(char *), /* 16 iSerialNumber : Index of serial number decriptor */ 0x01 /* 17 bNumConfigurations : Number of possible configs */ }; #endif @@ -561,27 +580,30 @@ unsigned char devQualDesc_Null[] = #define MIXER_LENGTH (0) #endif - -#ifdef HID_CONTROLS -unsigned char hidReportDescriptor[] = +#if( 0 < HID_CONTROLS ) +unsigned char hidReportDescriptor[] = /* Voice Command usage as per request #HUTRR45 */ { - 0x05, 0x0c, /* Usage Page (Consumer Device) */ - 0x09, 0x01, /* Usage (Consumer Control) */ - 0xa1, 0x01, /* Collection (Application) */ - 0x15, 0x00, /* Logical Minimum (0) */ - 0x25, 0x01, /* Logical Maximum (1) */ - 0x09, 0xb0, /* Usage (Play) */ - 0x09, 0xb5, /* Usage (Scan Next Track) */ - 0x09, 0xb6, /* Usage (Scan Previous Track) */ - 0x09, 0xe9, /* Usage (Volume Up) */ - 0x09, 0xea, /* Usage (Volume Down) */ - 0x09, 0xe2, /* Usage (Mute) */ - 0x75, 0x01, /* Report Size (1) */ - 0x95, 0x06, /* Report Count (6) */ - 0x81, 0x02, /* Input (Data, Var, Abs) */ - 0x95, 0x02, /* Report Count (2) */ - 0x81, 0x01, /* Input (Cnst, Ary, Abs) */ - 0xc0 /* End collection */ + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x06, /* Usage (Keyboard) */ + 0xa1, 0x01, /* Collection (Application) */ + 0x75, 0x01, /* Report Size (1) */ + 0x95, 0x04, /* Report Count (4) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x00, /* Logical Maximum (0) */ + 0x81, 0x01, /* Input (Cnst, Ary, Abs, No Wrap, Lin, Pref, No Nul) */ + 0x95, 0x01, /* Report Count (1) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x05, 0x0C, /* Usage Page (Consumer) */ + 0x0a, 0x21, 0x02, /* Usage (AC Search) */ + 0x81, 0x02, /* Input (Data, Var, Abs, No Wrap, Lin, Pref, No Nul) */ + 0x0a, 0x26, 0x02, /* Usage (AC Stop) */ + 0x81, 0x02, /* Input (Data, Var, Abs, No Wrap, Lin, Pref, No Nul) */ + 0x95, 0x02, /* Report Count (2) */ + 0x05, 0x07, /* Usage Page (Key Codes) */ + 0x19, 0x72, /* Usage Minimum (Keyboard F23) */ + 0x29, 0x73, /* Usage Maximum (Keyboard F24) */ + 0x81, 0x02, /* Input (Data, Var, Abs, No Wrap, Lin, Pref, No Nul) */ + 0xc0 /* End collection (Application) */ }; #endif @@ -724,7 +746,7 @@ typedef struct #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) USB_Descriptor_Endpoint_t Audio_Out_Fb_Endpoint_2; #endif -#endif +#endif // OUTPUT_FORMAT_COUNT > 1 #if (OUTPUT_FORMAT_COUNT > 2) USB_Descriptor_Interface_t Audio_Out_StreamInterface_Alt3; USB_Descriptor_Audio_Interface_AS_t Audio_Out_ClassStreamInterface_3; @@ -734,8 +756,8 @@ typedef struct #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) USB_Descriptor_Endpoint_t Audio_Out_Fb_Endpoint_3; #endif -#endif -#endif +#endif // OUTPUT_FORMAT_COUNT > 2 +#endif // NUM_USB_CHAN_OUT > 0 #if (NUM_USB_CHAN_IN > 0) /* Audio Streaming: Input stream */ USB_Descriptor_Interface_t Audio_In_StreamInterface_Alt0; /* Zero bandwith alternative */ @@ -758,7 +780,7 @@ typedef struct USB_Descriptor_Endpoint_t Audio_In_Endpoint_3; USB_Descriptor_Audio_Class_AS_Endpoint_t Audio_In_ClassEndpoint_3; #endif -#endif +#endif // NUM_USB_CHAN_IN > 0 #ifdef MIDI /* MIDI descriptors currently handled as a single block */ unsigned char configDesc_Midi[MIDI_LENGTH]; @@ -782,9 +804,9 @@ typedef struct USB_Descriptor_Endpoint_t iAP_EANativeTransport_Out_Endpoint; USB_Descriptor_Endpoint_t iAP_EANativeTransport_In_Endpoint; #endif -#endif +#endif // IAP -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) USB_Descriptor_Interface_t HID_Interface; unsigned char hidDesc[9]; //TODO ideally we would have a struct for this. USB_Descriptor_Endpoint_t HID_In_Endpoint; @@ -1099,7 +1121,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= }, 0, /* 60 iFeature */ }, -#endif +#endif /* (OUTPUT_VOLUME_CONTROL == 1) */ /* Output Terminal Descriptor (Audio) */ .Audio_Out_OutputTerminal = @@ -1119,7 +1141,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x0000, /* 9 bmControls */ 0, /* 11 iTerminal */ }, -#endif +#endif /* (NUM_USB_CHAN_OUT > 0) */ @@ -1274,7 +1296,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= }, 0, /* 60 iFeature */ }, -#endif +#endif /* (INPUT_VOLUME_CONTROL == 1) */ .Audio_In_OutputTerminal = { @@ -1295,7 +1317,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bmControls = 0x0000, .iTerminal = offsetof(StringDescTable_t, usbOutputTermStr_Audio2)/sizeof(char *) }, -#endif +#endif /* (NUM_USB_CHAN_IN > 0) */ #if defined(MIXER) && (MAX_MIX_COUNT > 0) /* Extension Unit Descriptor (4.7.2.12) */ @@ -1389,7 +1411,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x00, /* bmControls */ 0 /* Mixer unit string descriptor index */ }, -#endif +#endif /* defined(MIXER) && (MAX_MIX_COUNT > 0) */ #if (SPDIF_RX) || (ADAT_RX) /* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */ @@ -1473,9 +1495,13 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_OUT_AUDIO, #ifdef XUA_ADAPTIVE - .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, /* (bitmap) */ + .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, #else - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* (bitmap) */ + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ + #else + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ + #endif #endif .wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE, .bInterval = 1, @@ -1555,9 +1581,13 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_OUT_AUDIO, #ifdef XUA_ADAPTIVE - .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, /* (bitmap) */ + .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, #else - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* (bitmap) */ + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ + #else + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ + #endif #endif .wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_2_MAXPACKETSIZE, .bInterval = 1, @@ -1586,7 +1616,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 4, /* 6 bInterval. Only values <= 1 frame (4) supported by MS */ }, #endif -#endif +#endif /* OUTPUT_FORMAT_COUNT > 1 */ #if (OUTPUT_FORMAT_COUNT > 2) /* Standard AS Interface Descriptor (4.9.1) (Alt) */ .Audio_Out_StreamInterface_Alt3 = @@ -1639,10 +1669,15 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_OUT_AUDIO, #ifdef XUA_ADAPTIVE - .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, /* (bitmap) */ + .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, #else - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* (bitmap) */ -#endif .wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE, + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ + #else + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ + #endif +#endif + .wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE, .bInterval = 1, }, @@ -1734,11 +1769,11 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = 0x07, .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_IN_AUDIO, -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ -#else - #ifdef XUA_ADAPTIVE +#ifdef XUA_ADAPTIVE .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#else + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ #else .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ #endif @@ -1806,11 +1841,11 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = 0x07, .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_IN_AUDIO, -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ -#else - #ifdef XUA_ADAPTIVE +#ifdef XUA_ADAPTIVE .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#else + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ #else .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ #endif @@ -1830,7 +1865,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLockDelayUnits = 0x02, .wLockDelay = 0x0008, }, -#endif +#endif /* (INPUT_FORMAT_COUNT > 1) */ #if (INPUT_FORMAT_COUNT > 2) /* Alternative 3 */ /* Standard AS Interface Descriptor (4.9.1) (Alt) */ @@ -1879,11 +1914,11 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = 0x07, .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_IN_AUDIO, -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ -#else - #ifdef XUA_ADAPTIVE +#ifdef XUA_ADAPTIVE .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#else + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ #else .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ #endif @@ -1903,9 +1938,9 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLockDelayUnits = 0x02, .wLockDelay = 0x0008, }, -#endif - +#endif /* (INPUT_FORMAT_COUNT > 2) */ #endif /* #if(NUM_USB_CHAN_IN > 0) */ + #ifdef MIDI /* MIDI Descriptors */ /* Table B-3: MIDI Adapter Standard AC Interface Descriptor */ @@ -2024,7 +2059,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x01, /* 3 bNumEmbMIDIJack : Number of embedded MIDI OUT Jacks. (field size 1 bytes) */ 0x03, /* 4 BaAssocJackID(1) : ID of the Embedded MIDI OUT Jack. (field size 1 bytes) */ }, -#endif +#endif // MIDI #if (XUA_DFU_EN == 1) /* Standard DFU class Interface descriptor */ @@ -2052,14 +2087,14 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x09, /* 0 Size */ 0x21, /* 1 bDescriptorType : DFU FUNCTIONAL */ 0x07, /* 2 bmAttributes */ - 0xFA, /* 3 wDetachTimeOut */ - 0x00, /* 4 wDetachTimeOut */ + DFU_DETACH_TIME_OUT & 0xFF, /* 3 wDetachTimeOut */ + (DFU_DETACH_TIME_OUT >> 8) & 0xFF, /* 4 wDetachTimeOut */ 0x40, /* 5 wTransferSize */ 0x00, /* 6 wTransferSize */ 0x10, /* 7 bcdDFUVersion */ 0x01}, /* 7 bcdDFUVersion */ #endif -#endif +#endif /* (XUA_DFU_EN == 1) */ #ifdef IAP /* Interface descriptor */ @@ -2168,7 +2203,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= #endif #endif /* IAP */ -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) .HID_Interface = { 9, /* 0 bLength : Size of descriptor in Bytes */ @@ -2202,22 +2237,22 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= ENDPOINT_ADDRESS_IN_HID, /* 2 bEndpointAddress */ 3, /* 3 bmAttributes (INTERRUPT) */ 64, /* 4 wMaxPacketSize */ - 8, /* 6 bInterval */ + ENDPOINT_INT_INTERVAL_IN_HID, /* 6 bInterval */ } #endif }; -#endif +#endif /* (AUDIO_CLASS == 2) */ -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) unsigned char hidDescriptor[] = { - 9, /* 0 bLength : Size of descriptor in Bytes */ + 0x09, /* 0 bLength : Size of descriptor in Bytes */ 0x21, /* 1 bDescriptorType (HID) */ 0x10, /* 2 bcdHID */ 0x01, /* 3 bcdHID */ - 0, /* 4 bCountryCode */ - 1, /* 5 bNumDescriptors */ + 0x00, /* 4 bCountryCode */ + 0x01, /* 5 bNumDescriptors */ 0x22, /* 6 bDescriptorType[0] (Report) */ sizeof(hidReportDescriptor) & 0xff, /* 7 wDescriptorLength[0] */ sizeof(hidReportDescriptor) >> 8, /* 8 wDescriptorLength[0] */ @@ -2277,6 +2312,8 @@ unsigned char cfgDesc_Null[] = * To work around this we repeat MAX_FREQ_FS multiple times in some cases */ #define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) + const unsigned num_freqs_a1 = MAX(3, (0 #if(MIN_FREQ <= 8000) && (MAX_FREQ_FS >= 8000) + 1 @@ -2324,18 +2361,13 @@ const unsigned num_freqs_a1 = MAX(3, (0 #define DFU_INTERFACES_A1 0 #endif -/* Total number of bytes returned for the class-specific AudioControl interface descriptor. - * Includes the combined length of this descriptor header and all Unit and Terminal descriptors - * For us this is IT -> FU -> OT * 2 and a header */ -#define AC_TOTAL_LENGTH (AC_LENGTH + \ - (INPUT_INTERFACES_A1 * (12 + ( (8 + NUM_USB_CHAN_IN_FS) * INPUT_VOLUME_CONTROL) + 9)) +\ - (OUTPUT_INTERFACES_A1 * (12 + ( (8 + NUM_USB_CHAN_OUT_FS) * OUTPUT_VOLUME_CONTROL) + 9))) - -#define STREAMING_INTERFACES (INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1) - -//#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) -//#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (58 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES) -//#endif +#if( 0 < HID_CONTROLS ) +#define HID_INTERFACE_BYTES ( 9 + 9 + 7 ) +#define HID_INTERFACES_A1 1 +#else +#define HID_INTERFACE_BYTES 0 +#define HID_INTERFACES_A1 0 +#endif /* Total number of bytes returned for the class-specific AudioControl interface descriptor. * Includes the combined length of this descriptor header and all Unit and Terminal descriptors @@ -2348,12 +2380,27 @@ const unsigned num_freqs_a1 = MAX(3, (0 /* Number of interfaces for Audio 1.0 (+1 for control ) */ /* Note, this is different that INTERFACE_COUNT since we dont support items such as MIDI, iAP etc in UAC1 mode */ -#define NUM_INTERFACES_A1 (1+INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1+NUM_CONTROL_USB_INTERFACES+DFU_INTERFACES_A1) +#define NUM_INTERFACES_A1 (1 + INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1 + NUM_CONTROL_USB_INTERFACES + DFU_INTERFACES_A1 + HID_INTERFACES_A1) -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) -#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (58 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES) +#if ((NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP)) +#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (58 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES + HID_INTERFACE_BYTES) #else -#define CFG_TOTAL_LENGTH_A1 (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) +#define CFG_TOTAL_LENGTH_A1 (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 + HID_INTERFACE_BYTES) +#endif + +#ifdef XUA_USB_DESCRIPTOR_OVERWRITE_RATE_RES + #define AS_INTERFACE_BYTES (7) + #define INTERFACE_DESCRIPTOR_BYTES (9) + #define AS_FORMAT_TYPE_BYTES (17) + #define USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME (18 + AC_TOTAL_LENGTH + (OUTPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (2*INTERFACE_DESCRIPTOR_BYTES) + (AS_INTERFACE_BYTES) + 5) + #define USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_SUB_FRAME (18 + AC_TOTAL_LENGTH + (2*INTERFACE_DESCRIPTOR_BYTES) + (AS_INTERFACE_BYTES) + 5) + + #define USB_AS_IN_INTERFACE_DESCRIPTOR_OFFSET_FREQ (18 + AC_TOTAL_LENGTH + (OUTPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (2*INTERFACE_DESCRIPTOR_BYTES) + (AS_INTERFACE_BYTES) + 8) + #define USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_FREQ (18 + AC_TOTAL_LENGTH + (2*INTERFACE_DESCRIPTOR_BYTES) + (AS_INTERFACE_BYTES) + 8) + + #define USB_AS_IN_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE (18 + AC_TOTAL_LENGTH + (OUTPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (2*INTERFACE_DESCRIPTOR_BYTES) + (AS_INTERFACE_BYTES) + (AS_FORMAT_TYPE_BYTES) + 4) + #define USB_AS_OUT_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE (18 + AC_TOTAL_LENGTH + (2*INTERFACE_DESCRIPTOR_BYTES) + (AS_INTERFACE_BYTES) + (AS_FORMAT_TYPE_BYTES) + 4) + #endif #define CHARIFY_SR(x) (x & 0xff),((x & 0xff00)>> 8),((x & 0xff0000)>> 16) @@ -2459,7 +2506,7 @@ unsigned char cfgDesc_Audio1[] = #error NUM_USB_CHAN_OUT_FS > 8 currently supported #endif 0x00, /* String table index */ -#endif +#endif // OUTPUT_VOLUME_CONTROL == 1 /* CS_Interface Output Terminal Descriptor - Analogue out to speaker */ 0x09, @@ -2474,7 +2521,7 @@ unsigned char cfgDesc_Audio1[] = 0x01, /* sourceID - IT */ #endif 0x00, /* Unused */ -#endif +#endif // NUM_USB_CHAN_OUT > 0 #if (NUM_USB_CHAN_IN > 0) #define CHANNEL_CONFIG_IN (0xFF >> (8 - NUM_USB_CHAN_IN_FS)) @@ -2542,8 +2589,8 @@ unsigned char cfgDesc_Audio1[] = #error NUM_USB_CHAN_IN_FS > 8 currently supported #endif 0x00, /* String table index */ -#endif -#endif +#endif // INPUT_VOLUME_CONTROL == 1 +#endif // NUM_USB_CHAN_IN > 0 #if (NUM_USB_CHAN_OUT > 0) /* Standard AS Interface Descriptor (4.5.1) */ @@ -2588,7 +2635,6 @@ unsigned char cfgDesc_Audio1[] = NUM_USB_CHAN_OUT_FS, /* nrChannels */ FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES, /* subFrameSize */ FS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS, /* bitResolution */ - num_freqs_a1, /* SamFreqType - sample freq count */ /* Windows enum issue with <= two sample rates work around */ @@ -2645,16 +2691,20 @@ unsigned char cfgDesc_Audio1[] = /* Standard AS Isochronous Audio Data Endpoint Descriptor 4.6.1.1 */ 0x09, 0x05, /* ENDPOINT */ - 0x01, /* endpointAddress - D7, direction (0 OUT, 1 IN). D6..4 reserved (0). D3..0 endpoint no. */ + ENDPOINT_ADDRESS_OUT_AUDIO, /* endpointAddress - D7, direction (0 OUT, 1 IN). D6..4 reserved (0). D3..0 endpoint no. */ #ifdef XUA_ADAPTIVE ISO_EP_ATTRIBUTES_ADAPTIVE, #else - ISO_EP_ATTRIBUTES_ASYNCH, + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ + #else + ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ + #endif #endif (FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE&0xff), /* 4 wMaxPacketSize (Typically 294 bytes)*/ (FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE&0xff00)>>8, /* 5 wMaxPacketSize */ 0x01, /* bInterval */ - 0x00, /* bRefresh */ + 0x00, /* bRefresh */ #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) ENDPOINT_ADDRESS_IN_FEEDBACK, /* bSynchAdddress - address of EP used to communicate sync info */ #else /* Bi-directional in/out device */ @@ -2688,7 +2738,7 @@ unsigned char cfgDesc_Audio1[] = 0x04, /* bRefresh 2^x */ 0x0, /* bSynchAddress */ #endif -#endif +#endif // NUM_USB_CHAN_OUT > 0 #if (NUM_USB_CHAN_IN > 0) /* Standard Interface Descriptor - Audio streaming IN */ @@ -2786,11 +2836,11 @@ unsigned char cfgDesc_Audio1[] = 0x09, 0x05, /* ENDPOINT */ ENDPOINT_ADDRESS_IN_AUDIO, /* EndpointAddress */ -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ -#else - #ifdef XUA_ADAPTIVE +#ifdef XUA_ADAPTIVE ISO_EP_ATTRIBUTES_ADAPTIVE, +#else + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ #else ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ #endif @@ -2813,7 +2863,7 @@ unsigned char cfgDesc_Audio1[] = 0x00, /* Undefined */ 0x00, 0x00, /* Not used */ #endif // XUA_ADAPTIVE -#endif +#endif // NUM_USB_CHAN_IN > 0 #if (XUA_DFU_EN == 1) && (FORCE_UAC1_DFU == 1) @@ -2834,8 +2884,8 @@ unsigned char cfgDesc_Audio1[] = 0x09, /* 0 Size */ 0x21, /* 1 bDescriptorType : DFU FUNCTIONAL */ 0x07, /* 2 bmAttributes */ - 0xFA, /* 3 wDetachTimeOut */ - 0x00, /* 4 wDetachTimeOut */ + DFU_DETACH_TIME_OUT & 0xFF, /* 3 wDetachTimeOut */ + (DFU_DETACH_TIME_OUT >> 8) & 0xFF, /* 4 wDetachTimeOut */ 0x40, /* 5 wTransferSize */ 0x00, /* 6 wTransferSize */ 0x10, /* 7 bcdDFUVersion */ @@ -2855,7 +2905,40 @@ unsigned char cfgDesc_Audio1[] = offsetof(StringDescTable_t, ctrlStr)/sizeof(char *), /* 8 iInterface */ #endif +#if( 0 < HID_CONTROLS ) + /* HID interface descriptor */ + 0x09, /* 0 bLength : Size of descriptor in Bytes */ + 0x04, /* 1 bDescriptorType (Interface: 0x04)*/ + INTERFACE_NUMBER_HID, /* 2 bInterfaceNumber : Number of interface */ + 0x00, /* 3 bAlternateSetting : Value used alternate interfaces using SetInterface Request */ + 0x01, /* 4: bNumEndpoints : Number of endpoitns for this interface (excluding 0) */ + 0x03, /* 5: bInterfaceClass */ + 0x00, /* 6: bInterfaceSubClass - no boot device */ + 0x00, /* 7: bInterfaceProtocol*/ + 0x00, /* 8 iInterface */ + + /* HID descriptor */ + 0x09, /* 0 bLength : Size of descriptor in Bytes */ + 0x21, /* 1 bDescriptorType (HID) */ + 0x10, /* 2 bcdHID */ + 0x01, /* 3 bcdHID */ + 0x00, /* 4 bCountryCode */ + 0x01, /* 5 bNumDescriptors */ + 0x22, /* 6 bDescriptorType[0] (Report) */ + sizeof(hidReportDescriptor) & 0xff, /* 7 wDescriptorLength[0] */ + sizeof(hidReportDescriptor) >> 8, /* 8 wDescriptorLength[0] */ + + /* HID Endpoint descriptor (IN) */ + 0x07, /* 0 bLength */ + 0x05, /* 1 bDescriptorType */ + ENDPOINT_ADDRESS_IN_HID, /* 2 bEndpointAddress */ + 0x03, /* 3 bmAttributes (INTERRUPT) */ + 0x40, /* 4 wMaxPacketSize */ + 0x00, /* 5 wMaxPacketSize */ + ENDPOINT_INT_INTERVAL_IN_HID, /* 6 bInterval */ +#endif + }; +#endif // (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) #endif -#endif -#endif +#endif // _DEVICE_DESCRIPTORS_ diff --git a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.h b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.h index ab4c613d..60332730 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.h @@ -1,4 +1,5 @@ -// Copyright (c) 2014-2018, XMOS Ltd, All rights reserved +// Copyright 2014-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _AUDIOREQUESTS_H_ #define _AUDIOREQUESTS_H_ diff --git a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc index 2fdd434c..89169336 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc +++ b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 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 * @author Ross Owen, XMOS Semiconductor diff --git a/lib_xua/src/core/endpoint0/xua_ep0_wrapper.h b/lib_xua/src/core/endpoint0/xua_ep0_wrapper.h deleted file mode 100644 index 8015b95e..00000000 --- a/lib_xua/src/core/endpoint0/xua_ep0_wrapper.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _EP0_WRAPPER_ -#define _EP0_WRAPPER_ - -#include -#include -#include -#include "xua.h" - -typedef interface ep0_control_if{ - void set_output_interface(unsigned num); - void set_input_interface(unsigned num); - void set_host_active(unsigned num); -}ep0_control_if; - -extern "C"{ -void XUA_Endpoint0_lite_init(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, - chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_); -void XUA_Endpoint0_lite_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, - chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_, unsigned *input_interface_num, unsigned *output_interface_num); -} -#pragma select handler -void XUD_GetSetupData_Select(chanend c, XUD_ep e_out, unsigned &length, XUD_Result_t &result); - -[[combinable]] -void XUA_Endpoint0_select(chanend c_ep0_out, chanend c_ep0_in, client ep0_control_if i_ep0_ctl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_); - -#endif \ No newline at end of file diff --git a/lib_xua/src/core/endpoint0/xua_ep0_wrapper.xc b/lib_xua/src/core/endpoint0/xua_ep0_wrapper.xc deleted file mode 100644 index 092345a0..00000000 --- a/lib_xua/src/core/endpoint0/xua_ep0_wrapper.xc +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -#include "xua.h" - -#if XUA_USB_EN -#include "xua_ep0_wrapper.h" - -#define DEBUG_UNIT EP0_WRAPPER -#define DEBUG_PRINT_ENABLE_EP0_WRAPPER 0 -#include "debug_print.h" - -extern XUD_ep ep0_out; -extern XUD_ep ep0_in; - -[[combinable]] -void XUA_Endpoint0_select(chanend c_ep0_out, chanend c_ep0_in, client ep0_control_if i_ep0_ctl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_) -{ - - USB_SetupPacket_t sp; - XUA_Endpoint0_lite_init(c_ep0_out, c_ep0_in, null, null, null, null, dfuInterface VENDOR_REQUESTS_PARAMS_); - unsigned char sbuffer[120]; - XUD_SetReady_Out(ep0_out, sbuffer); - - unsigned input_interface_num = 0; - unsigned output_interface_num = 0; - - XUD_Result_t result = XUD_RES_ERR; - unsigned length = 0; - - while(1){ - select{ - case XUD_GetSetupData_Select(c_ep0_out, ep0_out, length, result): - if (result == XUD_RES_OKAY) - { - /* Parse data buffer end populate SetupPacket struct */ - USB_ParseSetupPacket(sbuffer, sp); - } - debug_printf("ep0, result: %d, length: %d\n", result, length); //-1 reset, 0 ok, 1 error - - XUA_Endpoint0_lite_loop(result, sp, c_ep0_out, c_ep0_in, null, null, null, null, dfuInterface - VENDOR_REQUESTS_PARAMS_, &input_interface_num, &output_interface_num); - i_ep0_ctl.set_output_interface(output_interface_num); - i_ep0_ctl.set_input_interface(input_interface_num); - - XUD_SetReady_Out(ep0_out, sbuffer); - break; - } - } -} -#endif diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index cb9d8af7..421793f2 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2012-2018, XMOS Ltd, All rights reserved +// Copyright 2012-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" /* Device specific defines */ #ifndef EXCLUDE_USB_AUDIO_MAIN @@ -259,7 +260,7 @@ XUD_EpType epTypeTableIn[ENDPOINT_COUNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENAB #ifdef MIDI XUD_EPTYPE_BUL, #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) XUD_EPTYPE_INT, #endif #ifdef IAP @@ -400,7 +401,7 @@ VENDOR_REQUESTS_PARAMS_DEC_ c_clk_int, #endif c_sof, c_aud_ctl, p_for_mclk_count -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , c_xud_in[ENDPOINT_NUMBER_IN_HID] #endif #ifdef CHAN_BUFF_CTRL diff --git a/lib_xua/src/core/mixer/fastmix.S b/lib_xua/src/core/mixer/fastmix.S index 4321b717..c8828a38 100644 --- a/lib_xua/src/core/mixer/fastmix.S +++ b/lib_xua/src/core/mixer/fastmix.S @@ -1,11 +1,12 @@ -// Copyright (c) 2018, XMOS Ltd, All rights reserved +// Copyright 2018-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. //#include "devicedefines.h" #define MAX_MIX_COUNT 8 #define MIX_INPUTS 18 -#if defined(__XS2A__) +#if defined(__XS2A__) || defined(__XS3A__) #define DOMIX_TOP(i) \ .cc_top doMix##i.function,doMix##i; \ diff --git a/lib_xua/src/core/mixer/mixer.h b/lib_xua/src/core/mixer/mixer.h index 05225b40..38e89ec3 100644 --- a/lib_xua/src/core/mixer/mixer.h +++ b/lib_xua/src/core/mixer/mixer.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __mixer_h__ #define __mixer_h__ diff --git a/lib_xua/src/core/mixer/mixer.xc b/lib_xua/src/core/mixer/mixer.xc index fe9dc766..7f8b6e05 100644 --- a/lib_xua/src/core/mixer/mixer.xc +++ b/lib_xua/src/core/mixer/mixer.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include diff --git a/lib_xua/src/core/mixer/repeat.h b/lib_xua/src/core/mixer/repeat.h index 99ec3bea..2246a940 100644 --- a/lib_xua/src/core/mixer/repeat.h +++ b/lib_xua/src/core/mixer/repeat.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef N #error "N must be defined before including repeat.h" #endif diff --git a/lib_xua/src/core/pdm_mics/mic_array_conf.h b/lib_xua/src/core/pdm_mics/mic_array_conf.h index 7f105514..d0164c28 100644 --- a/lib_xua/src/core/pdm_mics/mic_array_conf.h +++ b/lib_xua/src/core/pdm_mics/mic_array_conf.h @@ -1,15 +1,27 @@ -// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +// Copyright 2015-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef MIC_ARRAY_CONF_H_ #define MIC_ARRAY_CONF_H_ #include "xua_conf_full.h" +// The default definition of MIC_ARRAY_MAX_FRAME_SIZE_LOG2 must appear in this file +// because an assembler file #includes it. +// The assembler does not understand C language syntax, only C pre-processor syntax. #ifndef MIC_ARRAY_MAX_FRAME_SIZE_LOG2 -#define MIC_ARRAY_MAX_FRAME_SIZE_LOG2 0 +#define MIC_ARRAY_MAX_FRAME_SIZE_LOG2 (0) #endif #ifndef MIC_ARRAY_NUM_MICS #define MIC_ARRAY_NUM_MICS (XUA_NUM_PDM_MICS) #endif +// MIC_DUAL_FRAME_SIZE has no meaning if MIC_DUAL_ENABLED is false. +// Only define MIC_DUAL_FRAME_SIZE if MIC_DUAL_ENABLED is true. +#if defined(MIC_DUAL_ENABLED) && (MIC_DUAL_ENABLED != 0) +#ifndef MIC_DUAL_FRAME_SIZE +#define MIC_DUAL_FRAME_SIZE (XUA_MIC_FRAME_SIZE) +#endif +#endif + #endif /* MIC_ARRAY_CONF_H_ */ diff --git a/lib_xua/src/core/pdm_mics/pdm_mic.xc b/lib_xua/src/core/pdm_mics/pdm_mic.xc index dabfb794..a69115d7 100644 --- a/lib_xua/src/core/pdm_mics/pdm_mic.xc +++ b/lib_xua/src/core/pdm_mics/pdm_mic.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +// Copyright 2015-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" @@ -107,6 +108,7 @@ void XUA_PdmBuffer(streaming chanend c_ds_output[2], chanend c_audio) dc[0].mic_gain_compensation[2]=0; dc[0].mic_gain_compensation[3]=0; dc[0].channel_count = 4; + dc[0].async_interface_enabled = 0; dc[1].dcc = &dcc; dc[1].data = mic_decimator_fir_data[4]; dc[1].mic_gain_compensation[0]=0; @@ -114,6 +116,7 @@ void XUA_PdmBuffer(streaming chanend c_ds_output[2], chanend c_audio) dc[1].mic_gain_compensation[2]=0; dc[1].mic_gain_compensation[3]=0; dc[1].channel_count = 4; + dc[1].async_interface_enabled = 0; mic_array_decimator_configure(c_ds_output, decimatorCount, dc); diff --git a/lib_xua/src/core/pdm_mics/pdm_mic_user.c b/lib_xua/src/core/pdm_mics/pdm_mic_user.c index f7a35f78..6171cfca 100644 --- a/lib_xua/src/core/pdm_mics/pdm_mic_user.c +++ b/lib_xua/src/core/pdm_mics/pdm_mic_user.c @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" diff --git a/lib_xua/src/core/ports/audioports.c b/lib_xua/src/core/ports/audioports.c index f97538d3..64795ba0 100644 --- a/lib_xua/src/core/ports/audioports.c +++ b/lib_xua/src/core/ports/audioports.c @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #define __ASSEMBLER__ // Work around for bug #14118 diff --git a/lib_xua/src/core/ports/audioports.h b/lib_xua/src/core/ports/audioports.h index e207be09..5f01fd9c 100644 --- a/lib_xua/src/core/ports/audioports.h +++ b/lib_xua/src/core/ports/audioports.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _AUDIOPORTS_H_ #define _AUDIOPORTS_H_ diff --git a/lib_xua/src/core/ports/audioports.xc b/lib_xua/src/core/ports/audioports.xc index 80d2500a..330b7f96 100644 --- a/lib_xua/src/core/ports/audioports.xc +++ b/lib_xua/src/core/ports/audioports.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include #include @@ -61,7 +62,7 @@ unsigned int divide, unsigned curSamFreq) } #endif -#if defined(__XS2A__) +#if defined(__XS2A__) || defined(__XS3A__) unsafe { /* Clock bitclock clock block from master clock pin (divided) */ diff --git a/lib_xua/src/core/support/powersave/archU_powerSaving.h b/lib_xua/src/core/support/powersave/archU_powerSaving.h index 93d436cc..51f8281d 100644 --- a/lib_xua/src/core/support/powersave/archU_powerSaving.h +++ b/lib_xua/src/core/support/powersave/archU_powerSaving.h @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef ARCH_U_POWER_SAVING_ #define ARCH_U_POWER_SAVING_ diff --git a/lib_xua/src/core/support/powersave/archU_powerSaving.xc b/lib_xua/src/core/support/powersave/archU_powerSaving.xc index 8fea9efd..e6cd04c5 100644 --- a/lib_xua/src/core/support/powersave/archU_powerSaving.xc +++ b/lib_xua/src/core/support/powersave/archU_powerSaving.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #if (XUD_SERIES_SUPPORT==1) #include "archU_powerSaving.h" diff --git a/lib_xua/src/core/support/reboot.xc b/lib_xua/src/core/support/reboot.xc index fbc11f6c..d4c33d27 100644 --- a/lib_xua/src/core/support/reboot.xc +++ b/lib_xua/src/core/support/reboot.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2019, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include #include @@ -74,7 +75,7 @@ void device_reboot(void) } } -#ifdef __XS2A__ +#if defined(__XS2A__) || defined(__XS3A__) /* Reset all even tiles, starting from the remote ones */ for(int tileNum = tileArrayLength-2; tileNum>=0; tileNum-=2) #else @@ -86,7 +87,7 @@ void device_reboot(void) tileId = get_tile_id(tile[tileNum]); /* Do not reboot local tile (or tiles residing on the same node) yet */ -#ifdef __XS2A__ +#if defined(__XS2A__) || defined(__XS3A__) if((localTileNum | 1) != (tileNum | 1)) #else diff --git a/lib_xua/src/core/support/xc_ptr.h b/lib_xua/src/core/support/xc_ptr.h index d662eb8b..7168d196 100644 --- a/lib_xua/src/core/support/xc_ptr.h +++ b/lib_xua/src/core/support/xc_ptr.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __xc_ptr__ #define __xc_ptr__ diff --git a/lib_xua/src/core/support/xc_ptr.xc b/lib_xua/src/core/support/xc_ptr.xc index d337f4d5..7f75a53d 100644 --- a/lib_xua/src/core/support/xc_ptr.xc +++ b/lib_xua/src/core/support/xc_ptr.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2012-2018, XMOS Ltd, All rights reserved +// Copyright 2012-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xc_ptr.h" extern inline xc_ptr array_to_xc_ptr(const unsigned a[]); diff --git a/lib_xua/src/core/uac_hwresources.h b/lib_xua/src/core/uac_hwresources.h index 2e465aba..0142a2a9 100644 --- a/lib_xua/src/core/uac_hwresources.h +++ b/lib_xua/src/core/uac_hwresources.h @@ -1,4 +1,5 @@ -// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +// Copyright 2015-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _UAC_HWRESOURCES_H_ #define _UAC_HWRESOURCES_H_ diff --git a/lib_xua/src/core/user/audiostream/audiostream.c b/lib_xua/src/core/user/audiostream/audiostream.c index d07491df..24c7fe82 100644 --- a/lib_xua/src/core/user/audiostream/audiostream.c +++ b/lib_xua/src/core/user/audiostream/audiostream.c @@ -1,6 +1,10 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +/* Default implementations of AudioStreamStop() and AudioStreamStart() + * callbacks. + */ -/* Deafult implementations of AudioStreamStop() and AudioStreamStart(). Both can be over-ridden */ void UserAudioStreamStop() __attribute__ ((weak)); void UserAudioStreamStop() { @@ -12,3 +16,27 @@ void UserAudioStreamStart() { return; } + +void UserAudioInputStreamStop() __attribute__ ((weak)); +void UserAudioInputStreamStop() +{ + return; +} + +void UserAudioInputStreamStart() __attribute__ ((weak)); +void UserAudioInputStreamStart() +{ + return; +} + +void UserAudioOutputStreamStop() __attribute__ ((weak)); +void UserAudioOutputStreamStop() +{ + return; +} + +void UserAudioOutputStreamStart() __attribute__ ((weak)); +void UserAudioOutputStreamStart() +{ + return; +} diff --git a/lib_xua/src/core/user/audiostream/audiostream.h b/lib_xua/src/core/user/audiostream/audiostream.h index 60942914..1f27774e 100644 --- a/lib_xua/src/core/user/audiostream/audiostream.h +++ b/lib_xua/src/core/user/audiostream/audiostream.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _AUDIOSTREAM_H_ #define _AUDIOSTREAM_H_ @@ -14,5 +15,17 @@ void UserAudioStreamStart(void); /* Any actions required on stream stop e.g. DAC mute - run every steam stop */ void UserAudioStreamStop(void); +/* Any actions required on input stream start */ +void UserAudioInputStreamStart(void); + +/* Any actions required on input stream stop */ +void UserAudioInputStreamStop(void); + +/* Any actions required on output stream start */ +void UserAudioOutputStreamStart(void); + +/* Any actions required on output stream stop */ +void UserAudioOutputStreamStop(void); + #endif diff --git a/lib_xua/src/core/user/hid/user_hid.h b/lib_xua/src/core/user/hid/user_hid.h new file mode 100644 index 00000000..72d47abb --- /dev/null +++ b/lib_xua/src/core/user/hid/user_hid.h @@ -0,0 +1,86 @@ +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef __USER_HID_H__ +#define __USER_HID_H__ + +/** + * \brief HID event identifiers + * + * This enumeration defines a constant value for each HID event. + * It defines one value for each of the four GPI pins supported in the standard voice products. + * It defines a further 28 values for generic events. + */ +typedef enum hidEventId_t { + HID_EVENT_ID_GPI0 = 0, + HID_EVENT_ID_GPI1, + HID_EVENT_ID_GPI2, + HID_EVENT_ID_GPI3, + HID_EVENT_ID_EVT0, + HID_EVENT_ID_EVT1, + HID_EVENT_ID_EVT2, + HID_EVENT_ID_EVT3, + HID_EVENT_ID_EVT4, + HID_EVENT_ID_EVT5, + HID_EVENT_ID_EVT6, + HID_EVENT_ID_EVT7, + HID_EVENT_ID_EVT8, + HID_EVENT_ID_EVT9, + HID_EVENT_ID_EVT10, + HID_EVENT_ID_EVT11, + HID_EVENT_ID_EVT12, + HID_EVENT_ID_EVT13, + HID_EVENT_ID_EVT14, + HID_EVENT_ID_EVT15, + HID_EVENT_ID_EVT16, + HID_EVENT_ID_EVT17, + HID_EVENT_ID_EVT18, + HID_EVENT_ID_EVT19, + HID_EVENT_ID_EVT20, + HID_EVENT_ID_EVT21, + HID_EVENT_ID_EVT22, + HID_EVENT_ID_EVT23, + HID_EVENT_ID_EVT24, + HID_EVENT_ID_EVT25, + HID_EVENT_ID_EVT26, + HID_EVENT_ID_EVT27, + HID_EVENT_ID_INVALID = 0xffffffff, +} hidEventId_t; + +#define HID_DATA_BYTES 4 + +#if( 0 < HID_CONTROLS ) + +/** + * \brief Get the data for the next HID report + * + * \note This function returns the HID data as a list of unsigned char because the + * \c XUD_SetReady_In() accepts data for transmission to the USB Host using + * this type. + * + * \param{out} hidData The HID data + */ +void UserHIDGetData( unsigned char hidData[ HID_DATA_BYTES ]); + +/** + * \brief Initialize HID processing + */ +void UserHIDInit( void ); + +/** + * \brief Record that a HID event has occurred + * + * \param{in} hidEventId The identifier of an event which has occurred + * \param{in} hidEventData A list of data associated with the event + * \param{in} hidEventDataSize The length of the event data list + * + * \note At present, this function only takes a single element of event data, i.e. + * hidEventDataSize must equal 1. + * + * \note At present, this function treats the event data as a Boolean flag. + * Zero means False; all other values mean True. + */ +void UserHIDRecordEvent( const hidEventId_t hidEventId, const int * hidEventData, const unsigned hidEventDataSize ); + +#endif /* ( 0 < HID_CONTROLS ) */ +#endif /* __USER_HID_H__ */ diff --git a/lib_xua/src/core/user/hostactive/hostactive.c b/lib_xua/src/core/user/hostactive/hostactive.c index 6e0a91e6..e1cf546c 100644 --- a/lib_xua/src/core/user/hostactive/hostactive.c +++ b/lib_xua/src/core/user/hostactive/hostactive.c @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. void UserHostActive(int active) __attribute__ ((weak)); void UserHostActive(int active) diff --git a/lib_xua/src/core/user/hostactive/hostactive.h b/lib_xua/src/core/user/hostactive/hostactive.h index afa1c139..fa100d10 100644 --- a/lib_xua/src/core/user/hostactive/hostactive.h +++ b/lib_xua/src/core/user/hostactive/hostactive.h @@ -1,3 +1,4 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. void UserHostActive(int active); diff --git a/lib_xua/src/core/user/user_hid.h b/lib_xua/src/core/user/user_hid.h deleted file mode 100644 index b2530d0f..00000000 --- a/lib_xua/src/core/user/user_hid.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved - - -/* These defines relate to the HID report desc - do not mod */ -#define HID_CONTROL_PLAYPAUSE_SHIFT 0x00 -#define HID_CONTROL_NEXT_SHIFT 0x01 -#define HID_CONTROL_PREV_SHIFT 0x02 -#define HID_CONTROL_VOLUP_SHIFT 0x03 -#define HID_CONTROL_VOLDN_SHIFT 0x04 -#define HID_CONTROL_MUTE_SHIFT 0x05 - -void UserReadHIDButtons(unsigned char hidData[]); - diff --git a/lib_xua/src/core/warnings.xc b/lib_xua/src/core/warnings.xc index 11ebb139..16ffc49e 100644 --- a/lib_xua/src/core/warnings.xc +++ b/lib_xua/src/core/warnings.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /* Warnings relating to configuration defines located in this XC source file rather than the devicedefines.h header file in order to avoid multiple warnings being issued when the devicedefines.h header file is included in multiple files. diff --git a/lib_xua/src/core/xua_commands.h b/lib_xua/src/core/xua_commands.h index 54a76b9e..0e2bcb15 100644 --- a/lib_xua/src/core/xua_commands.h +++ b/lib_xua/src/core/xua_commands.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __XUA_INTERNAL_CMDS_H__ #define __XUA_INTERNAL_CMDS_H__ diff --git a/lib_xua/src/core/xuduser/xuduser.c b/lib_xua/src/core/xuduser/xuduser.c index 831acc1f..207906e7 100644 --- a/lib_xua/src/core/xuduser/xuduser.c +++ b/lib_xua/src/core/xuduser/xuduser.c @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #if XUA_USB_EN #include "xua.h" #include "hostactive.h" diff --git a/lib_xua/src/dfu/dfu.xc b/lib_xua/src/dfu/dfu.xc index 6e370b6c..1570c7eb 100644 --- a/lib_xua/src/dfu/dfu.xc +++ b/lib_xua/src/dfu/dfu.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" #if (XUA_DFU_EN== 1) #include diff --git a/lib_xua/src/dfu/dfu_interface.h b/lib_xua/src/dfu/dfu_interface.h index 4025b3f1..ed0ebff4 100644 --- a/lib_xua/src/dfu/dfu_interface.h +++ b/lib_xua/src/dfu/dfu_interface.h @@ -1,4 +1,5 @@ -// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved +// Copyright 2015-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __DFU_INTERFACE_H__ #define __DFU_INTERFACE_H__ diff --git a/lib_xua/src/dfu/dfu_types.h b/lib_xua/src/dfu/dfu_types.h index d4e809ee..63038c4b 100644 --- a/lib_xua/src/dfu/dfu_types.h +++ b/lib_xua/src/dfu/dfu_types.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. // Default Command requests (from Spec) #define DFU_DETACH 0 #define DFU_DNLOAD 1 diff --git a/lib_xua/src/dfu/flash_interface.c b/lib_xua/src/dfu/flash_interface.c index 69d66b97..078f4b54 100755 --- a/lib_xua/src/dfu/flash_interface.c +++ b/lib_xua/src/dfu/flash_interface.c @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include #include diff --git a/lib_xua/src/dfu/flash_interface.h b/lib_xua/src/dfu/flash_interface.h index 1c16522c..51d6f8fc 100755 --- a/lib_xua/src/dfu/flash_interface.h +++ b/lib_xua/src/dfu/flash_interface.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _flash_interface_h_ #define _flash_interface_h_ diff --git a/lib_xua/src/dfu/flashlib_user.c b/lib_xua/src/dfu/flashlib_user.c index d3ffa205..2ef7e47a 100644 --- a/lib_xua/src/dfu/flashlib_user.c +++ b/lib_xua/src/dfu/flashlib_user.c @@ -1,4 +1,5 @@ -// Copyright (c) 2012-2018, XMOS Ltd, All rights reserved +// Copyright 2012-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "xua.h" #if (XUA_DFU_EN == 1) #include "uac_hwresources.h" diff --git a/lib_xua/src/dfu/xua_dfu.h b/lib_xua/src/dfu/xua_dfu.h index 172f7f3b..00cd772d 100644 --- a/lib_xua/src/dfu/xua_dfu.h +++ b/lib_xua/src/dfu/xua_dfu.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _XUA_DFU_H_ #define _XUA_DFU_H_ 1 diff --git a/lib_xua/src/hid/hid.xc b/lib_xua/src/hid/hid.xc new file mode 100644 index 00000000..f3c741a1 --- /dev/null +++ b/lib_xua/src/hid/hid.xc @@ -0,0 +1,251 @@ +// Copyright 2019-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. +#include +#include +#include "descriptor_defs.h" +#include "hid.h" +#include "xud.h" +#include "xud_std_requests.h" +#include "xua_hid.h" + +#if( 0 < HID_CONTROLS ) +#define MS_IN_TICKS 100000U + +static unsigned s_hidChangePending = 0U; +static unsigned s_hidCurrentPeriod = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; +static unsigned s_hidIdleActive = 0U; +static unsigned s_hidIndefiniteDuration = 0U; +static unsigned s_hidNextReportTime = 0U; +static unsigned s_hidReportTime = 0U; + +unsafe { + volatile unsigned * unsafe s_hidChangePendingPtr = &s_hidChangePending; +} + +static unsigned HidCalcNewReportTime( const unsigned currentPeriod, const unsigned reportTime, const unsigned reportToSetIdleInterval, const unsigned newPeriod ); +static unsigned HidCalcReportToSetIdleInterval( const unsigned reportTime ); +static unsigned HidFindSetIdleActivationPoint( const unsigned currentPeriod, const unsigned timeWithinPeriod ); +static XUD_Result_t HidProcessSetIdleRequest( XUD_ep c_ep0_out, XUD_ep c_ep0_in, USB_SetupPacket_t &sp ); +static unsigned HidTimeDiff( const unsigned earlierTime, const unsigned laterTime ); + +void HidCalcNextReportTime( void ) +{ + s_hidNextReportTime = s_hidReportTime + s_hidCurrentPeriod; +} + +void HidCaptureReportTime( void ) +{ + timer tmr; + tmr :> s_hidReportTime; +} + +XUD_Result_t HidInterfaceClassRequests( + XUD_ep c_ep0_out, + XUD_ep c_ep0_in, + USB_SetupPacket_t &sp ) +{ + XUD_Result_t result = XUD_RES_ERR; + + switch ( sp.bRequest ) { + case HID_SET_IDLE: + result = HidProcessSetIdleRequest( c_ep0_out, c_ep0_in, sp ); + break; + + default: + break; + } + + return result; +} + +void HidClearChangePending( void ) +{ + unsafe { + *s_hidChangePendingPtr = 0U; + } +} + +unsigned HidIsChangePending( void ) +{ + return( s_hidChangePending != 0 ); +} + +unsigned HidIsSetIdleSilenced( void ) +{ + unsigned isSilenced = s_hidIdleActive; + + if( s_hidIdleActive ) { + unsigned currentTime; + // Use inline assembly to access the time without creating a side-effect. + // The mapper complains if the time comes from an XC timer because this function is called in the guard of a select case. + // Appearently the use of a timer creates a side-effect that prohibits the operation of the select functionality. + asm volatile( "gettime %0" : "=r" ( currentTime )); + isSilenced = ( s_hidIndefiniteDuration || ( timeafter( s_hidNextReportTime, currentTime ))); + } + + return isSilenced; +} + +void HidSetChangePending( void ) +{ + unsafe { + *s_hidChangePendingPtr = 1; + } +} + +/** + * \brief Calculate the timer value for sending the next HID Report. + * + * With regard to Section 7.2.4 Set_Idle Request of the USB Device Class Definition for Human + * Interface Devices (HID) Version 1.11, I've interpreted 'currently executing period' and + * 'current period' to mean the previously established Set Idle duration if one has been + * established or the polling interval from the HID Report Descriptor if a Set Idle duration + * has not been established. + * + * \param[in] currentPeriod -- The duration of the current period in timer ticks + * \param[in] reportTime -- The time at which the last HID Report was sent + * \param[in] reportToSetIdleInterval -- The time interval between receiving the Set Idle Request + * and sending the most recent HID Report + * \param[in] newPeriod -- The new period value in timer ticks + * + * \return The time at which the next HID Report should be sent + */ +static unsigned HidCalcNewReportTime( const unsigned currentPeriod, const unsigned reportTime, const unsigned reportToSetIdleInterval, const unsigned newPeriod ) +{ + unsigned nextReportTime = 0; + + if( HidFindSetIdleActivationPoint( currentPeriod, reportToSetIdleInterval )) { + /* Activate immediately after sending the next HID Report */ + nextReportTime = reportTime + currentPeriod; + } else { + /* Activate immediately after sending the most recent HID Report */ + nextReportTime = reportTime + newPeriod; + } + + return nextReportTime; +} + +/** + * \brief Calculate the time interval between the most recent HID Report and a subsequent Set Idle Request + * + * \warning For this function to produce an accurate interval measument, it must be called without delay + * upon receiving a Set Idle Request from the USB Host. + * + * \param[in] reportTime -- The time at which the last HID Report was sent + * + * \return The time interval between receiving the Set Idle Request and sending the most recent HID Report + */ +static unsigned HidCalcReportToSetIdleInterval( const unsigned reportTime ) +{ + timer tmr; + unsigned setIdleTime; + + tmr :> setIdleTime; + unsigned result = HidTimeDiff( reportTime, setIdleTime ); + return result; +} + +/** + * \brief Indicate if activation of the Set Idle Request happens at the previous or next HID Report + * + * Section 7.2.4 Set_Idle Request of the USB Device Class Definition for Human Interface + * Devices (HID) Version 1.11 makes two statements about the activation point for starting the + * duration of the request: + * - 'A new request will be executed as if it were issued immediately after the last report, if + * the new request is received at least 4 milliseconds before the end of the currently executing + * period.' + * - 'If the new request is received within 4 milliseconds of the end of the current period, then + * the new request will have no effect until after the report.' + * + * \param[in] currentPeriod -- The duration of the current period + * \param[in] timeWithinPeriod -- The current point in time relative to the current period + * + * \return A Boolean indicating where the activation of the Set Idle Request Duration occurs. + * \retval 1 -- Activate immediately after the next HID Report + * \retval 0 -- Activate immediately after the previous HID Report + */ +static unsigned HidFindSetIdleActivationPoint( const unsigned currentPeriod, const unsigned timeWithinPeriod ) +{ + unsigned result = (( currentPeriod - timeWithinPeriod ) < ( 4U * MS_IN_TICKS )) ? 1 : 0; + + return result; +} + +/** + * \brief Process a Set Idle request + * + * \param[in] c_ep0_out -- the channel that carries data from Endpoint 0 + * \param[in] c_ep0_in -- the channel that carries data for Endpoint 0 + * \param[in] sp -- a structure containing the Set Idle data + * + * \return An XUD status value + */ +static XUD_Result_t HidProcessSetIdleRequest( XUD_ep c_ep0_out, XUD_ep c_ep0_in, USB_SetupPacket_t &sp ) +{ + XUD_Result_t result = XUD_RES_ERR; + + /* + The Set Idle request wValue field contains two sub-fields: + - Duration in the MSB; and + - Report ID in the LSB. + + The Duration field specifies how long the USB Device responds with NAK provided the HID data hasn't changed. + Zero means indefinitely. + The value is in units of 4ms. + + The Report ID identifies the HID report that the USB Host wishes to silence. + + The Set Idle request xIndex field contains the interface number. + */ + uint16_t duration = ( sp.wValue & 0xFF00 ) >> 6; // Transform from units of 4ms into units of 1ms. + uint8_t reportId = sp.wValue & 0x00FF; + uint16_t interfaceNum = sp.wIndex; + + /* + As long as our HID Report Descriptor does not include a Report ID, any Report ID value other than zero + indicates an error by the USB Host (see xua_ep0_descriptors.h for the definition of the HID + Report Descriptor). + + Any Interface value other than INTERFACE_NUMBER_HID indicates an error by the USB Host. + */ + if(( 0U == reportId ) && ( INTERFACE_NUMBER_HID == interfaceNum )) { + s_hidIdleActive = (( 0U == duration ) || ( ENDPOINT_INT_INTERVAL_IN_HID < duration )); + + if( s_hidIdleActive ) { + unsigned reportToSetIdleInterval = HidCalcReportToSetIdleInterval( s_hidReportTime ); + s_hidNextReportTime = HidCalcNewReportTime( s_hidCurrentPeriod, s_hidReportTime, reportToSetIdleInterval, duration * MS_IN_TICKS ); + s_hidCurrentPeriod = duration * MS_IN_TICKS; + s_hidIndefiniteDuration = ( 0U == duration ); + } else { + s_hidCurrentPeriod = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; + s_hidIndefiniteDuration = 0U; + } + + result = XUD_DoSetRequestStatus( c_ep0_in ); + } + + return result; +} + +/** + * \brief Calculate the difference between two points in time + * + * This function calculates the difference between two two points in time. + * It always returns a positive value even if the timer used to obtain the two + * time measurements has wrapped around. + * + * \warning If time values have been obtained from a timer that has wrapped + * more than once in between the two measurements, this function returns an + * incorrect value. + * + * \param[in] earlierTime -- A value from a timer + * \param[in] laterTime -- A value from a timer taken after \a earlierTime + * + * \return The interval between the two points in time + */ +static unsigned HidTimeDiff( const unsigned earlierTime, const unsigned laterTime ) +{ + return ( earlierTime < laterTime ) ? laterTime - earlierTime : UINT_MAX - earlierTime + laterTime; +} + +#endif /* ( 0 < HID_CONTROLS ) */ diff --git a/lib_xua/src/hid/xua_hid.h b/lib_xua/src/hid/xua_hid.h new file mode 100644 index 00000000..1344b5a2 --- /dev/null +++ b/lib_xua/src/hid/xua_hid.h @@ -0,0 +1,78 @@ +// Copyright 2019-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef __XUA_HID_H__ +#define __XUA_HID_H__ + +#include +#include +#include "xud.h" +#include "xud_std_requests.h" + +/** + * \brief Calculate the next time to respond with a HID Report. + * + * If the USB Host has previously sent a valid HID Set_Idle request with + * a duration of zero or greater than the default reporting interval, + * the device sends HID Reports periodically or when the value of the + * payload has changed. + * + * This function calculates the time for sending the next periodic + * HID Report. + */ +void HidCalcNextReportTime( void ); + +/** + * \brief Capture the time of sending the current HID Report. + * + * If the USB Host has previously sent a valid HID Set_Idle request with + * a duration of zero or greater than the default reporting interval, + * the device sends HID Reports periodically or when the value of the + * payload has changed. + * + * This function captures the time when the HID Report was sent so that + * a subsequent call to HidCalNextReportTime() can calculate the time + * to send the next periodic HID Report. + */ +void HidCaptureReportTime( void ); + +XUD_Result_t HidInterfaceClassRequests( + XUD_ep c_ep0_out, + XUD_ep c_ep0_in, + REFERENCE_PARAM( USB_SetupPacket_t, sp )); + +/** + * \brief Register that previously changed HID Report data has reported + * to the USB Host. + */ +void HidClearChangePending( void ); + +/** + * \brief Indicate if a change to the HID Report data has been received. + */ +unsigned HidIsChangePending( void ); + +/** + * \brief Indicate whether to send a HID Report based on elapsed time. + * + * If the USB Host has previously sent a valid HID Set_Idle request with + * a duration of zero or greater than the default reporting interval, + * the device sends HID Reports periodically or when the value of the + * payload has changed. + * + * This function monitors the passage of time and reports to the caller + * whether or not the time to send the next periodic HID Report has + * elapsed. + * + * \return A Boolean value indicating whether or not to send the HID Report. + * \retval 1 -- Do not send the HID Report + * \retval 0 -- Send the HID Report + */ +unsigned HidIsSetIdleSilenced( void ); + +/** + * \brief Register that a change to the HID Report data has been received. + */ +void HidSetChangePending( void ); + +#endif // __XUA_HID_H__ diff --git a/lib_xua/src/midi/midi_descriptor.h b/lib_xua/src/midi/midi_descriptor.h index 277f3984..9f13c9b3 100644 --- a/lib_xua/src/midi/midi_descriptor.h +++ b/lib_xua/src/midi/midi_descriptor.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /* This file contains the MID device descriptor It is intended to be included in the main device descriptor definition */ diff --git a/lib_xua/src/midi/midiinparse.h b/lib_xua/src/midi/midiinparse.h index cb045a91..257820fd 100644 --- a/lib_xua/src/midi/midiinparse.h +++ b/lib_xua/src/midi/midiinparse.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef MIDIINPARSE_XH #define MIDIINPARSE_XH diff --git a/lib_xua/src/midi/midiinparse.xc b/lib_xua/src/midi/midiinparse.xc index 68b5999b..8265cdce 100644 --- a/lib_xua/src/midi/midiinparse.xc +++ b/lib_xua/src/midi/midiinparse.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /** * @file midiinparse.xc * @brief Generates USB MIDI events from MIDI events diff --git a/lib_xua/src/midi/midioutparse.h b/lib_xua/src/midi/midioutparse.h index 08734015..d1dc5fa6 100644 --- a/lib_xua/src/midi/midioutparse.h +++ b/lib_xua/src/midi/midioutparse.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef MIDIOUTPARSE_XH #define MIDIOUTPARSE_XH diff --git a/lib_xua/src/midi/midioutparse.xc b/lib_xua/src/midi/midioutparse.xc index 566df9bd..11bc8fbb 100644 --- a/lib_xua/src/midi/midioutparse.xc +++ b/lib_xua/src/midi/midioutparse.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /** * @file midioutparse.xc * @brief Parses USB-MIDI events into set of MIDI bytes diff --git a/lib_xua/src/midi/queue.h b/lib_xua/src/midi/queue.h index 27d54c72..af67e6e5 100644 --- a/lib_xua/src/midi/queue.h +++ b/lib_xua/src/midi/queue.h @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef QUEUE_H_ #define QUEUE_H_ diff --git a/lib_xua/src/midi/queue.xc b/lib_xua/src/midi/queue.xc index 125cbecd..6cab55f7 100644 --- a/lib_xua/src/midi/queue.xc +++ b/lib_xua/src/midi/queue.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2013-2018, XMOS Ltd, All rights reserved +// Copyright 2013-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include "queue.h" // Force external definitions of inline functions. diff --git a/lib_xua/src/midi/usb_midi.h b/lib_xua/src/midi/usb_midi.h index 8db4d663..d1a03adc 100644 --- a/lib_xua/src/midi/usb_midi.h +++ b/lib_xua/src/midi/usb_midi.h @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __usb_midi_h__ #define __usb_midi_h__ diff --git a/lib_xua/src/midi/usb_midi.xc b/lib_xua/src/midi/usb_midi.xc index 4971a9af..ecb5059d 100644 --- a/lib_xua/src/midi/usb_midi.xc +++ b/lib_xua/src/midi/usb_midi.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include #include diff --git a/lib_xua/src/midi/usb_midi_support.xc b/lib_xua/src/midi/usb_midi_support.xc index ffaaf109..1ee5d080 100644 --- a/lib_xua/src/midi/usb_midi_support.xc +++ b/lib_xua/src/midi/usb_midi_support.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2011-2018, XMOS Ltd, All rights reserved +// Copyright 2011-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #define __MIDI_IMPL #include "usb_midi.h" diff --git a/lib_xua/wscript b/lib_xua/wscript deleted file mode 100644 index 76f039b3..00000000 --- a/lib_xua/wscript +++ /dev/null @@ -1,109 +0,0 @@ -import os.path - - -def create_list_from_make_flag(bld, list_of_flags): - for i, flag in enumerate(list_of_flags): - if flag.startswith('$('): - for f in bld.env[flag.strip('$()')]: - list_of_flags.insert(i, f) - i += 1 - list_of_flags.remove(flag) - return list_of_flags - - -def create_list_of_strings(whitespace_seperated_list): - list_of_strings = whitespace_seperated_list.split(' ') - for item in list_of_strings: - item = "'{}'".format(item) - return list_of_strings - - -def read_module_build_info(bld): - with open(os.path.join(bld.path.abspath(), 'module_build_info')) as file: - module_build_info = {} - for line in file.readlines(): - line = line.strip() - if line and not line.startswith('#'): - key, value = line.split('=', 1) - module_build_info[key.strip(' +')] = value.strip() - - try: - module_build_info['OPTIONAL_HEADERS'] = ( - create_list_of_strings(module_build_info['OPTIONAL_HEADERS'])) - except KeyError: - pass - - try: - module_build_info['DEPENDENT_MODULES'] = ( - create_list_of_strings(module_build_info['DEPENDENT_MODULES'])) - except KeyError: - pass - - try: - module_build_info['MODULE_XCC_FLAGS'] = ( - create_list_from_make_flag(bld, - create_list_of_strings(module_build_info['MODULE_XCC_FLAGS']))) - except KeyError: - pass - - try: - module_build_info['MODULE_XCC_XC_FLAGS'] = ( - create_list_from_make_flag(bld, - create_list_of_strings(module_build_info['MODULE_XCC_XC_FLAGS']))) - except KeyError: - pass - - try: - module_build_info['MODULE_XCC_C_FLAGS'] = ( - create_list_from_make_flag(bld, - create_list_of_strings(module_build_info['MODULE_XCC_C_FLAGS']))) - except KeyError: - pass - - try: - module_build_info['MODULE_XCC_CPP_FLAGS'] = ( - create_list_from_make_flag(bld, - create_list_of_strings(module_build_info['MODULE_XCC_CPP_FLAGS']))) - except KeyError: - pass - - try: - module_build_info['MODULE_XCC_ASM_FLAGS'] = ( - create_list_from_make_flag(bld, - create_list_of_strings(module_build_info['MODULE_XCC_ASM_FLAGS']))) - except KeyError: - pass - - try: - module_build_info['INCLUDE_DIRS'] = ( - create_list_of_strings(module_build_info['INCLUDE_DIRS'])) - except KeyError: - pass - - return module_build_info - - -def use_module(bld): - module_build_info = read_module_build_info(bld) - source = bld.path.ant_glob(['src/**/*.xc', 'src/**/*.c', 'src/**/*.S'], - excl=['**/descriptors_2.rst']) - bld.env.MODULE_XCC_FLAGS = module_build_info['MODULE_XCC_FLAGS'] - - # The following file specific flags are not automatically kept in sync with the module_build_info file - # Core - bld.env['XCC_FLAGS_endpoint0.c'] = bld.env.XCC_FLAGS + ['-Os', '-mno-dual-issue'] - bld.env['XCC_FLAGS_xua_ep0_uacreqs.xc'] = bld.env.XCC_FLAGS + ['-Os', '-mno-dual-issue'] - bld.env['XCC_FLAGS_dbcalc.xc'] = bld.env.XCC_FLAGS + ['-Os', '-mno-dual-issue'] - bld.env['XCC_FLAGS_audioports.c'] = bld.env.XCC_FLAGS + ['-Os', '-mno-dual-issue'] - bld.env['XCC_FLAGS_audioports.xc'] = bld.env.XCC_FLAGS + ['-Os', '-mno-dual-issue'] - # DFU - bld.env['XCC_FLAGS_dfu.xc'] = bld.env.XCC_FLAGS + ['-Os', '-mno-dual-issue'] - bld.env['XCC_FLAGS_flash_interface.c'] = bld.env.XCC_FLAGS + ['-Os', '-mno-dual-issue'] - bld.env['XCC_FLAGS_flashlib_user.c'] = bld.env.XCC_FLAGS + ['-Os', '-mno-dual-issue'] - - bld.module( - source=source, - depends_on=module_build_info['DEPENDENT_MODULES'], - includes=module_build_info['INCLUDE_DIRS'], - optional_headers=module_build_info['OPTIONAL_HEADERS'], - version=module_build_info['VERSION']) \ No newline at end of file diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 00000000..98d3d6a5 --- /dev/null +++ b/python/setup.py @@ -0,0 +1,20 @@ +# Copyright 2020-2021 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. +import setuptools + +# Another repository might depend on python code defined in this one. The +# procedure to set up a suitable python environment for that repository may +# pip-install this one as editable using this setup.py file. To minimise the +# chance of version conflicts while ensuring a minimal degree of conformity, +# the 3rd-party modules listed here require the same major version and at +# least the same minor version as specified in the requirements.txt file. +# The same modules should appear in the requirements.txt file as given below. +setuptools.setup( + name='lib_xua', + packages=setuptools.find_packages(), + install_requires=[ + 'flake8~=3.8', + ], + dependency_links=[ + ], +) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..99e7dd7b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,34 @@ +# python_version 3.7.6 +# +# The parse_version_from_requirements() function in the installPipfile.groovy +# file of the Jenkins Shared Library uses the python_version comment to set +# the version of python used. + +# Distributed (released) dependencies +# +# The python modules listed below specify a known working combination required +# by the python code in this repository. The procedure used to set up a +# suitable python environment for it installs the version of each module in +# the list. Using a specific version ensures a controlled infrastructure for +# development, testing and release of this repository. +# +# Another repository might depend on python code defined in this one. The +# procedure to set up a suitable python environment for that repository may +# pip-install this one as editable using this repository's setup.py file. The +# same modules should appear in the setup.py list as given below. + +flake8==3.8.3 + +# Development dependencies +# +# Each link listed below specifies the path to a setup.py file which are +# installed in editable mode with '-e $PATH' (without the quotes). +# +# If python code in this repository depends on python code under development +# in another repository, then an entry for that other respository should +# appear in this list instead of the released dependencies list. +# +# If this repository uses the setup functionality (e.g., script entry points) +# of its own setup.py file, then this list must include an entry for that +# setup.py file, e.g., '-e .' or '-e ./python' (without the quotes). +-e ./python diff --git a/tests/app_test_i2s_loopback/LICENSE.txt b/tests/app_test_i2s_loopback/LICENSE.txt deleted file mode 100644 index c7b8c711..00000000 --- a/tests/app_test_i2s_loopback/LICENSE.txt +++ /dev/null @@ -1,135 +0,0 @@ -Software Release License Agreement - -Copyright (c) 2016-2018, XMOS, All rights reserved. - -BY ACCESSING, USING, INSTALLING OR DOWNLOADING THE XMOS SOFTWARE, YOU AGREE TO BE BOUND BY THE FOLLOWING TERMS. IF YOU DO NOT AGREE TO THESE, DO NOT ATTEMPT TO DOWNLOAD, ACCESS OR USE THE XMOS Software. - -Parties: - -(1) XMOS Limited, incorporated and registered in England and Wales with company number 5494985 whose registered office is 107 Cheapside, London, EC2V 6DN (XMOS). - -(2) An individual or legal entity exercising permissions granted by this License (Customer). - -If you are entering into this Agreement on behalf of another legal entity such as a company, partnership, university, college etc. (for example, as an employee, student or consultant), you warrant that you have authority to bind that entity. - -1. Definitions - -"License" means this Software License and any schedules or annexes to it. - -"License Fee" means the fee for the XMOS Software as detailed in any schedules or annexes to this Software License - -"Licensee Modifications" means all developments and modifications of the XMOS Software developed independently by the Customer. - -"XMOS Modifications" means all developments and modifications of the XMOS Software developed or co-developed by XMOS. - -"XMOS Hardware" means any XMOS hardware devices supplied by XMOS from time to time and/or the particular XMOS devices detailed in any schedules or annexes to this Software License. - -"XMOS Software" comprises the XMOS owned circuit designs, schematics, source code, object code, reference designs, (including related programmer comments and documentation, if any), error corrections, improvements, modifications (including XMOS Modifications) and updates. - -The headings in this License do not affect its interpretation. Save where the context otherwise requires, references to clauses and schedules are to clauses and schedules of this License. - -Unless the context otherwise requires: - -- references to XMOS and the Customer include their permitted successors and assigns; -- references to statutory provisions include those statutory provisions as amended or re-enacted; and -- references to any gender include all genders. - -Words in the singular include the plural and in the plural include the singular. - -2. License - -XMOS grants the Customer a non-exclusive license to use, develop, modify and distribute the XMOS Software with, or for the purpose of being used with, XMOS Hardware. - -Open Source Software (OSS) must be used and dealt with in accordance with any license terms under which OSS is distributed. - -3. Consideration - -In consideration of the mutual obligations contained in this License, the parties agree to its terms. - -4. Term - -Subject to clause 12 below, this License shall be perpetual. - -5. Restrictions on Use - -The Customer will adhere to all applicable import and export laws and regulations of the country in which it resides and of the United States and United Kingdom, without limitation. The Customer agrees that it is its responsibility to obtain copies of and to familiarise itself fully with these laws and regulations to avoid violation. - -6. Modifications - -The Customer will own all intellectual property rights in the Licensee Modifications but will undertake to provide XMOS with any fixes made to correct any bugs found in the XMOS Software on a non-exclusive, perpetual and royalty free license basis. - -XMOS will own all intellectual property rights in the XMOS Modifications. -The Customer may only use the Licensee Modifications and XMOS Modifications on, or in relation to, XMOS Hardware. - -7. Support - -Support of the XMOS Software may be provided by XMOS pursuant to a separate support agreement. - -8. Warranty and Disclaimer - -The XMOS Software is provided "AS IS" without a warranty of any kind. XMOS and its licensors' entire liability and Customer's exclusive remedy under this warranty to be determined in XMOS's sole and absolute discretion, will be either (a) the corrections of defects in media or replacement of the media, or (b) the refund of the license fee paid (if any). - -Whilst XMOS gives the Customer the ability to load their own software and applications onto XMOS devices, the security of such software and applications when on the XMOS devices is the Customer's own responsibility and any breach of security shall not be deemed a defect or failure of the hardware. XMOS shall have no liability whatsoever in relation to any costs, damages or other losses Customer may incur as a result of any breaches of security in relation to your software or applications. - -XMOS AND ITS LICENSORS DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY/ SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID UNDER APPLICABLE LAW. - -9. High Risk Activities - -The XMOS Software is not designed or intended for use in conjunction with on-line control equipment in hazardous environments requiring fail-safe performance, including without limitation the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, life support machines, or weapons systems (collectively "High Risk Activities") in which the failure of the XMOS Software could lead directly to death, personal injury, or severe physical or environmental damage. XMOS and its licensors specifically disclaim any express or implied warranties relating to use of the XMOS Software in connection with High Risk Activities. - -10. Liability - -TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, NEITHER XMOS NOR ITS LICENSORS SHALL BE LIABLE FOR ANY LOST REVENUE, BUSINESS, PROFIT, CONTRACTS OR DATA, ADMINISTRATIVE OR OVERHEAD EXPENSES, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THEORY OF LIABILITY ARISING OUT OF THIS LICENSE, EVEN IF XMOS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event shall XMOS's liability to the Customer whether in contract, tort (including negligence), or otherwise exceed the License Fee. - -Customer agrees to indemnify, hold harmless, and defend XMOS and its licensors from and against any claims or lawsuits, including attorneys' fees and any other liabilities, demands, proceedings, damages, losses, costs, expenses fines and charges which are made or brought against or incurred by XMOS as a result of your use or distribution of the Licensee Modifications or your use or distribution of XMOS Software, or any development of it, other than in accordance with the terms of this License. - -11. Ownership - -The copyrights and all other intellectual and industrial property rights for the protection of information with respect to the XMOS Software (including the methods and techniques on which they are based) are retained by XMOS and/or its licensors. Nothing in this Agreement serves to transfer such rights. Customer may not sell, mortgage, underlet, sublease, sublicense, lend or transfer possession of the XMOS Software in any way whatsoever to any third party who is not bound by this Agreement. - -12. Termination - -Either party may terminate this License at any time on written notice to the other if the other: - -- is in material or persistent breach of any of the terms of this License and either that breach is incapable of remedy, or the other party fails to remedy that breach within 30 days after receiving written notice requiring it to remedy that breach; or - -- is unable to pay its debts (within the meaning of section 123 of the Insolvency Act 1986), or becomes insolvent, or is subject to an order or a resolution for its liquidation, administration, winding-up or dissolution (otherwise than for the purposes of a solvent amalgamation or reconstruction), or has an administrative or other receiver, manager, trustee, liquidator, administrator or similar officer appointed over all or any substantial part of its assets, or enters into or proposes any composition or arrangement with its creditors generally, or is subject to any analogous event or proceeding in any applicable jurisdiction. - -Termination by either party in accordance with the rights contained in clause 12 shall be without prejudice to any other rights or remedies of that party accrued prior to termination. - -On termination for any reason: - -- all rights granted to the Customer under this License shall cease; -- the Customer shall cease all activities authorised by this License; -- the Customer shall immediately pay any sums due to XMOS under this License; and -- the Customer shall immediately destroy or return to the XMOS (at the XMOS's option) all copies of the XMOS Software then in its possession, custody or control and, in the case of destruction, certify to XMOS that it has done so. - -Clauses 5, 8, 9, 10 and 11 shall survive any effective termination of this Agreement. - -13. Third party rights - -No term of this License is intended to confer a benefit on, or to be enforceable by, any person who is not a party to this license. - -14. Confidentiality and publicity - -Each party shall, during the term of this License and thereafter, keep confidential all, and shall not use for its own purposes nor without the prior written consent of the other disclose to any third party any, information of a confidential nature (including, without limitation, trade secrets and information of commercial value) which may become known to such party from the other party and which relates to the other party, unless such information is public knowledge or already known to such party at the time of disclosure, or subsequently becomes public knowledge other than by breach of this license, or subsequently comes lawfully into the possession of such party from a third party. - -The terms of this license are confidential and may not be disclosed by the Customer without the prior written consent of XMOS. -The provisions of clause 14 shall remain in full force and effect notwithstanding termination of this license for any reason. - -15. Entire agreement - -This License and the documents annexed as appendices to this License or otherwise referred to herein contain the whole agreement between the parties relating to the subject matter hereof and supersede all prior agreements, arrangements and understandings between the parties relating to that subject matter. - -16. Assignment - -The Customer shall not assign this License or any of the rights granted under it without XMOS's prior written consent. - -17. Governing law and jurisdiction - -This License shall be governed by and construed in accordance with English law and each party hereby submits to the non-exclusive jurisdiction of the English courts. - -This License has been entered into on the date stated at the beginning of it. - -Schedule -XMOS lib_xua software diff --git a/tests/app_test_i2s_loopback/debug_conf.h b/tests/app_test_i2s_loopback/debug_conf.h index a7c079dd..aadb0014 100644 --- a/tests/app_test_i2s_loopback/debug_conf.h +++ b/tests/app_test_i2s_loopback/debug_conf.h @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __debug_conf_h__ #define __debug_conf_h__ diff --git a/tests/app_test_i2s_loopback/main.xc b/tests/app_test_i2s_loopback/main.xc index d6885126..9d012a49 100644 --- a/tests/app_test_i2s_loopback/main.xc +++ b/tests/app_test_i2s_loopback/main.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include #include diff --git a/tests/app_test_i2s_loopback/simulation.xc b/tests/app_test_i2s_loopback/simulation.xc index f963ac59..68541ca1 100644 --- a/tests/app_test_i2s_loopback/simulation.xc +++ b/tests/app_test_i2s_loopback/simulation.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifdef SIMULATION #include diff --git a/tests/app_test_i2s_loopback/usb_device.h b/tests/app_test_i2s_loopback/usb_device.h index 43c365e3..1f5aaa89 100644 --- a/tests/app_test_i2s_loopback/usb_device.h +++ b/tests/app_test_i2s_loopback/usb_device.h @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __usb_device_h__ #define __usb_device_h__ diff --git a/tests/app_test_i2s_loopback/usb_device.xc b/tests/app_test_i2s_loopback/usb_device.xc index ca74b48e..7a205735 100644 --- a/tests/app_test_i2s_loopback/usb_device.xc +++ b/tests/app_test_i2s_loopback/usb_device.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2018, XMOS Ltd, All rights reserved +// Copyright 2018-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #if 0 #include #include diff --git a/tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc b/tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc index ad2884cd..3a8cde53 100644 --- a/tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc +++ b/tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifdef HARDWARE #include diff --git a/tests/app_test_i2s_loopback/xk_216_mc/cs2100.h b/tests/app_test_i2s_loopback/xk_216_mc/cs2100.h index 447ec877..bc5a0cdd 100644 --- a/tests/app_test_i2s_loopback/xk_216_mc/cs2100.h +++ b/tests/app_test_i2s_loopback/xk_216_mc/cs2100.h @@ -1,4 +1,5 @@ -// Copyright (c) 2018, XMOS Ltd, All rights reserved +// Copyright 2018-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #define CS2100_I2C_DEVICE_ADDR (0x9c>>1) #define CS2100_DEVICE_CONTROL 0x02 diff --git a/tests/app_test_i2s_loopback/xk_216_mc/cs4384.h b/tests/app_test_i2s_loopback/xk_216_mc/cs4384.h index 98defbe3..6de83e81 100644 --- a/tests/app_test_i2s_loopback/xk_216_mc/cs4384.h +++ b/tests/app_test_i2s_loopback/xk_216_mc/cs4384.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef CS4384_H_ #define CS4384_H_ diff --git a/tests/app_test_i2s_loopback/xk_216_mc/cs5368.h b/tests/app_test_i2s_loopback/xk_216_mc/cs5368.h index 945ae536..d2de278d 100644 --- a/tests/app_test_i2s_loopback/xk_216_mc/cs5368.h +++ b/tests/app_test_i2s_loopback/xk_216_mc/cs5368.h @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved +// Copyright 2017-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _CS5368_H_ #define _CS5368_H_ diff --git a/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c b/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c index d6fc22d1..6d302c55 100644 --- a/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c +++ b/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifdef HARDWARE #include #include "gpio_access.h" diff --git a/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h b/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h index 1beac06f..93f66fee 100644 --- a/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h +++ b/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __gpio_access_h__ #define __gpio_access_h__ diff --git a/tests/app_test_i2s_loopback/xua_conf.h b/tests/app_test_i2s_loopback/xua_conf.h index 6dc9c95d..bec236b1 100644 --- a/tests/app_test_i2s_loopback/xua_conf.h +++ b/tests/app_test_i2s_loopback/xua_conf.h @@ -1,4 +1,5 @@ -// Copyright (c) 2016-2018, XMOS Ltd, All rights reserved +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __custom_defines_h__ #define __custom_defines_h__ @@ -22,5 +23,7 @@ #define AUDIO_CLASS_FALLBACK 0 #define BCD_DEVICE 0x1234 #define XUA_DFU_EN 0 +#define MIC_DUAL_ENABLED 1 //Use single thread, dual PDM mic +#define XUA_MIC_FRAME_SIZE 240 #endif // __custom_defines_h__ diff --git a/tests/runtests.py b/tests/runtests.py index 7d419e66..0fbc7f5d 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 -# Copyright (c) 2018, XMOS Ltd, All rights reserved +# Copyright 2018-2021 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. import xmostest import os.path diff --git a/tests/test_i2s_loopback.py b/tests/test_i2s_loopback.py index f56bdcf6..3e65e2f6 100644 --- a/tests/test_i2s_loopback.py +++ b/tests/test_i2s_loopback.py @@ -1,5 +1,6 @@ #!/usr/bin/env python -# Copyright (c) 2018, XMOS Ltd, All rights reserved +# Copyright 2018-2021 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. import xmostest def runtest_one_config(env, format, i2s_role, num_chans_in, num_chans_out, sample_rate):