Update NeoPixelBus library to 2.5.0.09
Update NeoPixelBus library to 2.5.0.09 (#6292)
@ -1,675 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://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 <http://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
|
||||
<http://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
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"name": "NeoPixelBus",
|
||||
"keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, RGB, RGBW",
|
||||
"description": "A library that makes controlling NeoPixels (WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102) easy. Supports most Arduino platforms. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang; and two methods of sending DotStar data, hardware SPI and software SPI.",
|
||||
"homepage": "https://github.com/Makuna/NeoPixelBus/wiki",
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/Makuna/NeoPixelBus"
|
||||
},
|
||||
"version": "2.2.9",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,216 +0,0 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Esp8266 UART hardware
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include "NeoEsp8266UartMethod.h"
|
||||
#include <utility>
|
||||
extern "C"
|
||||
{
|
||||
#include <eagle_soc.h>
|
||||
#include <ets_sys.h>
|
||||
#include <uart.h>
|
||||
#include <uart_register.h>
|
||||
}
|
||||
|
||||
#define UART1 1
|
||||
#define UART1_INV_MASK (0x3f << 19)
|
||||
|
||||
// Gets the number of bytes waiting in the TX FIFO of UART1
|
||||
static inline uint8_t getUartTxFifoLength()
|
||||
{
|
||||
return (U1S >> USTXC) & 0xff;
|
||||
}
|
||||
|
||||
// Append a byte to the TX FIFO of UART1
|
||||
// You must ensure the TX FIFO isn't full
|
||||
static inline void enqueue(uint8_t byte)
|
||||
{
|
||||
U1F = byte;
|
||||
}
|
||||
|
||||
static const uint8_t* esp8266_uart1_async_buf;
|
||||
static const uint8_t* esp8266_uart1_async_buf_end;
|
||||
|
||||
NeoEsp8266Uart::NeoEsp8266Uart(uint16_t pixelCount, size_t elementSize)
|
||||
{
|
||||
_sizePixels = pixelCount * elementSize;
|
||||
_pixels = (uint8_t*)malloc(_sizePixels);
|
||||
memset(_pixels, 0x00, _sizePixels);
|
||||
}
|
||||
|
||||
NeoEsp8266Uart::~NeoEsp8266Uart()
|
||||
{
|
||||
// Wait until the TX fifo is empty. This way we avoid broken frames
|
||||
// when destroying & creating a NeoPixelBus to change its length.
|
||||
while (getUartTxFifoLength() > 0)
|
||||
{
|
||||
yield();
|
||||
}
|
||||
|
||||
free(_pixels);
|
||||
}
|
||||
|
||||
void NeoEsp8266Uart::InitializeUart(uint32_t uartBaud)
|
||||
{
|
||||
// Configure the serial line with 1 start bit (0), 6 data bits and 1 stop bit (1)
|
||||
Serial1.begin(uartBaud, SERIAL_6N1, SERIAL_TX_ONLY);
|
||||
|
||||
// Invert the TX voltage associated with logic level so:
|
||||
// - A logic level 0 will generate a Vcc signal
|
||||
// - A logic level 1 will generate a Gnd signal
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(UART1), UART1_INV_MASK);
|
||||
SET_PERI_REG_MASK(UART_CONF0(UART1), (BIT(22)));
|
||||
}
|
||||
|
||||
void NeoEsp8266Uart::UpdateUart()
|
||||
{
|
||||
// Since the UART can finish sending queued bytes in the FIFO in
|
||||
// the background, instead of waiting for the FIFO to flush
|
||||
// we annotate the start time of the frame so we can calculate
|
||||
// when it will finish.
|
||||
_startTime = micros();
|
||||
|
||||
// Then keep filling the FIFO until done
|
||||
const uint8_t* ptr = _pixels;
|
||||
const uint8_t* end = ptr + _sizePixels;
|
||||
while (ptr != end)
|
||||
{
|
||||
ptr = FillUartFifo(ptr, end);
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t* ICACHE_RAM_ATTR NeoEsp8266Uart::FillUartFifo(const uint8_t* pixels, const uint8_t* end)
|
||||
{
|
||||
// Remember: UARTs send less significant bit (LSB) first so
|
||||
// pushing ABCDEF byte will generate a 0FEDCBA1 signal,
|
||||
// including a LOW(0) start & a HIGH(1) stop bits.
|
||||
// Also, we have configured UART to invert logic levels, so:
|
||||
const uint8_t _uartData[4] = {
|
||||
0b110111, // On wire: 1 000 100 0 [Neopixel reads 00]
|
||||
0b000111, // On wire: 1 000 111 0 [Neopixel reads 01]
|
||||
0b110100, // On wire: 1 110 100 0 [Neopixel reads 10]
|
||||
0b000100, // On wire: 1 110 111 0 [NeoPixel reads 11]
|
||||
};
|
||||
uint8_t avail = (UART_TX_FIFO_SIZE - getUartTxFifoLength()) / 4;
|
||||
if (end - pixels > avail)
|
||||
{
|
||||
end = pixels + avail;
|
||||
}
|
||||
while (pixels < end)
|
||||
{
|
||||
uint8_t subpix = *pixels++;
|
||||
enqueue(_uartData[(subpix >> 6) & 0x3]);
|
||||
enqueue(_uartData[(subpix >> 4) & 0x3]);
|
||||
enqueue(_uartData[(subpix >> 2) & 0x3]);
|
||||
enqueue(_uartData[ subpix & 0x3]);
|
||||
}
|
||||
return pixels;
|
||||
}
|
||||
|
||||
NeoEsp8266AsyncUart::NeoEsp8266AsyncUart(uint16_t pixelCount, size_t elementSize)
|
||||
: NeoEsp8266Uart(pixelCount, elementSize)
|
||||
{
|
||||
_asyncPixels = (uint8_t*)malloc(_sizePixels);
|
||||
}
|
||||
|
||||
NeoEsp8266AsyncUart::~NeoEsp8266AsyncUart()
|
||||
{
|
||||
// Remember: the UART interrupt can be sending data from _asyncPixels in the background
|
||||
while (esp8266_uart1_async_buf != esp8266_uart1_async_buf_end)
|
||||
{
|
||||
yield();
|
||||
}
|
||||
free(_asyncPixels);
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR NeoEsp8266AsyncUart::InitializeUart(uint32_t uartBaud)
|
||||
{
|
||||
NeoEsp8266Uart::InitializeUart(uartBaud);
|
||||
|
||||
// Disable all interrupts
|
||||
ETS_UART_INTR_DISABLE();
|
||||
|
||||
// Clear the RX & TX FIFOS
|
||||
SET_PERI_REG_MASK(UART_CONF0(UART1), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(UART1), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
||||
|
||||
// Set the interrupt handler
|
||||
ETS_UART_INTR_ATTACH(IntrHandler, NULL);
|
||||
|
||||
// Set tx fifo trigger. 80 bytes gives us 200 microsecs to refill the FIFO
|
||||
WRITE_PERI_REG(UART_CONF1(UART1), 80 << UART_TXFIFO_EMPTY_THRHD_S);
|
||||
|
||||
// Disable RX & TX interrupts. It is enabled by uart.c in the SDK
|
||||
CLEAR_PERI_REG_MASK(UART_INT_ENA(UART1), UART_RXFIFO_FULL_INT_ENA | UART_TXFIFO_EMPTY_INT_ENA);
|
||||
|
||||
// Clear all pending interrupts in UART1
|
||||
WRITE_PERI_REG(UART_INT_CLR(UART1), 0xffff);
|
||||
|
||||
// Reenable interrupts
|
||||
ETS_UART_INTR_ENABLE();
|
||||
}
|
||||
|
||||
void NeoEsp8266AsyncUart::UpdateUart()
|
||||
{
|
||||
// Instruct ESP8266 hardware uart1 to send the pixels asynchronously
|
||||
esp8266_uart1_async_buf = _pixels;
|
||||
esp8266_uart1_async_buf_end = _pixels + _sizePixels;
|
||||
SET_PERI_REG_MASK(UART_INT_ENA(1), UART_TXFIFO_EMPTY_INT_ENA);
|
||||
|
||||
// Annotate when we started to send bytes, so we can calculate when we are ready to send again
|
||||
_startTime = micros();
|
||||
|
||||
// Copy the pixels to the idle buffer and swap them
|
||||
memcpy(_asyncPixels, _pixels, _sizePixels);
|
||||
std::swap(_asyncPixels, _pixels);
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR NeoEsp8266AsyncUart::IntrHandler(void* param)
|
||||
{
|
||||
// Interrupt handler is shared between UART0 & UART1
|
||||
if (READ_PERI_REG(UART_INT_ST(UART1))) //any UART1 stuff
|
||||
{
|
||||
// Fill the FIFO with new data
|
||||
esp8266_uart1_async_buf = FillUartFifo(esp8266_uart1_async_buf, esp8266_uart1_async_buf_end);
|
||||
// Disable TX interrupt when done
|
||||
if (esp8266_uart1_async_buf == esp8266_uart1_async_buf_end)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(UART_INT_ENA(UART1), UART_TXFIFO_EMPTY_INT_ENA);
|
||||
}
|
||||
// Clear all interrupts flags (just in case)
|
||||
WRITE_PERI_REG(UART_INT_CLR(UART1), 0xffff);
|
||||
}
|
||||
|
||||
if (READ_PERI_REG(UART_INT_ST(UART0)))
|
||||
{
|
||||
// TODO: gdbstub uses the interrupt of UART0, but there is no way to call its
|
||||
// interrupt handler gdbstub_uart_hdlr since it's static.
|
||||
WRITE_PERI_REG(UART_INT_CLR(UART0), 0xffff);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,178 +0,0 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Esp8266 UART hardware
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <Arduino.h>
|
||||
|
||||
// NeoEsp8266Uart contains all the low level details that doesn't
|
||||
// depend on the transmission speed, and therefore, it isn't a template
|
||||
class NeoEsp8266Uart
|
||||
{
|
||||
protected:
|
||||
NeoEsp8266Uart(uint16_t pixelCount, size_t elementSize);
|
||||
|
||||
~NeoEsp8266Uart();
|
||||
|
||||
void InitializeUart(uint32_t uartBaud);
|
||||
|
||||
void UpdateUart();
|
||||
|
||||
static const uint8_t* ICACHE_RAM_ATTR FillUartFifo(const uint8_t* pixels, const uint8_t* end);
|
||||
|
||||
size_t _sizePixels; // Size of '_pixels' buffer below
|
||||
uint8_t* _pixels; // Holds LED color values
|
||||
uint32_t _startTime; // Microsecond count when last update started
|
||||
};
|
||||
|
||||
// NeoEsp8266AsyncUart handles all transmission asynchronously using interrupts
|
||||
//
|
||||
// This UART controller uses two buffers that are swapped in every call to
|
||||
// NeoPixelBus.Show(). One buffer contains the data that is being sent
|
||||
// asynchronosly and another buffer contains the data that will be send
|
||||
// in the next call to NeoPixelBus.Show().
|
||||
//
|
||||
// Therefore, the result of NeoPixelBus.Pixels() is invalidated after
|
||||
// every call to NeoPixelBus.Show() and must not be cached.
|
||||
class NeoEsp8266AsyncUart: public NeoEsp8266Uart
|
||||
{
|
||||
protected:
|
||||
NeoEsp8266AsyncUart(uint16_t pixelCount, size_t elementSize);
|
||||
|
||||
~NeoEsp8266AsyncUart();
|
||||
|
||||
void InitializeUart(uint32_t uartBaud);
|
||||
|
||||
void UpdateUart();
|
||||
|
||||
private:
|
||||
static void ICACHE_RAM_ATTR IntrHandler(void* param);
|
||||
|
||||
uint8_t* _asyncPixels; // Holds a copy of LED color values taken when UpdateUart began
|
||||
};
|
||||
|
||||
// NeoEsp8266UartSpeedWs2813 contains the timing constants used to get NeoPixelBus running with the Ws2813
|
||||
class NeoEsp8266UartSpeedWs2813
|
||||
{
|
||||
public:
|
||||
static const uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed
|
||||
static const uint32_t UartBaud = 3200000; // 800mhz, 4 serial bytes per NeoByte
|
||||
static const uint32_t ResetTimeUs = 250; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
// NeoEsp8266UartSpeed800Kbps contains the timing constant used to get NeoPixelBus running at 800Khz
|
||||
class NeoEsp8266UartSpeed800Kbps
|
||||
{
|
||||
public:
|
||||
static const uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed
|
||||
static const uint32_t UartBaud = 3200000; // 800mhz, 4 serial bytes per NeoByte
|
||||
static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
// NeoEsp8266UartSpeed800Kbps contains the timing constant used to get NeoPixelBus running at 400Khz
|
||||
class NeoEsp8266UartSpeed400Kbps
|
||||
{
|
||||
public:
|
||||
static const uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed
|
||||
static const uint32_t UartBaud = 1600000; // 400mhz, 4 serial bytes per NeoByte
|
||||
static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
// NeoEsp8266UartMethodBase is a light shell arround NeoEsp8266Uart or NeoEsp8266AsyncUart that
|
||||
// implements the methods needed to operate as a NeoPixelBus method.
|
||||
template<typename T_SPEED, typename T_BASE>
|
||||
class NeoEsp8266UartMethodBase: public T_BASE
|
||||
{
|
||||
public:
|
||||
NeoEsp8266UartMethodBase(uint16_t pixelCount, size_t elementSize)
|
||||
: T_BASE(pixelCount, elementSize)
|
||||
{
|
||||
}
|
||||
NeoEsp8266UartMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize)
|
||||
: T_BASE(pixelCount, elementSize)
|
||||
{
|
||||
}
|
||||
|
||||
bool IsReadyToUpdate() const
|
||||
{
|
||||
uint32_t delta = micros() - this->_startTime;
|
||||
return delta >= getPixelTime() + T_SPEED::ResetTimeUs;
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
this->InitializeUart(T_SPEED::UartBaud);
|
||||
|
||||
// Inverting logic levels can generate a phantom bit in the led strip bus
|
||||
// We need to delay 50+ microseconds the output stream to force a data
|
||||
// latch and discard this bit. Otherwise, that bit would be prepended to
|
||||
// the first frame corrupting it.
|
||||
this->_startTime = micros() - getPixelTime();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Data latch = 50+ microsecond pause in the output stream. Rather than
|
||||
// put a delay at the end of the function, the ending time is noted and
|
||||
// the function will simply hold off (if needed) on issuing the
|
||||
// subsequent round of data until the latch time has elapsed. This
|
||||
// allows the mainline code to start generating the next frame of data
|
||||
// rather than stalling for the latch.
|
||||
while (!this->IsReadyToUpdate())
|
||||
{
|
||||
yield();
|
||||
}
|
||||
this->UpdateUart();
|
||||
}
|
||||
|
||||
uint8_t* getPixels() const
|
||||
{
|
||||
return this->_pixels;
|
||||
};
|
||||
|
||||
size_t getPixelsSize() const
|
||||
{
|
||||
return this->_sizePixels;
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t getPixelTime() const
|
||||
{
|
||||
return (T_SPEED::ByteSendTimeUs * this->_sizePixels);
|
||||
};
|
||||
};
|
||||
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedWs2813, NeoEsp8266Uart> NeoEsp8266UartWs2813Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed800Kbps, NeoEsp8266Uart> NeoEsp8266Uart800KbpsMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed400Kbps, NeoEsp8266Uart> NeoEsp8266Uart400KbpsMethod;
|
||||
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedWs2813, NeoEsp8266AsyncUart> NeoEsp8266AsyncUartWs2813Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed800Kbps, NeoEsp8266AsyncUart> NeoEsp8266AsyncUart800KbpsMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed400Kbps, NeoEsp8266AsyncUart> NeoEsp8266AsyncUart400KbpsMethod;
|
||||
|
||||
#endif
|
||||
|
@ -1,151 +0,0 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Esp8266 and Esp32.
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
|
||||
#include <Arduino.h>
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <eagle_soc.h>
|
||||
#endif
|
||||
|
||||
// ESP32 doesn't define ICACHE_RAM_ATTR
|
||||
#ifndef ICACHE_RAM_ATTR
|
||||
#define ICACHE_RAM_ATTR IRAM_ATTR
|
||||
#endif
|
||||
|
||||
inline uint32_t _getCycleCount()
|
||||
{
|
||||
uint32_t ccount;
|
||||
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
|
||||
return ccount;
|
||||
}
|
||||
|
||||
#define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us
|
||||
#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us
|
||||
#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit
|
||||
#define CYCLES_400_T0H (F_CPU / 2000000)
|
||||
#define CYCLES_400_T1H (F_CPU / 833333)
|
||||
#define CYCLES_400 (F_CPU / 400000)
|
||||
|
||||
void ICACHE_RAM_ATTR bitbang_send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin)
|
||||
{
|
||||
const uint32_t pinRegister = _BV(pin);
|
||||
uint8_t mask;
|
||||
uint8_t subpix;
|
||||
uint32_t cyclesStart;
|
||||
|
||||
// trigger emediately
|
||||
cyclesStart = _getCycleCount() - CYCLES_800;
|
||||
do
|
||||
{
|
||||
subpix = *pixels++;
|
||||
for (mask = 0x80; mask != 0; mask >>= 1)
|
||||
{
|
||||
// do the checks here while we are waiting on time to pass
|
||||
uint32_t cyclesBit = ((subpix & mask)) ? CYCLES_800_T1H : CYCLES_800_T0H;
|
||||
uint32_t cyclesNext = cyclesStart;
|
||||
|
||||
// after we have done as much work as needed for this next bit
|
||||
// now wait for the HIGH
|
||||
do
|
||||
{
|
||||
// cache and use this count so we don't incur another
|
||||
// instruction before we turn the bit high
|
||||
cyclesStart = _getCycleCount();
|
||||
} while ((cyclesStart - cyclesNext) < CYCLES_800);
|
||||
|
||||
// set high
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1ts = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister);
|
||||
#endif
|
||||
|
||||
// wait for the LOW
|
||||
do
|
||||
{
|
||||
cyclesNext = _getCycleCount();
|
||||
} while ((cyclesNext - cyclesStart) < cyclesBit);
|
||||
|
||||
// set low
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1tc = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister);
|
||||
#endif
|
||||
}
|
||||
} while (pixels < end);
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR bitbang_send_pixels_400(uint8_t* pixels, uint8_t* end, uint8_t pin)
|
||||
{
|
||||
const uint32_t pinRegister = _BV(pin);
|
||||
uint8_t mask;
|
||||
uint8_t subpix;
|
||||
uint32_t cyclesStart;
|
||||
|
||||
// trigger emediately
|
||||
cyclesStart = _getCycleCount() - CYCLES_400;
|
||||
do
|
||||
{
|
||||
subpix = *pixels++;
|
||||
for (mask = 0x80; mask; mask >>= 1)
|
||||
{
|
||||
uint32_t cyclesBit = ((subpix & mask)) ? CYCLES_400_T1H : CYCLES_400_T0H;
|
||||
uint32_t cyclesNext = cyclesStart;
|
||||
|
||||
// after we have done as much work as needed for this next bit
|
||||
// now wait for the HIGH
|
||||
do
|
||||
{
|
||||
// cache and use this count so we don't incur another
|
||||
// instruction before we turn the bit high
|
||||
cyclesStart = _getCycleCount();
|
||||
} while ((cyclesStart - cyclesNext) < CYCLES_400);
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1ts = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister);
|
||||
#endif
|
||||
|
||||
// wait for the LOW
|
||||
do
|
||||
{
|
||||
cyclesNext = _getCycleCount();
|
||||
} while ((cyclesNext - cyclesStart) < cyclesBit);
|
||||
|
||||
// set low
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1tc = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister);
|
||||
#endif
|
||||
}
|
||||
} while (pixels < end);
|
||||
}
|
||||
|
||||
#endif
|
165
lib/NeoPixelBus-2.5.0.09/COPYING
Normal file
@ -0,0 +1,165 @@
|
||||
GNU LESSER 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.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
@ -1,15 +1,15 @@
|
||||
# NeoPixelBus
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6AA97KE54UJR4)
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6AA97KE54UJR4)
|
||||
|
||||
Arduino NeoPixel library
|
||||
|
||||
A library to control one wire protocol RGB and RGBW leds like SK6812, WS2811, WS2812 and WS2813 that are commonly refered to as NeoPixels and two wire protocol RGB like APA102 commonly refered to as DotStars.
|
||||
Supports most Arduino platforms.
|
||||
This is the most funtional library for the Esp8266 as it provides solutions for all Esp8266 module types even when WiFi is used.
|
||||
This is the most functional library for the Esp8266 as it provides solutions for all Esp8266 module types even when WiFi is used.
|
||||
|
||||
|
||||
Please read this best practices link before connecting your NeoPixels, it will save you alot of time and effort.
|
||||
Please read this best practices link before connecting your NeoPixels, it will save you a lot of time and effort.
|
||||
[Adafruit NeoPixel Best Practices](https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices)
|
||||
|
||||
For quick questions jump on Gitter and ask away.
|
||||
@ -17,6 +17,9 @@ For quick questions jump on Gitter and ask away.
|
||||
|
||||
For bugs, make sure there isn't an active issue and then create one.
|
||||
|
||||
## Why this library and not FastLED or some other library?
|
||||
See [Why this Library in the Wiki](https://github.com/Makuna/NeoPixelBus/wiki/Library-Comparisons).
|
||||
|
||||
## Documentation
|
||||
[See Wiki](https://github.com/Makuna/NeoPixelBus/wiki)
|
||||
|
@ -25,9 +25,7 @@ NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
|
||||
// There are other Esp8266 alternative methods that provide more pin options, but also have
|
||||
// other side effects.
|
||||
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
|
||||
//
|
||||
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
|
||||
// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
|
||||
// You can also use one of these for Esp8266,
|
||||
// each having their own restrictions
|
||||
@ -38,9 +36,10 @@ NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Dma400KbpsMethod> strip(PixelCount, PixelPin);
|
||||
|
||||
// Uart method is good for the Esp-01 or other pin restricted modules
|
||||
// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
// NOTE: These will ignore the PIN and use GPI02 pin
|
||||
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Uart400KbpsMethod> strip(PixelCount, PixelPin);
|
||||
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart1800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Uart1400KbpsMethod> strip(PixelCount, PixelPin);
|
||||
|
||||
// The bitbang method is really only good if you are not using WiFi features of the ESP
|
||||
// It works with all but pin 16
|
@ -29,10 +29,7 @@ NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
|
||||
// There are other Esp8266 alternative methods that provide more pin options, but also have
|
||||
// other side effects.
|
||||
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
|
||||
//
|
||||
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
|
||||
|
||||
// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
|
||||
// NeoPixel animation time management object
|
||||
NeoPixelAnimator animations(PixelCount, NEO_CENTISECONDS);
|
@ -16,13 +16,11 @@ NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
|
||||
// There are other Esp8266 alternative methods that provide more pin options, but also have
|
||||
// other side effects.
|
||||
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
|
||||
//
|
||||
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
|
||||
// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
|
||||
NeoPixelAnimator animations(AnimationChannels); // NeoPixel animation management object
|
||||
|
||||
uint16_t effectState = 0; // general purpose variable used to store effect state
|
||||
boolean fadeToColor = true; // general purpose variable used to store effect state
|
||||
|
||||
|
||||
// what is stored for state is specific to the need, in this case, the colors.
|
||||
@ -75,7 +73,7 @@ void BlendAnimUpdate(const AnimationParam& param)
|
||||
|
||||
void FadeInFadeOutRinseRepeat(float luminance)
|
||||
{
|
||||
if (effectState == 0)
|
||||
if (fadeToColor)
|
||||
{
|
||||
// Fade upto a random color
|
||||
// we use HslColor object as it allows us to easily pick a hue
|
||||
@ -89,7 +87,7 @@ void FadeInFadeOutRinseRepeat(float luminance)
|
||||
|
||||
animations.StartAnimation(0, time, BlendAnimUpdate);
|
||||
}
|
||||
else if (effectState == 1)
|
||||
else
|
||||
{
|
||||
// fade to black
|
||||
uint16_t time = random(600, 700);
|
||||
@ -101,7 +99,7 @@ void FadeInFadeOutRinseRepeat(float luminance)
|
||||
}
|
||||
|
||||
// toggle to the next effect state
|
||||
effectState = (effectState + 1) % 2;
|
||||
fadeToColor = !fadeToColor;
|
||||
}
|
||||
|
||||
void setup()
|
@ -29,9 +29,7 @@ NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
|
||||
// There are other Esp8266 alternative methods that provide more pin options, but also have
|
||||
// other side effects.
|
||||
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
|
||||
//
|
||||
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
|
||||
// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
|
||||
// what is stored for state is specific to the need, in this case, the colors and
|
||||
// the pixel to animate;
|
@ -14,9 +14,7 @@ NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
|
||||
// There are other Esp8266 alternative methods that provide more pin options, but also have
|
||||
// other side effects.
|
||||
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
|
||||
//
|
||||
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
|
||||
// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
|
||||
|
||||
NeoPixelAnimator animations(PixelCount); // NeoPixel animation management object
|
||||
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
@ -36,12 +36,12 @@ const RgbColor White(255);
|
||||
const RgbColor Black(0);
|
||||
|
||||
// define a custom shader object that provides brightness support
|
||||
// based upon the NeoBitsBase
|
||||
template<typename T_COLOR_FEATURE> class BrightnessShader : public NeoBitsBase
|
||||
// based upon the NeoShaderBase
|
||||
template<typename T_COLOR_FEATURE> class BrightnessShader : public NeoShaderBase
|
||||
{
|
||||
public:
|
||||
BrightnessShader():
|
||||
NeoBitsBase(),
|
||||
NeoShaderBase(),
|
||||
_brightness(255) // default to full bright
|
||||
{}
|
||||
|
@ -34,12 +34,12 @@ const RgbColor White(255);
|
||||
const RgbColor Black(0);
|
||||
|
||||
// define a custom shader object that provides brightness support
|
||||
// based upon the NeoBitsBase
|
||||
class BrightnessShader : public NeoBitsBase
|
||||
// based upon the NeoShaderBase
|
||||
class BrightnessShader : public NeoShaderBase
|
||||
{
|
||||
public:
|
||||
BrightnessShader():
|
||||
NeoBitsBase(),
|
||||
NeoShaderBase(),
|
||||
_brightness(255) // default to full bright
|
||||
{}
|
||||
|
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/circular.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/cubic.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/different.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/exponential.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/gamma.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/pronounced.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/quadratic.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/quintic.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
lib/NeoPixelBus-2.5.0.09/extras/curves/sinusoidal.png
Normal file
After Width: | Height: | Size: 40 KiB |
@ -20,25 +20,105 @@ NeoBrgFeature KEYWORD1
|
||||
NeoRbgFeature KEYWORD1
|
||||
DotStarBgrFeature KEYWORD1
|
||||
DotStarLbgrFeature KEYWORD1
|
||||
NeoWs2813Method KEYWORD1
|
||||
Neo800KbpsMethod KEYWORD1
|
||||
Neo400KbpsMethod KEYWORD1
|
||||
NeoAvrWs2813Method KEYWORD1
|
||||
NeoAvr800KbpsMethod KEYWORD1
|
||||
NeoAvr400KbpsMethod KEYWORD1
|
||||
NeoEsp8266DmaWs2813Method KEYWORD1
|
||||
NeoWs2813Method KEYWORD1
|
||||
NeoWs2812xMethod KEYWORD1
|
||||
NeoWs2812Method KEYWORD1
|
||||
NeoSk6812Method KEYWORD1
|
||||
NeoLc8812Method KEYWORD1
|
||||
NeoApa106Method KEYWORD1
|
||||
NeoEsp8266DmaWs2812xMethod KEYWORD1
|
||||
NeoEsp8266DmaSk6812Method KEYWORD1
|
||||
NeoEsp8266DmaApa106Method KEYWORD1
|
||||
NeoEsp8266Dma800KbpsMethod KEYWORD1
|
||||
NeoEsp8266Dma400KbpsMethod KEYWORD1
|
||||
NeoEsp8266UartWs2813Method KEYWORD1
|
||||
NeoEsp8266Uart800KbpsMethod KEYWORD1
|
||||
NeoEsp8266Uart400KbpsMethod KEYWORD1
|
||||
NeoEsp8266AsyncUartWs2813Method KEYWORD1
|
||||
NeoEsp8266AsyncUart800KbpsMethod KEYWORD1
|
||||
NeoEsp8266AsyncUart400KbpsMethod KEYWORD1
|
||||
NeoEsp8266Uart0Ws2813Method KEYWORD1
|
||||
NeoEsp8266Uart0Ws2812xMethod KEYWORD1
|
||||
NeoEsp8266Uart0Ws2812Method KEYWORD1
|
||||
NeoEsp8266Uart0Sk6812Method KEYWORD1
|
||||
NeoEsp8266Uart0Lc8812Method KEYWORD1
|
||||
NeoEsp8266Uart0Apa106Method KEYWORD1
|
||||
NeoEsp8266Uart0800KbpsMethod KEYWORD1
|
||||
NeoEsp8266Uart0400KbpsMethod KEYWORD1
|
||||
NeoEsp8266AsyncUart0Ws2813Method KEYWORD1
|
||||
NeoEsp8266AsyncUart0Ws2812xMethod KEYWORD1
|
||||
NeoEsp8266AsyncUart0Ws2812Method KEYWORD1
|
||||
NeoEsp8266AsyncUart0Sk6812Method KEYWORD1
|
||||
NeoEsp8266AsyncUart0Lc8812Method KEYWORD1
|
||||
NeoEsp8266AsyncUart0Apa106Method KEYWORD1
|
||||
NeoEsp8266AsyncUart0800KbpsMethod KEYWORD1
|
||||
NeoEsp8266AsyncUart0400KbpsMethod KEYWORD1
|
||||
NeoEsp8266Uart1Ws2813Method KEYWORD1
|
||||
NeoEsp8266Uart1Ws2812xMethod KEYWORD1
|
||||
NeoEsp8266Uart1Ws2812Method KEYWORD1
|
||||
NeoEsp8266Uart1Sk6812Method KEYWORD1
|
||||
NeoEsp8266Uart1Lc8812Method KEYWORD1
|
||||
NeoEsp8266Uart1Apa106Method KEYWORD1
|
||||
NeoEsp8266Uart1800KbpsMethod KEYWORD1
|
||||
NeoEsp8266Uart1400KbpsMethod KEYWORD1
|
||||
NeoEsp8266AsyncUart1Ws2813Method KEYWORD1
|
||||
NeoEsp8266AsyncUart1Ws2812xMethod KEYWORD1
|
||||
NeoEsp8266AsyncUart1Ws2812Method KEYWORD1
|
||||
NeoEsp8266AsyncUart1Sk6812Method KEYWORD1
|
||||
NeoEsp8266AsyncUart1Lc8812Method KEYWORD1
|
||||
NeoEsp8266AsyncUart1Apa106Method KEYWORD1
|
||||
NeoEsp8266AsyncUart1800KbpsMethod KEYWORD1
|
||||
NeoEsp8266AsyncUart1400KbpsMethod KEYWORD1
|
||||
NeoEsp8266BitBangWs2813Method KEYWORD1
|
||||
NeoEsp8266BitBangWs2812xMethod KEYWORD1
|
||||
NeoEsp8266BitBangWs2812Method KEYWORD1
|
||||
NeoEsp8266BitBangSk6812Method KEYWORD1
|
||||
NeoEsp8266BitBangLc8812Method KEYWORD1
|
||||
NeoEsp8266BitBangApa106Method KEYWORD1
|
||||
NeoEsp8266BitBang800KbpsMethod KEYWORD1
|
||||
NeoEsp8266BitBang400KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt0Ws2812xMethod KEYWORD1
|
||||
NeoEsp32Rmt0Sk6812Method KEYWORD1
|
||||
NeoEsp32Rmt0Apa106Method KEYWORD1
|
||||
NeoEsp32Rmt0800KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt0400KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt1Ws2812xMethod KEYWORD1
|
||||
NeoEsp32Rmt1Sk6812Method KEYWORD1
|
||||
NeoEsp32Rmt1Apa106Method KEYWORD1
|
||||
NeoEsp32Rmt1800KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt1400KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt2Ws2812xMethod KEYWORD1
|
||||
NeoEsp32Rmt2Sk6812Method KEYWORD1
|
||||
NeoEsp32Rmt2Apa106Method KEYWORD1
|
||||
NeoEsp32Rmt2800KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt2400KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt3Ws2812xMethod KEYWORD1
|
||||
NeoEsp32Rmt3Sk6812Method KEYWORD1
|
||||
NeoEsp32Rmt3Apa106Method KEYWORD1
|
||||
NeoEsp32Rmt3800KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt3400KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt4Ws2812xMethod KEYWORD1
|
||||
NeoEsp32Rmt4Sk6812Method KEYWORD1
|
||||
NeoEsp32Rmt4Apa106Method KEYWORD1
|
||||
NeoEsp32Rmt4800KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt4400KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt5Ws2812xMethod KEYWORD1
|
||||
NeoEsp32Rmt5Sk6812Method KEYWORD1
|
||||
NeoEsp32Rmt5Apa106Method KEYWORD1
|
||||
NeoEsp32Rmt5800KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt5400KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt6Ws2812xMethod KEYWORD1
|
||||
NeoEsp32Rmt6Sk6812Method KEYWORD1
|
||||
NeoEsp32Rmt6Apa106Method KEYWORD1
|
||||
NeoEsp32Rmt6800KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt6400KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt7Ws2812xMethod KEYWORD1
|
||||
NeoEsp32Rmt7Sk6812Method KEYWORD1
|
||||
NeoEsp32Rmt7Apa106Method KEYWORD1
|
||||
NeoEsp32Rmt7800KbpsMethod KEYWORD1
|
||||
NeoEsp32Rmt7400KbpsMethod KEYWORD1
|
||||
NeoEsp32BitBangWs2813Method KEYWORD1
|
||||
NeoEsp32BitBangWs2812xMethod KEYWORD1
|
||||
NeoEsp32BitBangWs2812Method KEYWORD1
|
||||
NeoEsp32BitBangSk6812Method KEYWORD1
|
||||
NeoEsp32BitBangLc8812Method KEYWORD1
|
||||
NeoEsp32BitBangApa106Method KEYWORD1
|
||||
NeoEsp32BitBang800KbpsMethod KEYWORD1
|
||||
NeoEsp32BitBang400KbpsMethod KEYWORD1
|
||||
DotStarMethod KEYWORD1
|
||||
@ -105,6 +185,7 @@ PixelsSize KEYWORD2
|
||||
PixelCount KEYWORD2
|
||||
SetPixelColor KEYWORD2
|
||||
GetPixelColor KEYWORD2
|
||||
SwapPixelColor KEYWORD2
|
||||
CalculateBrightness KEYWORD2
|
||||
Darken KEYWORD2
|
||||
Lighten KEYWORD2
|
||||
@ -117,6 +198,7 @@ StopAnimation KEYWORD2
|
||||
RestartAnimation KEYWORD2
|
||||
IsAnimationActive KEYWORD2
|
||||
AnimationDuration KEYWORD2
|
||||
ChangeAnimationDuration KEYWORD2
|
||||
UpdateAnimations KEYWORD2
|
||||
IsPaused KEYWORD2
|
||||
Pause KEYWORD2
|
||||
@ -126,29 +208,38 @@ setTimeScale KEYWORD2
|
||||
QuadraticIn KEYWORD2
|
||||
QuadraticOut KEYWORD2
|
||||
QuadraticInOut KEYWORD2
|
||||
QuadraticCenter KEYWORD2
|
||||
CubicIn KEYWORD2
|
||||
CubicOut KEYWORD2
|
||||
CubicInOut KEYWORD2
|
||||
CubicCenter KEYWORD2
|
||||
QuarticIn KEYWORD2
|
||||
QuarticOut KEYWORD2
|
||||
QuarticInOut KEYWORD2
|
||||
QuarticCenter KEYWORD2
|
||||
QuinticIn KEYWORD2
|
||||
QuinticOut KEYWORD2
|
||||
QuinticInOut KEYWORD2
|
||||
QuinticCenter KEYWORD2
|
||||
SinusoidalIn KEYWORD2
|
||||
SinusoidalOut KEYWORD2
|
||||
SinusoidalInOut KEYWORD2
|
||||
SinusoidalCenter KEYWORD2
|
||||
ExponentialIn KEYWORD2
|
||||
ExponentialOut KEYWORD2
|
||||
ExponentialInOut KEYWORD2
|
||||
ExponentialCenter KEYWORD2
|
||||
CircularIn KEYWORD2
|
||||
CircularOut KEYWORD2
|
||||
CircularInOut KEYWORD2
|
||||
CircularCenter KEYWORD2
|
||||
Gamma KEYWORD2
|
||||
Map KEYWORD2
|
||||
MapProbe KEYWORD2
|
||||
getWidth KEYWORD2
|
||||
getHeight KEYWORD2
|
||||
RingPixelShift KEYWORD2
|
||||
RingPixelRotate KEYWORD2
|
||||
getCountOfRings KEYWORD2
|
||||
getPixelCountAtRing KEYWORD2
|
||||
getPixelCount KEYWORD2
|
14
lib/NeoPixelBus-2.5.0.09/library.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "NeoPixelBus",
|
||||
"keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, RGB, RGBW",
|
||||
"description": "A library that makes controlling NeoPixels (WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102) easy. Supports most Arduino platforms. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang. For Esp32 it has two base methods of sending NeoPixel data, i2s and RMT. For all platforms, there are two methods of sending DotStar data, hardware SPI and software SPI.",
|
||||
"homepage": "https://github.com/Makuna/NeoPixelBus/wiki",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Makuna/NeoPixelBus"
|
||||
},
|
||||
"version": "2.5.0",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=NeoPixelBus by Makuna
|
||||
version=2.2.9
|
||||
version=2.5.0
|
||||
author=Michael C. Miller (makuna@live.com)
|
||||
maintainer=Michael C. Miller (makuna@live.com)
|
||||
sentence=A library that makes controlling NeoPixels (WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102) easy.
|
||||
paragraph=Supports most Arduino platforms, including Esp8266 and Esp32. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang; and two methods of sending DotStar data, hardware SPI and software SPI.
|
||||
paragraph=Supports most Arduino platforms, including Esp8266 and Esp32. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang. For Esp32 it has two base methods of sending NeoPixel data, i2s and RMT. For all platforms, there are two methods of sending DotStar data, hardware SPI and software SPI.
|
||||
category=Display
|
||||
url=https://github.com/Makuna/NeoPixelBus/wiki
|
||||
architectures=*
|
@ -109,6 +109,8 @@ public:
|
||||
return _animations[indexAnimation]._duration;
|
||||
}
|
||||
|
||||
void ChangeAnimationDuration(uint16_t indexAnimation, uint16_t newDuration);
|
||||
|
||||
void UpdateAnimations();
|
||||
|
||||
bool IsPaused()
|
||||
@ -159,6 +161,11 @@ private:
|
||||
_remaining = 0;
|
||||
}
|
||||
|
||||
float CurrentProgress()
|
||||
{
|
||||
return (float)(_duration - _remaining) / (float)_duration;
|
||||
}
|
||||
|
||||
uint16_t _duration;
|
||||
uint16_t _remaining;
|
||||
|
@ -57,8 +57,9 @@ License along with NeoPixel. If not, see
|
||||
#include "internal/NeoBufferMethods.h"
|
||||
#include "internal/NeoBuffer.h"
|
||||
#include "internal/NeoSpriteSheet.h"
|
||||
#include "internal/NeoBitmapFile.h"
|
||||
#include "internal/NeoDib.h"
|
||||
#include "internal/NeoBitmapFile.h"
|
||||
|
||||
#include "internal/NeoEase.h"
|
||||
#include "internal/NeoGamma.h"
|
||||
|
||||
@ -71,6 +72,8 @@ License along with NeoPixel. If not, see
|
||||
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
|
||||
#include "internal/NeoEsp32I2sMethod.h"
|
||||
#include "internal/NeoEsp32RmtMethod.h"
|
||||
#include "internal/NeoEspBitBangMethod.h"
|
||||
#include "internal/DotStarGenericMethod.h"
|
||||
|
||||
@ -136,14 +139,21 @@ public:
|
||||
Dirty();
|
||||
}
|
||||
|
||||
void Show()
|
||||
// used by DotStartSpiMethod if pins can be configured
|
||||
void Begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
_method.Initialize(sck, miso, mosi, ss);
|
||||
Dirty();
|
||||
}
|
||||
|
||||
void Show(bool maintainBufferConsistency = true)
|
||||
{
|
||||
if (!IsDirty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_method.Update();
|
||||
_method.Update(maintainBufferConsistency);
|
||||
|
||||
ResetDirty();
|
||||
}
|
||||
@ -321,7 +331,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void SwapPixelColor(uint16_t indexPixelOne, uint16_t indexPixelTwo)
|
||||
{
|
||||
auto colorOne = GetPixelColor(indexPixelOne);
|
||||
auto colorTwo = GetPixelColor(indexPixelTwo);
|
||||
|
||||
SetPixelColor(indexPixelOne, colorTwo);
|
||||
SetPixelColor(indexPixelTwo, colorOne);
|
||||
};
|
||||
|
||||
protected:
|
||||
const uint16_t _countPixels; // Number of RGB LEDs in strip
|
@ -68,7 +68,7 @@ public:
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update(bool)
|
||||
{
|
||||
// start frame
|
||||
for (int startFrameByte = 0; startFrameByte < 4; startFrameByte++)
|
@ -324,3 +324,332 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/* RGB Feature -- Some APA102s ship in RGB order */
|
||||
class DotStarRgbFeature : public DotStar3Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xff; // upper three bits are always 111 and brightness at max
|
||||
*p++ = color.R;
|
||||
*p++ = color.G;
|
||||
*p = color.B;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
p++; // ignore the first byte
|
||||
color.R = *p++;
|
||||
color.G = *p++;
|
||||
color.B = *p;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
pgm_read_byte(p++); // ignore the first byte
|
||||
color.R = pgm_read_byte(p++);
|
||||
color.G = pgm_read_byte(p++);
|
||||
color.B = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class DotStarLrgbFeature : public DotStar4Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111
|
||||
*p++ = color.R;
|
||||
*p++ = color.G;
|
||||
*p = color.B;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.W = (*p++) & 0x1F; // mask out upper three bits
|
||||
color.R = *p++;
|
||||
color.G = *p++;
|
||||
color.B = *p;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
|
||||
color.R = pgm_read_byte(p++);
|
||||
color.G = pgm_read_byte(p++);
|
||||
color.B = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
/* RBG Feature -- Some APA102s ship in RBG order */
|
||||
class DotStarRbgFeature : public DotStar3Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xff; // upper three bits are always 111 and brightness at max
|
||||
*p++ = color.R;
|
||||
*p++ = color.B;
|
||||
*p = color.G;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
p++; // ignore the first byte
|
||||
color.R = *p++;
|
||||
color.B = *p++;
|
||||
color.G = *p;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
pgm_read_byte(p++); // ignore the first byte
|
||||
color.R = pgm_read_byte(p++);
|
||||
color.B = pgm_read_byte(p++);
|
||||
color.G = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class DotStarLrbgFeature : public DotStar4Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111
|
||||
*p++ = color.R;
|
||||
*p++ = color.B;
|
||||
*p = color.G;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.W = (*p++) & 0x1F; // mask out upper three bits
|
||||
color.R = *p++;
|
||||
color.B = *p++;
|
||||
color.G = *p;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
|
||||
color.R = pgm_read_byte(p++);
|
||||
color.B = pgm_read_byte(p++);
|
||||
color.G = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* GBR Feature -- Some APA102s ship in GBR order */
|
||||
class DotStarGbrFeature : public DotStar3Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xff; // upper three bits are always 111 and brightness at max
|
||||
*p++ = color.G;
|
||||
*p++ = color.B;
|
||||
*p = color.R;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
p++; // ignore the first byte
|
||||
color.G = *p++;
|
||||
color.B = *p++;
|
||||
color.R = *p;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
pgm_read_byte(p++); // ignore the first byte
|
||||
color.G = pgm_read_byte(p++);
|
||||
color.B = pgm_read_byte(p++);
|
||||
color.R = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class DotStarLgbrFeature : public DotStar4Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111
|
||||
*p++ = color.G;
|
||||
*p++ = color.B;
|
||||
*p = color.R;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.W = (*p++) & 0x1F; // mask out upper three bits
|
||||
color.G = *p++;
|
||||
color.B = *p++;
|
||||
color.R = *p;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
|
||||
color.G = pgm_read_byte(p++);
|
||||
color.B = pgm_read_byte(p++);
|
||||
color.R = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
/* BRG Feature -- Some APA102s ship in BRG order */
|
||||
class DotStarBrgFeature : public DotStar3Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xff; // upper three bits are always 111 and brightness at max
|
||||
*p++ = color.B;
|
||||
*p++ = color.R;
|
||||
*p = color.G;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
p++; // ignore the first byte
|
||||
color.B = *p++;
|
||||
color.R = *p++;
|
||||
color.G = *p;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
pgm_read_byte(p++); // ignore the first byte
|
||||
color.B = pgm_read_byte(p++);
|
||||
color.R = pgm_read_byte(p++);
|
||||
color.G = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class DotStarLbrgFeature : public DotStar4Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111
|
||||
*p++ = color.B;
|
||||
*p++ = color.R;
|
||||
*p = color.G;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.W = (*p++) & 0x1F; // mask out upper three bits
|
||||
color.B = *p++;
|
||||
color.R = *p++;
|
||||
color.G = *p;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
|
||||
color.B = pgm_read_byte(p++);
|
||||
color.R = pgm_read_byte(p++);
|
||||
color.G = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
@ -60,7 +60,7 @@ public:
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update(bool)
|
||||
{
|
||||
// start frame
|
||||
for (int startFrameByte = 0; startFrameByte < 4; startFrameByte++)
|
@ -51,29 +51,37 @@ public:
|
||||
return true; // dot stars don't have a required delay
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
SPI.begin(sck, miso, mosi, ss);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
SPI.begin();
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
SPI.setFrequency(20000000L);
|
||||
#elif defined(ARDUINO_ARCH_AVR)
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (6 MHz on Pro Trinket 3V)
|
||||
#else
|
||||
SPI.setClockDivider((F_CPU + 4000000L) / 8000000L); // 8-ish MHz on Due
|
||||
#endif
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
SPI.setDataMode(SPI_MODE0);
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update(bool)
|
||||
{
|
||||
// due to API inconsistencies need to call different methods on SPI
|
||||
SPI.beginTransaction(SPISettings(20000000L, MSBFIRST, SPI_MODE0));
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
// ESPs have a method to write without inplace overwriting the send buffer
|
||||
// since we don't care what gets received, use it for performance
|
||||
SPI.writeBytes(_sendBuffer, _sizeSendBuffer);
|
||||
|
||||
#else
|
||||
SPI.transfer(_sendBuffer, _sizeSendBuffer);
|
||||
// default ARDUINO transfer inplace overwrites the send buffer
|
||||
// which is bad, so we have to send one byte at a time
|
||||
uint8_t* out = _sendBuffer;
|
||||
uint8_t* end = out + _sizeSendBuffer;
|
||||
while (out < end)
|
||||
{
|
||||
SPI.transfer(*out++);
|
||||
}
|
||||
#endif
|
||||
SPI.endTransaction();
|
||||
}
|
||||
|
||||
uint8_t* getPixels() const
|
484
lib/NeoPixelBus-2.5.0.09/src/internal/Esp32_i2s.c
Normal file
@ -0,0 +1,484 @@
|
||||
// WARNING: This file contains code that is more than likely already
|
||||
// exposed from the Esp32 Arduino API. It will be removed once integration is complete.
|
||||
//
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#include "esp_intr.h"
|
||||
#include "rom/ets_sys.h"
|
||||
#include "soc/gpio_reg.h"
|
||||
#include "soc/gpio_sig_map.h"
|
||||
#include "soc/io_mux_reg.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/i2s_struct.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/sens_reg.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2s.h"
|
||||
#include "driver/dac.h"
|
||||
#include "Esp32_i2s.h"
|
||||
#include "esp32-hal.h"
|
||||
|
||||
#define I2S_BASE_CLK (160000000L)
|
||||
#define ESP32_REG(addr) (*((volatile uint32_t*)(0x3FF00000+(addr))))
|
||||
|
||||
#define I2S_DMA_QUEUE_SIZE 16
|
||||
|
||||
#define I2S_DMA_SILENCE_LEN 256 // bytes
|
||||
|
||||
typedef struct i2s_dma_item_s {
|
||||
uint32_t blocksize: 12; // datalen
|
||||
uint32_t datalen : 12; // len*(bits_per_sample/8)*2 => max 2047*8bit/1023*16bit samples
|
||||
uint32_t unused : 5; // 0
|
||||
uint32_t sub_sof : 1; // 0
|
||||
uint32_t eof : 1; // 1 => last?
|
||||
uint32_t owner : 1; // 1
|
||||
|
||||
void* data; // malloc(datalen)
|
||||
struct i2s_dma_item_s* next;
|
||||
|
||||
// if this pointer is not null, it will be freed
|
||||
void* free_ptr;
|
||||
|
||||
// if DMA buffers are preallocated
|
||||
uint8_t* buf;
|
||||
} i2s_dma_item_t;
|
||||
|
||||
typedef struct {
|
||||
i2s_dev_t* bus;
|
||||
int8_t ws;
|
||||
int8_t bck;
|
||||
int8_t out;
|
||||
int8_t in;
|
||||
uint32_t rate;
|
||||
intr_handle_t isr_handle;
|
||||
xQueueHandle tx_queue;
|
||||
|
||||
uint8_t* silence_buf;
|
||||
size_t silence_len;
|
||||
|
||||
i2s_dma_item_t* dma_items;
|
||||
size_t dma_count;
|
||||
uint32_t dma_buf_len :12;
|
||||
uint32_t unused :20;
|
||||
} i2s_bus_t;
|
||||
|
||||
static uint8_t i2s_silence_buf[I2S_DMA_SILENCE_LEN];
|
||||
|
||||
static i2s_bus_t I2S[2] = {
|
||||
{&I2S0, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_LEN, NULL, I2S_DMA_QUEUE_SIZE, 0, 0},
|
||||
{&I2S1, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_LEN, NULL, I2S_DMA_QUEUE_SIZE, 0, 0}
|
||||
};
|
||||
|
||||
void IRAM_ATTR i2sDmaISR(void* arg);
|
||||
bool i2sInitDmaItems(uint8_t bus_num);
|
||||
|
||||
bool i2sInitDmaItems(uint8_t bus_num) {
|
||||
if (bus_num > 1) {
|
||||
return false;
|
||||
}
|
||||
if (I2S[bus_num].tx_queue) {// already set
|
||||
return true;
|
||||
}
|
||||
|
||||
if (I2S[bus_num].dma_items == NULL) {
|
||||
I2S[bus_num].dma_items = (i2s_dma_item_t*)(malloc(I2S[bus_num].dma_count* sizeof(i2s_dma_item_t)));
|
||||
if (I2S[bus_num].dma_items == NULL) {
|
||||
log_e("MEM ERROR!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int i, i2, a;
|
||||
i2s_dma_item_t* item;
|
||||
|
||||
for(i=0; i<I2S[bus_num].dma_count; i++) {
|
||||
i2 = (i+1) % I2S[bus_num].dma_count;
|
||||
item = &I2S[bus_num].dma_items[i];
|
||||
item->eof = 1;
|
||||
item->owner = 1;
|
||||
item->sub_sof = 0;
|
||||
item->unused = 0;
|
||||
item->data = I2S[bus_num].silence_buf;
|
||||
item->blocksize = I2S[bus_num].silence_len;
|
||||
item->datalen = I2S[bus_num].silence_len;
|
||||
item->next = &I2S[bus_num].dma_items[i2];
|
||||
item->free_ptr = NULL;
|
||||
if (I2S[bus_num].dma_buf_len) {
|
||||
item->buf = (uint8_t*)(malloc(I2S[bus_num].dma_buf_len));
|
||||
if (item->buf == NULL) {
|
||||
log_e("MEM ERROR!");
|
||||
for(a=0; a<i; a++) {
|
||||
free(I2S[bus_num].dma_items[i].buf);
|
||||
}
|
||||
free(I2S[bus_num].dma_items);
|
||||
I2S[bus_num].dma_items = NULL;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
item->buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
I2S[bus_num].tx_queue = xQueueCreate(I2S[bus_num].dma_count, sizeof(i2s_dma_item_t*));
|
||||
if (I2S[bus_num].tx_queue == NULL) {// memory error
|
||||
log_e("MEM ERROR!");
|
||||
free(I2S[bus_num].dma_items);
|
||||
I2S[bus_num].dma_items = NULL;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void i2sSetSilenceBuf(uint8_t bus_num, uint8_t* data, size_t len) {
|
||||
if (bus_num > 1 || !data || !len) {
|
||||
return;
|
||||
}
|
||||
I2S[bus_num].silence_buf = data;
|
||||
I2S[bus_num].silence_len = len;
|
||||
}
|
||||
|
||||
esp_err_t i2sSetClock(uint8_t bus_num, uint8_t div_num, uint8_t div_b, uint8_t div_a, uint8_t bck, uint8_t bits) {
|
||||
if (bus_num > 1 || div_a > 63 || div_b > 63 || bck > 63) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
i2s_dev_t* i2s = I2S[bus_num].bus;
|
||||
i2s->clkm_conf.clka_en = 0;
|
||||
i2s->clkm_conf.clkm_div_a = div_a;
|
||||
i2s->clkm_conf.clkm_div_b = div_b;
|
||||
i2s->clkm_conf.clkm_div_num = div_num;
|
||||
i2s->sample_rate_conf.tx_bck_div_num = bck;
|
||||
i2s->sample_rate_conf.rx_bck_div_num = bck;
|
||||
i2s->sample_rate_conf.tx_bits_mod = bits;
|
||||
i2s->sample_rate_conf.rx_bits_mod = bits;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void i2sSetTxDataMode(uint8_t bus_num, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod) {
|
||||
if (bus_num > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
I2S[bus_num].bus->conf_chan.tx_chan_mod = chan_mod; // 0:dual channel; 1:right channel; 2:left channel; 3:left channel constant; 4:right channel constant; (channels flipped if tx_msb_right == 1)
|
||||
I2S[bus_num].bus->fifo_conf.tx_fifo_mod = fifo_mod; // 0:16-bit dual channel; 1:16-bit single channel; 2:32-bit dual channel; 3:32-bit single channel data
|
||||
}
|
||||
|
||||
void i2sSetDac(uint8_t bus_num, bool right, bool left) {
|
||||
if (bus_num > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!right && !left) {
|
||||
dac_output_disable(1);
|
||||
dac_output_disable(2);
|
||||
dac_i2s_disable();
|
||||
I2S[bus_num].bus->conf2.lcd_en = 0;
|
||||
I2S[bus_num].bus->conf.tx_right_first = 0;
|
||||
I2S[bus_num].bus->conf2.camera_en = 0;
|
||||
I2S[bus_num].bus->conf.tx_msb_shift = 1;// I2S signaling
|
||||
return;
|
||||
}
|
||||
|
||||
i2sSetPins(bus_num, -1, -1, -1, -1);
|
||||
I2S[bus_num].bus->conf2.lcd_en = 1;
|
||||
I2S[bus_num].bus->conf.tx_right_first = 0;
|
||||
I2S[bus_num].bus->conf2.camera_en = 0;
|
||||
I2S[bus_num].bus->conf.tx_msb_shift = 0;
|
||||
dac_i2s_enable();
|
||||
|
||||
if (right) {// DAC1, right channel, GPIO25
|
||||
dac_output_enable(1);
|
||||
}
|
||||
if (left) { // DAC2, left channel, GPIO26
|
||||
dac_output_enable(2);
|
||||
}
|
||||
}
|
||||
|
||||
void i2sSetPins(uint8_t bus_num, int8_t out, int8_t ws, int8_t bck, int8_t in) {
|
||||
if (bus_num > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ws >= 0 && I2S[bus_num].ws == -1) || (bck >= 0 && I2S[bus_num].bck == -1) || (out >= 0 && I2S[bus_num].out == -1)) {
|
||||
i2sSetDac(bus_num, false, false);
|
||||
}
|
||||
|
||||
if (ws >= 0) {
|
||||
if (I2S[bus_num].ws != ws) {
|
||||
if (I2S[bus_num].ws >= 0) {
|
||||
gpio_matrix_out(I2S[bus_num].ws, 0x100, false, false);
|
||||
}
|
||||
I2S[bus_num].ws = ws;
|
||||
pinMode(ws, OUTPUT);
|
||||
gpio_matrix_out(ws, bus_num?I2S1O_WS_OUT_IDX:I2S0O_WS_OUT_IDX, false, false);
|
||||
}
|
||||
} else if (I2S[bus_num].ws >= 0) {
|
||||
gpio_matrix_out(I2S[bus_num].ws, 0x100, false, false);
|
||||
I2S[bus_num].ws = -1;
|
||||
}
|
||||
|
||||
if (bck >= 0) {
|
||||
if (I2S[bus_num].bck != bck) {
|
||||
if (I2S[bus_num].bck >= 0) {
|
||||
gpio_matrix_out(I2S[bus_num].bck, 0x100, false, false);
|
||||
}
|
||||
I2S[bus_num].bck = bck;
|
||||
pinMode(bck, OUTPUT);
|
||||
gpio_matrix_out(bck, bus_num?I2S1O_BCK_OUT_IDX:I2S0O_BCK_OUT_IDX, false, false);
|
||||
}
|
||||
} else if (I2S[bus_num].bck >= 0) {
|
||||
gpio_matrix_out(I2S[bus_num].bck, 0x100, false, false);
|
||||
I2S[bus_num].bck = -1;
|
||||
}
|
||||
|
||||
if (out >= 0) {
|
||||
if (I2S[bus_num].out != out) {
|
||||
if (I2S[bus_num].out >= 0) {
|
||||
gpio_matrix_out(I2S[bus_num].out, 0x100, false, false);
|
||||
}
|
||||
I2S[bus_num].out = out;
|
||||
pinMode(out, OUTPUT);
|
||||
gpio_matrix_out(out, bus_num?I2S1O_DATA_OUT23_IDX:I2S0O_DATA_OUT23_IDX, false, false);
|
||||
}
|
||||
} else if (I2S[bus_num].out >= 0) {
|
||||
gpio_matrix_out(I2S[bus_num].out, 0x100, false, false);
|
||||
I2S[bus_num].out = -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool i2sWriteDone(uint8_t bus_num) {
|
||||
if (bus_num > 1) {
|
||||
return false;
|
||||
}
|
||||
return (I2S[bus_num].dma_items[I2S[bus_num].dma_count - 1].data == I2S[bus_num].silence_buf);
|
||||
}
|
||||
|
||||
void i2sInit(uint8_t bus_num, uint32_t bits_per_sample, uint32_t sample_rate, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod, size_t dma_count, size_t dma_len) {
|
||||
if (bus_num > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
I2S[bus_num].dma_count = dma_count;
|
||||
I2S[bus_num].dma_buf_len = dma_len & 0xFFF;
|
||||
|
||||
if (!i2sInitDmaItems(bus_num)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bus_num) {
|
||||
periph_module_enable(PERIPH_I2S1_MODULE);
|
||||
} else {
|
||||
periph_module_enable(PERIPH_I2S0_MODULE);
|
||||
}
|
||||
|
||||
esp_intr_disable(I2S[bus_num].isr_handle);
|
||||
i2s_dev_t* i2s = I2S[bus_num].bus;
|
||||
i2s->out_link.stop = 1;
|
||||
i2s->conf.tx_start = 0;
|
||||
i2s->int_ena.val = 0;
|
||||
i2s->int_clr.val = 0xFFFFFFFF;
|
||||
i2s->fifo_conf.dscr_en = 0;
|
||||
|
||||
// reset fifo
|
||||
i2s->conf.rx_fifo_reset = 1;
|
||||
i2s->conf.rx_fifo_reset = 0;
|
||||
i2s->conf.tx_fifo_reset = 1;
|
||||
i2s->conf.tx_fifo_reset = 0;
|
||||
|
||||
// reset i2s
|
||||
i2s->conf.tx_reset = 1;
|
||||
i2s->conf.tx_reset = 0;
|
||||
i2s->conf.rx_reset = 1;
|
||||
i2s->conf.rx_reset = 0;
|
||||
|
||||
// reset dma
|
||||
i2s->lc_conf.in_rst = 1;
|
||||
i2s->lc_conf.in_rst = 0;
|
||||
i2s->lc_conf.out_rst = 1;
|
||||
i2s->lc_conf.out_rst = 0;
|
||||
|
||||
// Enable and configure DMA
|
||||
i2s->lc_conf.check_owner = 0;
|
||||
i2s->lc_conf.out_loop_test = 0;
|
||||
i2s->lc_conf.out_auto_wrback = 0;
|
||||
i2s->lc_conf.out_data_burst_en = 0;
|
||||
i2s->lc_conf.outdscr_burst_en = 0;
|
||||
i2s->lc_conf.out_no_restart_clr = 0;
|
||||
i2s->lc_conf.indscr_burst_en = 0;
|
||||
i2s->lc_conf.out_eof_mode = 1;
|
||||
|
||||
i2s->pdm_conf.pcm2pdm_conv_en = 0;
|
||||
i2s->pdm_conf.pdm2pcm_conv_en = 0;
|
||||
// SET_PERI_REG_BITS(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, 0x1, RTC_CNTL_SOC_CLK_SEL_S);
|
||||
|
||||
|
||||
i2s->conf_chan.tx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left
|
||||
i2s->conf_chan.rx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left
|
||||
i2s->fifo_conf.tx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel
|
||||
i2s->fifo_conf.rx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel
|
||||
|
||||
i2s->conf.tx_mono = 0;
|
||||
i2s->conf.rx_mono = 0;
|
||||
|
||||
i2s->conf.tx_start = 0;
|
||||
i2s->conf.rx_start = 0;
|
||||
|
||||
i2s->conf.tx_short_sync = 0;
|
||||
i2s->conf.rx_short_sync = 0;
|
||||
i2s->conf.tx_msb_shift = (bits_per_sample != 8);// 0:DAC/PCM, 1:I2S
|
||||
i2s->conf.rx_msb_shift = 0;
|
||||
|
||||
i2s->conf.tx_slave_mod = 0; // Master
|
||||
|
||||
i2s->conf.tx_msb_right = 0;
|
||||
i2s->conf.tx_right_first = (bits_per_sample == 8);
|
||||
i2s->conf2.lcd_en = (bits_per_sample == 8);
|
||||
i2s->conf2.camera_en = 0;
|
||||
|
||||
i2s->fifo_conf.tx_fifo_mod_force_en = 1;
|
||||
|
||||
i2s->pdm_conf.rx_pdm_en = 0;
|
||||
i2s->pdm_conf.tx_pdm_en = 0;
|
||||
|
||||
i2sSetSampleRate(bus_num, sample_rate, bits_per_sample);
|
||||
|
||||
// enable intr in cpu //
|
||||
esp_intr_alloc(bus_num?ETS_I2S1_INTR_SOURCE:ETS_I2S0_INTR_SOURCE, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1, &i2sDmaISR, &I2S[bus_num], &I2S[bus_num].isr_handle);
|
||||
// enable send intr
|
||||
i2s->int_ena.out_eof = 1;
|
||||
i2s->int_ena.out_dscr_err = 1;
|
||||
|
||||
i2s->fifo_conf.dscr_en = 1;// enable dma
|
||||
i2s->out_link.start = 0;
|
||||
i2s->out_link.addr = (uint32_t)(&I2S[bus_num].dma_items[0]); // loads dma_struct to dma
|
||||
i2s->out_link.start = 1; // starts dma
|
||||
i2s->conf.tx_start = 1;// Start I2s module
|
||||
|
||||
esp_intr_enable(I2S[bus_num].isr_handle);
|
||||
}
|
||||
|
||||
esp_err_t i2sSetSampleRate(uint8_t bus_num, uint32_t rate, uint8_t bits) {
|
||||
if (bus_num > 1) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (I2S[bus_num].rate == rate) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int clkmInteger, clkmDecimals, bck = 0;
|
||||
double denom = (double)1 / 63;
|
||||
int channel = 2;
|
||||
|
||||
// double mclk;
|
||||
double clkmdiv;
|
||||
|
||||
int factor;
|
||||
|
||||
if (bits == 8) {
|
||||
factor = 120;
|
||||
} else {
|
||||
factor = (256 % bits) ? 384 : 256;
|
||||
}
|
||||
|
||||
clkmdiv = (double)I2S_BASE_CLK / (rate* factor);
|
||||
if (clkmdiv > 256) {
|
||||
log_e("rate is too low");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
I2S[bus_num].rate = rate;
|
||||
|
||||
clkmInteger = clkmdiv;
|
||||
clkmDecimals = ((clkmdiv - clkmInteger) / denom);
|
||||
|
||||
if (bits == 8) {
|
||||
// mclk = rate* factor;
|
||||
bck = 60;
|
||||
bits = 16;
|
||||
} else {
|
||||
// mclk = (double)clkmInteger + (denom* clkmDecimals);
|
||||
bck = factor/(bits* channel);
|
||||
}
|
||||
|
||||
i2sSetClock(bus_num, clkmInteger, clkmDecimals, 63, bck, bits);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void IRAM_ATTR i2sDmaISR(void* arg)
|
||||
{
|
||||
i2s_dma_item_t* dummy = NULL;
|
||||
i2s_bus_t* dev = (i2s_bus_t*)(arg);
|
||||
portBASE_TYPE hpTaskAwoken = 0;
|
||||
|
||||
if (dev->bus->int_st.out_eof) {
|
||||
i2s_dma_item_t* item = (i2s_dma_item_t*)(dev->bus->out_eof_des_addr);
|
||||
item->data = dev->silence_buf;
|
||||
item->blocksize = dev->silence_len;
|
||||
item->datalen = dev->silence_len;
|
||||
if (xQueueIsQueueFullFromISR(dev->tx_queue) == pdTRUE) {
|
||||
xQueueReceiveFromISR(dev->tx_queue, &dummy, &hpTaskAwoken);
|
||||
}
|
||||
xQueueSendFromISR(dev->tx_queue, (void*)&item, &hpTaskAwoken);
|
||||
}
|
||||
dev->bus->int_clr.val = dev->bus->int_st.val;
|
||||
if (hpTaskAwoken == pdTRUE) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
size_t i2sWrite(uint8_t bus_num, uint8_t* data, size_t len, bool copy, bool free_when_sent) {
|
||||
if (bus_num > 1 || !I2S[bus_num].tx_queue) {
|
||||
return 0;
|
||||
}
|
||||
size_t index = 0;
|
||||
size_t toSend = len;
|
||||
size_t limit = I2S_DMA_MAX_DATA_LEN;
|
||||
i2s_dma_item_t* item = NULL;
|
||||
|
||||
while (len) {
|
||||
toSend = len;
|
||||
if (toSend > limit) {
|
||||
toSend = limit;
|
||||
}
|
||||
|
||||
if (xQueueReceive(I2S[bus_num].tx_queue, &item, portMAX_DELAY) == pdFALSE) {
|
||||
log_e("xQueueReceive failed\n");
|
||||
break;
|
||||
}
|
||||
// data is constant. no need to copy
|
||||
item->data = data + index;
|
||||
item->blocksize = toSend;
|
||||
item->datalen = toSend;
|
||||
|
||||
len -= toSend;
|
||||
index += toSend;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
40
lib/NeoPixelBus-2.5.0.09/src/internal/Esp32_i2s.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#define I2S_DMA_MAX_DATA_LEN 4092// maximum bytes in one dma item
|
||||
|
||||
typedef enum {
|
||||
I2S_CHAN_STEREO, I2S_CHAN_RIGHT_TO_LEFT, I2S_CHAN_LEFT_TO_RIGHT, I2S_CHAN_RIGHT_ONLY, I2S_CHAN_LEFT_ONLY
|
||||
} i2s_tx_chan_mod_t;
|
||||
|
||||
typedef enum {
|
||||
I2S_FIFO_16BIT_DUAL, I2S_FIFO_16BIT_SINGLE, I2S_FIFO_32BIT_DUAL, I2S_FIFO_32BIT_SINGLE
|
||||
} i2s_tx_fifo_mod_t;
|
||||
|
||||
void i2sInit(uint8_t bus_num, uint32_t bits_per_sample, uint32_t sample_rate, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod, size_t dma_count, size_t dma_len);
|
||||
|
||||
void i2sSetPins(uint8_t bus_num, int8_t out, int8_t ws, int8_t bck, int8_t in);
|
||||
void i2sSetDac(uint8_t bus_num, bool right, bool left);
|
||||
|
||||
esp_err_t i2sSetClock(uint8_t bus_num, uint8_t div_num, uint8_t div_b, uint8_t div_a, uint8_t bck, uint8_t bits_per_sample);
|
||||
esp_err_t i2sSetSampleRate(uint8_t bus_num, uint32_t sample_rate, uint8_t bits_per_sample);
|
||||
|
||||
void i2sSetTxDataMode(uint8_t bus_num, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod);
|
||||
|
||||
void i2sSetSilenceBuf(uint8_t bus_num, uint8_t* data, size_t len);
|
||||
|
||||
size_t i2sWrite(uint8_t bus_num, uint8_t* data, size_t len, bool copy, bool free_when_sent);
|
||||
bool i2sWriteDone(uint8_t bus_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -212,7 +212,7 @@ struct HtmlColor
|
||||
for (uint8_t indexName = 0; indexName < T_HTMLCOLORNAMES::Count(); ++indexName)
|
||||
{
|
||||
const HtmlColorPair* colorPair = T_HTMLCOLORNAMES::Pair(indexName);
|
||||
PGM_P searchName = (PGM_P)pgm_read_ptr(&colorPair->Name);
|
||||
PGM_P searchName = reinterpret_cast<PGM_P>(pgm_read_ptr(&(colorPair->Name)));
|
||||
size_t str1Size = nameSize;
|
||||
const char* str1 = name;
|
||||
const char* str2P = searchName;
|
@ -57,7 +57,7 @@ public:
|
||||
class RowMajorLayout : public RowMajorTilePreference
|
||||
{
|
||||
public:
|
||||
static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y)
|
||||
static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y)
|
||||
{
|
||||
return x + y * width;
|
||||
}
|
||||
@ -102,7 +102,7 @@ public:
|
||||
class RowMajor270Layout : public RowMajorTilePreference
|
||||
{
|
||||
public:
|
||||
static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y)
|
||||
static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y)
|
||||
{
|
||||
return x * height + (height - 1 - y);
|
||||
}
|
||||
@ -136,7 +136,7 @@ public:
|
||||
class ColumnMajorLayout : public ColumnMajorTilePreference
|
||||
{
|
||||
public:
|
||||
static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y)
|
||||
static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y)
|
||||
{
|
||||
return x * height + y;
|
||||
}
|
||||
@ -151,7 +151,7 @@ public:
|
||||
class ColumnMajor90Layout : public ColumnMajorTilePreference
|
||||
{
|
||||
public:
|
||||
static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y)
|
||||
static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y)
|
||||
{
|
||||
return (width - 1 - x) + y * width;
|
||||
}
|
||||
@ -213,7 +213,7 @@ public:
|
||||
class RowMajorAlternatingLayout : public RowMajorAlternatingTilePreference
|
||||
{
|
||||
public:
|
||||
static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y)
|
||||
static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y)
|
||||
{
|
||||
uint16_t index = y * width;
|
||||
|
||||
@ -290,7 +290,7 @@ public:
|
||||
class RowMajorAlternating270Layout : public RowMajorAlternatingTilePreference
|
||||
{
|
||||
public:
|
||||
static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y)
|
||||
static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y)
|
||||
{
|
||||
uint16_t index = x * height;
|
||||
|
||||
@ -332,7 +332,7 @@ public:
|
||||
class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference
|
||||
{
|
||||
public:
|
||||
static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y)
|
||||
static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y)
|
||||
{
|
||||
uint16_t index = x * height;
|
||||
|
||||
@ -357,7 +357,7 @@ public:
|
||||
class ColumnMajorAlternating90Layout : public ColumnMajorAlternatingTilePreference
|
||||
{
|
||||
public:
|
||||
static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y)
|
||||
static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y)
|
||||
{
|
||||
uint16_t index = y * width;
|
||||
|
@ -66,7 +66,7 @@ public:
|
||||
_endTime = micros();
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update(bool)
|
||||
{
|
||||
// Data latch = 50+ microsecond pause in the output stream. Rather than
|
||||
// put a delay at the end of the function, the ending time is noted and
|
||||
@ -106,24 +106,32 @@ private:
|
||||
uint8_t _pin; // output pin number
|
||||
};
|
||||
|
||||
// Teensy 3.0 or 3.1 (3.2) or 3.5 or 3.6
|
||||
#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
|
||||
#if defined(__MK20DX128__) || defined(__MK20DX256__) // Teensy 3.0 & 3.1
|
||||
|
||||
class NeoArmMk20dxSpeedPropsWs2813
|
||||
class NeoArmMk20dxSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t CyclesT0h = (F_CPU / 4000000);
|
||||
static const uint32_t CyclesT1h = (F_CPU / 1250000);
|
||||
static const uint32_t Cycles = (F_CPU / 800000);
|
||||
static const uint32_t ResetTimeUs = 250;
|
||||
};
|
||||
|
||||
class NeoArmMk20dxSpeedProps800Kbps
|
||||
class NeoArmMk20dxSpeedPropsWs2812x : public NeoArmMk20dxSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoArmMk20dxSpeedPropsSk6812 : public NeoArmMk20dxSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoArmMk20dxSpeedProps800Kbps : public NeoArmMk20dxSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t CyclesT0h = (F_CPU / 4000000);
|
||||
static const uint32_t CyclesT1h = (F_CPU / 1250000);
|
||||
static const uint32_t Cycles = (F_CPU / 800000);
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
@ -136,6 +144,15 @@ public:
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoArmMk20dxSpeedPropsApa106
|
||||
{
|
||||
public:
|
||||
static const uint32_t CyclesT0h = (F_CPU / 4000000);
|
||||
static const uint32_t CyclesT1h = (F_CPU / 913750);
|
||||
static const uint32_t Cycles = (F_CPU / 584800);
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
template<typename T_SPEEDPROPS> class NeoArmMk20dxSpeedBase
|
||||
{
|
||||
public:
|
||||
@ -180,16 +197,17 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedPropsWs2813>> NeoArmWs2813Method;
|
||||
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedPropsWs2812x>> NeoArmWs2812xMethod;
|
||||
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedPropsSk6812>> NeoArmSk6812Method;
|
||||
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedPropsApa106>> NeoArmApa106Method;
|
||||
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedProps800Kbps>> NeoArm800KbpsMethod;
|
||||
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedProps400Kbps>> NeoArm400KbpsMethod;
|
||||
|
||||
|
||||
#elif defined(__MKL26Z64__) // Teensy-LC
|
||||
|
||||
#if F_CPU == 48000000
|
||||
|
||||
|
||||
|
||||
class NeoArmMk26z64Speed800KbpsBase
|
||||
{
|
||||
public:
|
||||
@ -280,20 +298,28 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class NeoArmMk26z64SpeedWs2813 : public NeoArmMk26z64Speed800KbpsBase
|
||||
class NeoArmMk26z64SpeedWs2812x : public NeoArmMk26z64Speed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t ResetTimeUs = 250;
|
||||
const static uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoArmMk26z64SpeedSk6812 : public NeoArmMk26z64Speed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoArmMk26z64Speed800Kbps : public NeoArmMk26z64Speed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
}
|
||||
};
|
||||
|
||||
typedef NeoArmMethodBase<NeoArmMk26z64SpeedWs2813> NeoArmWs2813Method;
|
||||
typedef NeoArmMethodBase<NeoArmMk26z64SpeedWs2812x> NeoArmWs2812xMethod;
|
||||
typedef NeoArmMethodBase<NeoArmMk26z64SpeedSk6812> NeoArmSk6812Method;
|
||||
typedef NeoArmMethodBase<NeoArmMk26z64Speed800Kbps> NeoArm800KbpsMethod;
|
||||
typedef NeoArm800KbpsMethod NeoArmApa106Method
|
||||
|
||||
#else
|
||||
#error "Teensy-LC: Sorry, only 48 MHz is supported, please set Tools > CPU Speed to 48 MHz"
|
||||
@ -327,10 +353,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class NeoArmSamd21g18aSpeedPropsWs2813 : public NeoArmSamd21g18aSpeedProps800KbpsBase
|
||||
class NeoArmSamd21g18aSpeedPropsWs2812x : public NeoArmSamd21g18aSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 250;
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoArmSamd21g18aSpeedPropsSk6812 : public NeoArmSamd21g18aSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoArmSamd21g18aSpeedProps800Kbps : public NeoArmSamd21g18aSpeedProps800KbpsBase
|
||||
@ -419,11 +451,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef NeoArmMethodBase<NeoArmSamd21g18aSpeedBase<NeoArmSamd21g18aSpeedPropsWs2813>> NeoArmWs2813Method;
|
||||
typedef NeoArmMethodBase<NeoArmSamd21g18aSpeedBase<NeoArmSamd21g18aSpeedPropsWs2812x>> NeoArmWs2812xMethod;
|
||||
typedef NeoArmMethodBase<NeoArmSamd21g18aSpeedBase<NeoArmSamd21g18aSpeedPropsSk6812>> NeoArmSk6812Method;
|
||||
typedef NeoArmMethodBase<NeoArmSamd21g18aSpeedBase<NeoArmSamd21g18aSpeedProps800Kbps>> NeoArm800KbpsMethod;
|
||||
typedef NeoArmMethodBase<NeoArmSamd21g18aSpeedBase<NeoArmSamd21g18aSpeedProps400Kbps>> NeoArm400KbpsMethod;
|
||||
typedef NeoArm400KbpsMethod NeoArmApa106Method
|
||||
|
||||
#elif defined (ARDUINO_STM32_FEATHER) // FEATHER WICED (120MHz)
|
||||
#elif defined(ARDUINO_STM32_FEATHER) || defined(ARDUINO_ARCH_STM32L4) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32F1)// FEATHER WICED (120MHz)
|
||||
|
||||
class NeoArmStm32SpeedProps800KbpsBase
|
||||
{
|
||||
@ -477,18 +511,24 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class NeoArmStm32SpeedPropsWs2812x : public NeoArmStm32SpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoArmStm32SpeedPropsSk6812 : public NeoArmStm32SpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoArmStm32SpeedProps800Kbps : public NeoArmStm32SpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoArmStm32SpeedPropsWs2813 : public NeoArmStm32SpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 250;
|
||||
};
|
||||
|
||||
/* TODO - not found in Adafruit library
|
||||
class NeoArmStm32SpeedProps400Kbps
|
||||
{
|
||||
@ -521,11 +561,36 @@ public:
|
||||
uint8_t* end = ptr + sizePixels;
|
||||
uint8_t p = *ptr++;
|
||||
uint8_t bitMask = 0x80;
|
||||
uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit);
|
||||
|
||||
volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL);
|
||||
volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH);
|
||||
#if defined(ARDUINO_STM32_FEATHER)
|
||||
uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit);
|
||||
|
||||
volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL);
|
||||
volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH);
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32F4)
|
||||
uint32_t pinMask = BIT(pin & 0x0f);
|
||||
|
||||
volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL);
|
||||
volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH);
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32F1)
|
||||
|
||||
uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit);
|
||||
|
||||
volatile uint32_t* set = &(PIN_MAP[pin].gpio_device->regs->BRR);
|
||||
volatile uint32_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRR);
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32L4)
|
||||
|
||||
uint32_t pinMask = g_APinDescription[pin].bit;
|
||||
|
||||
GPIO_TypeDef* GPIO = static_cast<GPIO_TypeDef*>(g_APinDescription[pin].GPIO);
|
||||
|
||||
volatile uint32_t* set = &(GPIO->BRR);
|
||||
volatile uint32_t* clr = &(GPIO->BSRR);
|
||||
|
||||
#endif
|
||||
for (;;)
|
||||
{
|
||||
if (p & bitMask)
|
||||
@ -567,8 +632,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef NeoArmMethodBase<NeoArmStm32SpeedBase<NeoArmStm32SpeedPropsWs2813>> NeoArmWs2813Method;
|
||||
typedef NeoArmMethodBase<NeoArmStm32SpeedBase<NeoArmStm32SpeedPropsWs2812x>> NeoArmWs2812xMethod;
|
||||
typedef NeoArmMethodBase<NeoArmStm32SpeedBase<NeoArmStm32SpeedPropsSk6812>> NeoArmSk6812Method;
|
||||
typedef NeoArmMethodBase<NeoArmStm32SpeedBase<NeoArmStm32SpeedProps800Kbps>> NeoArm800KbpsMethod;
|
||||
typedef NeoArm800KbpsMethod NeoArmApa106Method;
|
||||
|
||||
#else // Other ARM architecture -- Presumed Arduino Due
|
||||
|
||||
@ -576,21 +643,29 @@ typedef NeoArmMethodBase<NeoArmStm32SpeedBase<NeoArmStm32SpeedProps800Kbps>> Neo
|
||||
#define ARM_OTHER_SCALE VARIANT_MCK / 2UL / 1000000UL
|
||||
#define ARM_OTHER_INST (2UL * F_CPU / VARIANT_MCK)
|
||||
|
||||
class NeoArmOtherSpeedPropsWs2813
|
||||
class NeoArmOtherSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t CyclesT0h = ((uint32_t)(0.40 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
|
||||
static const uint32_t CyclesT1h = ((uint32_t)(0.80 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
|
||||
static const uint32_t Cycles = ((uint32_t)(1.25 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
|
||||
static const uint32_t ResetTimeUs = 250;
|
||||
};
|
||||
|
||||
class NeoArmOtherSpeedProps800Kbps
|
||||
class NeoArmOtherSpeedPropsWs2812x : public NeoArmOtherSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoArmOtherSpeedPropsSk6812 : public NeoArmOtherSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoArmOtherSpeedProps800Kbps : public NeoArmOtherSpeedProps800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t CyclesT0h = ((uint32_t)(0.40 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
|
||||
static const uint32_t CyclesT1h = ((uint32_t)(0.80 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
|
||||
static const uint32_t Cycles = ((uint32_t)(1.25 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
@ -679,16 +754,23 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef NeoArmMethodBase<NeoArmOtherSpeedBase<NeoArmOtherSpeedPropsWs2813>> NeoArmWs2813Method;
|
||||
typedef NeoArmMethodBase<NeoArmOtherSpeedBase<NeoArmOtherSpeedPropsWs2812x>> NeoArmWs2812xMethod;
|
||||
typedef NeoArmMethodBase<NeoArmOtherSpeedBase<NeoArmOtherSpeedPropsSk6812>> NeoArmSk6812Method;
|
||||
typedef NeoArmMethodBase<NeoArmOtherSpeedBase<NeoArmOtherSpeedProps800Kbps>> NeoArm800KbpsMethod;
|
||||
typedef NeoArmMethodBase<NeoArmOtherSpeedBase<NeoArmOtherSpeedProps400Kbps>> NeoArm400KbpsMethod;
|
||||
typedef NeoArm400KbpsMethod NeoArmApa106Method;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Arm doesn't have alternatives methods yet, so only one to make the default
|
||||
typedef NeoArmWs2813Method NeoWs2813Method;
|
||||
typedef NeoArm800KbpsMethod Neo800KbpsMethod;
|
||||
typedef NeoArmWs2812xMethod NeoWs2813Method;
|
||||
typedef NeoArmWs2812xMethod NeoWs2812xMethod;
|
||||
typedef NeoArmSk6812Method NeoSk6812Method;
|
||||
typedef NeoArmSk6812Method NeoLc8812Method;
|
||||
typedef NeoArm800KbpsMethod NeoWs2812Method;
|
||||
typedef NeoArmApa106Method NeoApa106Method;
|
||||
typedef NeoArmWs2812xMethod Neo800KbpsMethod;
|
||||
#ifdef NeoArm400KbpsMethod // this is needed due to missing 400Kbps for some platforms
|
||||
typedef NeoArm400KbpsMethod Neo400KbpsMethod;
|
||||
#endif
|
@ -71,10 +71,16 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class NeoAvrSpeedWs2813 : public NeoAvrSpeed800KbpsBase
|
||||
class NeoAvrSpeedWs2812x : public NeoAvrSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 250;
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoAvrSpeedSk6812 : public NeoAvrSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoAvrSpeed800Kbps: public NeoAvrSpeed800KbpsBase
|
||||
@ -142,7 +148,7 @@ public:
|
||||
_endTime = micros();
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update(bool)
|
||||
{
|
||||
// Data latch = 50+ microsecond pause in the output stream. Rather than
|
||||
// put a delay at the end of the function, the ending time is noted and
|
||||
@ -187,13 +193,21 @@ private:
|
||||
uint8_t _pinMask; // Output PORT bitmask
|
||||
};
|
||||
|
||||
typedef NeoAvrMethodBase<NeoAvrSpeedWs2813> NeoAvrWs2813Method;
|
||||
|
||||
typedef NeoAvrMethodBase<NeoAvrSpeedWs2812x> NeoAvrWs2812xMethod;
|
||||
typedef NeoAvrMethodBase<NeoAvrSpeedSk6812> NeoAvrSk6812Method;
|
||||
typedef NeoAvrMethodBase<NeoAvrSpeed800Kbps> NeoAvr800KbpsMethod;
|
||||
typedef NeoAvrMethodBase<NeoAvrSpeed400Kbps> NeoAvr400KbpsMethod;
|
||||
|
||||
|
||||
// AVR doesn't have alternatives yet, so there is just the default
|
||||
typedef NeoAvrWs2813Method NeoWs2813Method;
|
||||
typedef NeoAvr800KbpsMethod Neo800KbpsMethod;
|
||||
typedef NeoAvrWs2812xMethod NeoWs2813Method;
|
||||
typedef NeoAvrWs2812xMethod NeoWs2812xMethod;
|
||||
typedef NeoAvr800KbpsMethod NeoWs2812Method;
|
||||
typedef NeoAvrSk6812Method NeoSk6812Method;
|
||||
typedef NeoAvrSk6812Method NeoLc8812Method;
|
||||
typedef NeoAvr400KbpsMethod NeoApa106Method;
|
||||
typedef NeoAvrWs2812xMethod Neo800KbpsMethod;
|
||||
typedef NeoAvr400KbpsMethod Neo400KbpsMethod;
|
||||
|
||||
#endif
|
@ -75,12 +75,11 @@ public:
|
||||
_width(0),
|
||||
_height(0),
|
||||
_sizeRow(0),
|
||||
_bottomToTop(true),
|
||||
_bytesPerPixel(0)
|
||||
_bytesPerPixel(0),
|
||||
_bottomToTop(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
~NeoBitmapFile()
|
||||
{
|
||||
_file.close();
|
||||
@ -172,7 +171,7 @@ public:
|
||||
return _height;
|
||||
};
|
||||
|
||||
typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const
|
||||
typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y)
|
||||
{
|
||||
if (x < 0 || x >= _width || y < 0 || y >= _height)
|
||||
{
|
||||
@ -190,7 +189,9 @@ public:
|
||||
return color;
|
||||
};
|
||||
|
||||
void Blt(NeoBufferContext<T_COLOR_FEATURE> destBuffer,
|
||||
|
||||
template <typename T_SHADER> void Render(NeoBufferContext<T_COLOR_FEATURE> destBuffer,
|
||||
T_SHADER& shader,
|
||||
uint16_t indexPixel,
|
||||
int16_t xSrc,
|
||||
int16_t ySrc,
|
||||
@ -205,10 +206,11 @@ public:
|
||||
{
|
||||
for (int16_t x = 0; x < wSrc && indexPixel < destPixelCount; x++, indexPixel++)
|
||||
{
|
||||
if (xSrc < _width)
|
||||
if ((uint16_t)xSrc < _width)
|
||||
{
|
||||
if (readPixel(&color))
|
||||
{
|
||||
color = shader.Apply(indexPixel, color);
|
||||
xSrc++;
|
||||
}
|
||||
}
|
||||
@ -217,8 +219,20 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Blt(NeoBufferContext<T_COLOR_FEATURE> destBuffer,
|
||||
uint16_t indexPixel,
|
||||
int16_t xSrc,
|
||||
int16_t ySrc,
|
||||
int16_t wSrc)
|
||||
{
|
||||
NeoShaderNop<typename T_COLOR_FEATURE::ColorObject> shaderNop;
|
||||
|
||||
Render<NeoShaderNop<typename T_COLOR_FEATURE::ColorObject>>(destBuffer, shaderNop, indexPixel, xSrc, ySrc, wSrc);
|
||||
};
|
||||
|
||||
template <typename T_SHADER> void Render(NeoBufferContext<T_COLOR_FEATURE> destBuffer,
|
||||
T_SHADER& shader,
|
||||
int16_t xDest,
|
||||
int16_t yDest,
|
||||
int16_t xSrc,
|
||||
@ -239,15 +253,16 @@ public:
|
||||
{
|
||||
for (int16_t x = 0; x < wSrc; x++)
|
||||
{
|
||||
if (xFile < _width)
|
||||
uint16_t indexDest = layoutMap(xDest + x, yDest + y);
|
||||
|
||||
if ((uint16_t)xFile < _width)
|
||||
{
|
||||
if (readPixel(&color))
|
||||
{
|
||||
color = shader.Apply(indexDest, color);
|
||||
xFile++;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t indexDest = layoutMap(xDest + x, yDest + y);
|
||||
|
||||
if (indexDest < destPixelCount)
|
||||
{
|
||||
@ -258,6 +273,28 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void Blt(NeoBufferContext<T_COLOR_FEATURE> destBuffer,
|
||||
int16_t xDest,
|
||||
int16_t yDest,
|
||||
int16_t xSrc,
|
||||
int16_t ySrc,
|
||||
int16_t wSrc,
|
||||
int16_t hSrc,
|
||||
LayoutMapCallback layoutMap)
|
||||
{
|
||||
NeoShaderNop<typename T_COLOR_FEATURE::ColorObject> shaderNop;
|
||||
|
||||
Render<NeoShaderNop<typename T_COLOR_FEATURE::ColorObject>>(destBuffer,
|
||||
shaderNop,
|
||||
xDest,
|
||||
yDest,
|
||||
xSrc,
|
||||
ySrc,
|
||||
wSrc,
|
||||
hSrc,
|
||||
layoutMap);
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
T_FILE_METHOD _file;
|
||||
@ -268,26 +305,26 @@ private:
|
||||
uint8_t _bytesPerPixel;
|
||||
bool _bottomToTop;
|
||||
|
||||
int16_t constrainX(int16_t x)
|
||||
int16_t constrainX(int16_t x) const
|
||||
{
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
else if (x >= _width)
|
||||
else if ((uint16_t)x >= _width)
|
||||
{
|
||||
x = _width - 1;
|
||||
}
|
||||
return x;
|
||||
};
|
||||
|
||||
int16_t constrainY(int16_t y)
|
||||
int16_t constrainY(int16_t y) const
|
||||
{
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
else if (y >= _height)
|
||||
else if ((uint16_t)y >= _height)
|
||||
{
|
||||
y = _height - 1;
|
||||
}
|
@ -133,19 +133,38 @@ public:
|
||||
Blt(destBuffer, xDest, yDest, 0, 0, Width(), Height(), layoutMap);
|
||||
}
|
||||
|
||||
template <typename T_SHADER> void Render(NeoBufferContext<typename T_BUFFER_METHOD::ColorFeature> destBuffer, T_SHADER& shader)
|
||||
{
|
||||
uint16_t countPixels = destBuffer.PixelCount();
|
||||
|
||||
if (countPixels > _method.PixelCount())
|
||||
{
|
||||
countPixels = _method.PixelCount();
|
||||
}
|
||||
|
||||
for (uint16_t indexPixel = 0; indexPixel < countPixels; indexPixel++)
|
||||
{
|
||||
typename T_BUFFER_METHOD::ColorObject color;
|
||||
|
||||
shader.Apply(indexPixel, (uint8_t*)(&color), _method.Pixels() + (indexPixel * _method.PixelSize()));
|
||||
|
||||
T_BUFFER_METHOD::ColorFeature::applyPixelColor(destBuffer.Pixels, indexPixel, color);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T_BUFFER_METHOD _method;
|
||||
|
||||
uint16_t pixelIndex(
|
||||
int16_t x,
|
||||
int16_t y)
|
||||
int16_t y) const
|
||||
{
|
||||
uint16_t result = PixelIndex_OutOfBounds;
|
||||
|
||||
if (x >= 0 &&
|
||||
x < Width() &&
|
||||
(uint16_t)x < Width() &&
|
||||
y >= 0 &&
|
||||
y < Height())
|
||||
(uint16_t)y < Height())
|
||||
{
|
||||
result = x + y * Width();
|
||||
}
|
@ -25,6 +25,32 @@ License along with NeoPixel. If not, see
|
||||
-------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
template<typename T_COLOR_OBJECT> class NeoShaderNop
|
||||
{
|
||||
public:
|
||||
NeoShaderNop()
|
||||
{
|
||||
}
|
||||
|
||||
bool IsDirty() const
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
void Dirty()
|
||||
{
|
||||
};
|
||||
|
||||
void ResetDirty()
|
||||
{
|
||||
};
|
||||
|
||||
T_COLOR_OBJECT Apply(uint16_t, T_COLOR_OBJECT color)
|
||||
{
|
||||
return color;
|
||||
};
|
||||
};
|
||||
|
||||
class NeoShaderBase
|
||||
{
|
||||
public:
|
||||
@ -118,11 +144,13 @@ public:
|
||||
Dirty();
|
||||
};
|
||||
|
||||
template <typename T_COLOR_FEATURE, typename T_SHADER> void Render(NeoBufferContext<T_COLOR_FEATURE> destBuffer, T_SHADER& shader)
|
||||
template <typename T_COLOR_FEATURE, typename T_SHADER> void Render(NeoBufferContext<T_COLOR_FEATURE> destBuffer,
|
||||
T_SHADER& shader)
|
||||
{
|
||||
if (IsDirty() || shader.IsDirty())
|
||||
{
|
||||
uint16_t countPixels = destBuffer.PixelCount();
|
||||
|
||||
if (countPixels > _countPixels)
|
||||
{
|
||||
countPixels = _countPixels;
|
@ -71,6 +71,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static float QuadraticCenter(float unitValue)
|
||||
{
|
||||
unitValue *= 2.0f;
|
||||
if (unitValue < 1.0f)
|
||||
{
|
||||
return (-0.5f * (unitValue * unitValue - 2.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
unitValue -= 1.0f;
|
||||
return (0.5f * (unitValue * unitValue + 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
static float CubicIn(float unitValue)
|
||||
{
|
||||
return (unitValue * unitValue * unitValue);
|
||||
@ -96,6 +110,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static float CubicCenter(float unitValue)
|
||||
{
|
||||
unitValue *= 2.0f;
|
||||
unitValue -= 1.0f;
|
||||
return (0.5f * (unitValue * unitValue * unitValue) + 1);
|
||||
}
|
||||
|
||||
static float QuarticIn(float unitValue)
|
||||
{
|
||||
return (unitValue * unitValue * unitValue * unitValue);
|
||||
@ -121,6 +142,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static float QuarticCenter(float unitValue)
|
||||
{
|
||||
unitValue *= 2.0f;
|
||||
unitValue -= 1.0f;
|
||||
if (unitValue < 0.0f)
|
||||
{
|
||||
return (-0.5f * (unitValue * unitValue * unitValue * unitValue - 1.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (0.5f * (unitValue * unitValue * unitValue * unitValue + 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
static float QuinticIn(float unitValue)
|
||||
{
|
||||
return (unitValue * unitValue * unitValue * unitValue * unitValue);
|
||||
@ -146,6 +181,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static float QuinticCenter(float unitValue)
|
||||
{
|
||||
unitValue *= 2.0f;
|
||||
unitValue -= 1.0f;
|
||||
return (0.5f * (unitValue * unitValue * unitValue * unitValue * unitValue + 1.0f));
|
||||
}
|
||||
|
||||
static float SinusoidalIn(float unitValue)
|
||||
{
|
||||
return (-cos(unitValue * HALF_PI) + 1.0f);
|
||||
@ -161,6 +203,19 @@ public:
|
||||
return -0.5 * (cos(PI * unitValue) - 1.0f);
|
||||
}
|
||||
|
||||
static float SinusoidalCenter(float unitValue)
|
||||
{
|
||||
if (unitValue < 0.5f)
|
||||
{
|
||||
return (0.5 * sin(PI * unitValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (-0.5 * (cos(PI * (unitValue-0.5f)) + 1.0f));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static float ExponentialIn(float unitValue)
|
||||
{
|
||||
return (pow(2, 10.0f * (unitValue - 1.0f)));
|
||||
@ -185,6 +240,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static float ExponentialCenter(float unitValue)
|
||||
{
|
||||
unitValue *= 2.0f;
|
||||
if (unitValue < 1.0f)
|
||||
{
|
||||
return (0.5f * (-pow(2, -10.0f * unitValue) + 1.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
unitValue -= 2.0f;
|
||||
return (0.5f * (pow(2, 10.0f * unitValue) + 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
static float CircularIn(float unitValue)
|
||||
{
|
||||
if (unitValue == 1.0f)
|
||||
@ -217,6 +286,25 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static float CircularCenter(float unitValue)
|
||||
{
|
||||
unitValue *= 2.0f;
|
||||
unitValue -= 1.0f;
|
||||
if (unitValue == 0.0f)
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
else if (unitValue < 0.0f)
|
||||
{
|
||||
return (0.5f * sqrt(1.0f - unitValue * unitValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
unitValue -= 2.0f;
|
||||
return (-0.5f * (sqrt(1.0f - unitValue * unitValue) - 1.0f ) + 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
static float Gamma(float unitValue)
|
||||
{
|
||||
return pow(unitValue, 1.0f / 0.45f);
|
217
lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp32I2sMethod.h
Normal file
@ -0,0 +1,217 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Esp32.
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <Arduino.h>
|
||||
#include "Esp32_i2s.h"
|
||||
}
|
||||
|
||||
const uint16_t c_dmaBytesPerPixelBytes = 4;
|
||||
|
||||
class NeoEsp32I2sSpeedWs2812x
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeedSk6812
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeed800Kbps
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeed400Kbps
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 50000;
|
||||
const static uint16_t ByteSendTimeUs = 20;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeedApa106
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 76000;
|
||||
const static uint16_t ByteSendTimeUs = 14;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sBusZero
|
||||
{
|
||||
public:
|
||||
const static uint8_t I2sBusNumber = 0;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sBusOne
|
||||
{
|
||||
public:
|
||||
const static uint8_t I2sBusNumber = 1;
|
||||
};
|
||||
|
||||
template<typename T_SPEED, typename T_BUS> class NeoEsp32I2sMethodBase
|
||||
{
|
||||
public:
|
||||
NeoEsp32I2sMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize) :
|
||||
_pin(pin)
|
||||
{
|
||||
uint16_t dmaPixelSize = c_dmaBytesPerPixelBytes * elementSize;
|
||||
uint16_t resetSize = c_dmaBytesPerPixelBytes * T_SPEED::ResetTimeUs / T_SPEED::ByteSendTimeUs;
|
||||
|
||||
_pixelsSize = pixelCount * elementSize;
|
||||
_i2sBufferSize = pixelCount * dmaPixelSize + resetSize;
|
||||
|
||||
// must have a 4 byte aligned buffer for i2s
|
||||
uint32_t alignment = _i2sBufferSize % 4;
|
||||
if (alignment)
|
||||
{
|
||||
_i2sBufferSize += 4 - alignment;
|
||||
}
|
||||
|
||||
_pixels = static_cast<uint8_t*>(malloc(_pixelsSize));
|
||||
memset(_pixels, 0x00, _pixelsSize);
|
||||
|
||||
_i2sBuffer = static_cast<uint8_t*>(malloc(_i2sBufferSize));
|
||||
memset(_i2sBuffer, 0x00, _i2sBufferSize);
|
||||
}
|
||||
|
||||
~NeoEsp32I2sMethodBase()
|
||||
{
|
||||
while (!IsReadyToUpdate())
|
||||
{
|
||||
yield();
|
||||
}
|
||||
|
||||
pinMode(_pin, INPUT);
|
||||
|
||||
free(_pixels);
|
||||
free(_i2sBuffer);
|
||||
}
|
||||
|
||||
bool IsReadyToUpdate() const
|
||||
{
|
||||
return (i2sWriteDone(T_BUS::I2sBusNumber));
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
size_t dmaCount = (_i2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN;
|
||||
i2sInit(T_BUS::I2sBusNumber, 16, T_SPEED::I2sSampleRate, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, dmaCount, 0);
|
||||
i2sSetPins(T_BUS::I2sBusNumber, _pin, -1, -1, -1);
|
||||
}
|
||||
|
||||
void Update(bool)
|
||||
{
|
||||
// wait for not actively sending data
|
||||
while (!IsReadyToUpdate())
|
||||
{
|
||||
yield();
|
||||
}
|
||||
|
||||
FillBuffers();
|
||||
|
||||
i2sWrite(T_BUS::I2sBusNumber, _i2sBuffer, _i2sBufferSize, false, false);
|
||||
}
|
||||
|
||||
uint8_t* getPixels() const
|
||||
{
|
||||
return _pixels;
|
||||
};
|
||||
|
||||
size_t getPixelsSize() const
|
||||
{
|
||||
return _pixelsSize;
|
||||
}
|
||||
|
||||
private:
|
||||
const uint8_t _pin; // output pin number
|
||||
|
||||
size_t _pixelsSize; // Size of '_pixels' buffer
|
||||
uint8_t* _pixels; // Holds LED color values
|
||||
|
||||
uint32_t _i2sBufferSize; // total size of _i2sBuffer
|
||||
uint8_t* _i2sBuffer; // holds the DMA buffer that is referenced by _i2sBufDesc
|
||||
|
||||
void FillBuffers()
|
||||
{
|
||||
const uint16_t bitpatterns[16] =
|
||||
{
|
||||
0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110,
|
||||
0b1000111010001000, 0b1000111010001110, 0b1000111011101000, 0b1000111011101110,
|
||||
0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110,
|
||||
0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110,
|
||||
};
|
||||
|
||||
uint16_t* pDma = reinterpret_cast<uint16_t*>(_i2sBuffer);
|
||||
uint8_t* pPixelsEnd = _pixels + _pixelsSize;
|
||||
for (uint8_t* pPixel = _pixels; pPixel < pPixelsEnd; pPixel++)
|
||||
{
|
||||
*(pDma++) = bitpatterns[((*pPixel) & 0x0f)];
|
||||
*(pDma++) = bitpatterns[((*pPixel) >> 4) & 0x0f];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedWs2812x, NeoEsp32I2sBusZero> NeoEsp32I2s0Ws2812xMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedSk6812, NeoEsp32I2sBusZero> NeoEsp32I2s0Sk6812Method;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeed800Kbps, NeoEsp32I2sBusZero> NeoEsp32I2s0800KbpsMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeed400Kbps, NeoEsp32I2sBusZero> NeoEsp32I2s0400KbpsMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedApa106, NeoEsp32I2sBusZero> NeoEsp32I2s0Apa106Method;
|
||||
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedWs2812x, NeoEsp32I2sBusOne> NeoEsp32I2s1Ws2812xMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedSk6812, NeoEsp32I2sBusOne> NeoEsp32I2s1Sk6812Method;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeed800Kbps, NeoEsp32I2sBusOne> NeoEsp32I2s1800KbpsMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeed400Kbps, NeoEsp32I2sBusOne> NeoEsp32I2s1400KbpsMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedApa106, NeoEsp32I2sBusOne> NeoEsp32I2s1Apa106Method;
|
||||
|
||||
// I2s Bus 1 method is the default method for Esp32
|
||||
typedef NeoEsp32I2s1Ws2812xMethod NeoWs2813Method;
|
||||
typedef NeoEsp32I2s1Ws2812xMethod NeoWs2812xMethod;
|
||||
typedef NeoEsp32I2s1800KbpsMethod NeoWs2812Method;
|
||||
typedef NeoEsp32I2s1Sk6812Method NeoSk6812Method;
|
||||
typedef NeoEsp32I2s1Sk6812Method NeoLc8812Method;
|
||||
typedef NeoEsp32I2s1Apa106Method NeoApa106Method;
|
||||
|
||||
typedef NeoEsp32I2s1Ws2812xMethod Neo800KbpsMethod;
|
||||
typedef NeoEsp32I2s1400KbpsMethod Neo400KbpsMethod;
|
||||
|
||||
#endif
|
369
lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp32RmtMethod.h
Normal file
@ -0,0 +1,369 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Esp32.
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
||||
/* General Reference documentation for the APIs used in this implementation
|
||||
LOW LEVEL: (what is actually used)
|
||||
DOCS: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/rmt.html
|
||||
EXAMPLE: https://github.com/espressif/esp-idf/blob/826ff7186ae07dc81e960a8ea09ebfc5304bfb3b/examples/peripherals/rmt_tx/main/rmt_tx_main.c
|
||||
HIGHER LEVEL:
|
||||
NO TRANSLATE SUPPORT so this was not used
|
||||
NOTE: https://github.com/espressif/arduino-esp32/commit/50d142950d229b8fabca9b749dc4a5f2533bc426
|
||||
Esp32-hal-rmt.h
|
||||
Esp32-hal-rmt.c
|
||||
*/
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <Arduino.h>
|
||||
#include <driver/rmt.h>
|
||||
}
|
||||
|
||||
class NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
// ClkDiv of 2 provides for good resolution and plenty of reset resolution; but
|
||||
// a ClkDiv of 1 will provide enough space for the longest reset and does show
|
||||
// little better pulse accuracy
|
||||
const static uint8_t RmtClockDivider = 2;
|
||||
|
||||
inline constexpr static uint32_t FromNs(uint32_t ns)
|
||||
{
|
||||
return ns / NsPerRmtTick;
|
||||
}
|
||||
// this is used rather than the rmt_item32_t as you can't correctly initialize
|
||||
// it as a static constexpr within the template
|
||||
inline constexpr static uint32_t Item32Val(uint16_t nsHigh, uint16_t nsLow)
|
||||
{
|
||||
return (FromNs(nsLow) << 16) | (1 << 15) | (FromNs(nsHigh));
|
||||
}
|
||||
|
||||
public:
|
||||
const static uint32_t RmtCpu = 80000000L; // 80 mhz RMT clock
|
||||
const static uint32_t NsPerSecond = 1000000000L;
|
||||
const static uint32_t RmtTicksPerSecond = (RmtCpu / RmtClockDivider);
|
||||
const static uint32_t NsPerRmtTick = (NsPerSecond / RmtTicksPerSecond); // about 25
|
||||
};
|
||||
|
||||
class NeoEsp32RmtSpeedWs2812x : public NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static uint16_t RmtDurationReset = FromNs(300000); // 300us
|
||||
};
|
||||
|
||||
class NeoEsp32RmtSpeedSk6812 : public NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static uint16_t RmtDurationReset = FromNs(80000); // 80us
|
||||
};
|
||||
|
||||
class NeoEsp32RmtSpeed800Kbps : public NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
};
|
||||
|
||||
class NeoEsp32RmtSpeed400Kbps : public NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t RmtBit0 = Item32Val(800, 1700);
|
||||
const static uint32_t RmtBit1 = Item32Val(1600, 900);
|
||||
const static uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
};
|
||||
|
||||
class NeoEsp32RmtSpeedApa106 : public NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t RmtBit0 = Item32Val(400, 1250);
|
||||
const static uint32_t RmtBit1 = Item32Val(1250, 400);
|
||||
const static uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
};
|
||||
|
||||
class NeoEsp32RmtChannel0
|
||||
{
|
||||
public:
|
||||
const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_0;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtChannel1
|
||||
{
|
||||
public:
|
||||
const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_1;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtChannel2
|
||||
{
|
||||
public:
|
||||
const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_2;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtChannel3
|
||||
{
|
||||
public:
|
||||
const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_3;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtChannel4
|
||||
{
|
||||
public:
|
||||
const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_4;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtChannel5
|
||||
{
|
||||
public:
|
||||
const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_5;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtChannel6
|
||||
{
|
||||
public:
|
||||
const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_6;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtChannel7
|
||||
{
|
||||
public:
|
||||
const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_7;
|
||||
};
|
||||
|
||||
template<typename T_SPEED, typename T_CHANNEL> class NeoEsp32RmtMethodBase
|
||||
{
|
||||
public:
|
||||
NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize) :
|
||||
_pin(pin)
|
||||
{
|
||||
_pixelsSize = pixelCount * elementSize;
|
||||
|
||||
_pixelsEditing = static_cast<uint8_t*>(malloc(_pixelsSize));
|
||||
memset(_pixelsEditing, 0x00, _pixelsSize);
|
||||
|
||||
_pixelsSending = static_cast<uint8_t*>(malloc(_pixelsSize));
|
||||
// no need to initialize it, it gets overwritten on every send
|
||||
}
|
||||
|
||||
~NeoEsp32RmtMethodBase()
|
||||
{
|
||||
// wait until the last send finishes before destructing everything
|
||||
// arbitrary time out of 10 seconds
|
||||
rmt_wait_tx_done(T_CHANNEL::RmtChannelNumber, 10000 / portTICK_PERIOD_MS);
|
||||
|
||||
rmt_driver_uninstall(T_CHANNEL::RmtChannelNumber);
|
||||
|
||||
free(_pixelsEditing);
|
||||
free(_pixelsSending);
|
||||
}
|
||||
|
||||
|
||||
bool IsReadyToUpdate() const
|
||||
{
|
||||
return (ESP_OK == rmt_wait_tx_done(T_CHANNEL::RmtChannelNumber, 0));
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
rmt_config_t config;
|
||||
|
||||
config.rmt_mode = RMT_MODE_TX;
|
||||
config.channel = T_CHANNEL::RmtChannelNumber;
|
||||
config.gpio_num = static_cast<gpio_num_t>(_pin);
|
||||
config.mem_block_num = 1;
|
||||
config.tx_config.loop_en = false;
|
||||
|
||||
config.tx_config.idle_output_en = true;
|
||||
config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
|
||||
|
||||
config.tx_config.carrier_en = false;
|
||||
config.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW;
|
||||
|
||||
config.clk_div = T_SPEED::RmtClockDivider;
|
||||
|
||||
rmt_config(&config);
|
||||
rmt_driver_install(T_CHANNEL::RmtChannelNumber, 0, 0);
|
||||
rmt_translator_init(T_CHANNEL::RmtChannelNumber, _translate);
|
||||
}
|
||||
|
||||
void Update(bool maintainBufferConsistency)
|
||||
{
|
||||
// wait for not actively sending data
|
||||
// this will time out at 10 seconds, an arbitrarily long period of time
|
||||
// and do nothing if this happens
|
||||
if (ESP_OK == rmt_wait_tx_done(T_CHANNEL::RmtChannelNumber, 10000 / portTICK_PERIOD_MS))
|
||||
{
|
||||
// now start the RMT transmit with the editing buffer before we swap
|
||||
rmt_write_sample(T_CHANNEL::RmtChannelNumber, _pixelsEditing, _pixelsSize, false);
|
||||
|
||||
if (maintainBufferConsistency)
|
||||
{
|
||||
// copy editing to sending,
|
||||
// this maintains the contract that "colors present before will
|
||||
// be the same after", otherwise GetPixelColor will be inconsistent
|
||||
memcpy(_pixelsSending, _pixelsEditing, _pixelsSize);
|
||||
}
|
||||
|
||||
// swap so the user can modify without affecting the async operation
|
||||
std::swap(_pixelsSending, _pixelsEditing);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* getPixels() const
|
||||
{
|
||||
return _pixelsEditing;
|
||||
};
|
||||
|
||||
size_t getPixelsSize() const
|
||||
{
|
||||
return _pixelsSize;
|
||||
}
|
||||
|
||||
private:
|
||||
const uint8_t _pin; // output pin number
|
||||
|
||||
size_t _pixelsSize; // Size of '_pixels' buffer
|
||||
uint8_t* _pixelsEditing; // Holds LED color values exposed for get and set
|
||||
uint8_t* _pixelsSending; // Holds LED color values used to async send using RMT
|
||||
|
||||
|
||||
// stranslate NeoPixelBuffer into RMT buffer
|
||||
// this is done on the fly so we don't require a send buffer in raw RMT format
|
||||
// which would be 32x larger than the primary buffer
|
||||
static void IRAM_ATTR _translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
size_t src_size,
|
||||
size_t wanted_num,
|
||||
size_t* translated_size,
|
||||
size_t* item_num)
|
||||
{
|
||||
if (src == NULL || dest == NULL)
|
||||
{
|
||||
*translated_size = 0;
|
||||
*item_num = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t size = 0;
|
||||
size_t num = 0;
|
||||
const uint8_t* psrc = static_cast<const uint8_t*>(src);
|
||||
rmt_item32_t* pdest = dest;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint8_t data = *psrc;
|
||||
|
||||
for (uint8_t bit = 0; bit < 8; bit++)
|
||||
{
|
||||
pdest->val = (data & 0x80) ? T_SPEED::RmtBit1 : T_SPEED::RmtBit0;
|
||||
pdest++;
|
||||
data <<= 1;
|
||||
}
|
||||
num += 8;
|
||||
size++;
|
||||
|
||||
// if this is the last byte we need to adjust the length of the last pulse
|
||||
if (size >= src_size)
|
||||
{
|
||||
// extend the last bits LOW value to include the full reset signal length
|
||||
pdest--;
|
||||
pdest->duration1 = T_SPEED::RmtDurationReset;
|
||||
// and stop updating data to send
|
||||
break;
|
||||
}
|
||||
|
||||
if (num >= wanted_num)
|
||||
{
|
||||
// stop updating data to send
|
||||
break;
|
||||
}
|
||||
|
||||
psrc++;
|
||||
}
|
||||
|
||||
*translated_size = size;
|
||||
*item_num = num;
|
||||
}
|
||||
};
|
||||
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedWs2812x, NeoEsp32RmtChannel0> NeoEsp32Rmt0Ws2812xMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedSk6812, NeoEsp32RmtChannel0> NeoEsp32Rmt0Sk6812Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedApa106, NeoEsp32RmtChannel0> NeoEsp32Rmt0Apa106Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed800Kbps, NeoEsp32RmtChannel0> NeoEsp32Rmt0800KbpsMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed400Kbps, NeoEsp32RmtChannel0> NeoEsp32Rmt0400KbpsMethod;
|
||||
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedWs2812x, NeoEsp32RmtChannel1> NeoEsp32Rmt1Ws2812xMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedSk6812, NeoEsp32RmtChannel1> NeoEsp32Rmt1Sk6812Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedApa106, NeoEsp32RmtChannel1> NeoEsp32Rmt1Apa106Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed800Kbps, NeoEsp32RmtChannel1> NeoEsp32Rmt1800KbpsMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed400Kbps, NeoEsp32RmtChannel1> NeoEsp32Rmt1400KbpsMethod;
|
||||
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedWs2812x, NeoEsp32RmtChannel2> NeoEsp32Rmt2Ws2812xMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedSk6812, NeoEsp32RmtChannel2> NeoEsp32Rmt2Sk6812Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedApa106, NeoEsp32RmtChannel2> NeoEsp32Rmt2Apa106Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed800Kbps, NeoEsp32RmtChannel2> NeoEsp32Rmt2800KbpsMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed400Kbps, NeoEsp32RmtChannel2> NeoEsp32Rmt2400KbpsMethod;
|
||||
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedWs2812x, NeoEsp32RmtChannel3> NeoEsp32Rmt3Ws2812xMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedSk6812, NeoEsp32RmtChannel3> NeoEsp32Rmt3Sk6812Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedApa106, NeoEsp32RmtChannel3> NeoEsp32Rmt3Apa106Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed800Kbps, NeoEsp32RmtChannel3> NeoEsp32Rmt3800KbpsMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed400Kbps, NeoEsp32RmtChannel3> NeoEsp32Rmt3400KbpsMethod;
|
||||
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedWs2812x, NeoEsp32RmtChannel4> NeoEsp32Rmt4Ws2812xMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedSk6812, NeoEsp32RmtChannel4> NeoEsp32Rmt4Sk6812Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedApa106, NeoEsp32RmtChannel4> NeoEsp32Rmt4Apa106Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed800Kbps, NeoEsp32RmtChannel4> NeoEsp32Rmt4800KbpsMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed400Kbps, NeoEsp32RmtChannel4> NeoEsp32Rmt4400KbpsMethod;
|
||||
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedWs2812x, NeoEsp32RmtChannel5> NeoEsp32Rmt5Ws2812xMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedSk6812, NeoEsp32RmtChannel5> NeoEsp32Rmt5Sk6812Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedApa106, NeoEsp32RmtChannel5> NeoEsp32Rmt5Apa106Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed800Kbps, NeoEsp32RmtChannel5> NeoEsp32Rmt5800KbpsMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed400Kbps, NeoEsp32RmtChannel5> NeoEsp32Rmt5400KbpsMethod;
|
||||
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedWs2812x, NeoEsp32RmtChannel6> NeoEsp32Rmt6Ws2812xMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedSk6812, NeoEsp32RmtChannel6> NeoEsp32Rmt6Sk6812Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedApa106, NeoEsp32RmtChannel6> NeoEsp32Rmt6Apa106Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed800Kbps, NeoEsp32RmtChannel6> NeoEsp32Rmt6800KbpsMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed400Kbps, NeoEsp32RmtChannel6> NeoEsp32Rmt6400KbpsMethod;
|
||||
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedWs2812x, NeoEsp32RmtChannel7> NeoEsp32Rmt7Ws2812xMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedSk6812, NeoEsp32RmtChannel7> NeoEsp32Rmt7Sk6812Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeedApa106, NeoEsp32RmtChannel7> NeoEsp32Rmt7Apa106Method;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed800Kbps, NeoEsp32RmtChannel7> NeoEsp32Rmt7800KbpsMethod;
|
||||
typedef NeoEsp32RmtMethodBase<NeoEsp32RmtSpeed400Kbps, NeoEsp32RmtChannel7> NeoEsp32Rmt7400KbpsMethod;
|
||||
|
||||
// RMT is NOT the default method for Esp32,
|
||||
// you are required to use a specific channel listed above
|
||||
|
||||
#endif
|
@ -48,9 +48,7 @@ extern "C"
|
||||
#include "ets_sys.h"
|
||||
#include "user_interface.h"
|
||||
|
||||
// Workaround STAGE compile error
|
||||
#include <core_version.h>
|
||||
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2) || defined(ARDUINO_ESP8266_RELEASE_2_5_0)
|
||||
#if !defined(__CORE_ESP8266_VERSION_H) || defined(ARDUINO_ESP8266_RELEASE_2_5_0)
|
||||
void rom_i2c_writeReg_Mask(uint32_t block, uint32_t host_id, uint32_t reg_add, uint32_t Msb, uint32_t Lsb, uint32_t indata);
|
||||
#endif
|
||||
}
|
||||
@ -67,19 +65,29 @@ struct slc_queue_item
|
||||
uint32 next_link_ptr;
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaSpeedWs2813
|
||||
class NeoEsp8266DmaSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sClockDivisor = 3;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ResetTimeUs = 250;
|
||||
const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaSpeed800Kbps
|
||||
class NeoEsp8266DmaSpeedWs2812x : public NeoEsp8266DmaSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaSpeedSk6812 : public NeoEsp8266DmaSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaSpeed800Kbps : public NeoEsp8266DmaSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sClockDivisor = 3;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
@ -88,14 +96,25 @@ class NeoEsp8266DmaSpeed400Kbps
|
||||
public:
|
||||
const static uint32_t I2sClockDivisor = 6;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaSpeedApa106
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sClockDivisor = 4;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
enum NeoDmaState
|
||||
{
|
||||
NeoDmaState_Idle,
|
||||
NeoDmaState_Pending,
|
||||
NeoDmaState_Sending,
|
||||
NeoDmaState_Zeroing,
|
||||
};
|
||||
const uint16_t c_maxDmaBlockSize = 4095;
|
||||
const uint16_t c_dmaBytesPerPixelBytes = 4;
|
||||
@ -117,6 +136,8 @@ public:
|
||||
_i2sBuffer = (uint8_t*)malloc(_i2sBufferSize);
|
||||
memset(_i2sBuffer, 0x00, _i2sBufferSize);
|
||||
|
||||
// _i2sBuffer[0] = 0b11101000; // debug, 1 bit then 0 bit
|
||||
|
||||
memset(_i2sZeroes, 0x00, sizeof(_i2sZeroes));
|
||||
|
||||
_is2BufMaxBlockSize = (c_maxDmaBlockSize / dmaPixelSize) * dmaPixelSize;
|
||||
@ -133,8 +154,26 @@ public:
|
||||
|
||||
~NeoEsp8266DmaMethodBase()
|
||||
{
|
||||
uint8_t waits = 1;
|
||||
while (!IsReadyToUpdate())
|
||||
{
|
||||
waits = 2;
|
||||
yield();
|
||||
}
|
||||
|
||||
// wait for any pending sends to complete
|
||||
// due to internal i2s caching/send delays, this can more that once the data size
|
||||
uint32_t time = micros();
|
||||
while ((micros() - time) < ((getPixelTime() + T_SPEED::ResetTimeUs) * waits))
|
||||
{
|
||||
yield();
|
||||
}
|
||||
|
||||
StopDma();
|
||||
|
||||
s_this = nullptr;
|
||||
pinMode(c_I2sPin, INPUT);
|
||||
|
||||
free(_pixels);
|
||||
free(_i2sBuffer);
|
||||
free(_i2sBufDesc);
|
||||
@ -148,7 +187,8 @@ public:
|
||||
void Initialize()
|
||||
{
|
||||
StopDma();
|
||||
_dmaState = NeoDmaState_Sending; // start off sending empty buffer
|
||||
|
||||
pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA
|
||||
|
||||
uint8_t* is2Buffer = _i2sBuffer;
|
||||
uint32_t is2BufferSize = _i2sBufferSize;
|
||||
@ -193,6 +233,11 @@ public:
|
||||
// setup the rest of i2s DMA
|
||||
//
|
||||
ETS_SLC_INTR_DISABLE();
|
||||
|
||||
// start off in sending state as that is what it will be all setup to be
|
||||
// for the interrupt
|
||||
_dmaState = NeoDmaState_Sending;
|
||||
|
||||
SLCC0 |= SLCRXLR | SLCTXLR;
|
||||
SLCC0 &= ~(SLCRXLR | SLCTXLR);
|
||||
SLCIC = 0xFFFFFFFF;
|
||||
@ -208,9 +253,11 @@ public:
|
||||
// expect. The TXLINK part still needs a valid DMA descriptor, even if it's unused: the DMA engine will throw
|
||||
// an error at us otherwise. Just feed it any random descriptor.
|
||||
SLCTXL &= ~(SLCTXLAM << SLCTXLA); // clear TX descriptor address
|
||||
SLCTXL |= (uint32)&(_i2sBufDesc[_i2sBufDescCount-1]) << SLCTXLA; // set TX descriptor address. any random desc is OK, we don't use TX but it needs to be valid
|
||||
// set TX descriptor address. any random desc is OK, we don't use TX but it needs to be valid
|
||||
SLCTXL |= (uint32)&(_i2sBufDesc[_i2sBufDescCount-1]) << SLCTXLA;
|
||||
SLCRXL &= ~(SLCRXLAM << SLCRXLA); // clear RX descriptor address
|
||||
SLCRXL |= (uint32)_i2sBufDesc << SLCRXLA; // set RX descriptor address
|
||||
// set RX descriptor address. use first of the data addresses
|
||||
SLCRXL |= (uint32)&(_i2sBufDesc[0]) << SLCRXLA;
|
||||
|
||||
ETS_SLC_INTR_ATTACH(i2s_slc_isr, NULL);
|
||||
SLCIE = SLCIRXEOF; // Enable only for RX EOF interrupt
|
||||
@ -221,8 +268,6 @@ public:
|
||||
SLCTXL |= SLCTXLS;
|
||||
SLCRXL |= SLCRXLS;
|
||||
|
||||
pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA
|
||||
|
||||
I2S_CLK_ENABLE();
|
||||
I2SIC = 0x3F;
|
||||
I2SIE = 0;
|
||||
@ -232,30 +277,32 @@ public:
|
||||
I2SC |= I2SRST;
|
||||
I2SC &= ~(I2SRST);
|
||||
|
||||
I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM) | (I2SRXFMM << I2SRXFM)); // Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only)
|
||||
// Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only)
|
||||
I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM) | (I2SRXFMM << I2SRXFM));
|
||||
I2SFC |= I2SDE; //Enable DMA
|
||||
I2SCC &= ~((I2STXCMM << I2STXCM) | (I2SRXCMM << I2SRXCM)); // Set RX/TX CHAN_MOD=0
|
||||
// Set RX/TX CHAN_MOD=0
|
||||
I2SCC &= ~((I2STXCMM << I2STXCM) | (I2SRXCMM << I2SRXCM));
|
||||
|
||||
// set the rate
|
||||
uint32_t i2s_clock_div = T_SPEED::I2sClockDivisor & I2SCDM;
|
||||
uint8_t i2s_bck_div = T_SPEED::I2sBaseClockDivisor & I2SBDM;
|
||||
|
||||
//!trans master, !bits mod, rece slave mod, rece msb shift, right first, msb right
|
||||
I2SC &= ~(I2STSM | (I2SBMM << I2SBM) | (I2SBDM << I2SBD) | (I2SCDM << I2SCD));
|
||||
I2SC &= ~(I2STSM | I2SRSM | (I2SBMM << I2SBM) | (I2SBDM << I2SBD) | (I2SCDM << I2SCD));
|
||||
I2SC |= I2SRF | I2SMR | I2SRSM | I2SRMS | (i2s_bck_div << I2SBD) | (i2s_clock_div << I2SCD);
|
||||
|
||||
I2SC |= I2STXS; // Start transmission
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR Update()
|
||||
void ICACHE_RAM_ATTR Update(bool)
|
||||
{
|
||||
// wait for not actively sending data
|
||||
while (_dmaState != NeoDmaState_Idle)
|
||||
while (!IsReadyToUpdate())
|
||||
{
|
||||
yield();
|
||||
}
|
||||
FillBuffers();
|
||||
|
||||
|
||||
// toggle state so the ISR reacts
|
||||
_dmaState = NeoDmaState_Pending;
|
||||
}
|
||||
@ -273,16 +320,16 @@ public:
|
||||
private:
|
||||
static NeoEsp8266DmaMethodBase* s_this; // for the ISR
|
||||
|
||||
size_t _pixelsSize; // Size of '_pixels' buffer
|
||||
size_t _pixelsSize; // Size of '_pixels' buffer
|
||||
uint8_t* _pixels; // Holds LED color values
|
||||
|
||||
uint32_t _i2sBufferSize; // total size of _i2sBuffer
|
||||
uint8_t* _i2sBuffer; // holds the DMA buffer that is referenced by _i2sBufDesc
|
||||
|
||||
// normally 24 bytes creates the minimum 50us latch per spec, but
|
||||
// with the new logic, this latch is used to space between three states
|
||||
// buffer size = (24 * (speed / 50)) / 3
|
||||
uint8_t _i2sZeroes[(24L * (T_SPEED::ResetTimeUs / 50L)) / 3L];
|
||||
// with the new logic, this latch is used to space between mulitple states
|
||||
// buffer size = (24 * (reset time / 50)) / 6
|
||||
uint8_t _i2sZeroes[(24L * (T_SPEED::ResetTimeUs / 50L)) / 6L];
|
||||
|
||||
slc_queue_item* _i2sBufDesc; // dma block descriptors
|
||||
uint16_t _i2sBufDescCount; // count of block descriptors in _i2sBufDesc
|
||||
@ -296,15 +343,15 @@ private:
|
||||
// in the case of this code, the second to last state descriptor
|
||||
volatile static void ICACHE_RAM_ATTR i2s_slc_isr(void)
|
||||
{
|
||||
ETS_SLC_INTR_DISABLE();
|
||||
|
||||
uint32_t slc_intr_status = SLCIS;
|
||||
|
||||
SLCIC = 0xFFFFFFFF;
|
||||
|
||||
if (slc_intr_status & SLCIRXEOF)
|
||||
if ((slc_intr_status & SLCIRXEOF) && s_this)
|
||||
{
|
||||
ETS_SLC_INTR_DISABLE();
|
||||
|
||||
switch (s_this->_dmaState)
|
||||
switch (s_this->_dmaState)
|
||||
{
|
||||
case NeoDmaState_Idle:
|
||||
break;
|
||||
@ -314,7 +361,7 @@ private:
|
||||
slc_queue_item* finished_item = (slc_queue_item*)SLCRXEDA;
|
||||
|
||||
// data block has pending data waiting to send, prepare it
|
||||
// point last state block to top
|
||||
// point last state block to top
|
||||
(finished_item + 1)->next_link_ptr = (uint32_t)(s_this->_i2sBufDesc);
|
||||
|
||||
s_this->_dmaState = NeoDmaState_Sending;
|
||||
@ -330,14 +377,17 @@ private:
|
||||
// just looping and not sending the data blocks
|
||||
(finished_item + 1)->next_link_ptr = (uint32_t)(finished_item);
|
||||
|
||||
s_this->_dmaState = NeoDmaState_Idle;
|
||||
s_this->_dmaState = NeoDmaState_Zeroing;
|
||||
}
|
||||
break;
|
||||
|
||||
case NeoDmaState_Zeroing:
|
||||
s_this->_dmaState = NeoDmaState_Idle;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
ETS_SLC_INTR_ENABLE();
|
||||
}
|
||||
|
||||
ETS_SLC_INTR_ENABLE();
|
||||
}
|
||||
|
||||
void FillBuffers()
|
||||
@ -362,6 +412,16 @@ private:
|
||||
void StopDma()
|
||||
{
|
||||
ETS_SLC_INTR_DISABLE();
|
||||
|
||||
// Disable any I2S send or receive
|
||||
I2SC &= ~(I2STXS | I2SRXS);
|
||||
|
||||
// Reset I2S
|
||||
I2SC &= ~(I2SRST);
|
||||
I2SC |= I2SRST;
|
||||
I2SC &= ~(I2SRST);
|
||||
|
||||
|
||||
SLCIC = 0xFFFFFFFF;
|
||||
SLCIE = 0;
|
||||
SLCTXL &= ~(SLCTXLAM << SLCTXLA); // clear TX descriptor address
|
||||
@ -369,18 +429,32 @@ private:
|
||||
|
||||
pinMode(c_I2sPin, INPUT);
|
||||
}
|
||||
|
||||
uint32_t getPixelTime() const
|
||||
{
|
||||
return (T_SPEED::ByteSendTimeUs * this->_pixelsSize);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
template<typename T_SPEED>
|
||||
template<typename T_SPEED>
|
||||
NeoEsp8266DmaMethodBase<T_SPEED>* NeoEsp8266DmaMethodBase<T_SPEED>::s_this;
|
||||
|
||||
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeedWs2813> NeoEsp8266DmaWs2813Method;
|
||||
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeedWs2812x> NeoEsp8266DmaWs2812xMethod;
|
||||
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeedSk6812> NeoEsp8266DmaSk6812Method;
|
||||
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeed800Kbps> NeoEsp8266Dma800KbpsMethod;
|
||||
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeed400Kbps> NeoEsp8266Dma400KbpsMethod;
|
||||
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeedApa106> NeoEsp8266DmaApa106Method;
|
||||
|
||||
// Dma method is the default method for Esp8266
|
||||
typedef NeoEsp8266DmaWs2813Method NeoWs2813Method;
|
||||
typedef NeoEsp8266Dma800KbpsMethod Neo800KbpsMethod;
|
||||
typedef NeoEsp8266DmaWs2812xMethod NeoWs2813Method;
|
||||
typedef NeoEsp8266DmaWs2812xMethod NeoWs2812xMethod;
|
||||
typedef NeoEsp8266Dma800KbpsMethod NeoWs2812Method;
|
||||
typedef NeoEsp8266DmaSk6812Method NeoSk6812Method;
|
||||
typedef NeoEsp8266DmaSk6812Method NeoLc8812Method;
|
||||
typedef NeoEsp8266DmaApa106Method NeoApa106Method;
|
||||
|
||||
typedef NeoEsp8266DmaWs2812xMethod Neo800KbpsMethod;
|
||||
typedef NeoEsp8266Dma400KbpsMethod Neo400KbpsMethod;
|
||||
|
||||
#endif
|
||||
#endif
|
171
lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Esp8266 UART hardware
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include "NeoEsp8266UartMethod.h"
|
||||
#include <utility>
|
||||
extern "C"
|
||||
{
|
||||
#include <ets_sys.h>
|
||||
}
|
||||
|
||||
const volatile uint8_t* ICACHE_RAM_ATTR NeoEsp8266UartContext::FillUartFifo(uint8_t uartNum,
|
||||
const volatile uint8_t* pixels,
|
||||
const volatile uint8_t* end)
|
||||
{
|
||||
// Remember: UARTs send less significant bit (LSB) first so
|
||||
// pushing ABCDEF byte will generate a 0FEDCBA1 signal,
|
||||
// including a LOW(0) start & a HIGH(1) stop bits.
|
||||
// Also, we have configured UART to invert logic levels, so:
|
||||
const uint8_t _uartData[4] = {
|
||||
0b110111, // On wire: 1 000 100 0 [Neopixel reads 00]
|
||||
0b000111, // On wire: 1 000 111 0 [Neopixel reads 01]
|
||||
0b110100, // On wire: 1 110 100 0 [Neopixel reads 10]
|
||||
0b000100, // On wire: 1 110 111 0 [NeoPixel reads 11]
|
||||
};
|
||||
uint8_t avail = (UART_TX_FIFO_SIZE - GetTxFifoLength(uartNum)) / 4;
|
||||
if (end - pixels > avail)
|
||||
{
|
||||
end = pixels + avail;
|
||||
}
|
||||
while (pixels < end)
|
||||
{
|
||||
uint8_t subpix = *pixels++;
|
||||
Enqueue(uartNum, _uartData[(subpix >> 6) & 0x3]);
|
||||
Enqueue(uartNum, _uartData[(subpix >> 4) & 0x3]);
|
||||
Enqueue(uartNum, _uartData[(subpix >> 2) & 0x3]);
|
||||
Enqueue(uartNum, _uartData[subpix & 0x3]);
|
||||
}
|
||||
return pixels;
|
||||
}
|
||||
|
||||
volatile NeoEsp8266UartInterruptContext* NeoEsp8266UartInterruptContext::s_uartInteruptContext[] = { nullptr, nullptr };
|
||||
|
||||
void NeoEsp8266UartInterruptContext::StartSending(uint8_t uartNum, uint8_t* start, uint8_t* end)
|
||||
{
|
||||
// send the pixels asynchronously
|
||||
_asyncBuff = start;
|
||||
_asyncBuffEnd = end;
|
||||
|
||||
// enable the transmit interrupt
|
||||
USIE(uartNum) |= (1 << UIFE);
|
||||
}
|
||||
|
||||
void NeoEsp8266UartInterruptContext::Attach(uint8_t uartNum)
|
||||
{
|
||||
// Disable all interrupts
|
||||
ETS_UART_INTR_DISABLE();
|
||||
|
||||
// Clear the RX & TX FIFOS
|
||||
const uint32_t fifoResetFlags = (1 << UCTXRST) | (1 << UCRXRST);
|
||||
USC0(uartNum) |= fifoResetFlags;
|
||||
USC0(uartNum) &= ~(fifoResetFlags);
|
||||
|
||||
// attach the ISR if needed
|
||||
if (s_uartInteruptContext[0] == nullptr &&
|
||||
s_uartInteruptContext[1] == nullptr)
|
||||
{
|
||||
ETS_UART_INTR_ATTACH(Isr, s_uartInteruptContext);
|
||||
}
|
||||
|
||||
// attach the context
|
||||
s_uartInteruptContext[uartNum] = this;
|
||||
|
||||
// Set tx fifo trigger. 80 bytes gives us 200 microsecs to refill the FIFO
|
||||
USC1(uartNum) = (80 << UCFET);
|
||||
|
||||
// Disable RX & TX interrupts. It maybe still enabled by uart.c in the SDK
|
||||
USIE(uartNum) &= ~((1 << UIFF) | (1 << UIFE));
|
||||
|
||||
// Clear all pending interrupts in UART1
|
||||
USIC(uartNum) = 0xffff;
|
||||
|
||||
// Reenable interrupts
|
||||
ETS_UART_INTR_ENABLE();
|
||||
}
|
||||
|
||||
void NeoEsp8266UartInterruptContext::Detach(uint8_t uartNum)
|
||||
{
|
||||
// Disable interrupts
|
||||
ETS_UART_INTR_DISABLE();
|
||||
|
||||
if (s_uartInteruptContext[uartNum] != nullptr)
|
||||
{
|
||||
// turn off uart
|
||||
USC1(uartNum) = 0;
|
||||
USIC(uartNum) = 0xffff;
|
||||
USIE(uartNum) = 0;
|
||||
|
||||
s_uartInteruptContext[uartNum] = nullptr;
|
||||
|
||||
if (s_uartInteruptContext[0] == nullptr &&
|
||||
s_uartInteruptContext[1] == nullptr)
|
||||
{
|
||||
// detach our ISR
|
||||
ETS_UART_INTR_ATTACH(NULL, NULL);
|
||||
|
||||
// return so we don't enable interrupts since there is no ISR anymore
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Reenable interrupts
|
||||
ETS_UART_INTR_ENABLE();
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR NeoEsp8266UartInterruptContext::Isr(void* param)
|
||||
{
|
||||
// make sure this is for us
|
||||
if (param == s_uartInteruptContext)
|
||||
{
|
||||
// Interrupt handler is shared between UART0 & UART1
|
||||
// so we need to test for both
|
||||
for (uint8_t uartNum = 0; uartNum < 2; uartNum++)
|
||||
{
|
||||
if (USIS(uartNum) && s_uartInteruptContext[uartNum] != nullptr)
|
||||
{
|
||||
// Fill the FIFO with new data
|
||||
s_uartInteruptContext[uartNum]->_asyncBuff = FillUartFifo(
|
||||
uartNum,
|
||||
s_uartInteruptContext[uartNum]->_asyncBuff,
|
||||
s_uartInteruptContext[uartNum]->_asyncBuffEnd);
|
||||
|
||||
// Disable TX interrupt when done
|
||||
if (s_uartInteruptContext[uartNum]->_asyncBuff == s_uartInteruptContext[uartNum]->_asyncBuffEnd)
|
||||
{
|
||||
// clear the TX FIFO Empty
|
||||
USIE(uartNum) &= ~(1 << UIFE);
|
||||
}
|
||||
|
||||
// Clear all interrupts flags (just in case)
|
||||
USIC(uartNum) = 0xffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
431
lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.h
Normal file
@ -0,0 +1,431 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Esp8266 UART hardware
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <Arduino.h>
|
||||
|
||||
// this template method class is used to track the data being sent on the uart
|
||||
// when using the default serial ISR installed by the core
|
||||
// used with NeoEsp8266Uart and NeoEsp8266AsyncUart classes
|
||||
//
|
||||
class NeoEsp8266UartContext
|
||||
{
|
||||
public:
|
||||
// Gets the number of bytes waiting in the TX FIFO
|
||||
static inline uint8_t ICACHE_RAM_ATTR GetTxFifoLength(uint8_t uartNum)
|
||||
{
|
||||
return (USS(uartNum) >> USTXC) & 0xff;
|
||||
}
|
||||
// Append a byte to the TX FIFO
|
||||
static inline void ICACHE_RAM_ATTR Enqueue(uint8_t uartNum, uint8_t value)
|
||||
{
|
||||
USF(uartNum) = value;
|
||||
}
|
||||
|
||||
static const volatile uint8_t* ICACHE_RAM_ATTR FillUartFifo(uint8_t uartNum,
|
||||
const volatile uint8_t* pixels,
|
||||
const volatile uint8_t* end);
|
||||
};
|
||||
|
||||
// this template method class is used to track the data being sent on the uart
|
||||
// when using our own UART ISR
|
||||
// used with NeoEsp8266Uart and NeoEsp8266AsyncUart classes
|
||||
//
|
||||
class NeoEsp8266UartInterruptContext : NeoEsp8266UartContext
|
||||
{
|
||||
public:
|
||||
NeoEsp8266UartInterruptContext() :
|
||||
_asyncBuff(nullptr),
|
||||
_asyncBuffEnd(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
bool IsSending()
|
||||
{
|
||||
return (_asyncBuff != _asyncBuffEnd);
|
||||
}
|
||||
|
||||
void StartSending(uint8_t uartNum, uint8_t* start, uint8_t* end);
|
||||
void Attach(uint8_t uartNum);
|
||||
void Detach(uint8_t uartNum);
|
||||
|
||||
private:
|
||||
volatile const uint8_t* _asyncBuff;
|
||||
volatile const uint8_t* _asyncBuffEnd;
|
||||
volatile static NeoEsp8266UartInterruptContext* s_uartInteruptContext[2];
|
||||
|
||||
static void ICACHE_RAM_ATTR Isr(void* param);
|
||||
};
|
||||
|
||||
// this template feature class is used a base for all others and contains
|
||||
// common methods
|
||||
//
|
||||
class UartFeatureBase
|
||||
{
|
||||
protected:
|
||||
static void ConfigUart(uint8_t uartNum)
|
||||
{
|
||||
// clear all invert bits
|
||||
USC0(uartNum) &= ~((1 << UCDTRI) | (1 << UCRTSI) | (1 << UCTXI) | (1 << UCDSRI) | (1 << UCCTSI) | (1 << UCRXI));
|
||||
// Invert the TX voltage associated with logic level so:
|
||||
// - A logic level 0 will generate a Vcc signal
|
||||
// - A logic level 1 will generate a Gnd signal
|
||||
USC0(uartNum) |= (1 << UCTXI);
|
||||
}
|
||||
};
|
||||
|
||||
// this template feature class is used to define the specifics for uart0
|
||||
// used with NeoEsp8266Uart and NeoEsp8266AsyncUart classes
|
||||
//
|
||||
class UartFeature0 : UartFeatureBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t Index = 0;
|
||||
static void Init(uint32_t baud)
|
||||
{
|
||||
// Configure the serial line with 1 start bit (0), 6 data bits and 1 stop bit (1)
|
||||
Serial.begin(baud, SERIAL_6N1, SERIAL_TX_ONLY);
|
||||
ConfigUart(Index);
|
||||
}
|
||||
};
|
||||
|
||||
// this template feature class is used to define the specifics for uart1
|
||||
// used with NeoEsp8266Uart and NeoEsp8266AsyncUart classes
|
||||
//
|
||||
class UartFeature1 : UartFeatureBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t Index = 1;
|
||||
static void Init(uint32_t baud)
|
||||
{
|
||||
// Configure the serial line with 1 start bit (0), 6 data bits and 1 stop bit (1)
|
||||
Serial1.begin(baud, SERIAL_6N1, SERIAL_TX_ONLY);
|
||||
ConfigUart(Index);
|
||||
}
|
||||
};
|
||||
|
||||
// this template method class is used a base for all others and contains
|
||||
// common properties and methods
|
||||
//
|
||||
// used by NeoEsp8266Uart and NeoEsp8266AsyncUart
|
||||
//
|
||||
class NeoEsp8266UartBase
|
||||
{
|
||||
protected:
|
||||
size_t _sizePixels; // Size of '_pixels' buffer below
|
||||
uint8_t* _pixels; // Holds LED color values
|
||||
uint32_t _startTime; // Microsecond count when last update started
|
||||
|
||||
NeoEsp8266UartBase(uint16_t pixelCount, size_t elementSize)
|
||||
{
|
||||
_sizePixels = pixelCount * elementSize;
|
||||
_pixels = (uint8_t*)malloc(_sizePixels);
|
||||
memset(_pixels, 0x00, _sizePixels);
|
||||
}
|
||||
|
||||
~NeoEsp8266UartBase()
|
||||
{
|
||||
free(_pixels);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// this template method class is used to glue uart feature and context for
|
||||
// synchronous uart method
|
||||
//
|
||||
// used by NeoEsp8266UartMethodBase
|
||||
//
|
||||
template<typename T_UARTFEATURE, typename T_UARTCONTEXT> class NeoEsp8266Uart : public NeoEsp8266UartBase
|
||||
{
|
||||
protected:
|
||||
|
||||
NeoEsp8266Uart(uint16_t pixelCount, size_t elementSize) :
|
||||
NeoEsp8266UartBase(pixelCount, elementSize)
|
||||
{
|
||||
}
|
||||
|
||||
~NeoEsp8266Uart()
|
||||
{
|
||||
// Wait until the TX fifo is empty. This way we avoid broken frames
|
||||
// when destroying & creating a NeoPixelBus to change its length.
|
||||
while (T_UARTCONTEXT::GetTxFifoLength(T_UARTFEATURE::Index) > 0)
|
||||
{
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
void InitializeUart(uint32_t uartBaud)
|
||||
{
|
||||
T_UARTFEATURE::Init(uartBaud);
|
||||
}
|
||||
|
||||
void UpdateUart(bool)
|
||||
{
|
||||
// Since the UART can finish sending queued bytes in the FIFO in
|
||||
// the background, instead of waiting for the FIFO to flush
|
||||
// we annotate the start time of the frame so we can calculate
|
||||
// when it will finish.
|
||||
_startTime = micros();
|
||||
|
||||
// Then keep filling the FIFO until done
|
||||
const uint8_t* ptr = _pixels;
|
||||
const uint8_t* end = ptr + _sizePixels;
|
||||
while (ptr != end)
|
||||
{
|
||||
ptr = const_cast<uint8_t*>(T_UARTCONTEXT::FillUartFifo(T_UARTFEATURE::Index, ptr, end));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// this template method class is used to glue uart feature and context for
|
||||
// asynchronously uart method
|
||||
//
|
||||
// This UART controller uses two buffers that are swapped in every call to
|
||||
// NeoPixelBus.Show(). One buffer contains the data that is being sent
|
||||
// asynchronosly and another buffer contains the data that will be send
|
||||
// in the next call to NeoPixelBus.Show().
|
||||
//
|
||||
// Therefore, the result of NeoPixelBus.Pixels() is invalidated after
|
||||
// every call to NeoPixelBus.Show() and must not be cached.
|
||||
//
|
||||
// used by NeoEsp8266UartMethodBase
|
||||
//
|
||||
template<typename T_UARTFEATURE, typename T_UARTCONTEXT> class NeoEsp8266AsyncUart : public NeoEsp8266UartBase
|
||||
{
|
||||
protected:
|
||||
NeoEsp8266AsyncUart(uint16_t pixelCount, size_t elementSize) :
|
||||
NeoEsp8266UartBase(pixelCount, elementSize)
|
||||
{
|
||||
_pixelsSending = (uint8_t*)malloc(_sizePixels);
|
||||
}
|
||||
|
||||
~NeoEsp8266AsyncUart()
|
||||
{
|
||||
// Remember: the UART interrupt can be sending data from _pixelsSending in the background
|
||||
while (_context.IsSending())
|
||||
{
|
||||
yield();
|
||||
}
|
||||
// detach context, which will disable intr, may disable ISR
|
||||
_context.Detach(T_UARTFEATURE::Index);
|
||||
|
||||
free(_pixelsSending);
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR InitializeUart(uint32_t uartBaud)
|
||||
{
|
||||
T_UARTFEATURE::Init(uartBaud);
|
||||
|
||||
// attach the context, which will enable the ISR
|
||||
_context.Attach(T_UARTFEATURE::Index);
|
||||
}
|
||||
|
||||
void UpdateUart(bool maintainBufferConsistency)
|
||||
{
|
||||
// Instruct ESP8266 hardware uart to send the pixels asynchronously
|
||||
_context.StartSending(T_UARTFEATURE::Index,
|
||||
_pixels,
|
||||
_pixels + _sizePixels);
|
||||
|
||||
// Annotate when we started to send bytes, so we can calculate when we are ready to send again
|
||||
_startTime = micros();
|
||||
|
||||
if (maintainBufferConsistency)
|
||||
{
|
||||
// copy editing to sending,
|
||||
// this maintains the contract that "colors present before will
|
||||
// be the same after", otherwise GetPixelColor will be inconsistent
|
||||
memcpy(_pixelsSending, _pixels, _sizePixels);
|
||||
}
|
||||
|
||||
// swap so the user can modify without affecting the async operation
|
||||
std::swap(_pixelsSending, _pixels);
|
||||
}
|
||||
|
||||
private:
|
||||
T_UARTCONTEXT _context;
|
||||
|
||||
uint8_t* _pixelsSending; // Holds a copy of LED color values taken when UpdateUart began
|
||||
};
|
||||
|
||||
class NeoEsp8266UartSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed
|
||||
static const uint32_t UartBaud = 3200000; // 800mhz, 4 serial bytes per NeoByte
|
||||
};
|
||||
|
||||
// NeoEsp8266UartSpeedWs2813 contains the timing constants used to get NeoPixelBus running with the Ws2813
|
||||
class NeoEsp8266UartSpeedWs2812x : public NeoEsp8266UartSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 300; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
class NeoEsp8266UartSpeedSk6812 : public NeoEsp8266UartSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 80; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
// NeoEsp8266UartSpeed800Kbps contains the timing constant used to get NeoPixelBus running at 800Khz
|
||||
class NeoEsp8266UartSpeed800Kbps : public NeoEsp8266UartSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
// NeoEsp8266UartSpeed400Kbps contains the timing constant used to get NeoPixelBus running at 400Khz
|
||||
class NeoEsp8266UartSpeed400Kbps
|
||||
{
|
||||
public:
|
||||
static const uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed
|
||||
static const uint32_t UartBaud = 1600000; // 400mhz, 4 serial bytes per NeoByte
|
||||
static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
// NeoEsp8266UartSpeedApa106 contains the timing constant used to get NeoPixelBus running for Apa106
|
||||
// Pulse cycle = 1.71 = 1.368 longer than normal, 0.731 slower, NeoEsp8266UartSpeedApa1066
|
||||
class NeoEsp8266UartSpeedApa106
|
||||
{
|
||||
public:
|
||||
static const uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element at 400khz speed
|
||||
static const uint32_t UartBaud = 2339181; // APA106 pulse cycle of 1.71us, 4 serial bytes per NeoByte
|
||||
static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
// NeoEsp8266UartMethodBase is a light shell arround NeoEsp8266Uart or NeoEsp8266AsyncUart that
|
||||
// implements the methods needed to operate as a NeoPixelBus method.
|
||||
template<typename T_SPEED, typename T_BASE>
|
||||
class NeoEsp8266UartMethodBase: public T_BASE
|
||||
{
|
||||
public:
|
||||
NeoEsp8266UartMethodBase(uint16_t pixelCount, size_t elementSize)
|
||||
: T_BASE(pixelCount, elementSize)
|
||||
{
|
||||
}
|
||||
NeoEsp8266UartMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize)
|
||||
: T_BASE(pixelCount, elementSize)
|
||||
{
|
||||
}
|
||||
|
||||
bool IsReadyToUpdate() const
|
||||
{
|
||||
uint32_t delta = micros() - this->_startTime;
|
||||
return delta >= getPixelTime() + T_SPEED::ResetTimeUs;
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
this->InitializeUart(T_SPEED::UartBaud);
|
||||
|
||||
// Inverting logic levels can generate a phantom bit in the led strip bus
|
||||
// We need to delay 50+ microseconds the output stream to force a data
|
||||
// latch and discard this bit. Otherwise, that bit would be prepended to
|
||||
// the first frame corrupting it.
|
||||
this->_startTime = micros() - getPixelTime();
|
||||
}
|
||||
|
||||
void Update(bool maintainBufferConsistency)
|
||||
{
|
||||
// Data latch = 50+ microsecond pause in the output stream. Rather than
|
||||
// put a delay at the end of the function, the ending time is noted and
|
||||
// the function will simply hold off (if needed) on issuing the
|
||||
// subsequent round of data until the latch time has elapsed. This
|
||||
// allows the mainline code to start generating the next frame of data
|
||||
// rather than stalling for the latch.
|
||||
while (!this->IsReadyToUpdate())
|
||||
{
|
||||
yield();
|
||||
}
|
||||
this->UpdateUart(maintainBufferConsistency);
|
||||
}
|
||||
|
||||
uint8_t* getPixels() const
|
||||
{
|
||||
return this->_pixels;
|
||||
};
|
||||
|
||||
size_t getPixelsSize() const
|
||||
{
|
||||
return this->_sizePixels;
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t getPixelTime() const
|
||||
{
|
||||
return (T_SPEED::ByteSendTimeUs * this->_sizePixels);
|
||||
};
|
||||
};
|
||||
|
||||
// uart 0
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedWs2812x, NeoEsp8266Uart<UartFeature0, NeoEsp8266UartContext>> NeoEsp8266Uart0Ws2812xMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedSk6812, NeoEsp8266Uart<UartFeature0, NeoEsp8266UartContext>> NeoEsp8266Uart0Sk6812Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedApa106, NeoEsp8266Uart<UartFeature0, NeoEsp8266UartContext>> NeoEsp8266Uart0Apa106Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed800Kbps, NeoEsp8266Uart<UartFeature0, NeoEsp8266UartContext>> NeoEsp8266Uart0800KbpsMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed400Kbps, NeoEsp8266Uart<UartFeature0, NeoEsp8266UartContext>> NeoEsp8266Uart0400KbpsMethod;
|
||||
|
||||
typedef NeoEsp8266Uart0Ws2812xMethod NeoEsp8266Uart0Ws2813Method;
|
||||
typedef NeoEsp8266Uart0800KbpsMethod NeoEsp8266Uart0Ws2812Method;
|
||||
typedef NeoEsp8266Uart0Sk6812Method NeoEsp8266Uart0Lc8812Method;
|
||||
|
||||
// uart 1
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedWs2812x, NeoEsp8266Uart<UartFeature1, NeoEsp8266UartContext>> NeoEsp8266Uart1Ws2812xMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedSk6812, NeoEsp8266Uart<UartFeature1, NeoEsp8266UartContext>> NeoEsp8266Uart1Sk6812Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedApa106, NeoEsp8266Uart<UartFeature1, NeoEsp8266UartContext>> NeoEsp8266Uart1Apa106Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed800Kbps, NeoEsp8266Uart<UartFeature1, NeoEsp8266UartContext>> NeoEsp8266Uart1800KbpsMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed400Kbps, NeoEsp8266Uart<UartFeature1, NeoEsp8266UartContext>> NeoEsp8266Uart1400KbpsMethod;
|
||||
|
||||
typedef NeoEsp8266Uart1Ws2812xMethod NeoEsp8266Uart1Ws2813Method;
|
||||
typedef NeoEsp8266Uart1800KbpsMethod NeoEsp8266Uart1Ws2812Method;
|
||||
typedef NeoEsp8266Uart1Sk6812Method NeoEsp8266Uart1Lc8812Method;
|
||||
|
||||
// uart 0 async
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedWs2812x, NeoEsp8266AsyncUart<UartFeature0, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart0Ws2812xMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedSk6812, NeoEsp8266AsyncUart<UartFeature0, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart0Sk6812Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedApa106, NeoEsp8266AsyncUart<UartFeature0, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart0Apa106Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed800Kbps, NeoEsp8266AsyncUart<UartFeature0, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart0800KbpsMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed400Kbps, NeoEsp8266AsyncUart<UartFeature0, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart0400KbpsMethod;
|
||||
|
||||
typedef NeoEsp8266AsyncUart0Ws2812xMethod NeoEsp8266AsyncUart0Ws2813Method;
|
||||
typedef NeoEsp8266AsyncUart0800KbpsMethod NeoEsp8266AsyncUart0Ws2812Method;
|
||||
typedef NeoEsp8266AsyncUart0Sk6812Method NeoEsp8266AsyncUart0Lc8812Method;
|
||||
|
||||
// uart 1 async
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedWs2812x, NeoEsp8266AsyncUart<UartFeature1, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart1Ws2812xMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedSk6812, NeoEsp8266AsyncUart<UartFeature1, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart1Sk6812Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeedApa106, NeoEsp8266AsyncUart<UartFeature1, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart1Apa106Method;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed800Kbps, NeoEsp8266AsyncUart<UartFeature1, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart1800KbpsMethod;
|
||||
typedef NeoEsp8266UartMethodBase<NeoEsp8266UartSpeed400Kbps, NeoEsp8266AsyncUart<UartFeature1, NeoEsp8266UartInterruptContext>> NeoEsp8266AsyncUart1400KbpsMethod;
|
||||
|
||||
typedef NeoEsp8266AsyncUart1Ws2812xMethod NeoEsp8266AsyncUart1Ws2813Method;
|
||||
typedef NeoEsp8266AsyncUart1800KbpsMethod NeoEsp8266AsyncUart1Ws2812Method;
|
||||
typedef NeoEsp8266AsyncUart1Sk6812Method NeoEsp8266AsyncUart1Lc8812Method;
|
||||
|
||||
#endif
|
||||
|
@ -39,14 +39,24 @@ License along with NeoPixel. If not, see
|
||||
extern "C" void ICACHE_RAM_ATTR bitbang_send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin);
|
||||
extern "C" void ICACHE_RAM_ATTR bitbang_send_pixels_400(uint8_t* pixels, uint8_t* end, uint8_t pin);
|
||||
|
||||
class NeoEspBitBangSpeedWs2813
|
||||
class NeoEspBitBangSpeedWs2812x
|
||||
{
|
||||
public:
|
||||
static void send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin)
|
||||
{
|
||||
bitbang_send_pixels_800(pixels, end, pin);
|
||||
}
|
||||
static const uint32_t ResetTimeUs = 250;
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoEspBitBangSpeedSk6812
|
||||
{
|
||||
public:
|
||||
static void send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin)
|
||||
{
|
||||
bitbang_send_pixels_800(pixels, end, pin);
|
||||
}
|
||||
static const uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoEspBitBangSpeed800Kbps
|
||||
@ -103,7 +113,7 @@ public:
|
||||
_endTime = micros();
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update(bool)
|
||||
{
|
||||
// Data latch = 50+ microsecond pause in the output stream. Rather than
|
||||
// put a delay at the end of the function, the ending time is noted and
|
||||
@ -116,11 +126,23 @@ public:
|
||||
yield(); // allows for system yield if needed
|
||||
}
|
||||
|
||||
noInterrupts(); // Need 100% focus on instruction timing
|
||||
// Need 100% focus on instruction timing
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
delay(1); // required
|
||||
portMUX_TYPE updateMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
portENTER_CRITICAL(&updateMux);
|
||||
#else
|
||||
noInterrupts();
|
||||
#endif
|
||||
|
||||
T_SPEED::send_pixels(_pixels, _pixels + _sizePixels, _pin);
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
portEXIT_CRITICAL(&updateMux);
|
||||
#else
|
||||
interrupts();
|
||||
#endif
|
||||
|
||||
// save EOD time for latch on next call
|
||||
_endTime = micros();
|
||||
@ -146,21 +168,28 @@ private:
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeedWs2813> NeoEsp32BitBangWs2813Method;
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeedWs2812x> NeoEsp32BitBangWs2812xMethod;
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeedSk6812> NeoEsp32BitBangSk6812Method;
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeed800Kbps> NeoEsp32BitBang800KbpsMethod;
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeed400Kbps> NeoEsp32BitBang400KbpsMethod;
|
||||
|
||||
// Bitbang method is the default method for Esp32
|
||||
typedef NeoEsp32BitBangWs2813Method NeoWs2813Method;
|
||||
typedef NeoEsp32BitBang800KbpsMethod Neo800KbpsMethod;
|
||||
typedef NeoEsp32BitBang400KbpsMethod Neo400KbpsMethod;
|
||||
typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2813Method;
|
||||
typedef NeoEsp32BitBang800KbpsMethod NeoEsp32BitBangWs2812Method;
|
||||
typedef NeoEsp32BitBangSk6812Method NeoEsp32BitBangLc8812Method;
|
||||
typedef NeoEsp32BitBang400KbpsMethod NeoEsp32BitBangApa106Method;
|
||||
|
||||
#else
|
||||
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeedWs2813> NeoEsp8266BitBangWs2813Method;
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeedWs2812x> NeoEsp8266BitBangWs2812xMethod;
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeedSk6812> NeoEsp8266BitBangSk6812Method;
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeed800Kbps> NeoEsp8266BitBang800KbpsMethod;
|
||||
typedef NeoEspBitBangMethodBase<NeoEspBitBangSpeed400Kbps> NeoEsp8266BitBang400KbpsMethod;
|
||||
|
||||
typedef NeoEsp8266BitBangWs2812xMethod NeoEsp8266BitBangWs2813Method;
|
||||
typedef NeoEsp8266BitBang800KbpsMethod NeoEsp8266BitBangWs2812Method;
|
||||
typedef NeoEsp8266BitBangSk6812Method NeoEsp8266BitBangLc8812Method;
|
||||
typedef NeoEsp8266BitBang400KbpsMethod NeoEsp8266BitBangApa106Method;
|
||||
#endif
|
||||
|
||||
// ESP bitbang doesn't have defaults and should avoided except for testing
|
||||
#endif
|
@ -1,5 +1,6 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixelGamma class is used to correct RGB colors for human eye gamma levels
|
||||
NeoGamma class is used to correct RGB colors for human eye gamma levels equally
|
||||
across all color channels
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
@ -142,7 +142,7 @@ void NeoPixelAnimator::UpdateAnimations()
|
||||
if (pAnim->_remaining > delta)
|
||||
{
|
||||
param.state = (pAnim->_remaining == pAnim->_duration) ? AnimationState_Started : AnimationState_Progress;
|
||||
param.progress = (float)(pAnim->_duration - pAnim->_remaining) / (float)pAnim->_duration;
|
||||
param.progress = pAnim->CurrentProgress();
|
||||
|
||||
fnUpdate(param);
|
||||
|
||||
@ -164,3 +164,33 @@ void NeoPixelAnimator::UpdateAnimations()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NeoPixelAnimator::ChangeAnimationDuration(uint16_t indexAnimation, uint16_t newDuration)
|
||||
{
|
||||
if (indexAnimation >= _countAnimations)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AnimationContext* pAnim = &_animations[indexAnimation];
|
||||
|
||||
// calc the current animation progress
|
||||
float progress = pAnim->CurrentProgress();
|
||||
|
||||
// keep progress in range just in case
|
||||
if (progress < 0.0f)
|
||||
{
|
||||
progress = 0.0f;
|
||||
}
|
||||
else if (progress > 1.0f)
|
||||
{
|
||||
progress = 1.0f;
|
||||
}
|
||||
|
||||
// change the duration
|
||||
pAnim->_duration = newDuration;
|
||||
|
||||
// _remaining time must also be reset after a duration change;
|
||||
// use the progress to recalculate it
|
||||
pAnim->_remaining = uint16_t(pAnim->_duration * (1.0f - progress));
|
||||
}
|
@ -64,7 +64,7 @@ void send_pixels_8mhz_800_PortD(uint8_t* pixels, size_t sizePixels, uint8_t pinM
|
||||
volatile uint8_t lo; // PORT w/output bit set low
|
||||
|
||||
volatile uint8_t n1;
|
||||
volatile n2 = 0; // First, next bits out
|
||||
volatile uint8_t n2 = 0; // First, next bits out
|
||||
|
||||
// Squeezing an 800 KHz stream out of an 8 MHz chip requires code
|
||||
// specific to each PORT register. At present this is only written
|
||||
@ -189,7 +189,7 @@ void send_pixels_8mhz_800_PortB(uint8_t* pixels, size_t sizePixels, uint8_t pinM
|
||||
volatile uint8_t lo; // PORT w/output bit set low
|
||||
|
||||
volatile uint8_t n1;
|
||||
volatile n2 = 0; // First, next bits out
|
||||
volatile uint8_t n2 = 0; // First, next bits out
|
||||
|
||||
// Same as above, just switched to PORTB and stripped of comments.
|
||||
hi = PORTB | pinMask;
|
||||
@ -645,4 +645,4 @@ void send_pixels_16mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t*
|
||||
#error "CPU SPEED NOT SUPPORTED"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
169
lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelEsp.c
Normal file
@ -0,0 +1,169 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Esp8266 and Esp32.
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
|
||||
#include <Arduino.h>
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <eagle_soc.h>
|
||||
#endif
|
||||
|
||||
// ESP32 doesn't define ICACHE_RAM_ATTR
|
||||
#ifndef ICACHE_RAM_ATTR
|
||||
#define ICACHE_RAM_ATTR IRAM_ATTR
|
||||
#endif
|
||||
|
||||
static uint32_t _getCycleCount(void) __attribute__((always_inline));
|
||||
|
||||
static inline uint32_t _getCycleCount(void)
|
||||
{
|
||||
uint32_t ccount;
|
||||
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
|
||||
return ccount;
|
||||
}
|
||||
|
||||
#define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us
|
||||
#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us
|
||||
#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit
|
||||
#define CYCLES_400_T0H (F_CPU / 2000000)
|
||||
#define CYCLES_400_T1H (F_CPU / 833333)
|
||||
#define CYCLES_400 (F_CPU / 400000)
|
||||
|
||||
void ICACHE_RAM_ATTR bitbang_send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin)
|
||||
{
|
||||
const uint32_t pinRegister = _BV(pin);
|
||||
uint8_t mask = 0x80;
|
||||
uint8_t subpix = *pixels++;
|
||||
uint32_t cyclesStart = 0; // trigger emediately
|
||||
uint32_t cyclesNext = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
// do the checks here while we are waiting on time to pass
|
||||
uint32_t cyclesBit = CYCLES_800_T0H;
|
||||
if (subpix & mask)
|
||||
{
|
||||
cyclesBit = CYCLES_800_T1H;
|
||||
}
|
||||
|
||||
// after we have done as much work as needed for this next bit
|
||||
// now wait for the HIGH
|
||||
while (((cyclesStart = _getCycleCount()) - cyclesNext) < CYCLES_800);
|
||||
|
||||
// set high
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1ts = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister);
|
||||
#endif
|
||||
|
||||
// wait for the LOW
|
||||
while ((_getCycleCount() - cyclesStart) < cyclesBit);
|
||||
|
||||
// set low
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1tc = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister);
|
||||
#endif
|
||||
cyclesNext = cyclesStart;
|
||||
|
||||
// next bit
|
||||
mask >>= 1;
|
||||
if (mask == 0)
|
||||
{
|
||||
// no more bits to send in this byte
|
||||
// check for another byte
|
||||
if (pixels >= end)
|
||||
{
|
||||
// no more bytes to send so stop
|
||||
break;
|
||||
}
|
||||
// reset mask to first bit and get the next byte
|
||||
mask = 0x80;
|
||||
subpix = *pixels++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR bitbang_send_pixels_400(uint8_t* pixels, uint8_t* end, uint8_t pin)
|
||||
{
|
||||
const uint32_t pinRegister = _BV(pin);
|
||||
uint8_t mask = 0x80;
|
||||
uint8_t subpix = *pixels++;
|
||||
uint32_t cyclesStart = 0; // trigger emediately
|
||||
uint32_t cyclesNext = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
// do the checks here while we are waiting on time to pass
|
||||
uint32_t cyclesBit = CYCLES_400_T0H;
|
||||
if (subpix & mask)
|
||||
{
|
||||
cyclesBit = CYCLES_400_T1H;
|
||||
}
|
||||
|
||||
// after we have done as much work as needed for this next bit
|
||||
// now wait for the HIGH
|
||||
while (((cyclesStart = _getCycleCount()) - cyclesNext) < CYCLES_400);
|
||||
|
||||
// set high
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1ts = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister);
|
||||
#endif
|
||||
|
||||
// wait for the LOW
|
||||
while ((_getCycleCount() - cyclesStart) < cyclesBit);
|
||||
|
||||
// set low
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1tc = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister);
|
||||
#endif
|
||||
cyclesNext = cyclesStart;
|
||||
|
||||
// next bit
|
||||
mask >>= 1;
|
||||
if (mask == 0)
|
||||
{
|
||||
// no more bits to send in this byte
|
||||
// check for another byte
|
||||
if (pixels >= end)
|
||||
{
|
||||
// no more bytes to send so stop
|
||||
break;
|
||||
}
|
||||
// reset mask to first bit and get the next byte
|
||||
mask = 0x80;
|
||||
subpix = *pixels++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -56,6 +56,33 @@ public:
|
||||
return _map(ring, pixel);
|
||||
}
|
||||
|
||||
uint16_t RingPixelShift(uint8_t ring, uint16_t pixel, int16_t shift)
|
||||
{
|
||||
int32_t ringPixel = pixel;
|
||||
ringPixel += shift;
|
||||
|
||||
if (ringPixel < 0)
|
||||
{
|
||||
ringPixel = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t count = getPixelCountAtRing(ring);
|
||||
if (ringPixel >= count)
|
||||
{
|
||||
ringPixel = count - 1;
|
||||
}
|
||||
}
|
||||
return ringPixel;
|
||||
}
|
||||
|
||||
uint16_t RingPixelRotate(uint8_t ring, uint16_t pixel, int16_t rotate)
|
||||
{
|
||||
int32_t ringPixel = pixel;
|
||||
ringPixel += rotate;
|
||||
return ringPixel % getPixelCountAtRing(ring);
|
||||
}
|
||||
|
||||
uint8_t getCountOfRings() const
|
||||
{
|
||||
return _ringCount() - 1; // minus one as the Rings includes the extra value
|
@ -146,15 +146,15 @@ private:
|
||||
|
||||
uint16_t pixelIndex(uint16_t indexSprite,
|
||||
int16_t x,
|
||||
int16_t y)
|
||||
int16_t y) const
|
||||
{
|
||||
uint16_t result = PixelIndex_OutOfBounds;
|
||||
|
||||
if (indexSprite < _spriteCount &&
|
||||
x >= 0 &&
|
||||
x < SpriteWidth() &&
|
||||
(uint16_t)x < SpriteWidth() &&
|
||||
y >= 0 &&
|
||||
y < SpriteHeight())
|
||||
(uint16_t)y < SpriteHeight())
|
||||
{
|
||||
result = x + y * SpriteWidth() + indexSprite * _spriteHeight * SpriteWidth();
|
||||
}
|