firmware, mechanicals
This commit is contained in:
parent
50c0888a53
commit
d530889f4c
11
README.md
11
README.md
|
@ -0,0 +1,11 @@
|
|||
# The Ploopy Headphones
|
||||
|
||||
By some stroke of luck, you've made your way here. The Ploopy Headphones. Your life will never be the same.
|
||||
|
||||
This repository contains all of the design and production files necessary to make a set of Ploopy Headphones. We've also included some kick-ass documentation in the Wiki on how to get it made, assemble it, and program it.
|
||||
|
||||
What are you waiting for? Your new life awaits.
|
||||
|
||||
## Under what license is this released?
|
||||
|
||||
The firmware is released under GPLv3. The hardware is released under OHL CERN v2-S. Check the respective directories for full license text.
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -0,0 +1,3 @@
|
|||
## Borked your firmware?
|
||||
|
||||
All Ploopy Headphones pre-amp boards ship with "ploopy_headphones.uf2". If things aren't working the way you want them to, try reflashing the uf2 file included in this directory.
|
|
@ -0,0 +1,4 @@
|
|||
.vscode/
|
||||
inc/
|
||||
lib/
|
||||
build/
|
|
@ -0,0 +1,782 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2020.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2020 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaims all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common definitions and declarations for the library USB Audio 1.0 Class driver.
|
||||
*
|
||||
* Common definitions and declarations for the library USB Audio 1.0 Class driver.
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB module driver
|
||||
* dispatch header located in LUFA/Drivers/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USBClassAudio
|
||||
* \defgroup Group_USBClassAudioCommon Common Class Definitions
|
||||
*
|
||||
* \section Sec_USBClassAudioCommon_ModDescription Module Description
|
||||
* Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
|
||||
* Audio 1.0 Class.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _AUDIO_CLASS_COMMON_H_
|
||||
#define _AUDIO_CLASS_COMMON_H_
|
||||
|
||||
/* Includes: */
|
||||
#include "StdDescriptors.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Macros: */
|
||||
/** \name Audio Channel Masks */
|
||||
/**@{*/
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_LEFT_FRONT (1 << 0)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_RIGHT_FRONT (1 << 1)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_CENTER_FRONT (1 << 2)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_LOW_FREQ_ENHANCE (1 << 3)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_LEFT_SURROUND (1 << 4)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_RIGHT_SURROUND (1 << 5)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_LEFT_OF_CENTER (1 << 6)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_RIGHT_OF_CENTER (1 << 7)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_SURROUND (1 << 8)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_SIDE_LEFT (1 << 9)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_SIDE_RIGHT (1 << 10)
|
||||
|
||||
/** Supported channel mask for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_CHANNEL_TOP (1 << 11)
|
||||
/**@}*/
|
||||
|
||||
/** \name Audio Feature Masks */
|
||||
/**@{*/
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_MUTE (1 << 0)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_VOLUME (1 << 1)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_BASS (1 << 2)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_MID (1 << 3)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_TREBLE (1 << 4)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_GRAPHIC_EQUALIZER (1 << 5)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_AUTOMATIC_GAIN (1 << 6)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_DELAY (1 << 7)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_BASS_BOOST (1 << 8)
|
||||
|
||||
/** Supported feature mask for an Audio class feature unit descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_FEATURE_BASS_LOUDNESS (1 << 9)
|
||||
/**@}*/
|
||||
|
||||
/** \name Audio Terminal Types */
|
||||
/**@{*/
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_UNDEFINED 0x0100
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_STREAMING 0x0101
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_VENDOR 0x01FF
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_IN_UNDEFINED 0x0200
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_IN_MIC 0x0201
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_IN_DESKTOP_MIC 0x0202
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_IN_PERSONAL_MIC 0x0203
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_IN_OMNIDIR_MIC 0x0204
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_IN_MIC_ARRAY 0x0205
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_IN_PROCESSING_MIC 0x0206
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_IN_OUT_UNDEFINED 0x0300
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_OUT_SPEAKER 0x0301
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_OUT_HEADPHONES 0x0302
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_OUT_HEAD_MOUNTED 0x0303
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_OUT_DESKTOP 0x0304
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_OUT_ROOM 0x0305
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_OUT_COMMUNICATION 0x0306
|
||||
|
||||
/** Terminal type constant for an Audio class terminal descriptor. See the Audio class specification for more details. */
|
||||
#define AUDIO_TERMINAL_OUT_LOWFREQ 0x0307
|
||||
/**@}*/
|
||||
|
||||
/** Convenience macro to fill a 24-bit \ref USB_Audio_SampleFreq_t structure with the given sample rate as a 24-bit number.
|
||||
*
|
||||
* \param[in] freq Required audio sampling frequency in HZ
|
||||
*/
|
||||
#define AUDIO_SAMPLE_FREQ(freq) {.Byte1 = ((uint32_t)freq & 0xFF), .Byte2 = (((uint32_t)freq >> 8) & 0xFF), .Byte3 = (((uint32_t)freq >> 16) & 0xFF)}
|
||||
|
||||
/** Mask for the attributes parameter of an Audio class-specific Endpoint descriptor, indicating that the endpoint
|
||||
* accepts only filled endpoint packets of audio samples.
|
||||
*/
|
||||
#define AUDIO_EP_FULL_PACKETS_ONLY (1 << 7)
|
||||
|
||||
/** Mask for the attributes parameter of an Audio class-specific Endpoint descriptor, indicating that the endpoint
|
||||
* will accept partially filled endpoint packets of audio samples.
|
||||
*/
|
||||
#define AUDIO_EP_ACCEPTS_SMALL_PACKETS (0 << 7)
|
||||
|
||||
/** Mask for the attributes parameter of an Audio class-specific Endpoint descriptor, indicating that the endpoint
|
||||
* allows for sampling frequency adjustments to be made via control requests directed at the endpoint.
|
||||
*/
|
||||
#define AUDIO_EP_SAMPLE_FREQ_CONTROL (1 << 0)
|
||||
|
||||
/** Mask for the attributes parameter of an Audio class-specific Endpoint descriptor, indicating that the endpoint
|
||||
* allows for pitch adjustments to be made via control requests directed at the endpoint.
|
||||
*/
|
||||
#define AUDIO_EP_PITCH_CONTROL (1 << 1)
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the Audio
|
||||
* device class.
|
||||
*/
|
||||
enum Audio_Descriptor_ClassSubclassProtocol_t
|
||||
{
|
||||
AUDIO_CSCP_AudioClass = 0x01, /**< Descriptor Class value indicating that the device or
|
||||
* interface belongs to the USB Audio 1.0 class.
|
||||
*/
|
||||
AUDIO_CSCP_ControlSubclass = 0x01, /**< Descriptor Subclass value indicating that the device or
|
||||
* interface belongs to the Audio Control subclass.
|
||||
*/
|
||||
AUDIO_CSCP_ControlProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or
|
||||
* interface belongs to the Audio Control protocol.
|
||||
*/
|
||||
AUDIO_CSCP_AudioStreamingSubclass = 0x02, /**< Descriptor Subclass value indicating that the device or
|
||||
* interface belongs to the MIDI Streaming subclass.
|
||||
*/
|
||||
AUDIO_CSCP_MIDIStreamingSubclass = 0x03, /**< Descriptor Subclass value indicating that the device or
|
||||
* interface belongs to the Audio streaming subclass.
|
||||
*/
|
||||
AUDIO_CSCP_StreamingProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or
|
||||
* interface belongs to the Streaming Audio protocol.
|
||||
*/
|
||||
};
|
||||
|
||||
/** Enum for the Audio class specific descriptor types. */
|
||||
enum AUDIO_DescriptorTypes_t
|
||||
{
|
||||
AUDIO_DTYPE_CSInterface = 0x24, /**< Audio class specific Interface functional descriptor. */
|
||||
AUDIO_DTYPE_CSEndpoint = 0x25, /**< Audio class specific Endpoint functional descriptor. */
|
||||
};
|
||||
|
||||
/** Audio class specific interface description subtypes, for the Audio Control interface. */
|
||||
enum Audio_CSInterface_AC_SubTypes_t
|
||||
{
|
||||
AUDIO_DSUBTYPE_CSInterface_Header = 0x01, /**< Audio class specific control interface header. */
|
||||
AUDIO_DSUBTYPE_CSInterface_InputTerminal = 0x02, /**< Audio class specific control interface Input Terminal. */
|
||||
AUDIO_DSUBTYPE_CSInterface_OutputTerminal = 0x03, /**< Audio class specific control interface Output Terminal. */
|
||||
AUDIO_DSUBTYPE_CSInterface_Mixer = 0x04, /**< Audio class specific control interface Mixer Unit. */
|
||||
AUDIO_DSUBTYPE_CSInterface_Selector = 0x05, /**< Audio class specific control interface Selector Unit. */
|
||||
AUDIO_DSUBTYPE_CSInterface_Feature = 0x06, /**< Audio class specific control interface Feature Unit. */
|
||||
AUDIO_DSUBTYPE_CSInterface_Processing = 0x07, /**< Audio class specific control interface Processing Unit. */
|
||||
AUDIO_DSUBTYPE_CSInterface_Extension = 0x08, /**< Audio class specific control interface Extension Unit. */
|
||||
};
|
||||
|
||||
/** Audio class specific interface description subtypes, for the Audio Streaming interface. */
|
||||
enum Audio_CSInterface_AS_SubTypes_t
|
||||
{
|
||||
AUDIO_DSUBTYPE_CSInterface_General = 0x01, /**< Audio class specific streaming interface general descriptor. */
|
||||
AUDIO_DSUBTYPE_CSInterface_FormatType = 0x02, /**< Audio class specific streaming interface format type descriptor. */
|
||||
AUDIO_DSUBTYPE_CSInterface_FormatSpecific = 0x03, /**< Audio class specific streaming interface format information descriptor. */
|
||||
};
|
||||
|
||||
/** Audio class specific endpoint description subtypes, for the Audio Streaming interface. */
|
||||
enum Audio_CSEndpoint_SubTypes_t
|
||||
{
|
||||
AUDIO_DSUBTYPE_CSEndpoint_General = 0x01, /**< Audio class specific endpoint general descriptor. */
|
||||
};
|
||||
|
||||
/** Enum for the Audio class specific control requests that can be issued by the USB bus host. */
|
||||
enum Audio_ClassRequests_t
|
||||
{
|
||||
AUDIO_REQ_SetCurrent = 0x01, /**< Audio class-specific request to set the current value of a parameter within the device. */
|
||||
AUDIO_REQ_SetMinimum = 0x02, /**< Audio class-specific request to set the minimum value of a parameter within the device. */
|
||||
AUDIO_REQ_SetMaximum = 0x03, /**< Audio class-specific request to set the maximum value of a parameter within the device. */
|
||||
AUDIO_REQ_SetResolution = 0x04, /**< Audio class-specific request to set the resolution value of a parameter within the device. */
|
||||
AUDIO_REQ_SetMemory = 0x05, /**< Audio class-specific request to set the memory value of a parameter within the device. */
|
||||
AUDIO_REQ_GetCurrent = 0x81, /**< Audio class-specific request to get the current value of a parameter within the device. */
|
||||
AUDIO_REQ_GetMinimum = 0x82, /**< Audio class-specific request to get the minimum value of a parameter within the device. */
|
||||
AUDIO_REQ_GetMaximum = 0x83, /**< Audio class-specific request to get the maximum value of a parameter within the device. */
|
||||
AUDIO_REQ_GetResolution = 0x84, /**< Audio class-specific request to get the resolution value of a parameter within the device. */
|
||||
AUDIO_REQ_GetMemory = 0x85, /**< Audio class-specific request to get the memory value of a parameter within the device. */
|
||||
AUDIO_REQ_GetStatus = 0xFF, /**< Audio class-specific request to get the device status. */
|
||||
};
|
||||
|
||||
/** Enum for Audio class specific Endpoint control modifiers which can be set and retrieved by a USB host, if the corresponding
|
||||
* endpoint control is indicated to be supported in the Endpoint's Audio-class specific endpoint descriptor.
|
||||
*/
|
||||
enum Audio_EndpointControls_t
|
||||
{
|
||||
AUDIO_EPCONTROL_SamplingFreq = 0x01, /**< Sampling frequency adjustment of the endpoint. */
|
||||
AUDIO_EPCONTROL_Pitch = 0x02, /**< Pitch adjustment of the endpoint. */
|
||||
};
|
||||
|
||||
/* Type Defines: */
|
||||
/** \brief Audio class-specific Input Terminal Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific input terminal descriptor. This indicates to the host that the device
|
||||
* contains an input audio source, either from a physical terminal on the device, or a logical terminal (for example,
|
||||
* a USB endpoint). See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_StdDescriptor_InputTerminal_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
|
||||
uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* must be \ref AUDIO_DSUBTYPE_CSInterface_InputTerminal.
|
||||
*/
|
||||
|
||||
uint8_t TerminalID; /**< ID value of this terminal unit - must be a unique value within the device. */
|
||||
uint16_t TerminalType; /**< Type of terminal, a \c TERMINAL_* mask. */
|
||||
uint8_t AssociatedOutputTerminal; /**< ID of associated output terminal, for physically grouped terminals
|
||||
* such as the speaker and microphone of a phone handset.
|
||||
*/
|
||||
uint8_t TotalChannels; /**< Total number of separate audio channels within this interface (right, left, etc.) */
|
||||
uint16_t ChannelConfig; /**< \c CHANNEL_* masks indicating what channel layout is supported by this terminal. */
|
||||
|
||||
uint8_t ChannelStrIndex; /**< Index of a string descriptor describing this channel within the device. */
|
||||
uint8_t TerminalStrIndex; /**< Index of a string descriptor describing this descriptor within the device. */
|
||||
} ATTR_PACKED USB_Audio_Descriptor_InputTerminal_t;
|
||||
|
||||
/** \brief Audio class-specific Input Terminal Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific input terminal descriptor. This indicates to the host that the device
|
||||
* contains an input audio source, either from a physical terminal on the device, or a logical terminal (for example,
|
||||
* a USB endpoint). See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_Descriptor_InputTerminal_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
|
||||
uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* must be \ref AUDIO_DSUBTYPE_CSInterface_InputTerminal.
|
||||
*/
|
||||
uint8_t bTerminalID; /**< ID value of this terminal unit - must be a unique value within the device. */
|
||||
uint16_t wTerminalType; /**< Type of terminal, a \c TERMINAL_* mask. */
|
||||
uint8_t bAssocTerminal; /**< ID of associated output terminal, for physically grouped terminals
|
||||
* such as the speaker and microphone of a phone handset.
|
||||
*/
|
||||
uint8_t bNrChannels; /**< Total number of separate audio channels within this interface (right, left, etc.) */
|
||||
uint16_t wChannelConfig; /**< \c CHANNEL_* masks indicating what channel layout is supported by this terminal. */
|
||||
|
||||
uint8_t iChannelNames; /**< Index of a string descriptor describing this channel within the device. */
|
||||
uint8_t iTerminal; /**< Index of a string descriptor describing this descriptor within the device. */
|
||||
} ATTR_PACKED USB_Audio_StdDescriptor_InputTerminal_t;
|
||||
|
||||
/** \brief Audio class-specific Output Terminal Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific output terminal descriptor. This indicates to the host that the device
|
||||
* contains an output audio sink, either to a physical terminal on the device, or a logical terminal (for example,
|
||||
* a USB endpoint). See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_StdDescriptor_OutputTerminal_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
|
||||
uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* must be \ref AUDIO_DSUBTYPE_CSInterface_OutputTerminal.
|
||||
*/
|
||||
|
||||
uint8_t TerminalID; /**< ID value of this terminal unit - must be a unique value within the device. */
|
||||
uint16_t TerminalType; /**< Type of terminal, a \c TERMINAL_* mask. */
|
||||
uint8_t AssociatedInputTerminal; /**< ID of associated input terminal, for physically grouped terminals
|
||||
* such as the speaker and microphone of a phone handset.
|
||||
*/
|
||||
uint8_t SourceID; /**< ID value of the unit this terminal's audio is sourced from. */
|
||||
|
||||
uint8_t TerminalStrIndex; /**< Index of a string descriptor describing this descriptor within the device. */
|
||||
} ATTR_PACKED USB_Audio_Descriptor_OutputTerminal_t;
|
||||
|
||||
/** \brief Audio class-specific Output Terminal Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific output terminal descriptor. This indicates to the host that the device
|
||||
* contains an output audio sink, either to a physical terminal on the device, or a logical terminal (for example,
|
||||
* a USB endpoint). See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_Descriptor_OutputTerminal_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* must be \ref AUDIO_DSUBTYPE_CSInterface_OutputTerminal.
|
||||
*/
|
||||
|
||||
uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* a value from the \ref Audio_CSInterface_AC_SubTypes_t enum.
|
||||
*/
|
||||
uint8_t bTerminalID; /**< ID value of this terminal unit - must be a unique value within the device. */
|
||||
uint16_t wTerminalType; /**< Type of terminal, a \c TERMINAL_* mask. */
|
||||
uint8_t bAssocTerminal; /**< ID of associated input terminal, for physically grouped terminals
|
||||
* such as the speaker and microphone of a phone handset.
|
||||
*/
|
||||
uint8_t bSourceID; /**< ID value of the unit this terminal's audio is sourced from. */
|
||||
|
||||
uint8_t iTerminal; /**< Index of a string descriptor describing this descriptor within the device. */
|
||||
} ATTR_PACKED USB_Audio_StdDescriptor_OutputTerminal_t;
|
||||
|
||||
/** \brief Audio class-specific Interface Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific interface descriptor. This follows a regular interface descriptor to
|
||||
* supply extra information about the audio device's layout to the host. See the USB Audio specification for more
|
||||
* details.
|
||||
*
|
||||
* \see \ref USB_Audio_StdDescriptor_Interface_AC_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
|
||||
uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* a value from the \ref Audio_CSInterface_AS_SubTypes_t enum.
|
||||
*/
|
||||
|
||||
uint16_t ACSpecification; /**< Binary Coded Decimal value, indicating the supported Audio Class specification version.
|
||||
*
|
||||
* \see \ref VERSION_BCD() utility macro.
|
||||
*/
|
||||
uint16_t TotalLength; /**< Total length of the Audio class-specific descriptors, including this descriptor. */
|
||||
|
||||
uint8_t InCollection; /**< Total number of Audio Streaming interfaces linked to this Audio Control interface (must be 1). */
|
||||
uint8_t InterfaceNumber; /**< Interface number of the associated Audio Streaming interface. */
|
||||
} ATTR_PACKED USB_Audio_Descriptor_Interface_AC_t;
|
||||
|
||||
/** \brief Audio class-specific Interface Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific interface descriptor. This follows a regular interface descriptor to
|
||||
* supply extra information about the audio device's layout to the host. See the USB Audio specification for more
|
||||
* details.
|
||||
*
|
||||
* \see \ref USB_Audio_Descriptor_Interface_AC_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
|
||||
uint8_t bDescriptorSubtype;/**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* a value from the \ref Audio_CSInterface_AS_SubTypes_t enum.
|
||||
*/
|
||||
|
||||
uint16_t bcdADC; /**< Binary coded decimal value, indicating the supported Audio Class specification version.
|
||||
*
|
||||
* \see \ref VERSION_BCD() utility macro.
|
||||
*/
|
||||
uint16_t wTotalLength; /**< Total length of the Audio class-specific descriptors, including this descriptor. */
|
||||
|
||||
uint8_t bInCollection; /**< Total number of Audio Streaming interfaces linked to this Audio Control interface (must be 1). */
|
||||
uint8_t bInterfaceNumbers; /**< Interface number of the associated Audio Streaming interface. */
|
||||
} ATTR_PACKED USB_Audio_StdDescriptor_Interface_AC_t;
|
||||
|
||||
/** \brief Audio class-specific Feature Unit Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific Feature Unit descriptor. This indicates to the host what features
|
||||
* are present in the device's audio stream for basic control, such as per-channel volume. See the USB Audio
|
||||
* specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_StdDescriptor_FeatureUnit_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
|
||||
uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* must be \ref AUDIO_DSUBTYPE_CSInterface_Feature.
|
||||
*/
|
||||
|
||||
uint8_t UnitID; /**< ID value of this feature unit - must be a unique value within the device. */
|
||||
uint8_t SourceID; /**< Source ID value of the audio source input into this feature unit. */
|
||||
|
||||
uint8_t ControlSize; /**< Size of each element in the \c ChannelControls array. */
|
||||
uint8_t ChannelControls[3]; /**< Feature masks for the control channel, and each separate audio channel. */
|
||||
|
||||
uint8_t FeatureUnitStrIndex; /**< Index of a string descriptor describing this descriptor within the device. */
|
||||
} ATTR_PACKED USB_Audio_Descriptor_FeatureUnit_t;
|
||||
|
||||
/** \brief Audio class-specific Feature Unit Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific Feature Unit descriptor. This indicates to the host what features
|
||||
* are present in the device's audio stream for basic control, such as per-channel volume. See the USB Audio
|
||||
* specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_Descriptor_FeatureUnit_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
|
||||
uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* must be \ref AUDIO_DSUBTYPE_CSInterface_Feature.
|
||||
*/
|
||||
|
||||
uint8_t bUnitID; /**< ID value of this feature unit - must be a unique value within the device. */
|
||||
uint8_t bSourceID; /**< Source ID value of the audio source input into this feature unit. */
|
||||
|
||||
uint8_t bControlSize; /**< Size of each element in the \c ChannelControls array. */
|
||||
uint8_t bmaControls[3]; /**< Feature masks for the control channel, and each separate audio channel. */
|
||||
|
||||
uint8_t iFeature; /**< Index of a string descriptor describing this descriptor within the device. */
|
||||
} ATTR_PACKED USB_Audio_StdDescriptor_FeatureUnit_t;
|
||||
|
||||
/** \brief Audio class-specific Streaming Audio Interface Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific streaming interface descriptor. This indicates to the host
|
||||
* how audio streams within the device are formatted. See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_StdDescriptor_Interface_AS_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
|
||||
uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* a value from the \ref Audio_CSInterface_AS_SubTypes_t enum.
|
||||
*/
|
||||
|
||||
uint8_t TerminalLink; /**< ID value of the output terminal this descriptor is describing. */
|
||||
|
||||
uint8_t FrameDelay; /**< Delay in frames resulting from the complete sample processing from input to output. */
|
||||
uint16_t AudioFormat; /**< Format of the audio stream, see Audio Device Formats specification. */
|
||||
} ATTR_PACKED USB_Audio_Descriptor_Interface_AS_t;
|
||||
|
||||
/** \brief Audio class-specific Streaming Audio Interface Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific streaming interface descriptor. This indicates to the host
|
||||
* how audio streams within the device are formatted. See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_Descriptor_Interface_AS_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
|
||||
uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* a value from the \ref Audio_CSInterface_AS_SubTypes_t enum.
|
||||
*/
|
||||
|
||||
uint8_t bTerminalLink; /**< ID value of the output terminal this descriptor is describing. */
|
||||
|
||||
uint8_t bDelay; /**< Delay in frames resulting from the complete sample processing from input to output. */
|
||||
uint16_t wFormatTag; /**< Format of the audio stream, see Audio Device Formats specification. */
|
||||
} ATTR_PACKED USB_Audio_StdDescriptor_Interface_AS_t;
|
||||
|
||||
/** \brief Audio class-specific Format Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific audio format descriptor. This is used to give the host full details
|
||||
* about the number of channels, the sample resolution, acceptable sample frequencies and encoding method used
|
||||
* in the device's audio streams. See the USB Audio specification for more details.
|
||||
*
|
||||
* \attention This descriptor <b>must</b> be followed by one or more \ref USB_Audio_SampleFreq_t elements containing
|
||||
* the continuous or discrete sample frequencies.
|
||||
*
|
||||
* \see \ref USB_Audio_StdDescriptor_Format_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
|
||||
uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* must be \ref AUDIO_DSUBTYPE_CSInterface_FormatType.
|
||||
*/
|
||||
|
||||
uint8_t FormatType; /**< Format of the audio stream, see Audio Device Formats specification. */
|
||||
uint8_t Channels; /**< Total number of discrete channels in the stream. */
|
||||
|
||||
uint8_t SubFrameSize; /**< Size in bytes of each channel's sample data in the stream. */
|
||||
uint8_t BitResolution; /**< Bits of resolution of each channel's samples in the stream. */
|
||||
|
||||
uint8_t TotalDiscreteSampleRates; /**< Total number of discrete sample frequencies supported by the device. When
|
||||
* zero, this must be followed by the lower and upper continuous sampling
|
||||
* frequencies supported by the device; otherwise, this must be followed
|
||||
* by the given number of discrete sampling frequencies supported.
|
||||
*/
|
||||
} ATTR_PACKED USB_Audio_Descriptor_Format_t;
|
||||
|
||||
/** \brief 24-Bit Audio Frequency Structure.
|
||||
*
|
||||
* Type define for a 24-bit audio sample frequency structure. As GCC does not contain a built in 24-bit datatype,
|
||||
* this this structure is used to build up the value instead. Fill this structure with the \ref AUDIO_SAMPLE_FREQ() macro.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Byte1; /**< Lowest 8 bits of the 24-bit value. */
|
||||
uint8_t Byte2; /**< Middle 8 bits of the 24-bit value. */
|
||||
uint8_t Byte3; /**< Upper 8 bits of the 24-bit value. */
|
||||
} ATTR_PACKED USB_Audio_SampleFreq_t;
|
||||
|
||||
/** \brief Audio class-specific Format Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific audio format descriptor. This is used to give the host full details
|
||||
* about the number of channels, the sample resolution, acceptable sample frequencies and encoding method used
|
||||
* in the device's audio streams. See the USB Audio specification for more details.
|
||||
*
|
||||
* \attention This descriptor <b>must</b> be followed by one or more 24-bit integer elements containing the continuous
|
||||
* or discrete sample frequencies.
|
||||
*
|
||||
* \see \ref USB_Audio_Descriptor_Format_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* must be \ref AUDIO_DSUBTYPE_CSInterface_FormatType.
|
||||
*/
|
||||
|
||||
uint8_t bDescriptorSubtype;/**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* a value from the \ref Audio_CSInterface_AS_SubTypes_t enum.
|
||||
*/
|
||||
|
||||
uint8_t bFormatType; /**< Format of the audio stream, see Audio Device Formats specification. */
|
||||
uint8_t bNrChannels; /**< Total number of discrete channels in the stream. */
|
||||
|
||||
uint8_t bSubFrameSize; /**< Size in bytes of each channel's sample data in the stream. */
|
||||
uint8_t bBitResolution; /**< Bits of resolution of each channel's samples in the stream. */
|
||||
|
||||
uint8_t bSampleFrequencyType; /**< Total number of sample frequencies supported by the device. When
|
||||
* zero, this must be followed by the lower and upper continuous sampling
|
||||
* frequencies supported by the device; otherwise, this must be followed
|
||||
* by the given number of discrete sampling frequencies supported.
|
||||
*/
|
||||
} ATTR_PACKED USB_Audio_StdDescriptor_Format_t;
|
||||
|
||||
/** \brief Audio class-specific Streaming Endpoint Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific endpoint descriptor. This contains a regular endpoint
|
||||
* descriptor with a few Audio-class-specific extensions. See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_StdDescriptor_StreamEndpoint_Std_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Endpoint_t Endpoint; /**< Standard endpoint descriptor describing the audio endpoint. */
|
||||
|
||||
uint8_t Refresh; /**< Always set to zero for Audio class devices. */
|
||||
uint8_t SyncEndpointNumber; /**< Endpoint address to send synchronization information to, if needed (zero otherwise). */
|
||||
} ATTR_PACKED USB_Audio_Descriptor_StreamEndpoint_Std_t;
|
||||
|
||||
/** \brief Audio class-specific Streaming Endpoint Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific endpoint descriptor. This contains a regular endpoint
|
||||
* descriptor with a few Audio-class-specific extensions. See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_Descriptor_StreamEndpoint_Std_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a
|
||||
* value given by the specific class.
|
||||
*/
|
||||
uint8_t bEndpointAddress; /**< Logical address of the endpoint within the device for the current
|
||||
* configuration, including direction mask.
|
||||
*/
|
||||
uint8_t bmAttributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (\c EP_TYPE_*)
|
||||
* and attributes (\c ENDPOINT_ATTR_*) masks.
|
||||
*/
|
||||
uint16_t wMaxPacketSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet size
|
||||
* that the endpoint can receive at a time.
|
||||
*/
|
||||
uint8_t bInterval; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT or
|
||||
* ISOCHRONOUS type.
|
||||
*/
|
||||
|
||||
uint8_t bRefresh; /**< Always set to zero for Audio class devices. */
|
||||
uint8_t bSynchAddress; /**< Endpoint address to send synchronization information to, if needed (zero otherwise). */
|
||||
} ATTR_PACKED USB_Audio_StdDescriptor_StreamEndpoint_Std_t;
|
||||
|
||||
/** \brief Audio class-specific Extended Endpoint Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific extended endpoint descriptor. This contains extra information
|
||||
* on the usage of endpoints used to stream audio in and out of the USB Audio device, and follows an Audio
|
||||
* class-specific extended endpoint descriptor. See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_StdDescriptor_StreamEndpoint_Spc_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
|
||||
uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* a value from the \ref Audio_CSEndpoint_SubTypes_t enum.
|
||||
*/
|
||||
|
||||
uint8_t Attributes; /**< Audio class-specific endpoint attributes, such as \ref AUDIO_EP_FULL_PACKETS_ONLY. */
|
||||
|
||||
uint8_t LockDelayUnits; /**< Units used for the LockDelay field, see Audio class specification. */
|
||||
uint16_t LockDelay; /**< Time required to internally lock endpoint's internal clock recovery circuitry. */
|
||||
} ATTR_PACKED USB_Audio_Descriptor_StreamEndpoint_Spc_t;
|
||||
|
||||
/** \brief Audio class-specific Extended Endpoint Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for an Audio class-specific extended endpoint descriptor. This contains extra information
|
||||
* on the usage of endpoints used to stream audio in and out of the USB Audio device, and follows an Audio
|
||||
* class-specific extended endpoint descriptor. See the USB Audio specification for more details.
|
||||
*
|
||||
* \see \ref USB_Audio_Descriptor_StreamEndpoint_Spc_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
|
||||
uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors,
|
||||
* a value from the \ref Audio_CSEndpoint_SubTypes_t enum.
|
||||
*/
|
||||
|
||||
uint8_t bmAttributes; /**< Audio class-specific endpoint attributes, such as \ref AUDIO_EP_FULL_PACKETS_ONLY. */
|
||||
|
||||
uint8_t bLockDelayUnits; /**< Units used for the LockDelay field, see Audio class specification. */
|
||||
uint16_t wLockDelay; /**< Time required to internally lock endpoint's internal clock recovery circuitry. */
|
||||
} ATTR_PACKED USB_Audio_StdDescriptor_StreamEndpoint_Spc_t;
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
include(pico_extras_import.cmake)
|
||||
|
||||
project(ploopy_headphones_project C CXX ASM)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
pico_sdk_init()
|
||||
|
||||
add_executable(ploopy_headphones
|
||||
run.c
|
||||
ringbuf.c
|
||||
i2s.c
|
||||
fix16.c
|
||||
bqf.c
|
||||
user.c
|
||||
)
|
||||
|
||||
target_include_directories(ploopy_headphones PRIVATE ${CMAKE_SOURCE_DIR})
|
||||
|
||||
pico_generate_pio_header(ploopy_headphones ${CMAKE_CURRENT_LIST_DIR}/i2s.pio)
|
||||
|
||||
target_compile_definitions(ploopy_headphones PRIVATE
|
||||
# ours are zero based, so say so
|
||||
PICO_USBDEV_USE_ZERO_BASED_INTERFACES=1
|
||||
|
||||
# need large descriptor
|
||||
PICO_USBDEV_MAX_DESCRIPTOR_SIZE=256
|
||||
|
||||
PICO_USBDEV_ISOCHRONOUS_BUFFER_STRIDE_TYPE=1
|
||||
)
|
||||
|
||||
pico_enable_stdio_usb(ploopy_headphones 0)
|
||||
pico_enable_stdio_uart(ploopy_headphones 0)
|
||||
|
||||
pico_add_extra_outputs(ploopy_headphones)
|
||||
|
||||
target_link_libraries(ploopy_headphones
|
||||
hardware_pio
|
||||
hardware_clocks
|
||||
hardware_dma
|
||||
hardware_irq
|
||||
hardware_pwm
|
||||
hardware_i2c
|
||||
hardware_vreg
|
||||
hardware_sync
|
||||
pico_stdlib
|
||||
pico_multicore
|
||||
usb_device
|
||||
)
|
|
@ -0,0 +1,765 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2020.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2020 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaims all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common standard USB Descriptor definitions for all architectures.
|
||||
* \copydetails Group_StdDescriptors
|
||||
*
|
||||
* \note This file should not be included directly. It is automatically included as needed by the USB driver
|
||||
* dispatch header located in LUFA/Drivers/USB/USB.h.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* \defgroup Group_StdDescriptors USB Descriptors
|
||||
* \brief Standard USB Descriptor definitions.
|
||||
*
|
||||
* Standard USB device descriptor defines and retrieval routines, for USB devices. This module contains
|
||||
* structures and macros for the easy creation of standard USB descriptors in USB device projects.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __USBDESCRIPTORS_H__
|
||||
#define __USBDESCRIPTORS_H__
|
||||
|
||||
/* Includes: */
|
||||
|
||||
#define ATTR_PACKED __packed
|
||||
#define CPU_TO_LE16(x) (x)
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** Indicates that a given descriptor does not exist in the device. This can be used inside descriptors
|
||||
* for string descriptor indexes, or may be use as a return value for GetDescriptor when the specified
|
||||
* descriptor does not exist.
|
||||
*/
|
||||
#define NO_DESCRIPTOR 0
|
||||
|
||||
/** Macro to calculate the power value for the configuration descriptor, from a given number of milliamperes.
|
||||
*
|
||||
* \param[in] mA Maximum number of milliamps the device consumes when the given configuration is selected.
|
||||
*/
|
||||
#define USB_CONFIG_POWER_MA(mA) ((mA) >> 1)
|
||||
|
||||
/** Macro to calculate the Unicode length of a string with a given number of Unicode characters.
|
||||
* Should be used in string descriptor's headers for giving the string descriptor's byte length.
|
||||
*
|
||||
* \param[in] UnicodeChars Number of Unicode characters in the string text.
|
||||
*/
|
||||
#define USB_STRING_LEN(UnicodeChars) (sizeof(USB_Descriptor_Header_t) + ((UnicodeChars) << 1))
|
||||
|
||||
/** Convenience macro to easily create \ref USB_Descriptor_String_t instances from a wide character string.
|
||||
*
|
||||
* \note This macro is for little-endian systems only.
|
||||
*
|
||||
* \param[in] String String to initialize a USB String Descriptor structure with.
|
||||
*/
|
||||
#define USB_STRING_DESCRIPTOR(String) { .Header = {.Size = sizeof(USB_Descriptor_Header_t) + (sizeof(String) - 2), .Type = DTYPE_String}, .UnicodeString = String }
|
||||
|
||||
/** Convenience macro to easily create \ref USB_Descriptor_String_t instances from an array of characters.
|
||||
*
|
||||
* \param[in] ... Characters to initialize a USB String Descriptor structure with.
|
||||
*/
|
||||
#define USB_STRING_DESCRIPTOR_ARRAY(...) { .Header = {.Size = sizeof(USB_Descriptor_Header_t) + sizeof((uint16_t[]){__VA_ARGS__}), .Type = DTYPE_String}, .UnicodeString = {__VA_ARGS__} }
|
||||
|
||||
/** Macro to encode a given major/minor/revision version number into Binary Coded Decimal format for descriptor
|
||||
* fields requiring BCD encoding, such as the USB version number in the standard device descriptor.
|
||||
*
|
||||
* \note This value is automatically converted into Little Endian, suitable for direct use inside device
|
||||
* descriptors on all architectures without endianness conversion macros.
|
||||
*
|
||||
* \param[in] Major Major version number to encode.
|
||||
* \param[in] Minor Minor version number to encode.
|
||||
* \param[in] Revision Revision version number to encode.
|
||||
*/
|
||||
#define VERSION_BCD(Major, Minor, Revision) \
|
||||
CPU_TO_LE16( ((Major & 0xFF) << 8) | \
|
||||
((Minor & 0x0F) << 4) | \
|
||||
(Revision & 0x0F) )
|
||||
|
||||
/** String language ID for the English language. Should be used in \ref USB_Descriptor_String_t descriptors
|
||||
* to indicate that the English language is supported by the device in its string descriptors.
|
||||
*/
|
||||
#define LANGUAGE_ID_ENG 0x0409
|
||||
|
||||
/** \name USB Configuration Descriptor Attribute Masks */
|
||||
/**@{*/
|
||||
/** Mask for the reserved bit in the Configuration Descriptor's \c ConfigAttributes field, which must be always
|
||||
* set on all USB devices for historical purposes.
|
||||
*/
|
||||
#define USB_CONFIG_ATTR_RESERVED 0x80
|
||||
|
||||
/** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
|
||||
* descriptor's \c ConfigAttributes value to indicate that the specified configuration can draw its power
|
||||
* from the device's own power source, instead of drawing it from the USB host.
|
||||
*
|
||||
* Note that the host will probe this dynamically - the device should report its current power state via the
|
||||
* \ref USB_Device_CurrentlySelfPowered global variable.
|
||||
*/
|
||||
#define USB_CONFIG_ATTR_SELFPOWERED 0x40
|
||||
|
||||
/** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
|
||||
* descriptor's \c ConfigAttributes value to indicate that the specified configuration supports the
|
||||
* remote wakeup feature of the USB standard, allowing a suspended USB device to wake up the host upon
|
||||
* request.
|
||||
*
|
||||
* If set, the host will dynamically enable and disable remote wakeup support, indicated via the
|
||||
* \ref USB_Device_RemoteWakeupEnabled global variable. To initiate a remote wakeup of the host (when allowed)
|
||||
* see \ref USB_Device_RemoteWakeupEnabled().
|
||||
*/
|
||||
#define USB_CONFIG_ATTR_REMOTEWAKEUP 0x20
|
||||
/**@}*/
|
||||
|
||||
/** \name Endpoint Descriptor Attribute Masks */
|
||||
/**@{*/
|
||||
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
|
||||
* \c Attributes value to indicate that the specified endpoint is not synchronized.
|
||||
*
|
||||
* \see The USB specification for more details on the possible Endpoint attributes.
|
||||
*/
|
||||
#define ENDPOINT_ATTR_NO_SYNC (0 << 2)
|
||||
|
||||
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
|
||||
* \c Attributes value to indicate that the specified endpoint is asynchronous.
|
||||
*
|
||||
* \see The USB specification for more details on the possible Endpoint attributes.
|
||||
*/
|
||||
#define ENDPOINT_ATTR_ASYNC (1 << 2)
|
||||
|
||||
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
|
||||
* \c Attributes value to indicate that the specified endpoint is adaptive.
|
||||
*
|
||||
* \see The USB specification for more details on the possible Endpoint attributes.
|
||||
*/
|
||||
#define ENDPOINT_ATTR_ADAPTIVE (2 << 2)
|
||||
|
||||
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
|
||||
* \c Attributes value to indicate that the specified endpoint is synchronized.
|
||||
*
|
||||
* \see The USB specification for more details on the possible Endpoint attributes.
|
||||
*/
|
||||
#define ENDPOINT_ATTR_SYNC (3 << 2)
|
||||
/**@}*/
|
||||
|
||||
/** \name Endpoint Descriptor Usage Masks */
|
||||
/**@{*/
|
||||
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
|
||||
* \c Attributes value to indicate that the specified endpoint is used for data transfers.
|
||||
*
|
||||
* \see The USB specification for more details on the possible Endpoint usage attributes.
|
||||
*/
|
||||
#define ENDPOINT_USAGE_DATA (0 << 4)
|
||||
|
||||
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
|
||||
* \c Attributes value to indicate that the specified endpoint is used for feedback.
|
||||
*
|
||||
* \see The USB specification for more details on the possible Endpoint usage attributes.
|
||||
*/
|
||||
#define ENDPOINT_USAGE_FEEDBACK (1 << 4)
|
||||
|
||||
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
|
||||
* \c Attributes value to indicate that the specified endpoint is used for implicit feedback.
|
||||
*
|
||||
* \see The USB specification for more details on the possible Endpoint usage attributes.
|
||||
*/
|
||||
#define ENDPOINT_USAGE_IMPLICIT_FEEDBACK (2 << 4)
|
||||
/**@}*/
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible standard descriptor types, as given in each descriptor's header. */
|
||||
enum USB_DescriptorTypes_t
|
||||
{
|
||||
DTYPE_Device = 0x01, /**< Indicates that the descriptor is a device descriptor. */
|
||||
DTYPE_Configuration = 0x02, /**< Indicates that the descriptor is a configuration descriptor. */
|
||||
DTYPE_String = 0x03, /**< Indicates that the descriptor is a string descriptor. */
|
||||
DTYPE_Interface = 0x04, /**< Indicates that the descriptor is an interface descriptor. */
|
||||
DTYPE_Endpoint = 0x05, /**< Indicates that the descriptor is an endpoint descriptor. */
|
||||
DTYPE_DeviceQualifier = 0x06, /**< Indicates that the descriptor is a device qualifier descriptor. */
|
||||
DTYPE_Other = 0x07, /**< Indicates that the descriptor is of other type. */
|
||||
DTYPE_InterfacePower = 0x08, /**< Indicates that the descriptor is an interface power descriptor. */
|
||||
DTYPE_InterfaceAssociation = 0x0B, /**< Indicates that the descriptor is an interface association descriptor. */
|
||||
};
|
||||
|
||||
/** Enum for possible Class, Subclass and Protocol values of device and interface descriptors. */
|
||||
enum USB_Descriptor_ClassSubclassProtocol_t
|
||||
{
|
||||
USB_CSCP_NoDeviceClass = 0x00, /**< Descriptor Class value indicating that the device does not belong
|
||||
* to a particular class at the device level.
|
||||
*/
|
||||
USB_CSCP_NoDeviceSubclass = 0x00, /**< Descriptor Subclass value indicating that the device does not belong
|
||||
* to a particular subclass at the device level.
|
||||
*/
|
||||
USB_CSCP_NoDeviceProtocol = 0x00, /**< Descriptor Protocol value indicating that the device does not belong
|
||||
* to a particular protocol at the device level.
|
||||
*/
|
||||
USB_CSCP_VendorSpecificClass = 0xFF, /**< Descriptor Class value indicating that the device/interface belongs
|
||||
* to a vendor specific class.
|
||||
*/
|
||||
USB_CSCP_VendorSpecificSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device/interface belongs
|
||||
* to a vendor specific subclass.
|
||||
*/
|
||||
USB_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device/interface belongs
|
||||
* to a vendor specific protocol.
|
||||
*/
|
||||
USB_CSCP_IADDeviceClass = 0xEF, /**< Descriptor Class value indicating that the device belongs to the
|
||||
* Interface Association Descriptor class.
|
||||
*/
|
||||
USB_CSCP_IADDeviceSubclass = 0x02, /**< Descriptor Subclass value indicating that the device belongs to the
|
||||
* Interface Association Descriptor subclass.
|
||||
*/
|
||||
USB_CSCP_IADDeviceProtocol = 0x01, /**< Descriptor Protocol value indicating that the device belongs to the
|
||||
* Interface Association Descriptor protocol.
|
||||
*/
|
||||
};
|
||||
|
||||
/* Type Defines: */
|
||||
/** \brief Standard USB Descriptor Header (LUFA naming conventions).
|
||||
*
|
||||
* Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
|
||||
* uses LUFA-specific element names to make each element's purpose clearer.
|
||||
*
|
||||
* \see \ref USB_StdDescriptor_Header_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Size; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t Type; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
} ATTR_PACKED USB_Descriptor_Header_t;
|
||||
|
||||
/** \brief Standard USB Descriptor Header (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
|
||||
* uses the relevant standard's given element names to ensure compatibility with the standard.
|
||||
*
|
||||
* \see \ref USB_Descriptor_Header_t for the version of this type with non-standard LUFA specific element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
} ATTR_PACKED USB_StdDescriptor_Header_t;
|
||||
|
||||
/** \brief Standard USB Device Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for a standard Device Descriptor. This structure uses LUFA-specific element names to make each
|
||||
* element's purpose clearer.
|
||||
*
|
||||
* \see \ref USB_StdDescriptor_Device_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
|
||||
|
||||
uint16_t USBSpecification; /**< BCD of the supported USB specification.
|
||||
*
|
||||
* \see \ref VERSION_BCD() utility macro.
|
||||
*/
|
||||
uint8_t Class; /**< USB device class. */
|
||||
uint8_t SubClass; /**< USB device subclass. */
|
||||
uint8_t Protocol; /**< USB device protocol. */
|
||||
|
||||
uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */
|
||||
|
||||
uint16_t VendorID; /**< Vendor ID for the USB product. */
|
||||
uint16_t ProductID; /**< Unique product ID for the USB product. */
|
||||
uint16_t ReleaseNumber; /**< Product release (version) number.
|
||||
*
|
||||
* \see \ref VERSION_BCD() utility macro.
|
||||
*/
|
||||
uint8_t ManufacturerStrIndex; /**< String index for the manufacturer's name. The
|
||||
* host will request this string via a separate
|
||||
* control request for the string descriptor.
|
||||
*
|
||||
* \note If no string supplied, use \ref NO_DESCRIPTOR.
|
||||
*/
|
||||
uint8_t ProductStrIndex; /**< String index for the product name/details.
|
||||
*
|
||||
* \see ManufacturerStrIndex structure entry.
|
||||
*/
|
||||
uint8_t SerialNumStrIndex; /**< String index for the product's globally unique hexadecimal
|
||||
* serial number, in uppercase Unicode ASCII.
|
||||
*
|
||||
* \note On some microcontroller models, there is an embedded serial number
|
||||
* in the chip which can be used for the device serial number.
|
||||
* To use this serial number, set this to \c USE_INTERNAL_SERIAL.
|
||||
* On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR
|
||||
* and will cause the host to generate a pseudo-unique value for the
|
||||
* device upon insertion.
|
||||
*
|
||||
* \see \c ManufacturerStrIndex structure entry.
|
||||
*/
|
||||
uint8_t NumberOfConfigurations; /**< Total number of configurations supported by
|
||||
* the device.
|
||||
*/
|
||||
} ATTR_PACKED USB_Descriptor_Device_t;
|
||||
|
||||
/** \brief Standard USB Device Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for a standard Device Descriptor. This structure uses the relevant standard's given element names
|
||||
* to ensure compatibility with the standard.
|
||||
*
|
||||
* \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
uint16_t bcdUSB; /**< BCD of the supported USB specification.
|
||||
*
|
||||
* \see \ref VERSION_BCD() utility macro.
|
||||
*/
|
||||
uint8_t bDeviceClass; /**< USB device class. */
|
||||
uint8_t bDeviceSubClass; /**< USB device subclass. */
|
||||
uint8_t bDeviceProtocol; /**< USB device protocol. */
|
||||
uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
|
||||
uint16_t idVendor; /**< Vendor ID for the USB product. */
|
||||
uint16_t idProduct; /**< Unique product ID for the USB product. */
|
||||
uint16_t bcdDevice; /**< Product release (version) number.
|
||||
*
|
||||
* \see \ref VERSION_BCD() utility macro.
|
||||
*/
|
||||
uint8_t iManufacturer; /**< String index for the manufacturer's name. The
|
||||
* host will request this string via a separate
|
||||
* control request for the string descriptor.
|
||||
*
|
||||
* \note If no string supplied, use \ref NO_DESCRIPTOR.
|
||||
*/
|
||||
uint8_t iProduct; /**< String index for the product name/details.
|
||||
*
|
||||
* \see ManufacturerStrIndex structure entry.
|
||||
*/
|
||||
uint8_t iSerialNumber; /**< String index for the product's globally unique hexadecimal
|
||||
* serial number, in uppercase Unicode ASCII.
|
||||
*
|
||||
* \note On some microcontroller models, there is an embedded serial number
|
||||
* in the chip which can be used for the device serial number.
|
||||
* To use this serial number, set this to \c USE_INTERNAL_SERIAL.
|
||||
* On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR
|
||||
* and will cause the host to generate a pseudo-unique value for the
|
||||
* device upon insertion.
|
||||
*
|
||||
* \see \c ManufacturerStrIndex structure entry.
|
||||
*/
|
||||
uint8_t bNumConfigurations; /**< Total number of configurations supported by
|
||||
* the device.
|
||||
*/
|
||||
} ATTR_PACKED USB_StdDescriptor_Device_t;
|
||||
|
||||
/** \brief Standard USB Device Qualifier Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for a standard Device Qualifier Descriptor. This structure uses LUFA-specific element names
|
||||
* to make each element's purpose clearer.
|
||||
*
|
||||
* \see \ref USB_StdDescriptor_DeviceQualifier_t for the version of this type with standard element names.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
|
||||
|
||||
uint16_t USBSpecification; /**< BCD of the supported USB specification.
|
||||
*
|
||||
* \see \ref VERSION_BCD() utility macro.
|
||||
*/
|
||||
uint8_t Class; /**< USB device class. */
|
||||
uint8_t SubClass; /**< USB device subclass. */
|
||||
uint8_t Protocol; /**< USB device protocol. */
|
||||
|
||||
uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */
|
||||
uint8_t NumberOfConfigurations; /**< Total number of configurations supported by
|
||||
* the device.
|
||||
*/
|
||||
uint8_t Reserved; /**< Reserved for future use, must be 0. */
|
||||
} ATTR_PACKED USB_Descriptor_DeviceQualifier_t;
|
||||
|
||||
/** \brief Standard USB Device Qualifier Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for a standard Device Qualifier Descriptor. This structure uses the relevant standard's given element names
|
||||
* to ensure compatibility with the standard.
|
||||
*
|
||||
* \see \ref USB_Descriptor_DeviceQualifier_t for the version of this type with non-standard LUFA specific element names.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
uint16_t bcdUSB; /**< BCD of the supported USB specification.
|
||||
*
|
||||
* \see \ref VERSION_BCD() utility macro.
|
||||
*/
|
||||
uint8_t bDeviceClass; /**< USB device class. */
|
||||
uint8_t bDeviceSubClass; /**< USB device subclass. */
|
||||
uint8_t bDeviceProtocol; /**< USB device protocol. */
|
||||
uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
|
||||
uint8_t bNumConfigurations; /**< Total number of configurations supported by
|
||||
* the device.
|
||||
*/
|
||||
uint8_t bReserved; /**< Reserved for future use, must be 0. */
|
||||
} ATTR_PACKED USB_StdDescriptor_DeviceQualifier_t;
|
||||
|
||||
/** \brief Standard USB Configuration Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for a standard Configuration Descriptor header. This structure uses LUFA-specific element names
|
||||
* to make each element's purpose clearer.
|
||||
*
|
||||
* \see \ref USB_StdDescriptor_Configuration_Header_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
|
||||
|
||||
uint16_t TotalConfigurationSize; /**< Size of the configuration descriptor header,
|
||||
* and all sub descriptors inside the configuration.
|
||||
*/
|
||||
uint8_t TotalInterfaces; /**< Total number of interfaces in the configuration. */
|
||||
|
||||
uint8_t ConfigurationNumber; /**< Configuration index of the current configuration. */
|
||||
uint8_t ConfigurationStrIndex; /**< Index of a string descriptor describing the configuration. */
|
||||
|
||||
uint8_t ConfigAttributes; /**< Configuration attributes, comprised of a mask of \c USB_CONFIG_ATTR_* masks.
|
||||
* On all devices, this should include USB_CONFIG_ATTR_RESERVED at a minimum.
|
||||
*/
|
||||
|
||||
uint8_t MaxPowerConsumption; /**< Maximum power consumption of the device while in the
|
||||
* current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
|
||||
* macro.
|
||||
*/
|
||||
} ATTR_PACKED USB_Descriptor_Configuration_Header_t;
|
||||
|
||||
/** \brief Standard USB Configuration Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for a standard Configuration Descriptor header. This structure uses the relevant standard's given element names
|
||||
* to ensure compatibility with the standard.
|
||||
*
|
||||
* \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
uint16_t wTotalLength; /**< Size of the configuration descriptor header,
|
||||
* and all sub descriptors inside the configuration.
|
||||
*/
|
||||
uint8_t bNumInterfaces; /**< Total number of interfaces in the configuration. */
|
||||
uint8_t bConfigurationValue; /**< Configuration index of the current configuration. */
|
||||
uint8_t iConfiguration; /**< Index of a string descriptor describing the configuration. */
|
||||
uint8_t bmAttributes; /**< Configuration attributes, comprised of a mask of \c USB_CONFIG_ATTR_* masks.
|
||||
* On all devices, this should include USB_CONFIG_ATTR_RESERVED at a minimum.
|
||||
*/
|
||||
uint8_t bMaxPower; /**< Maximum power consumption of the device while in the
|
||||
* current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
|
||||
* macro.
|
||||
*/
|
||||
} ATTR_PACKED USB_StdDescriptor_Configuration_Header_t;
|
||||
|
||||
/** \brief Standard USB Interface Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for a standard Interface Descriptor. This structure uses LUFA-specific element names
|
||||
* to make each element's purpose clearer.
|
||||
*
|
||||
* \see \ref USB_StdDescriptor_Interface_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
|
||||
|
||||
uint8_t InterfaceNumber; /**< Index of the interface in the current configuration. */
|
||||
uint8_t AlternateSetting; /**< Alternate setting for the interface number. The same
|
||||
* interface number can have multiple alternate settings
|
||||
* with different endpoint configurations, which can be
|
||||
* selected by the host.
|
||||
*/
|
||||
uint8_t TotalEndpoints; /**< Total number of endpoints in the interface. */
|
||||
|
||||
uint8_t Class; /**< Interface class ID. */
|
||||
uint8_t SubClass; /**< Interface subclass ID. */
|
||||
uint8_t Protocol; /**< Interface protocol ID. */
|
||||
|
||||
uint8_t InterfaceStrIndex; /**< Index of the string descriptor describing the interface. */
|
||||
} ATTR_PACKED USB_Descriptor_Interface_t;
|
||||
|
||||
/** \brief Standard USB Interface Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for a standard Interface Descriptor. This structure uses the relevant standard's given element names
|
||||
* to ensure compatibility with the standard.
|
||||
*
|
||||
* \see \ref USB_Descriptor_Interface_t for the version of this type with non-standard LUFA specific element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
uint8_t bInterfaceNumber; /**< Index of the interface in the current configuration. */
|
||||
uint8_t bAlternateSetting; /**< Alternate setting for the interface number. The same
|
||||
* interface number can have multiple alternate settings
|
||||
* with different endpoint configurations, which can be
|
||||
* selected by the host.
|
||||
*/
|
||||
uint8_t bNumEndpoints; /**< Total number of endpoints in the interface. */
|
||||
uint8_t bInterfaceClass; /**< Interface class ID. */
|
||||
uint8_t bInterfaceSubClass; /**< Interface subclass ID. */
|
||||
uint8_t bInterfaceProtocol; /**< Interface protocol ID. */
|
||||
uint8_t iInterface; /**< Index of the string descriptor describing the
|
||||
* interface.
|
||||
*/
|
||||
} ATTR_PACKED USB_StdDescriptor_Interface_t;
|
||||
|
||||
/** \brief Standard USB Interface Association Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for a standard Interface Association Descriptor. This structure uses LUFA-specific element names
|
||||
* to make each element's purpose clearer.
|
||||
*
|
||||
* This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
|
||||
* <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
|
||||
* devices with multiple interfaces related to the same function to have the multiple interfaces bound
|
||||
* together at the point of enumeration, loading one generic driver for all the interfaces in the single
|
||||
* function. Read the ECN for more information.
|
||||
*
|
||||
* \see \ref USB_StdDescriptor_Interface_Association_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
|
||||
|
||||
uint8_t FirstInterfaceIndex; /**< Index of the first associated interface. */
|
||||
uint8_t TotalInterfaces; /**< Total number of associated interfaces. */
|
||||
|
||||
uint8_t Class; /**< Interface class ID. */
|
||||
uint8_t SubClass; /**< Interface subclass ID. */
|
||||
uint8_t Protocol; /**< Interface protocol ID. */
|
||||
|
||||
uint8_t IADStrIndex; /**< Index of the string descriptor describing the
|
||||
* interface association.
|
||||
*/
|
||||
} ATTR_PACKED USB_Descriptor_Interface_Association_t;
|
||||
|
||||
/** \brief Standard USB Interface Association Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for a standard Interface Association Descriptor. This structure uses the relevant standard's given
|
||||
* element names to ensure compatibility with the standard.
|
||||
*
|
||||
* This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
|
||||
* <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
|
||||
* devices with multiple interfaces related to the same function to have the multiple interfaces bound
|
||||
* together at the point of enumeration, loading one generic driver for all the interfaces in the single
|
||||
* function. Read the ECN for more information.
|
||||
*
|
||||
* \see \ref USB_Descriptor_Interface_Association_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
|
||||
* given by the specific class.
|
||||
*/
|
||||
uint8_t bFirstInterface; /**< Index of the first associated interface. */
|
||||
uint8_t bInterfaceCount; /**< Total number of associated interfaces. */
|
||||
uint8_t bFunctionClass; /**< Interface class ID. */
|
||||
uint8_t bFunctionSubClass; /**< Interface subclass ID. */
|
||||
uint8_t bFunctionProtocol; /**< Interface protocol ID. */
|
||||
uint8_t iFunction; /**< Index of the string descriptor describing the
|
||||
* interface association.
|
||||
*/
|
||||
} ATTR_PACKED USB_StdDescriptor_Interface_Association_t;
|
||||
|
||||
/** \brief Standard USB Endpoint Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for a standard Endpoint Descriptor. This structure uses LUFA-specific element names
|
||||
* to make each element's purpose clearer.
|
||||
*
|
||||
* \see \ref USB_StdDescriptor_Endpoint_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
|
||||
|
||||
uint8_t EndpointAddress; /**< Logical address of the endpoint within the device for the current
|
||||
* configuration, including direction mask.
|
||||
*/
|
||||
uint8_t Attributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
|
||||
* and attributes (ENDPOINT_ATTR_*) masks.
|
||||
*/
|
||||
uint16_t EndpointSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet
|
||||
* size that the endpoint can receive at a time.
|
||||
*/
|
||||
uint8_t PollingIntervalMS; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT
|
||||
* or ISOCHRONOUS type.
|
||||
*/
|
||||
} ATTR_PACKED USB_Descriptor_Endpoint_t;
|
||||
|
||||
/** \brief Standard USB Endpoint Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for a standard Endpoint Descriptor. This structure uses the relevant standard's given
|
||||
* element names to ensure compatibility with the standard.
|
||||
*
|
||||
* \see \ref USB_Descriptor_Endpoint_t for the version of this type with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a
|
||||
* value given by the specific class.
|
||||
*/
|
||||
uint8_t bEndpointAddress; /**< Logical address of the endpoint within the device for the current
|
||||
* configuration, including direction mask.
|
||||
*/
|
||||
uint8_t bmAttributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
|
||||
* and attributes (ENDPOINT_ATTR_*) masks.
|
||||
*/
|
||||
uint16_t wMaxPacketSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet size
|
||||
* that the endpoint can receive at a time.
|
||||
*/
|
||||
uint8_t bInterval; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT or
|
||||
* ISOCHRONOUS type.
|
||||
*/
|
||||
} ATTR_PACKED USB_StdDescriptor_Endpoint_t;
|
||||
|
||||
/** \brief Standard USB String Descriptor (LUFA naming conventions).
|
||||
*
|
||||
* Type define for a standard string descriptor. Unlike other standard descriptors, the length
|
||||
* of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
|
||||
* macro rather than by the size of the descriptor structure, as the length is not fixed.
|
||||
*
|
||||
* This structure should also be used for string index 0, which contains the supported language IDs for
|
||||
* the device as an array.
|
||||
*
|
||||
* This structure uses LUFA-specific element names to make each element's purpose clearer.
|
||||
*
|
||||
* \see \ref USB_StdDescriptor_String_t for the version of this type with standard element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
|
||||
|
||||
#if (((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA)) && !defined(__DOXYGEN__))
|
||||
wchar_t UnicodeString[];
|
||||
#else
|
||||
uint16_t UnicodeString[]; /**< String data, as unicode characters (alternatively,
|
||||
* string language IDs). If normal ASCII characters are
|
||||
* to be used, they must be added as an array of characters
|
||||
* rather than a normal C string so that they are widened to
|
||||
* Unicode size.
|
||||
*
|
||||
* Under GCC, strings prefixed with the "L" character (before
|
||||
* the opening string quotation mark) are considered to be
|
||||
* Unicode strings, and may be used instead of an explicit
|
||||
* array of ASCII characters on little endian devices with
|
||||
* UTF-16-LE \c wchar_t encoding.
|
||||
*/
|
||||
#endif
|
||||
} ATTR_PACKED USB_Descriptor_String_t;
|
||||
|
||||
/** \brief Standard USB String Descriptor (USB-IF naming conventions).
|
||||
*
|
||||
* Type define for a standard string descriptor. Unlike other standard descriptors, the length
|
||||
* of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
|
||||
* macro rather than by the size of the descriptor structure, as the length is not fixed.
|
||||
*
|
||||
* This structure should also be used for string index 0, which contains the supported language IDs for
|
||||
* the device as an array.
|
||||
*
|
||||
* This structure uses the relevant standard's given element names to ensure compatibility with the standard.
|
||||
*
|
||||
* \see \ref USB_Descriptor_String_t for the version of this type with with non-standard LUFA specific
|
||||
* element names.
|
||||
*
|
||||
* \note Regardless of CPU architecture, these values should be stored as little endian.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /**< Size of the descriptor, in bytes. */
|
||||
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t
|
||||
* or a value given by the specific class.
|
||||
*/
|
||||
uint16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs).
|
||||
* If normal ASCII characters are to be used, they must be added as an array
|
||||
* of characters rather than a normal C string so that they are widened to
|
||||
* Unicode size.
|
||||
*
|
||||
* Under GCC, strings prefixed with the "L" character (before the opening string
|
||||
* quotation mark) are considered to be Unicode strings, and may be used instead
|
||||
* of an explicit array of ASCII characters.
|
||||
*/
|
||||
} ATTR_PACKED USB_StdDescriptor_String_t;
|
||||
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
@ -0,0 +1,484 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* Robert Bristow-Johnson, a.k.a. RBJ
|
||||
* for his exceptional work on biquad formulae as applied to digital
|
||||
* audio filtering, summarised in his pamphlet, "Audio EQ Cookbook".
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bqf.h"
|
||||
|
||||
/**
|
||||
* Configure a low-pass filter. Parameters are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* Q: The quality factor. This is hard to explain. If you want to sound smart,
|
||||
* though, just start saying things like "Linkwitz-Riley filters are superior
|
||||
* due to their multi-stage flat summations to unity gain". Some example
|
||||
* values for this:
|
||||
* - 1/sqrt(2). A "Butterworth" filter. Use this by default; it results in
|
||||
* maximally-flat passband.
|
||||
* - 1/sqrt(3). A "Bessel" filter. Results in maximally-flat group delay.
|
||||
* - 1/2. A "Linkwitz-Riley" filter. Used for sounding smart. Optionally,
|
||||
* used to make lowpass and highpass sections that sum flat to unity gain.
|
||||
*/
|
||||
void bqf_lowpass_config(double fs, double f0, double Q, bqf_coeff_t *coefficients) {
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double b0 = (1.0 - cosw0) / 2.0;
|
||||
double b1 = 1.0 - cosw0;
|
||||
double b2 = (1.0 - cosw0) / 2.0;
|
||||
double a0 = 1.0 + alpha;
|
||||
double a1 = -2.0 * cosw0;
|
||||
double a2 = 1.0 - alpha;
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a high-pass filter. Parameters are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* Q: The quality factor. This is hard to explain. If you want to sound smart,
|
||||
* though, just start saying things like "Linkwitz-Riley filters are superior
|
||||
* due to their multi-stage flat summations to unity gain". Some example
|
||||
* values for this:
|
||||
* - 1/sqrt(2). A "Butterworth" filter. Use this by default; it results in
|
||||
* maximally-flat passband.
|
||||
* - 1/sqrt(3). A "Bessel" filter. Results in maximally-flat group delay.
|
||||
* - 1/2. A "Linkwitz-Riley" filter. Used for sounding smart. Optionally,
|
||||
* used to make lowpass and highpass sections that sum flat to unity gain.
|
||||
*/
|
||||
void bqf_highpass_config(double fs, double f0, double Q, bqf_coeff_t *coefficients) {
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double b0 = (1.0 + cosw0) / 2.0;
|
||||
double b1 = -(1.0 + cosw0);
|
||||
double b2 = (1.0 + cosw0) / 2.0;
|
||||
double a0 = 1.0 + alpha;
|
||||
double a1 = -2.0 * cosw0;
|
||||
double a2 = 1.0 - alpha;
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a band-pass filter, with constant skirt gain - which has a peak
|
||||
* gain of Q. Parameters are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* Q: The quality factor. It defines how aggressive the band pass attenuates
|
||||
* from the centre frequency. Some example values for Q:
|
||||
* - sqrt(2) is 1 octave wide
|
||||
*/
|
||||
void bqf_bandpass_skirt_config(double fs, double f0, double Q, bqf_coeff_t *coefficients) {
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double b0 = sinw0 / 2.0;
|
||||
double b1 = 0.0;
|
||||
double b2 = -sinw0 / 2.0;
|
||||
double a0 = 1.0 + alpha;
|
||||
double a1 = -2.0 * cosw0;
|
||||
double a2 = 1.0 - alpha;
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a band-pass filter, with constant peak gain of 0 dB. Parameters
|
||||
* are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* Q: The quality factor. It defines how aggressive the band pass attenuates
|
||||
* from the centre frequency. Some example values for Q:
|
||||
* - sqrt(2) is 1 octave wide
|
||||
*/
|
||||
void bqf_bandpass_peak_config(double fs, double f0, double Q, bqf_coeff_t *coefficients) {
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double b0 = alpha;
|
||||
double b1 = 0.0;
|
||||
double b2 = -alpha;
|
||||
double a0 = 1.0 + alpha;
|
||||
double a1 = -2.0 * cosw0;
|
||||
double a2 = 1.0 - alpha;
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a notch filter. Parameters are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* Q: The quality factor. It defines how aggressive the notch attenuates
|
||||
* from the centre frequency. Some example values for Q:
|
||||
* - sqrt(2) is 1 octave wide
|
||||
*/
|
||||
void bqf_notch_config(double fs, double f0, double Q, bqf_coeff_t *coefficients) {
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double b0 = 1.0;
|
||||
double b1 = -2.0 * cosw0;
|
||||
double b2 = 1.0;
|
||||
double a0 = 1.0 + alpha;
|
||||
double a1 = -2.0 * cosw0;
|
||||
double a2 = 1.0 - alpha;
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure an allpass filter. Parameters are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* Q: The quality factor. I don't actually know what this is for an allpass.
|
||||
* Try experimenting. Why do I have to do all the work?
|
||||
*/
|
||||
void bqf_allpass_config(double fs, double f0, double Q, bqf_coeff_t *coefficients) {
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double b0 = 1.0 - alpha;
|
||||
double b1 = -2.0 * cosw0;
|
||||
double b2 = 1.0 + alpha;
|
||||
double a0 = 1.0 + alpha;
|
||||
double a1 = -2.0 * cosw0;
|
||||
double a2 = 1.0 - alpha;
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a peaking filter. Parameters are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* dBgain: The gain at the centre frequency, in dB. Positive for boost,
|
||||
* negative for cut.
|
||||
*
|
||||
* Q: The quality factor. It defines the bandwidth from the centre frequency.
|
||||
* For the purposes of this filter, the bandwidth is defined using the points
|
||||
* on the curve at which the gain in dB is half of the peak gain. Some
|
||||
* example values for Q:
|
||||
* - sqrt(2) is 1 octave wide
|
||||
*/
|
||||
void bqf_peaking_config(double fs, double f0, double dBgain, double Q,
|
||||
bqf_coeff_t *coefficients) {
|
||||
|
||||
double A = pow(10.0, (dBgain/40));
|
||||
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double b0 = 1.0 + (alpha * A);
|
||||
double b1 = -2.0 * cosw0;
|
||||
double b2 = 1.0 - (alpha * A);
|
||||
double a0 = 1.0 + (alpha / A);
|
||||
double a1 = -2.0 * cosw0;
|
||||
double a2 = 1.0 - (alpha / A);
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a low-shelf filter. Parameters are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* dBgain: The gain at the centre frequency, in dB. Positive for boost,
|
||||
* negative for cut.
|
||||
*
|
||||
* Q: The quality factor. It defines the steepness of the shelf's slope. I
|
||||
* don't actually know what this is for a shelf filter. Try experimenting.
|
||||
* Why do I have to do all the work?
|
||||
*/
|
||||
void bqf_lowshelf_config(double fs, double f0, double dBgain, double Q,
|
||||
bqf_coeff_t *coefficients) {
|
||||
|
||||
double A = pow(10.0, (dBgain/40));
|
||||
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double trAa = 2 * sqrt(A) * alpha;
|
||||
|
||||
double b0 = A * ((A + 1) - ((A - 1) * cosw0) + trAa);
|
||||
double b1 = 2 * A * ((A - 1) - ((A + 1) * cosw0));
|
||||
double b2 = A * ((A + 1) - ((A - 1) * cosw0) - trAa);
|
||||
double a0 = (A + 1) + ((A - 1) * cosw0) + trAa;
|
||||
double a1 = -2 * ((A - 1) + ((A + 1) * cosw0));
|
||||
double a2 = (A + 1) + ((A - 1) * cosw0) - trAa;
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a high-shelf filter. Parameters are as follows:
|
||||
*
|
||||
* fs: The sampling frequency. This is usually defined for you by
|
||||
* SAMPLING_FREQ in run.h. It's the sampling frequency of the DAC on the
|
||||
* board.
|
||||
*
|
||||
* f0: The centre frequency. this is where the signal starts getting
|
||||
* attenuated.
|
||||
*
|
||||
* dBgain: The gain at the centre frequency, in dB. Positive for boost,
|
||||
* negative for cut.
|
||||
*
|
||||
* Q: The quality factor. It defines the steepness of the shelf's slope. I
|
||||
* don't actually know what this is for a shelf filter. Try experimenting.
|
||||
* Why do I have to do all the work?
|
||||
*/
|
||||
void bqf_highshelf_config(double fs, double f0, double dBgain, double Q,
|
||||
bqf_coeff_t *coefficients) {
|
||||
|
||||
double A = pow(10.0, (dBgain/40));
|
||||
|
||||
double w0 = 2.0 * M_PI * f0 / fs;
|
||||
|
||||
double cosw0 = cos(w0);
|
||||
double sinw0 = sin(w0);
|
||||
double alpha = sinw0 / (2.0 * Q);
|
||||
|
||||
double trAa = 2 * sqrt(A) * alpha;
|
||||
|
||||
double b0 = A * ((A + 1) + ((A - 1) * cosw0) + trAa);
|
||||
double b1 = -2 * A * ((A - 1) + ((A + 1) * cosw0));
|
||||
double b2 = A * ((A + 1) + ((A - 1) * cosw0) - trAa);
|
||||
double a0 = (A + 1) - ((A - 1) * cosw0) + trAa;
|
||||
double a1 = 2 * ((A - 1) - ((A + 1) * cosw0));
|
||||
double a2 = (A + 1) - ((A - 1) * cosw0) - trAa;
|
||||
|
||||
// Normalise all values to a0
|
||||
b0 = b0 / a0;
|
||||
b1 = b1 / a0;
|
||||
b2 = b2 / a0;
|
||||
a1 = a1 / a0;
|
||||
a2 = a2 / a0;
|
||||
a0 = 1.0;
|
||||
|
||||
coefficients->b0 = fix16_from_dbl(b0);
|
||||
coefficients->b1 = fix16_from_dbl(b1);
|
||||
coefficients->b2 = fix16_from_dbl(b2);
|
||||
coefficients->a0 = fix16_from_dbl(a0);
|
||||
coefficients->a1 = fix16_from_dbl(a1);
|
||||
coefficients->a2 = fix16_from_dbl(a2);
|
||||
}
|
||||
|
||||
fix16_t bqf_transform(fix16_t x, bqf_coeff_t *coefficients, bqf_mem_t *memory) {
|
||||
fix16_t y = fix16_mul(coefficients->b0, x) -
|
||||
fix16_mul(coefficients->a1, memory->y_1) +
|
||||
fix16_mul(coefficients->b1, memory->x_1) -
|
||||
fix16_mul(coefficients->a2, memory->y_2) +
|
||||
fix16_mul(coefficients->b2, memory->x_2);
|
||||
|
||||
memory->x_2 = memory->x_1;
|
||||
memory->x_1 = x;
|
||||
memory->y_2 = memory->y_1;
|
||||
memory->y_1 = y;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
void bqf_memreset(bqf_mem_t *memory) {
|
||||
memory->x_1 = fix16_from_dbl(0.0);
|
||||
memory->x_2 = fix16_from_dbl(0.0);
|
||||
memory->y_1 = fix16_from_dbl(0.0);
|
||||
memory->y_2 = fix16_from_dbl(0.0);
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* Robert Bristow-Johnson, a.k.a. RBJ
|
||||
* for his exceptional work on biquad formulae as applied to digital
|
||||
* audio filtering, summarised in his pamphlet, "Audio EQ Cookbook".
|
||||
*/
|
||||
|
||||
#ifndef BQF_H
|
||||
#define BQF_H
|
||||
|
||||
#include "fix16.h"
|
||||
|
||||
typedef struct _bqf_coeff_t {
|
||||
fix16_t a0;
|
||||
fix16_t a1;
|
||||
fix16_t a2;
|
||||
fix16_t b0;
|
||||
fix16_t b1;
|
||||
fix16_t b2;
|
||||
} bqf_coeff_t;
|
||||
|
||||
typedef struct _bqf_mem_t {
|
||||
fix16_t x_1;
|
||||
fix16_t x_2;
|
||||
fix16_t y_1;
|
||||
fix16_t y_2;
|
||||
} bqf_mem_t;
|
||||
|
||||
#define Q_BUTTERWORTH 0.707106781
|
||||
#define Q_BESSEL 0.577350269
|
||||
#define Q_LINKWITZ_RILEY 0.5
|
||||
|
||||
void bqf_lowpass_config(double, double, double, bqf_coeff_t *);
|
||||
void bqf_highpass_config(double, double, double, bqf_coeff_t *);
|
||||
void bqf_bandpass_skirt_config(double, double, double, bqf_coeff_t *);
|
||||
void bqf_bandpass_peak_config(double, double, double, bqf_coeff_t *);
|
||||
void bqf_notch_config(double, double, double, bqf_coeff_t *);
|
||||
void bqf_allpass_config(double, double, double, bqf_coeff_t *);
|
||||
void bqf_peaking_config(double, double, double, double, bqf_coeff_t *);
|
||||
void bqf_lowshelf_config(double, double, double, double, bqf_coeff_t *);
|
||||
void bqf_highshelf_config(double, double, double, double, bqf_coeff_t *);
|
||||
|
||||
fix16_t bqf_transform(fix16_t, bqf_coeff_t *, bqf_mem_t *);
|
||||
void bqf_memreset(bqf_mem_t *);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* Ben Brewer, a.k.a. flatmush
|
||||
* for his exceptional work on libfixmath, on which this is based.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "fix16.h"
|
||||
|
||||
fix16_t fix16_from_int(int16_t a) {
|
||||
return a * fix16_one;
|
||||
}
|
||||
|
||||
int16_t fix16_to_int(fix16_t a) {
|
||||
if (a >= 0)
|
||||
return (a + (fix16_one >> 1)) / fix16_one;
|
||||
return (a - (fix16_one >> 1)) / fix16_one;
|
||||
}
|
||||
|
||||
fix16_t fix16_from_dbl(double a) {
|
||||
double temp = a * fix16_one;
|
||||
temp += (double)((temp >= 0) ? 0.5f : -0.5f);
|
||||
return (fix16_t)temp;
|
||||
}
|
||||
|
||||
double fix16_to_dbl(fix16_t a) {
|
||||
return (double)a / fix16_one;
|
||||
}
|
||||
|
||||
// hic sunt dracones
|
||||
fix16_t fix16_mul(fix16_t inArg0, fix16_t inArg1) {
|
||||
int64_t product = (int64_t)inArg0 * inArg1;
|
||||
|
||||
uint32_t upper = (product >> 47);
|
||||
if (product < 0) {
|
||||
if (~upper)
|
||||
return fix16_overflow;
|
||||
product--;
|
||||
} else {
|
||||
if (upper)
|
||||
return fix16_overflow;
|
||||
}
|
||||
|
||||
fix16_t result = product >> 15;
|
||||
result += (product & 0x4000) >> 14;
|
||||
|
||||
return result;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* Ben Brewer, a.k.a. flatmush
|
||||
* for his exceptional work on libfixmath, on which this is based.
|
||||
*/
|
||||
|
||||
#ifndef FIX16_H
|
||||
#define FIX16_H
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef int32_t fix16_t;
|
||||
|
||||
static const fix16_t fix16_overflow = 0x80000000;
|
||||
static const fix16_t fix16_one = 0x00008000;
|
||||
|
||||
fix16_t fix16_from_int(int16_t);
|
||||
int16_t fix16_to_int(fix16_t);
|
||||
fix16_t fix16_from_dbl(double);
|
||||
double fix16_to_dbl(fix16_t);
|
||||
|
||||
fix16_t fix16_mul(fix16_t, fix16_t);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,204 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* @miketeachman (github.com/miketeachman)
|
||||
* @jimmo (github.com/jimmo)
|
||||
* @dlech (github.com/dlech)
|
||||
* for their exceptional work on the I2S library for the rp2 port of the
|
||||
* Micropython project (github.com/micropython/micropython).
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#include "hardware/pio.h"
|
||||
#include "hardware/clocks.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/dma.h"
|
||||
#include "hardware/irq.h"
|
||||
|
||||
#include "ringbuf.h"
|
||||
#include "i2s.h"
|
||||
#include "i2s.pio.h"
|
||||
|
||||
void i2s_write_init(i2s_obj_t *self) {
|
||||
self->pio = pio1;
|
||||
self->pio_program = &i2s_write_program;
|
||||
self->sm = pio_claim_unused_sm(self->pio, true);
|
||||
self->prog_offset = pio_add_program(self->pio, self->pio_program);
|
||||
pio_sm_init(self->pio, self->sm, self->prog_offset, NULL);
|
||||
|
||||
pio_sm_config config = pio_get_default_sm_config();
|
||||
|
||||
float pio_freq = self->sampling_rate * SAMPLES_PER_FRAME * 32 *
|
||||
PIO_INSTRUCTIONS_PER_BIT;
|
||||
|
||||
float clkdiv = clock_get_hz(clk_sys) / pio_freq;
|
||||
|
||||
sm_config_set_clkdiv(&config, clkdiv);
|
||||
|
||||
sm_config_set_out_pins(&config, self->sd_pin, 1);
|
||||
sm_config_set_out_shift(&config, false, true, 32);
|
||||
sm_config_set_fifo_join(&config, PIO_FIFO_JOIN_TX); // double TX FIFO size
|
||||
|
||||
sm_config_set_sideset(&config, 2, false, false);
|
||||
sm_config_set_sideset_pins(&config, self->sck_pin);
|
||||
sm_config_set_wrap(&config, self->prog_offset,
|
||||
self->prog_offset + self->pio_program->length - 1);
|
||||
pio_sm_set_config(self->pio, self->sm, &config);
|
||||
|
||||
uint8_t *rbs = malloc(sizeof(uint8_t) * RINGBUF_LEN_IN_BYTES);
|
||||
ringbuf_init(&self->ring_buffer, rbs, RINGBUF_LEN_IN_BYTES);
|
||||
|
||||
irq_set_exclusive_handler(DMA_IRQ_1, dma_irq_write_handler);
|
||||
irq_set_enabled(DMA_IRQ_1, true);
|
||||
|
||||
gpio_init_i2s(self->pio, self->sm, self->sck_pin, 0, GP_OUTPUT);
|
||||
gpio_init_i2s(self->pio, self->sm, self->ws_pin, 0, GP_OUTPUT);
|
||||
gpio_init_i2s(self->pio, self->sm, self->sd_pin, 0, GP_OUTPUT);
|
||||
|
||||
dma_configure(self);
|
||||
|
||||
pio_sm_set_enabled(self->pio, self->sm, true);
|
||||
dma_channel_start(self->dma_channel[0]);
|
||||
}
|
||||
|
||||
void gpio_init_i2s(PIO pio, uint8_t sm, uint pin_num, uint8_t pin_val, gpio_dir_t pin_dir) {
|
||||
uint32_t pinmask = 1 << pin_num;
|
||||
pio_sm_set_pins_with_mask(pio, sm, pin_val << pin_num, pinmask);
|
||||
pio_sm_set_pindirs_with_mask(pio, sm, pin_dir << pin_num, pinmask);
|
||||
pio_gpio_init(pio, pin_num);
|
||||
}
|
||||
|
||||
void dma_irq_write_handler() {
|
||||
i2s_obj_t *self = &i2s_write_obj;
|
||||
|
||||
uint dma_channel;
|
||||
if (dma_irqn_get_channel_status(1, self->dma_channel[0]))
|
||||
dma_channel = self->dma_channel[0];
|
||||
else if (dma_irqn_get_channel_status(1, self->dma_channel[1]))
|
||||
dma_channel = self->dma_channel[1];
|
||||
else {
|
||||
//printf("ERROR write: dma_channel not found");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uint8_t *dma_buffer = dma_get_buffer(self, dma_channel);
|
||||
if (dma_buffer == NULL) {
|
||||
//printf("ERROR write: dma_buffer not found\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
feed_dma(self, dma_buffer);
|
||||
dma_irqn_acknowledge_channel(1, dma_channel);
|
||||
dma_channel_set_read_addr(dma_channel, dma_buffer, false);
|
||||
}
|
||||
|
||||
void dma_configure(i2s_obj_t *self) {
|
||||
uint8_t num_free_dma_channels = 0;
|
||||
for (uint8_t ch = 0; ch < NUM_DMA_CHANNELS; ch++) {
|
||||
if (!dma_channel_is_claimed(ch)) {
|
||||
num_free_dma_channels++;
|
||||
}
|
||||
}
|
||||
if (num_free_dma_channels < I2S_NUM_DMA_CHANNELS) {
|
||||
//printf("ERROR: cannot claim 2 DMA channels");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (uint8_t ch = 0; ch < I2S_NUM_DMA_CHANNELS; ch++) {
|
||||
self->dma_channel[ch] = dma_claim_unused_channel(true);
|
||||
}
|
||||
|
||||
// The DMA channels are chained together. The first DMA channel is used to access
|
||||
// the top half of the DMA buffer. The second DMA channel accesses the bottom half of the DMA buffer.
|
||||
// With chaining, when one DMA channel has completed a data transfer, the other
|
||||
// DMA channel automatically starts a new data transfer.
|
||||
enum dma_channel_transfer_size dma_size = DMA_SIZE_32;
|
||||
for (uint8_t ch = 0; ch < I2S_NUM_DMA_CHANNELS; ch++) {
|
||||
dma_channel_config dma_config = dma_channel_get_default_config(self->dma_channel[ch]);
|
||||
channel_config_set_transfer_data_size(&dma_config, dma_size);
|
||||
channel_config_set_chain_to(&dma_config, self->dma_channel[(ch + 1) % I2S_NUM_DMA_CHANNELS]);
|
||||
|
||||
uint8_t *dma_buffer = self->dma_buffer + (SIZEOF_HALF_DMA_BUFFER_IN_BYTES * ch);
|
||||
channel_config_set_dreq(&dma_config, pio_get_dreq(self->pio, self->sm, true));
|
||||
channel_config_set_read_increment(&dma_config, true);
|
||||
channel_config_set_write_increment(&dma_config, false);
|
||||
dma_channel_configure(self->dma_channel[ch],
|
||||
&dma_config,
|
||||
(void *)&self->pio->txf[self->sm], // dest = PIO TX FIFO
|
||||
dma_buffer, // src = DMA buffer
|
||||
SIZEOF_HALF_DMA_BUFFER_IN_BYTES / (32 / 8),
|
||||
false);
|
||||
}
|
||||
|
||||
for (uint8_t ch = 0; ch < I2S_NUM_DMA_CHANNELS; ch++) {
|
||||
dma_irqn_acknowledge_channel(1, self->dma_channel[ch]); // clear pending. e.g. from SPI
|
||||
dma_irqn_set_channel_enabled(1, self->dma_channel[ch], true);
|
||||
}
|
||||
}
|
||||
|
||||
// note: first DMA channel is mapped to the top half of buffer, second is mapped to the bottom half
|
||||
uint8_t *dma_get_buffer(i2s_obj_t *i2s_obj, uint channel) {
|
||||
for (uint8_t ch = 0; ch < I2S_NUM_DMA_CHANNELS; ch++) {
|
||||
if (i2s_obj->dma_channel[ch] == channel) {
|
||||
return i2s_obj->dma_buffer + (SIZEOF_HALF_DMA_BUFFER_IN_BYTES * ch);
|
||||
}
|
||||
}
|
||||
// This should never happen
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void feed_dma(i2s_obj_t *self, uint8_t *dma_buffer_p) {
|
||||
// when data exists, copy samples from ring buffer
|
||||
if (ringbuf_available_data(&self->ring_buffer) >= SIZEOF_HALF_DMA_BUFFER_IN_BYTES) {
|
||||
for (uint32_t i = 0; i < SIZEOF_HALF_DMA_BUFFER_IN_BYTES; i++)
|
||||
ringbuf_pop(&self->ring_buffer, &dma_buffer_p[i]);
|
||||
} else {
|
||||
// underflow. clear buffer to transmit "silence" on the I2S bus
|
||||
memset(dma_buffer_p, 0, SIZEOF_HALF_DMA_BUFFER_IN_BYTES);
|
||||
}
|
||||
}
|
||||
|
||||
uint i2s_stream_write(i2s_obj_t *self, const uint8_t *buf_out, uint size) {
|
||||
if (size == 0) {
|
||||
//printf("ERROR: buffer can't be length zero");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uint32_t num_bytes_written = copy_userbuf_to_ringbuf(self, buf_out, size);
|
||||
return num_bytes_written;
|
||||
}
|
||||
|
||||
// TODO maybe we can skip every fourth byte, if we're doing this in 24-bit...
|
||||
// could save on some processing power
|
||||
uint32_t copy_userbuf_to_ringbuf(i2s_obj_t *self, const uint8_t *buf_out, uint size) {
|
||||
uint32_t a_index = 0;
|
||||
|
||||
while (a_index < size) {
|
||||
// copy a byte to the ringbuf when space becomes available
|
||||
while (ringbuf_push(&self->ring_buffer, buf_out[a_index]) == false) {
|
||||
;
|
||||
}
|
||||
a_index++;
|
||||
}
|
||||
|
||||
return a_index;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* @miketeachman (github.com/miketeachman)
|
||||
* @jimmo (github.com/jimmo)
|
||||
* @dlech (github.com/dlech)
|
||||
* for their exceptional work on the I2S library for the rp2 port of the
|
||||
* Micropython project (github.com/micropython/micropython).
|
||||
*/
|
||||
|
||||
#ifndef I2S_H
|
||||
#define I2S_H
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/pio.h"
|
||||
#include "ringbuf.h"
|
||||
|
||||
#define SAMPLES_PER_FRAME 2
|
||||
#define PIO_INSTRUCTIONS_PER_BIT 2
|
||||
#define RINGBUF_LEN_IN_BYTES 16384
|
||||
#define I2S_NUM_DMA_CHANNELS 2
|
||||
|
||||
#define SIZEOF_DMA_BUFFER_IN_BYTES 768
|
||||
#define SIZEOF_HALF_DMA_BUFFER_IN_BYTES (SIZEOF_DMA_BUFFER_IN_BYTES / 2)
|
||||
|
||||
typedef enum {
|
||||
GP_INPUT = 0,
|
||||
GP_OUTPUT = 1
|
||||
} gpio_dir_t;
|
||||
|
||||
typedef struct _i2s_obj_t {
|
||||
uint sck_pin;
|
||||
uint ws_pin;
|
||||
uint sd_pin;
|
||||
PIO pio;
|
||||
uint8_t sm;
|
||||
float sampling_rate;
|
||||
const pio_program_t *pio_program;
|
||||
uint prog_offset;
|
||||
int dma_channel[I2S_NUM_DMA_CHANNELS];
|
||||
uint8_t dma_buffer[SIZEOF_DMA_BUFFER_IN_BYTES];
|
||||
ring_buf_t ring_buffer;
|
||||
} i2s_obj_t;
|
||||
|
||||
extern i2s_obj_t i2s_write_obj;
|
||||
|
||||
void i2s_write_init(i2s_obj_t *);
|
||||
uint i2s_stream_write(i2s_obj_t *, const uint8_t *, uint);
|
||||
|
||||
void dma_irq_handler(uint8_t);
|
||||
void dma_irq_write_handler(void);
|
||||
void gpio_init_i2s(PIO, uint8_t, uint, uint8_t, gpio_dir_t);
|
||||
void dma_configure(i2s_obj_t *);
|
||||
uint8_t *dma_get_buffer(i2s_obj_t *, uint);
|
||||
void feed_dma(i2s_obj_t *, uint8_t *);
|
||||
|
||||
uint32_t copy_userbuf_to_ringbuf(i2s_obj_t *, const uint8_t *, uint);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
; Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program 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 General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
.program i2s_read
|
||||
.side_set 2
|
||||
|
||||
set x, 30 side 0b00
|
||||
|
||||
left_channel:
|
||||
in pins, 1 side 0b01
|
||||
jmp x-- left_channel side 0b00
|
||||
in pins, 1 side 0b11
|
||||
|
||||
set x, 30 side 0b10
|
||||
|
||||
right_channel:
|
||||
in pins, 1 side 0b11
|
||||
jmp x--, right_channel side 0b10
|
||||
in pins, 1 side 0b01
|
||||
|
||||
|
||||
.program i2s_write
|
||||
.side_set 2
|
||||
|
||||
set x, 30 side 0b01
|
||||
|
||||
left_channel:
|
||||
out pins, 1 side 0b00
|
||||
jmp x-- left_channel side 0b01
|
||||
out pins, 1 side 0b10
|
||||
|
||||
set x, 30 side 0b11
|
||||
|
||||
right_channel:
|
||||
out pins, 1 side 0b10
|
||||
jmp x--, right_channel side 0b11
|
||||
out pins, 1 side 0b00
|
|
@ -0,0 +1,62 @@
|
|||
# This is a copy of <PICO_EXTRAS_PATH>/external/pico_extras_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate pico-extras
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_EXTRAS_PATH} AND (NOT PICO_EXTRAS_PATH))
|
||||
set(PICO_EXTRAS_PATH $ENV{PICO_EXTRAS_PATH})
|
||||
message("Using PICO_EXTRAS_PATH from environment ('${PICO_EXTRAS_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_EXTRAS_FETCH_FROM_GIT} AND (NOT PICO_EXTRAS_FETCH_FROM_GIT))
|
||||
set(PICO_EXTRAS_FETCH_FROM_GIT $ENV{PICO_EXTRAS_FETCH_FROM_GIT})
|
||||
message("Using PICO_EXTRAS_FETCH_FROM_GIT from environment ('${PICO_EXTRAS_FETCH_FROM_GIT}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_EXTRAS_FETCH_FROM_GIT_PATH} AND (NOT PICO_EXTRAS_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_EXTRAS_FETCH_FROM_GIT_PATH $ENV{PICO_EXTRAS_FETCH_FROM_GIT_PATH})
|
||||
message("Using PICO_EXTRAS_FETCH_FROM_GIT_PATH from environment ('${PICO_EXTRAS_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (NOT PICO_EXTRAS_PATH)
|
||||
if (PICO_EXTRAS_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
if (PICO_EXTRAS_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
FetchContent_Declare(
|
||||
pico_extras
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-extras
|
||||
GIT_TAG master
|
||||
)
|
||||
if (NOT pico_extras)
|
||||
message("Downloading Raspberry Pi Pico Extras")
|
||||
FetchContent_Populate(pico_extras)
|
||||
set(PICO_EXTRAS_PATH ${pico_extras_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
if (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../pico-extras")
|
||||
set(PICO_EXTRAS_PATH ${PICO_SDK_PATH}/../pico-extras)
|
||||
message("Defaulting PICO_EXTRAS_PATH as sibling of PICO_SDK_PATH: ${PICO_EXTRAS_PATH}")
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
"PICO EXTRAS location was not specified. Please set PICO_EXTRAS_PATH or set PICO_EXTRAS_FETCH_FROM_GIT to on to fetch from git."
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
set(PICO_EXTRAS_PATH "${PICO_EXTRAS_PATH}" CACHE PATH "Path to the PICO EXTRAS")
|
||||
set(PICO_EXTRAS_FETCH_FROM_GIT "${PICO_EXTRAS_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of PICO EXTRAS from git if not otherwise locatable")
|
||||
set(PICO_EXTRAS_FETCH_FROM_GIT_PATH "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download EXTRAS")
|
||||
|
||||
get_filename_component(PICO_EXTRAS_PATH "${PICO_EXTRAS_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_EXTRAS_PATH})
|
||||
message(FATAL_ERROR "Directory '${PICO_EXTRAS_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_PATH} CACHE PATH "Path to the PICO EXTRAS" FORCE)
|
||||
|
||||
add_subdirectory(${PICO_EXTRAS_PATH} pico_extras)
|
|
@ -0,0 +1,73 @@
|
|||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
|
||||
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
GIT_SUBMODULES_RECURSE FALSE
|
||||
)
|
||||
else ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_SDK_PATH})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
|
||||
include(${PICO_SDK_INIT_CMAKE_FILE})
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* @miketeachman (github.com/miketeachman)
|
||||
* @jimmo (github.com/jimmo)
|
||||
* @dlech (github.com/dlech)
|
||||
* for their exceptional work on the I2S library for the rp2 port of the
|
||||
* Micropython project (github.com/micropython/micropython).
|
||||
*/
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "ringbuf.h"
|
||||
|
||||
// TODO can this be sped up by using uint32_t instead of uint8_t?
|
||||
|
||||
// Ring Buffer
|
||||
// Thread safe when used with these constraints:
|
||||
// - Single Producer, Single Consumer
|
||||
// - Sequential atomic operations
|
||||
// One byte of capacity is used to detect buffer empty/full
|
||||
|
||||
void ringbuf_init(ring_buf_t *rbuf, uint8_t *buffer, size_t size) {
|
||||
rbuf->buffer = buffer;
|
||||
rbuf->size = size;
|
||||
rbuf->head = 0;
|
||||
rbuf->tail = 0;
|
||||
}
|
||||
|
||||
bool ringbuf_push(ring_buf_t *rbuf, uint8_t data) {
|
||||
size_t next_tail = (rbuf->tail + 1) % rbuf->size;
|
||||
|
||||
if (next_tail != rbuf->head) {
|
||||
rbuf->buffer[rbuf->tail] = data;
|
||||
rbuf->tail = next_tail;
|
||||
return true;
|
||||
}
|
||||
|
||||
// full
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ringbuf_pop(ring_buf_t *rbuf, uint8_t *data) {
|
||||
if (rbuf->head == rbuf->tail) {
|
||||
// empty
|
||||
return false;
|
||||
}
|
||||
|
||||
*data = rbuf->buffer[rbuf->head];
|
||||
rbuf->head = (rbuf->head + 1) % rbuf->size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ringbuf_is_empty(ring_buf_t *rbuf) {
|
||||
return rbuf->head == rbuf->tail;
|
||||
}
|
||||
|
||||
bool ringbuf_is_full(ring_buf_t *rbuf) {
|
||||
return ((rbuf->tail + 1) % rbuf->size) == rbuf->head;
|
||||
}
|
||||
|
||||
size_t ringbuf_available_data(ring_buf_t *rbuf) {
|
||||
return (rbuf->tail - rbuf->head + rbuf->size) % rbuf->size;
|
||||
}
|
||||
|
||||
size_t ringbuf_available_space(ring_buf_t *rbuf) {
|
||||
return rbuf->size - ringbuf_available_data(rbuf) - 1;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* @miketeachman (github.com/miketeachman)
|
||||
* @jimmo (github.com/jimmo)
|
||||
* @dlech (github.com/dlech)
|
||||
* for their exceptional work on the I2S library for the rp2 port of the
|
||||
* Micropython project (github.com/micropython/micropython).
|
||||
*/
|
||||
|
||||
#ifndef RINGBUF_H
|
||||
#define RINGBUF_H
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
typedef struct _ring_buf_t {
|
||||
uint8_t *buffer;
|
||||
size_t head;
|
||||
size_t tail;
|
||||
size_t size;
|
||||
} ring_buf_t;
|
||||
|
||||
void ringbuf_init(ring_buf_t *, uint8_t *, size_t);
|
||||
bool ringbuf_push(ring_buf_t *, uint8_t );
|
||||
bool ringbuf_pop(ring_buf_t *, uint8_t *);
|
||||
bool ringbuf_is_empty(ring_buf_t *);
|
||||
bool ringbuf_is_full(ring_buf_t *);
|
||||
size_t ringbuf_available_data(ring_buf_t *);
|
||||
size_t ringbuf_available_space(ring_buf_t *);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,737 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* @kilograham (github.com/kilograham)
|
||||
* for his exceptional work on Pico Playground's usb-sound-card, on which
|
||||
* a large portion of this work is based.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "hardware/vreg.h"
|
||||
#include "hardware/pwm.h"
|
||||
#include "hardware/i2c.h"
|
||||
#include "hardware/sync.h"
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/usb_device.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "AudioClassCommon.h"
|
||||
|
||||
#include "run.h"
|
||||
#include "ringbuf.h"
|
||||
#include "i2s.h"
|
||||
#include "bqf.h"
|
||||
#include "user.h"
|
||||
|
||||
i2s_obj_t i2s_write_obj;
|
||||
static uint8_t *userbuf;
|
||||
|
||||
bqf_coeff_t bqf_filters_left[FILTER_STAGES];
|
||||
bqf_coeff_t bqf_filters_right[FILTER_STAGES];
|
||||
bqf_mem_t bqf_filters_mem_left[FILTER_STAGES];
|
||||
bqf_mem_t bqf_filters_mem_right[FILTER_STAGES];
|
||||
|
||||
static struct {
|
||||
uint32_t freq;
|
||||
int16_t volume;
|
||||
int16_t vol_mul;
|
||||
bool mute;
|
||||
} audio_state = {
|
||||
.freq = 48000,
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
setup();
|
||||
|
||||
define_filters();
|
||||
|
||||
// start second core (called "core 1" in the SDK)
|
||||
multicore_launch_core1(core1_entry);
|
||||
multicore_fifo_push_blocking((uintptr_t) userbuf);
|
||||
uint32_t ready = multicore_fifo_pop_blocking();
|
||||
if (ready != CORE1_READY) {
|
||||
//printf("core 1 startup sequence is hella borked")
|
||||
exit(1);
|
||||
}
|
||||
|
||||
usb_sound_card_init();
|
||||
|
||||
while (true)
|
||||
__wfi();
|
||||
}
|
||||
|
||||
// Here's the meat. It's where the data buffer from USB gets transformed from
|
||||
// PCM data into I2S data that gets shipped out to the PCM3060. It really
|
||||
// belongs with the other USB-related code due to its utter indecipherability,
|
||||
// but it's placed here to emphasize its importance.
|
||||
static void _as_audio_packet(struct usb_endpoint *ep) {
|
||||
struct usb_buffer *usb_buffer = usb_current_out_packet_buffer(ep);
|
||||
int16_t *in = (int16_t *) usb_buffer->data;
|
||||
int32_t *out = (int32_t *) userbuf;
|
||||
uint16_t vol_mul = audio_state.vol_mul;
|
||||
int samples = usb_buffer->data_len / 2;
|
||||
|
||||
for (int i = 0; i < samples; i++)
|
||||
out[i] = in[i] / 2; // fixes digital distortion bug
|
||||
|
||||
multicore_fifo_push_blocking(CORE0_READY);
|
||||
multicore_fifo_push_blocking(samples);
|
||||
|
||||
for (int j = 0; j < FILTER_STAGES; j++) {
|
||||
// Left channel filter
|
||||
for (int i = 0; i < samples; i += 2) {
|
||||
fix16_t x_f16 = fix16_from_int((int16_t) out[i]);
|
||||
|
||||
x_f16 = bqf_transform(x_f16, &bqf_filters_left[j],
|
||||
&bqf_filters_mem_left[j]);
|
||||
|
||||
out[i] = (int32_t) fix16_to_int(x_f16);
|
||||
}
|
||||
}
|
||||
|
||||
// Block until core 1 has finished transforming the data
|
||||
uint32_t ready = multicore_fifo_pop_blocking();
|
||||
|
||||
// Multiply the outgoing signal with the volume multiple
|
||||
for (int i = 0; i < samples; i++)
|
||||
out[i] = out[i] * (int32_t) vol_mul * 4;
|
||||
|
||||
i2s_stream_write(&i2s_write_obj, userbuf, samples * 4);
|
||||
|
||||
// keep on truckin'
|
||||
usb_grow_transfer(ep->current_transfer, 1);
|
||||
usb_packet_done(ep);
|
||||
}
|
||||
|
||||
void core1_entry() {
|
||||
uint8_t *userbuf = (uint8_t *) multicore_fifo_pop_blocking();
|
||||
int32_t *out = (int32_t *) userbuf;
|
||||
|
||||
multicore_fifo_push_blocking(CORE1_READY);
|
||||
|
||||
while (true) {
|
||||
// Block until the userbuf is filled with data
|
||||
uint32_t ready = multicore_fifo_pop_blocking();
|
||||
while (ready != CORE0_READY)
|
||||
ready = multicore_fifo_pop_blocking();
|
||||
|
||||
uint32_t limit = multicore_fifo_pop_blocking();
|
||||
|
||||
for (int j = 0; j < FILTER_STAGES; j++) {
|
||||
for (int i = 1; i < limit; i += 2) {
|
||||
fix16_t x_f16 = fix16_from_int((int16_t) out[i]);
|
||||
|
||||
x_f16 = bqf_transform(x_f16, &bqf_filters_right[j],
|
||||
&bqf_filters_mem_right[j]);
|
||||
|
||||
out[i] = (int16_t) fix16_to_int(x_f16);
|
||||
}
|
||||
}
|
||||
|
||||
// Signal to core 0 that the data has all been transformed
|
||||
multicore_fifo_push_blocking(CORE1_READY);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
set_sys_clock_khz(SYSTEM_FREQ / 1000, true);
|
||||
sleep_ms(100);
|
||||
|
||||
userbuf = malloc(sizeof(uint8_t) * RINGBUF_LEN_IN_BYTES);
|
||||
|
||||
// Configure DAC PWM
|
||||
gpio_set_function(PCM3060_SCKI2_PIN, GPIO_FUNC_PWM);
|
||||
uint slice_num_dac = pwm_gpio_to_slice_num(PCM3060_SCKI2_PIN);
|
||||
uint chan_num_dac = pwm_gpio_to_channel(PCM3060_SCKI2_PIN);
|
||||
pwm_set_phase_correct(slice_num_dac, false);
|
||||
pwm_set_wrap(slice_num_dac, (SYSTEM_FREQ / CODEC_FREQ) - 1);
|
||||
pwm_set_chan_level(slice_num_dac, chan_num_dac, (SYSTEM_FREQ / CODEC_FREQ / 2));
|
||||
pwm_set_enabled(slice_num_dac, true);
|
||||
|
||||
gpio_init(AUDIO_POS_SUPPLY_EN_PIN);
|
||||
gpio_set_dir(AUDIO_POS_SUPPLY_EN_PIN, GPIO_OUT);
|
||||
gpio_put(AUDIO_POS_SUPPLY_EN_PIN, true);
|
||||
|
||||
sleep_ms(100);
|
||||
|
||||
configure_neg_switch_pwm();
|
||||
|
||||
// After negative switching PWM is configured, take the PCM out of reset
|
||||
gpio_init(PCM3060_RST_PIN);
|
||||
gpio_set_dir(PCM3060_RST_PIN, GPIO_OUT);
|
||||
gpio_put(PCM3060_RST_PIN, true);
|
||||
|
||||
i2c_init(i2c0, 50000);
|
||||
gpio_set_function(PCM3060_SDA_PIN, GPIO_FUNC_I2C);
|
||||
gpio_set_function(PCM3060_SCL_PIN, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(PCM3060_SDA_PIN);
|
||||
gpio_pull_up(PCM3060_SCL_PIN);
|
||||
|
||||
// Let the PCM stabilize before power-on
|
||||
sleep_ms(200);
|
||||
|
||||
// Resynchronise clocks. Do not enable PCM yet.
|
||||
uint8_t buf[2];
|
||||
buf[0] = 64; // register addr
|
||||
buf[1] = 0xB0; // data
|
||||
i2c_write_blocking(i2c0, PCM_I2C_ADDR, buf, 2, false);
|
||||
|
||||
// Don't remove this. Don't do it.
|
||||
sleep_ms(200);
|
||||
|
||||
// Enable DAC
|
||||
buf[0] = 64; // register addr
|
||||
buf[1] = 0xE0; // data
|
||||
i2c_write_blocking(i2c0, PCM_I2C_ADDR, buf, 2, false);
|
||||
|
||||
// Same here, pal. Hands off.
|
||||
sleep_ms(100);
|
||||
|
||||
i2s_write_obj.sck_pin = PCM3060_DAC_SCK_PIN;
|
||||
i2s_write_obj.ws_pin = PCM3060_DAC_WS_PIN;
|
||||
i2s_write_obj.sd_pin = PCM3060_DAC_SD_PIN;
|
||||
i2s_write_obj.sampling_rate = SAMPLING_FREQ;
|
||||
|
||||
i2s_write_init(&i2s_write_obj);
|
||||
}
|
||||
|
||||
/** **************************************************************************
|
||||
* DO. NOT. FUCKING. CHANGE. THIS. FUNCTION. *
|
||||
* IF YOU DO, YOU COULD BLOW UP YOUR HARDWARE! *
|
||||
* YOU WERE WARNED!!!!!!!!!!!!!!!! *
|
||||
****************************************************************************/
|
||||
void configure_neg_switch_pwm() {
|
||||
gpio_set_function(NEG_SWITCH_PWM_PIN, GPIO_FUNC_PWM);
|
||||
uint slice_num = pwm_gpio_to_slice_num(NEG_SWITCH_PWM_PIN);
|
||||
uint chan_num = pwm_gpio_to_channel(NEG_SWITCH_PWM_PIN);
|
||||
pwm_set_phase_correct(slice_num, false);
|
||||
|
||||
uint16_t wrap = round((float) SYSTEM_FREQ / (float) NEG_SWITCH_FREQ);
|
||||
pwm_set_wrap(slice_num, wrap - 1);
|
||||
|
||||
uint16_t target_level = round((float) SYSTEM_FREQ / (float) NEG_SWITCH_FREQ /
|
||||
(float) NEG_DUTY_DEN * (float) NEG_DUTY_NUM);
|
||||
pwm_set_chan_level(slice_num, chan_num, 0);
|
||||
pwm_set_enabled(slice_num, true);
|
||||
sleep_ms(10);
|
||||
|
||||
// Ramp up the duty cycle.
|
||||
// Seriously, don't fuck with this. A spike on the negative voltage supply
|
||||
// because this isn't ramping correctly will destroy the hardware.
|
||||
size_t i;
|
||||
for(i = 0; i < 200; i++) {
|
||||
uint16_t current_level = round(i * ((float)target_level / 200.0));
|
||||
pwm_set_chan_level(slice_num, chan_num, current_level);
|
||||
sleep_ms(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* USB-related code begins here. It's a refactoring nightmare, so here it
|
||||
* shall lie for a thousand years.
|
||||
****************************************************************************/
|
||||
|
||||
// todo noop when muted
|
||||
|
||||
static const audio_device_config ad_conf = {
|
||||
.descriptor = {
|
||||
.bLength = sizeof(ad_conf.descriptor),
|
||||
.bDescriptorType = DTYPE_Configuration,
|
||||
.wTotalLength = sizeof(ad_conf),
|
||||
.bNumInterfaces = 2,
|
||||
.bConfigurationValue = 0x01,
|
||||
.iConfiguration = 0x00,
|
||||
.bmAttributes = 0x80,
|
||||
.bMaxPower = 0xFA,
|
||||
},
|
||||
.ac_interface = {
|
||||
.bLength = sizeof(ad_conf.ac_interface),
|
||||
.bDescriptorType = DTYPE_Interface,
|
||||
.bInterfaceNumber = 0x00,
|
||||
.bAlternateSetting = 0x00,
|
||||
.bNumEndpoints = 0x00,
|
||||
.bInterfaceClass = AUDIO_CSCP_AudioClass,
|
||||
.bInterfaceSubClass = AUDIO_CSCP_ControlSubclass,
|
||||
.bInterfaceProtocol = AUDIO_CSCP_ControlProtocol,
|
||||
.iInterface = 0x00,
|
||||
},
|
||||
.ac_audio = {
|
||||
.core = {
|
||||
.bLength = sizeof(ad_conf.ac_audio.core),
|
||||
.bDescriptorType = AUDIO_DTYPE_CSInterface,
|
||||
.bDescriptorSubtype = AUDIO_DSUBTYPE_CSInterface_Header,
|
||||
.bcdADC = VERSION_BCD(1, 0, 0),
|
||||
.wTotalLength = sizeof(ad_conf.ac_audio),
|
||||
.bInCollection = 1,
|
||||
.bInterfaceNumbers = 1,
|
||||
},
|
||||
.input_terminal = {
|
||||
.bLength = sizeof(ad_conf.ac_audio.input_terminal),
|
||||
.bDescriptorType = AUDIO_DTYPE_CSInterface,
|
||||
.bDescriptorSubtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
|
||||
.bTerminalID = 1,
|
||||
.wTerminalType = AUDIO_TERMINAL_STREAMING,
|
||||
.bAssocTerminal = 0,
|
||||
.bNrChannels = 2,
|
||||
.wChannelConfig = AUDIO_CHANNEL_LEFT_FRONT | AUDIO_CHANNEL_RIGHT_FRONT,
|
||||
.iChannelNames = 0,
|
||||
.iTerminal = 0,
|
||||
},
|
||||
.feature_unit = {
|
||||
.bLength = sizeof(ad_conf.ac_audio.feature_unit),
|
||||
.bDescriptorType = AUDIO_DTYPE_CSInterface,
|
||||
.bDescriptorSubtype = AUDIO_DSUBTYPE_CSInterface_Feature,
|
||||
.bUnitID = 2,
|
||||
.bSourceID = 1,
|
||||
.bControlSize = 1,
|
||||
.bmaControls = {
|
||||
AUDIO_FEATURE_MUTE | AUDIO_FEATURE_VOLUME,
|
||||
0,
|
||||
0
|
||||
},
|
||||
.iFeature = 0,
|
||||
},
|
||||
.output_terminal = {
|
||||
.bLength = sizeof(ad_conf.ac_audio.output_terminal),
|
||||
.bDescriptorType = AUDIO_DTYPE_CSInterface,
|
||||
.bDescriptorSubtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
|
||||
.bTerminalID = 3,
|
||||
.wTerminalType = AUDIO_TERMINAL_OUT_HEADPHONES,
|
||||
.bAssocTerminal = 0,
|
||||
.bSourceID = 2,
|
||||
.iTerminal = 0,
|
||||
},
|
||||
},
|
||||
.as_zero_interface = {
|
||||
.bLength = sizeof(ad_conf.as_zero_interface),
|
||||
.bDescriptorType = DTYPE_Interface,
|
||||
.bInterfaceNumber = 0x01,
|
||||
.bAlternateSetting = 0x00,
|
||||
.bNumEndpoints = 0x00,
|
||||
.bInterfaceClass = AUDIO_CSCP_AudioClass,
|
||||
.bInterfaceSubClass = AUDIO_CSCP_AudioStreamingSubclass,
|
||||
.bInterfaceProtocol = AUDIO_CSCP_ControlProtocol,
|
||||
.iInterface = 0x00,
|
||||
},
|
||||
.as_op_interface = {
|
||||
.bLength = sizeof(ad_conf.as_op_interface),
|
||||
.bDescriptorType = DTYPE_Interface,
|
||||
.bInterfaceNumber = 0x01,
|
||||
.bAlternateSetting = 0x01,
|
||||
.bNumEndpoints = 0x02,
|
||||
.bInterfaceClass = AUDIO_CSCP_AudioClass,
|
||||
.bInterfaceSubClass = AUDIO_CSCP_AudioStreamingSubclass,
|
||||
.bInterfaceProtocol = AUDIO_CSCP_ControlProtocol,
|
||||
.iInterface = 0x00,
|
||||
},
|
||||
.as_audio = {
|
||||
.streaming = {
|
||||
.bLength = sizeof(ad_conf.as_audio.streaming),
|
||||
.bDescriptorType = AUDIO_DTYPE_CSInterface,
|
||||
.bDescriptorSubtype = AUDIO_DSUBTYPE_CSInterface_General,
|
||||
.bTerminalLink = 1,
|
||||
.bDelay = 1,
|
||||
.wFormatTag = 1, // PCM
|
||||
},
|
||||
.format = {
|
||||
.core = {
|
||||
.bLength = sizeof(ad_conf.as_audio.format),
|
||||
.bDescriptorType = AUDIO_DTYPE_CSInterface,
|
||||
.bDescriptorSubtype = AUDIO_DSUBTYPE_CSInterface_FormatType,
|
||||
.bFormatType = 1,
|
||||
.bNrChannels = 2,
|
||||
.bSubFrameSize = 2,
|
||||
.bBitResolution = 16,
|
||||
.bSampleFrequencyType = 1,
|
||||
},
|
||||
.freqs = {
|
||||
0x80,
|
||||
0xBB,
|
||||
0x00
|
||||
},
|
||||
},
|
||||
},
|
||||
.ep1 = {
|
||||
.core = {
|
||||
.bLength = sizeof(ad_conf.ep1.core),
|
||||
.bDescriptorType = DTYPE_Endpoint,
|
||||
.bEndpointAddress = 0x01,
|
||||
.bmAttributes = 5,
|
||||
.wMaxPacketSize = (uint8_t) 0xC4,
|
||||
.bInterval = 1,
|
||||
.bRefresh = 0,
|
||||
.bSyncAddr = 0x82,
|
||||
},
|
||||
.audio = {
|
||||
.bLength = sizeof(ad_conf.ep1.audio),
|
||||
.bDescriptorType = AUDIO_DTYPE_CSEndpoint,
|
||||
.bDescriptorSubtype = AUDIO_DSUBTYPE_CSEndpoint_General,
|
||||
.bmAttributes = 1,
|
||||
.bLockDelayUnits = 0,
|
||||
.wLockDelay = 0,
|
||||
}
|
||||
},
|
||||
.ep2 = {
|
||||
.bLength = sizeof(ad_conf.ep2),
|
||||
.bDescriptorType = 0x05,
|
||||
.bEndpointAddress = 0x82,
|
||||
.bmAttributes = 0x11,
|
||||
.wMaxPacketSize = 3,
|
||||
.bInterval = 0x01,
|
||||
.bRefresh = 2,
|
||||
.bSyncAddr = 0,
|
||||
},
|
||||
};
|
||||
|
||||
static struct usb_interface ac_interface;
|
||||
static struct usb_interface as_op_interface;
|
||||
static struct usb_endpoint ep_op_out, ep_op_sync;
|
||||
|
||||
static const struct usb_device_descriptor boot_device_descriptor = {
|
||||
.bLength = 18,
|
||||
.bDescriptorType = 0x01,
|
||||
.bcdUSB = 0x0110,
|
||||
.bDeviceClass = 0x00,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = 0x40,
|
||||
.idVendor = 0x2E8A,
|
||||
.idProduct = 0xFEDD,
|
||||
.bcdDevice = 0x0200,
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
.bNumConfigurations = 0x01,
|
||||
};
|
||||
|
||||
const char *_get_descriptor_string(uint index) {
|
||||
if (index <= count_of(descriptor_strings)) {
|
||||
return descriptor_strings[index - 1];
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static void _as_sync_packet(struct usb_endpoint *ep) {
|
||||
assert(ep->current_transfer);
|
||||
struct usb_buffer *buffer = usb_current_in_packet_buffer(ep);
|
||||
assert(buffer->data_max >= 3);
|
||||
buffer->data_len = 3;
|
||||
|
||||
ring_buf_t rb = i2s_write_obj.ring_buffer;
|
||||
uint32_t feedback;
|
||||
|
||||
size_t lower_limit = (RINGBUF_LEN_IN_BYTES / 2) - (RINGBUF_LEN_IN_BYTES / 4);
|
||||
size_t upper_limit = (RINGBUF_LEN_IN_BYTES / 2) + (RINGBUF_LEN_IN_BYTES / 4);
|
||||
|
||||
if (ringbuf_available_data(&rb) > upper_limit) {
|
||||
// slow down
|
||||
feedback = 47 << 14;
|
||||
} else if (ringbuf_available_data(&rb) < lower_limit) {
|
||||
// we need more data
|
||||
feedback = 49 << 14;
|
||||
} else
|
||||
feedback = 48 << 14;
|
||||
|
||||
//double temp = rate * 0x00004000;
|
||||
//temp += (double)((temp >= 0) ? 0.5f : -0.5f);
|
||||
//uint32_t feedback = (uint32_t) temp;
|
||||
|
||||
// todo lie thru our teeth for now
|
||||
//uint feedback = 48 << 14u;
|
||||
|
||||
buffer->data[0] = feedback;
|
||||
buffer->data[1] = feedback >> 8u;
|
||||
buffer->data[2] = feedback >> 16u;
|
||||
|
||||
// keep on truckin'
|
||||
usb_grow_transfer(ep->current_transfer, 1);
|
||||
usb_packet_done(ep);
|
||||
}
|
||||
|
||||
static const struct usb_transfer_type as_transfer_type = {
|
||||
.on_packet = _as_audio_packet,
|
||||
.initial_packet_count = 1,
|
||||
};
|
||||
|
||||
static const struct usb_transfer_type as_sync_transfer_type = {
|
||||
.on_packet = _as_sync_packet,
|
||||
.initial_packet_count = 1,
|
||||
};
|
||||
|
||||
static struct usb_transfer as_transfer;
|
||||
static struct usb_transfer as_sync_transfer;
|
||||
|
||||
static bool do_get_current(struct usb_setup_packet *setup) {
|
||||
if ((setup->bmRequestType & USB_REQ_TYPE_RECIPIENT_MASK) == USB_REQ_TYPE_RECIPIENT_INTERFACE) {
|
||||
switch (setup->wValue >> 8u) {
|
||||
case 1: { // mute
|
||||
usb_start_tiny_control_in_transfer(audio_state.mute, 1);
|
||||
return true;
|
||||
}
|
||||
case 2: { // volume
|
||||
/* Current volume. See UAC Spec 1.0 p.77 */
|
||||
usb_start_tiny_control_in_transfer(audio_state.volume, 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if ((setup->bmRequestType & USB_REQ_TYPE_RECIPIENT_MASK) == USB_REQ_TYPE_RECIPIENT_ENDPOINT) {
|
||||
if ((setup->wValue >> 8u) == 1) { // endpoint frequency control
|
||||
/* Current frequency */
|
||||
usb_start_tiny_control_in_transfer(audio_state.freq, 3);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// todo this seemed like aood guess, but is not correct
|
||||
uint16_t db_to_vol[91] = {
|
||||
0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002,
|
||||
0x0002, 0x0002, 0x0003, 0x0003, 0x0004, 0x0004, 0x0005, 0x0005,
|
||||
0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000d, 0x000e,
|
||||
0x0010, 0x0012, 0x0014, 0x0017, 0x001a, 0x001d, 0x0020, 0x0024,
|
||||
0x0029, 0x002e, 0x0033, 0x003a, 0x0041, 0x0049, 0x0052, 0x005c,
|
||||
0x0067, 0x0074, 0x0082, 0x0092, 0x00a4, 0x00b8, 0x00ce, 0x00e7,
|
||||
0x0104, 0x0124, 0x0147, 0x016f, 0x019c, 0x01ce, 0x0207, 0x0246,
|
||||
0x028d, 0x02dd, 0x0337, 0x039b, 0x040c, 0x048a, 0x0518, 0x05b7,
|
||||
0x066a, 0x0732, 0x0813, 0x090f, 0x0a2a, 0x0b68, 0x0ccc, 0x0e5c,
|
||||
0x101d, 0x1214, 0x1449, 0x16c3, 0x198a, 0x1ca7, 0x2026, 0x2413,
|
||||
0x287a, 0x2d6a, 0x32f5, 0x392c, 0x4026, 0x47fa, 0x50c3, 0x5a9d,
|
||||
0x65ac, 0x7214, 0x7fff
|
||||
};
|
||||
|
||||
static bool do_get_minimum(struct usb_setup_packet *setup) {
|
||||
if ((setup->bmRequestType & USB_REQ_TYPE_RECIPIENT_MASK) == USB_REQ_TYPE_RECIPIENT_INTERFACE) {
|
||||
switch (setup->wValue >> 8u) {
|
||||
case 2: { // volume
|
||||
usb_start_tiny_control_in_transfer(MIN_VOLUME, 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool do_get_maximum(struct usb_setup_packet *setup) {
|
||||
if ((setup->bmRequestType & USB_REQ_TYPE_RECIPIENT_MASK) == USB_REQ_TYPE_RECIPIENT_INTERFACE) {
|
||||
switch (setup->wValue >> 8u) {
|
||||
case 2: { // volume
|
||||
usb_start_tiny_control_in_transfer(MAX_VOLUME, 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool do_get_resolution(struct usb_setup_packet *setup) {
|
||||
if ((setup->bmRequestType & USB_REQ_TYPE_RECIPIENT_MASK) == USB_REQ_TYPE_RECIPIENT_INTERFACE) {
|
||||
switch (setup->wValue >> 8u) {
|
||||
case 2: { // volume
|
||||
usb_start_tiny_control_in_transfer(VOLUME_RESOLUTION, 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct audio_control_cmd {
|
||||
uint8_t cmd;
|
||||
uint8_t type;
|
||||
uint8_t cs;
|
||||
uint8_t cn;
|
||||
uint8_t unit;
|
||||
uint8_t len;
|
||||
} audio_control_cmd_t;
|
||||
|
||||
static void _audio_reconfigure() {
|
||||
switch (audio_state.freq) {
|
||||
case 44100:
|
||||
case 48000:
|
||||
break;
|
||||
default:
|
||||
audio_state.freq = 48000;
|
||||
}
|
||||
}
|
||||
|
||||
static void audio_set_volume(int16_t volume) {
|
||||
audio_state.volume = volume;
|
||||
// todo interpolate
|
||||
volume += CENTER_VOLUME_INDEX * 256;
|
||||
if (volume < 0)
|
||||
volume = 0;
|
||||
if (volume >= count_of(db_to_vol) * 256)
|
||||
volume = count_of(db_to_vol) * 256 - 1;
|
||||
audio_state.vol_mul = db_to_vol[((uint16_t)volume) >> 8u];
|
||||
}
|
||||
|
||||
static void audio_cmd_packet(struct usb_endpoint *ep) {
|
||||
assert(audio_control_cmd_t.cmd == AUDIO_REQ_SetCurrent);
|
||||
struct usb_buffer *buffer = usb_current_out_packet_buffer(ep);
|
||||
audio_control_cmd_t.cmd = 0;
|
||||
if (buffer->data_len >= audio_control_cmd_t.len) {
|
||||
if (audio_control_cmd_t.type == USB_REQ_TYPE_RECIPIENT_INTERFACE) {
|
||||
switch (audio_control_cmd_t.cs) {
|
||||
case 1: { // mute
|
||||
audio_state.mute = buffer->data[0];
|
||||
break;
|
||||
}
|
||||
case 2: { // volume
|
||||
audio_set_volume(*(int16_t *) buffer->data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (audio_control_cmd_t.type == USB_REQ_TYPE_RECIPIENT_ENDPOINT) {
|
||||
if (audio_control_cmd_t.cs == 1) { // endpoint frequency control
|
||||
uint32_t new_freq = (*(uint32_t *) buffer->data) & 0x00ffffffu;
|
||||
|
||||
if (audio_state.freq != new_freq) {
|
||||
audio_state.freq = new_freq;
|
||||
_audio_reconfigure();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
usb_start_empty_control_in_transfer_null_completion();
|
||||
// todo is there error handling?
|
||||
}
|
||||
|
||||
|
||||
static const struct usb_transfer_type _audio_cmd_transfer_type = {
|
||||
.on_packet = audio_cmd_packet,
|
||||
.initial_packet_count = 1,
|
||||
};
|
||||
|
||||
static bool as_set_alternate(struct usb_interface *interface, uint alt) {
|
||||
assert(interface == &as_op_interface);
|
||||
return alt < 2;
|
||||
}
|
||||
|
||||
static bool do_set_current(struct usb_setup_packet *setup) {
|
||||
if (setup->wLength && setup->wLength < 64) {
|
||||
audio_control_cmd_t.cmd = AUDIO_REQ_SetCurrent;
|
||||
audio_control_cmd_t.type = setup->bmRequestType & USB_REQ_TYPE_RECIPIENT_MASK;
|
||||
audio_control_cmd_t.len = (uint8_t) setup->wLength;
|
||||
audio_control_cmd_t.unit = setup->wIndex >> 8u;
|
||||
audio_control_cmd_t.cs = setup->wValue >> 8u;
|
||||
audio_control_cmd_t.cn = (uint8_t) setup->wValue;
|
||||
usb_start_control_out_transfer(&_audio_cmd_transfer_type);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ac_setup_request_handler(__unused struct usb_interface *interface, struct usb_setup_packet *setup) {
|
||||
setup = __builtin_assume_aligned(setup, 4);
|
||||
if (USB_REQ_TYPE_TYPE_CLASS == (setup->bmRequestType & USB_REQ_TYPE_TYPE_MASK)) {
|
||||
switch (setup->bRequest) {
|
||||
case AUDIO_REQ_SetCurrent:
|
||||
return do_set_current(setup);
|
||||
|
||||
case AUDIO_REQ_GetCurrent:
|
||||
return do_get_current(setup);
|
||||
|
||||
case AUDIO_REQ_GetMinimum:
|
||||
return do_get_minimum(setup);
|
||||
|
||||
case AUDIO_REQ_GetMaximum:
|
||||
return do_get_maximum(setup);
|
||||
|
||||
case AUDIO_REQ_GetResolution:
|
||||
return do_get_resolution(setup);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _as_setup_request_handler(__unused struct usb_endpoint *ep, struct usb_setup_packet *setup) {
|
||||
setup = __builtin_assume_aligned(setup, 4);
|
||||
if (USB_REQ_TYPE_TYPE_CLASS == (setup->bmRequestType & USB_REQ_TYPE_TYPE_MASK)) {
|
||||
switch (setup->bRequest) {
|
||||
case AUDIO_REQ_SetCurrent:
|
||||
return do_set_current(setup);
|
||||
|
||||
case AUDIO_REQ_GetCurrent:
|
||||
return do_get_current(setup);
|
||||
|
||||
case AUDIO_REQ_GetMinimum:
|
||||
return do_get_minimum(setup);
|
||||
|
||||
case AUDIO_REQ_GetMaximum:
|
||||
return do_get_maximum(setup);
|
||||
|
||||
case AUDIO_REQ_GetResolution:
|
||||
return do_get_resolution(setup);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void usb_sound_card_init() {
|
||||
usb_interface_init(&ac_interface, &ad_conf.ac_interface, NULL, 0, true);
|
||||
ac_interface.setup_request_handler = ac_setup_request_handler;
|
||||
|
||||
static struct usb_endpoint *const op_endpoints[] = {
|
||||
&ep_op_out, &ep_op_sync
|
||||
};
|
||||
|
||||
usb_interface_init(&as_op_interface, &ad_conf.as_op_interface, op_endpoints,
|
||||
count_of(op_endpoints), true);
|
||||
|
||||
as_op_interface.set_alternate_handler = as_set_alternate;
|
||||
ep_op_out.setup_request_handler = _as_setup_request_handler;
|
||||
as_transfer.type = &as_transfer_type;
|
||||
usb_set_default_transfer(&ep_op_out, &as_transfer);
|
||||
as_sync_transfer.type = &as_sync_transfer_type;
|
||||
usb_set_default_transfer(&ep_op_sync, &as_sync_transfer);
|
||||
|
||||
static struct usb_interface *const boot_device_interfaces[] = {
|
||||
&ac_interface,
|
||||
&as_op_interface,
|
||||
};
|
||||
|
||||
__unused struct usb_device *device = usb_device_init(&boot_device_descriptor,
|
||||
&ad_conf.descriptor, boot_device_interfaces,
|
||||
count_of(boot_device_interfaces), _get_descriptor_string);
|
||||
|
||||
assert(device);
|
||||
audio_set_volume(DEFAULT_VOLUME);
|
||||
_audio_reconfigure();
|
||||
|
||||
usb_device_start();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* USB-related code ends here.
|
||||
****************************************************************************/
|
|
@ -0,0 +1,136 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPECIAL THANKS TO:
|
||||
* @kilograham (github.com/kilograham)
|
||||
* for his exceptional work on Pico Playground's usb-sound-card, on which
|
||||
* a large portion of this work is based.
|
||||
*/
|
||||
|
||||
#ifndef RUN_H
|
||||
#define RUN_H
|
||||
|
||||
#include "pico/usb_device.h"
|
||||
#include "AudioClassCommon.h"
|
||||
|
||||
#include "ringbuf.h"
|
||||
#include "i2s.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* USB-related definitions begin here.
|
||||
****************************************************************************/
|
||||
|
||||
// todo fix these
|
||||
|
||||
// actually windows doesn't seem to like this in the middle, so set top range to 0db
|
||||
#define CENTER_VOLUME_INDEX 91
|
||||
|
||||
#define ENCODE_DB(x) ((uint16_t)(int16_t)((x)*256))
|
||||
|
||||
#define MIN_VOLUME ENCODE_DB(-CENTER_VOLUME_INDEX)
|
||||
#define DEFAULT_VOLUME ENCODE_DB(0)
|
||||
#define MAX_VOLUME ENCODE_DB(count_of(db_to_vol)-CENTER_VOLUME_INDEX)
|
||||
#define VOLUME_RESOLUTION ENCODE_DB(1)
|
||||
|
||||
typedef struct _audio_device_config {
|
||||
struct usb_configuration_descriptor descriptor;
|
||||
struct usb_interface_descriptor ac_interface;
|
||||
struct __packed {
|
||||
USB_Audio_StdDescriptor_Interface_AC_t core;
|
||||
USB_Audio_StdDescriptor_InputTerminal_t input_terminal;
|
||||
USB_Audio_StdDescriptor_FeatureUnit_t feature_unit;
|
||||
USB_Audio_StdDescriptor_OutputTerminal_t output_terminal;
|
||||
} ac_audio;
|
||||
struct usb_interface_descriptor as_zero_interface;
|
||||
struct usb_interface_descriptor as_op_interface;
|
||||
struct __packed {
|
||||
USB_Audio_StdDescriptor_Interface_AS_t streaming;
|
||||
struct __packed {
|
||||
USB_Audio_StdDescriptor_Format_t core;
|
||||
USB_Audio_SampleFreq_t freqs[2];
|
||||
} format;
|
||||
} as_audio;
|
||||
struct __packed {
|
||||
struct usb_endpoint_descriptor_long core;
|
||||
USB_Audio_StdDescriptor_StreamEndpoint_Spc_t audio;
|
||||
} ep1;
|
||||
struct usb_endpoint_descriptor_long ep2;
|
||||
} audio_device_config;
|
||||
|
||||
static char *descriptor_strings[] = {
|
||||
"Ploopy Corporation",
|
||||
"Ploopy Headphones",
|
||||
"000000000001"
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* USB-related definitions end here.
|
||||
****************************************************************************/
|
||||
|
||||
// I2C pin definitions
|
||||
#define PCM3060_SDA_PIN 0
|
||||
#define PCM3060_SCL_PIN 1
|
||||
|
||||
// PCM3060 pin definitions
|
||||
#define PCM3060_SCKI2_PIN 19 // a.k.a. DAC SCKI
|
||||
#define PCM3060_DAC_SCK_PIN 8 // a.k.a. DAC BCK
|
||||
#define PCM3060_DAC_WS_PIN 9 // a.k.a. DAC LRCK
|
||||
#define PCM3060_DAC_SD_PIN 12 // a.k.a. DAC DIN
|
||||
#define PCM3060_RST_PIN 14 // a.k.a. PCM RESET
|
||||
|
||||
#define NEG_SWITCH_PWM_PIN 17
|
||||
|
||||
#define AUDIO_POS_SUPPLY_EN_PIN 22
|
||||
|
||||
#define PCM_I2C_ADDR 70
|
||||
|
||||
#define SYSTEM_FREQ 230400000
|
||||
#define CODEC_FREQ 9216000
|
||||
#define SAMPLING_FREQ (CODEC_FREQ / 192)
|
||||
|
||||
#define CORE0_READY 19813219
|
||||
#define CORE1_READY 72965426
|
||||
|
||||
/*****************************************************************************
|
||||
* DO NOT CHANGE THESE VALUES. YOU COULD BREAK YOUR HARDWARE IF YOU DO!
|
||||
****************************************************************************/
|
||||
#define NEG_SWITCH_FREQ 3067000 // 1429000?
|
||||
#define NEG_DUTY_NUM 34734 // 37451?
|
||||
#define NEG_DUTY_DEN 65536
|
||||
/*****************************************************************************
|
||||
* /seriousness
|
||||
****************************************************************************/
|
||||
|
||||
void core1_entry(void);
|
||||
void setup(void);
|
||||
void configure_neg_switch_pwm(void);
|
||||
|
||||
const char *_get_descriptor_string(uint);
|
||||
static void _as_sync_packet(struct usb_endpoint *);
|
||||
static bool do_get_current(struct usb_setup_packet *);
|
||||
static bool do_get_minimum(struct usb_setup_packet *);
|
||||
static bool do_get_maximum(struct usb_setup_packet *);
|
||||
static bool do_get_resolution(struct usb_setup_packet *);
|
||||
static void _audio_reconfigure(void);
|
||||
static void audio_set_volume(int16_t);
|
||||
static void audio_cmd_packet(struct usb_endpoint *);
|
||||
static bool as_set_alternate(struct usb_interface *, uint);
|
||||
static bool do_set_current(struct usb_setup_packet *);
|
||||
static bool ac_setup_request_handler(__unused struct usb_interface *, struct usb_setup_packet *);
|
||||
bool _as_setup_request_handler(__unused struct usb_endpoint *, struct usb_setup_packet *);
|
||||
void usb_sound_card_init(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "user.h"
|
||||
#include "bqf.h"
|
||||
#include "run.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Here is where your digital signal processing journey begins. Follow this
|
||||
* guide, and don't forget any steps!
|
||||
*
|
||||
* 1. Go to user.h and change FILTER_STAGES to the number of filter stages you
|
||||
* want.
|
||||
* 2. Define the filters that you want to use. Check out "bqf.c" for a
|
||||
* complete list of what they are and how they work. Using those filters, you
|
||||
* can create ANY digital signal shape you want. Anything you can dream of.
|
||||
* 3. You're done! Enjoy the sounds of anything you want.
|
||||
****************************************************************************/
|
||||
|
||||
void define_filters() {
|
||||
// First filter.
|
||||
bqf_memreset(&bqf_filters_mem_left[0]);
|
||||
bqf_memreset(&bqf_filters_mem_right[0]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 38.0, -22.0, 0.9, &bqf_filters_left[0]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 38.0, -22.0, 0.9, &bqf_filters_right[0]);
|
||||
|
||||
// Second filter.
|
||||
bqf_memreset(&bqf_filters_mem_left[1]);
|
||||
bqf_memreset(&bqf_filters_mem_right[1]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 430.0, 6.0, 3.5, &bqf_filters_left[1]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 430.0, 6.0, 3.5, &bqf_filters_right[1]);
|
||||
|
||||
// Third filter.
|
||||
bqf_memreset(&bqf_filters_mem_left[2]);
|
||||
bqf_memreset(&bqf_filters_mem_right[2]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 2200.0, 7.0, 4.0, &bqf_filters_left[2]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 2200.0, 7.0, 4.0, &bqf_filters_right[2]);
|
||||
|
||||
// Fourth filter.
|
||||
bqf_memreset(&bqf_filters_mem_left[3]);
|
||||
bqf_memreset(&bqf_filters_mem_right[3]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 3500.0, -5.0, 2.0, &bqf_filters_left[3]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 3500.0, -5.0, 2.0, &bqf_filters_right[3]);
|
||||
|
||||
// Fifth filter.
|
||||
bqf_memreset(&bqf_filters_mem_left[4]);
|
||||
bqf_memreset(&bqf_filters_mem_right[4]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 6800.0, -6.0, 3.0, &bqf_filters_left[4]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 6800.0, -6.0, 3.0, &bqf_filters_right[4]);
|
||||
|
||||
// Sixth filter.
|
||||
bqf_memreset(&bqf_filters_mem_left[5]);
|
||||
bqf_memreset(&bqf_filters_mem_right[5]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 9200.0, 3.0, 4.0, &bqf_filters_left[5]);
|
||||
bqf_peaking_config(SAMPLING_FREQ, 9200.0, 3.0, 4.0, &bqf_filters_right[5]);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Copyright 2022 Colin Lam, Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef USER_H
|
||||
#define USER_H
|
||||
|
||||
#include "bqf.h"
|
||||
|
||||
// todo fix this. people will forget this.
|
||||
#define FILTER_STAGES 6 // Don't forget to set this to the right size!
|
||||
|
||||
extern bqf_coeff_t bqf_filters_left[FILTER_STAGES];
|
||||
extern bqf_coeff_t bqf_filters_right[FILTER_STAGES];
|
||||
extern bqf_mem_t bqf_filters_mem_left[FILTER_STAGES];
|
||||
extern bqf_mem_t bqf_filters_mem_right[FILTER_STAGES];
|
||||
|
||||
void define_filters(void);
|
||||
|
||||
#endif
|
Binary file not shown.
|
@ -0,0 +1,289 @@
|
|||
CERN Open Hardware Licence Version 2 - Strongly Reciprocal
|
||||
|
||||
|
||||
Preamble
|
||||
|
||||
CERN has developed this licence to promote collaboration among
|
||||
hardware designers and to provide a legal tool which supports the
|
||||
freedom to use, study, modify, share and distribute hardware designs
|
||||
and products based on those designs. Version 2 of the CERN Open
|
||||
Hardware Licence comes in three variants: CERN-OHL-P (permissive); and
|
||||
two reciprocal licences: CERN-OHL-W (weakly reciprocal) and this
|
||||
licence, CERN-OHL-S (strongly reciprocal).
|
||||
|
||||
The CERN-OHL-S is copyright CERN 2020. Anyone is welcome to use it, in
|
||||
unmodified form only.
|
||||
|
||||
Use of this Licence does not imply any endorsement by CERN of any
|
||||
Licensor or their designs nor does it imply any involvement by CERN in
|
||||
their development.
|
||||
|
||||
|
||||
1 Definitions
|
||||
|
||||
1.1 'Licence' means this CERN-OHL-S.
|
||||
|
||||
1.2 'Compatible Licence' means
|
||||
|
||||
a) any earlier version of the CERN Open Hardware licence, or
|
||||
|
||||
b) any version of the CERN-OHL-S, or
|
||||
|
||||
c) any licence which permits You to treat the Source to which
|
||||
it applies as licensed under CERN-OHL-S provided that on
|
||||
Conveyance of any such Source, or any associated Product You
|
||||
treat the Source in question as being licensed under
|
||||
CERN-OHL-S.
|
||||
|
||||
1.3 'Source' means information such as design materials or digital
|
||||
code which can be applied to Make or test a Product or to
|
||||
prepare a Product for use, Conveyance or sale, regardless of its
|
||||
medium or how it is expressed. It may include Notices.
|
||||
|
||||
1.4 'Covered Source' means Source that is explicitly made available
|
||||
under this Licence.
|
||||
|
||||
1.5 'Product' means any device, component, work or physical object,
|
||||
whether in finished or intermediate form, arising from the use,
|
||||
application or processing of Covered Source.
|
||||
|
||||
1.6 'Make' means to create or configure something, whether by
|
||||
manufacture, assembly, compiling, loading or applying Covered
|
||||
Source or another Product or otherwise.
|
||||
|
||||
1.7 'Available Component' means any part, sub-assembly, library or
|
||||
code which:
|
||||
|
||||
a) is licensed to You as Complete Source under a Compatible
|
||||
Licence; or
|
||||
|
||||
b) is available, at the time a Product or the Source containing
|
||||
it is first Conveyed, to You and any other prospective
|
||||
licensees
|
||||
|
||||
i) as a physical part with sufficient rights and
|
||||
information (including any configuration and
|
||||
programming files and information about its
|
||||
characteristics and interfaces) to enable it either to
|
||||
be Made itself, or to be sourced and used to Make the
|
||||
Product; or
|
||||
ii) as part of the normal distribution of a tool used to
|
||||
design or Make the Product.
|
||||
|
||||
1.8 'Complete Source' means the set of all Source necessary to Make
|
||||
a Product, in the preferred form for making modifications,
|
||||
including necessary installation and interfacing information
|
||||
both for the Product, and for any included Available Components.
|
||||
If the format is proprietary, it must also be made available in
|
||||
a format (if the proprietary tool can create it) which is
|
||||
viewable with a tool available to potential licensees and
|
||||
licensed under a licence approved by the Free Software
|
||||
Foundation or the Open Source Initiative. Complete Source need
|
||||
not include the Source of any Available Component, provided that
|
||||
You include in the Complete Source sufficient information to
|
||||
enable a recipient to Make or source and use the Available
|
||||
Component to Make the Product.
|
||||
|
||||
1.9 'Source Location' means a location where a Licensor has placed
|
||||
Covered Source, and which that Licensor reasonably believes will
|
||||
remain easily accessible for at least three years for anyone to
|
||||
obtain a digital copy.
|
||||
|
||||
1.10 'Notice' means copyright, acknowledgement and trademark notices,
|
||||
Source Location references, modification notices (subsection
|
||||
3.3(b)) and all notices that refer to this Licence and to the
|
||||
disclaimer of warranties that are included in the Covered
|
||||
Source.
|
||||
|
||||
1.11 'Licensee' or 'You' means any person exercising rights under
|
||||
this Licence.
|
||||
|
||||
1.12 'Licensor' means a natural or legal person who creates or
|
||||
modifies Covered Source. A person may be a Licensee and a
|
||||
Licensor at the same time.
|
||||
|
||||
1.13 'Convey' means to communicate to the public or distribute.
|
||||
|
||||
|
||||
2 Applicability
|
||||
|
||||
2.1 This Licence governs the use, copying, modification, Conveying
|
||||
of Covered Source and Products, and the Making of Products. By
|
||||
exercising any right granted under this Licence, You irrevocably
|
||||
accept these terms and conditions.
|
||||
|
||||
2.2 This Licence is granted by the Licensor directly to You, and
|
||||
shall apply worldwide and without limitation in time.
|
||||
|
||||
2.3 You shall not attempt to restrict by contract or otherwise the
|
||||
rights granted under this Licence to other Licensees.
|
||||
|
||||
2.4 This Licence is not intended to restrict fair use, fair dealing,
|
||||
or any other similar right.
|
||||
|
||||
|
||||
3 Copying, Modifying and Conveying Covered Source
|
||||
|
||||
3.1 You may copy and Convey verbatim copies of Covered Source, in
|
||||
any medium, provided You retain all Notices.
|
||||
|
||||
3.2 You may modify Covered Source, other than Notices, provided that
|
||||
You irrevocably undertake to make that modified Covered Source
|
||||
available from a Source Location should You Convey a Product in
|
||||
circumstances where the recipient does not otherwise receive a
|
||||
copy of the modified Covered Source. In each case subsection 3.3
|
||||
shall apply.
|
||||
|
||||
You may only delete Notices if they are no longer applicable to
|
||||
the corresponding Covered Source as modified by You and You may
|
||||
add additional Notices applicable to Your modifications.
|
||||
Including Covered Source in a larger work is modifying the
|
||||
Covered Source, and the larger work becomes modified Covered
|
||||
Source.
|
||||
|
||||
3.3 You may Convey modified Covered Source (with the effect that You
|
||||
shall also become a Licensor) provided that You:
|
||||
|
||||
a) retain Notices as required in subsection 3.2;
|
||||
|
||||
b) add a Notice to the modified Covered Source stating that You
|
||||
have modified it, with the date and brief description of how
|
||||
You have modified it;
|
||||
|
||||
c) add a Source Location Notice for the modified Covered Source
|
||||
if You Convey in circumstances where the recipient does not
|
||||
otherwise receive a copy of the modified Covered Source; and
|
||||
|
||||
d) license the modified Covered Source under the terms and
|
||||
conditions of this Licence (or, as set out in subsection
|
||||
8.3, a later version, if permitted by the licence of the
|
||||
original Covered Source). Such modified Covered Source must
|
||||
be licensed as a whole, but excluding Available Components
|
||||
contained in it, which remain licensed under their own
|
||||
applicable licences.
|
||||
|
||||
|
||||
4 Making and Conveying Products
|
||||
|
||||
You may Make Products, and/or Convey them, provided that You either
|
||||
provide each recipient with a copy of the Complete Source or ensure
|
||||
that each recipient is notified of the Source Location of the Complete
|
||||
Source. That Complete Source is Covered Source, and You must
|
||||
accordingly satisfy Your obligations set out in subsection 3.3. If
|
||||
specified in a Notice, the Product must visibly and securely display
|
||||
the Source Location on it or its packaging or documentation in the
|
||||
manner specified in that Notice.
|
||||
|
||||
|
||||
5 Research and Development
|
||||
|
||||
You may Convey Covered Source, modified Covered Source or Products to
|
||||
a legal entity carrying out development, testing or quality assurance
|
||||
work on Your behalf provided that the work is performed on terms which
|
||||
prevent the entity from both using the Source or Products for its own
|
||||
internal purposes and Conveying the Source or Products or any
|
||||
modifications to them to any person other than You. Any modifications
|
||||
made by the entity shall be deemed to be made by You pursuant to
|
||||
subsection 3.2.
|
||||
|
||||
|
||||
6 DISCLAIMER AND LIABILITY
|
||||
|
||||
6.1 DISCLAIMER OF WARRANTY -- The Covered Source and any Products
|
||||
are provided 'as is' and any express or implied warranties,
|
||||
including, but not limited to, implied warranties of
|
||||
merchantability, of satisfactory quality, non-infringement of
|
||||
third party rights, and fitness for a particular purpose or use
|
||||
are disclaimed in respect of any Source or Product to the
|
||||
maximum extent permitted by law. The Licensor makes no
|
||||
representation that any Source or Product does not or will not
|
||||
infringe any patent, copyright, trade secret or other
|
||||
proprietary right. The entire risk as to the use, quality, and
|
||||
performance of any Source or Product shall be with You and not
|
||||
the Licensor. This disclaimer of warranty is an essential part
|
||||
of this Licence and a condition for the grant of any rights
|
||||
granted under this Licence.
|
||||
|
||||
6.2 EXCLUSION AND LIMITATION OF LIABILITY -- The Licensor shall, to
|
||||
the maximum extent permitted by law, have no liability for
|
||||
direct, indirect, special, incidental, consequential, exemplary,
|
||||
punitive or other damages of any character including, without
|
||||
limitation, procurement of substitute goods or services, loss of
|
||||
use, data or profits, or business interruption, however caused
|
||||
and on any theory of contract, warranty, tort (including
|
||||
negligence), product liability or otherwise, arising in any way
|
||||
in relation to the Covered Source, modified Covered Source
|
||||
and/or the Making or Conveyance of a Product, even if advised of
|
||||
the possibility of such damages, and You shall hold the
|
||||
Licensor(s) free and harmless from any liability, costs,
|
||||
damages, fees and expenses, including claims by third parties,
|
||||
in relation to such use.
|
||||
|
||||
|
||||
7 Patents
|
||||
|
||||
7.1 Subject to the terms and conditions of this Licence, each
|
||||
Licensor hereby grants to You a perpetual, worldwide,
|
||||
non-exclusive, no-charge, royalty-free, irrevocable (except as
|
||||
stated in subsections 7.2 and 8.4) patent licence to Make, have
|
||||
Made, use, offer to sell, sell, import, and otherwise transfer
|
||||
the Covered Source and Products, where such licence applies only
|
||||
to those patent claims licensable by such Licensor that are
|
||||
necessarily infringed by exercising rights under the Covered
|
||||
Source as Conveyed by that Licensor.
|
||||
|
||||
7.2 If You institute patent litigation against any entity (including
|
||||
a cross-claim or counterclaim in a lawsuit) alleging that the
|
||||
Covered Source or a Product constitutes direct or contributory
|
||||
patent infringement, or You seek any declaration that a patent
|
||||
licensed to You under this Licence is invalid or unenforceable
|
||||
then any rights granted to You under this Licence shall
|
||||
terminate as of the date such process is initiated.
|
||||
|
||||
|
||||
8 General
|
||||
|
||||
8.1 If any provisions of this Licence are or subsequently become
|
||||
invalid or unenforceable for any reason, the remaining
|
||||
provisions shall remain effective.
|
||||
|
||||
8.2 You shall not use any of the name (including acronyms and
|
||||
abbreviations), image, or logo by which the Licensor or CERN is
|
||||
known, except where needed to comply with section 3, or where
|
||||
the use is otherwise allowed by law. Any such permitted use
|
||||
shall be factual and shall not be made so as to suggest any kind
|
||||
of endorsement or implication of involvement by the Licensor or
|
||||
its personnel.
|
||||
|
||||
8.3 CERN may publish updated versions and variants of this Licence
|
||||
which it considers to be in the spirit of this version, but may
|
||||
differ in detail to address new problems or concerns. New
|
||||
versions will be published with a unique version number and a
|
||||
variant identifier specifying the variant. If the Licensor has
|
||||
specified that a given variant applies to the Covered Source
|
||||
without specifying a version, You may treat that Covered Source
|
||||
as being released under any version of the CERN-OHL with that
|
||||
variant. If no variant is specified, the Covered Source shall be
|
||||
treated as being released under CERN-OHL-S. The Licensor may
|
||||
also specify that the Covered Source is subject to a specific
|
||||
version of the CERN-OHL or any later version in which case You
|
||||
may apply this or any later version of CERN-OHL with the same
|
||||
variant identifier published by CERN.
|
||||
|
||||
8.4 This Licence shall terminate with immediate effect if You fail
|
||||
to comply with any of its terms and conditions.
|
||||
|
||||
8.5 However, if You cease all breaches of this Licence, then Your
|
||||
Licence from any Licensor is reinstated unless such Licensor has
|
||||
terminated this Licence by giving You, while You remain in
|
||||
breach, a notice specifying the breach and requiring You to cure
|
||||
it within 30 days, and You have failed to come into compliance
|
||||
in all material respects by the end of the 30 day period. Should
|
||||
You repeat the breach after receipt of a cure notice and
|
||||
subsequent reinstatement, this Licence will terminate
|
||||
immediately and permanently. Section 6 shall continue to apply
|
||||
after any termination.
|
||||
|
||||
8.6 This Licence shall not be enforceable except by a Licensor
|
||||
acting as such, and third party beneficiary rights are
|
||||
specifically excluded.
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue