From 0e06c9ccc40984d6530e05003789e3d90a711853 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Thu, 26 Oct 2023 21:38:58 +0200 Subject: [PATCH 01/25] [NEOPIXEL] Add NeoPixelBus_wrapper and implement in NeoPixel plugins --- lib/NeoPixelBus_wrapper/LICENSE | 674 ++++++++++++++++++ lib/NeoPixelBus_wrapper/README.md | 27 + lib/NeoPixelBus_wrapper/library.properties | 10 + .../src/NeoPixelBus_wrapper.cpp | 117 +++ .../src/NeoPixelBus_wrapper.h | 64 ++ src/_P041_NeoClock.ino | 6 +- src/src/PluginStructs/P038_data_struct.cpp | 8 +- src/src/PluginStructs/P038_data_struct.h | 4 +- src/src/PluginStructs/P042_data_struct.cpp | 2 +- src/src/PluginStructs/P042_data_struct.h | 4 +- src/src/PluginStructs/P070_data_struct.cpp | 2 +- src/src/PluginStructs/P070_data_struct.h | 4 +- 12 files changed, 907 insertions(+), 15 deletions(-) create mode 100644 lib/NeoPixelBus_wrapper/LICENSE create mode 100644 lib/NeoPixelBus_wrapper/README.md create mode 100644 lib/NeoPixelBus_wrapper/library.properties create mode 100644 lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp create mode 100644 lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.h diff --git a/lib/NeoPixelBus_wrapper/LICENSE b/lib/NeoPixelBus_wrapper/LICENSE new file mode 100644 index 0000000000..f288702d2f --- /dev/null +++ b/lib/NeoPixelBus_wrapper/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + + Copyright (C) + + 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 . + +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: + + Copyright (C) + 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 +. + + 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 +. diff --git a/lib/NeoPixelBus_wrapper/README.md b/lib/NeoPixelBus_wrapper/README.md new file mode 100644 index 0000000000..1ac59f7fea --- /dev/null +++ b/lib/NeoPixelBus_wrapper/README.md @@ -0,0 +1,27 @@ +# NeoPixelBus_wrapper + +**NeoPixelBus_wrapper**: A minimal wrapper to replace Adafruit_NeoPixel API to use Makuna's NeoPixelBus API. + +(c) 2023, Ton Huisman for ESPEasy. + +### How to use + +- Add this library to your `lib` folder +- Add the [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) library to your `lib` folder +- Replace the `#include ` line by `#include ` +- Replace your type `Adafruit_NeoPixel` variable(s) by type `NeoPixelBus_wrapper` variable(s) +- When using runtime instantiation of the wrapper object, replace your `pixels = new Adafruit_NeoPixel(...)` call by `pixels = new NeoPixelBus_wrapper(...)` +- Compile, and presto! + +### Limitations + +- Currently only supports the most commonly used NeoPixel stripes `NEO_GRB` and `NEO_GRBW`, and the default `NEO_KHZ800` method. (That's all what is used in ESPEasy...) + +### Support + +For questions and improvement requests, please use the Github Issues system. + +### Reference + +- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) +- [Adafruit_NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) \ No newline at end of file diff --git a/lib/NeoPixelBus_wrapper/library.properties b/lib/NeoPixelBus_wrapper/library.properties new file mode 100644 index 0000000000..b00f7c338f --- /dev/null +++ b/lib/NeoPixelBus_wrapper/library.properties @@ -0,0 +1,10 @@ +name=NeoPixelBus_wrapper +version=0.1.0 +author=tonhuisman +maintainer=tonhuisman +sentence=Arduino wrapper library for interfacing Adafruit_NeoPixel applications to use Makuna NeoPixelBus +paragraph=Arduino wrapper library for interfacing Adafruit_NeoPixel applications to use Makuna NeoPixelBus +category=Display +url=https://github.com/tonhuisman/NeoPixelBus_wrapper +architectures=* +includes=NeoPixelBus by Makuna diff --git a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp new file mode 100644 index 0000000000..09d2d1739d --- /dev/null +++ b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp @@ -0,0 +1,117 @@ +#ifndef _NEOPIXELBUS_WRAPPER_CPP +#define _NEOPIXELBUS_WRAPPER_CPP +#include "./NeoPixelBus_wrapper.h" + +NeoPixelBus_wrapper::NeoPixelBus_wrapper(uint16_t _maxPixels, + int16_t _gpioPin, + neoPixelType _stripType) + : numLEDs(_maxPixels) { + if (NEO_GRB == (_stripType & NEO_GRB)) { + #ifdef ESP8266 + neopixels_grb = new (std::nothrow) NEOPIXEL_LIB(_maxPixels); + #endif // ifdef ESP8266 + #ifdef ESP32 + neopixels_grb = new (std::nothrow) NEOPIXEL_LIB(_maxPixels, _gpioPin); + #endif // ifdef ESP32 + } + + if (NEO_GRBW == (_stripType & NEO_GRBW)) { + #ifdef ESP8266 + neopixels_grbw = new (std::nothrow) NEOPIXEL_LIB(_maxPixels); + #endif // ifdef ESP8266 + #ifdef ESP32 + neopixels_grbw = new (std::nothrow) NEOPIXEL_LIB(_maxPixels, _gpioPin); + #endif // ifdef ESP32 + } +} + +NeoPixelBus_wrapper::~NeoPixelBus_wrapper() { + delete neopixels_grb; + neopixels_grb = nullptr; + delete neopixels_grbw; + neopixels_grbw = nullptr; +} + +void NeoPixelBus_wrapper::begin() { + if (nullptr != neopixels_grb) { + neopixels_grb->Begin(); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->Begin(); + } +} + +void NeoPixelBus_wrapper::show(void) { + if (nullptr != neopixels_grb) { + neopixels_grb->Show(); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->Show(); + } +} + +void NeoPixelBus_wrapper::setBrightness(uint8_t b) { + if (nullptr != neopixels_grb) { + neopixels_grb->SetBrightness(b); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->SetBrightness(b); + } +} + +void NeoPixelBus_wrapper::setPixelColor(uint16_t pxl, + uint8_t r, + uint8_t g, + uint8_t b) { + if (nullptr != neopixels_grb) { + neopixels_grb->SetPixelColor(pxl, RgbColor(r, g, b)); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->SetPixelColor(pxl, RgbwColor(r, g, b)); + } +} + +void NeoPixelBus_wrapper::setPixelColor(uint16_t pxl, + uint8_t r, + uint8_t g, + uint8_t b, + uint8_t w) { + if (nullptr != neopixels_grb) { + neopixels_grb->SetPixelColor(pxl, RgbColor(r, g, b)); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->SetPixelColor(pxl, RgbwColor(r, g, b, w)); + } +} + +void NeoPixelBus_wrapper::setPixelColor(uint16_t pxl, + uint32_t c) { + if (nullptr != neopixels_grb) { + neopixels_grb->SetPixelColor(pxl, RgbColor((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF)); // Unfold the Color(r,g,b,w) static + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->SetPixelColor(pxl, RgbwColor((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF, (c >> 24) & 0xFF)); + } +} + +uint32_t NeoPixelBus_wrapper::getPixelColor(uint16_t n) { + if (nullptr != neopixels_grb) { + RgbColor color; + color = neopixels_grb->GetPixelColor(n); + return Color(color.R, color.G, color.B); + } + + if (nullptr != neopixels_grbw) { + RgbwColor color; + color = neopixels_grbw->GetPixelColor(n); + return Color(color.R, color.G, color.B, color.W); + } +} + +#endif // ifndef _NEOPIXELBUS_WRAPPER_CPP diff --git a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.h b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.h new file mode 100644 index 0000000000..10f1b88f0e --- /dev/null +++ b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.h @@ -0,0 +1,64 @@ +#ifndef _HELPERS_NEOPIXELBUS_WRAPPER_H +#define _HELPERS_NEOPIXELBUS_WRAPPER_H + +#include +#include // Be sure to keep this header file when upgrading the NeoPixelBus library, + // and remove the deprecation warning if needed +// Some stuff from Adafruit_NeoPixel.h used in plugins +#ifndef NEO_GRB +# define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B +# define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B,W +# define NEO_KHZ800 0x0000 ///< 800 KHz data transmission +typedef uint16_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor +#endif // ifndef NEO_GRB + + +#define NEOPIXEL_LIB NeoPixelBrightnessBus // Neopixel library type +#if defined(ESP32) +# define METHOD NeoWs2812xMethod // Automatic method, user selected pin +#endif // if defined(ESP32) +#if defined(ESP8266) +# define METHOD NeoEsp8266Uart1800KbpsMethod // GPIO2 - use NeoEsp8266Uart0800KbpsMethod for GPIO1(TX) +#endif // if defined(ESP8266) + +struct NeoPixelBus_wrapper { +public: + + NeoPixelBus_wrapper(uint16_t _maxPixels, + int16_t _gpioPin, + neoPixelType _stripType); + virtual ~NeoPixelBus_wrapper(); + void begin(); + void show(void); + void setBrightness(uint8_t); + void setPixelColor(uint16_t pxl, + uint8_t r, + uint8_t g, + uint8_t b); + void setPixelColor(uint16_t pxl, + uint8_t r, + uint8_t g, + uint8_t b, + uint8_t w); + void setPixelColor(uint16_t pxl, + uint32_t c); + uint32_t getPixelColor(uint16_t n); + uint16_t numPixels(void) const { + return numLEDs; + } + + static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { + return static_cast(w) << 24 | + static_cast(r) << 16 | + static_cast(g) << 8 | + static_cast(b); + } + +private: + + NEOPIXEL_LIB *neopixels_grb = nullptr; + NEOPIXEL_LIB *neopixels_grbw = nullptr; + uint16_t numLEDs = 0; +}; + +#endif // ifndef _HELPERS_NEOPIXELBUS_WRAPPER_H diff --git a/src/_P041_NeoClock.ino b/src/_P041_NeoClock.ino index b9d28a0ea6..260ce7d318 100644 --- a/src/_P041_NeoClock.ino +++ b/src/_P041_NeoClock.ino @@ -3,7 +3,7 @@ //####################################################################################################### //#################################### Plugin 041: NeoPixel clock ####################################### //####################################################################################################### -#include +#include #define NUM_LEDS 114 @@ -12,7 +12,7 @@ uint8_t Plugin_041_red = 0; uint8_t Plugin_041_green = 0; uint8_t Plugin_041_blue = 0; -Adafruit_NeoPixel *Plugin_041_pixels; +NeoPixelBus_wrapper *Plugin_041_pixels; #define PLUGIN_041 #define PLUGIN_ID_041 41 @@ -82,7 +82,7 @@ boolean Plugin_041(uint8_t function, struct EventStruct *event, String& string) { if (Plugin_041_pixels == nullptr) { - Plugin_041_pixels = new (std::nothrow) Adafruit_NeoPixel(NUM_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); + Plugin_041_pixels = new (std::nothrow) NeoPixelBus_wrapper(NUM_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); if (Plugin_041_pixels != nullptr) { Plugin_041_pixels->begin(); // This initializes the NeoPixel library. } diff --git a/src/src/PluginStructs/P038_data_struct.cpp b/src/src/PluginStructs/P038_data_struct.cpp index d4a4ffeaf9..352dc23e7a 100644 --- a/src/src/PluginStructs/P038_data_struct.cpp +++ b/src/src/PluginStructs/P038_data_struct.cpp @@ -26,9 +26,9 @@ bool P038_data_struct::plugin_init(struct EventStruct *event) { bool success = false; if (!isInitialized()) { - Plugin_038_pixels = new (std::nothrow) Adafruit_NeoPixel(_maxPixels, - _gpioPin, - (_stripType == P038_STRIP_TYPE_RGBW ? NEO_GRBW : NEO_GRB) + NEO_KHZ800); + Plugin_038_pixels = new (std::nothrow) NeoPixelBus_wrapper(_maxPixels, + _gpioPin, + (_stripType == P038_STRIP_TYPE_RGBW ? NEO_GRBW : NEO_GRB) + NEO_KHZ800); if (Plugin_038_pixels != nullptr) { Plugin_038_pixels->begin(); // This initializes the NeoPixel library. @@ -110,7 +110,7 @@ bool P038_data_struct::plugin_write(struct EventStruct *event, const String& str } } else - if (equals(cmd, F("neopixelline"))) { // NeoPixelLine + if (equals(cmd, F("neopixelline"))) { // NeoPixelLine int brightness = 0; validIntFromString(parseString(string, 7), brightness); // Get 7th argument aka Par6 diff --git a/src/src/PluginStructs/P038_data_struct.h b/src/src/PluginStructs/P038_data_struct.h index 84f07ecb03..24aa5d8093 100644 --- a/src/src/PluginStructs/P038_data_struct.h +++ b/src/src/PluginStructs/P038_data_struct.h @@ -4,7 +4,7 @@ #include "../../_Plugin_Helper.h" #ifdef USES_P038 -# include +# include // # define P038_DEBUG_LOG // Enable for some (extra) logging @@ -39,7 +39,7 @@ struct P038_data_struct : public PluginTaskData_base { private: - Adafruit_NeoPixel *Plugin_038_pixels = nullptr; + NeoPixelBus_wrapper *Plugin_038_pixels = nullptr; void HSV2RGBWorRGBandLog(float H, float S, diff --git a/src/src/PluginStructs/P042_data_struct.cpp b/src/src/PluginStructs/P042_data_struct.cpp index d44f168dd2..f260491b4b 100644 --- a/src/src/PluginStructs/P042_data_struct.cpp +++ b/src/src/PluginStructs/P042_data_struct.cpp @@ -38,7 +38,7 @@ bool P042_data_struct::plugin_init(struct EventStruct *event) { if (Candle_pixels) { delete Candle_pixels; } - Candle_pixels = new (std::nothrow) Adafruit_NeoPixel(P042_CONFIG_PIXELCOUNT, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); + Candle_pixels = new (std::nothrow) NeoPixelBus_wrapper(P042_CONFIG_PIXELCOUNT, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); if (Candle_pixels != nullptr) { SetPixelsBlack(); diff --git a/src/src/PluginStructs/P042_data_struct.h b/src/src/PluginStructs/P042_data_struct.h index 414b5debf0..d89d5884c8 100644 --- a/src/src/PluginStructs/P042_data_struct.h +++ b/src/src/PluginStructs/P042_data_struct.h @@ -5,7 +5,7 @@ #ifdef USES_P042 -# include +#include # define P042_NUM_PIXEL 20 // Defines the default amount of LED Pixels @@ -100,7 +100,7 @@ struct P042_data_struct : public PluginTaskData_base { word Candle_Temp[3] = { 0 }; // Temp variables boolean GPIO_Set = false; - Adafruit_NeoPixel *Candle_pixels; + NeoPixelBus_wrapper *Candle_pixels; }; diff --git a/src/src/PluginStructs/P070_data_struct.cpp b/src/src/PluginStructs/P070_data_struct.cpp index 1bc5c81bf3..090c714982 100644 --- a/src/src/PluginStructs/P070_data_struct.cpp +++ b/src/src/PluginStructs/P070_data_struct.cpp @@ -20,7 +20,7 @@ void P070_data_struct::reset() { void P070_data_struct::init(struct EventStruct *event) { if (!Plugin_070_pixels) { - Plugin_070_pixels = new (std::nothrow) Adafruit_NeoPixel(NUMBER_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); + Plugin_070_pixels = new (std::nothrow) NeoPixelBus_wrapper(NUMBER_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); if (Plugin_070_pixels == nullptr) { return; diff --git a/src/src/PluginStructs/P070_data_struct.h b/src/src/PluginStructs/P070_data_struct.h index 4d3cd34c67..a48f6b9a0f 100644 --- a/src/src/PluginStructs/P070_data_struct.h +++ b/src/src/PluginStructs/P070_data_struct.h @@ -5,7 +5,7 @@ #ifdef USES_P070 -# include +#include # define NUMBER_LEDS 60 // number of LED in the strip @@ -39,7 +39,7 @@ struct P070_data_struct : public PluginTaskData_base { bool thick_12_mark = false; // thicker marking of the 12h position uint8_t marks[14] = { 0 }; // Positions of the hour marks and dials - Adafruit_NeoPixel *Plugin_070_pixels = nullptr; + NeoPixelBus_wrapper *Plugin_070_pixels = nullptr; }; From 17a60bf8237bfb1689826ae3bec2c0249c1e448e Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Thu, 26 Oct 2023 21:51:32 +0200 Subject: [PATCH 02/25] [Lib] Adjust Adafruit_NeoMatrix to use NeoPixelBus_wrapper --- lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp | 4 ++-- lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp index d29cd8ac46..7a1fa1f801 100644 --- a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp +++ b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp @@ -73,7 +73,7 @@ // Constructor for single matrix: Adafruit_NeoMatrix::Adafruit_NeoMatrix(int w, int h, uint8_t pin, uint8_t matrixType, neoPixelType ledType) - : Adafruit_GFX(w, h), Adafruit_NeoPixel(w * h, pin, ledType), + : Adafruit_GFX(w, h), NeoPixelBus_wrapper(w * h, pin, ledType), type(matrixType), matrixWidth(w), matrixHeight(h), tilesX(0), tilesY(0), remapFn(NULL) {} @@ -82,7 +82,7 @@ Adafruit_NeoMatrix::Adafruit_NeoMatrix(uint8_t mW, uint8_t mH, uint8_t tX, uint8_t tY, uint8_t pin, uint8_t matrixType, neoPixelType ledType) : Adafruit_GFX(mW * tX, mH * tY), - Adafruit_NeoPixel(mW * mH * tX * tY, pin, ledType), type(matrixType), + NeoPixelBus_wrapper(mW * mH * tX * tY, pin, ledType), type(matrixType), matrixWidth(mW), matrixHeight(mH), tilesX(tX), tilesY(tY), remapFn(NULL) { } diff --git a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h index fe23b55a62..ba814302c7 100644 --- a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h +++ b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h @@ -40,7 +40,7 @@ #include #endif #include -#include +#include // Matrix layout information is passed in the 'matrixType' parameter for // each constructor (the parameter immediately following is the LED type @@ -79,7 +79,7 @@ /** * @brief Class for using NeoPixel matrices with the GFX graphics library. */ -class Adafruit_NeoMatrix : public Adafruit_GFX, public Adafruit_NeoPixel { +class Adafruit_NeoMatrix : public Adafruit_GFX, public NeoPixelBus_wrapper { public: /** From a648e97311d248cace787de71ed4e3556de1dacf Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Thu, 26 Oct 2023 22:08:25 +0200 Subject: [PATCH 03/25] [ESP-IDF5.1] Update NeoPixelBus with Tasmota's patches for ESP-IDF5.1 --- .../.github/ISSUE_TEMPLATE/all-others.md | 7 +- .../DotStarTest_Esp32DmaSpi.ino | 24 +- .../NeoPixel_ESP32_I2sParallel.ino | 54 -- .../NeoPixelBrightness/NeoPixelBrightness.ino | 83 ++ .../examples/NeoPixelBusLg/NeoPixelBusLg.ino | 108 --- .../NeoPixelGamma/NeoPixelGamma.ino | 6 +- .../examples/NeoPixelTest/NeoPixelTest.ino | 30 +- .../NeoPixelAnimation/NeoPixelAnimation.ino | 2 +- .../NeoPixelCylon/NeoPixelCylon.ino | 4 +- .../NeoPixelFunFadeInOut.ino | 2 +- .../NeoPixelFunLoop/NeoPixelFunLoop.ino | 2 +- .../NeoPixelFunRandomChange.ino | 2 +- .../NeoPixelRotateLoop/NeoPixelRotateLoop.ino | 4 +- .../bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino | 4 +- .../NeoPixelBufferCylon.ino | 4 +- .../NeoPixelBufferShader.ino | 4 +- .../NeoPixelDibTest/NeoPixelDibTest.ino | 2 +- .../NeoPixelGammaDynamic.ino | 103 --- .../NeoPixelMosaicDump/NeoPixelMosaicDump.ino | 11 +- .../NeoPixelMosaicTest/NeoPixelMosaicTest.ino | 4 +- .../NeoPixelRingDynamicTopologyTest.ino | 2 +- .../NeoPixelRingTopologyTest.ino | 2 +- .../NeoPixelTilesDump/NeoPixelTilesDump.ino | 11 +- .../NeoPixelTilesTest/NeoPixelTilesTest.ino | 8 +- .../NeoPixelTopologyDump.ino | 11 +- .../NeoPixelTopologyTest.ino | 8 +- lib/NeoPixelBus/keywords.txt | 161 +--- lib/NeoPixelBus/library.json | 6 +- lib/NeoPixelBus/library.properties | 8 +- lib/NeoPixelBus/src/NeoPixelAnimator.h | 2 +- lib/NeoPixelBus/src/NeoPixelBrightnessBus.h | 18 +- lib/NeoPixelBus/src/NeoPixelBus.h | 130 ++- lib/NeoPixelBus/src/NeoPixelBusLg.h | 197 ----- .../src/internal/DotStarColorFeatures.h | 698 +++++++++++++++ .../src/internal/DotStarEsp32DmaSpiMethod.h | 356 ++++++++ .../{methods => }/DotStarGenericMethod.h | 48 +- lib/NeoPixelBus/src/internal/Esp32_i2s.c | 501 +++++++++++ lib/NeoPixelBus/src/internal/Esp32_i2s.h | 45 + .../src/internal/{colors => }/HsbColor.cpp | 3 - .../src/internal/{colors => }/HsbColor.h | 2 + .../src/internal/{colors => }/HslColor.cpp | 3 - .../src/internal/{colors => }/HslColor.h | 2 + .../src/internal/{colors => }/HtmlColor.cpp | 5 - .../src/internal/{colors => }/HtmlColor.h | 7 + .../{colors => }/HtmlColorNameStrings.cpp | 1 - .../{colors => }/HtmlColorNameStrings.h | 2 + .../internal/{colors => }/HtmlColorNames.cpp | 6 - .../{colors => }/HtmlColorShortNames.cpp | 6 - lib/NeoPixelBus/src/internal/Layouts.h | 426 +++++++++ .../src/internal/Lpd6803ColorFeatures.h | 301 +++++++ .../{methods => }/Lpd6803GenericMethod.h | 10 +- .../src/internal/Lpd8806ColorFeatures.h | 189 ++++ .../{methods => }/Lpd8806GenericMethod.h | 10 +- .../src/internal/{methods => }/NeoArmMethod.h | 11 +- .../src/internal/{methods => }/NeoAvrMethod.h | 125 +-- .../internal/{buffers => }/NeoBitmapFile.h | 5 +- .../src/internal/{buffers => }/NeoBuffer.h | 33 +- .../internal/{buffers => }/NeoBufferContext.h | 2 +- .../internal/{buffers => }/NeoBufferMethods.h | 116 ++- lib/NeoPixelBus/src/internal/NeoBuffers.h | 40 - lib/NeoPixelBus/src/internal/NeoBusChannel.h | 9 +- .../src/internal/NeoColorFeatures.h | 450 ++++++++-- lib/NeoPixelBus/src/internal/NeoColors.h | 55 -- .../src/internal/{buffers => }/NeoDib.h | 64 +- .../src/internal/{animations => }/NeoEase.h | 12 - .../{methods => }/NeoEsp32I2sMethod.h | 48 +- .../{methods => }/NeoEsp32RmtMethod.cpp | 29 +- .../{methods => }/NeoEsp32RmtMethod.h | 111 +-- .../src/internal/NeoEsp32RmtMethod_idf5.cpp | 112 +++ .../src/internal/NeoEsp32RmtMethod_idf5.h | 805 ++++++++++++++++++ .../src/internal/NeoEsp32SpiMethod_idf5.h | 504 +++++++++++ ...MethodCore.cpp => NeoEsp8266DmaMethod.cpp} | 7 +- .../src/internal/NeoEsp8266DmaMethod.h | 612 +++++++++++++ .../{methods => }/NeoEsp8266UartMethod.cpp | 8 +- .../{methods => }/NeoEsp8266UartMethod.h | 30 +- .../{methods => }/NeoEspBitBangMethod.cpp | 125 +-- .../src/internal/NeoEspBitBangMethod.h | 381 +++++++++ .../NeoGammaTableMethod.cpp => NeoGamma.cpp} | 37 +- .../NeoGammaEquationMethod.h => NeoGamma.h} | 38 +- .../src/internal/{colors => }/NeoHueBlend.h | 0 lib/NeoPixelBus/src/internal/NeoMethods.h | 71 -- .../src/internal/{topologies => }/NeoMosaic.h | 18 +- .../internal/{methods => }/NeoNrf52xMethod.h | 22 +- .../{animations => }/NeoPixelAnimator.cpp | 1 - .../src/internal/{methods => }/NeoPixelAvr.c | 149 +--- .../{topologies => }/NeoRingTopology.h | 22 +- .../src/internal/NeoSegmentFeatures.h | 216 +++++ lib/NeoPixelBus/src/internal/NeoSettings.h | 92 +- ...VerticalSpriteSheet.h => NeoSpriteSheet.h} | 7 +- .../src/internal/{topologies => }/NeoTiles.h | 16 +- ...814Features.h => NeoTm1814ColorFeatures.h} | 70 +- ...914Features.h => NeoTm1914ColorFeatures.h} | 91 +- lib/NeoPixelBus/src/internal/NeoTopologies.h | 39 - .../internal/{topologies => }/NeoTopology.h | 15 +- lib/NeoPixelBus/src/internal/NeoUtil.h | 94 -- .../src/internal/P9813ColorFeatures.h | 162 ++++ .../{methods => }/P9813GenericMethod.h | 10 +- .../src/internal/{colors => }/Rgb16Color.h | 46 +- .../src/internal/{colors => }/Rgb48Color.cpp | 34 +- .../src/internal/{colors => }/Rgb48Color.h | 130 +-- .../src/internal/{colors => }/RgbColor.cpp | 17 +- .../src/internal/{colors => }/RgbColor.h | 73 +- .../internal/{colors => }/RgbColorBase.cpp | 2 - .../NeoShaderBase.h => RgbColorBase.h} | 35 +- .../src/internal/{colors => }/RgbwColor.cpp | 18 +- .../src/internal/{colors => }/RgbwColor.h | 91 +- .../internal/{colors => }/SegmentDigit.cpp | 50 +- .../src/internal/{colors => }/SegmentDigit.h | 74 +- .../{methods => }/TwoWireBitBangImple.h | 15 +- .../{methods => }/TwoWireBitBangImpleAvr.h | 25 +- .../internal/{methods => }/TwoWireHspiImple.h | 4 +- .../internal/{methods => }/TwoWireSpiImple.h | 42 +- .../{methods => }/Ws2801GenericMethod.h | 28 +- .../src/internal/buffers/LayoutMapCallback.h | 41 - .../internal/buffers/NeoBufferProgmemMethod.h | 126 --- .../src/internal/buffers/NeoShaderNop.h | 53 -- .../src/internal/colors/NeoGamma.h | 81 -- .../colors/NeoGammaCieLabEquationMethod.h | 41 - .../colors/NeoGammaDynamicTableMethod.cpp | 34 - .../colors/NeoGammaDynamicTableMethod.h | 226 ----- .../internal/colors/NeoGammaInvertMethod.h | 48 -- .../src/internal/colors/NeoGammaNullMethod.h | 42 - .../src/internal/colors/NeoGammaTableMethod.h | 113 --- .../src/internal/colors/RgbColorBase.h | 69 -- .../src/internal/colors/RgbColorIndexes.h | 35 - .../src/internal/colors/Rgbw64Color.cpp | 190 ----- .../src/internal/colors/Rgbw64Color.h | 348 -------- .../src/internal/colors/RgbwwColor.cpp | 229 ----- .../src/internal/colors/RgbwwColor.h | 325 ------- .../internal/features/DotStarL4ByteFeature.h | 70 -- .../internal/features/DotStarLrgbFeatures.h | 65 -- .../internal/features/DotStarRgbFeatures.h | 65 -- .../internal/features/DotStarX4ByteFeature.h | 70 -- .../internal/features/Lpd6803RgbFeatures.h | 52 -- .../internal/features/Lpd8806RgbFeatures.h | 39 - .../internal/features/Neo2Byte555Feature.h | 89 -- .../internal/features/Neo3Byte777Feature.h | 67 -- .../src/internal/features/Neo3ByteFeature.h | 67 -- .../src/internal/features/Neo3WordFeature.h | 77 -- .../src/internal/features/Neo4ByteFeature.h | 69 -- .../src/internal/features/Neo4WordFeature.h | 82 -- .../src/internal/features/Neo6xByteFeature.h | 76 -- .../src/internal/features/Neo6xxByteFeature.h | 73 -- .../features/NeoAbcdefgpsSegmentFeature.h | 72 -- .../features/NeoBacedfpgsSegmentFeature.h | 93 -- .../src/internal/features/NeoByteElements.h | 139 --- .../internal/features/NeoElementsNoSettings.h | 49 -- .../src/internal/features/NeoRgb48Features.h | 63 -- .../src/internal/features/NeoRgbFeatures.h | 64 -- .../src/internal/features/NeoRgbcwxFeatures.h | 33 - .../src/internal/features/NeoRgbw64Features.h | 66 -- .../src/internal/features/NeoRgbwFeatures.h | 63 -- .../src/internal/features/NeoRgbwxxFeatures.h | 33 - .../internal/features/NeoSm168xxFeatures.h | 305 ------- .../src/internal/features/P9813BgrFeature.h | 77 -- .../methods/DotStarEsp32DmaSpiMethod.h | 334 -------- .../src/internal/methods/Esp32_i2s.c | 671 --------------- .../src/internal/methods/Esp32_i2s.h | 49 -- .../internal/methods/Mbi6033GenericMethod.h | 208 ----- .../src/internal/methods/NeoEsp32I2sXMethod.h | 763 ----------------- .../internal/methods/NeoEsp8266DmaMethod.h | 437 ---------- .../methods/NeoEsp8266I2sDmx512Method.h | 354 -------- .../methods/NeoEsp8266I2sMethodCore.h | 362 -------- .../internal/methods/NeoEspBitBangMethod.h | 366 -------- .../internal/methods/Sm16716GenericMethod.h | 140 --- .../internal/methods/Tlc5947GenericMethod.h | 222 ----- .../topologies/ColumnMajorAlternatingLayout.h | 144 ---- .../internal/topologies/ColumnMajorLayout.h | 104 --- .../topologies/RowMajorAlternatingLayout.h | 144 ---- .../src/internal/topologies/RowMajorLayout.h | 103 --- 170 files changed, 6626 insertions(+), 10987 deletions(-) delete mode 100644 lib/NeoPixelBus/examples/ESP32/NeoPixel_ESP32_I2sParallel/NeoPixel_ESP32_I2sParallel.ino create mode 100644 lib/NeoPixelBus/examples/NeoPixelBrightness/NeoPixelBrightness.ino delete mode 100644 lib/NeoPixelBus/examples/NeoPixelBusLg/NeoPixelBusLg.ino rename lib/NeoPixelBus/examples/{gamma => }/NeoPixelGamma/NeoPixelGamma.ino (93%) delete mode 100644 lib/NeoPixelBus/examples/gamma/NeoPixelGammaDynamic/NeoPixelGammaDynamic.ino delete mode 100644 lib/NeoPixelBus/src/NeoPixelBusLg.h create mode 100644 lib/NeoPixelBus/src/internal/DotStarColorFeatures.h create mode 100644 lib/NeoPixelBus/src/internal/DotStarEsp32DmaSpiMethod.h rename lib/NeoPixelBus/src/internal/{methods => }/DotStarGenericMethod.h (87%) create mode 100644 lib/NeoPixelBus/src/internal/Esp32_i2s.c create mode 100644 lib/NeoPixelBus/src/internal/Esp32_i2s.h rename lib/NeoPixelBus/src/internal/{colors => }/HsbColor.cpp (96%) rename lib/NeoPixelBus/src/internal/{colors => }/HsbColor.h (99%) rename lib/NeoPixelBus/src/internal/{colors => }/HslColor.cpp (96%) rename lib/NeoPixelBus/src/internal/{colors => }/HslColor.h (99%) rename lib/NeoPixelBus/src/internal/{colors => }/HtmlColor.cpp (94%) rename lib/NeoPixelBus/src/internal/{colors => }/HtmlColor.h (99%) rename lib/NeoPixelBus/src/internal/{colors => }/HtmlColorNameStrings.cpp (99%) rename lib/NeoPixelBus/src/internal/{colors => }/HtmlColorNameStrings.h (99%) rename lib/NeoPixelBus/src/internal/{colors => }/HtmlColorNames.cpp (98%) rename lib/NeoPixelBus/src/internal/{colors => }/HtmlColorShortNames.cpp (94%) create mode 100644 lib/NeoPixelBus/src/internal/Layouts.h create mode 100644 lib/NeoPixelBus/src/internal/Lpd6803ColorFeatures.h rename lib/NeoPixelBus/src/internal/{methods => }/Lpd6803GenericMethod.h (94%) create mode 100644 lib/NeoPixelBus/src/internal/Lpd8806ColorFeatures.h rename lib/NeoPixelBus/src/internal/{methods => }/Lpd8806GenericMethod.h (94%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoArmMethod.h (99%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoAvrMethod.h (63%) rename lib/NeoPixelBus/src/internal/{buffers => }/NeoBitmapFile.h (98%) rename lib/NeoPixelBus/src/internal/{buffers => }/NeoBuffer.h (87%) rename lib/NeoPixelBus/src/internal/{buffers => }/NeoBufferContext.h (98%) rename lib/NeoPixelBus/src/internal/{buffers => }/NeoBufferMethods.h (60%) delete mode 100644 lib/NeoPixelBus/src/internal/NeoBuffers.h delete mode 100644 lib/NeoPixelBus/src/internal/NeoColors.h rename lib/NeoPixelBus/src/internal/{buffers => }/NeoDib.h (85%) rename lib/NeoPixelBus/src/internal/{animations => }/NeoEase.h (96%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoEsp32I2sMethod.h (93%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoEsp32RmtMethod.cpp (93%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoEsp32RmtMethod.h (87%) create mode 100644 lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp create mode 100644 lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h create mode 100644 lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h rename lib/NeoPixelBus/src/internal/{methods/NeoEsp8266I2sMethodCore.cpp => NeoEsp8266DmaMethod.cpp} (89%) create mode 100644 lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.h rename lib/NeoPixelBus/src/internal/{methods => }/NeoEsp8266UartMethod.cpp (95%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoEsp8266UartMethod.h (95%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoEspBitBangMethod.cpp (55%) create mode 100644 lib/NeoPixelBus/src/internal/NeoEspBitBangMethod.h rename lib/NeoPixelBus/src/internal/{colors/NeoGammaTableMethod.cpp => NeoGamma.cpp} (63%) rename lib/NeoPixelBus/src/internal/{colors/NeoGammaEquationMethod.h => NeoGamma.h} (60%) rename lib/NeoPixelBus/src/internal/{colors => }/NeoHueBlend.h (100%) delete mode 100644 lib/NeoPixelBus/src/internal/NeoMethods.h rename lib/NeoPixelBus/src/internal/{topologies => }/NeoMosaic.h (91%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoNrf52xMethod.h (95%) rename lib/NeoPixelBus/src/internal/{animations => }/NeoPixelAnimator.cpp (99%) rename lib/NeoPixelBus/src/internal/{methods => }/NeoPixelAvr.c (81%) rename lib/NeoPixelBus/src/internal/{topologies => }/NeoRingTopology.h (84%) create mode 100644 lib/NeoPixelBus/src/internal/NeoSegmentFeatures.h rename lib/NeoPixelBus/src/internal/{buffers/NeoVerticalSpriteSheet.h => NeoSpriteSheet.h} (97%) rename lib/NeoPixelBus/src/internal/{topologies => }/NeoTiles.h (91%) rename lib/NeoPixelBus/src/internal/{features/NeoTm1814Features.h => NeoTm1814ColorFeatures.h} (54%) rename lib/NeoPixelBus/src/internal/{features/NeoTm1914Features.h => NeoTm1914ColorFeatures.h} (53%) delete mode 100644 lib/NeoPixelBus/src/internal/NeoTopologies.h rename lib/NeoPixelBus/src/internal/{topologies => }/NeoTopology.h (88%) delete mode 100644 lib/NeoPixelBus/src/internal/NeoUtil.h create mode 100644 lib/NeoPixelBus/src/internal/P9813ColorFeatures.h rename lib/NeoPixelBus/src/internal/{methods => }/P9813GenericMethod.h (94%) rename lib/NeoPixelBus/src/internal/{colors => }/Rgb16Color.h (87%) rename lib/NeoPixelBus/src/internal/{colors => }/Rgb48Color.cpp (80%) rename lib/NeoPixelBus/src/internal/{colors => }/Rgb48Color.h (64%) rename lib/NeoPixelBus/src/internal/{colors => }/RgbColor.cpp (84%) rename lib/NeoPixelBus/src/internal/{colors => }/RgbColor.h (76%) rename lib/NeoPixelBus/src/internal/{colors => }/RgbColorBase.cpp (98%) rename lib/NeoPixelBus/src/internal/{buffers/NeoShaderBase.h => RgbColorBase.h} (75%) rename lib/NeoPixelBus/src/internal/{colors => }/RgbwColor.cpp (81%) rename lib/NeoPixelBus/src/internal/{colors => }/RgbwColor.h (74%) rename lib/NeoPixelBus/src/internal/{colors => }/SegmentDigit.cpp (75%) rename lib/NeoPixelBus/src/internal/{colors => }/SegmentDigit.h (76%) rename lib/NeoPixelBus/src/internal/{methods => }/TwoWireBitBangImple.h (87%) rename lib/NeoPixelBus/src/internal/{methods => }/TwoWireBitBangImpleAvr.h (84%) rename lib/NeoPixelBus/src/internal/{methods => }/TwoWireHspiImple.h (96%) rename lib/NeoPixelBus/src/internal/{methods => }/TwoWireSpiImple.h (78%) rename lib/NeoPixelBus/src/internal/{methods => }/Ws2801GenericMethod.h (79%) delete mode 100644 lib/NeoPixelBus/src/internal/buffers/LayoutMapCallback.h delete mode 100644 lib/NeoPixelBus/src/internal/buffers/NeoBufferProgmemMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/buffers/NeoShaderNop.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/NeoGamma.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/NeoGammaCieLabEquationMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.cpp delete mode 100644 lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/NeoGammaInvertMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/NeoGammaNullMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/RgbColorBase.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/RgbColorIndexes.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/Rgbw64Color.cpp delete mode 100644 lib/NeoPixelBus/src/internal/colors/Rgbw64Color.h delete mode 100644 lib/NeoPixelBus/src/internal/colors/RgbwwColor.cpp delete mode 100644 lib/NeoPixelBus/src/internal/colors/RgbwwColor.h delete mode 100644 lib/NeoPixelBus/src/internal/features/DotStarL4ByteFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/DotStarLrgbFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/DotStarRgbFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/DotStarX4ByteFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Lpd6803RgbFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Lpd8806RgbFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Neo2Byte555Feature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Neo3Byte777Feature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Neo3ByteFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Neo3WordFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Neo4ByteFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Neo4WordFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Neo6xByteFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/Neo6xxByteFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoAbcdefgpsSegmentFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoBacedfpgsSegmentFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoByteElements.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoElementsNoSettings.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoRgb48Features.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoRgbFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoRgbcwxFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoRgbw64Features.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoRgbwFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoRgbwxxFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/NeoSm168xxFeatures.h delete mode 100644 lib/NeoPixelBus/src/internal/features/P9813BgrFeature.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/DotStarEsp32DmaSpiMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/Esp32_i2s.c delete mode 100644 lib/NeoPixelBus/src/internal/methods/Esp32_i2s.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/Mbi6033GenericMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/NeoEsp8266DmaMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sDmx512Method.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/NeoEspBitBangMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/Sm16716GenericMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/methods/Tlc5947GenericMethod.h delete mode 100644 lib/NeoPixelBus/src/internal/topologies/ColumnMajorAlternatingLayout.h delete mode 100644 lib/NeoPixelBus/src/internal/topologies/ColumnMajorLayout.h delete mode 100644 lib/NeoPixelBus/src/internal/topologies/RowMajorAlternatingLayout.h delete mode 100644 lib/NeoPixelBus/src/internal/topologies/RowMajorLayout.h diff --git a/lib/NeoPixelBus/.github/ISSUE_TEMPLATE/all-others.md b/lib/NeoPixelBus/.github/ISSUE_TEMPLATE/all-others.md index 0c394e63b8..1e4e000b9f 100644 --- a/lib/NeoPixelBus/.github/ISSUE_TEMPLATE/all-others.md +++ b/lib/NeoPixelBus/.github/ISSUE_TEMPLATE/all-others.md @@ -8,8 +8,7 @@ assignees: '' --- ### STOP -If you are seeking support, then please use the Discussions feature or gitter channel by following one of these links. -[NeoPixelBus Discussions](https://github.com/Makuna/NeoPixelBus/discussions) -[NeoPixelBus Gitter Channel](https://gitter.im/Makuna/NeoPixelBus) +If you are seeking support, then please use the gitter channel by following this link. +[NeoPixelBus Gitter Channel](https://gitter.im/Makuna/NeoPixelBus) -If you submit issues that are not traceable bugs or feature requests, it will just get closed. +If you submit issues that are not traceable bugs or feature requests, it will get closed and you will be directed to the gitter channel. diff --git a/lib/NeoPixelBus/examples/ESP32/DotStarTest_Esp32DmaSpi/DotStarTest_Esp32DmaSpi.ino b/lib/NeoPixelBus/examples/ESP32/DotStarTest_Esp32DmaSpi/DotStarTest_Esp32DmaSpi.ino index 41ffdbac9f..9805ac451f 100644 --- a/lib/NeoPixelBus/examples/ESP32/DotStarTest_Esp32DmaSpi/DotStarTest_Esp32DmaSpi.ino +++ b/lib/NeoPixelBus/examples/ESP32/DotStarTest_Esp32DmaSpi/DotStarTest_Esp32DmaSpi.ino @@ -6,28 +6,10 @@ // There is serial output of the current state so you can confirm and follow along // -// -// ESP32 SPI Buses and up to how many bits they support: -// ESP32: Spi1 (4 bit) | Spi2 (4 bit) | Spi3 (4 bit) -// ESP32-S2: | Spi2 (8 bit) | Spi3 -// ESP32-S3: | Spi2 (8 bit) | Spi3 (4 bit) -// ESP32-C3: | Spi2 (4 bit) | -// -// If a DotStarEsp32DmaSpi method is used without specifying the bus number -// then Spi2 will be used by default -// -// In this demo if an alternate SPI bus is chosen then Spi3 will be used - #include #define USE_DEFAULT_SPI_PORT 1 - -// C3 only has a single Spi bus -#if CONFIG_IDF_TARGET_ESP32C3 -#define USE_ALTERNATE_SPI_PORT 0 -#else #define USE_ALTERNATE_SPI_PORT 1 -#endif #if (USE_DEFAULT_SPI_PORT == 1) const uint16_t PixelCount = 4; // this example assumes 4 pixels, making it smaller will cause a failure @@ -44,7 +26,7 @@ //NeoPixelBus strip(PixelCount, DotClockPin, DotDataPin); // for hardware SPI (best performance) with default SPI peripheral - NeoPixelBus strip(PixelCount); + NeoPixelBus strip(PixelCount); // DotStarEsp32DmaVspiMethod defaults to 10MHz clock speed. For other speeds, replace "DotStarSpiMethod" with another method specifying speed, e.g. "DotStarSpi2MhzMethod" (see wiki for more details) // See DotStarTest_Esp32Advanced example for how to set clock speed at runtime @@ -62,14 +44,14 @@ const int8_t DotChipSelectPin2 = -1; // -1 means the chip select signal won't be output, freeing up one pin compared to useSpiAlternatePins2=false // for hardware SPI (best performance) with alternate SPI peripheral - NeoPixelBus strip2(PixelCount2); + NeoPixelBus strip2(PixelCount2); // DotStarEsp32DmaHspiMethod defaults to 10MHz clock speed. For other speeds, replace "DotStarSpiMethod" with another method specifying speed, e.g. "DotStarHspi2MhzMethod" (see wiki for more details) #endif #define colorSaturation 128 -// Note that both DotStarEsp32DmaSpiMethod and DotStarEsp32DmaSpi1Method can be used with DotStarLbgrFeature and DotStarWbgrFeature but to keep things simple those are excluded from this example, see DotStarTest for more details +// Note that both DotStarEsp32DmaVspiMethod and DotStarEsp32DmaHspiMethod can be used with DotStarLbgrFeature and DotStarWbgrFeature but to keep things simple those are excluded from this example, see DotStarTest for more details RgbColor red(colorSaturation, 0, 0); RgbColor green(0, colorSaturation, 0); diff --git a/lib/NeoPixelBus/examples/ESP32/NeoPixel_ESP32_I2sParallel/NeoPixel_ESP32_I2sParallel.ino b/lib/NeoPixelBus/examples/ESP32/NeoPixel_ESP32_I2sParallel/NeoPixel_ESP32_I2sParallel.ino deleted file mode 100644 index 72d558232a..0000000000 --- a/lib/NeoPixelBus/examples/ESP32/NeoPixel_ESP32_I2sParallel/NeoPixel_ESP32_I2sParallel.ino +++ /dev/null @@ -1,54 +0,0 @@ -// -// NeoPixel_ESP32_I2sParallel - -// This sketch demonstrates the use of the I2S Parallel method allowing upto 8 hardware updated channels -// This example only works on the ESP32 -// -// The key part of the method name is Esp32I2s1X8, -// E2p32 (platform specific method), -// I2s Channel 1 (most commonly available), -// X8 (8 parallel channel mode) -// -// In this example, it demonstrates different ColorFeatures, Method specification, and count per strip -// -#include - -// Demonstrating the use of the first four channels, but the method used allows for eight -NeoPixelBus strip1(120, 15); // note: older WS2811 and longer strip -NeoPixelBus strip2(100, 2); // note: modern WS2812 with letter like WS2812b -NeoPixelBus strip3(100, 4); // note: inverted -NeoPixelBus strip4(50, 16); // note: RGBW and Sk6812 and smaller strip - -void setup() { - Serial.begin(115200); - while (!Serial); // wait for serial attach - - Serial.println(); - Serial.println("Initializing..."); - Serial.flush(); - - // must call begin on all the strips - strip1.Begin(); - strip2.Begin(); - strip3.Begin(); - strip4.Begin(); - - Serial.println(); - Serial.println("Running..."); -} - -void loop() { - delay(1000); - - // draw on the strips - strip1.SetPixelColor(0, RgbColor(255, 0, 0)); // red - strip2.SetPixelColor(0, RgbColor(0, 127, 0)); // green - strip3.SetPixelColor(0, RgbColor(0, 0, 53)); // blue - strip4.SetPixelColor(0, RgbwColor(0, 0, 128, 255)); // white channel with a little blue - - // show them, - // only on the last show, no matter the order, will the data be sent - strip1.Show(); - strip2.Show(); - strip3.Show(); - strip4.Show(); -} \ No newline at end of file diff --git a/lib/NeoPixelBus/examples/NeoPixelBrightness/NeoPixelBrightness.ino b/lib/NeoPixelBus/examples/NeoPixelBrightness/NeoPixelBrightness.ino new file mode 100644 index 0000000000..01af6cb3a4 --- /dev/null +++ b/lib/NeoPixelBus/examples/NeoPixelBrightness/NeoPixelBrightness.ino @@ -0,0 +1,83 @@ +// NeoPixelBrightness +// This example will cycle brightness from high to low of +// three pixels colored Red, Green, Blue. +// This demonstrates the use of the NeoPixelBrightnessBus +// with integrated brightness support +// +// There is serial output of the current state so you can +// confirm and follow along +// + +#include // instead of NeoPixelBus.h + +const uint16_t PixelCount = 3; // this example assumes 3 pixels, making it smaller will cause a failure +const uint8_t PixelPin = 14; // make sure to set this to the correct pin, ignored for Esp8266 + +#define colorSaturation 255 // saturation of color constants +RgbColor red(colorSaturation, 0, 0); +RgbColor green(0, colorSaturation, 0); +RgbColor blue(0, 0, colorSaturation); + +// Make sure to provide the correct color order feature +// for your NeoPixels +NeoPixelBrightnessBus strip(PixelCount, PixelPin); + +// you loose the original color the lower the dim value used +// here due to quantization +const uint8_t c_MinBrightness = 8; +const uint8_t c_MaxBrightness = 255; + +int8_t direction; // current direction of dimming + +void setup() +{ + Serial.begin(115200); + while (!Serial); // wait for serial attach + + Serial.println(); + Serial.println("Initializing..."); + Serial.flush(); + + // this resets all the neopixels to an off state + strip.Begin(); + strip.Show(); + + direction = -1; // default to dim first + + Serial.println(); + Serial.println("Running..."); + + // set our three original colors + strip.SetPixelColor(0, red); + strip.SetPixelColor(1, green); + strip.SetPixelColor(2, blue); + + strip.Show(); +} + + +void loop() +{ + uint8_t brightness = strip.GetBrightness(); + Serial.println(brightness); + + delay(100); + + // swap diection of dim when limits are reached + // + if (direction < 0 && brightness <= c_MinBrightness) + { + direction = 1; + } + else if (direction > 0 && brightness >= c_MaxBrightness) + { + direction = -1; + } + // apply dimming + brightness += direction; + strip.SetBrightness(brightness); + + // show the results + strip.Show(); +} + diff --git a/lib/NeoPixelBus/examples/NeoPixelBusLg/NeoPixelBusLg.ino b/lib/NeoPixelBus/examples/NeoPixelBusLg/NeoPixelBusLg.ino deleted file mode 100644 index 55240cfbf2..0000000000 --- a/lib/NeoPixelBus/examples/NeoPixelBusLg/NeoPixelBusLg.ino +++ /dev/null @@ -1,108 +0,0 @@ -// NeoPixelBusLg -// -// This example demonstrates the use of the NeoPixelBusLg -// with integrated luminance and gamma support -// -// There is serial output of the current state so you can -// confirm and follow along -// - -#include // instead of NeoPixelBus.h - -const uint16_t PixelCount = 96; // set to the number of pixels in your strip -const uint8_t PixelPin = 14; // make sure to set this to the correct pin, ignored for Esp8266 - -RgbColor red(255, 0, 0); -RgbColor green(0, 255, 0); -RgbColor blue(0, 0, 255); -RgbColor black(0, 0, 0); -RgbColor white(255, 255, 255); - -// Make sure to provide the correct color order feature -// for your NeoPixels -NeoPixelBusLg strip(PixelCount, PixelPin); - -// If speed is an issue and memory is not, then you can use the gamma table variant -// which is much faster but uses 256 bytes of RAM -// NeoPixelBusLg strip(PixelCount, PixelPin); - -// If you want to turn gamma correction off, then you can use the null gamma method -// NeoPixelBusLg strip(PixelCount, PixelPin); - -// If you use a LED driver between the NeoPixel chip and the LEDs that require the PWM range inverted -// NeoPixelBusLg> strip(PixelCount, PixelPin); - -void setup() -{ - Serial.begin(115200); - while (!Serial); // wait for serial attach - - Serial.println(); - Serial.println("Initializing..."); - Serial.flush(); - - // this resets all the neopixels to an off state - strip.Begin(); - strip.SetLuminance(128); // (0-255) - initially at half brightness - strip.Show(); - - Serial.println(); - Serial.println("Running..."); -} - -void loop() -{ - static const uint8_t c_MinBrightness = 0; - static const uint8_t c_MaxBrightness = 255; - - static int8_t direction = -1; // start with dimming - - uint8_t luminance = strip.GetLuminance(); - - Serial.print(direction); - Serial.print(" "); - Serial.println(luminance); - - delay(200); - - // swap direction of luminance when limits are reached - // - if (direction < 0 && luminance <= c_MinBrightness) - { - direction = 1; - } - else if (direction > 0 && luminance >= c_MaxBrightness) - { - direction = -1; - } - else - { - luminance += direction; - } - - strip.SetLuminance(luminance); - - // draw something - // - uint16_t half = strip.PixelCount() / 2; - DrawGradient(green, black, 0, half - 1); - DrawGradient(black, red, half, strip.PixelCount() - 1); - - // show the results - strip.Show(); -} - -void DrawGradient(RgbColor startColor, - RgbColor finishColor, - uint16_t startIndex, - uint16_t finishIndex) -{ - uint16_t delta = finishIndex - startIndex; - - for (uint16_t index = startIndex; index < finishIndex; index++) - { - float progress = static_cast(index - startIndex) / delta; - RgbColor color = RgbColor::LinearBlend(startColor, finishColor, progress); - strip.SetPixelColor(index, color); - } -} \ No newline at end of file diff --git a/lib/NeoPixelBus/examples/gamma/NeoPixelGamma/NeoPixelGamma.ino b/lib/NeoPixelBus/examples/NeoPixelGamma/NeoPixelGamma.ino similarity index 93% rename from lib/NeoPixelBus/examples/gamma/NeoPixelGamma/NeoPixelGamma.ino rename to lib/NeoPixelBus/examples/NeoPixelGamma/NeoPixelGamma.ino index 4c859c92d5..3ed91524ef 100644 --- a/lib/NeoPixelBus/examples/gamma/NeoPixelGamma/NeoPixelGamma.ino +++ b/lib/NeoPixelBus/examples/NeoPixelGamma/NeoPixelGamma.ino @@ -1,5 +1,5 @@ // NeoPixelGamma -// This example will display a timed series of color gradients with gamma correction +// This example will display a timed series of color gradiants with gamma correction // and then without. // If the last pixel is on, then the colors being shown are color corrected. // It will show Red grandiant, Green grandiant, Blue grandiant, a White grandiant, and @@ -15,9 +15,9 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); // uncomment only one of these to compare memory use or speed // diff --git a/lib/NeoPixelBus/examples/NeoPixelTest/NeoPixelTest.ino b/lib/NeoPixelBus/examples/NeoPixelTest/NeoPixelTest.ino index dd63558f30..415c8538ce 100644 --- a/lib/NeoPixelBus/examples/NeoPixelTest/NeoPixelTest.ino +++ b/lib/NeoPixelBus/examples/NeoPixelTest/NeoPixelTest.ino @@ -8,7 +8,7 @@ // NOTE: You will need to make sure to pick the one for your platform // // -// There is serial output of the current state so you can confirm and follow along. +// There is serial output of the current state so you can confirm and follow along // #include @@ -19,35 +19,35 @@ const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignore #define colorSaturation 128 // three element pixels, in different order and speeds -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); //NeoPixelBus 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. -// For details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods. +// 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. +// each having their own restrictions // -// These two are the same as above as the DMA method is the default. -// NOTE: These will ignore the PIN and use GPI03 pin. -//NeoPixelBus strip(PixelCount, PixelPin); +// These two are the same as above as the DMA method is the default +// NOTE: These will ignore the PIN and use GPI03 pin +//NeoPixelBus strip(PixelCount, PixelPin); //NeoPixelBus 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 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 strip(PixelCount, PixelPin); //NeoPixelBus 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. -//NeoPixelBus 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 +//NeoPixelBus strip(PixelCount, PixelPin); //NeoPixelBus strip(PixelCount, PixelPin); // four element pixels, RGBW -//NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); RgbColor red(colorSaturation, 0, 0); RgbColor green(0, colorSaturation, 0); diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino b/lib/NeoPixelBus/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino index 04c24b2be7..fc3a372f90 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino @@ -25,7 +25,7 @@ const uint16_t PixelCount = 4; // make sure to set this to the number of pixels in your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus 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. diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelCylon/NeoPixelCylon.ino b/lib/NeoPixelBus/examples/animations/NeoPixelCylon/NeoPixelCylon.ino index 15b36d0b8e..4eec443d47 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelCylon/NeoPixelCylon.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelCylon/NeoPixelCylon.ino @@ -14,9 +14,9 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 const RgbColor CylonEyeColor(HtmlColor(0x7f0000)); -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); NeoPixelAnimator animations(2); // only ever need 2 animations diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino b/lib/NeoPixelBus/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino index ac18de5f0b..f6c065c2cf 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino @@ -12,7 +12,7 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 const uint8_t AnimationChannels = 1; // we only need one as all the pixels are animated at once -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus 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. diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino b/lib/NeoPixelBus/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino index 30a0e20272..c8a7788ded 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino @@ -25,7 +25,7 @@ const uint16_t NextPixelMoveDuration = 1000 / PixelCount; // how fast we move th NeoGamma colorGamma; // for any fade animations, best to correct gamma -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus 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. diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino b/lib/NeoPixelBus/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino index 89e8347a78..8e88667758 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino @@ -10,7 +10,7 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus 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. diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino b/lib/NeoPixelBus/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino index b796091c02..bdc9af70c9 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino @@ -18,9 +18,9 @@ const float MaxLightness = 0.4f; // max lightness at the head of the tail (0.5f NeoGamma colorGamma; // for any fade animations, best to correct gamma -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object diff --git a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino index 34111e83d8..56071b2b15 100644 --- a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino +++ b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino @@ -23,9 +23,9 @@ const uint16_t PixelCount = 144; // the sample images are meant for 144 pixels const uint16_t PixelPin = 2; const uint16_t AnimCount = 1; // we only need one -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object // our NeoBitmapFile will use the same color feature as NeoPixelBus and diff --git a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino index 1ba86644d6..34b97f2a65 100644 --- a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino +++ b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino @@ -22,9 +22,9 @@ const uint16_t PixelCount = 16; // the sample images are meant for 16 pixels const uint16_t PixelPin = 2; const uint16_t AnimCount = 1; // we only need one -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object // sprite sheet stored in progmem using the same pixel feature as the NeoPixelBus diff --git a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino index a435167f2d..c2c8e74b24 100644 --- a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino +++ b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino @@ -9,7 +9,7 @@ const uint16_t PixelCount = 64; // set this to the size of your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 // three element GRB pixels, change to your needs -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // the buffer object, // defined to use memory with the same feature as the strip @@ -47,7 +47,7 @@ public: // required for a shader object, it will be called for // every pixel - void Apply(uint16_t index, uint8_t* pDest, const uint8_t* pSrc) + void Apply(uint16_t index, uint8_t* pDest, uint8_t* pSrc) { // we don't care what the index is so we ignore it // diff --git a/lib/NeoPixelBus/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino b/lib/NeoPixelBus/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino index 4988aecd73..1a13c135c1 100644 --- a/lib/NeoPixelBus/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino +++ b/lib/NeoPixelBus/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino @@ -9,7 +9,7 @@ const uint16_t PixelCount = 64; // set this to the size of your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 // three element GRB pixels, change to your needs -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // the DIB object, using RgbColor and initialized with the same number of pixels as our strip NeoDib image(PixelCount); diff --git a/lib/NeoPixelBus/examples/gamma/NeoPixelGammaDynamic/NeoPixelGammaDynamic.ino b/lib/NeoPixelBus/examples/gamma/NeoPixelGammaDynamic/NeoPixelGammaDynamic.ino deleted file mode 100644 index 977d6780eb..0000000000 --- a/lib/NeoPixelBus/examples/gamma/NeoPixelGammaDynamic/NeoPixelGammaDynamic.ino +++ /dev/null @@ -1,103 +0,0 @@ -// NeoPixelGammaDynamic -// This example will display a timed series of color gradients with gamma correction -// and then without. -// If the last pixel is on, then the colors being shown are color corrected. -// It will show Red grandiant, Green grandiant, Blue grandiant, a White grandiant, and -// then repeat. -// -// This will demonstrate the use of the NeoGamma class with the -// NeoGammaDynamicTableMethod being used for a custom gamma table -// -// - -#include -#include - -const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip -const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 - -// for esp8266 the pin is ignored unless it is the bitbang method -NeoPixelBus strip(PixelCount, PixelPin); - -NeoGamma colorGamma; - -void DrawPixels(bool corrected, HslColor startColor, HslColor stopColor) -{ - for (uint16_t index = 0; index < strip.PixelCount() - 1; index++) - { - float progress = index / static_cast(strip.PixelCount() - 2); - RgbColor color = HslColor::LinearBlend(startColor, stopColor, progress); - if (corrected) - { - color = colorGamma.Correct(color); - } - strip.SetPixelColor(index, color); - } - - // use the last pixel to indicate if we are showing corrected colors or not - if (corrected) - { - strip.SetPixelColor(strip.PixelCount() - 1, RgbColor(64)); - } - else - { - strip.SetPixelColor(strip.PixelCount() - 1, RgbColor(0)); - } - - strip.Show(); -} - - -float GammaCalc(float unitValue) -{ - // we will use CieLab gamma equation for our custom table - return NeoEase::GammaCieLab(unitValue); -} - -void setup() -{ - // initialize the internal gamma table using our GammaCalc function - // if you plan on using 16bit element colors, add a second optional arg as `true` - NeoGammaDynamicTableMethod::Initialize(GammaCalc); // , true); - - strip.Begin(); - strip.Show(); -} - -void loop() -{ - HslColor startColor; - HslColor stopColor; - - // red color - startColor = HslColor(0.0f, 1.0f, 0.0f); - stopColor = HslColor(0.0f, 1.0f, 0.5f); - DrawPixels(true, startColor, stopColor); - delay(5000); - DrawPixels(false, startColor, stopColor); - delay(5000); - - // green color - startColor = HslColor(0.33f, 1.0f, 0.0f); - stopColor = HslColor(0.33f, 1.0f, 0.5f); - DrawPixels(true, startColor, stopColor); - delay(5000); - DrawPixels(false, startColor, stopColor); - delay(5000); - - // blue color - startColor = HslColor(0.66f, 1.0f, 0.0f); - stopColor = HslColor(0.66f, 1.0f, 0.5f); - DrawPixels(true, startColor, stopColor); - delay(5000); - DrawPixels(false, startColor, stopColor); - delay(5000); - - // white color - startColor = HslColor(0.0f, 0.0f, 0.0f); - stopColor = HslColor(0.0f, 0.0f, 0.5f); - DrawPixels(true, startColor, stopColor); - delay(5000); - DrawPixels(false, startColor, stopColor); - delay(5000); -} \ No newline at end of file diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino index 4854b00af4..6b70b6f427 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino @@ -41,13 +41,10 @@ NeoMosaic mosaic( void DumpMosaic() { - int16_t totalWidth = static_cast(mosaic.getWidth()); - int16_t totalHeight = static_cast(mosaic.getHeight()); - Serial.println(); Serial.print("\t\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < mosaic.getWidth(); x++) { Serial.print(x); Serial.print("\t"); @@ -55,19 +52,19 @@ void DumpMosaic() Serial.println(); Serial.print("\t---"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < mosaic.getWidth(); x++) { Serial.print("--------"); } Serial.println(); - for (int16_t y = 0; y < totalHeight; y++) + for (int y = 0; y < mosaic.getHeight(); y++) { Serial.print(" "); Serial.print(y); Serial.print("\t|\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < mosaic.getWidth(); x++) { NeoTopologyHint hint = mosaic.TopologyHint(x, y); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino index 700a1bfed3..2f6500c9f0 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino @@ -35,9 +35,9 @@ NeoMosaic mosaic( TileWidth, TileHeight); -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); RgbColor red(128, 0, 0); RgbColor green(0, 128, 0); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino index 6e4753a11a..57aa6e4b82 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino @@ -63,7 +63,7 @@ NeoRingTopology topo; // declare our strip // -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // define some handy colors // diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino index 47922a7f3b..26d526fd7e 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino @@ -47,7 +47,7 @@ NeoRingTopology topo; // declare our strip // -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // define some handy colors // diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino index c95a0d2f44..2849c56197 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino @@ -45,13 +45,10 @@ NeoTiles tiles( void DumpTopo() { - int16_t totalWidth = static_cast(tiles.getWidth()); - int16_t totalHeight = static_cast(tiles.getHeight()); - Serial.println(); Serial.print("\t\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < tiles.getWidth(); x++) { Serial.print(x); Serial.print("\t"); @@ -59,19 +56,19 @@ void DumpTopo() Serial.println(); Serial.print("\t---"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < tiles.getWidth(); x++) { Serial.print("--------"); } Serial.println(); - for (int16_t y = 0; y < totalHeight; y++) + for (int y = 0; y < tiles.getHeight(); y++) { Serial.print(" "); Serial.print(y); Serial.print("\t|\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < tiles.getWidth(); x++) { NeoTopologyHint hint = tiles.TopologyHint(x, y); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino index f86e603b49..1dfc645169 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino @@ -39,11 +39,11 @@ NeoTiles tiles( TileWidth, TileHeight); -NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); RgbColor red(128, 0, 0); RgbColor green(0, 128, 0); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino index d0e5548f88..aa78a25399 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino @@ -31,13 +31,10 @@ NeoTopology topo(PanelWidth, PanelHeight); void DumpTopo() { - int16_t totalWidth = static_cast(topo.getWidth()); - int16_t totalHeight = static_cast(topo.getHeight()); - Serial.println(); Serial.print("\t\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < topo.getWidth(); x++) { Serial.print(x); Serial.print("\t"); @@ -45,19 +42,19 @@ void DumpTopo() Serial.println(); Serial.print("\t--"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < topo.getWidth(); x++) { Serial.print("--------"); } Serial.println(); - for (int16_t y = 0; y < totalHeight; y++) + for (int y = 0; y < topo.getHeight(); y++) { Serial.print(" "); Serial.print(y); Serial.print("\t|\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < topo.getWidth(); x++) { Serial.print(topo.Map(x, y)); Serial.print("\t"); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino index 6ff0628683..2071abb348 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino @@ -28,11 +28,11 @@ const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignore NeoTopology topo(PanelWidth, PanelHeight); -NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); RgbColor red(128, 0, 0); RgbColor green(0, 128, 0); diff --git a/lib/NeoPixelBus/keywords.txt b/lib/NeoPixelBus/keywords.txt index 7fce1f1256..03f59e82cd 100644 --- a/lib/NeoPixelBus/keywords.txt +++ b/lib/NeoPixelBus/keywords.txt @@ -7,24 +7,17 @@ ####################################### NeoPixelBus KEYWORD1 -NeoPixelBusLg KEYWORD1 NeoPixelSegmentBus KEYWORD1 RgbwColor KEYWORD1 RgbColor KEYWORD1 Rgb16Color KEYWORD1 Rgb48Color KEYWORD1 -Rgbw64Color KEYWORD1 -RgbwwColor KEYWORD1 HslColor KEYWORD1 HsbColor KEYWORD1 HtmlColor KEYWORD1 NeoNoSettings KEYWORD1 NeoTm1814Settings KEYWORD1 NeoTm1914Settings KEYWORD1 -NeoSm16803pbSettings KEYWORD1 -NeoSm16823eSettings KEYWORD1 -NeoSm16804ebSettings KEYWORD1 -NeoSm16824eSettings KEYWORD1 NeoSpiSettings KEYWORD1 NeoGrbFeature KEYWORD1 NeoGrbwFeature KEYWORD1 @@ -32,21 +25,9 @@ NeoRgbwFeature KEYWORD1 NeoRgbFeature KEYWORD1 NeoBrgFeature KEYWORD1 NeoRbgFeature KEYWORD1 -NeoBgrFeature KEYWORD1 -NeoRgbw64Feature KEYWORD1 -NeoRgb48Feature KEYWORD1 -NeoGrb48Feature KEYWORD1 -NeoGrbcwxFeature KEYWORD1 -NeoRgbUcs8903Feature KEYWORD1 -NeoRgbwUcs8904Feature KEYWORD1 -NeoGrb48Ws2816Feature KEYWORD1 NeoWrgbTm1814Feature KEYWORD1 NeoRgbTm1914Feature KEYWORD1 NeoGrbTm1914Feature KEYWORD1 -NeoRgbSm16803pbFeature KEYWORD1 -NeoRgbSm16823eFeature KEYWORD1 -NeoRgbwSm16804ebFeature KEYWORD1 -NeoRgbwSm16824eFeature KEYWORD1 DotStarBgrFeature KEYWORD1 DotStarLbgrFeature KEYWORD1 Lpd6803GrbFeature KEYWORD1 @@ -63,7 +44,6 @@ NeoWs2813Method KEYWORD1 NeoWs2812xMethod KEYWORD1 NeoWs2812Method KEYWORD1 NeoWs2811Method KEYWORD1 -NeoWs2816Method KEYWORD1 NeoSk6812Method KEYWORD1 NeoTm1814Method KEYWORD1 NeoTm1914Method KEYWORD1 @@ -71,14 +51,12 @@ NeoTm1829Method KEYWORD1 NeoTx1812Method KEYWORD1 NeoLc8812Method KEYWORD1 NeoApa106Method KEYWORD1 -NeoIntertekMethod KEYWORD1 Neo800KbpsInvertedMethod KEYWORD1 Neo400KbpsInvertedMethod KEYWORD1 NeoWs2813InvertedMethod KEYWORD1 NeoWs2812xInvertedMethod KEYWORD1 NeoWs2812InvertedMethod KEYWORD1 NeoWs2811InvertedMethod KEYWORD1 -NeoWs2816InvertedMethod KEYWORD1 NeoSk6812InvertedMethod KEYWORD1 NeoTm1814InvertedMethod KEYWORD1 NeoTm1914InvertedMethod KEYWORD1 @@ -86,9 +64,7 @@ NeoTm1829InvertedMethod KEYWORD1 NeoTx1812InvertedMethod KEYWORD1 NeoLc8812InvertedMethod KEYWORD1 NeoApa106InvertedMethod KEYWORD1 -NeoInvertedIntertekMethod KEYWORD1 NeoEsp8266DmaWs2812xMethod KEYWORD1 -NeoEsp8266DmaWs2816Method KEYWORD1 NeoEsp8266DmaSk6812Method KEYWORD1 NeoEsp8266DmaTm1814Method KEYWORD1 NeoEsp8266DmaTm1914Method KEYWORD1 @@ -97,7 +73,6 @@ NeoEsp8266DmaApa106Method KEYWORD1 NeoEsp8266Dma800KbpsMethod KEYWORD1 NeoEsp8266Dma400KbpsMethod KEYWORD1 NeoEsp8266DmaInvertedWs2812xMethod KEYWORD1 -NeoEsp8266DmaInvertedWs2816Method KEYWORD1 NeoEsp8266DmaInvertedSk6812Method KEYWORD1 NeoEsp8266DmaInvertedTm1814Method KEYWORD1 NeoEsp8266DmaInvertedTm1914Method KEYWORD1 @@ -105,15 +80,10 @@ NeoEsp8266DmaInvertedTm1829Method KEYWORD1 NeoEsp8266DmaInvertedApa106Method KEYWORD1 NeoEsp8266DmaInverted800KbpsMethod KEYWORD1 NeoEsp8266DmaInverted400KbpsMethod KEYWORD1 -NeoEsp8266Dmx512Method KEYWORD1 -NeoEsp8266Ws2821Method KEYWORD1 -NeoEsp8266Dmx512InvertedMethod KEYWORD1 -NeoEsp8266Ws2821InvertedMethod KEYWORD1 NeoEsp8266Uart0Ws2813Method KEYWORD1 NeoEsp8266Uart0Ws2812xMethod KEYWORD1 NeoEsp8266Uart0Ws2812Method KEYWORD1 NeoEsp8266Uart0Ws2811Method KEYWORD1 -NeoEsp8266Uart0Ws2816Method KEYWORD1 NeoEsp8266Uart0Sk6812Method KEYWORD1 NeoEsp8266Uart0Tm1814Method KEYWORD1 NeoEsp8266Uart0Tm1914Method KEYWORD1 @@ -126,7 +96,6 @@ NeoEsp8266AsyncUart0Ws2813Method KEYWORD1 NeoEsp8266AsyncUart0Ws2812xMethod KEYWORD1 NeoEsp8266AsyncUart0Ws2812Method KEYWORD1 NeoEsp8266AsyncUart0Ws2811Method KEYWORD1 -NeoEsp8266AsyncUart0Ws2816Method KEYWORD1 NeoEsp8266AsyncUart0Sk6812Method KEYWORD1 NeoEsp8266AsyncUart0Tm1814Method KEYWORD1 NeoEsp8266AsyncUart0Tm1914Method KEYWORD1 @@ -139,7 +108,6 @@ NeoEsp8266Uart1Ws2813Method KEYWORD1 NeoEsp8266Uart1Ws2812xMethod KEYWORD1 NeoEsp8266Uart1Ws2812Method KEYWORD1 NeoEsp8266Uart1Ws2811Method KEYWORD1 -NeoEsp8266Uart1Ws2816Method KEYWORD1 NeoEsp8266Uart1Sk6812Method KEYWORD1 NeoEsp8266Uart1Tm1814 KEYWORD1 NeoEsp8266Uart1Tm1914 KEYWORD1 @@ -152,7 +120,6 @@ NeoEsp8266AsyncUart1Ws2813Method KEYWORD1 NeoEsp8266AsyncUart1Ws2812xMethod KEYWORD1 NeoEsp8266AsyncUart1Ws2812Method KEYWORD1 NeoEsp8266AsyncUart1Ws2811Method KEYWORD1 -NeoEsp8266AsyncUart1Ws2816Method KEYWORD1 NeoEsp8266AsyncUart1Sk6812Method KEYWORD1 NeoEsp8266AsyncUart1Tm1814 KEYWORD1 NeoEsp8266AsyncUart1Tm1914 KEYWORD1 @@ -165,7 +132,6 @@ NeoEsp8266Uart0Ws2813InvertedMethod KEYWORD1 NeoEsp8266Uart0Ws2812xInvertedMethod KEYWORD1 NeoEsp8266Uart0Ws2812InvertedMethod KEYWORD1 NeoEsp8266Uart0Ws2811InvertedMethod KEYWORD1 -NeoEsp8266Uart0Ws2816InvertedMethod KEYWORD1 NeoEsp8266Uart0Sk6812InvertedMethod KEYWORD1 NeoEsp8266Uart0Tm1814InvertedMethod KEYWORD1 NeoEsp8266Uart0Tm1914InvertedMethod KEYWORD1 @@ -178,7 +144,6 @@ NeoEsp8266AsyncUart0Ws2813InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Ws2812xInvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Ws2812InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Ws2811InvertedMethod KEYWORD1 -NeoEsp8266AsyncUart0Ws2816InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Sk6812InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Tm1814InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Tm1914InvertedMethod KEYWORD1 @@ -191,7 +156,6 @@ NeoEsp8266Uart1Ws2813InvertedMethod KEYWORD1 NeoEsp8266Uart1Ws2812xInvertedMethod KEYWORD1 NeoEsp8266Uart1Ws2812InvertedMethod KEYWORD1 NeoEsp8266Uart1Ws2811InvertedMethod KEYWORD1 -NeoEsp8266Uart1Ws2816InvertedMethod KEYWORD1 NeoEsp8266Uart1Sk6812InvertedMethod KEYWORD1 NeoEsp8266Uart1Tm1814InvertedMethod KEYWORD1 NeoEsp8266Uart1Tm1914InvertedMethod KEYWORD1 @@ -204,7 +168,6 @@ NeoEsp8266AsyncUart1Ws2813InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Ws2812xInvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Ws2812InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Ws2811InvertedMethod KEYWORD1 -NeoEsp8266AsyncUart1Ws2816InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Sk6812InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Tm1814InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Tm1914InvertedMethod KEYWORD1 @@ -217,7 +180,6 @@ NeoEsp8266BitBangWs2813Method KEYWORD1 NeoEsp8266BitBangWs2812xMethod KEYWORD1 NeoEsp8266BitBangWs2812Method KEYWORD1 NeoEsp8266BitBangWs2811Method KEYWORD1 -NeoEsp8266BitBangWs2816Method KEYWORD1 NeoEsp8266BitBangSk6812Method KEYWORD1 NeoEsp8266BitBangTm1814Method KEYWORD1 NeoEsp8266BitBangTm1914Method KEYWORD1 @@ -230,7 +192,6 @@ NeoEsp8266BitBangWs2813InvertedMethod KEYWORD1 NeoEsp8266BitBangWs2812xInvertedMethod KEYWORD1 NeoEsp8266BitBangWs2812InvertedMethod KEYWORD1 NeoEsp8266BitBangWs2811InvertedMethod KEYWORD1 -NeoEsp8266BitBangWs2816InvertedMethod KEYWORD1 NeoEsp8266BitBangSk6812InvertedMethod KEYWORD1 NeoEsp8266BitBangTm1814InvertedMethod KEYWORD1 NeoEsp8266BitBangTm1914InvertedMethod KEYWORD1 @@ -240,7 +201,6 @@ NeoEsp8266BitBangApa106InvertedMethod KEYWORD1 NeoEsp8266BitBang800KbpsInvertedMethod KEYWORD1 NeoEsp8266BitBang400KbpsInvertedMethod KEYWORD1 NeoEsp32I2sNWs2812xMethod KEYWORD1 -NeoEsp32I2sNWs2816Method KEYWORD1 NeoEsp32I2sNSk6812Method KEYWORD1 NeoEsp32I2sNTm1814Method KEYWORD1 NeoEsp32I2sNTm1914Method KEYWORD1 @@ -248,7 +208,6 @@ NeoEsp32I2sN800KbpsMethod KEYWORD1 NeoEsp32I2sN400KbpsMethod KEYWORD1 NeoEsp32I2sNApa106Method KEYWORD1 NeoEsp32I2s0Ws2812xMethod KEYWORD1 -NeoEsp32I2s0Ws2816Method KEYWORD1 NeoEsp32I2s0Sk6812Method KEYWORD1 NeoEsp32I2s0Tm1814Method KEYWORD1 NeoEsp32I2s0Tm1914Method KEYWORD1 @@ -257,7 +216,6 @@ NeoEsp32I2s0800KbpsMethod KEYWORD1 NeoEsp32I2s0400KbpsMethod KEYWORD1 NeoEsp32I2s0Apa106Method KEYWORD1 NeoEsp32I2s1Ws2812xMethod KEYWORD1 -NeoEsp32I2s1Ws2816Method KEYWORD1 NeoEsp32I2s1Sk6812Method KEYWORD1 NeoEsp32I2s1Tm1814Method KEYWORD1 NeoEsp32I2s1Tm1914Method KEYWORD1 @@ -266,7 +224,6 @@ NeoEsp32I2s1800KbpsMethod KEYWORD1 NeoEsp32I2s1400KbpsMethod KEYWORD1 NeoEsp32I2s1Apa106Method KEYWORD1 NeoEsp32I2sNWs2812xInvertedMethod KEYWORD1 -NeoEsp32I2sNWs2816InvertedMethod KEYWORD1 NeoEsp32I2sNSk6812InvertedMethod KEYWORD1 NeoEsp32I2sNTm1814InvertedMethod KEYWORD1 NeoEsp32I2sNTm1914InvertedMethod KEYWORD1 @@ -274,7 +231,6 @@ NeoEsp32I2sN800KbpsInvertedMethod KEYWORD1 NeoEsp32I2sN400KbpsInvertedMethod KEYWORD1 NeoEsp32I2sNApa106InvertedMethod KEYWORD1 NeoEsp32I2s0Ws2812xInvertedMethod KEYWORD1 -NeoEsp32I2s0Ws2816InvertedMethod KEYWORD1 NeoEsp32I2s0Sk6812InvertedMethod KEYWORD1 NeoEsp32I2s0Tm1814InvertedMethod KEYWORD1 NeoEsp32I2s0Tm1914InvertedMethod KEYWORD1 @@ -283,7 +239,6 @@ NeoEsp32I2s0800KbpsInvertedMethod KEYWORD1 NeoEsp32I2s0400KbpsInvertedMethod KEYWORD1 NeoEsp32I2s0Apa106InvertedMethod KEYWORD1 NeoEsp32I2s1Ws2812xInvertedMethod KEYWORD1 -NeoEsp32I2s1Ws2816InvertedMethod KEYWORD1 NeoEsp32I2s1Sk6812InvertedMethod KEYWORD1 NeoEsp32I2s1Tm1814InvertedMethod KEYWORD1 NeoEsp32I2s1Tm1914InvertedMethod KEYWORD1 @@ -291,65 +246,8 @@ NeoEsp32I2s1Tm1829InvertedMethod KEYWORD1 NeoEsp32I2s1800KbpsInvertedMethod KEYWORD1 NeoEsp32I2s1400KbpsInvertedMethod KEYWORD1 NeoEsp32I2s1Apa106InvertedMethod KEYWORD1 -NeoEsp32I2s0X8Ws2812xMethod KEYWORD1 -NeoEsp32I2s0X8800KbpsMethod KEYWORD1 -NeoEsp32I2s0X8400KbpsMethod KEYWORD1 -NeoEsp32I2s0X8Ws2813Method KEYWORD1 -NeoEsp32I2s0X8Ws2812dMethod KEYWORD1 -NeoEsp32I2s0X8Ws2811Method KEYWORD1 -NeoEsp32I2s0X8Ws2816Method KEYWORD1 -NeoEsp32I2s0X8Ws2812Method KEYWORD1 -NeoEsp32I2s0X8Sk6812Method KEYWORD1 -NeoEsp32I2s0X8Tm1814Method KEYWORD1 -NeoEsp32I2s0X8Tm1829Method KEYWORD1 -NeoEsp32I2s0X8Tm1914Method KEYWORD1 -NeoEsp32I2s0X8Lc8812Method KEYWORD1 -NeoEsp32I2s0X8Apa106Method KEYWORD1 -NeoEsp32I2s0X16Ws2812xMethod KEYWORD1 -NeoEsp32I2s0X16800KbpsMethod KEYWORD1 -NeoEsp32I2s0X16400KbpsMethod KEYWORD1 -NeoEsp32I2s0X16Ws2813Method KEYWORD1 -NeoEsp32I2s0X16Ws2812dMethod KEYWORD1 -NeoEsp32I2s0X16Ws2811Method KEYWORD1 -NeoEsp32I2s0X16Ws2816Method KEYWORD1 -NeoEsp32I2s0X16Ws2812Method KEYWORD1 -NeoEsp32I2s0X16Sk6812Method KEYWORD1 -NeoEsp32I2s0X16Tm1814Method KEYWORD1 -NeoEsp32I2s0X16Tm1829Method KEYWORD1 -NeoEsp32I2s0X16Tm1914Method KEYWORD1 -NeoEsp32I2s0X16Lc8812Method KEYWORD1 -NeoEsp32I2s0X16Apa106Method KEYWORD1 -NeoEsp32I2s1X8Ws2812xMethod KEYWORD1 -NeoEsp32I2s1X8800KbpsMethod KEYWORD1 -NeoEsp32I2s1X8400KbpsMethod KEYWORD1 -NeoEsp32I2s1X8Ws2813Method KEYWORD1 -NeoEsp32I2s1X8Ws2812dMethod KEYWORD1 -NeoEsp32I2s1X8Ws2811Method KEYWORD1 -NeoEsp32I2s1X8Ws2816Method KEYWORD1 -NeoEsp32I2s1X8Ws2812Method KEYWORD1 -NeoEsp32I2s1X8Sk6812Method KEYWORD1 -NeoEsp32I2s1X8Tm1814Method KEYWORD1 -NeoEsp32I2s1X8Tm1829Method KEYWORD1 -NeoEsp32I2s1X8Tm1914Method KEYWORD1 -NeoEsp32I2s1X8Lc8812Method KEYWORD1 -NeoEsp32I2s1X8Apa106Method KEYWORD1 -NeoEsp32I2s1X16Ws2812xMethod KEYWORD1 -NeoEsp32I2s1X16800KbpsMethod KEYWORD1 -NeoEsp32I2s1X16400KbpsMethod KEYWORD1 -NeoEsp32I2s1X16Ws2813Method KEYWORD1 -NeoEsp32I2s1X16Ws2812dMethod KEYWORD1 -NeoEsp32I2s1X16Ws2811Method KEYWORD1 -NeoEsp32I2s1X16Ws2816Method KEYWORD1 -NeoEsp32I2s1X16Ws2812Method KEYWORD1 -NeoEsp32I2s1X16Sk6812Method KEYWORD1 -NeoEsp32I2s1X16Tm1814Method KEYWORD1 -NeoEsp32I2s1X16Tm1829Method KEYWORD1 -NeoEsp32I2s1X16Tm1914Method KEYWORD1 -NeoEsp32I2s1X16Lc8812Method KEYWORD1 -NeoEsp32I2s1X16Apa106Method KEYWORD1 NeoEsp32RmtNWs2811Method KEYWORD1 NeoEsp32RmtNWs2812xMethod KEYWORD1 -NeoEsp32RmtNWs2816Method KEYWORD1 NeoEsp32RmtNSk6812Method KEYWORD1 NeoEsp32RmtNTm1814Method KEYWORD1 NeoEsp32RmtNTm1914Method KEYWORD1 @@ -359,7 +257,6 @@ NeoEsp32RmtN800KbpsMethod KEYWORD1 NeoEsp32RmtN400KbpsMethod KEYWORD1 NeoEsp32Rmt0Ws2811Method KEYWORD1 NeoEsp32Rmt0Ws2812xMethod KEYWORD1 -NeoEsp32Rmt0Ws2816Method KEYWORD1 NeoEsp32Rmt0Sk6812Method KEYWORD1 NeoEsp32Rmt0Tm1814Method KEYWORD1 NeoEsp32Rmt0Tm1914Method KEYWORD1 @@ -369,7 +266,6 @@ NeoEsp32Rmt0800KbpsMethod KEYWORD1 NeoEsp32Rmt0400KbpsMethod KEYWORD1 NeoEsp32Rmt1Ws2811Method KEYWORD1 NeoEsp32Rmt1Ws2812xMethod KEYWORD1 -NeoEsp32Rmt1Ws2816Method KEYWORD1 NeoEsp32Rmt1Sk6812Method KEYWORD1 NeoEsp32Rmt1Tm1814Method KEYWORD1 NeoEsp32Rmt1Tm1914Method KEYWORD1 @@ -379,7 +275,6 @@ NeoEsp32Rmt1800KbpsMethod KEYWORD1 NeoEsp32Rmt1400KbpsMethod KEYWORD1 NeoEsp32Rmt2Ws2811Method KEYWORD1 NeoEsp32Rmt2Ws2812xMethod KEYWORD1 -NeoEsp32Rmt2Ws2816Method KEYWORD1 NeoEsp32Rmt2Sk6812Method KEYWORD1 NeoEsp32Rmt2Tm1814Method KEYWORD1 NeoEsp32Rmt2Tm1829Method KEYWORD1 @@ -389,7 +284,6 @@ NeoEsp32Rmt2800KbpsMethod KEYWORD1 NeoEsp32Rmt2400KbpsMethod KEYWORD1 NeoEsp32Rmt3Ws2811Method KEYWORD1 NeoEsp32Rmt3Ws2812xMethod KEYWORD1 -NeoEsp32Rmt3Ws2816Method KEYWORD1 NeoEsp32Rmt3Sk6812Method KEYWORD1 NeoEsp32Rmt3Tm1814Method KEYWORD1 NeoEsp32Rmt3Tm1914Method KEYWORD1 @@ -399,7 +293,6 @@ NeoEsp32Rmt3800KbpsMethod KEYWORD1 NeoEsp32Rmt3400KbpsMethod KEYWORD1 NeoEsp32Rmt4Ws2811Method KEYWORD1 NeoEsp32Rmt4Ws2812xMethod KEYWORD1 -NeoEsp32Rmt4Ws2816Method KEYWORD1 NeoEsp32Rmt4Sk6812Method KEYWORD1 NeoEsp32Rmt4Tm1814Method KEYWORD1 NeoEsp32Rmt4Tm1914Method KEYWORD1 @@ -409,7 +302,6 @@ NeoEsp32Rmt4800KbpsMethod KEYWORD1 NeoEsp32Rmt4400KbpsMethod KEYWORD1 NeoEsp32Rmt5Ws2811Method KEYWORD1 NeoEsp32Rmt5Ws2812xMethod KEYWORD1 -NeoEsp32Rmt5Ws2816Method KEYWORD1 NeoEsp32Rmt5Sk6812Method KEYWORD1 NeoEsp32Rmt5Tm1814Method KEYWORD1 NeoEsp32Rmt5Tm1914Method KEYWORD1 @@ -419,7 +311,6 @@ NeoEsp32Rmt5800KbpsMethod KEYWORD1 NeoEsp32Rmt5400KbpsMethod KEYWORD1 NeoEsp32Rmt6Ws2811Method KEYWORD1 NeoEsp32Rmt6Ws2812xMethod KEYWORD1 -NeoEsp32Rmt6Ws2816Method KEYWORD1 NeoEsp32Rmt6Sk6812Method KEYWORD1 NeoEsp32Rmt6Tm1814Method KEYWORD1 NeoEsp32Rmt6Tm1914Method KEYWORD1 @@ -429,7 +320,6 @@ NeoEsp32Rmt6800KbpsMethod KEYWORD1 NeoEsp32Rmt6400KbpsMethod KEYWORD1 NeoEsp32Rmt7Ws2811Method KEYWORD1 NeoEsp32Rmt7Ws2812xMethod KEYWORD1 -NeoEsp32Rmt7Ws2816Method KEYWORD1 NeoEsp32Rmt7Sk6812Method KEYWORD1 NeoEsp32Rmt7Tm1814Method KEYWORD1 NeoEsp32Rmt7Tm1914Method KEYWORD1 @@ -439,7 +329,6 @@ NeoEsp32Rmt7800KbpsMethod KEYWORD1 NeoEsp32Rmt7400KbpsMethod KEYWORD1 NeoEsp32RmtNWs2811InvertedMethod KEYWORD1 NeoEsp32RmtNWs2812xInvertedMethod KEYWORD1 -NeoEsp32RmtNWs2816InvertedMethod KEYWORD1 NeoEsp32RmtNSk6812InvertedMethod KEYWORD1 NeoEsp32RmtNTm1814InvertedMethod KEYWORD1 NeoEsp32RmtNTm1914InvertedMethod KEYWORD1 @@ -449,7 +338,6 @@ NeoEsp32RmtN800KbpsInvertedMethod KEYWORD1 NeoEsp32RmtN400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt0Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt0Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt0Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt0Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt0Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt0Tm1914InvertedMethod KEYWORD1 @@ -459,7 +347,6 @@ NeoEsp32Rmt0800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt0400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt1Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt1Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt1Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt1Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt1Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt1Tm1914InvertedMethod KEYWORD1 @@ -469,7 +356,6 @@ NeoEsp32Rmt1800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt1400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt2Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt2Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt2Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt2Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt2Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt2Tm1914InvertedMethod KEYWORD1 @@ -479,7 +365,6 @@ NeoEsp32Rmt2800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt2400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt3Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt3Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt3Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt3Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt3Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt3Tm1914InvertedMethod KEYWORD1 @@ -489,7 +374,6 @@ NeoEsp32Rmt3800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt3400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt4Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt4Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt4Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt4Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt4Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt4Tm1914InvertedMethod KEYWORD1 @@ -499,7 +383,6 @@ NeoEsp32Rmt4800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt4400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt5Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt5Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt5Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt5Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt5Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt5Tm1914InvertedMethod KEYWORD1 @@ -509,7 +392,6 @@ NeoEsp32Rmt5800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt5400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt6Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt6Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt6Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt6Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt6Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt6Tm1914InvertedMethod KEYWORD1 @@ -519,7 +401,6 @@ NeoEsp32Rmt6800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt6400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt7Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt7Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt7Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt7Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt7Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt7Tm1914InvertedMethod KEYWORD1 @@ -531,7 +412,6 @@ NeoEsp32BitBangWs2813Method KEYWORD1 NeoEsp32BitBangWs2812xMethod KEYWORD1 NeoEsp32BitBangWs2812Method KEYWORD1 NeoEsp32BitBangWs2811Method KEYWORD1 -NeoEsp32BitBangWs2816Method KEYWORD1 NeoEsp32BitBangSk6812Method KEYWORD1 NeoEsp32BitBangTm1814Method KEYWORD1 NeoEsp32BitBangTm1914Method KEYWORD1 @@ -544,7 +424,6 @@ NeoEsp32BitBangWs2813InvertedMethod KEYWORD1 NeoEsp32BitBangWs2812xInvertedMethod KEYWORD1 NeoEsp32BitBangWs2812InvertedMethod KEYWORD1 NeoEsp32BitBangWs2811InvertedMethod KEYWORD1 -NeoEsp32BitBangWs2816InvertedMethod KEYWORD1 NeoEsp32BitBangSk6812InvertedMethod KEYWORD1 NeoEsp32BitBangTm1814InvertedMethod KEYWORD1 NeoEsp32BitBangTm1914InvertedMethod KEYWORD1 @@ -554,7 +433,6 @@ NeoEsp32BitBangApa106InvertedMethod KEYWORD1 NeoEsp32BitBang800KbpsInvertedMethod KEYWORD1 NeoEsp32BitBang400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwmNWs2812xMethod KEYWORD1 -NeoNrf52xPwmNWs2816Method KEYWORD1 NeoNrf52xPwmNSk6812Method KEYWORD1 NeoNrf52xPwmNTm1814Method KEYWORD1 NeoNrf52xPwmNTm1914Method KEYWORD1 @@ -564,7 +442,6 @@ NeoNrf52xPwmN800KbpsMethod KEYWORD1 NeoNrf52xPwmN400KbpsMethod KEYWORD1 NeoNrf52xPwmNApa106Method KEYWORD1 NeoNrf52xPwm0Ws2812xMethod KEYWORD1 -NeoNrf52xPwm0Ws2816Method KEYWORD1 NeoNrf52xPwm0Sk6812Method KEYWORD1 NeoNrf52xPwm0Tm1814Method KEYWORD1 NeoNrf52xPwm0Tm1914Method KEYWORD1 @@ -574,7 +451,6 @@ NeoNrf52xPwm0800KbpsMethod KEYWORD1 NeoNrf52xPwm0400KbpsMethod KEYWORD1 NeoNrf52xPwm0Apa106Method KEYWORD1 NeoNrf52xPwm1Ws2812xMethod KEYWORD1 -NeoNrf52xPwm1Ws2816Method KEYWORD1 NeoNrf52xPwm1Sk6812Method KEYWORD1 NeoNrf52xPwm1Tm1814Method KEYWORD1 NeoNrf52xPwm1Tm1914Method KEYWORD1 @@ -584,7 +460,6 @@ NeoNrf52xPwm1800KbpsMethod KEYWORD1 NeoNrf52xPwm1400KbpsMethod KEYWORD1 NeoNrf52xPwm1Apa106Method KEYWORD1 NeoNrf52xPwm2Ws2812xMethod KEYWORD1 -NeoNrf52xPwm2Ws2816Method KEYWORD1 NeoNrf52xPwm2Sk6812Method KEYWORD1 NeoNrf52xPwm2Tm1814Method KEYWORD1 NeoNrf52xPwm2Tm1914Method KEYWORD1 @@ -594,7 +469,6 @@ NeoNrf52xPwm2800KbpsMethod KEYWORD1 NeoNrf52xPwm2400KbpsMethod KEYWORD1 NeoNrf52xPwm2Apa106Method KEYWORD1 NeoNrf52xPwm3Ws2812xMethod KEYWORD1 -NeoNrf52xPwm3Ws2816Method KEYWORD1 NeoNrf52xPwm3Sk6812Method KEYWORD1 NeoNrf52xPwm3Tm1814Method KEYWORD1 NeoNrf52xPwm3Tm1914Method KEYWORD1 @@ -604,7 +478,6 @@ NeoNrf52xPwm3800KbpsMethod KEYWORD1 NeoNrf52xPwm3400KbpsMethod KEYWORD1 NeoNrf52xPwm3Apa106Method KEYWORD1 NeoNrf52xPwmNWs2812xInvertedMethod KEYWORD1 -NeoNrf52xPwmNWs2816InvertedMethod KEYWORD1 NeoNrf52xPwmNSk6812InvertedMethod KEYWORD1 NeoNrf52xPwmNTm1814InvertedMethod KEYWORD1 NeoNrf52xPwmNTm1914InvertedMethod KEYWORD1 @@ -614,7 +487,6 @@ NeoNrf52xPwmN800KbpsInvertedMethod KEYWORD1 NeoNrf52xPwmN400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwmNApa106InvertedMethod KEYWORD1 NeoNrf52xPwm0Ws2812xInvertedMethod KEYWORD1 -NeoNrf52xPwm0Ws2816InvertedMethod KEYWORD1 NeoNrf52xPwm0Sk6812InvertedMethod KEYWORD1 NeoNrf52xPwm0Tm1814InvertedMethod KEYWORD1 NeoNrf52xPwm0Tm1914InvertedMethod KEYWORD1 @@ -624,7 +496,6 @@ NeoNrf52xPwm0800KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm0400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm0Apa106InvertedMethod KEYWORD1 NeoNrf52xPwm1Ws2812xInvertedMethod KEYWORD1 -NeoNrf52xPwm1Ws2816InvertedMethod KEYWORD1 NeoNrf52xPwm1Sk6812InvertedMethod KEYWORD1 NeoNrf52xPwm1Tm1814InvertedMethod KEYWORD1 NeoNrf52xPwm1Tm1914InvertedMethod KEYWORD1 @@ -634,7 +505,6 @@ NeoNrf52xPwm1800KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm1400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm1Apa106InvertedMethod KEYWORD1 NeoNrf52xPwm2Ws2812xInvertedMethod KEYWORD1 -NeoNrf52xPwm2Ws2816InvertedMethod KEYWORD1 NeoNrf52xPwm2Sk6812InvertedMethod KEYWORD1 NeoNrf52xPwm2Tm1814InvertedMethod KEYWORD1 NeoNrf52xPwm2Tm1914InvertedMethod KEYWORD1 @@ -644,7 +514,6 @@ NeoNrf52xPwm2800KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm2400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm2Apa106InvertedMethod KEYWORD1 NeoNrf52xPwm3Ws2812xInvertedMethod KEYWORD1 -NeoNrf52xPwm3Ws2816InvertedMethod KEYWORD1 NeoNrf52xPwm3Sk6812InvertedMethod KEYWORD1 NeoNrf52xPwm3Tm1814InvertedMethod KEYWORD1 NeoNrf52xPwm3Tm1914InvertedMethod KEYWORD1 @@ -661,14 +530,14 @@ DotStarSpi2MhzMethod KEYWORD1 DotStarSpi1MhzMethod KEYWORD1 DotStarSpi500KhzMethod KEYWORD1 DotStarSpiHzMethod KEYWORD1 -Ws2801Method KEYWORD1 -Ws2801SpiMethod KEYWORD1 -Ws2801Spi20MhzMethod KEYWORD1 -Ws2801Spi10MhzMethod KEYWORD1 -Ws2801Spi2MhzMethod KEYWORD1 -Ws2801Spi1MhzMethod KEYWORD1 -Ws2801Spi500KhzMethod KEYWORD1 -Ws2801SpiHzMethod KEYWORD1 +NeoWs2801Method KEYWORD1 +NeoWs2801SpiMethod KEYWORD1 +NeoWs2801Spi20MhzMethod KEYWORD1 +NeoWs2801Spi10MhzMethod KEYWORD1 +NeoWs2801Spi2MhzMethod KEYWORD1 +NeoWs2801Spi1MhzMethod KEYWORD1 +NeoWs2801Spi500KhzMethod KEYWORD1 +NeoWs2801SpiHzMethod KEYWORD1 Lpd6803SpiMethod KEYWORD1 Lpd6803Method KEYWORD1 Lpd6803Spi20MhzMethod KEYWORD1 @@ -693,15 +562,6 @@ P9813Spi2MhzMethod KEYWORD1 P9813Spi1MhzMethod KEYWORD1 P9813Spi500KhzMethod KEYWORD1 P9813SpiHzMethod KEYWORD1 -Tlc5947Method KEYWORD1 -Tlc5947Method16Bit KEYWORD1 -Tlc5947Spi30MhzMethod KEYWORD1 -Tlc5947Spi30MhzMethod16Bit KEYWORD1 -Tlc5947Spi15MhzMethod KEYWORD1 -Tlc5947Spi15MhzMethod16Bit KEYWORD1 -Tlc5947SpiMethod KEYWORD1 -Tlc5947SpiMethod16Bit KEYWORD1 -Sm16716Method KEYWORD1 NeoPixelAnimator KEYWORD1 AnimUpdateCallback KEYWORD1 AnimationParam KEYWORD1 @@ -727,7 +587,6 @@ NeoTopology KEYWORD1 NeoRingTopology KEYWORD1 NeoTiles KEYWORD1 NeoMosaic KEYWORD1 -NeoGammaCieLabEquationMethod KEYWORD1 NeoGammaEquationMethod KEYWORD1 NeoGammaTableMethod KEYWORD1 NeoGamma KEYWORD1 @@ -767,9 +626,6 @@ PixelCount KEYWORD2 SetPixelColor KEYWORD2 GetPixelColor KEYWORD2 SwapPixelColor KEYWORD2 -SetLuminance KEYWORD2 -GetLuminance KEYWORD2 -ApplyPostAdjustments KEYWORD2 SetString KEYWORD2 CalculateBrightness KEYWORD2 Dim KEYWORD2 @@ -823,7 +679,6 @@ CircularOut KEYWORD2 CircularInOut KEYWORD2 CircularCenter KEYWORD2 Gamma KEYWORD2 -GammaCieLab KEYWORD2 Map KEYWORD2 MapProbe KEYWORD2 getWidth KEYWORD2 diff --git a/lib/NeoPixelBus/library.json b/lib/NeoPixelBus/library.json index 638e27dfb7..306e6e0942 100644 --- a/lib/NeoPixelBus/library.json +++ b/lib/NeoPixelBus/library.json @@ -1,13 +1,13 @@ { "name": "NeoPixelBus", - "keywords": "NeoPixel, WS2811, WS2812, WS2813, WS2821, SK6812, DotStar, APA102, SK9822, APA106, LPD8806, LPD6803, P9813, TM1829, TM1814, TM1914, TX1812, WS2801, SM16803, SM16823, SM16804, SM16824, SM16716, DMX512, RGB, RGBW", - "description": "A library that makes controlling NeoPixels (WS2812x and many others) and DotStars (SK6812 and many others) easy. Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels and 7 Segment LED direct driven. Includes separate RgbColor, RgbwColor, Rgb16Color, Rgb48Color, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For all platforms; there are two methods of sending DotStar data, hardware SPI and software SPI.", + "keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, SK9822, APA106, LPD8806, LPD6803, P9813, TM1829, TM1814, TM1914, TX1812, WS2801 RGB, RGBW", + "description": "A library that makes controlling NeoPixels (APA106, WS2811, WS2812, WS2813, SK6812, TM1829, TM1814, TM1914, TX1812) and DotStars (APA102, LPD8806, LPD6803, SK9822, WS2801, P9813) easy. Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels and 7 Segment LED direct driven. Includes seperate RgbColor, RgbwColor, Rgb16Color, Rgb48Color, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. 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.7.6", + "version": "2.6.7", "frameworks": "arduino", "platforms": "*", "dependencies": [ diff --git a/lib/NeoPixelBus/library.properties b/lib/NeoPixelBus/library.properties index 7bfa7171b9..35c9faea15 100644 --- a/lib/NeoPixelBus/library.properties +++ b/lib/NeoPixelBus/library.properties @@ -1,9 +1,9 @@ name=NeoPixelBus by Makuna -version=2.7.6 +version=2.6.7 author=Michael C. Miller (makuna@live.com) maintainer=Michael C. Miller (makuna@live.com) -sentence=A library that makes controlling NeoPixels (WS2812x and many others) and DotStars (SK6812 and many others) easy. -paragraph=Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels and 7 Segment LED direct driven. Includes separate RgbColor, RgbwColor, Rgb16Color, Rgb48Color, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. For all platforms; there are two methods of sending DotStar data, hardware SPI and software SPI. +sentence=A library that makes controlling NeoPixels (APA106, WS2811, WS2812, WS2813, SK6812, TM1829, TM1814, TM1914, TX1812) and DotStars (APA102, LPD8806, LPD6803, SK9822, WS2801, P9813) easy. +paragraph=Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels and 7 Segment LED direct driven. Includes seperate RgbColor, RgbwColor, Rgb16Color, Rgb48Color, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. 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=* +architectures=* \ No newline at end of file diff --git a/lib/NeoPixelBus/src/NeoPixelAnimator.h b/lib/NeoPixelBus/src/NeoPixelAnimator.h index b16816477c..d990599a47 100644 --- a/lib/NeoPixelBus/src/NeoPixelAnimator.h +++ b/lib/NeoPixelBus/src/NeoPixelAnimator.h @@ -27,7 +27,7 @@ License along with NeoPixel. If not, see #pragma once #include -#include "internal/animations/NeoEase.h" +#include "internal/NeoEase.h" enum AnimationState { diff --git a/lib/NeoPixelBus/src/NeoPixelBrightnessBus.h b/lib/NeoPixelBus/src/NeoPixelBrightnessBus.h index 15527b9670..e110fdfc24 100644 --- a/lib/NeoPixelBus/src/NeoPixelBrightnessBus.h +++ b/lib/NeoPixelBus/src/NeoPixelBrightnessBus.h @@ -28,18 +28,13 @@ License along with NeoPixel. If not, see #include "NeoPixelBus.h" -// FIXME 2023-08-09 tonhuisman: Disabled deprecation warning as the newer classes won't properly work with ESP8266 for ESPEasy P128 -template class /*[[deprecated("Use NeoPixelBusLg instead.")]]*/ NeoPixelBrightnessBus : +template class NeoPixelBrightnessBus : public NeoPixelBus { private: void ScaleColor(uint16_t scale, typename T_COLOR_FEATURE::ColorObject* color) { - // This is the similiar as calling Dim on the color object - // there is an assumption that all color elements are byte aligned - // so if any future color object gets introduced that is not it will - // cause a problem uint8_t* ptr = (uint8_t*)color; uint8_t* ptrEnd = ptr + sizeof(typename T_COLOR_FEATURE::ColorObject); @@ -52,17 +47,12 @@ template class /*[[deprecated("Use void ConvertColor(typename T_COLOR_FEATURE::ColorObject* color) { - // This is the same as calling Dim on the color object uint16_t scale = _brightness + 1; ScaleColor(scale, color); } void RecoverColor(typename T_COLOR_FEATURE::ColorObject* color) const { - // this is the same as calling Brighton on the color object - // there is an assumption that all color elements are byte aligned - // so if any future color object gets introduced that is not it will - // cause a problem uint8_t* ptr = (uint8_t*)color; uint8_t* ptrEnd = ptr + sizeof(typename T_COLOR_FEATURE::ColorObject); uint16_t scale = _brightness + 1; @@ -93,12 +83,6 @@ template class /*[[deprecated("Use { } - NeoPixelBrightnessBus(uint16_t countPixels, uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint8_t pinOutputEnable = NOT_A_PIN) : - NeoPixelBus(countPixels, pinClock, pinData, pinLatch, pinOutputEnable), - _brightness(255) - { - } - NeoPixelBrightnessBus(uint16_t countPixels) : NeoPixelBus(countPixels), _brightness(255) diff --git a/lib/NeoPixelBus/src/NeoPixelBus.h b/lib/NeoPixelBus/src/NeoPixelBus.h index bf6344fd6a..d810e2a94b 100644 --- a/lib/NeoPixelBus/src/NeoPixelBus.h +++ b/lib/NeoPixelBus/src/NeoPixelBus.h @@ -27,20 +27,108 @@ License along with NeoPixel. If not, see #include -// standard neo definitions -// -const uint8_t NEO_DIRTY = 0x80; // a change was made to pixel data that requires a show -const uint16_t PixelIndex_OutOfBounds = 0xffff; +// some platforms do not come with STL or properly defined one, specifically functional +// if you see... +// undefined reference to `std::__throw_bad_function_call()' +// ...then you can either add the platform symbol to the list so NEOPIXEBUS_NO_STL gets defined or +// go to boards.txt and enable c++ by adding (teensy31.build.flags.libs=-lstdc++) and set to "smallest code" option in Arduino +// +#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(STM32L432xx) || defined(STM32L476xx) || defined(ARDUINO_ARCH_SAM) +#define NEOPIXEBUS_NO_STL 1 +#endif + +// some platforms do not define this standard progmem type for some reason +// +#ifndef PGM_VOID_P +#define PGM_VOID_P const void * +#endif + +// '_state' flags for internal state +#define NEO_DIRTY 0x80 // a change was made to pixel data that requires a show + +#include "internal/NeoHueBlend.h" -#include "internal/NeoUtil.h" -#include "internal/animations/NeoEase.h" #include "internal/NeoSettings.h" -#include "internal/NeoColors.h" + +#include "internal/RgbColor.h" +#include "internal/Rgb16Color.h" +#include "internal/Rgb48Color.h" + +#include "internal/HslColor.h" +#include "internal/HsbColor.h" +#include "internal/HtmlColor.h" + +#include "internal/RgbwColor.h" +#include "internal/SegmentDigit.h" + #include "internal/NeoColorFeatures.h" -#include "internal/NeoTopologies.h" -#include "internal/NeoBuffers.h" +#include "internal/NeoTm1814ColorFeatures.h" +#include "internal/NeoTm1914ColorFeatures.h" +#include "internal/DotStarColorFeatures.h" +#include "internal/Lpd8806ColorFeatures.h" +#include "internal/Lpd6803ColorFeatures.h" +#include "internal/P9813ColorFeatures.h" +#include "internal/NeoSegmentFeatures.h" + +#include "internal/Layouts.h" +#include "internal/NeoTopology.h" +#include "internal/NeoRingTopology.h" +#include "internal/NeoTiles.h" +#include "internal/NeoMosaic.h" + +#include "internal/NeoBufferContext.h" +#include "internal/NeoBufferMethods.h" +#include "internal/NeoBuffer.h" +#include "internal/NeoSpriteSheet.h" +#include "internal/NeoDib.h" +#include "internal/NeoBitmapFile.h" + +#include "internal/NeoEase.h" +#include "internal/NeoGamma.h" + #include "internal/NeoBusChannel.h" -#include "internal/NeoMethods.h" + +#include "internal/DotStarGenericMethod.h" +#include "internal/Lpd8806GenericMethod.h" +#include "internal/Lpd6803GenericMethod.h" +#include "internal/Ws2801GenericMethod.h" +#include "internal/P9813GenericMethod.h" + +#if defined(ARDUINO_ARCH_ESP8266) + +#include "internal/NeoEsp8266DmaMethod.h" +#include "internal/NeoEsp8266UartMethod.h" +#include "internal/NeoEspBitBangMethod.h" + +#elif defined(ARDUINO_ARCH_ESP32) +#if ESP_IDF_VERSION_MAJOR < 5 +#include "internal/NeoEsp32I2sMethod.h" +#include "internal/NeoEsp32RmtMethod.h" +#else +#if !defined(CONFIG_IDF_TARGET_ESP32C2) +#include "internal/NeoEsp32RmtMethod_idf5.h" // every other SOC +#else //CONFIG_IDF_TARGET_ESP32C2 +#include "internal/NeoEsp32SpiMethod_idf5.h" // ESP32C2 +#endif //CONFIG_IDF_TARGET_ESP32C2 +#endif // ESP_IDF_VERSION_MAJOR +#include "internal/NeoEspBitBangMethod.h" +#include "internal/DotStarEsp32DmaSpiMethod.h" + +#elif defined(ARDUINO_ARCH_NRF52840) // must be before __arm__ + +#include "internal/NeoNrf52xMethod.h" + +#elif defined(__arm__) // must be before ARDUINO_ARCH_AVR due to Teensy incorrectly having it set + +#include "internal/NeoArmMethod.h" + +#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) + +#include "internal/NeoAvrMethod.h" + +#else +#error "Platform Currently Not Supported, please add an Issue at Github/Makuna/NeoPixelBus" +#endif template class NeoPixelBus @@ -70,13 +158,6 @@ template class NeoPixelBus { } - NeoPixelBus(uint16_t countPixels, uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint8_t pinOutputEnable = NOT_A_PIN) : - _countPixels(countPixels), - _state(0), - _method(pinClock, pinData, pinLatch, pinOutputEnable, countPixels, T_COLOR_FEATURE::PixelSize, T_COLOR_FEATURE::SettingsSize) - { - } - NeoPixelBus(uint16_t countPixels) : _countPixels(countPixels), _state(0), @@ -114,16 +195,9 @@ template class NeoPixelBus ClearTo(0); } - // used by DotStarEsp32DmaSpiMethod if pins can be configured - reordered and extended version supporting oct SPI - void Begin(int8_t sck, int8_t dat0, int8_t dat1, int8_t dat2, int8_t dat3, int8_t dat4, int8_t dat5, int8_t dat6, int8_t dat7, int8_t ss) - { - _method.Initialize(sck, dat0, dat1, dat2, dat3, dat4, dat5, dat6, dat7, ss); - ClearTo(0); - } - void Show(bool maintainBufferConsistency = true) { - if (!IsDirty() && !_method.AlwaysUpdate()) + if (!IsDirty()) { return; } @@ -317,7 +391,7 @@ template class NeoPixelBus void SetPixelSettings(const typename T_COLOR_FEATURE::SettingsObject& settings) { - T_COLOR_FEATURE::applySettings(_method.getData(), _method.getDataSize(), settings); + T_COLOR_FEATURE::applySettings(_method.getData(), settings); Dirty(); }; @@ -349,13 +423,13 @@ template class NeoPixelBus uint8_t* _pixels() { // get pixels data within the data stream - return T_COLOR_FEATURE::pixels(_method.getData(), _method.getDataSize()); + return T_COLOR_FEATURE::pixels(_method.getData()); } const uint8_t* _pixels() const { // get pixels data within the data stream - return T_COLOR_FEATURE::pixels(_method.getData(), _method.getDataSize()); + return T_COLOR_FEATURE::pixels(_method.getData()); } void _rotateLeft(uint16_t rotationCount, uint16_t first, uint16_t last) diff --git a/lib/NeoPixelBus/src/NeoPixelBusLg.h b/lib/NeoPixelBus/src/NeoPixelBusLg.h deleted file mode 100644 index 9afaeee601..0000000000 --- a/lib/NeoPixelBus/src/NeoPixelBusLg.h +++ /dev/null @@ -1,197 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixelBus library wrapper template class that provides luminance and gamma control - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "NeoPixelBus.h" - -// -// -// T_GAMMA - -// NeoGammaEquationMethod -// NeoGammaCieLabEquationMethod -// NeoGammaTableMethod -// NeoGammaNullMethod -// NeoGammaInvert - -template class NeoPixelBusLg : - public NeoPixelBus -{ -public: - class LuminanceShader - { - public: - LuminanceShader(uint8_t luminance = 255) : - _luminance(luminance) - { - } - - // our shader is always dirty, but these are needed for standard - // shader support - bool IsDirty() const - { - return true; - }; - - void Dirty() - { - }; - - void ResetDirty() - { - }; - - typename T_COLOR_FEATURE::ColorObject Apply(uint16_t, const typename T_COLOR_FEATURE::ColorObject& original) - { - // dim and then return gamma adjusted - typename T_COLOR_FEATURE::ColorObject color = original.Dim(_luminance); - return NeoGamma::Correct(color); - } - - protected: - uint8_t _luminance; - - bool setLuminance(uint8_t luminance) - { - bool different = (_luminance != luminance); - - if (different) - { - _luminance = luminance; - } - - return different; - } - - uint8_t getLuminance() const - { - return _luminance; - } - - friend class NeoPixelBusLg; - }; - - // Exposed Shader instance for use with NeoDib.Render like - // - // image.Render(strip, strip.Shader); - // where MyBusType is defined like - // typedef NeoPixelBusLg MyBusType; - // - LuminanceShader Shader; - -public: - NeoPixelBusLg(uint16_t countPixels, uint8_t pin) : - NeoPixelBus(countPixels, pin), - Shader() - { - } - - NeoPixelBusLg(uint16_t countPixels, uint8_t pin, NeoBusChannel channel) : - NeoPixelBus(countPixels, pin, channel), - Shader() - { - } - - NeoPixelBusLg(uint16_t countPixels, uint8_t pinClock, uint8_t pinData) : - NeoPixelBus(countPixels, pinClock, pinData), - Shader() - { - } - - NeoPixelBusLg(uint16_t countPixels, uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint8_t pinOutputEnable = NOT_A_PIN) : - NeoPixelBus(countPixels, pinClock, pinData, pinLatch, pinOutputEnable), - Shader() - { - } - - NeoPixelBusLg(uint16_t countPixels) : - NeoPixelBus(countPixels), - Shader() - { - } - - ~NeoPixelBusLg() - { - } - - void SetLuminance(uint8_t luminance) - { - // does NOT affect current pixel data as there is no safe way - // to reconstruct the original color values after being - // modified with both luminance and gamma without storing them - if (Shader.setLuminance(luminance)) - { - this->Dirty(); - } - } - - uint8_t GetLuminance() const - { - return Shader.getLuminance(); - } - - void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) - { - color = Shader.Apply(indexPixel, color); - NeoPixelBus::SetPixelColor(indexPixel, color); - } - - /* - GetPixelColor is not overloaded as the original will be used - to just return the fully adjusted color value directly with - no reverse conversion since it is fraught with inaccuracy - */ - - void ClearTo(typename T_COLOR_FEATURE::ColorObject color) - { - color = Shader.Apply(0, color); - NeoPixelBus::ClearTo(color); - }; - - void ClearTo(typename T_COLOR_FEATURE::ColorObject color, uint16_t first, uint16_t last) - { - color = Shader.Apply(0, color); - NeoPixelBus::ClearTo(color, first, last); - } - - // if the Pixels buffer is manipulated directly, then this can be called - // to apply the luminance and gamma correction to those changes - void ApplyPostAdjustments() - { - if (this->IsDirty()) - { - for (uint16_t indexPixel = 0; indexPixel < NeoPixelBus::PixelCount(); indexPixel++) - { - typename T_COLOR_FEATURE::ColorObject color = NeoPixelBus::GetPixelColor(indexPixel); - color = Shader.Apply(indexPixel, color); - NeoPixelBus::SetPixelColor(indexPixel, color); - } - this->Dirty(); - } - } -}; - - diff --git a/lib/NeoPixelBus/src/internal/DotStarColorFeatures.h b/lib/NeoPixelBus/src/internal/DotStarColorFeatures.h new file mode 100644 index 0000000000..e0b8575732 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/DotStarColorFeatures.h @@ -0,0 +1,698 @@ +/*------------------------------------------------------------------------- +DotStarColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class when used with DotStars + +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 +. +-------------------------------------------------------------------------*/ +#pragma once + +class DotStar3Elements +{ +public: + static const size_t PixelSize = 4; // still requires 4 to be sent + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + *pPixelDest++ = pPixelSrc[2]; + *pPixelDest++ = pPixelSrc[3]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; +}; + +class DotStar4Elements +{ +public: + static const size_t PixelSize = 4; + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + *pPixelDest++ = pPixelSrc[2]; + *pPixelDest++ = pPixelSrc[3]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbwColor ColorObject; +}; + + +class DotStar3ElementsNoSettings : public DotStar3Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class DotStar4ElementsNoSettings : public DotStar4Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class DotStarBgrFeature : public DotStar3ElementsNoSettings +{ +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.G; + *p = color.R; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.B = *p++; + color.G = *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); + + p++; // ignore the first byte + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarLbgrFeature : public DotStar4ElementsNoSettings +{ +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.G; + *p = color.R; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = (*p++) & 0x1F; // mask out upper three bits + color.B = *p++; + color.G = *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.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarGrbFeature : public DotStar3ElementsNoSettings +{ +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.R; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.G = *p++; + color.R = *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); + + p++; // ignore the first byte + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarLgrbFeature : public DotStar4ElementsNoSettings +{ +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.R; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = (*p++) & 0x1F; // mask out upper three bits + color.G = *p++; + color.R = *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.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +/* RGB Feature -- Some APA102s ship in RGB order */ +class DotStarRgbFeature : public DotStar3ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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); + + 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 DotStar4ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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 DotStar3ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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); + + (void)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 DotStar4ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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 DotStar3ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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); + + 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 DotStar4ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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 DotStar3ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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); + + 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 DotStar4ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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; + } + +}; diff --git a/lib/NeoPixelBus/src/internal/DotStarEsp32DmaSpiMethod.h b/lib/NeoPixelBus/src/internal/DotStarEsp32DmaSpiMethod.h new file mode 100644 index 0000000000..953a216e74 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/DotStarEsp32DmaSpiMethod.h @@ -0,0 +1,356 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for DotStars using Esp32, DMA and SPI (APA102). + +Written by Michael C. Miller. +DotStarEsp32DmaSpiMethod written by Louis Beaudoin (Pixelvation) + +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 +. +-------------------------------------------------------------------------*/ + +#pragma once + +#include "driver/spi_master.h" + +#if (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6)) && !defined(HSPI_HOST) +// HSPI_HOST depreciated in C3 +#define HSPI_HOST SPI2_HOST +#endif + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +class Esp32VspiBus +{ +public: + const static spi_host_device_t SpiHostDevice = VSPI_HOST; + const static int DmaChannel = 1; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 1; +}; +#endif + +class Esp32HspiBus +{ +public: + const static spi_host_device_t SpiHostDevice = HSPI_HOST; + const static int DmaChannel = 2; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 1; +}; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +class Esp32Vspi2BitBus +{ +public: + const static spi_host_device_t SpiHostDevice = VSPI_HOST; + const static int DmaChannel = 1; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 2; +}; +#endif + +class Esp32Hspi2BitBus +{ +public: + const static spi_host_device_t SpiHostDevice = HSPI_HOST; + const static int DmaChannel = 2; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 2; +}; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +class Esp32Vspi4BitBus +{ +public: + const static spi_host_device_t SpiHostDevice = VSPI_HOST; + const static int DmaChannel = 1; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 4; +}; +#endif + +class Esp32Hspi4BitBus +{ +public: + const static spi_host_device_t SpiHostDevice = HSPI_HOST; + const static int DmaChannel = 2; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 4; +}; + +template class DotStarEsp32DmaSpiMethod +{ +public: + typedef typename T_SPISPEED::SettingsObject SettingsObject; + + DotStarEsp32DmaSpiMethod(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizePixelData(pixelCount * elementSize + settingsSize), + _sizeEndFrame((pixelCount + 15) / 16) // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes) + { + _spiBufferSize = _sizeStartFrame + _sizePixelData + _sizeEndFrame; + + // must have a 4 byte aligned buffer for i2s + uint32_t alignment = _spiBufferSize % 4; + if (alignment) + { + _spiBufferSize += 4 - alignment; + } + + _data = static_cast(malloc(_spiBufferSize)); + _dmadata = static_cast(heap_caps_malloc(_spiBufferSize, MALLOC_CAP_DMA)); + + // data cleared later in NeoPixelBus::Begin() + } + + // Support constructor specifying pins by ignoring pins + DotStarEsp32DmaSpiMethod(uint8_t, uint8_t, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + DotStarEsp32DmaSpiMethod(pixelCount, elementSize, settingsSize) + { + } + + ~DotStarEsp32DmaSpiMethod() + { + if (_spiHandle) + { + deinitSpiDevice(); + esp_err_t ret = spi_bus_free(T_SPIBUS::SpiHostDevice); + ESP_ERROR_CHECK(ret); + } + free(_data); + free(_dmadata); + _spiHandle = NULL; + } + + bool IsReadyToUpdate() const + { + spi_transaction_t t; + spi_transaction_t * tptr = &t; + esp_err_t ret = spi_device_get_trans_result(_spiHandle, &tptr, 0); + + // We know the previous transaction completed if we got ESP_OK, and we know there's no transactions queued if tptr is unmodified + return (ret == ESP_OK || tptr == &t); + } + + void Initialize(int8_t sck, int8_t dat0, int8_t dat1, int8_t dat2, int8_t dat3, int8_t ss) + { + memset(_data, 0x00, _sizeStartFrame); + memset(_data + _sizeStartFrame + _sizePixelData, 0x00, _spiBufferSize - (_sizeStartFrame + _sizePixelData)); + + _ssPin = ss; + + esp_err_t ret; + spi_bus_config_t buscfg; + memset(&buscfg, 0x00, sizeof(buscfg)); + + buscfg.miso_io_num = dat1; + buscfg.mosi_io_num = dat0; + buscfg.sclk_io_num = sck; + buscfg.quadwp_io_num = dat2; + buscfg.quadhd_io_num = dat3; + buscfg.max_transfer_sz = _spiBufferSize; + + //Initialize the SPI bus + ret = spi_bus_initialize(T_SPIBUS::SpiHostDevice, &buscfg, T_SPIBUS::DmaChannel); + ESP_ERROR_CHECK(ret); + + initSpiDevice(); + } + + void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) + { + Initialize(sck, mosi, miso, -1, -1, ss); + } + + // If pins aren't specified, initialize bus with just the default SCK and MOSI pins for the SPI peripheral (no SS, no >1-bit pins) + void Initialize() + { +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) + if (T_SPIBUS::SpiHostDevice == VSPI_HOST) + { + Initialize(SCK, -1, MOSI, -1, -1, -1); + } + else + { + Initialize(14, -1, 13, -1, -1, -1); + } +#else + Initialize(SCK, -1, MOSI, -1, -1, -1); +#endif + } + + void Update(bool) + { + while(!IsReadyToUpdate()); + + memcpy(_dmadata, _data, _spiBufferSize); + + memset(&_spiTransaction, 0, sizeof(spi_transaction_t)); + _spiTransaction.length = (_spiBufferSize) * 8; // in bits not bytes! + if (T_SPIBUS::ParallelBits == 1) + { + _spiTransaction.flags = 0; + } + if (T_SPIBUS::ParallelBits == 2) + { + _spiTransaction.flags = SPI_TRANS_MODE_DIO; + } + if (T_SPIBUS::ParallelBits == 4) + { + _spiTransaction.flags = SPI_TRANS_MODE_QIO; + } + _spiTransaction.tx_buffer = _dmadata; + + esp_err_t ret = spi_device_queue_trans(_spiHandle, &_spiTransaction, 0); //Transmit! + assert(ret == ESP_OK); //Should have had no issues. + } + + uint8_t* getData() const + { + return _data + _sizeStartFrame; + }; + + size_t getDataSize() const + { + return _sizePixelData; + }; + + void applySettings(const SettingsObject& settings) + { + _speed.applySettings(settings); + if (_spiHandle) + { + deinitSpiDevice(); + initSpiDevice(); + } + } + +private: + void initSpiDevice() + { + spi_device_interface_config_t devcfg = {}; + + devcfg.clock_speed_hz = _speed.Clock; + devcfg.mode = 0; //SPI mode 0 + devcfg.spics_io_num = _ssPin; //CS pin + devcfg.queue_size = 1; + if (T_SPIBUS::ParallelBits == 1) + { + devcfg.flags = 0; + } + if (T_SPIBUS::ParallelBits >= 2) + { + devcfg.flags = SPI_DEVICE_HALFDUPLEX; + } + + //Allocate the LEDs on the SPI bus + esp_err_t ret = spi_bus_add_device(T_SPIBUS::SpiHostDevice, &devcfg, &_spiHandle); + ESP_ERROR_CHECK(ret); + } + + void deinitSpiDevice() + { + while(!IsReadyToUpdate()); + esp_err_t ret = spi_bus_remove_device(_spiHandle); + ESP_ERROR_CHECK(ret); + } + + const size_t _sizeStartFrame = 4; + const size_t _sizePixelData; // Size of '_data' buffer below, minus (_sizeStartFrame + _sizeEndFrame) + const size_t _sizeEndFrame; + + size_t _spiBufferSize; + uint8_t* _data; // Holds start/end frames and LED color values + uint8_t* _dmadata; // Holds start/end frames and LED color values + spi_device_handle_t _spiHandle = NULL; + spi_transaction_t _spiTransaction; + T_SPISPEED _speed; + int8_t _ssPin; +}; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +// Clock Speed and Default Definitions for DotStarEsp32DmaVspi +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspiHzMethod; + +typedef DotStarEsp32DmaVspi10MhzMethod DotStarEsp32DmaVspiMethod; +#endif + +// Clock Speed and Default Definitions for DotStarEsp32DmaHspi +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspiHzMethod; + +typedef DotStarEsp32DmaHspi10MhzMethod DotStarEsp32DmaHspiMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +// Clock Speed and Default Definitions for DotStarEsp32DmaVspi2Bit +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2BitHzMethod; + +typedef DotStarEsp32DmaVspi2Bit10MhzMethod DotStarEsp32DmaVspi2BitMethod; +#endif + +// Clock Speed and Default Definitions for DotStarEsp32DmaHspi2Bit +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2BitHzMethod; + +typedef DotStarEsp32DmaHspi2Bit10MhzMethod DotStarEsp32DmaHspi2BitMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +// Clock Speed and Default Definitions for DotStarEsp32DmaVspi4Bit +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4BitHzMethod; + +typedef DotStarEsp32DmaVspi4Bit10MhzMethod DotStarEsp32DmaVspi4BitMethod; +#endif + +// Clock Speed and Default Definitions for DotStarEsp32DmaHspi4Bit +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4BitHzMethod; + +typedef DotStarEsp32DmaHspi4Bit10MhzMethod DotStarEsp32DmaHspi4BitMethod; diff --git a/lib/NeoPixelBus/src/internal/methods/DotStarGenericMethod.h b/lib/NeoPixelBus/src/internal/DotStarGenericMethod.h similarity index 87% rename from lib/NeoPixelBus/src/internal/methods/DotStarGenericMethod.h rename to lib/NeoPixelBus/src/internal/DotStarGenericMethod.h index 591ec6d0fb..81a4527ec6 100644 --- a/lib/NeoPixelBus/src/internal/methods/DotStarGenericMethod.h +++ b/lib/NeoPixelBus/src/internal/DotStarGenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -106,12 +104,6 @@ template class DotStarMethodBase _wire.endTransaction(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -122,7 +114,7 @@ template class DotStarMethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } @@ -153,26 +145,26 @@ typedef DotStarSpi10MhzMethod DotStarSpiMethod; #if defined(ARDUINO_ARCH_ESP32) // Give option to use Vspi alias of Spi class if wanting to specify which SPI peripheral is used on the ESP32 -typedef DotStarMethodBase> DotStarEsp32Vspi40MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi20MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi10MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi5MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi2MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi1MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi500KhzMethod; -typedef DotStarMethodBase> DotStarEsp32VspiHzMethod; +typedef DotStarMethodBase> DotStarVspi40MhzMethod; +typedef DotStarMethodBase> DotStarVspi20MhzMethod; +typedef DotStarMethodBase> DotStarVspi10MhzMethod; +typedef DotStarMethodBase> DotStarVspi5MhzMethod; +typedef DotStarMethodBase> DotStarVspi2MhzMethod; +typedef DotStarMethodBase> DotStarVspi1MhzMethod; +typedef DotStarMethodBase> DotStarVspi500KhzMethod; +typedef DotStarMethodBase> DotStarVspiHzMethod; -typedef DotStarSpi10MhzMethod DotStarEsp32VspiMethod; +typedef DotStarSpi10MhzMethod DotStarVspiMethod; #include "TwoWireHspiImple.h" -typedef DotStarMethodBase> DotStarEsp32Hspi40MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi20MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi10MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi5MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi2MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi1MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi500KhzMethod; -typedef DotStarMethodBase> DotStarEsp32HspiHzMethod; - -typedef DotStarEsp32Hspi10MhzMethod DotStarEsp32HspiMethod; +typedef DotStarMethodBase> DotStarHspi40MhzMethod; +typedef DotStarMethodBase> DotStarHspi20MhzMethod; +typedef DotStarMethodBase> DotStarHspi10MhzMethod; +typedef DotStarMethodBase> DotStarHspi5MhzMethod; +typedef DotStarMethodBase> DotStarHspi2MhzMethod; +typedef DotStarMethodBase> DotStarHspi1MhzMethod; +typedef DotStarMethodBase> DotStarHspi500KhzMethod; +typedef DotStarMethodBase> DotStarHspiHzMethod; + +typedef DotStarHspi10MhzMethod DotStarHspiMethod; #endif diff --git a/lib/NeoPixelBus/src/internal/Esp32_i2s.c b/lib/NeoPixelBus/src/internal/Esp32_i2s.c new file mode 100644 index 0000000000..5823b1875f --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Esp32_i2s.c @@ -0,0 +1,501 @@ +// 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 "sdkconfig.h" // this sets useful config symbols, like CONFIG_IDF_TARGET_ESP32C3 + +// ESP32C3/S3 I2S is not supported yet due to significant changes to interface +#ifndef CONFIG_SOC_RMT_TX_CANDIDATES_PER_GROUP // turn this off with something new from idf5.1 +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32C2) + +#include +#include +#include "stdlib.h" + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/queue.h" + + +#if ESP_IDF_VERSION_MAJOR>=4 +#include "esp_intr_alloc.h" +#else +#include "esp_intr.h" +#endif + +#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" +#if defined(CONFIG_IDF_TARGET_ESP32) +/* included here for ESP-IDF v4.x compatibility */ +#include "soc/dport_reg.h" +#endif +#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" + +#if ESP_IDF_VERSION_MAJOR<=4 +#define I2S_BASE_CLK (160000000L) +#endif + +#define ESP32_REG(addr) (*((volatile uint32_t*)(0x3FF00000+(addr)))) + +#define I2S_DMA_BLOCK_COUNT_DEFAULT 16 +// 24 bytes gives us enough time if we use single stage idle +// with the two stage idle we can use the minimum of 4 bytes +#define I2S_DMA_SILENCE_SIZE 4*1 +#define I2S_DMA_SILENCE_BLOCK_COUNT 3 // two front, one back +#define I2S_DMA_QUEUE_COUNT 2 + +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; + volatile uint32_t is_sending_data; +} i2s_bus_t; + +// is_sending_data values +#define I2s_Is_Idle 0 +#define I2s_Is_Pending 1 +#define I2s_Is_Sending 2 + +static uint8_t i2s_silence_buf[I2S_DMA_SILENCE_SIZE] = { 0 }; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// (I2S_NUM_MAX == 2) +static i2s_bus_t I2S[I2S_NUM_MAX] = { + {&I2S0, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_SIZE, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, 0, 0, I2s_Is_Idle}, + {&I2S1, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_SIZE, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, 0, 0, I2s_Is_Idle} +}; +#else +static i2s_bus_t I2S[I2S_NUM_MAX] = { + {&I2S0, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_SIZE, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, 0, 0, I2s_Is_Idle} +}; +#endif + +void IRAM_ATTR i2sDmaISR(void* arg); + +bool i2sInitDmaItems(uint8_t bus_num) { + if (bus_num >= I2S_NUM_MAX) { + return false; + } + if (I2S[bus_num].tx_queue) {// already set + return true; + } + + size_t dmaCount = I2S[bus_num].dma_count; + + if (I2S[bus_num].dma_items == NULL) { + I2S[bus_num].dma_items = (i2s_dma_item_t*)heap_caps_malloc(dmaCount * sizeof(i2s_dma_item_t), MALLOC_CAP_DMA); + if (I2S[bus_num].dma_items == NULL) { + log_e("MEM ERROR!"); + return false; + } + } + + int i, i2; + i2s_dma_item_t* item = NULL; + i2s_dma_item_t* itemPrev = NULL; + + for(i=0; i< dmaCount; i++) { + itemPrev = item; + + i2 = (i+1) % dmaCount; + item = &I2S[bus_num].dma_items[i]; + item->eof = 0; + 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; + item->buf = NULL; + } + itemPrev->eof = 1; + item->eof = 1; + + I2S[bus_num].tx_queue = xQueueCreate(I2S_DMA_QUEUE_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; +} + +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 >= I2S_NUM_MAX || div_a > 63 || div_b > 63 || bck > 63) { + return ESP_FAIL; + } + i2s_dev_t* i2s = I2S[bus_num].bus; + + typeof(i2s->clkm_conf) clkm_conf; + + clkm_conf.val = 0; +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + clkm_conf.clka_en = 0; +#else + clkm_conf.clk_sel = 2; +#endif + + clkm_conf.clkm_div_a = div_a; + clkm_conf.clkm_div_b = div_b; + clkm_conf.clkm_div_num = div_num; + i2s->clkm_conf.val = clkm_conf.val; + + typeof(i2s->sample_rate_conf) sample_rate_conf; + sample_rate_conf.val = 0; + sample_rate_conf.tx_bck_div_num = bck; + sample_rate_conf.rx_bck_div_num = bck; + sample_rate_conf.tx_bits_mod = bits; + sample_rate_conf.rx_bits_mod = bits; + i2s->sample_rate_conf.val = sample_rate_conf.val; + return ESP_OK; +} + +void i2sSetPins(uint8_t bus_num, int8_t out, bool invert) { + if (bus_num >= I2S_NUM_MAX) { + return; + } + + if (out >= 0) { + if (I2S[bus_num].out != out) { + if (I2S[bus_num].out >= 0) { + gpio_matrix_out(I2S[bus_num].out, 0x100, invert, false); + } + I2S[bus_num].out = out; + pinMode(out, OUTPUT); + + int i2sSignal; +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// (I2S_NUM_MAX == 2) + if (bus_num == 1) { + i2sSignal = I2S1O_DATA_OUT23_IDX; + } + else +#endif + { + i2sSignal = I2S0O_DATA_OUT23_IDX; + } + + gpio_matrix_out(out, i2sSignal, invert, false); + } + } else if (I2S[bus_num].out >= 0) { + gpio_matrix_out(I2S[bus_num].out, 0x100, invert, false); + I2S[bus_num].out = -1; + } + +} + +bool i2sWriteDone(uint8_t bus_num) { + if (bus_num >= I2S_NUM_MAX) { + return false; + } + + return (I2S[bus_num].is_sending_data == I2s_Is_Idle); +} + +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 >= I2S_NUM_MAX) { + return; + } + + I2S[bus_num].dma_count = dma_count + I2S_DMA_SILENCE_BLOCK_COUNT; // an extra two for looping silence + I2S[bus_num].dma_buf_len = dma_len & 0xFFF; + + if (!i2sInitDmaItems(bus_num)) { + return; + } + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// (I2S_NUM_MAX == 2) + if (bus_num) { + periph_module_enable(PERIPH_I2S1_MODULE); + } else +#endif + { + 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 + typeof(i2s->lc_conf) lc_conf; + lc_conf.val = 0; + lc_conf.out_eof_mode = 1; + i2s->lc_conf.val = lc_conf.val; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + i2s->pdm_conf.pcm2pdm_conv_en = 0; + i2s->pdm_conf.pdm2pcm_conv_en = 0; +#endif + // SET_PERI_REG_BITS(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, 0x1, RTC_CNTL_SOC_CLK_SEL_S); + + typeof(i2s->conf_chan) conf_chan; + conf_chan.val = 0; + conf_chan.tx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left + conf_chan.rx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left + i2s->conf_chan.val = conf_chan.val; + + typeof(i2s->fifo_conf) fifo_conf; + fifo_conf.val = 0; + fifo_conf.tx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel + fifo_conf.rx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel + i2s->fifo_conf.val = fifo_conf.val; + + typeof(i2s->conf) conf; + conf.val = 0; + conf.tx_msb_shift = (bits_per_sample != 8);// 0:DAC/PCM, 1:I2S + conf.tx_right_first = (bits_per_sample == 8); + i2s->conf.val = conf.val; + + typeof(i2s->conf2) conf2; + conf2.val = 0; + conf2.lcd_en = (bits_per_sample == 8); + i2s->conf2.val = conf2.val; + + i2s->fifo_conf.tx_fifo_mod_force_en = 1; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + i2s->pdm_conf.rx_pdm_en = 0; + i2s->pdm_conf.tx_pdm_en = 0; +#endif + + i2sSetSampleRate(bus_num, sample_rate, bits_per_sample); + + // enable intr in cpu // + int i2sIntSource; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// (I2S_NUM_MAX == 2) + if (bus_num == 1) { + i2sIntSource = ETS_I2S1_INTR_SOURCE; + } + else +#endif + { + i2sIntSource = ETS_I2S0_INTR_SOURCE; + } + + + esp_intr_alloc(i2sIntSource, 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 >= I2S_NUM_MAX) { + 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_bus_t* dev = (i2s_bus_t*)(arg); + + if (dev->bus->int_st.out_eof) + { + // i2s_dma_item_t* item = (i2s_dma_item_t*)(dev->bus->out_eof_des_addr); + if (dev->is_sending_data == I2s_Is_Pending) + { + dev->is_sending_data = I2s_Is_Idle; + } + else if (dev->is_sending_data == I2s_Is_Sending) + { + // loop the silent items + i2s_dma_item_t* itemSilence = &dev->dma_items[1]; + itemSilence->next = &dev->dma_items[0]; + + dev->is_sending_data = I2s_Is_Pending; + } + } + + dev->bus->int_clr.val = dev->bus->int_st.val; +} + +size_t i2sWrite(uint8_t bus_num, uint8_t* data, size_t len, bool copy, bool free_when_sent) { + if (bus_num >= I2S_NUM_MAX || !I2S[bus_num].tx_queue) { + return 0; + } + size_t blockSize = len; + + i2s_dma_item_t* item = &I2S[bus_num].dma_items[0]; + size_t dataLeft = len; + uint8_t* pos = data; + + // skip front two silent items + item += 2; + + while (dataLeft) { + + blockSize = dataLeft; + if (blockSize > I2S_DMA_MAX_DATA_LEN) { + blockSize = I2S_DMA_MAX_DATA_LEN; + } + dataLeft -= blockSize; + + // data is constant. no need to copy + item->data = pos; + item->blocksize = blockSize; + item->datalen = blockSize; + + item++; + + pos += blockSize; + } + + + // reset silence item to not loop + item = &I2S[bus_num].dma_items[1]; + item->next = &I2S[bus_num].dma_items[2]; + I2S[bus_num].is_sending_data = I2s_Is_Sending; + + + xQueueReset(I2S[bus_num].tx_queue); + xQueueSend(I2S[bus_num].tx_queue, (void*)&I2S[bus_num].dma_items[0], 10); + + return len; +} + +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) +#endif //ESP_IDF_VERSION_MAJOR < 5 +#endif // defined(ARDUINO_ARCH_ESP32) + diff --git a/lib/NeoPixelBus/src/internal/Esp32_i2s.h b/lib/NeoPixelBus/src/internal/Esp32_i2s.h new file mode 100644 index 0000000000..bfc024a8ce --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Esp32_i2s.h @@ -0,0 +1,45 @@ +#pragma once + +#include "sdkconfig.h" // this sets useful config symbols, like CONFIG_IDF_TARGET_ESP32C3 + +#ifndef CONFIG_SOC_RMT_TX_CANDIDATES_PER_GROUP // turn this off with something new from idf5.1 +// ESP32C3 I2S is not supported yet due to significant changes to interface +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) + +#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, bool invert); + +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); + +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 +#endif // ESP_IDF_VERSION_MAJOR < 5 diff --git a/lib/NeoPixelBus/src/internal/colors/HsbColor.cpp b/lib/NeoPixelBus/src/internal/HsbColor.cpp similarity index 96% rename from lib/NeoPixelBus/src/internal/colors/HsbColor.cpp rename to lib/NeoPixelBus/src/internal/HsbColor.cpp index b45f5113f7..146ddb84e0 100644 --- a/lib/NeoPixelBus/src/internal/colors/HsbColor.cpp +++ b/lib/NeoPixelBus/src/internal/HsbColor.cpp @@ -24,9 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HsbColor.h" diff --git a/lib/NeoPixelBus/src/internal/colors/HsbColor.h b/lib/NeoPixelBus/src/internal/HsbColor.h similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HsbColor.h rename to lib/NeoPixelBus/src/internal/HsbColor.h index bf9466bd6c..939d5a1003 100644 --- a/lib/NeoPixelBus/src/internal/colors/HsbColor.h +++ b/lib/NeoPixelBus/src/internal/HsbColor.h @@ -26,6 +26,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include + // ------------------------------------------------------------------------ // HsbColor represents a color object that is represented by Hue, Saturation, Brightness // component values. It contains helpful color routines to manipulate the diff --git a/lib/NeoPixelBus/src/internal/colors/HslColor.cpp b/lib/NeoPixelBus/src/internal/HslColor.cpp similarity index 96% rename from lib/NeoPixelBus/src/internal/colors/HslColor.cpp rename to lib/NeoPixelBus/src/internal/HslColor.cpp index bd6c3f43c2..92ae687516 100644 --- a/lib/NeoPixelBus/src/internal/colors/HslColor.cpp +++ b/lib/NeoPixelBus/src/internal/HslColor.cpp @@ -25,9 +25,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HslColor.h" diff --git a/lib/NeoPixelBus/src/internal/colors/HslColor.h b/lib/NeoPixelBus/src/internal/HslColor.h similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HslColor.h rename to lib/NeoPixelBus/src/internal/HslColor.h index 44f9061ef5..3555a5c068 100644 --- a/lib/NeoPixelBus/src/internal/colors/HslColor.h +++ b/lib/NeoPixelBus/src/internal/HslColor.h @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include + // ------------------------------------------------------------------------ // HslColor represents a color object that is represented by Hue, Saturation, Lightness // component values. It contains helpful color routines to manipulate the diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColor.cpp b/lib/NeoPixelBus/src/internal/HtmlColor.cpp similarity index 94% rename from lib/NeoPixelBus/src/internal/colors/HtmlColor.cpp rename to lib/NeoPixelBus/src/internal/HtmlColor.cpp index 9e9af5f90e..018d58f561 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColor.cpp +++ b/lib/NeoPixelBus/src/internal/HtmlColor.cpp @@ -23,11 +23,6 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ - -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" #include "HtmlColor.h" static inline char hexdigit(uint8_t v) diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColor.h b/lib/NeoPixelBus/src/internal/HtmlColor.h similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HtmlColor.h rename to lib/NeoPixelBus/src/internal/HtmlColor.h index 3e63421e1f..25329eb6ef 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColor.h +++ b/lib/NeoPixelBus/src/internal/HtmlColor.h @@ -25,6 +25,9 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include +#include "RgbColor.h" + #define MAX_HTML_COLOR_NAME_LEN 21 #ifndef pgm_read_ptr @@ -32,6 +35,10 @@ License along with NeoPixel. If not, see #define pgm_read_ptr(addr) (*reinterpret_cast(addr)) #endif +#ifndef countof +#define countof(array) (sizeof(array)/sizeof(array[0])) +#endif + // ------------------------------------------------------------------------ // HtmlColorPair represents an association between a name and a HTML color code // ------------------------------------------------------------------------ diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.cpp b/lib/NeoPixelBus/src/internal/HtmlColorNameStrings.cpp similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.cpp rename to lib/NeoPixelBus/src/internal/HtmlColorNameStrings.cpp index 6c71b33c2b..87dda4b3d8 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.cpp +++ b/lib/NeoPixelBus/src/internal/HtmlColorNameStrings.cpp @@ -24,7 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include #include "HtmlColorNameStrings.h" /* HTML4 color names */ diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.h b/lib/NeoPixelBus/src/internal/HtmlColorNameStrings.h similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.h rename to lib/NeoPixelBus/src/internal/HtmlColorNameStrings.h index dcd30c62d9..86ffcf4f23 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.h +++ b/lib/NeoPixelBus/src/internal/HtmlColorNameStrings.h @@ -26,6 +26,8 @@ License along with NeoPixel. If not, see #pragma once +#include + /* HTML4 color names */ extern const char c_HtmlNameAqua[] PROGMEM; extern const char c_HtmlNameBlack[] PROGMEM; diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColorNames.cpp b/lib/NeoPixelBus/src/internal/HtmlColorNames.cpp similarity index 98% rename from lib/NeoPixelBus/src/internal/colors/HtmlColorNames.cpp rename to lib/NeoPixelBus/src/internal/HtmlColorNames.cpp index ce6fd63011..b1098eaae4 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColorNames.cpp +++ b/lib/NeoPixelBus/src/internal/HtmlColorNames.cpp @@ -24,12 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ - -#include -#include "../NeoUtil.h" -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" #include "HtmlColor.h" #include "HtmlColorNameStrings.h" diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColorShortNames.cpp b/lib/NeoPixelBus/src/internal/HtmlColorShortNames.cpp similarity index 94% rename from lib/NeoPixelBus/src/internal/colors/HtmlColorShortNames.cpp rename to lib/NeoPixelBus/src/internal/HtmlColorShortNames.cpp index 14aaf268f3..3c4e27c3eb 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColorShortNames.cpp +++ b/lib/NeoPixelBus/src/internal/HtmlColorShortNames.cpp @@ -24,12 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ - -#include -#include "../NeoUtil.h" -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" #include "HtmlColor.h" #include "HtmlColorNameStrings.h" diff --git a/lib/NeoPixelBus/src/internal/Layouts.h b/lib/NeoPixelBus/src/internal/Layouts.h new file mode 100644 index 0000000000..5b1016ea99 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Layouts.h @@ -0,0 +1,426 @@ +#pragma once +/*------------------------------------------------------------------------- +Layout provides a collection of class objects that are used with NeoTopology +object. +They define the specific layout of pixels and do the math to change the 2d +cordinate space to 1d cordinate space + +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 +. +-------------------------------------------------------------------------*/ + +const uint16_t PixelIndex_OutOfBounds = 0xffff; + +//----------------------------------------------------------------------------- +// RowMajor +//----------------------------------------------------------------------------- + +class RowMajorLayout; +class RowMajor90Layout; +class RowMajor180Layout; +class RowMajor270Layout; + +class RowMajorTilePreference +{ +public: + typedef RowMajorLayout EvenRowEvenColumnLayout; + typedef RowMajor270Layout EvenRowOddColumnLayout; + typedef RowMajor90Layout OddRowEvenColumnLayout; + typedef RowMajor180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 01 02 03 +// 04 05 06 07 +// 08 09 10 11 +// 12 13 14 15 +// +class RowMajorLayout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + return x + y * width; + } +}; + +// layout example of 4x4 +// 12 08 04 00 +// 13 09 05 01 +// 14 10 06 02 +// 15 11 07 03 +// +class RowMajor90Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) * height + y; + } +}; + +// layout example of 4x4 +// 15 14 13 12 +// 11 10 09 08 +// 07 06 05 04 +// 03 02 01 00 +// +class RowMajor180Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) + (height - 1 - y) * width; + } +}; + +// layout example of 4x4 +// 03 07 11 15 +// 02 06 10 14 +// 01 05 09 13 +// 00 04 08 12 +// +class RowMajor270Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + return x * height + (height - 1 - y); + } +}; + + +//----------------------------------------------------------------------------- +// ColumnMajor +//----------------------------------------------------------------------------- + +class ColumnMajorLayout; +class ColumnMajor90Layout; +class ColumnMajor180Layout; +class ColumnMajor270Layout; + +class ColumnMajorTilePreference +{ +public: + typedef ColumnMajorLayout EvenRowEvenColumnLayout; + typedef ColumnMajor270Layout EvenRowOddColumnLayout; + typedef ColumnMajor90Layout OddRowEvenColumnLayout; + typedef ColumnMajor180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 04 08 12 +// 01 05 09 13 +// 02 06 10 14 +// 03 07 11 15 +// +class ColumnMajorLayout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + return x * height + y; + } +}; + +// layout example of 4x4 +// 03 02 01 00 +// 07 06 05 04 +// 11 10 09 08 +// 15 14 13 12 +// +class ColumnMajor90Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + return (width - 1 - x) + y * width; + } +}; + +// layout example of 4x4 +// 15 11 07 03 +// 14 10 06 02 +// 13 09 05 01 +// 12 08 04 00 +// +class ColumnMajor180Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) * height + (height - 1 - y); + } +}; + +// layout example of 4x4 +// 12 13 14 15 +// 08 09 10 11 +// 04 05 06 07 +// 00 01 02 03 +// +class ColumnMajor270Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return x + (height - 1 - y) * width; + } +}; + + +//----------------------------------------------------------------------------- +// RowMajorAlternating +//----------------------------------------------------------------------------- + +class RowMajorAlternating270Layout; +class RowMajorAlternating90Layout; + +class RowMajorAlternatingTilePreference +{ +public: + typedef RowMajorAlternating270Layout EvenRowEvenColumnLayout; + typedef RowMajorAlternating270Layout EvenRowOddColumnLayout; + typedef RowMajorAlternating90Layout OddRowEvenColumnLayout; + typedef RowMajorAlternating90Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 01 02 03 +// 07 06 05 04 +// 08 09 10 11 +// 15 14 13 12 +// +class RowMajorAlternatingLayout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + uint16_t index = y * width; + + if (y & 0x0001) + { + index += ((width - 1) - x); + } + else + { + index += x; + } + return index; + } +}; + +// layout example of 4x4 +// 15 08 07 00 +// 14 09 06 01 +// 13 10 05 02 +// 12 11 04 03 +// +class RowMajorAlternating90Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t mx = ((width - 1) - x); + uint16_t index = mx * height; + + if (mx & 0x0001) + { + index += ((height - 1) - y); + } + else + { + index += y; + } + return index; + } +}; + +// layout example of 4x4 +// 12 13 14 15 +// 11 10 09 08 +// 04 05 06 07 +// 03 02 01 00 +// +class RowMajorAlternating180Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t my = ((height - 1) - y); + uint16_t index = my * width; + + if (my & 0x0001) + { + index += x; + } + else + { + index += ((width - 1) - x); + } + return index; + } +}; + +// layout example of 4x4 +// 03 04 11 12 +// 02 05 10 13 +// 01 06 09 14 +// 00 07 08 15 +// +class RowMajorAlternating270Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t index = x * height; + + if (x & 0x0001) + { + index += y; + } + else + { + index += ((height - 1) - y); + } + return index; + } +}; + + +//----------------------------------------------------------------------------- +// ColumnMajorAlternating +//----------------------------------------------------------------------------- + +class ColumnMajorAlternatingLayout; +class ColumnMajorAlternating180Layout; + +class ColumnMajorAlternatingTilePreference +{ +public: + typedef ColumnMajorAlternatingLayout EvenRowEvenColumnLayout; + typedef ColumnMajorAlternatingLayout EvenRowOddColumnLayout; + typedef ColumnMajorAlternating180Layout OddRowEvenColumnLayout; + typedef ColumnMajorAlternating180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 07 08 15 +// 01 06 09 14 +// 02 05 10 13 +// 03 04 11 12 +// +class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t index = x * height; + + if (x & 0x0001) + { + index += ((height - 1) - y); + } + else + { + index += y; + } + return index; + } +}; + +// layout example of 4x4 +// 03 02 01 00 +// 04 05 06 07 +// 11 10 09 08 +// 12 13 14 15 +// +class ColumnMajorAlternating90Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + uint16_t index = y * width; + + if (y & 0x0001) + { + index += x; + } + else + { + index += ((width - 1) - x); + } + return index; + } +}; + +// layout example of 4x4 +// 12 11 04 03 +// 13 10 05 02 +// 14 09 06 01 +// 15 08 07 00 +// +class ColumnMajorAlternating180Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t mx = ((width - 1) - x); + uint16_t index = mx * height; + + if (mx & 0x0001) + { + index += y; + } + else + { + index += ((height - 1) - y); + } + return index; + } +}; + +// layout example of 4x4 +// 15 14 13 12 +// 08 09 10 11 +// 07 06 05 04 +// 00 01 02 03 +// +class ColumnMajorAlternating270Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t my = ((height - 1) - y); + uint16_t index = my * width; + + if (my & 0x0001) + { + index += ((width - 1) - x); + } + else + { + index += x; + } + return index; + } +}; diff --git a/lib/NeoPixelBus/src/internal/Lpd6803ColorFeatures.h b/lib/NeoPixelBus/src/internal/Lpd6803ColorFeatures.h new file mode 100644 index 0000000000..709935073f --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Lpd6803ColorFeatures.h @@ -0,0 +1,301 @@ +/*------------------------------------------------------------------------- +Lpd6803ColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class when used with DotStar like chips + +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 +. +-------------------------------------------------------------------------*/ +#pragma once + +class Lpd68033ElementsNoSettings +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class Lpd68033Elements : public Lpd68033ElementsNoSettings +{ +public: + static const size_t PixelSize = 2; // 1 bit + 555 encoded elements + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; + +protected: + static void encodePixel(uint8_t c1, uint8_t c2, uint8_t c3, uint16_t* color555) + { + *color555 = (0x8000 | + ((c1 & 0xf8) << 7) | + ((c2 & 0xf8) << 2) | + ((c3 & 0xf8) >> 3)); + } + + static void decodePixel(uint16_t color555, uint8_t* c1, uint8_t* c2, uint8_t* c3) + { + *c1 = (color555 >> 7) & 0xf8; + *c2 = (color555 >> 2) & 0xf8; + *c3 = (color555 << 3) & 0xf8; + } +}; + +class Lpd6803BrgFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.B, color.R, color.G, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.B, &color.R, &color.G); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.B, &color.R, &color.G); + + return color; + } +}; + +class Lpd6803GrbFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.G, color.R, color.B, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.G, &color.R, &color.B); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.G, &color.R, &color.B); + + return color; + } +}; + +class Lpd6803GbrFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.G, color.B, color.R, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.G, &color.B, &color.R); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.G, &color.B, &color.R); + + return color; + } +}; + + +class Lpd6803RgbFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.R, color.G, color.B, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.R, &color.G, &color.B); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.R, &color.G, &color.B); + + return color; + } +}; + diff --git a/lib/NeoPixelBus/src/internal/methods/Lpd6803GenericMethod.h b/lib/NeoPixelBus/src/internal/Lpd6803GenericMethod.h similarity index 94% rename from lib/NeoPixelBus/src/internal/methods/Lpd6803GenericMethod.h rename to lib/NeoPixelBus/src/internal/Lpd6803GenericMethod.h index 9807db8f1b..ecb7e49732 100644 --- a/lib/NeoPixelBus/src/internal/methods/Lpd6803GenericMethod.h +++ b/lib/NeoPixelBus/src/internal/Lpd6803GenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -102,12 +100,6 @@ template class Lpd6803MethodBase _wire.endTransaction(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -118,7 +110,7 @@ template class Lpd6803MethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/Lpd8806ColorFeatures.h b/lib/NeoPixelBus/src/internal/Lpd8806ColorFeatures.h new file mode 100644 index 0000000000..6ffb4d0d9b --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Lpd8806ColorFeatures.h @@ -0,0 +1,189 @@ +/*------------------------------------------------------------------------- +Lpd8806ColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class when used with DotStar like chips + +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 +. +-------------------------------------------------------------------------*/ +#pragma once + +class Lpd88063ElementsNoSettings +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class Lpd88063Elements : public Lpd88063ElementsNoSettings +{ +public: + static const size_t PixelSize = 3; + + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + *pPixelDest++ = pPixelSrc[2]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; +}; + +class Lpd8806BrgFeature : public Lpd88063Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = (color.B >> 1) | 0x80; + *p++ = (color.R >> 1) | 0x80; + *p = (color.G >> 1) | 0x80; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.B = (*p++) << 1; + color.R = (*p++) << 1; + color.G = (*p) << 1; + + 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.B = (pgm_read_byte(p++)) << 1; + color.R = (pgm_read_byte(p++)) << 1; + color.G = (pgm_read_byte(p)) << 1; + + return color; + } + +}; + +class Lpd8806GrbFeature : public Lpd88063Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = (color.G >> 1) | 0x80; + *p++ = (color.R >> 1) | 0x80; + *p = (color.B >> 1) | 0x80; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.G = (*p++) << 1; + color.R = (*p++) << 1; + color.B = (*p) << 1; + + 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.G = (pgm_read_byte(p++)) << 1; + color.R = (pgm_read_byte(p++)) << 1; + color.B = (pgm_read_byte(p)) << 1; + + return color; + } + +}; + diff --git a/lib/NeoPixelBus/src/internal/methods/Lpd8806GenericMethod.h b/lib/NeoPixelBus/src/internal/Lpd8806GenericMethod.h similarity index 94% rename from lib/NeoPixelBus/src/internal/methods/Lpd8806GenericMethod.h rename to lib/NeoPixelBus/src/internal/Lpd8806GenericMethod.h index e33555707d..c2372f21a1 100644 --- a/lib/NeoPixelBus/src/internal/methods/Lpd8806GenericMethod.h +++ b/lib/NeoPixelBus/src/internal/Lpd8806GenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -102,12 +100,6 @@ template class Lpd8806MethodBase _wire.endTransaction(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -118,7 +110,7 @@ template class Lpd8806MethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/methods/NeoArmMethod.h b/lib/NeoPixelBus/src/internal/NeoArmMethod.h similarity index 99% rename from lib/NeoPixelBus/src/internal/methods/NeoArmMethod.h rename to lib/NeoPixelBus/src/internal/NeoArmMethod.h index 2f23000566..ef1f7cf698 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoArmMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoArmMethod.h @@ -30,8 +30,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #if defined(__arm__) && !defined(ARDUINO_ARCH_NRF52840) template class NeoArmMethodBase @@ -93,12 +91,6 @@ template class NeoArmMethodBase _endTime = micros(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -109,7 +101,7 @@ template class NeoArmMethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -857,7 +849,6 @@ typedef NeoArmTm1814InvertedMethod NeoArmTm1914InvertedMethod; typedef NeoArmWs2812xMethod NeoWs2813Method; typedef NeoArmWs2812xMethod NeoWs2812xMethod; typedef NeoArmWs2812xMethod NeoWs2811Method; -typedef NeoArmWs2812xMethod NeoWs2816Method; typedef NeoArmSk6812Method NeoSk6812Method; typedef NeoArmSk6812Method NeoLc8812Method; typedef NeoArm800KbpsMethod NeoWs2812Method; diff --git a/lib/NeoPixelBus/src/internal/methods/NeoAvrMethod.h b/lib/NeoPixelBus/src/internal/NeoAvrMethod.h similarity index 63% rename from lib/NeoPixelBus/src/internal/methods/NeoAvrMethod.h rename to lib/NeoPixelBus/src/internal/NeoAvrMethod.h index 8e250347ce..685ab56ef6 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoAvrMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoAvrMethod.h @@ -27,8 +27,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) extern "C" @@ -41,8 +39,6 @@ extern "C" void send_data_12mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); void send_data_16mhz_800(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); void send_data_16mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); - void send_data_16mhz_600(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); - void send_data_32mhz(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask, const uint8_t cycleTiming); } class NeoAvrSpeed800KbpsBase @@ -66,10 +62,8 @@ class NeoAvrSpeed800KbpsBase #endif // PORTD send_data_12mhz_800_PortB(data, sizeData, pinMask); -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000UL) // 16Mhz CPU +#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU send_data_16mhz_800(data, sizeData, port, pinMask); -#elif (F_CPU >= 31000000UL) && (F_CPU <= 35000000UL) // 32Mhz CPU - send_data_32mhz(data, sizeData, port, pinMask, 3); #else #error "CPU SPEED NOT SUPPORTED" #endif @@ -77,38 +71,6 @@ class NeoAvrSpeed800KbpsBase }; -class NeoAvrSpeed600KbpsBase -{ -public: - static void send_data(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) - { -#if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) // 8Mhz CPU -#ifdef PORTD // PORTD isn't present on ATtiny85, etc. - if (port == &PORTD) - send_data_8mhz_800_PortD(data, sizeData, pinMask); - else if (port == &PORTB) -#endif // PORTD - send_data_8mhz_800_PortB(data, sizeData, pinMask); - -#elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) // 12Mhz CPU -#ifdef PORTD // PORTD - if (port == &PORTD) - send_data_12mhz_800_PortD(data, sizeData, pinMask); - else if (port == &PORTB) -#endif // PORTD - send_data_12mhz_800_PortB(data, sizeData, pinMask); - -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000UL) // 16Mhz CPU - send_data_16mhz_600(data, sizeData, port, pinMask); -#elif (F_CPU >= 31000000UL) && (F_CPU <= 35000000UL) // 32Mhz CPU - send_data_32mhz(data, sizeData, port, pinMask, 3); -#else -#error "CPU SPEED NOT SUPPORTED" -#endif - } - -}; - class NeoAvrSpeedWs2812x : public NeoAvrSpeed800KbpsBase { public: @@ -121,19 +83,6 @@ class NeoAvrSpeedSk6812 : public NeoAvrSpeed800KbpsBase static const uint32_t ResetTimeUs = 80; }; -class NeoAvrSpeedApa106 : public NeoAvrSpeed600KbpsBase -{ -public: - static const uint32_t ResetTimeUs = 100; -}; - -class NeoAvrSpeed600KbpsIps : public NeoAvrSpeed600KbpsBase -{ -public: - static const uint32_t ResetTimeUs = 300; - static const uint16_t InterpixelTimeUs = 8; // 12.4, with loop overhead of about 5us for loop -}; - class NeoAvrSpeedTm1814 : public NeoAvrSpeed800KbpsBase { public: @@ -163,10 +112,8 @@ class NeoAvrSpeed400Kbps #elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) // 12Mhz CPU send_data_12mhz_400(data, sizeData, port, pinMask); -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000UL) // 16Mhz CPU +#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU send_data_16mhz_400(data, sizeData, port, pinMask); -#elif (F_CPU >= 31000000UL) && (F_CPU <= 35000000UL) // 32Mhz CPU - send_data_32mhz(data, sizeData, port, pinMask, 7); #else #error "CPU SPEED NOT SUPPORTED" #endif @@ -240,12 +187,6 @@ template class NeoAvrMethodBase _endTime = micros(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -256,11 +197,11 @@ template class NeoAvrMethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } -protected: +private: const size_t _sizeData; // size of _data below const uint8_t _pin; // output pin number @@ -271,64 +212,9 @@ template class NeoAvrMethodBase uint8_t _pinMask; // Output PORT bitmask }; -template class NeoAvrIpsMethodBase : public NeoAvrMethodBase -{ -public: - NeoAvrIpsMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - NeoAvrMethodBase(pin, pixelCount, elementSize, settingsSize), - _elementSize(elementSize) - { - } - - ~NeoAvrIpsMethodBase() - { - } - - 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 - // 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 (!NeoAvrMethodBase::IsReadyToUpdate()) - { -#if !defined(ARDUINO_TEEONARDU_LEO) && !defined(ARDUINO_TEEONARDU_FLORA) - yield(); // allows for system yield if needed -#endif - } - - noInterrupts(); // Need 100% focus on instruction timing - - uint8_t* dataPixel = NeoAvrMethodBase::_data; - const uint8_t* dataEnd = dataPixel + NeoAvrMethodBase::_sizeData; - - while (dataPixel < dataEnd) - { - T_SPEED::send_data(dataPixel, - _elementSize, - NeoAvrMethodBase::_port, - NeoAvrMethodBase::_pinMask); - dataPixel += _elementSize; - delayMicroseconds(T_SPEED::InterpixelTimeUs); - } - - interrupts(); - - // save EOD time for latch on next call - NeoAvrMethodBase::_endTime = micros(); - } - -private: - const size_t _elementSize; // size of a single pixel -}; typedef NeoAvrMethodBase NeoAvrWs2812xMethod; typedef NeoAvrMethodBase NeoAvrSk6812Method; -typedef NeoAvrMethodBase NeoAvrApa106Method; -typedef NeoAvrIpsMethodBase NeoAvr600KbpsIpsMethod; - typedef NeoAvrMethodBase NeoAvrTm1814InvertedMethod; typedef NeoAvrMethodBase NeoAvrTm1829InvertedMethod; typedef NeoAvrMethodBase NeoAvr800KbpsMethod; @@ -340,10 +226,9 @@ typedef NeoAvrWs2812xMethod NeoWs2813Method; typedef NeoAvrWs2812xMethod NeoWs2812xMethod; typedef NeoAvr800KbpsMethod NeoWs2812Method; typedef NeoAvrWs2812xMethod NeoWs2811Method; -typedef NeoAvrWs2812xMethod NeoWs2816Method; typedef NeoAvrSk6812Method NeoSk6812Method; typedef NeoAvrSk6812Method NeoLc8812Method; -typedef NeoAvrApa106Method NeoApa106Method; +typedef NeoAvr400KbpsMethod NeoApa106Method; typedef NeoAvrWs2812xMethod Neo800KbpsMethod; typedef NeoAvr400KbpsMethod Neo400KbpsMethod; diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBitmapFile.h b/lib/NeoPixelBus/src/internal/NeoBitmapFile.h similarity index 98% rename from lib/NeoPixelBus/src/internal/buffers/NeoBitmapFile.h rename to lib/NeoPixelBus/src/internal/NeoBitmapFile.h index d66316a811..467d55d1c5 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBitmapFile.h +++ b/lib/NeoPixelBus/src/internal/NeoBitmapFile.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoBitmapFile +NeoPixel library Written by Michael C. Miller. @@ -67,9 +67,6 @@ enum BmpCompression BI_CmykRle4 }; -// T_COLOR_FEATURE - one of the Features -// T_FILE_METHOD - any standard File object following Arduino File methods/members -// template class NeoBitmapFile { public: diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBuffer.h b/lib/NeoPixelBus/src/internal/NeoBuffer.h similarity index 87% rename from lib/NeoPixelBus/src/internal/buffers/NeoBuffer.h rename to lib/NeoPixelBus/src/internal/NeoBuffer.h index fa18994fb6..d904e87146 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBuffer.h +++ b/lib/NeoPixelBus/src/internal/NeoBuffer.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoBuffer +NeoPixel library Written by Michael C. Miller. @@ -25,24 +25,16 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -// T_BUFFER_METHOD - one of -// NeoBufferMethod -// NeoBufferProgmemMethod -// template class NeoBuffer { public: NeoBuffer(uint16_t width, uint16_t height, - PGM_VOID_P pixels = nullptr) : + PGM_VOID_P pixels) : _method(width, height, pixels) { } - ~NeoBuffer() - { - } - operator NeoBufferContext() { return _method; @@ -68,14 +60,14 @@ template class NeoBuffer int16_t y, typename T_BUFFER_METHOD::ColorObject color) { - _method.SetPixelColor(PixelIndex(x, y), color); + _method.SetPixelColor(pixelIndex(x, y), color); }; typename T_BUFFER_METHOD::ColorObject GetPixelColor( int16_t x, int16_t y) const { - return _method.GetPixelColor(PixelIndex(x, y)); + return _method.GetPixelColor(pixelIndex(x, y)); }; void ClearTo(typename T_BUFFER_METHOD::ColorObject color) @@ -124,7 +116,7 @@ template class NeoBuffer if (indexDest < destPixelCount) { - const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), PixelIndex(xSrc + x, ySrc + y)); + const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), pixelIndex(xSrc + x, ySrc + y)); uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexDest); _method.CopyPixels(pDest, pSrc, 1); @@ -152,14 +144,18 @@ template class NeoBuffer for (uint16_t indexPixel = 0; indexPixel < countPixels; indexPixel++) { - const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), indexPixel); - uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexPixel); + typename T_BUFFER_METHOD::ColorObject color; + + shader.Apply(indexPixel, (uint8_t*)(&color), _method.Pixels() + (indexPixel * _method.PixelSize())); - shader.Apply(indexPixel, pDest, pSrc); + T_BUFFER_METHOD::ColorFeature::applyPixelColor(destBuffer.Pixels, indexPixel, color); } } - uint16_t PixelIndex( +private: + T_BUFFER_METHOD _method; + + uint16_t pixelIndex( int16_t x, int16_t y) const { @@ -174,7 +170,4 @@ template class NeoBuffer } return result; } - -private: - T_BUFFER_METHOD _method; }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBufferContext.h b/lib/NeoPixelBus/src/internal/NeoBufferContext.h similarity index 98% rename from lib/NeoPixelBus/src/internal/buffers/NeoBufferContext.h rename to lib/NeoPixelBus/src/internal/NeoBufferContext.h index d1cb0b8154..8b57344961 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBufferContext.h +++ b/lib/NeoPixelBus/src/internal/NeoBufferContext.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoBufferContext +NeoPixel library Written by Michael C. Miller. diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBufferMethods.h b/lib/NeoPixelBus/src/internal/NeoBufferMethods.h similarity index 60% rename from lib/NeoPixelBus/src/internal/buffers/NeoBufferMethods.h rename to lib/NeoPixelBus/src/internal/NeoBufferMethods.h index af97805263..79d354f57d 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBufferMethods.h +++ b/lib/NeoPixelBus/src/internal/NeoBufferMethods.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoBufferMethod +NeoPixel library Written by Michael C. Miller. @@ -26,10 +26,24 @@ License along with NeoPixel. If not, see #pragma once + +#if defined(NEOPIXEBUS_NO_STL) + +typedef uint16_t(*LayoutMapCallback)(int16_t x, int16_t y); + +#else + +#undef max +#undef min +#include +typedef std::function LayoutMapCallback; + +#endif + template class NeoBufferMethod { public: - NeoBufferMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels = nullptr) : + NeoBufferMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels = NULL) : _width(width), _height(height) { @@ -44,7 +58,6 @@ template class NeoBufferMethod ~NeoBufferMethod() { free(_pixels); - _pixels = nullptr; } operator NeoBufferContext() @@ -149,5 +162,102 @@ template class NeoBufferMethod uint8_t* _pixels; }; +template class NeoBufferProgmemMethod +{ +public: + NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) : + _width(width), + _height(height), + _pixels(pixels) + { + } + + operator NeoBufferContext() + { + return NeoBufferContext(Pixels(), PixelsSize()); + } + + uint8_t* Pixels() const + { + return (uint8_t*)_pixels; + }; + + size_t PixelsSize() const + { + return PixelSize() * PixelCount(); + }; + + size_t PixelSize() const + { + return T_COLOR_FEATURE::PixelSize; + }; + + uint16_t PixelCount() const + { + return _width * _height; + }; + + uint16_t Width() const + { + return _width; + }; + + uint16_t Height() const + { + return _height; + }; + + void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + + void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const + { + if (indexPixel >= PixelCount()) + { + // Pixel # is out of bounds, this will get converted to a + // color object type initialized to 0 (black) + return 0; + } + + return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); + }; + + typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const + { + if (x < 0 || x >= _width || y < 0 || y >= _height) + { + // Pixel # is out of bounds, this will get converted to a + // color object type initialized to 0 (black) + return 0; + } + + uint16_t indexPixel = x + y * _width; + return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); + }; + + void ClearTo(typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + + void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + T_COLOR_FEATURE::movePixelsInc_P(pPixelDest, pPixelSrc, count); + } + + typedef typename T_COLOR_FEATURE::ColorObject ColorObject; + typedef T_COLOR_FEATURE ColorFeature; + +private: + const uint16_t _width; + const uint16_t _height; + PGM_VOID_P _pixels; +}; diff --git a/lib/NeoPixelBus/src/internal/NeoBuffers.h b/lib/NeoPixelBus/src/internal/NeoBuffers.h deleted file mode 100644 index a3eacc4952..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoBuffers.h +++ /dev/null @@ -1,40 +0,0 @@ -/*------------------------------------------------------------------------- -NeoBuffers includes all the classes that describe pixel buffers - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -#include "buffers/LayoutMapCallback.h" -#include "buffers/NeoShaderNop.h" -#include "buffers/NeoShaderBase.h" -#include "buffers/NeoBufferContext.h" - -#include "buffers/NeoBuffer.h" -#include "buffers/NeoBufferMethods.h" -#include "buffers/NeoBufferProgmemMethod.h" - -#include "buffers/NeoDib.h" -#include "buffers/NeoBitmapFile.h" -#include "buffers/NeoVerticalSpriteSheet.h" - diff --git a/lib/NeoPixelBus/src/internal/NeoBusChannel.h b/lib/NeoPixelBus/src/internal/NeoBusChannel.h index ea3ef515b6..5fdb131bf3 100644 --- a/lib/NeoPixelBus/src/internal/NeoBusChannel.h +++ b/lib/NeoPixelBus/src/internal/NeoBusChannel.h @@ -5,7 +5,6 @@ // ESP32 - 8 TX channels // ESP32S2 - 4 TX channels // ESP32C3 - 2 TX channels -// ESP32S3 - 4 TX channels // NRF52840 - 3 or 4 channels (some variants only have 3) enum NeoBusChannel @@ -13,7 +12,7 @@ enum NeoBusChannel NeoBusChannel_0, NeoBusChannel_1, -#if !defined(CONFIG_IDF_TARGET_ESP32C3) +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) NeoBusChannel_2, @@ -29,14 +28,14 @@ enum NeoBusChannel NeoBusChannel_3, -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) NeoBusChannel_4, NeoBusChannel_5, NeoBusChannel_6, NeoBusChannel_7, -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) -#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) #endif // ARDUINO_ARCH_ESP32 diff --git a/lib/NeoPixelBus/src/internal/NeoColorFeatures.h b/lib/NeoPixelBus/src/internal/NeoColorFeatures.h index b33a170bb0..d1494a278e 100644 --- a/lib/NeoPixelBus/src/internal/NeoColorFeatures.h +++ b/lib/NeoPixelBus/src/internal/NeoColorFeatures.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoColorFeatures includes all the feature classes that describe color order and +NeoColorFeatures provides feature classes to describe color order and color depth for NeoPixelBus template class Written by Michael C. Miller. @@ -26,52 +26,402 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -// Core Element base classes -// -#include "features/NeoElementsNoSettings.h" -#include "features/NeoByteElements.h" - -// Core Feature base classes -#include "features/Neo2Byte555Feature.h" -#include "features/Neo3ByteFeature.h" -#include "features/Neo3Byte777Feature.h" -#include "features/Neo4ByteFeature.h" -#include "features/DotStarX4ByteFeature.h" -#include "features/DotStarL4ByteFeature.h" -#include "features/Neo6xByteFeature.h" -#include "features/Neo6xxByteFeature.h" -#include "features/Neo3WordFeature.h" -#include "features/Neo4WordFeature.h" - -// NeoPixel Features -// -#include "features/NeoRgbFeatures.h" -#include "features/NeoRgbwFeatures.h" -#include "features/NeoRgb48Features.h" -#include "features/NeoRgbw64Features.h" - -#include "features/NeoRgbwxxFeatures.h" -#include "features/NeoRgbcwxFeatures.h" -#include "features/NeoSm168xxFeatures.h" -#include "features/NeoTm1814Features.h" -#include "features/NeoTm1914Features.h" - -typedef NeoRgb48Feature NeoRgbUcs8903Feature; -typedef NeoRgbw64Feature NeoRgbwUcs8904Feature; -typedef NeoGrb48Feature NeoGrbWs2816Feature; - -// DotStart Features -// -#include "features/DotStarRgbFeatures.h" -#include "features/DotStarLrgbFeatures.h" -#include "features/Lpd6803RgbFeatures.h" -#include "features/Lpd8806RgbFeatures.h" - -#include "features/P9813BgrFeature.h" - -// 7 Segment Features -// -#include "features/NeoAbcdefgpsSegmentFeature.h" -#include "features/NeoBacedfpgsSegmentFeature.h" - -typedef NeoAbcdefgpsSegmentFeature SevenSegmentFeature; // Abcdefg order is default +class Neo3Elements +{ +public: + static const size_t PixelSize = 3; + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + for (uint8_t iElement = 0; iElement < PixelSize; iElement++) + { + *pPixelDest++ = pPixelSrc[iElement]; + } + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; +}; + +class Neo4Elements +{ +public: + static const size_t PixelSize = 4; + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (const uint32_t*)pPixelSrc; + + uint32_t* pEnd = pDest + count; + while (pDest < pEnd) + { + *pDest++ = *pSrc; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (uint32_t*)pPixelSrc; + uint32_t* pEnd = pDest + count; + while (pDest < pEnd) + { + *pDest++ = *pSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (const uint32_t*)pPixelSrc; + uint32_t* pEnd = pDest + count; + while (pDest < pEnd) + { + *pDest++ = pgm_read_dword(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (uint32_t*)pPixelSrc; + uint32_t* pDestBack = pDest + count; + const uint32_t* pSrcBack = pSrc + count; + while (pDestBack > pDest) + { + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbwColor ColorObject; +}; + + +class Neo3ElementsNoSettings : public Neo3Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class Neo4ElementsNoSettings : public Neo4Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class NeoGrbFeature : public Neo3ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.G; + *p++ = color.R; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.G = *p++; + color.R = *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.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +class NeoGrbwFeature : public Neo4ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.G; + *p++ = color.R; + *p++ = color.B; + *p = color.W; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.G = *p++; + color.R = *p++; + color.B = *p++; + color.W = *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.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.W = pgm_read_byte(p); + + return color; + } + +}; + +class NeoRgbwFeature : public Neo4ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.G; + *p++ = color.B; + *p = color.W; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.R = *p++; + color.G = *p++; + color.B = *p++; + color.W = *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.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.W = pgm_read_byte(p); + + return color; + } + +}; + +class NeoRgbFeature : public Neo3ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +class NeoBrgFeature : public Neo3ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.B; + *p++ = color.R; + *p = color.G; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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.B = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + +}; + +class NeoRbgFeature : public Neo3ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.B; + *p = color.G; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + +}; diff --git a/lib/NeoPixelBus/src/internal/NeoColors.h b/lib/NeoPixelBus/src/internal/NeoColors.h deleted file mode 100644 index dd26204a3a..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoColors.h +++ /dev/null @@ -1,55 +0,0 @@ -/*------------------------------------------------------------------------- -NeoColors includes all the color classes that describe color and -modify colors for NeoPixelBus - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -#include "colors/NeoHueBlend.h" - -#include "colors/RgbColorIndexes.h" -#include "colors/RgbColorBase.h" - -#include "colors/RgbColor.h" -#include "colors/Rgb16Color.h" -#include "colors/Rgb48Color.h" - -#include "colors/HslColor.h" -#include "colors/HsbColor.h" -#include "colors/HtmlColor.h" - -#include "colors/RgbwColor.h" -#include "colors/Rgbw64Color.h" - -#include "colors/RgbwwColor.h" - -#include "colors/SegmentDigit.h" - -#include "colors/NeoGamma.h" -#include "colors/NeoGammaEquationMethod.h" -#include "colors/NeoGammaCieLabEquationMethod.h" -#include "colors/NeoGammaTableMethod.h" -#include "colors/NeoGammaDynamicTableMethod.h" -#include "colors/NeoGammaNullMethod.h" -#include "colors/NeoGammaInvertMethod.h" diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoDib.h b/lib/NeoPixelBus/src/internal/NeoDib.h similarity index 85% rename from lib/NeoPixelBus/src/internal/buffers/NeoDib.h rename to lib/NeoPixelBus/src/internal/NeoDib.h index f3d162fccd..9ede9b110e 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoDib.h +++ b/lib/NeoPixelBus/src/internal/NeoDib.h @@ -1,6 +1,5 @@ /*------------------------------------------------------------------------- -NeoDib - Device Independant Bitmap, interal data stored in RGB/RGBW format -rather than the ColorFeature format +NeoPixel library Written by Michael C. Miller. @@ -26,14 +25,59 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -// T_COLOR_OBJECT - one of the color objects -// RgbColor -// RgbwColor -// Rgb16Color -// Rgb48Color -// Rgbw64Color -// SevenSegDigit -// +template 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: + NeoShaderBase() : + _state(0) + { + } + + bool IsDirty() const + { + return (_state & NEO_DIRTY); + }; + + void Dirty() + { + _state |= NEO_DIRTY; + }; + + void ResetDirty() + { + _state &= ~NEO_DIRTY; + }; + +protected: + uint8_t _state; // internal state +}; + template class NeoDib { public: diff --git a/lib/NeoPixelBus/src/internal/animations/NeoEase.h b/lib/NeoPixelBus/src/internal/NeoEase.h similarity index 96% rename from lib/NeoPixelBus/src/internal/animations/NeoEase.h rename to lib/NeoPixelBus/src/internal/NeoEase.h index 52c0012bbd..77a3460751 100644 --- a/lib/NeoPixelBus/src/internal/animations/NeoEase.h +++ b/lib/NeoPixelBus/src/internal/NeoEase.h @@ -310,16 +310,4 @@ class NeoEase { return pow(unitValue, 1.0f / 0.45f); } - - static float GammaCieLab(float unitValue) - { - if (unitValue <= 0.08f) - { - return unitValue / 9.033f; - } - else - { - return pow((unitValue + 0.16f) / 1.16f, 3.0f); - } - } }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp32I2sMethod.h similarity index 93% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sMethod.h rename to lib/NeoPixelBus/src/internal/NeoEsp32I2sMethod.h index 5e3d2432b0..2afe6d5aa8 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32I2sMethod.h @@ -26,14 +26,16 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - -// ESP32 C3 & S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - +#if ESP_IDF_VERSION_MAJOR <= 4 +// ESP32C3 I2S is not supported yet due to significant changes to interface +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) extern "C" { +#include +#if ESP_IDF_VERSION_MAJOR >= 5 +#include +#endif #include "Esp32_i2s.h" } @@ -171,13 +173,11 @@ template class NeoEsp32I2sM yield(); } - i2sDeinit(_bus.I2sBusNumber); - gpio_matrix_out(_pin, 0x100, false, false); pinMode(_pin, INPUT); free(_data); - heap_caps_free(_i2sBuffer); + free(_i2sBuffer); } bool IsReadyToUpdate() const @@ -190,15 +190,13 @@ template class NeoEsp32I2sM size_t dmaBlockCount = (_i2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN; i2sInit(_bus.I2sBusNumber, - false, - 2, // bytes per sample + 16, T_SPEED::I2sSampleRate, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, dmaBlockCount, - _i2sBuffer, - _i2sBufferSize); - i2sSetPins(_bus.I2sBusNumber, _pin, -1, -1, T_INVERT::Inverted); + 0); + i2sSetPins(_bus.I2sBusNumber, _pin, T_INVERT::Inverted); } void Update(bool) @@ -211,13 +209,7 @@ template class NeoEsp32I2sM FillBuffers(); - i2sWrite(_bus.I2sBusNumber); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; + i2sWrite(_bus.I2sBusNumber, _i2sBuffer, _i2sBufferSize, false, false); } uint8_t* getData() const @@ -230,7 +222,7 @@ template class NeoEsp32I2sM return _sizeData; } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -241,7 +233,7 @@ template class NeoEsp32I2sM uint8_t* _data; // Holds LED color values - size_t _i2sBufferSize; // total size of _i2sBuffer + uint32_t _i2sBufferSize; // total size of _i2sBuffer uint8_t* _i2sBuffer; // holds the DMA buffer that is referenced by _i2sBufDesc void construct(uint16_t pixelCount, size_t elementSize, size_t settingsSize) @@ -313,7 +305,7 @@ typedef NeoEsp32I2sMethodBase NeoEsp32I2s0400KbpsInvertedMethod; typedef NeoEsp32I2sMethodBase NeoEsp32I2s0Apa106InvertedMethod; -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) // (I2S_NUM_MAX == 2) typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Ws2812xMethod; @@ -355,15 +347,14 @@ typedef NeoEsp32I2sMethodBase -#include "../NeoSettings.h" -#include "../NeoBusChannel.h" +#include "NeoSettings.h" +#include "NeoBusChannel.h" #include "NeoEsp32RmtMethod.h" -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2) // translate NeoPixelBuffer into RMT buffer @@ -219,17 +219,6 @@ void NeoEsp32RmtSpeedTx1812::Translate(const void* src, RmtBit0, RmtBit1, RmtDurationReset); } -void NeoEsp32RmtSpeedGs1903::Translate(const void* src, - rmt_item32_t* dest, - size_t src_size, - size_t wanted_num, - size_t* translated_size, - size_t* item_num) -{ - _translate(src, dest, src_size, wanted_num, translated_size, item_num, - RmtBit0, RmtBit1, RmtDurationReset); -} - void NeoEsp32RmtInvertedSpeedWs2811::Translate(const void* src, rmt_item32_t* dest, size_t src_size, @@ -339,16 +328,4 @@ void NeoEsp32RmtInvertedSpeedTx1812::Translate(const void* src, _translate(src, dest, src_size, wanted_num, translated_size, item_num, RmtBit0, RmtBit1, RmtDurationReset); } - -void NeoEsp32RmtInvertedSpeedGs1903::Translate(const void* src, - rmt_item32_t* dest, - size_t src_size, - size_t wanted_num, - size_t* translated_size, - size_t* item_num) -{ - _translate(src, dest, src_size, wanted_num, translated_size, item_num, - RmtBit0, RmtBit1, RmtDurationReset); -} - #endif \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp32RmtMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h similarity index 87% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp32RmtMethod.h rename to lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h index 1753b664c5..e804cc2a7e 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp32RmtMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h @@ -29,9 +29,7 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2) /* General Reference documentation for the APIs used in this implementation LOW LEVEL: (what is actually used) @@ -45,8 +43,13 @@ Esp32-hal-rmt.h Esp32-hal-rmt.c */ +#include + extern "C" { +#if ESP_IDF_VERSION_MAJOR >= 5 +#include +#endif #include } @@ -266,21 +269,6 @@ class NeoEsp32RmtSpeedTx1812 : public NeoEsp32RmtSpeedBase size_t* item_num); }; -class NeoEsp32RmtSpeedGs1903 : public NeoEsp32RmtSpeedBase -{ -public: - const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 900); - const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 300); - const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(40000); // 40us - - 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); -}; - class NeoEsp32RmtInvertedSpeedWs2811 : public NeoEsp32RmtInvertedSpeedBase { public: @@ -434,21 +422,6 @@ class NeoEsp32RmtInvertedSpeedTx1812 : public NeoEsp32RmtInvertedSpeedBase size_t* item_num); }; -class NeoEsp32RmtInvertedSpeedGs1903 : public NeoEsp32RmtInvertedSpeedBase -{ -public: - const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 900); - const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 300); - const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(40000); // 40us - - 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); -}; - class NeoEsp32RmtChannel0 { public: @@ -481,7 +454,7 @@ class NeoEsp32RmtChannel3 const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_3; }; -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) class NeoEsp32RmtChannel4 { @@ -617,12 +590,6 @@ template class NeoEsp32RmtMethodBase } } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _dataEditing; @@ -633,7 +600,7 @@ template class NeoEsp32RmtMethodBase return _sizeData; } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -660,40 +627,34 @@ template class NeoEsp32RmtMethodBase // normal typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNSk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNApa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32RmtNGs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtN800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtN400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsMethod; @@ -701,124 +662,106 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsMethod; -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsMethod; -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) #endif // !defined(CONFIG_IDF_TARGET_ESP32C3) // inverted typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNSk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNApa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32RmtNGs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtN800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtN400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsInvertedMethod; @@ -826,102 +769,89 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsInvertedMethod; -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsInvertedMethod; -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) #endif // !defined(CONFIG_IDF_TARGET_ESP32C3) -#if defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) +#if defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) // Normally I2s method is the default, defining NEOPIXEL_ESP32_RMT_DEFAULT // will switch to use RMT as the default method -// The ESP32S2, ESP32S3, and ESP32C3 will always defualt to RMT +// The ESP32S2 & ESP32C3 will always defualt to RMT -#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) -// RMT channel 1 method is the default method for ESP32S2, ESP32S3, and ESP32C3 +// RMT channel 1 method is the default method for Esp32S2 & Esp32C3 typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2813Method; typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2812xMethod; typedef NeoEsp32Rmt1800KbpsMethod NeoWs2812Method; typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2811Method; -typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2816Method; typedef NeoEsp32Rmt1Sk6812Method NeoSk6812Method; typedef NeoEsp32Rmt1Tm1814Method NeoTm1814Method; typedef NeoEsp32Rmt1Tm1829Method NeoTm1829Method; @@ -929,7 +859,6 @@ typedef NeoEsp32Rmt1Tm1914Method NeoTm1914Method; typedef NeoEsp32Rmt1Sk6812Method NeoLc8812Method; typedef NeoEsp32Rmt1Apa106Method NeoApa106Method; typedef NeoEsp32Rmt1Tx1812Method NeoTx1812Method; -typedef NeoEsp32Rmt1Gs1903Method NeoGs1903Method; typedef NeoEsp32Rmt1Ws2812xMethod Neo800KbpsMethod; typedef NeoEsp32Rmt1400KbpsMethod Neo400KbpsMethod; @@ -938,7 +867,6 @@ typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2813InvertedMethod; typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2812xInvertedMethod; typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2811InvertedMethod; typedef NeoEsp32Rmt1800KbpsInvertedMethod NeoWs2812InvertedMethod; -typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2816InvertedMethod; typedef NeoEsp32Rmt1Sk6812InvertedMethod NeoSk6812InvertedMethod; typedef NeoEsp32Rmt1Tm1814InvertedMethod NeoTm1814InvertedMethod; typedef NeoEsp32Rmt1Tm1829InvertedMethod NeoTm1829InvertedMethod; @@ -946,19 +874,17 @@ typedef NeoEsp32Rmt1Tm1914InvertedMethod NeoTm1914InvertedMethod; typedef NeoEsp32Rmt1Sk6812InvertedMethod NeoLc8812InvertedMethod; typedef NeoEsp32Rmt1Apa106InvertedMethod NeoApa106InvertedMethod; typedef NeoEsp32Rmt1Tx1812InvertedMethod NeoTx1812InvertedMethod; -typedef NeoEsp32Rmt1Gs1903InvertedMethod NeoGs1903InvertedMethod; typedef NeoEsp32Rmt1Ws2812xInvertedMethod Neo800KbpsInvertedMethod; typedef NeoEsp32Rmt1400KbpsInvertedMethod Neo400KbpsInvertedMethod; -#else // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) +#else // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) // RMT channel 6 method is the default method for Esp32 typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2813Method; typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2812xMethod; typedef NeoEsp32Rmt6800KbpsMethod NeoWs2812Method; typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2811Method; -typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2816Method; typedef NeoEsp32Rmt6Sk6812Method NeoSk6812Method; typedef NeoEsp32Rmt6Tm1814Method NeoTm1814Method; typedef NeoEsp32Rmt6Tm1829Method NeoTm1829Method; @@ -966,7 +892,6 @@ typedef NeoEsp32Rmt6Tm1914Method NeoTm1914Method; typedef NeoEsp32Rmt6Sk6812Method NeoLc8812Method; typedef NeoEsp32Rmt6Apa106Method NeoApa106Method; typedef NeoEsp32Rmt6Tx1812Method NeoTx1812Method; -typedef NeoEsp32Rmt6Gs1903Method NeoGs1903Method; typedef NeoEsp32Rmt6Ws2812xMethod Neo800KbpsMethod; typedef NeoEsp32Rmt6400KbpsMethod Neo400KbpsMethod; @@ -975,7 +900,6 @@ typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2813InvertedMethod; typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2812xInvertedMethod; typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2811InvertedMethod; typedef NeoEsp32Rmt6800KbpsInvertedMethod NeoWs2812InvertedMethod; -typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2816InvertedMethod; typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoSk6812InvertedMethod; typedef NeoEsp32Rmt6Tm1814InvertedMethod NeoTm1814InvertedMethod; typedef NeoEsp32Rmt6Tm1829InvertedMethod NeoTm1829InvertedMethod; @@ -983,7 +907,6 @@ typedef NeoEsp32Rmt6Tm1914InvertedMethod NeoTm1914InvertedMethod; typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoLc8812InvertedMethod; typedef NeoEsp32Rmt6Apa106InvertedMethod NeoApa106InvertedMethod; typedef NeoEsp32Rmt6Tx1812InvertedMethod NeoTx1812InvertedMethod; -typedef NeoEsp32Rmt6Gs1903InvertedMethod NeoGs1903InvertedMethod; typedef NeoEsp32Rmt6Ws2812xInvertedMethod Neo800KbpsInvertedMethod; typedef NeoEsp32Rmt6400KbpsInvertedMethod Neo400KbpsInvertedMethod; diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp new file mode 100644 index 0000000000..4279fef9cc --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp @@ -0,0 +1,112 @@ +#include "../internal/NeoEsp32RmtMethod_idf5.h" + +#if ESP_IDF_VERSION_MAJOR >= 5 + +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C2) + + +size_t rmt_encode_led_strip(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state) +{ + rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base); + rmt_encoder_handle_t bytes_encoder = led_encoder->bytes_encoder; + rmt_encoder_handle_t copy_encoder = led_encoder->copy_encoder; + rmt_encode_state_t session_state = RMT_ENCODING_RESET; + rmt_encode_state_t state = RMT_ENCODING_RESET; + size_t encoded_symbols = 0; + switch (led_encoder->state) { + case 0: // send RGB data + encoded_symbols += bytes_encoder->encode(bytes_encoder, channel, primary_data, data_size, &session_state); + if (session_state & RMT_ENCODING_COMPLETE) { + led_encoder->state = 1; // switch to next state when current encoding session finished + } + if (session_state & RMT_ENCODING_MEM_FULL) { + // static_cast(static_cast(a) | static_cast(b)); + state = static_cast(static_cast(state) | static_cast(RMT_ENCODING_MEM_FULL)); + goto out; // yield if there's no free space for encoding artifacts + } + // fall-through + case 1: // send reset code + encoded_symbols += copy_encoder->encode(copy_encoder, channel, &led_encoder->reset_code, + sizeof(led_encoder->reset_code), &session_state); + if (session_state & RMT_ENCODING_COMPLETE) { + led_encoder->state = RMT_ENCODING_RESET; // back to the initial encoding session + state = static_cast(static_cast(state) | static_cast(RMT_ENCODING_COMPLETE)); + } + if (session_state & RMT_ENCODING_MEM_FULL) { + state = static_cast(static_cast(state) | static_cast(RMT_ENCODING_MEM_FULL)); + goto out; // yield if there's no free space for encoding artifacts + } + } +out: + *ret_state = state; + return encoded_symbols; +} + +esp_err_t rmt_del_led_strip_encoder(rmt_encoder_t *encoder) +{ + rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base); + rmt_del_encoder(led_encoder->bytes_encoder); + rmt_del_encoder(led_encoder->copy_encoder); + delete led_encoder; + return ESP_OK; +} + +esp_err_t rmt_led_strip_encoder_reset(rmt_encoder_t *encoder) +{ + rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base); + rmt_encoder_reset(led_encoder->bytes_encoder); + rmt_encoder_reset(led_encoder->copy_encoder); + led_encoder->state = RMT_ENCODING_RESET; + return ESP_OK; +} + +esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder, uint32_t bit0, uint32_t bit1) +{ + const char* TAG = "TEST_RMT"; //TODO: Remove later + esp_err_t ret = ESP_OK; + rmt_led_strip_encoder_t *led_encoder = NULL; + uint32_t reset_ticks = config->resolution / 1000000 * 50 / 2; // reset code duration defaults to 50us + rmt_bytes_encoder_config_t bytes_encoder_config; + rmt_copy_encoder_config_t copy_encoder_config = {}; + rmt_symbol_word_t reset_code_config; + + + ESP_GOTO_ON_FALSE(config && ret_encoder, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument"); + led_encoder = new rmt_led_strip_encoder_t(); + ESP_GOTO_ON_FALSE(led_encoder, ESP_ERR_NO_MEM, err, TAG, "no mem for led strip encoder"); + led_encoder->base.encode = rmt_encode_led_strip; + led_encoder->base.del = rmt_del_led_strip_encoder; + led_encoder->base.reset = rmt_led_strip_encoder_reset; + + bytes_encoder_config.bit0.val = bit0; + bytes_encoder_config.bit1.val = bit1; + + bytes_encoder_config.flags.msb_first = 1; // WS2812 transfer bit order: G7...G0R7...R0B7...B0 - TODO: more checks + + ESP_GOTO_ON_ERROR(rmt_new_bytes_encoder(&bytes_encoder_config, &led_encoder->bytes_encoder), err, TAG, "create bytes encoder failed"); + ESP_GOTO_ON_ERROR(rmt_new_copy_encoder(©_encoder_config, &led_encoder->copy_encoder), err, TAG, "create copy encoder failed"); + + reset_code_config.level0 = 0; + reset_code_config.duration0 = reset_ticks; + reset_code_config.level1 = 0; + reset_code_config.duration1 = reset_ticks; + led_encoder->reset_code = reset_code_config; + *ret_encoder = &led_encoder->base; + return ret; +err: + // AddLog(2,"RMT:could not init led decoder"); + if (led_encoder) { + if (led_encoder->bytes_encoder) { + rmt_del_encoder(led_encoder->bytes_encoder); + } + if (led_encoder->copy_encoder) { + rmt_del_encoder(led_encoder->copy_encoder); + } + delete led_encoder; + } + return ret; +} + +#endif + +#endif // if ESP_IDF_VERSION_MAJOR >= 5 diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h new file mode 100644 index 0000000000..5807f46309 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h @@ -0,0 +1,805 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp32. + +A BIG thanks to Andreas Merkle for the investigation and implementation of +a workaround to the GCC bug that drops method attributes from template methods + +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 +. +-------------------------------------------------------------------------*/ + +#pragma once + +#if ESP_IDF_VERSION_MAJOR >= 5 + +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C2) + +/* 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 +*/ + +#include + +//extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); + +extern "C" +{ +#include +#include "driver/rmt_tx.h" +#include "driver/rmt_encoder.h" +#include "esp_check.h" +} + +#include "NeoBusChannel.h" +#include "NeoSettings.h" + +#define RMT_LED_STRIP_RESOLUTION_HZ 40000000 // 40MHz resolution - setting of the "old" driver + +typedef struct { + uint32_t resolution; /*!< Encoder resolution, in Hz */ +} led_strip_encoder_config_t; + +typedef struct { + rmt_encoder_t base; + rmt_encoder_t *bytes_encoder; + rmt_encoder_t *copy_encoder; + int state; + rmt_symbol_word_t reset_code; +} rmt_led_strip_encoder_t; + +size_t rmt_encode_led_strip(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state); + +esp_err_t rmt_del_led_strip_encoder(rmt_encoder_t *encoder); + +esp_err_t rmt_led_strip_encoder_reset(rmt_encoder_t *encoder); + +esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder, uint32_t bit0, uint32_t bit1); + +#define NEOPIXELBUS_RMT_INT_FLAGS (ESP_INTR_FLAG_LOWMED) + +class NeoEsp32RmtSpeed +{ +public: +// next section is probably not needed anymore for IDF 5.1 + // 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; + } + +protected: + 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 +// end of deprecated section + +}; + +class NeoEsp32RmtSpeedBase : public NeoEsp32RmtSpeed +{ +public: + // this is used rather than the rmt_symbol_word_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)); + } +}; + +class NeoEsp32RmtInvertedSpeedBase : public NeoEsp32RmtSpeed +{ +public: + // this is used rather than the rmt_symbol_word_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 << 31) | (FromNs(nsHigh)); + } +}; + +class NeoEsp32RmtSpeedWs2811 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 950); // TODO: DRAM_ATTR debatable everywhere + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 350); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtSpeedWs2812x : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtSpeedSk6812 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +// normal is inverted signal +class NeoEsp32RmtSpeedTm1814 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(360, 890); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(720, 530); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +// normal is inverted signal +class NeoEsp32RmtSpeedTm1829 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 900); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 400); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +// normal is inverted signal +class NeoEsp32RmtSpeedTm1914 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(360, 890); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(720, 530); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +class NeoEsp32RmtSpeed800Kbps : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtSpeed400Kbps : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(800, 1700); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1600, 900); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtSpeedApa106 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(350, 1350); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1350, 350); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtSpeedTx1812 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 600); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(600, 300); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +class NeoEsp32RmtInvertedSpeedWs2811 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 950); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 350); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtInvertedSpeedWs2812x : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtInvertedSpeedSk6812 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +// normal is inverted signal +class NeoEsp32RmtInvertedSpeedTm1814 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(360, 890); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(720, 530); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +// normal is inverted signal +class NeoEsp32RmtInvertedSpeedTm1829 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 900); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 400); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +// normal is inverted signal +class NeoEsp32RmtInvertedSpeedTm1914 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(360, 890); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(720, 530); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +class NeoEsp32RmtInvertedSpeed800Kbps : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtInvertedSpeed400Kbps : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(800, 1700); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1600, 900); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtInvertedSpeedApa106 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(350, 1350); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1350, 350); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtInvertedSpeedTx1812 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 600); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(600, 300); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +class NeoEsp32RmtChannel0 +{ +public: + NeoEsp32RmtChannel0() {}; + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel1 +{ +public: + NeoEsp32RmtChannel1() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +#if !defined(CONFIG_IDF_TARGET_ESP32C6) // C6 only 2 RMT channels ?? +class NeoEsp32RmtChannel2 +{ +public: + NeoEsp32RmtChannel2() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel3 +{ +public: + NeoEsp32RmtChannel3() {}; + +protected: + rmt_channel_handle_t RmtChannelNumber = NULL; +}; +#endif // !defined(CONFIG_IDF_TARGET_ESP32C6) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) + +class NeoEsp32RmtChannel4 +{ +public: + NeoEsp32RmtChannel4() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel5 +{ +public: + NeoEsp32RmtChannel5() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel6 +{ +public: + NeoEsp32RmtChannel6() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel7 +{ +public: + NeoEsp32RmtChannel7() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +#endif + +// dynamic channel support +class NeoEsp32RmtChannelN +{ +public: + NeoEsp32RmtChannelN(NeoBusChannel channel) : + RmtChannelNumber(RmtChannelNumber) + { + RmtChannelNumber = NULL; + }; + NeoEsp32RmtChannelN() = delete; // no default constructor + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +template class NeoEsp32RmtMethodBase +{ +public: + typedef NeoNoSettings SettingsObject; + + NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), + _pin(pin) + { + construct(); + } + + NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize, NeoBusChannel channel) : + _sizeData(pixelCount* elementSize + settingsSize), + _pin(pin), + _channel(channel) + { + construct(); + } + + ~NeoEsp32RmtMethodBase() + { + // wait until the last send finishes before destructing everything + // arbitrary time out of 10 seconds + + ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_tx_wait_all_done(_channel.RmtChannelNumber, 10000 / portTICK_PERIOD_MS)); + ESP_ERROR_CHECK( rmt_del_channel(_channel.RmtChannelNumber)); + + gpio_matrix_out(_pin, 0x100, false, false); + pinMode(_pin, INPUT); + + free(_dataEditing); + free(_dataSending); + } + + + bool IsReadyToUpdate() const + { + return (ESP_OK == rmt_tx_wait_all_done(_channel.RmtChannelNumber, 0)); + } + + void Initialize() + { + esp_err_t ret = ESP_OK; + rmt_tx_channel_config_t config = {}; + config.clk_src = RMT_CLK_SRC_DEFAULT; + config.gpio_num = static_cast(_pin); + config.mem_block_symbols = 64; // memory block size, 64 * 4 = 256 Bytes + config.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ; // 1 MHz tick resolution, i.e., 1 tick = 1 µs + config.trans_queue_depth = 4; // set the number of transactions that can pend in the background + config.flags.invert_out = false; // do not invert output signal + config.flags.with_dma = false; // do not need DMA backend + + ret += rmt_new_tx_channel(&config,&_channel.RmtChannelNumber); + led_strip_encoder_config_t encoder_config = {}; + encoder_config.resolution = RMT_LED_STRIP_RESOLUTION_HZ; + + _tx_config.loop_count = 0; //no loop + + ret += rmt_new_led_strip_encoder(&encoder_config, &_led_encoder, T_SPEED::RmtBit0, T_SPEED::RmtBit1); + + // ESP_LOGI(TAG, "Enable RMT TX channel"); + ret += rmt_enable(_channel.RmtChannelNumber); + // AddLog(2,"RMT:initialized with error code: %u on pin: %u",ret, _pin); + } + + void Update(bool maintainBufferConsistency) + { + // AddLog(2,".."); + // 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 == ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_tx_wait_all_done(_channel.RmtChannelNumber, 10000 / portTICK_PERIOD_MS))) + { + // AddLog(2,"__ %u", _sizeData); + // now start the RMT transmit with the editing buffer before we swap + esp_err_t ret = rmt_transmit(_channel.RmtChannelNumber, _led_encoder, _dataEditing, _sizeData, &_tx_config); // 3 for _sizeData + // AddLog(2,"rmt_transmit: %u", ret); + 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(_dataSending, _dataEditing, _sizeData); + } + + // swap so the user can modify without affecting the async operation + std::swap(_dataSending, _dataEditing); + } + } + + uint8_t* getData() const + { + return _dataEditing; + }; + + size_t getDataSize() const + { + return _sizeData; + } + + void applySettings(const SettingsObject& settings) + { + } + +private: + const size_t _sizeData; // Size of '_data*' buffers + const uint8_t _pin; // output pin number + + rmt_transmit_config_t _tx_config = {}; + rmt_encoder_handle_t _led_encoder = nullptr; + + T_CHANNEL _channel; // holds instance for multi channel support + + + // Holds data stream which include LED color values and other settings as needed + uint8_t* _dataEditing; // exposed for get and set + uint8_t* _dataSending; // used for async send using RMT + + + void construct() + { + // AddLog(2,"RMT:construct"); + _dataEditing = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + + _dataSending = static_cast(malloc(_sizeData)); + // no need to initialize it, it gets overwritten on every send + } +}; + +// normal +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNSk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNApa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtN800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtN400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsMethod; + +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C3) + +// inverted +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNSk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNApa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtN800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtN400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsInvertedMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsInvertedMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsInvertedMethod; + +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) + + +#if defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + +// Normally I2s method is the default, defining NEOPIXEL_ESP32_RMT_DEFAULT +// will switch to use RMT as the default method +// The ESP32S2 & ESP32C3 will always defualt to RMT + +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + +// RMT channel 1 method is the default method for Esp32S2 & Esp32C3 +typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2813Method; +typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2812xMethod; +typedef NeoEsp32Rmt1800KbpsMethod NeoWs2812Method; +typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2811Method; +typedef NeoEsp32Rmt1Sk6812Method NeoSk6812Method; +typedef NeoEsp32Rmt1Tm1814Method NeoTm1814Method; +typedef NeoEsp32Rmt1Tm1829Method NeoTm1829Method; +typedef NeoEsp32Rmt1Tm1914Method NeoTm1914Method; +typedef NeoEsp32Rmt1Sk6812Method NeoLc8812Method; +typedef NeoEsp32Rmt1Apa106Method NeoApa106Method; +typedef NeoEsp32Rmt1Tx1812Method NeoTx1812Method; + +typedef NeoEsp32Rmt1Ws2812xMethod Neo800KbpsMethod; +typedef NeoEsp32Rmt1400KbpsMethod Neo400KbpsMethod; + +typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2813InvertedMethod; +typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2812xInvertedMethod; +typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2811InvertedMethod; +typedef NeoEsp32Rmt1800KbpsInvertedMethod NeoWs2812InvertedMethod; +typedef NeoEsp32Rmt1Sk6812InvertedMethod NeoSk6812InvertedMethod; +typedef NeoEsp32Rmt1Tm1814InvertedMethod NeoTm1814InvertedMethod; +typedef NeoEsp32Rmt1Tm1829InvertedMethod NeoTm1829InvertedMethod; +typedef NeoEsp32Rmt1Tm1914InvertedMethod NeoTm1914InvertedMethod; +typedef NeoEsp32Rmt1Sk6812InvertedMethod NeoLc8812InvertedMethod; +typedef NeoEsp32Rmt1Apa106InvertedMethod NeoApa106InvertedMethod; +typedef NeoEsp32Rmt1Tx1812InvertedMethod NeoTx1812InvertedMethod; + +typedef NeoEsp32Rmt1Ws2812xInvertedMethod Neo800KbpsInvertedMethod; +typedef NeoEsp32Rmt1400KbpsInvertedMethod Neo400KbpsInvertedMethod; + +#else // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) + +// RMT channel 6 method is the default method for Esp32 +typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2813Method; +typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2812xMethod; +typedef NeoEsp32Rmt6800KbpsMethod NeoWs2812Method; +typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2811Method; +typedef NeoEsp32Rmt6Sk6812Method NeoSk6812Method; +typedef NeoEsp32Rmt6Tm1814Method NeoTm1814Method; +typedef NeoEsp32Rmt6Tm1829Method NeoTm1829Method; +typedef NeoEsp32Rmt6Tm1914Method NeoTm1914Method; +typedef NeoEsp32Rmt6Sk6812Method NeoLc8812Method; +typedef NeoEsp32Rmt6Apa106Method NeoApa106Method; +typedef NeoEsp32Rmt6Tx1812Method NeoTx1812Method; + +typedef NeoEsp32Rmt6Ws2812xMethod Neo800KbpsMethod; +typedef NeoEsp32Rmt6400KbpsMethod Neo400KbpsMethod; + +typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2813InvertedMethod; +typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2812xInvertedMethod; +typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2811InvertedMethod; +typedef NeoEsp32Rmt6800KbpsInvertedMethod NeoWs2812InvertedMethod; +typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoSk6812InvertedMethod; +typedef NeoEsp32Rmt6Tm1814InvertedMethod NeoTm1814InvertedMethod; +typedef NeoEsp32Rmt6Tm1829InvertedMethod NeoTm1829InvertedMethod; +typedef NeoEsp32Rmt6Tm1914InvertedMethod NeoTm1914InvertedMethod; +typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoLc8812InvertedMethod; +typedef NeoEsp32Rmt6Apa106InvertedMethod NeoApa106InvertedMethod; +typedef NeoEsp32Rmt6Tx1812InvertedMethod NeoTx1812InvertedMethod; + +typedef NeoEsp32Rmt6Ws2812xInvertedMethod Neo800KbpsInvertedMethod; +typedef NeoEsp32Rmt6400KbpsInvertedMethod Neo400KbpsInvertedMethod; + +#endif // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + +#endif // defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + +#endif + +#endif // if ESP_IDF_VERSION_MAJOR >= 5 \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h b/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h new file mode 100644 index 0000000000..826d6ef99c --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h @@ -0,0 +1,504 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp32. + +Adaption of Espressif's component library code by Christian Baars + +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 not yet 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 +. +-------------------------------------------------------------------------*/ + +#pragma once + +#if defined(ARDUINO_ARCH_ESP32) + +#if (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6)) && !defined(HSPI_HOST) +// HSPI_HOST depreciated in C3 +#define HSPI_HOST SPI2_HOST +#endif + +#include + +extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); // TODO: Remove all Addlogs + +extern "C" +{ +#include +#include "esp_rom_gpio.h" +#include "driver/spi_master.h" +#include "esp_check.h" +} + +#define LED_STRIP_SPI_DEFAULT_RESOLUTION (25 * 100 * 1000) // 2.5MHz resolution +#define LED_STRIP_SPI_DEFAULT_TRANS_QUEUE_SIZE 4 + +#define SPI_BYTES_PER_COLOR_BYTE 3 +#define SPI_BITS_PER_COLOR_BYTE (SPI_BYTES_PER_COLOR_BYTE * 8) + +static const char *TAG = "led_strip_spi"; // TODO: Remove all TAG log stuff + +typedef enum { + LED_MODEL_WS2812, /*!< LED strip model: WS2812 */ + LED_MODEL_SK6812, /*!< LED strip model: SK6812 */ + LED_MODEL_INVALID /*!< Invalid LED strip model */ +} led_model_t; + +typedef enum { + LED_PIXEL_FORMAT_GRB, /*!< Pixel format: GRB */ + LED_PIXEL_FORMAT_GRBW, /*!< Pixel format: GRBW */ + LED_PIXEL_FORMAT_INVALID /*!< Invalid pixel format */ +} led_pixel_format_t; + +typedef struct { + spi_host_device_t spi_host; + spi_device_handle_t spi_device; + uint32_t strip_len; + uint8_t bytes_per_pixel; + uint8_t pixel_buf[]; +} led_strip_spi_obj; + +/** + * @brief LED Strip Configuration + */ +typedef struct { + int strip_gpio_num; /*!< GPIO number that used by LED strip */ + uint32_t max_leds; /*!< Maximum LEDs in a single strip */ + led_pixel_format_t led_pixel_format; /*!< LED pixel format */ + led_model_t led_model; /*!< LED model */ + + struct { + uint32_t invert_out: 1; /*!< Invert output signal */ + } flags; +} led_strip_config_t; + +typedef struct { + spi_clock_source_t clk_src; /*!< SPI clock source */ + spi_host_device_t spi_bus; /*!< SPI bus ID. Which buses are available depends on the specific chip */ + struct { + uint32_t with_dma: 1; /*!< Use DMA to transmit data */ + } flags; +} led_strip_spi_config_t; + + +class NeoEsp32SpiSpeed +{ +public: + + +protected: + +// end of deprecated section + +}; + +class NeoEsp32SpiSpeedBase : public NeoEsp32SpiSpeed +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedBase : public NeoEsp32SpiSpeed +{ +public: + +}; + +class NeoEsp32SpiSpeedWs2811 : public NeoEsp32SpiSpeedBase +{ +public: + +}; + +class NeoEsp32SpiSpeedWs2812x : public NeoEsp32SpiSpeedBase +{ +public: + static const uint8_t bytes_per_pixel = 3; + +}; + +class NeoEsp32SpiSpeedSk6812 : public NeoEsp32SpiSpeedBase +{ +public: + static const uint8_t bytes_per_pixel = 4; + +}; + +class NeoEsp32SpiSpeed400Kbps : public NeoEsp32SpiSpeedBase +{ +public: + +}; + +class NeoEsp32SpiSpeedApa106 : public NeoEsp32SpiSpeedBase +{ +public: + +}; + +class NeoEsp32SpiSpeedTx1812 : public NeoEsp32SpiSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedWs2811 : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedWs2812x : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedSk6812 : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeed800Kbps : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeed400Kbps : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedApa106 : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedTx1812 : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiChannel +{ +public: + +}; + + +template class NeoEsp32SpiMethodBase +{ +public: + typedef NeoNoSettings SettingsObject; + + NeoEsp32SpiMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), + // _pixelCount(pixelCount), + _pin(pin) + { + _pixelCount = pixelCount; + construct(); + } + + NeoEsp32SpiMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize, NeoBusChannel channel) : + _sizeData(pixelCount* elementSize + settingsSize), + // _pixelCount(pixelCount), + _pin(pin) + // _channel(channel) // TODO: Refactor this somehow + { + _pixelCount = pixelCount; + construct(); + } + + ~NeoEsp32SpiMethodBase() + { + // wait until the last send finishes before destructing everything + // arbitrary time out of 10 seconds + + gpio_matrix_out(_pin, 0x100, false, false); + pinMode(_pin, INPUT); + + spi_bus_remove_device(_spi_strip->spi_device); + spi_bus_free(_spi_strip->spi_host); + free(_spi_strip); + + free(_dataEditing); + free(_dataSending); + } + + + bool IsReadyToUpdate() const + { + return true; // TODO + } + + void Initialize() + { + esp_err_t ret = ESP_OK; + uint8_t bytes_per_pixel = T_SPEED::bytes_per_pixel; + uint32_t mem_caps = MALLOC_CAP_DEFAULT; + spi_clock_source_t clk_src = SPI_CLK_SRC_DEFAULT; + spi_bus_config_t spi_bus_cfg; + spi_device_interface_config_t spi_dev_cfg; + bool with_dma = true; /// TODO: pass value or compute based on pixelcount + int clock_resolution_khz = 0; + + // ESP_GOTO_ON_FALSE(led_config && spi_config && ret_strip, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument"); + // ESP_GOTO_ON_FALSE(led_config->led_pixel_format < LED_PIXEL_FORMAT_INVALID, ESP_ERR_INVALID_ARG, err, TAG, "invalid led_pixel_format"); + + // if ( LED_PIXEL_FORMAT_GRB == LED_PIXEL_FORMAT_GRBW) { // TODO + // bytes_per_pixel = 4; + // } else if (LED_PIXEL_FORMAT_GRB == LED_PIXEL_FORMAT_GRB) { + // bytes_per_pixel = 3; + // } else { + // assert(false); + // } + + if (with_dma) { // TODO + // DMA buffer must be placed in internal SRAM + mem_caps |= MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA; + } + _spi_strip = (led_strip_spi_obj *)heap_caps_calloc(1, sizeof(led_strip_spi_obj) + _pixelCount * bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE, mem_caps); + + ESP_GOTO_ON_FALSE(_spi_strip, ESP_ERR_NO_MEM, err, TAG, "no mem for spi strip"); + + _spi_strip->spi_host = SPI2_HOST; + + // for backward compatibility, if the user does not set the clk_src, use the default value + // if (clk_src) { + // clk_src = spi_config->clk_src; + // } + + spi_bus_cfg = { + .mosi_io_num = _pin, + //Only use MOSI to generate the signal, set -1 when other pins are not used. + .miso_io_num = -1, + .sclk_io_num = -1, + .quadwp_io_num = -1, + .quadhd_io_num = -1, + .max_transfer_sz = _pixelCount * bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE, + }; + ESP_GOTO_ON_ERROR(spi_bus_initialize(_spi_strip->spi_host, &spi_bus_cfg, with_dma ? SPI_DMA_CH_AUTO : SPI_DMA_DISABLED), err, TAG, "create SPI bus failed"); + + // if (led_config->flags.invert_out == true) { + // esp_rom_gpio_connect_out_signal(_pin, spi_periph_signal[_spi_strip->spi_host].spid_out, true, false); + // } + + spi_dev_cfg = { + .command_bits = 0, + .address_bits = 0, + .dummy_bits = 0, + .mode = 0, + //set -1 when CS is not used + .clock_source = clk_src, + .clock_speed_hz = LED_STRIP_SPI_DEFAULT_RESOLUTION, + .spics_io_num = -1, + .queue_size = LED_STRIP_SPI_DEFAULT_TRANS_QUEUE_SIZE, + }; + + ESP_GOTO_ON_ERROR(spi_bus_add_device(_spi_strip->spi_host, &spi_dev_cfg, &_spi_strip->spi_device), err, TAG, "Failed to add spi device"); + + spi_device_get_actual_freq(_spi_strip->spi_device, &clock_resolution_khz); + // TODO: ideally we should decide the SPI_BYTES_PER_COLOR_BYTE by the real clock resolution + // But now, let's fixed the resolution, the downside is, we don't support a clock source whose frequency is not multiple of LED_STRIP_SPI_DEFAULT_RESOLUTION + ESP_GOTO_ON_FALSE(clock_resolution_khz == LED_STRIP_SPI_DEFAULT_RESOLUTION / 1000, ESP_ERR_NOT_SUPPORTED, err, + TAG, "unsupported clock resolution:%dKHz", clock_resolution_khz); + + _spi_strip->bytes_per_pixel = bytes_per_pixel; + _spi_strip->strip_len = _pixelCount; + + AddLog(2,"SPI:initialized with error code: %u on pin: %u",ret, _pin); + return; + err: + if (_spi_strip) { + if (_spi_strip->spi_device) { + spi_bus_remove_device(_spi_strip->spi_device); + } + if (_spi_strip->spi_host) { + spi_bus_free(_spi_strip->spi_host); + } + free(_spi_strip); + } + AddLog(2,"SPI-Error:initialized with error code: %u on pin: %u",ret, _pin); + return; + } + + void Update(bool maintainBufferConsistency) + { + // AddLog(2,".."); + // 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 READY + { + // AddLog(2,"__ %u", _sizeData); + // now start the SPI transmit with the editing buffer before we swap + led_strip_transmit_RGB_buffer(_dataEditing, _sizeData, T_SPEED::bytes_per_pixel); + + 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(_dataSending, _dataEditing, _sizeData); + } + + // swap so the user can modify without affecting the async operation + std::swap(_dataSending, _dataEditing); + } + } + + uint8_t* getData() const + { + return _dataEditing; + }; + + size_t getDataSize() const + { + return _sizeData; + } + + void applySettings(const SettingsObject& settings) + { + } + +private: + const size_t _sizeData; // Size of '_data*' buffers + int16_t _pixelCount; + const uint8_t _pin; // output pin number + T_CHANNEL _channel; // not really used here + + led_strip_spi_obj *_spi_strip; + + + // Holds data stream which include LED color values and other settings as needed + uint8_t* _dataEditing; // exposed for get and set + uint8_t* _dataSending; // used for async send using RMT - TODO: Check if this useful for SPI + + + void construct() + { + _dataEditing = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + + _dataSending = static_cast(malloc(_sizeData)); + // no need to initialize it, it gets overwritten on every send + } + + // please make sure to zero-initialize the buf before calling this function + + void __led_strip_spi_bit(uint8_t data, uint8_t *buf) + { + // Each color of 1 bit is represented by 3 bits of SPI, low_level:100 ,high_level:110 + // So a color byte occupies 3 bytes of SPI. + *(buf + 2) |= data & BIT(0) ? BIT(2) | BIT(1) : BIT(2); + *(buf + 2) |= data & BIT(1) ? BIT(5) | BIT(4) : BIT(5); + *(buf + 2) |= data & BIT(2) ? BIT(7) : 0x00; + *(buf + 1) |= BIT(0); + *(buf + 1) |= data & BIT(3) ? BIT(3) | BIT(2) : BIT(3); + *(buf + 1) |= data & BIT(4) ? BIT(6) | BIT(5) : BIT(6); + *(buf + 0) |= data & BIT(5) ? BIT(1) | BIT(0) : BIT(1); + *(buf + 0) |= data & BIT(6) ? BIT(4) | BIT(3) : BIT(4); + *(buf + 0) |= data & BIT(7) ? BIT(7) | BIT(6) : BIT(7); + } + + esp_err_t led_strip_spi_set_pixel(uint32_t index, uint32_t red, uint32_t green, uint32_t blue) + { + if(index >= _spi_strip->strip_len) return ESP_FAIL; + // LED_PIXEL_FORMAT_GRB takes 72bits(9bytes) + uint32_t start = index * _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE; + memset(_spi_strip->pixel_buf + start, 0, _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE); + __led_strip_spi_bit(green, &_spi_strip->pixel_buf[start]); + __led_strip_spi_bit(red, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE]); + __led_strip_spi_bit(blue, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE * 2]); + if (_spi_strip->bytes_per_pixel > 3) { + __led_strip_spi_bit(0, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE * 3]); + } + return ESP_OK; + } + + esp_err_t led_strip_spi_set_pixel_rgbw(uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white) + { + // LED_PIXEL_FORMAT_GRBW takes 96bits(12bytes) + uint32_t start = index * _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE; + // SK6812 component order is GRBW + memset(_spi_strip->pixel_buf + start, 0, _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE); + __led_strip_spi_bit(green, &_spi_strip->pixel_buf[start]); + __led_strip_spi_bit(red, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE]); + __led_strip_spi_bit(blue, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE * 2]); + __led_strip_spi_bit(white, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE * 3]); + + return ESP_OK; + } + + esp_err_t led_strip_spi_clear() + { + //Write zero to turn off all leds + memset(_spi_strip->pixel_buf, 0, _spi_strip->strip_len * _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE); + uint8_t *buf = _spi_strip->pixel_buf; + for (int index = 0; index < _spi_strip->strip_len * _spi_strip->bytes_per_pixel; index++) { + __led_strip_spi_bit(0, buf); + buf += SPI_BYTES_PER_COLOR_BYTE; + } + return led_strip_spi_refresh(); + } + + esp_err_t led_strip_spi_refresh() + { + spi_transaction_t tx_conf; + memset(&tx_conf, 0, sizeof(tx_conf)); + + tx_conf.length = _spi_strip->strip_len * _spi_strip->bytes_per_pixel * SPI_BITS_PER_COLOR_BYTE; + tx_conf.tx_buffer = _spi_strip->pixel_buf; + tx_conf.rx_buffer = NULL; + spi_device_transmit(_spi_strip->spi_device, &tx_conf); // TODO -check + return ESP_OK; + } + + void led_strip_transmit_RGB_buffer(uint8_t * buffer, size_t size, uint8_t bytes_per_pixel) + { + for (int i = 0; i < size; i+=bytes_per_pixel) { + led_strip_spi_set_pixel(i/bytes_per_pixel, buffer[i+1], buffer[i], buffer[i+2]); //GRB -> RGB + } + /* Refresh the strip to send data */ + led_strip_spi_refresh(); + } +}; + +// normal +typedef NeoEsp32SpiMethodBase NeoEsp32SpiN800KbpsMethod; +typedef NeoEsp32SpiMethodBase NeoEsp32SpiNSk6812Method; + + +// SPI channel method is the default method for Esp32C2 +#ifdef CONFIG_IDF_TARGET_ESP32C2 +typedef NeoEsp32SpiSpeedWs2812x NeoWs2813Method; +typedef NeoEsp32SpiSpeedWs2812x NeoWs2812xMethod; +typedef NeoEsp32SpiSpeedSk6812 NeoSk6812Method; + +#endif //CONFIG_IDF_TARGET_ESP32C2 + +#endif diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.cpp b/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.cpp similarity index 89% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.cpp rename to lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.cpp index e47e0bfa34..4bfc7d3409 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.cpp +++ b/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.cpp @@ -25,11 +25,12 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include -#include "../NeoUtil.h" -#include "NeoEsp8266I2sMethodCore.h" +#include "NeoSettings.h" +#include "NeoBusChannel.h" +#include "NeoEsp8266DmaMethod.h" #ifdef ARDUINO_ARCH_ESP8266 -NeoEsp8266I2sMethodCore* NeoEsp8266I2sMethodCore::s_this; +NeoEsp8266DmaMethodCore* NeoEsp8266DmaMethodCore::s_this; #endif \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.h new file mode 100644 index 0000000000..7a8a32330c --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.h @@ -0,0 +1,612 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp8266. + + +Written by Michael C. Miller. +Thanks to g3gg0.de for porting the initial DMA support which lead to this. +Thanks to github/cnlohr for the original work on DMA support, which opend +all our minds to a better way (located at https://github.com/cnlohr/esp8266ws2812i2s). + +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 +. +-------------------------------------------------------------------------*/ + +#pragma once + +#ifdef ARDUINO_ARCH_ESP8266 + +#include "Arduino.h" + +extern "C" +{ +#include "osapi.h" +#include "ets_sys.h" + +#include "i2s_reg.h" + +#ifdef ARDUINO_ESP8266_MAJOR //this define was added in ESP8266 Arduino Core version v3.0.1 + #include "core_esp8266_i2s.h" //for Arduino core >= 3.0.1 +#else + #include "i2s.h" //for Arduino core <= 3.0.0 +#endif + +#include "eagle_soc.h" +#include "esp8266_peri.h" +#include "slc_register.h" + +#include "osapi.h" +#include "ets_sys.h" +#include "user_interface.h" + +#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 +} + +struct slc_queue_item +{ + uint32 blocksize : 12; + uint32 datalen : 12; + uint32 unused : 5; + uint32 sub_sof : 1; + uint32 eof : 1; + uint32 owner : 1; + uint8* buf_ptr; + struct slc_queue_item* next_link_ptr; +}; + +class NeoEsp8266DmaSpeedBase +{ +public: + static const uint8_t Level = 0x00; + static uint16_t Convert(uint8_t value) + { + const uint16_t bitpatterns[16] = + { + 0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110, + 0b1000111010001000, 0b1000111010001110, 0b1000111011101000, 0b1000111011101110, + 0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110, + 0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110, + }; + + return bitpatterns[value]; + } +}; + +class NeoEsp8266DmaInvertedSpeedBase +{ +public: + static const uint8_t Level = 0xFF; + static uint16_t Convert(uint8_t value) + { + const uint16_t bitpatterns[16] = + { + 0b0111011101110111, 0b0111011101110001, 0b0111011100010111, 0b0111011100010001, + 0b0111000101110111, 0b0111000101110001, 0b0111000100010111, 0b0111000100010001, + 0b0001011101110111, 0b0001011101110001, 0b0001011100010111, 0b0001011100010001, + 0b0001000101110111, 0b0001000101110001, 0b0001000100010111, 0b0001000100010001, + }; + + return bitpatterns[value]; + } +}; + +class NeoEsp8266DmaSpeed800KbpsBase : public NeoEsp8266DmaSpeedBase +{ +public: + const static uint32_t I2sClockDivisor = 3; + const static uint32_t I2sBaseClockDivisor = 16; + const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed +}; + +class NeoEsp8266DmaSpeedWs2812x : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 300; +}; + +class NeoEsp8266DmaSpeedSk6812 : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 80; +}; + +class NeoEsp8266DmaInvertedSpeedTm1814 : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 200; +}; + +class NeoEsp8266DmaInvertedSpeedTm1829 : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 200; +}; + +class NeoEsp8266DmaSpeed800Kbps : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 50; +}; + +class NeoEsp8266DmaSpeed400Kbps : public NeoEsp8266DmaSpeedBase +{ +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 NeoEsp8266DmaSpeedBase +{ +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; +}; + + + +class NeoEsp8266DmaInvertedSpeed800KbpsBase : public NeoEsp8266DmaInvertedSpeedBase +{ +public: + const static uint32_t I2sClockDivisor = 3; + const static uint32_t I2sBaseClockDivisor = 16; + const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed +}; + +class NeoEsp8266DmaInvertedSpeedWs2812x : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 300; +}; + +class NeoEsp8266DmaInvertedSpeedSk6812 : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 80; +}; + +class NeoEsp8266DmaSpeedTm1814 : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 200; +}; + +class NeoEsp8266DmaSpeedTm1829 : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 200; +}; + +class NeoEsp8266DmaInvertedSpeed800Kbps : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 50; +}; + +class NeoEsp8266DmaInvertedSpeed400Kbps : public NeoEsp8266DmaInvertedSpeedBase +{ +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 NeoEsp8266DmaInvertedSpeedApa106 : public NeoEsp8266DmaInvertedSpeedBase +{ +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; +const uint8_t c_I2sPin = 3; // due to I2S hardware, the pin used is restricted to this + +class NeoEsp8266DmaMethodCore +{ +protected: + static NeoEsp8266DmaMethodCore* s_this; // for the ISR + + volatile NeoDmaState _dmaState; + + slc_queue_item* _i2sBufDesc; // dma block descriptors + uint16_t _i2sBufDescCount; // count of block descriptors in _i2sBufDesc + + + // This routine is called as soon as the DMA routine has something to tell us. All we + // handle here is the RX_EOF_INT status, which indicate the DMA has sent a buffer whose + // descriptor has the 'EOF' field set to 1. + // in the case of this code, the second to last state descriptor + static void IRAM_ATTR i2s_slc_isr(void) + { + ETS_SLC_INTR_DISABLE(); + + uint32_t slc_intr_status = SLCIS; + + SLCIC = 0xFFFFFFFF; + + if ((slc_intr_status & SLCIRXEOF) && s_this) + { + switch (s_this->_dmaState) + { + case NeoDmaState_Idle: + break; + + case NeoDmaState_Pending: + { + 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 + (finished_item + 1)->next_link_ptr = s_this->_i2sBufDesc; + + s_this->_dmaState = NeoDmaState_Sending; + } + break; + + case NeoDmaState_Sending: + { + slc_queue_item* finished_item = (slc_queue_item*)SLCRXEDA; + + // the data block had actual data sent + // point last state block to first state block thus + // just looping and not sending the data blocks + (finished_item + 1)->next_link_ptr = finished_item; + + s_this->_dmaState = NeoDmaState_Zeroing; + } + break; + + case NeoDmaState_Zeroing: + s_this->_dmaState = NeoDmaState_Idle; + break; + } + } + + ETS_SLC_INTR_ENABLE(); + } +}; + +template class NeoEsp8266DmaMethodBase : NeoEsp8266DmaMethodCore +{ +public: + typedef NeoNoSettings SettingsObject; + + NeoEsp8266DmaMethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize) + { + uint16_t dmaPixelSize = c_dmaBytesPerPixelBytes * elementSize; + uint16_t dmaSettingsSize = c_dmaBytesPerPixelBytes * settingsSize; + + _i2sBufferSize = pixelCount * dmaPixelSize + dmaSettingsSize; + + _data = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + + _i2sBuffer = static_cast(malloc(_i2sBufferSize)); + // no need to initialize it, it gets overwritten on every send + + // _i2sBuffer[0] = 0b11101000; // debug, 1 bit then 0 bit + + memset(_i2sZeroes, T_SPEED::Level, sizeof(_i2sZeroes)); + + _is2BufMaxBlockSize = (c_maxDmaBlockSize / dmaPixelSize) * dmaPixelSize; + + _i2sBufDescCount = (_i2sBufferSize / _is2BufMaxBlockSize) + 1 + 2; // need two more for state/latch blocks + _i2sBufDesc = (slc_queue_item*)malloc(_i2sBufDescCount * sizeof(slc_queue_item)); + + s_this = this; // store this for the ISR + } + + NeoEsp8266DmaMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + NeoEsp8266DmaMethodBase(pixelCount, elementSize, settingsSize) + { + } + + ~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(_data); + free(_i2sBuffer); + free(_i2sBufDesc); + } + + bool IsReadyToUpdate() const + { + return (_dmaState == NeoDmaState_Idle); + } + + void Initialize() + { + StopDma(); + + pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA + + uint8_t* is2Buffer = _i2sBuffer; + uint32_t is2BufferSize = _i2sBufferSize; + uint16_t indexDesc; + + // prepare main data block decriptors that point into our one static dma buffer + for (indexDesc = 0; indexDesc < (_i2sBufDescCount - 2); indexDesc++) + { + uint32_t blockSize = (is2BufferSize > _is2BufMaxBlockSize) ? _is2BufMaxBlockSize : is2BufferSize; + + _i2sBufDesc[indexDesc].owner = 1; + _i2sBufDesc[indexDesc].eof = 0; // no need to trigger interrupt generally + _i2sBufDesc[indexDesc].sub_sof = 0; + _i2sBufDesc[indexDesc].datalen = blockSize; + _i2sBufDesc[indexDesc].blocksize = blockSize; + _i2sBufDesc[indexDesc].buf_ptr = is2Buffer; + _i2sBufDesc[indexDesc].unused = 0; + _i2sBufDesc[indexDesc].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[indexDesc + 1])); + + is2Buffer += blockSize; + is2BufferSize -= blockSize; + } + + // prepare the two state/latch descriptors + for (; indexDesc < _i2sBufDescCount; indexDesc++) + { + _i2sBufDesc[indexDesc].owner = 1; + _i2sBufDesc[indexDesc].eof = 0; // no need to trigger interrupt generally + _i2sBufDesc[indexDesc].sub_sof = 0; + _i2sBufDesc[indexDesc].datalen = sizeof(_i2sZeroes); + _i2sBufDesc[indexDesc].blocksize = sizeof(_i2sZeroes); + _i2sBufDesc[indexDesc].buf_ptr = _i2sZeroes; + _i2sBufDesc[indexDesc].unused = 0; + _i2sBufDesc[indexDesc].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[indexDesc + 1])); + } + + // the first state block will trigger the interrupt + _i2sBufDesc[indexDesc - 2].eof = 1; + // the last state block will loop to the first state block by defualt + _i2sBufDesc[indexDesc - 1].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[indexDesc - 2])); + + // 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; + + // Configure DMA + SLCC0 &= ~(SLCMM << SLCM); // clear DMA MODE + SLCC0 |= (1 << SLCM); // set DMA MODE to 1 + SLCRXDC |= SLCBINR | SLCBTNR; // enable INFOR_NO_REPLACE and TOKEN_NO_REPLACE + SLCRXDC &= ~(SLCBRXFE | SLCBRXEM | SLCBRXFM); // disable RX_FILL, RX_EOF_MODE and RX_FILL_MODE + + // Feed DMA the 1st buffer desc addr + // To send data to the I2S subsystem, counter-intuitively we use the RXLINK part, not the TXLINK as you might + // 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 + // 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 + // 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 + + ETS_SLC_INTR_ENABLE(); + + //Start transmission + SLCTXL |= SLCTXLS; + SLCRXL |= SLCRXLS; + + I2S_CLK_ENABLE(); + I2SIC = 0x3F; + I2SIE = 0; + + //Reset I2S + I2SC &= ~(I2SRST); + I2SC |= I2SRST; + I2SC &= ~(I2SRST); + + // Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only) + I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM) | (I2SRXFMM << I2SRXFM)); + I2SFC |= I2SDE; //Enable DMA + // 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 | 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 IRAM_ATTR Update(bool) + { + // wait for not actively sending data + while (!IsReadyToUpdate()) + { + yield(); + } + FillBuffers(); + + // toggle state so the ISR reacts + _dmaState = NeoDmaState_Pending; + } + + uint8_t* getData() const + { + return _data; + }; + + size_t getDataSize() const + { + return _sizeData; + } + + void applySettings(const SettingsObject& settings) + { + } + +private: + const size_t _sizeData; // Size of '_data' buffer + uint8_t* _data; // Holds LED color values + + size_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 mulitple states + // buffer size = (24 * (reset time / 50)) / 6 + uint8_t _i2sZeroes[(24L * (T_SPEED::ResetTimeUs / 50L)) / 6L]; + + uint16_t _is2BufMaxBlockSize; // max size based on size of a pixel of a single block + + + void FillBuffers() + { + uint16_t* pDma = (uint16_t*)_i2sBuffer; + uint8_t* pEnd = _data + _sizeData; + for (uint8_t* pData = _data; pData < pEnd; pData++) + { + *(pDma++) = T_SPEED::Convert(((*pData) & 0x0f)); + *(pDma++) = T_SPEED::Convert(((*pData) >> 4) & 0x0f); + } + } + + 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 + SLCRXL &= ~(SLCRXLAM << SLCRXLA); // clear RX descriptor address + + pinMode(c_I2sPin, INPUT); + } + + uint32_t getPixelTime() const + { + return (T_SPEED::ByteSendTimeUs * this->_sizeData); + }; + +}; + + + +// normal +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaWs2812xMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaSk6812Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaTm1814Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaTm1829Method; +typedef NeoEsp8266DmaTm1814Method NeoEsp8266DmaTm1914Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266Dma800KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266Dma400KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaApa106Method; + + +// inverted +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedWs2812xMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedSk6812Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedTm1814Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedTm1829Method; +typedef NeoEsp8266DmaInvertedTm1814Method NeoEsp8266DmaInvertedTm1914Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInverted800KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInverted400KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedApa106Method; + +// Dma method is the default method for Esp8266 +typedef NeoEsp8266DmaWs2812xMethod NeoWs2813Method; +typedef NeoEsp8266DmaWs2812xMethod NeoWs2812xMethod; +typedef NeoEsp8266Dma800KbpsMethod NeoWs2812Method; +typedef NeoEsp8266DmaWs2812xMethod NeoWs2811Method; +typedef NeoEsp8266DmaSk6812Method NeoSk6812Method; +typedef NeoEsp8266DmaTm1814Method NeoTm1814Method; +typedef NeoEsp8266DmaTm1829Method NeoTm1829Method; +typedef NeoEsp8266DmaTm1914Method NeoTm1914Method; +typedef NeoEsp8266DmaSk6812Method NeoLc8812Method; +typedef NeoEsp8266DmaApa106Method NeoApa106Method; + +typedef NeoEsp8266DmaWs2812xMethod Neo800KbpsMethod; +typedef NeoEsp8266Dma400KbpsMethod Neo400KbpsMethod; + +// inverted +typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2813InvertedMethod; +typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2812xInvertedMethod; +typedef NeoEsp8266DmaInverted800KbpsMethod NeoWs2812InvertedMethod; +typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2811InvertedMethod; +typedef NeoEsp8266DmaInvertedSk6812Method NeoSk6812InvertedMethod; +typedef NeoEsp8266DmaInvertedTm1814Method NeoTm1814InvertedMethod; +typedef NeoEsp8266DmaInvertedTm1829Method NeoTm1829InvertedMethod; +typedef NeoEsp8266DmaInvertedTm1914Method NeoTm1914InvertedMethod; +typedef NeoEsp8266DmaInvertedSk6812Method NeoLc8812InvertedMethod; +typedef NeoEsp8266DmaInvertedApa106Method NeoApa106InvertedMethod; + +typedef NeoEsp8266DmaInvertedWs2812xMethod Neo800KbpsInvertedMethod; +typedef NeoEsp8266DmaInverted400KbpsMethod Neo400KbpsInvertedMethod; +#endif diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.cpp b/lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.cpp similarity index 95% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.cpp rename to lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.cpp index cde0c4a4b7..66324b9d58 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.cpp +++ b/lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.cpp @@ -24,12 +24,10 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include "../NeoUtil.h" - #ifdef ARDUINO_ARCH_ESP8266 #include -#include "../NeoSettings.h" +#include "NeoSettings.h" #include "NeoEsp8266UartMethod.h" #include extern "C" @@ -141,9 +139,7 @@ void NeoEsp8266UartInterruptContext::Detach(uint8_t uartNum) ETS_UART_INTR_ENABLE(); } -// The xtos_1int handler calls with param1 as the arg, param2 as a pointer -// to an exception frame in memory. -void IRAM_ATTR NeoEsp8266UartInterruptContext::Isr(void* param, MAYBE_UNUSED void* exceptionFrame) +void IRAM_ATTR NeoEsp8266UartInterruptContext::Isr(void* param) { // make sure this is for us if (param == s_uartInteruptContext) diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.h similarity index 95% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.h rename to lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.h index 073b5edaff..9ef2f4b453 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.h @@ -26,9 +26,8 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #ifdef ARDUINO_ARCH_ESP8266 +#include // 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 @@ -80,7 +79,7 @@ class NeoEsp8266UartInterruptContext : NeoEsp8266UartContext volatile const uint8_t* _asyncBuffEnd; volatile static NeoEsp8266UartInterruptContext* s_uartInteruptContext[2]; - static void IRAM_ATTR Isr(void* param, void* exceptionFrame); + static void IRAM_ATTR Isr(void* param); }; // this template feature class is used a base for all others and contains @@ -165,8 +164,6 @@ class NeoEsp8266UartBase // synchronous uart method // // used by NeoEsp8266UartMethodBase -// T_UARTFEATURE - (UartFeature0 | UartFeature1) -// T_UARTCONTEXT - (NeoEsp8266UartContext | NeoEsp8266UartInterruptContext) // template class NeoEsp8266Uart : public NeoEsp8266UartBase { @@ -221,8 +218,6 @@ template class NeoEsp8266Uart : // every call to NeoPixelBus.Show() and must not be cached. // // used by NeoEsp8266UartMethodBase -// T_UARTFEATURE - (UartFeature0 | UartFeature1) -// T_UARTCONTEXT - (NeoEsp8266UartContext | NeoEsp8266UartInterruptContext) // template class NeoEsp8266AsyncUart : public NeoEsp8266UartBase { @@ -354,11 +349,6 @@ class NeoEsp8266UartInverted // NeoEsp8266UartMethodBase is a light shell arround NeoEsp8266Uart or NeoEsp8266AsyncUart that // implements the methods needed to operate as a NeoPixelBus method. -// -// T_SPEED - (NeoEsp8266UartSpeed*) -// T_BASE - (NeoEsp8266Uart | NeoEsp8266AsyncUart) -// T_INVERT - (NeoEsp8266UartNotInverted | NeoEsp8266UartInverted) -// template class NeoEsp8266UartMethodBase: public T_BASE { @@ -406,12 +396,6 @@ class NeoEsp8266UartMethodBase: public T_BASE this->UpdateUart(maintainBufferConsistency); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return this->_data; @@ -422,7 +406,7 @@ class NeoEsp8266UartMethodBase: public T_BASE return this->_sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -445,7 +429,6 @@ typedef NeoEsp8266UartMethodBase +// ESP32C3 I2S is not supported yet +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +#if !defined(ARDUINO_ARCH_ESP8266) +#include "soc/gpio_periph.h" +#endif + static inline uint32_t getCycleCount(void) { uint32_t ccount; - -#if defined(CONFIG_IDF_TARGET_ESP32C3) - __asm__ __volatile__("csrr %0,0x7e2":"=r" (ccount)); - //ccount = esp_cpu_get_ccount(); -#else __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); -#endif return ccount; } -void IRAM_ATTR neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, - const uint8_t* end, - uint8_t pin, - uint32_t t0h, - uint32_t t1h, - uint32_t period, - size_t sizePixel, - uint32_t tSpacing, - bool invert) +void IRAM_ATTR NeoEspBitBangBase_send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period) { - uint32_t setValue = _BV(pin); - uint32_t clearValue = _BV(pin); + const uint32_t pinRegister = _BV(pin); uint8_t mask = 0x80; uint8_t subpix = *pixels++; - uint8_t element = 0; 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 = t0h; + if (subpix & mask) + { + cyclesBit = t1h; + } + + // after we have done as much work as needed for this next bit + // now wait for the HIGH + while (((cyclesStart = getCycleCount()) - cyclesNext) < period); + + // set pin state #if defined(ARDUINO_ARCH_ESP32) -#if defined(CONFIG_IDF_TARGET_ESP32C3) - volatile uint32_t* setRegister = &GPIO.out_w1ts.val; - volatile uint32_t* clearRegister = &GPIO.out_w1tc.val; - setValue = _BV(pin); - clearValue = _BV(pin); + GPIO.out_w1ts = pinRegister; #else - volatile uint32_t* setRegister = &GPIO.out_w1ts; - volatile uint32_t* clearRegister = &GPIO.out_w1tc; -#endif // defined(CONFIG_IDF_TARGET_ESP32C3) + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); +#endif + + // wait for the LOW + while ((getCycleCount() - cyclesStart) < cyclesBit); + + // reset pin start +#if defined(ARDUINO_ARCH_ESP32) + GPIO.out_w1tc = pinRegister; #else - uint32_t setRegister = PERIPHS_GPIO_BASEADDR + GPIO_OUT_W1TS_ADDRESS; - uint32_t clearRegister = PERIPHS_GPIO_BASEADDR + GPIO_OUT_W1TC_ADDRESS; - if (pin == 16) - { - setRegister = RTC_GPIO_OUT; - clearRegister = RTC_GPIO_OUT; - // reading AND writing RTC_GPIO_OUT is too slow inside the loop so - // we only do writing in the loop - clearValue = (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe); - setValue = clearValue | 1; - } -#endif // defined(ARDUINO_ARCH_ESP32) + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); +#endif - if (invert) - { - std::swap(setRegister, clearRegister); - std::swap(setValue, clearValue); + 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 IRAM_ATTR NeoEspBitBangBase_send_pixels_inv(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period) +{ + 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 (;;) { @@ -104,9 +122,9 @@ void IRAM_ATTR neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, // set pin state #if defined(ARDUINO_ARCH_ESP32) - *setRegister = setValue; + GPIO.out_w1tc = pinRegister; #else - WRITE_PERI_REG(setRegister, setValue); + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); #endif // wait for the LOW @@ -114,9 +132,9 @@ void IRAM_ATTR neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, // reset pin start #if defined(ARDUINO_ARCH_ESP32) - *clearRegister = clearValue; + GPIO.out_w1ts = pinRegister; #else - WRITE_PERI_REG(clearRegister, clearValue); + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); #endif cyclesNext = cyclesStart; @@ -135,22 +153,9 @@ void IRAM_ATTR neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, // reset mask to first bit and get the next byte mask = 0x80; subpix = *pixels++; - - // if pixel spacing is needed - if (tSpacing) - { - element++; - if (element == sizePixel) - { - element = 0; - - // wait for pixel spacing - while ((getCycleCount() - cyclesNext) < tSpacing); - } - } } } } - +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) #endif // defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) diff --git a/lib/NeoPixelBus/src/internal/NeoEspBitBangMethod.h b/lib/NeoPixelBus/src/internal/NeoEspBitBangMethod.h new file mode 100644 index 0000000000..44f8654889 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEspBitBangMethod.h @@ -0,0 +1,381 @@ +/*------------------------------------------------------------------------- +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 +. +-------------------------------------------------------------------------*/ + +#pragma once + +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + +// ESP32C3 I2S is not supported yet +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) + +#if defined(ARDUINO_ARCH_ESP8266) +#include +#endif + +#define CYCLES_LOOPTEST (4) // adjustment due to loop exit test instruction cycles + +class NeoEspSpeedWs2811 +{ +public: + const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us + const static uint32_t T1H = (F_CPU / 1052632 - CYCLES_LOOPTEST); // 0.95us + const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit +}; + +class NeoEspSpeedTm1814 +{ +public: + const static uint32_t T0H = (F_CPU / 2916666 - CYCLES_LOOPTEST); // 0.35us + const static uint32_t T1H = (F_CPU / 1666666 - CYCLES_LOOPTEST); // 0.75us + const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit +}; + +class NeoEspSpeedTm1829 +{ +public: + const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us + const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us + const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit +}; + +class NeoEspSpeed800Mhz +{ +public: + const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us + const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us + const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit +}; + +class NeoEspSpeed400Mhz +{ +public: + const static uint32_t T0H = (F_CPU / 2000000 - CYCLES_LOOPTEST); + const static uint32_t T1H = (F_CPU / 833333 - CYCLES_LOOPTEST); + const static uint32_t Period = (F_CPU / 400000 - CYCLES_LOOPTEST); +}; + +class NeoEspSpeedApa106 +{ +public: + const static uint32_t T0H = (F_CPU / 2857143 - CYCLES_LOOPTEST); // 0.35us + const static uint32_t T1H = (F_CPU / 740741 - CYCLES_LOOPTEST); // 1.35 + const static uint32_t Period = (F_CPU / 606061 - CYCLES_LOOPTEST); // 1.65us +}; + +extern void NeoEspBitBangBase_send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period); +extern void NeoEspBitBangBase_send_pixels_inv(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period); + +class NeoEspPinset +{ +public: + const static uint8_t IdleLevel = LOW; + + inline static void send_pixels_impl(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period) + { + NeoEspBitBangBase_send_pixels(pixels, end, pin, t0h, t1h, period); + } +}; + +class NeoEspPinsetInverted +{ +public: + const static uint8_t IdleLevel = HIGH; + + inline static void send_pixels_impl(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period) + { + NeoEspBitBangBase_send_pixels_inv(pixels, end, pin, t0h, t1h, period); + } +}; + +template class NeoEspBitBangBase +{ +public: + static void send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin) + { + T_PINSET::send_pixels_impl(pixels, end, pin, T_SPEED::T0H, T_SPEED::T1H, T_SPEED::Period); + } +}; + +class NeoEspBitBangSpeedWs2811 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangSpeedWs2812x : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangSpeedSk6812 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 80; +}; + +// normal is inverted signal +class NeoEspBitBangSpeedTm1814 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 200; +}; + +// normal is inverted signal +class NeoEspBitBangSpeedTm1829 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 200; +}; + +class NeoEspBitBangSpeed800Kbps : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangSpeed400Kbps : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangSpeedApa106 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangInvertedSpeedWs2811 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangInvertedSpeedWs2812x : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangInvertedSpeedSk6812 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 80; +}; + +// normal is inverted signal, so inverted is normal +class NeoEspBitBangInvertedSpeedTm1814 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 200; +}; + +// normal is inverted signal, so inverted is normal +class NeoEspBitBangInvertedSpeedTm1829 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 200; +}; + +class NeoEspBitBangInvertedSpeed800Kbps : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangInvertedSpeed400Kbps : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangInvertedSpeedApa106 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +template class NeoEspBitBangMethodBase +{ +public: + typedef NeoNoSettings SettingsObject; + + NeoEspBitBangMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), + _pin(pin) + { + pinMode(pin, OUTPUT); + + _data = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + } + + ~NeoEspBitBangMethodBase() + { + pinMode(_pin, INPUT); + + free(_data); + } + + bool IsReadyToUpdate() const + { + uint32_t delta = micros() - _endTime; + + return (delta >= T_SPEED::ResetTimeUs); + } + + void Initialize() + { + digitalWrite(_pin, T_PINSET::IdleLevel); + + _endTime = micros(); + } + + 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 + // 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 (!IsReadyToUpdate()) + { + yield(); // allows for system yield if needed + } + + // 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(_data, _data + _sizeData, _pin); + +#if defined(ARDUINO_ARCH_ESP32) + portEXIT_CRITICAL(&updateMux); +#else + interrupts(); +#endif + + // save EOD time for latch on next call + _endTime = micros(); + } + + uint8_t* getData() const + { + return _data; + }; + + size_t getDataSize() const + { + return _sizeData; + }; + + void applySettings(const SettingsObject& settings) + { + } + +private: + const size_t _sizeData; // Size of '_data' buffer below + const uint8_t _pin; // output pin number + + uint32_t _endTime; // Latch timing reference + uint8_t* _data; // Holds LED color values +}; + + +#if defined(ARDUINO_ARCH_ESP32) + +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2811Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2812xMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangSk6812Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangTm1814Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangTm1829Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBang800KbpsMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBang400KbpsMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangApa106Method; + +typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2813Method; +typedef NeoEsp32BitBang800KbpsMethod NeoEsp32BitBangWs2812Method; +typedef NeoEsp32BitBangTm1814Method NeoEsp32BitBangTm1914Method; +typedef NeoEsp32BitBangSk6812Method NeoEsp32BitBangLc8812Method; + +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2811InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2812xInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangSk6812InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangTm1814InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangTm1829InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBang800KbpsInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBang400KbpsInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangApa106InvertedMethod; + +typedef NeoEsp32BitBangWs2812xInvertedMethod NeoEsp32BitBangWs2813InvertedMethod; +typedef NeoEsp32BitBang800KbpsInvertedMethod NeoEsp32BitBangWs2812InvertedMethod; +typedef NeoEsp32BitBangTm1814InvertedMethod NeoEsp32BitBangTm1914InvertedMethod; +typedef NeoEsp32BitBangSk6812InvertedMethod NeoEsp32BitBangLc8812InvertedMethod; + +#else + +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2811Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2812xMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangSk6812Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangTm1814Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangTm1829Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBang800KbpsMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBang400KbpsMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangApa106Method; + +typedef NeoEsp8266BitBangWs2812xMethod NeoEsp8266BitBangWs2813Method; +typedef NeoEsp8266BitBang800KbpsMethod NeoEsp8266BitBangWs2812Method; +typedef NeoEsp8266BitBangTm1814Method NeoEsp8266BitBangTm1914Method; +typedef NeoEsp8266BitBangSk6812Method NeoEsp8266BitBangLc8812Method; + +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2811InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2812xInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangSk6812InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangTm1814InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangTm1829InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBang800KbpsInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBang400KbpsInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangApa106InvertedMethod; + +typedef NeoEsp8266BitBangWs2812xInvertedMethod NeoEsp8266BitBangWs2813InvertedMethod; +typedef NeoEsp8266BitBang800KbpsInvertedMethod NeoEsp8266BitBangWs2812InvertedMethod; +typedef NeoEsp8266BitBangTm1814InvertedMethod NeoEsp8266BitBangTm1914InvertedMethod; +typedef NeoEsp8266BitBangSk6812InvertedMethod NeoEsp8266BitBangLc8812InvertedMethod; + +#endif + +// ESP bitbang doesn't have defaults and should avoided except for testing + +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +#endif // defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.cpp b/lib/NeoPixelBus/src/internal/NeoGamma.cpp similarity index 63% rename from lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.cpp rename to lib/NeoPixelBus/src/internal/NeoGamma.cpp index f1d8782527..fdff9e784f 100644 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.cpp +++ b/lib/NeoPixelBus/src/internal/NeoGamma.cpp @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoGamma classes are used to correct RGB colors for human eye gamma levels +NeoPixelGamma class is used to correct RGB colors for human eye gamma levels Written by Michael C. Miller. @@ -25,24 +25,23 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include -#include "../NeoUtil.h" -#include "NeoGammaTableMethod.h" +#include "NeoPixelBus.h" const uint8_t NeoGammaTableMethod::_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, // 32 - 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, // 48 - 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, // 64 - 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, // 80 - 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, // 96 - 29, 30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, // 112 - 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, // 128 - 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, // 144 - 71, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 87, 88, 89, // 160 - 90, 91, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, // 176 - 111, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, // 192 - 135, 137, 138, 140, 142, 143, 145, 146, 148, 150, 151, 153, 155, 156, 158, 160, // 208 - 162, 163, 165, 167, 168, 170, 172, 174, 176, 177, 179, 181, 183, 185, 187, 189, // 224 - 190, 192, 194, 196, 198, 200, 202, 203, 206, 207, 210, 212, 214, 216, 218, 220, // 240 - 222, 224, 226, 228, 230, 232, 234, 237, 239, 241, 243, 245, 247, 250, 251, 255 // 256 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, + 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, + 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, + 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, + 29, 30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, + 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, + 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 86, 87, 88, 89, + 91, 92, 93, 94, 96, 97, 98, 100, 101, 102, 104, 105, 106, 108, 109, 110, + 112, 113, 115, 116, 118, 119, 121, 122, 123, 125, 126, 128, 130, 131, 133, 134, + 136, 137, 139, 140, 142, 144, 145, 147, 149, 150, 152, 154, 155, 157, 159, 160, + 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 187, 189, + 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, + 223, 225, 227, 229, 231, 233, 235, 238, 240, 242, 244, 246, 248, 251, 253, 255 }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaEquationMethod.h b/lib/NeoPixelBus/src/internal/NeoGamma.h similarity index 60% rename from lib/NeoPixelBus/src/internal/colors/NeoGammaEquationMethod.h rename to lib/NeoPixelBus/src/internal/NeoGamma.h index 19ce6879ca..4aaf68e4a8 100644 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaEquationMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoGamma.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoGammaEquationMethod class is used to correct RGB colors for human eye gamma levels equally +NeoGamma class is used to correct RGB colors for human eye gamma levels equally across all color channels Written by Michael C. Miller. @@ -26,7 +26,6 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once - // NeoGammaEquationMethod uses no memory but is slower than NeoGammaTableMethod class NeoGammaEquationMethod { @@ -35,10 +34,41 @@ class NeoGammaEquationMethod { return static_cast(255.0f * NeoEase::Gamma(value / 255.0f) + 0.5f); } - static uint16_t Correct(uint16_t value) +}; + +// NeoGammaTableMethod uses 256 bytes of memory, but is significantly faster +class NeoGammaTableMethod +{ +public: + static uint8_t Correct(uint8_t value) + { + return _table[value]; + } + +private: + static const uint8_t _table[256]; +}; + + +// use one of the method classes above as a converter for this template class +template class NeoGamma +{ +public: + RgbColor Correct(const RgbColor& original) + { + return RgbColor(T_METHOD::Correct(original.R), + T_METHOD::Correct(original.G), + T_METHOD::Correct(original.B)); + } + + RgbwColor Correct(const RgbwColor& original) { - return static_cast(65535.0f * NeoEase::Gamma(value / 65535.0f) + 0.5f); + return RgbwColor(T_METHOD::Correct(original.R), + T_METHOD::Correct(original.G), + T_METHOD::Correct(original.B), + T_METHOD::Correct(original.W) ); } }; + diff --git a/lib/NeoPixelBus/src/internal/colors/NeoHueBlend.h b/lib/NeoPixelBus/src/internal/NeoHueBlend.h similarity index 100% rename from lib/NeoPixelBus/src/internal/colors/NeoHueBlend.h rename to lib/NeoPixelBus/src/internal/NeoHueBlend.h diff --git a/lib/NeoPixelBus/src/internal/NeoMethods.h b/lib/NeoPixelBus/src/internal/NeoMethods.h deleted file mode 100644 index 27ac2bcfcd..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoMethods.h +++ /dev/null @@ -1,71 +0,0 @@ -/*------------------------------------------------------------------------- -NeoMethods includes all the classes that describe pulse/data sending methods using -bitbang, SPI, or other platform specific hardware peripherl support. - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -// Generic Two Wire (clk and data) methods -// -#include "methods/DotStarGenericMethod.h" -#include "methods/Lpd8806GenericMethod.h" -#include "methods/Lpd6803GenericMethod.h" -#include "methods/Ws2801GenericMethod.h" -#include "methods/P9813GenericMethod.h" -#include "methods/Tlc5947GenericMethod.h" -#include "methods/Sm16716GenericMethod.h" -#include "methods/Mbi6033GenericMethod.h" - -// Platform specific and One Wire (data) methods -// -#if defined(ARDUINO_ARCH_ESP8266) - -#include "methods/NeoEsp8266DmaMethod.h" -#include "methods/NeoEsp8266I2sDmx512Method.h" -#include "methods/NeoEsp8266UartMethod.h" -#include "methods/NeoEspBitBangMethod.h" - -#elif defined(ARDUINO_ARCH_ESP32) - -#include "methods/NeoEsp32I2sMethod.h" -#include "methods/NeoEsp32RmtMethod.h" -#include "methods/NeoEspBitBangMethod.h" -#include "methods/DotStarEsp32DmaSpiMethod.h" -#include "methods/NeoEsp32I2sXMethod.h" - -#elif defined(ARDUINO_ARCH_NRF52840) // must be before __arm__ - -#include "methods/NeoNrf52xMethod.h" - -#elif defined(__arm__) // must be before ARDUINO_ARCH_AVR due to Teensy incorrectly having it set - -#include "methods/NeoArmMethod.h" - -#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) - -#include "methods/NeoAvrMethod.h" - -#else -#error "Platform Currently Not Supported, please add an Issue at Github/Makuna/NeoPixelBus" -#endif diff --git a/lib/NeoPixelBus/src/internal/topologies/NeoMosaic.h b/lib/NeoPixelBus/src/internal/NeoMosaic.h similarity index 91% rename from lib/NeoPixelBus/src/internal/topologies/NeoMosaic.h rename to lib/NeoPixelBus/src/internal/NeoMosaic.h index c42ba0d404..551bd53773 100644 --- a/lib/NeoPixelBus/src/internal/topologies/NeoMosaic.h +++ b/lib/NeoPixelBus/src/internal/NeoMosaic.h @@ -1,5 +1,7 @@ +#pragma once + /*------------------------------------------------------------------------- -NeoMosaic provides a mapping feature of a 2d cordinate to linear 1d cordinate +Mosiac provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map tiles of matricies of NeoPixels to a index on the NeoPixelBus where the the matricies use a set of prefered topology and the tiles of those matricies use the RowMajorAlternating layout @@ -26,7 +28,6 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#pragma once //----------------------------------------------------------------------------- @@ -35,12 +36,6 @@ License along with NeoPixel. If not, see // the tiles by using different rotations of the layout at specific locations // // T_LAYOUT = the layout used for matrix panel (rotation is ignored) -// One of the following classes and their rotated variants -// RowMajorLayout -// ColumnMajorLayout -// RowMajorAlternatingLayout -// ColumnMajorAlternatingLayout -// // // NOTE: The tiles in the mosaic are always laid out using RowMajorAlternating // @@ -63,7 +58,7 @@ template class NeoMosaic uint16_t totalWidth = getWidth(); uint16_t totalHeight = getHeight(); - if (x >= static_cast(totalWidth)) + if (x >= totalWidth) { x = totalWidth - 1; } @@ -72,7 +67,7 @@ template class NeoMosaic x = 0; } - if (y >= static_cast(totalHeight)) + if (y >= totalHeight) { y = totalHeight - 1; } @@ -112,8 +107,7 @@ template class NeoMosaic uint16_t totalWidth = getWidth(); uint16_t totalHeight = getHeight(); - if (x < 0 || x >= static_cast(totalWidth) || - y < 0 || y >= static_cast(totalHeight)) + if (x < 0 || x >= totalWidth || y < 0 || y >= totalHeight) { return NeoTopologyHint_OutOfBounds; } diff --git a/lib/NeoPixelBus/src/internal/methods/NeoNrf52xMethod.h b/lib/NeoPixelBus/src/internal/NeoNrf52xMethod.h similarity index 95% rename from lib/NeoPixelBus/src/internal/methods/NeoNrf52xMethod.h rename to lib/NeoPixelBus/src/internal/NeoNrf52xMethod.h index 5d085d1e32..da97fe7752 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoNrf52xMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoNrf52xMethod.h @@ -29,8 +29,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #if defined(ARDUINO_ARCH_NRF52840) const uint16_t c_dmaBytesPerDataByte = 8 * sizeof(nrf_pwm_values_common_t); // bits * bytes to represent pulse @@ -402,12 +400,6 @@ template class NeoNrf52xMethodBase dmaStart(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -418,7 +410,7 @@ template class NeoNrf52xMethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -526,7 +518,6 @@ template class NeoNrf52xMethodBase // normal typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwmNSk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwmNTm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwmNTm1829Method; @@ -538,7 +529,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Sk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Tm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Tm1829Method; @@ -550,7 +540,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Sk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Tm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Tm1829Method; @@ -562,7 +551,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Sk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Tm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Tm1829Method; @@ -575,7 +563,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw #if defined(NRF_PWM3) typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Sk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Tm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Tm1829Method; @@ -589,7 +576,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw // inverted typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwmNSk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwmNTm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwmNTm1829InvertedMethod; @@ -601,7 +587,6 @@ typedef NeoNrf52xMethodBase Neo typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Sk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Tm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Tm1829InvertedMethod; @@ -613,7 +598,6 @@ typedef NeoNrf52xMethodBase Neo typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Sk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Tm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Tm1829InvertedMethod; @@ -625,7 +609,6 @@ typedef NeoNrf52xMethodBase Neo typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Sk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Tm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Tm1829InvertedMethod; @@ -638,7 +621,6 @@ typedef NeoNrf52xMethodBase Neo #if defined(NRF_PWM3) typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Sk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Tm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Tm1829InvertedMethod; @@ -654,7 +636,6 @@ typedef NeoNrf52xPwm2Ws2812xMethod NeoWs2813Method; typedef NeoNrf52xPwm2Ws2812xMethod NeoWs2812xMethod; typedef NeoNrf52xPwm2800KbpsMethod NeoWs2812Method; typedef NeoNrf52xPwm2Ws2812xMethod NeoWs2811Method; -typedef NeoNrf52xPwm2Ws2812xMethod NeoWs2816Method; typedef NeoNrf52xPwm2Sk6812Method NeoSk6812Method; typedef NeoNrf52xPwm2Tm1814Method NeoTm1814Method; typedef NeoNrf52xPwm2Tm1829Method NeoTm1829Method; @@ -670,7 +651,6 @@ typedef NeoNrf52xPwm2Ws2812xInvertedMethod NeoWs2813InvertedMethod; typedef NeoNrf52xPwm2Ws2812xInvertedMethod NeoWs2812xInvertedMethod; typedef NeoNrf52xPwm2Ws2812xInvertedMethod NeoWs2811InvertedMethod; typedef NeoNrf52xPwm2800KbpsInvertedMethod NeoWs2812InvertedMethod; -typedef NeoNrf52xPwm2Ws2812xInvertedMethod NeoWs2816InvertedMethod; typedef NeoNrf52xPwm2Sk6812InvertedMethod NeoSk6812InvertedMethod; typedef NeoNrf52xPwm2Tm1814InvertedMethod NeoTm1814InvertedMethod; typedef NeoNrf52xPwm2Tm1829InvertedMethod NeoTm1829InvertedMethod; diff --git a/lib/NeoPixelBus/src/internal/animations/NeoPixelAnimator.cpp b/lib/NeoPixelBus/src/internal/NeoPixelAnimator.cpp similarity index 99% rename from lib/NeoPixelBus/src/internal/animations/NeoPixelAnimator.cpp rename to lib/NeoPixelBus/src/internal/NeoPixelAnimator.cpp index b97565fa7f..55e74ae218 100644 --- a/lib/NeoPixelBus/src/internal/animations/NeoPixelAnimator.cpp +++ b/lib/NeoPixelBus/src/internal/NeoPixelAnimator.cpp @@ -24,7 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include #include "NeoPixelBus.h" #include "NeoPixelAnimator.h" diff --git a/lib/NeoPixelBus/src/internal/methods/NeoPixelAvr.c b/lib/NeoPixelBus/src/internal/NeoPixelAvr.c similarity index 81% rename from lib/NeoPixelBus/src/internal/methods/NeoPixelAvr.c rename to lib/NeoPixelBus/src/internal/NeoPixelAvr.c index e6572c6747..84e989388b 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoPixelAvr.c +++ b/lib/NeoPixelBus/src/internal/NeoPixelAvr.c @@ -466,10 +466,7 @@ void send_data_12mhz_800_PortB(uint8_t* data, size_t sizeData, uint8_t pinMask) [lo] "r" (lo)); } -void send_data_12mhz_400(uint8_t* data, - size_t sizeData, - volatile uint8_t* port, - uint8_t pinMask) +void send_data_12mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { volatile uint16_t i = (uint16_t)sizeData; // Loop counter volatile uint8_t* ptr = data; // Pointer to next byte @@ -480,8 +477,7 @@ void send_data_12mhz_400(uint8_t* data, // 30 instruction clocks per bit: HHHHHHxxxxxxxxxLLLLLLLLLLLLLLL // ST instructions: ^ ^ ^ (T=0,6,15) - volatile uint8_t next; - volatile uint8_t bit; + volatile uint8_t next, bit; hi = *port | pinMask; lo = *port & ~pinMask; @@ -524,7 +520,7 @@ void send_data_12mhz_400(uint8_t* data, [ptr] "e" (ptr)); } -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000UL) // 16Mhz CPU +#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU void send_data_16mhz_800(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { @@ -581,10 +577,7 @@ void send_data_16mhz_800(uint8_t* data, size_t sizeData, volatile uint8_t* port, [lo] "r" (lo)); } -void send_data_16mhz_400(uint8_t* data, - size_t sizeData, - volatile uint8_t* port, - uint8_t pinMask) +void send_data_16mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { volatile size_t i = sizeData; // Loop counter volatile uint8_t* ptr = data; // Pointer to next byte @@ -597,8 +590,7 @@ void send_data_16mhz_400(uint8_t* data, // 40 inst. clocks per bit: HHHHHHHHxxxxxxxxxxxxLLLLLLLLLLLLLLLLLLLL // ST instructions: ^ ^ ^ (T=0,8,20) - volatile uint8_t next; - volatile uint8_t bit; + volatile uint8_t next, bit; hi = *port | pinMask; lo = *port & ~pinMask; @@ -649,137 +641,6 @@ void send_data_16mhz_400(uint8_t* data, [lo] "r" (lo)); } -// 0 400us (320-480) -// 1 1100us (960-1200) -// w 1600us -void send_data_16mhz_600(uint8_t* data, - size_t sizeData, - volatile uint8_t* port, - uint8_t pinMask) -{ - volatile size_t i = sizeData; // Loop counter - volatile uint8_t* ptr = data; // Pointer to next byte - volatile uint8_t b = *ptr++; // Current byte value - volatile uint8_t hi; // PORT w/output bit set high - volatile uint8_t lo; // PORT w/output bit set low - - // The 633 KHz clock on 16 MHz MCU. - // - // 25 inst. clocks per bit: HHHHHHHHxxxxxxxxxxLLLLLLLL - // ST instructions: ^ ^ ^ (T=0,8,18) - - - volatile uint8_t next; - volatile uint8_t bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile( - "head40:" "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte] , 7" "\n\t" // 1-2 if(b & 0b10000000) - "mov %[next] , %[hi]" "\n\t" // 0-1 next = hi (T = 4) - "rjmp .+0" "\n\t" // 2 nop nop (T = 6) - "st %a[port], %[next]" "\n\t" // 2 PORT = next (T = 8) - "mov %[next] , %[lo]" "\n\t" // 1 next = lo (T = 9) - "rjmp .+0" "\n\t" // 2 nop nop (T = 11) - "rjmp .+0" "\n\t" // 2 nop nop (T = 13) - "rjmp .+0" "\n\t" // 2 nop nop (T = 15) - "dec %[bit]" "\n\t" // 1 bit-- (T = 16) - "breq nextbyte40" "\n\t" // 1-2 if(bit == 0) - "st %a[port], %[lo]" "\n\t" // 2 PORT = lo (T = 18) duplicate here improves high length for non byte boundary - "rol %[byte]" "\n\t" // 1 b <<= 1 (T = 21) - "nop" "\n\t" // 1 nop (T = 22) - "rjmp .+0" "\n\t" // 2 nop nop (T = 24) - "rjmp head40" "\n\t" // 2 -> head40 (next bit out) - "nextbyte40:" "\n\t" // (T = 18) - "st %a[port], %[lo]" "\n\t" // 2 PORT = lo (T = 20) duplicate here improves high length while reducing interbyte - "ldi %[bit] , 8" "\n\t" // 1 bit = 8 (T = 21) - "ld %[byte] , %a[ptr]+" "\n\t" // 2 b = *ptr++ (T = 23) - "sbiw %[count], 1" "\n\t" // 2 i-- (T = 25) - "brne head40" "\n" // 1-2 if(i != 0) -> (next byte) - : [port] "+e" (port), - [byte] "+r" (b), - [bit] "+r" (bit), - [next] "+r" (next), - [count] "+w" (i) - : [ptr] "e" (ptr), - [hi] "r" (hi), - [lo] "r" (lo)); -} - -#elif (F_CPU >= 31000000UL) && (F_CPU <= 35000000UL) // 32Mhz CPU - -void send_data_32mhz(uint8_t* data, - size_t sizeData, - volatile uint8_t* port, - uint8_t pinMask, - const uint8_t cycleTiming) -{ - volatile uint16_t i = (uint16_t)sizeData; // Loop counter - volatile uint8_t* ptr = data; // Pointer to next byte - volatile uint8_t b = *ptr++; // Current byte value - volatile uint8_t hi; // PORT w/output bit set high - volatile uint8_t lo; // PORT w/output bit set low - - volatile uint8_t next; - volatile uint8_t bit; - volatile uint8_t cycle; - volatile uint8_t cycleCount; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - cycleCount = cycleTiming; - - asm volatile( - "head20:" "\n\t" // Clk Pseudocode - "st %a[port], %[hi]" "\n\t" // 2 PORT = hi - "sbrc %[byte], 7" "\n\t" // 1-2 if(b & 128) - "mov %[next], %[hi]" "\n\t" // 0-1 next = hi - "mov %[cycle], %[cycleCount]" "\n\t" // 0-1 cycle = shortCycle - "cycleLoop1:" "\n\t" - "dec %[cycle]" "\n\t" // 1 cycle-- - "brne cycleLoop1" "\n\t" // 2 if(cycle != 0) -> (cycleLoop1) - "st %a[port], %[next]" "\n\t" // 2 PORT = next - "mov %[cycle], %[cycleCount]" "\n\t" // 0-1 cycle = shortCycle - "cycleLoop2:" "\n\t" - "dec %[cycle]" "\n\t" // 1 cycle-- - "brne cycleLoop2" "\n\t" // 2 if(cycle != 0) -> (cycleLoop2) - "rjmp .+0" "\n\t" // 2 nop nop (timing tuning) - "st %a[port], %[lo]" "\n\t" // 2 PORT = lo - "mov %[next] , %[lo]" "\n\t" // 1 next = lo - "mov %[cycle], %[cycleCount]" "\n\t" // 0-1 cycle = shortCycle - "cycleLoop3:" "\n\t" - "dec %[cycle]" "\n\t" // 1 cycle-- - "brne cycleLoop3" "\n\t" // 2 if(cycle != 0) -> (cycleLoop3) - "dec %[bit]" "\n\t" // 1 bit-- - "breq nextbyte20" "\n\t" // 1-2 if(bit == 0) (from dec above) - "rol %[byte]" "\n\t" // 1 b <<= 1 (T = 15) - "rjmp head20" "\n\t" // 2 -> head20 (next bit out) - "nextbyte20:" "\n\t" // (T = 15) - "ldi %[bit] , 8" "\n\t" // 1 bit = 8 (T = 16) - "ld %[byte] , %a[ptr]+" "\n\t" // 2 b = *ptr++ (T = 18) - "sbiw %[count], 1" "\n\t" // 2 i-- (T = 38) - "brne head20" "\n" // 2 if(i != 0) -> (next byte) - // outputs - : [port] "+e" (port), - [byte] "+r" (b), - [bit] "+r" (bit), - [next] "+r" (next), - [cycle] "+r" (cycle), - [count] "+w" (i) - // inputs - : [ptr] "e" (ptr), - [hi] "r" (hi), - [lo] "r" (lo), - [cycleCount] "r" (cycleCount)); -} - #else #error "CPU SPEED NOT SUPPORTED" #endif diff --git a/lib/NeoPixelBus/src/internal/topologies/NeoRingTopology.h b/lib/NeoPixelBus/src/internal/NeoRingTopology.h similarity index 84% rename from lib/NeoPixelBus/src/internal/topologies/NeoRingTopology.h rename to lib/NeoPixelBus/src/internal/NeoRingTopology.h index 970de02c18..7255a97e38 100644 --- a/lib/NeoPixelBus/src/internal/topologies/NeoRingTopology.h +++ b/lib/NeoPixelBus/src/internal/NeoRingTopology.h @@ -1,3 +1,5 @@ +#pragma once + /*------------------------------------------------------------------------- NeoRingTopology provides a mapping feature of a 2d polar cordinate to a linear 1d cordinate. @@ -26,26 +28,6 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#pragma once - -// NeoRingTopology - -// -// T_LAYOUT - a user provided class that contains the following members with -// the Rings[] initialized with the starting index of each ring and -// one extra entry for the total count (example below). -// Other methods and members can exist to intialize a dynamic layout as needed. -// -// class RingsLayout -// { -// protected: -// const uint16_t Rings[] = { 0, 1, 7, 19, 35, 59, PixelCount }; -// -// uint8_t _ringCount() const -// { -// return sizeof(Rings) / sizeof(Rings[0]); -// } -// }; -// template class NeoRingTopology : public T_LAYOUT { diff --git a/lib/NeoPixelBus/src/internal/NeoSegmentFeatures.h b/lib/NeoPixelBus/src/internal/NeoSegmentFeatures.h new file mode 100644 index 0000000000..0198a838db --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoSegmentFeatures.h @@ -0,0 +1,216 @@ +/*------------------------------------------------------------------------- +NeoSegmentFeatures provides feature classes to describe seven segment display +elements for NeoPixelBus template class + +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 +. +-------------------------------------------------------------------------*/ +#pragma once + +class Neo9Elements +{ +public: + static const size_t PixelSize = 9; // three 3 element + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + for (uint8_t iElement = 0; iElement < PixelSize; iElement++) + { + *pPixelDest++ = pPixelSrc[iElement]; + } + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + } + } + + typedef SevenSegDigit ColorObject; +}; + +class Neo9ElementsNoSettings : public Neo9Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +// Abcdefgps byte order +class NeoAbcdefgSegmentFeature : public Neo9ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint8_t commonSize = (PixelSize < color.SegmentCount) ? PixelSize : color.SegmentCount; + for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) + { + *p++ = color.Segment[iSegment]; + } + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint8_t commonSize = (PixelSize < color.SegmentCount) ? PixelSize : color.SegmentCount; + + for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) + { + color.Segment[iSegment] = *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); + uint8_t commonSize = (PixelSize < color.SegmentCount) ? PixelSize : color.SegmentCount; + + for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) + { + color.Segment[iSegment] = pgm_read_byte(p++); + } + + return color; + } + +}; + + +// BACEDF.G+ byte order +class NeoBacedfpgsSegmentFeature : public Neo9ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + // Segment Digit is Abcdefgps order + *p++ = color.Segment[LedSegment_B]; + *p++ = color.Segment[LedSegment_A]; + *p++ = color.Segment[LedSegment_C]; + + *p++ = color.Segment[LedSegment_E]; + *p++ = color.Segment[LedSegment_D]; + *p++ = color.Segment[LedSegment_F]; + + *p++ = color.Segment[LedSegment_Decimal]; + *p++ = color.Segment[LedSegment_G]; + *p++ = color.Segment[LedSegment_Custom]; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.Segment[LedSegment_B] = *p++; + color.Segment[LedSegment_A] = *p++; + color.Segment[LedSegment_C] = *p++; + + color.Segment[LedSegment_E] = *p++; + color.Segment[LedSegment_D] = *p++; + color.Segment[LedSegment_F] = *p++; + + color.Segment[LedSegment_Decimal] = *p++; + color.Segment[LedSegment_G] = *p++; + color.Segment[LedSegment_Custom] = *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.Segment[LedSegment_B] = pgm_read_byte(p++); + color.Segment[LedSegment_A] = pgm_read_byte(p++); + color.Segment[LedSegment_C] = pgm_read_byte(p++); + + color.Segment[LedSegment_E] = pgm_read_byte(p++); + color.Segment[LedSegment_D] = pgm_read_byte(p++); + color.Segment[LedSegment_F] = pgm_read_byte(p++); + + color.Segment[LedSegment_Decimal] = pgm_read_byte(p++); + color.Segment[LedSegment_G] = pgm_read_byte(p++); + color.Segment[LedSegment_Custom] = pgm_read_byte(p++); + + return color; + } + +}; + +typedef NeoBacedfpgsSegmentFeature SevenSegmentFeature; // Abcdefg order is default \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoSettings.h b/lib/NeoPixelBus/src/internal/NeoSettings.h index 3835d6a045..1af9f82b1f 100644 --- a/lib/NeoPixelBus/src/internal/NeoSettings.h +++ b/lib/NeoPixelBus/src/internal/NeoSettings.h @@ -39,26 +39,9 @@ class NeoRgbCurrentSettings { } - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return RedTenthMilliAmpere; - case 1: - return GreenTenthMilliAmpere; - default: - return BlueTenthMilliAmpere; - } - } - - const uint16_t RedTenthMilliAmpere; // in 1/10th ma - const uint16_t GreenTenthMilliAmpere; // in 1/10th ma - const uint16_t BlueTenthMilliAmpere; // in 1/10th ma + uint16_t RedTenthMilliAmpere; // in 1/10th ma + uint16_t GreenTenthMilliAmpere; // in 1/10th ma + uint16_t BlueTenthMilliAmpere; // in 1/10th ma }; class NeoRgbwCurrentSettings @@ -68,71 +51,12 @@ class NeoRgbwCurrentSettings RedTenthMilliAmpere(red), GreenTenthMilliAmpere(green), BlueTenthMilliAmpere(blue), - WhiteTenthMilliAmpere(white) - { - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return RedTenthMilliAmpere; - case 1: - return GreenTenthMilliAmpere; - case 2: - return BlueTenthMilliAmpere; - default: - return WhiteTenthMilliAmpere; - } - } - - const uint16_t RedTenthMilliAmpere; // in 1/10th ma - const uint16_t GreenTenthMilliAmpere; // in 1/10th ma - const uint16_t BlueTenthMilliAmpere; // in 1/10th ma - const uint16_t WhiteTenthMilliAmpere; // in 1/10th ma -}; - -class NeoRgbwwCurrentSettings -{ -public: - NeoRgbwwCurrentSettings(uint16_t red, uint16_t green, uint16_t blue, uint16_t warmWhite, uint16_t coolWhite) : - RedTenthMilliAmpere(red), - GreenTenthMilliAmpere(green), - BlueTenthMilliAmpere(blue), - WarmWhiteTenthMilliAmpere(warmWhite), - CoolWhiteTenthMilliAmpere(coolWhite) - { - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const + WhiteCurrent(white) { - switch (idx) - { - case 0: - return RedTenthMilliAmpere; - case 1: - return GreenTenthMilliAmpere; - case 2: - return BlueTenthMilliAmpere; - case 3: - return WarmWhiteTenthMilliAmpere; - default: - return CoolWhiteTenthMilliAmpere; - } } - const uint16_t RedTenthMilliAmpere; // in 1/10th ma - const uint16_t GreenTenthMilliAmpere; // in 1/10th ma - const uint16_t BlueTenthMilliAmpere; // in 1/10th ma - const uint16_t WarmWhiteTenthMilliAmpere; // in 1/10th ma - const uint16_t CoolWhiteTenthMilliAmpere; // in 1/10th ma + uint16_t RedTenthMilliAmpere; // in 1/10th ma + uint16_t GreenTenthMilliAmpere; // in 1/10th ma + uint16_t BlueTenthMilliAmpere; // in 1/10th ma + uint16_t WhiteCurrent; // in 1/10th ma }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoVerticalSpriteSheet.h b/lib/NeoPixelBus/src/internal/NeoSpriteSheet.h similarity index 97% rename from lib/NeoPixelBus/src/internal/buffers/NeoVerticalSpriteSheet.h rename to lib/NeoPixelBus/src/internal/NeoSpriteSheet.h index bc1885f13c..73fdde3d66 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoVerticalSpriteSheet.h +++ b/lib/NeoPixelBus/src/internal/NeoSpriteSheet.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoVerticalSpriteSheet +NeoPixel library Written by Michael C. Miller. @@ -25,10 +25,7 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -// T_BUFFER_METHOD - one of -// NeoBufferMethod -// NeoBufferProgmemMethod -// + template class NeoVerticalSpriteSheet { public: diff --git a/lib/NeoPixelBus/src/internal/topologies/NeoTiles.h b/lib/NeoPixelBus/src/internal/NeoTiles.h similarity index 91% rename from lib/NeoPixelBus/src/internal/topologies/NeoTiles.h rename to lib/NeoPixelBus/src/internal/NeoTiles.h index d614e4a633..2c0ca8338d 100644 --- a/lib/NeoPixelBus/src/internal/topologies/NeoTiles.h +++ b/lib/NeoPixelBus/src/internal/NeoTiles.h @@ -1,3 +1,5 @@ +#pragma once + /*------------------------------------------------------------------------- NeoTiles provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map tiles of matricies of NeoPixels to a index on the NeoPixelBus @@ -26,18 +28,13 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#pragma once //----------------------------------------------------------------------------- // class NeoTiles // Simple template Tile layout class // T_MATRIX_LAYOUT = the layout used on the pixel matrix panel (a tile) // T_TILE_LAYOUT = the layout used for the tiles. -// one of the following classes and their rotated variants -// RowMajorLayout -// ColumnMajorLayout -// RowMajorAlternatingLayout -// ColumnMajorAlternatingLayout +// //----------------------------------------------------------------------------- template class NeoTiles { @@ -55,7 +52,7 @@ template class NeoTiles uint16_t totalWidth = getWidth(); uint16_t totalHeight = getHeight(); - if (x >= static_cast(totalWidth)) + if (x >= totalWidth) { x = totalWidth - 1; } @@ -64,7 +61,7 @@ template class NeoTiles x = 0; } - if (y >= static_cast(totalHeight)) + if (y >= totalHeight) { y = totalHeight - 1; } @@ -104,8 +101,7 @@ template class NeoTiles uint16_t totalWidth = getWidth(); uint16_t totalHeight = getHeight(); - if (x < 0 || x >= static_cast(totalWidth) || - y < 0 || y >= static_cast(totalHeight)) + if (x < 0 || x >= totalWidth || y < 0 || y >= totalHeight) { return NeoTopologyHint_OutOfBounds; } diff --git a/lib/NeoPixelBus/src/internal/features/NeoTm1814Features.h b/lib/NeoPixelBus/src/internal/NeoTm1814ColorFeatures.h similarity index 54% rename from lib/NeoPixelBus/src/internal/features/NeoTm1814Features.h rename to lib/NeoPixelBus/src/internal/NeoTm1814ColorFeatures.h index 41ea38f828..00d0dfa371 100644 --- a/lib/NeoPixelBus/src/internal/features/NeoTm1814Features.h +++ b/lib/NeoPixelBus/src/internal/NeoTm1814ColorFeatures.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoTm1814Features provides feature classes to describe color order and +NeoTm1814ColorFeatures provides feature classes to describe color order and color depth for NeoPixelBus template class specific to the TM1814 chip Written by Michael C. Miller. @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -#include "../NeoUtil.h" - class NeoTm1814Settings : public NeoRgbwCurrentSettings { public: @@ -53,26 +51,21 @@ class NeoTm1814Settings : public NeoRgbwCurrentSettings } }; -template -class NeoElementsTm1814Settings +class Neo4ElementsTm1814Settings : public Neo4Elements { -private: - const static uint16_t EncodeDivisor = 5; - public: typedef NeoTm1814Settings SettingsObject; static const size_t SettingsSize = 8; - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) + static void applySettings(uint8_t* pData, const SettingsObject& settings) { - // settings are at the front of the data stream uint8_t* pSet = pData; // C1 - *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_1]) - SettingsObject::MinCurrent) / EncodeDivisor; - *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_2]) - SettingsObject::MinCurrent) / EncodeDivisor; - *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_3]) - SettingsObject::MinCurrent) / EncodeDivisor; - *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_4]) - SettingsObject::MinCurrent) / EncodeDivisor; + *pSet++ = (SettingsObject::LimitCurrent(settings.WhiteCurrent) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.RedTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.GreenTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.BlueTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; uint8_t* pC1 = pData; @@ -83,23 +76,56 @@ class NeoElementsTm1814Settings } } - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) + static uint8_t* pixels(uint8_t* pData) { - // settings are at the front of the data stream return pData + SettingsSize; } - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) + static const uint8_t* pixels(const uint8_t* pData) { - // settings are at the front of the data stream return pData + SettingsSize; } }; -class NeoWrgbTm1814Feature : - public Neo4ByteFeature, - public NeoElementsTm1814Settings -{ +class NeoWrgbTm1814Feature : public Neo4ElementsTm1814Settings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.W; + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = *p++; + 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++); + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + }; diff --git a/lib/NeoPixelBus/src/internal/features/NeoTm1914Features.h b/lib/NeoPixelBus/src/internal/NeoTm1914ColorFeatures.h similarity index 53% rename from lib/NeoPixelBus/src/internal/features/NeoTm1914Features.h rename to lib/NeoPixelBus/src/internal/NeoTm1914ColorFeatures.h index 3a72a0ec40..52bc03d181 100644 --- a/lib/NeoPixelBus/src/internal/features/NeoTm1914Features.h +++ b/lib/NeoPixelBus/src/internal/NeoTm1914ColorFeatures.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoTm1914Features provides feature classes to describe color order and +NeoTm1914ColorFeatures provides feature classes to describe color order and color depth for NeoPixelBus template class specific to the TM1914 chip Written by Michael C. Miller. @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -#include "../NeoUtil.h" - enum NeoTm1914_Mode { NeoTm1914_Mode_DinFdinAutoSwitch, // Switches between DIN and FDIN on any signal pause > 300ms @@ -46,15 +44,14 @@ class NeoTm1914Settings NeoTm1914_Mode Mode; }; -class Neo3ByteElementsTm1914Settings +class Neo3ElementsTm1914Settings : public Neo3Elements { public: typedef NeoTm1914Settings SettingsObject; static const size_t SettingsSize = 6; - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) + static void applySettings(uint8_t* pData, const SettingsObject& settings) { - // settings are at the front of the data stream uint8_t* pSet = pData; uint8_t mode = 0xff; @@ -87,29 +84,91 @@ class Neo3ByteElementsTm1914Settings } } - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) + static uint8_t* pixels(uint8_t* pData) { - // settings are at the front of the data stream return pData + SettingsSize; } - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) + static const uint8_t* pixels(const uint8_t* pData) { - // settings are at the front of the data stream return pData + SettingsSize; } }; -class NeoRgbTm1914Feature : - public Neo3ByteFeature, - public Neo3ByteElementsTm1914Settings +class NeoRgbTm1914Feature : public Neo3ElementsTm1914Settings { +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + }; -class NeoGrbTm1914Feature : - public Neo3ByteFeature, - public Neo3ByteElementsTm1914Settings +class NeoGrbTm1914Feature : public Neo3ElementsTm1914Settings { +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.G; + *p++ = color.R; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.G = *p++; + color.R = *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.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoTopologies.h b/lib/NeoPixelBus/src/internal/NeoTopologies.h deleted file mode 100644 index ce41f3e47a..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoTopologies.h +++ /dev/null @@ -1,39 +0,0 @@ -/*------------------------------------------------------------------------- -NeoTopologies includes all the classes that describe pixel cordinate mapping -from 2d spaces to 1d strips that NeoPixelBus uses. - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -#include "topologies/ColumnMajorAlternatingLayout.h" -#include "topologies/ColumnMajorLayout.h" -#include "topologies/RowMajorAlternatingLayout.h" -#include "topologies/RowMajorLayout.h" - -#include "topologies/NeoTopology.h" -#include "topologies/NeoRingTopology.h" -#include "topologies/NeoTiles.h" -#include "topologies/NeoMosaic.h" - - diff --git a/lib/NeoPixelBus/src/internal/topologies/NeoTopology.h b/lib/NeoPixelBus/src/internal/NeoTopology.h similarity index 88% rename from lib/NeoPixelBus/src/internal/topologies/NeoTopology.h rename to lib/NeoPixelBus/src/internal/NeoTopology.h index 0909764cb1..224c1dbdf6 100644 --- a/lib/NeoPixelBus/src/internal/topologies/NeoTopology.h +++ b/lib/NeoPixelBus/src/internal/NeoTopology.h @@ -1,3 +1,5 @@ +#pragma once + /*------------------------------------------------------------------------- NeoTopology provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map a matrix of NeoPixels to a index on the NeoPixelBus @@ -24,7 +26,6 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#pragma once enum NeoTopologyHint { @@ -34,14 +35,6 @@ enum NeoTopologyHint NeoTopologyHint_OutOfBounds }; -// NeoTopology - -// -// T_LAYOUT - the following classes and their rotated variants -// RowMajorLayout -// ColumnMajorLayout -// RowMajorAlternatingLayout -// ColumnMajorAlternatingLayout -// template class NeoTopology { public: @@ -54,7 +47,7 @@ template class NeoTopology uint16_t Map(int16_t x, int16_t y) const { - if (x >= static_cast(_width)) + if (x >= _width) { x = _width - 1; } @@ -62,7 +55,7 @@ template class NeoTopology { x = 0; } - if (y >= static_cast(_height)) + if (y >= _height) { y = _height - 1; } diff --git a/lib/NeoPixelBus/src/internal/NeoUtil.h b/lib/NeoPixelBus/src/internal/NeoUtil.h deleted file mode 100644 index 3c08a80430..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoUtil.h +++ /dev/null @@ -1,94 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -// some platforms do not come with STL or properly defined one, specifically functional -// if you see... -// undefined reference to `std::__throw_bad_function_call()' -// ...then you can either add the platform symbol to the list so NEOPIXEBUS_NO_STL gets defined or -// go to boards.txt and enable c++ by adding (teensy31.build.flags.libs=-lstdc++) and set to "smallest code" option in Arduino -// -#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(STM32L432xx) || defined(STM32L476xx) || defined(ARDUINO_ARCH_SAM) -#define NEOPIXEBUS_NO_STL 1 -#endif - -#ifndef MAYBE_UNUSED - #ifdef ESP32 - #define MAYBE_UNUSED [[maybe_unused]] - #endif - #ifdef ESP8266 - #define MAYBE_UNUSED - #endif -#endif - -// some platforms do not define this standard progmem type for some reason -// -#ifndef PGM_VOID_P -#define PGM_VOID_P const void * -#endif - -#ifndef countof -#define countof(array) (sizeof(array)/sizeof(array[0])) -#endif - -class NeoUtil -{ -private: - static constexpr uint8_t Reverse8BitsLookup[16] = { - 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, - 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf }; - -public: - inline static uint8_t Reverse8Bits(uint8_t n) - { - return (Reverse8BitsLookup[n & 0b1111] << 4) | Reverse8BitsLookup[n >> 4]; - } - - inline static size_t RoundUp(size_t numToRound, size_t multiple) - { - return ((numToRound + multiple - 1) / multiple) * multiple; - } - - // alternatives that proved to be slower but left for more periodic testing - /* - // marginally slower than the table - static uint8_t Reverse8Bits(uint8_t b) - { - b = (b & 0b11110000) >> 4 | (b & 0b00001111) << 4; - b = (b & 0b11001100) >> 2 | (b & 0b00110011) << 2; - b = (b & 0b10101010) >> 1 | (b & 0b01010101) << 1; - return b; - } - */ - - /* WAY TO SLOW - static uint8_t Reverse8Bits(uint8_t b) - { - return (b * 0x0202020202ULL & 0x010884422010ULL) % 1023; - } - */ -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/P9813ColorFeatures.h b/lib/NeoPixelBus/src/internal/P9813ColorFeatures.h new file mode 100644 index 0000000000..cad80d0726 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/P9813ColorFeatures.h @@ -0,0 +1,162 @@ +/*------------------------------------------------------------------------- +P9813ColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class when used with P9813s + +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 +. +-------------------------------------------------------------------------*/ +#pragma once + +class P98133Elements +{ +public: + static const size_t PixelSize = 4; // still requires 4 to be sent + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + *pPixelDest++ = pPixelSrc[2]; + *pPixelDest++ = pPixelSrc[3]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; +}; + +class P98133ElementsNoSettings : public P98133Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class P9813BgrFeature : public P98133ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xC0 | ((~color.B & 0xC0) >> 2) | ((~color.G & 0xC0) >> 4) | ((~color.R & 0xC0) >> 6); + *p++ = color.B; + *p++ = color.G; + *p = color.R; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.B = *p++; + color.G = *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); + + p++; // ignore the first byte + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p); + + return color; + } + +}; + + + + + + diff --git a/lib/NeoPixelBus/src/internal/methods/P9813GenericMethod.h b/lib/NeoPixelBus/src/internal/P9813GenericMethod.h similarity index 94% rename from lib/NeoPixelBus/src/internal/methods/P9813GenericMethod.h rename to lib/NeoPixelBus/src/internal/P9813GenericMethod.h index 4023c59b7c..2fd1d4b5a4 100644 --- a/lib/NeoPixelBus/src/internal/methods/P9813GenericMethod.h +++ b/lib/NeoPixelBus/src/internal/P9813GenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -98,12 +96,6 @@ template class P9813MethodBase _wire.endTransaction(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -114,7 +106,7 @@ template class P9813MethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/colors/Rgb16Color.h b/lib/NeoPixelBus/src/internal/Rgb16Color.h similarity index 87% rename from lib/NeoPixelBus/src/internal/colors/Rgb16Color.h rename to lib/NeoPixelBus/src/internal/Rgb16Color.h index aa08164b28..d2fdd8cd56 100644 --- a/lib/NeoPixelBus/src/internal/colors/Rgb16Color.h +++ b/lib/NeoPixelBus/src/internal/Rgb16Color.h @@ -25,6 +25,11 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include +#include "NeoSettings.h" +#include "RgbColorBase.h" + + // ------------------------------------------------------------------------ // Rgb16Color represents a color object that is represented by Red, Green, Blue // component values stored in a single 16 bit value using 565 model. @@ -66,16 +71,6 @@ struct Rgb16Color : RgbColorBase { }; - // ------------------------------------------------------------------------ - // Construct a Rgb16Color using RgbCOlor - // ------------------------------------------------------------------------ - Rgb16Color(const RgbColor& color) - { - setR(color.R); - setG(color.G); - setB(color.B); - }; - // ------------------------------------------------------------------------ // Construct a Rgb16Color using HtmlColor // ------------------------------------------------------------------------ @@ -153,23 +148,6 @@ struct Rgb16Color : RgbColorBase return (Color565 & 0x001f) << 3; }; - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return getR(); - case 1: - return getG(); - default: - return getB(); - } - } // ------------------------------------------------------------------------ // Comparison operators @@ -265,16 +243,7 @@ struct Rgb16Color : RgbColorBase return Rgb16Color(result.R, result.G, result.B); }; - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static Rgb16Color LinearBlend(const Rgb16Color& left, const Rgb16Color& right, uint8_t progress) - { - RgbColor result = RgbColor::LinearBlend(left, right, progress); - - return Rgb16Color(result.R, result.G, result.B); - }; - + // ------------------------------------------------------------------------ // BilinearBlend between four colors by the amount defined by 2d variable // c00 - upper left quadrant color @@ -308,8 +277,5 @@ struct Rgb16Color : RgbColorBase }; uint16_t Color565; - - const static uint8_t Max = 255; - const static size_t Count = 3; // three elements in [] }; diff --git a/lib/NeoPixelBus/src/internal/colors/Rgb48Color.cpp b/lib/NeoPixelBus/src/internal/Rgb48Color.cpp similarity index 80% rename from lib/NeoPixelBus/src/internal/colors/Rgb48Color.cpp rename to lib/NeoPixelBus/src/internal/Rgb48Color.cpp index d33b355dd5..ea03f92229 100644 --- a/lib/NeoPixelBus/src/internal/colors/Rgb48Color.cpp +++ b/lib/NeoPixelBus/src/internal/Rgb48Color.cpp @@ -24,24 +24,22 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" #include "Rgb48Color.h" +#include "RgbColor.h" #include "HslColor.h" #include "HsbColor.h" #include "HtmlColor.h" -#include "RgbwColor.h" -#include "Rgbw64Color.h" - -Rgb48Color::Rgb48Color(const Rgbw64Color& color) : - R(color.R), - G(color.G), - B(color.B) +Rgb48Color::Rgb48Color(const HtmlColor& color) { -} + uint32_t temp = color.Color; + + B = (temp & 0xff); + temp = temp >> 8; + G = (temp & 0xff); + temp = temp >> 8; + R = (temp & 0xff); +}; Rgb48Color::Rgb48Color(const HslColor& color) { @@ -148,15 +146,9 @@ void Rgb48Color::Lighten(uint16_t delta) Rgb48Color Rgb48Color::LinearBlend(const Rgb48Color& left, const Rgb48Color& right, float progress) { - return Rgb48Color( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress)); -} -Rgb48Color Rgb48Color::LinearBlend(const Rgb48Color& left, const Rgb48Color& right, uint8_t progress) -{ - return Rgb48Color(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8)); + return Rgb48Color( left.R + ((right.R - left.R) * progress), + left.G + ((right.G - left.G) * progress), + left.B + ((right.B - left.B) * progress)); } Rgb48Color Rgb48Color::BilinearBlend(const Rgb48Color& c00, diff --git a/lib/NeoPixelBus/src/internal/colors/Rgb48Color.h b/lib/NeoPixelBus/src/internal/Rgb48Color.h similarity index 64% rename from lib/NeoPixelBus/src/internal/colors/Rgb48Color.h rename to lib/NeoPixelBus/src/internal/Rgb48Color.h index b7881c88e3..eb351421be 100644 --- a/lib/NeoPixelBus/src/internal/colors/Rgb48Color.h +++ b/lib/NeoPixelBus/src/internal/Rgb48Color.h @@ -25,7 +25,11 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -struct Rgbw64Color; // forward declared +#include +#include "NeoSettings.h" +#include "RgbColorBase.h" +#include "RgbColor.h" + // ------------------------------------------------------------------------ // Rgb48Color represents a color object that is represented by Red, Green, Blue @@ -57,34 +61,17 @@ struct Rgb48Color : RgbColorBase // ------------------------------------------------------------------------ // Construct a Rgb48Color using RgbColor // ------------------------------------------------------------------------ - Rgb48Color(const RgbColor& color) + Rgb48Color(const RgbColor& color) { - // x16 = map(x8, 0, 255, 0, 65535); // refactors to just * 257 - R = (uint16_t)color.R * 257; // 257 = MAXUINT16/MAXUINT8 = 65535/255 - G = (uint16_t)color.G * 257; - B = (uint16_t)color.B * 257; - }; - - // ------------------------------------------------------------------------ - // explicitly Construct a Rgb48Color using RgbwColor - // ------------------------------------------------------------------------ - explicit Rgb48Color(const RgbwColor& color) - { - *this = RgbColor(color); + R = (color.R == 0) ? 0 : (color.R << 8 | 0xff); + G = (color.G == 0) ? 0 : (color.G << 8 | 0xff); + B = (color.B == 0) ? 0 : (color.B << 8 | 0xff); } - // ------------------------------------------------------------------------ - // explicitly Construct a Rgb48Color using Rgbw64Color - // ------------------------------------------------------------------------ - explicit Rgb48Color(const Rgbw64Color& color); - // ------------------------------------------------------------------------ // Construct a Rgb48Color using HtmlColor // ------------------------------------------------------------------------ - Rgb48Color(const HtmlColor& color) - { - *this = RgbColor(color); - }; + Rgb48Color(const HtmlColor& color); // ------------------------------------------------------------------------ // Construct a Rgb48Color using HslColor @@ -117,68 +104,6 @@ struct Rgb48Color : RgbColorBase return !(*this == other); }; - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int32_t CompareTo(const Rgb48Color& other, uint16_t epsilon = 256) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int32_t Compare(const Rgb48Color& left, const Rgb48Color& right, uint16_t epsilon = 256) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - default: - return B; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint16_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - default: - return B; - } - } - // ------------------------------------------------------------------------ // CalculateBrightness will calculate the overall brightness // NOTE: This is a simple linear brightness @@ -193,18 +118,6 @@ struct Rgb48Color : RgbColorBase // ------------------------------------------------------------------------ Rgb48Color Dim(uint16_t ratio) const; - // ------------------------------------------------------------------------ - // Dim will return a new color that is blended to black with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return black - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgb48Color Dim(uint8_t ratio) const - { - uint16_t expanded = ratio << 8; - return Dim(expanded); - } - // ------------------------------------------------------------------------ // Brighten will return a new color that is blended to white with the given ratio // ratio - (0-65535) where 65535 will return the original color and 0 will return white @@ -213,18 +126,6 @@ struct Rgb48Color : RgbColorBase // ------------------------------------------------------------------------ Rgb48Color Brighten(uint16_t ratio) const; - // ------------------------------------------------------------------------ - // Brighten will return a new color that is blended to white with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return white - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgb48Color Brighten(uint8_t ratio) const - { - uint16_t expanded = ratio << 8; - return Brighten(expanded); - } - // ------------------------------------------------------------------------ // Darken will adjust the color by the given delta toward black // NOTE: This is a simple linear change @@ -247,11 +148,7 @@ struct Rgb48Color : RgbColorBase // and a value between will blend the color weighted linearly between them // ------------------------------------------------------------------------ static Rgb48Color LinearBlend(const Rgb48Color& left, const Rgb48Color& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static Rgb48Color LinearBlend(const Rgb48Color& left, const Rgb48Color& right, uint8_t progress); - + // ------------------------------------------------------------------------ // BilinearBlend between four colors by the amount defined by 2d variable // c00 - upper left quadrant color @@ -288,17 +185,16 @@ struct Rgb48Color : RgbColorBase uint16_t B; const static uint16_t Max = 65535; - const static size_t Count = 3; // three elements in [] private: inline static uint16_t _elementDim(uint16_t value, uint16_t ratio) { - return (static_cast(value) * (static_cast(ratio) + 1)) >> 16; + return (static_cast(value) * (static_cast(ratio) + 1)) >> 8; } inline static uint16_t _elementBrighten(uint16_t value, uint16_t ratio) { - uint32_t element = ((static_cast(value) + 1) << 16) / (static_cast(ratio) + 1); + uint32_t element = ((static_cast(value) + 1) << 8) / (static_cast(ratio) + 1); if (element > Max) { diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColor.cpp b/lib/NeoPixelBus/src/internal/RgbColor.cpp similarity index 84% rename from lib/NeoPixelBus/src/internal/colors/RgbColor.cpp rename to lib/NeoPixelBus/src/internal/RgbColor.cpp index 81d0ba56f1..406d78e12e 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbColor.cpp +++ b/lib/NeoPixelBus/src/internal/RgbColor.cpp @@ -24,16 +24,12 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb16Color.h" #include "Rgb48Color.h" #include "HslColor.h" #include "HsbColor.h" #include "HtmlColor.h" - #include "RgbwColor.h" RgbColor::RgbColor(const RgbwColor& color) : @@ -166,16 +162,9 @@ void RgbColor::Lighten(uint8_t delta) RgbColor RgbColor::LinearBlend(const RgbColor& left, const RgbColor& right, float progress) { - return RgbColor( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress)); -} - -RgbColor RgbColor::LinearBlend(const RgbColor& left, const RgbColor& right, uint8_t progress) -{ - return RgbColor(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8)); + return RgbColor( left.R + ((right.R - left.R) * progress), + left.G + ((right.G - left.G) * progress), + left.B + ((right.B - left.B) * progress)); } RgbColor RgbColor::BilinearBlend(const RgbColor& c00, diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColor.h b/lib/NeoPixelBus/src/internal/RgbColor.h similarity index 76% rename from lib/NeoPixelBus/src/internal/colors/RgbColor.h rename to lib/NeoPixelBus/src/internal/RgbColor.h index 2b34d80431..aa999f5ba9 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbColor.h +++ b/lib/NeoPixelBus/src/internal/RgbColor.h @@ -25,6 +25,10 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include +#include "NeoSettings.h" +#include "RgbColorBase.h" + struct RgbwColor; // ------------------------------------------------------------------------ @@ -101,68 +105,6 @@ struct RgbColor : RgbColorBase return !(*this == other); }; - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int16_t CompareTo(const RgbColor& other, uint8_t epsilon = 1) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int16_t Compare(const RgbColor& left, const RgbColor& right, uint8_t epsilon = 1) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - default: - return B; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - default: - return B; - } - } - // ------------------------------------------------------------------------ // CalculateBrightness will calculate the overall brightness // NOTE: This is a simple linear brightness @@ -207,11 +149,7 @@ struct RgbColor : RgbColorBase // and a value between will blend the color weighted linearly between them // ------------------------------------------------------------------------ static RgbColor LinearBlend(const RgbColor& left, const RgbColor& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static RgbColor LinearBlend(const RgbColor& left, const RgbColor& right, uint8_t progress); - + // ------------------------------------------------------------------------ // BilinearBlend between four colors by the amount defined by 2d variable // c00 - upper left quadrant color @@ -248,7 +186,6 @@ struct RgbColor : RgbColorBase uint8_t B; const static uint8_t Max = 255; - const static size_t Count = 3; // three elements in [] private: inline static uint8_t _elementDim(uint8_t value, uint8_t ratio) diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColorBase.cpp b/lib/NeoPixelBus/src/internal/RgbColorBase.cpp similarity index 98% rename from lib/NeoPixelBus/src/internal/colors/RgbColorBase.cpp rename to lib/NeoPixelBus/src/internal/RgbColorBase.cpp index 92c43f9d3f..ad0eb82772 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbColorBase.cpp +++ b/lib/NeoPixelBus/src/internal/RgbColorBase.cpp @@ -24,8 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" #include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoShaderBase.h b/lib/NeoPixelBus/src/internal/RgbColorBase.h similarity index 75% rename from lib/NeoPixelBus/src/internal/buffers/NeoShaderBase.h rename to lib/NeoPixelBus/src/internal/RgbColorBase.h index 399c6f9ba0..689fe884e5 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoShaderBase.h +++ b/lib/NeoPixelBus/src/internal/RgbColorBase.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoShaderBase +RgbColorBase provides a RGB color object common support Written by Michael C. Miller. @@ -25,29 +25,18 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -class NeoShaderBase +struct HslColor; +struct HsbColor; +struct HtmlColor; +struct Rgb16Color; + +struct RgbColorBase { -public: - NeoShaderBase() : - _state(0) - { - } - - bool IsDirty() const - { - return (_state & NEO_DIRTY); - }; - - void Dirty() - { - _state |= NEO_DIRTY; - }; - - void ResetDirty() - { - _state &= ~NEO_DIRTY; - }; protected: - uint8_t _state; // internal state + static float _CalcColor(float p, float q, float t); + + static void _HslToRgb(const HslColor& color, float* r, float* g, float* b); + + static void _HsbToRgb(const HsbColor& color, float* r, float* g, float* b); }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/RgbwColor.cpp b/lib/NeoPixelBus/src/internal/RgbwColor.cpp similarity index 81% rename from lib/NeoPixelBus/src/internal/colors/RgbwColor.cpp rename to lib/NeoPixelBus/src/internal/RgbwColor.cpp index 5391583dd2..10b3727843 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbwColor.cpp +++ b/lib/NeoPixelBus/src/internal/RgbwColor.cpp @@ -24,9 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HslColor.h" @@ -168,17 +165,10 @@ void RgbwColor::Lighten(uint8_t delta) RgbwColor RgbwColor::LinearBlend(const RgbwColor& left, const RgbwColor& right, float progress) { - return RgbwColor( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress), - left.W + ((static_cast(right.W) - left.W) * progress) ); -} -RgbwColor RgbwColor::LinearBlend(const RgbwColor& left, const RgbwColor& right, uint8_t progress) -{ - return RgbwColor(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8), - left.W + (((static_cast(right.W) - left.W) * static_cast(progress) + 1) >> 8)); + return RgbwColor( left.R + ((right.R - left.R) * progress), + left.G + ((right.G - left.G) * progress), + left.B + ((right.B - left.B) * progress), + left.W + ((right.W - left.W) * progress) ); } RgbwColor RgbwColor::BilinearBlend(const RgbwColor& c00, diff --git a/lib/NeoPixelBus/src/internal/colors/RgbwColor.h b/lib/NeoPixelBus/src/internal/RgbwColor.h similarity index 74% rename from lib/NeoPixelBus/src/internal/colors/RgbwColor.h rename to lib/NeoPixelBus/src/internal/RgbwColor.h index 6154769fd6..73732b5e40 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbwColor.h +++ b/lib/NeoPixelBus/src/internal/RgbwColor.h @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include + struct RgbColor; struct HslColor; struct HsbColor; @@ -34,7 +36,7 @@ struct HsbColor; // component values and an extra White component. It contains helpful color // routines to manipulate the color. // ------------------------------------------------------------------------ -struct RgbwColor : RgbColorBase +struct RgbwColor { typedef NeoRgbwCurrentSettings SettingsObject; @@ -103,72 +105,6 @@ struct RgbwColor : RgbColorBase return !(*this == other); }; - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int16_t CompareTo(const RgbwColor& other, uint8_t epsilon = 1) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int16_t Compare(const RgbwColor& left, const RgbwColor& right, uint8_t epsilon = 1) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - default: - return W; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - default: - return W; - } - } - // ------------------------------------------------------------------------ // Returns if the color is grey, all values are equal other than white // ------------------------------------------------------------------------ @@ -230,11 +166,7 @@ struct RgbwColor : RgbColorBase // and a value between will blend the color weighted linearly between them // ------------------------------------------------------------------------ static RgbwColor LinearBlend(const RgbwColor& left, const RgbwColor& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static RgbwColor LinearBlend(const RgbwColor& left, const RgbwColor& right, uint8_t progress); - + // ------------------------------------------------------------------------ // BilinearBlend between four colors by the amount defined by 2d variable // c00 - upper left quadrant color @@ -255,10 +187,10 @@ struct RgbwColor : RgbColorBase { auto total = 0; - total += R * settings.RedTenthMilliAmpere / Max; - total += G * settings.GreenTenthMilliAmpere / Max; - total += B * settings.BlueTenthMilliAmpere / Max; - total += W * settings.WhiteTenthMilliAmpere / Max; + total += R * settings.RedTenthMilliAmpere / 255; + total += G * settings.GreenTenthMilliAmpere / 255; + total += B * settings.BlueTenthMilliAmpere / 255; + total += W * settings.WhiteCurrent / 255; return total; } @@ -273,9 +205,6 @@ struct RgbwColor : RgbColorBase uint8_t B; uint8_t W; - const static uint8_t Max = 255; - const static size_t Count = 4; // four elements in [] - private: inline static uint8_t _elementDim(uint8_t value, uint8_t ratio) { @@ -286,9 +215,9 @@ struct RgbwColor : RgbColorBase { uint16_t element = ((static_cast(value) + 1) << 8) / (static_cast(ratio) + 1); - if (element > Max) + if (element > 255) { - element = Max; + element = 255; } else { diff --git a/lib/NeoPixelBus/src/internal/colors/SegmentDigit.cpp b/lib/NeoPixelBus/src/internal/SegmentDigit.cpp similarity index 75% rename from lib/NeoPixelBus/src/internal/colors/SegmentDigit.cpp rename to lib/NeoPixelBus/src/internal/SegmentDigit.cpp index 2984cf8576..b310f59039 100644 --- a/lib/NeoPixelBus/src/internal/colors/SegmentDigit.cpp +++ b/lib/NeoPixelBus/src/internal/SegmentDigit.cpp @@ -24,7 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include #include "SegmentDigit.h" // @@ -60,7 +59,7 @@ const uint8_t SevenSegDigit::DecodeSpecial[] = { void SevenSegDigit::init(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness) { - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { Segment[iSegment] = (bitmask & 0x01) ? brightness : defaultBrightness; bitmask >>= 1; @@ -112,39 +111,17 @@ uint8_t SevenSegDigit::CalculateBrightness() const { uint16_t sum = 0; - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { sum += Segment[iSegment]; } - return static_cast(sum / Count); -} - -SevenSegDigit SevenSegDigit::Dim(uint8_t ratio) const -{ - SevenSegDigit result; - - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) - { - result.Segment[iSegment] = _elementDim(Segment[iSegment], ratio); - } - return result; -} - -SevenSegDigit SevenSegDigit::Brighten(uint8_t ratio) const -{ - SevenSegDigit result; - - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) - { - result.Segment[iSegment] = _elementBrighten(Segment[iSegment], ratio); - } - return result; + return static_cast(sum / SegmentCount); } void SevenSegDigit::Darken(uint8_t delta) { - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { uint8_t element = Segment[iSegment]; if (element > delta) @@ -161,7 +138,7 @@ void SevenSegDigit::Darken(uint8_t delta) void SevenSegDigit::Lighten(uint8_t delta) { - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { uint8_t element = Segment[iSegment]; if (element < 255 - delta) @@ -180,22 +157,9 @@ SevenSegDigit SevenSegDigit::LinearBlend(const SevenSegDigit& left, const SevenS { SevenSegDigit result; - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) - { - result.Segment[iSegment] = left.Segment[iSegment] + ((static_cast(right.Segment[iSegment]) - left.Segment[iSegment]) * progress); - } - return result; -} - -SevenSegDigit SevenSegDigit::LinearBlend(const SevenSegDigit& left, const SevenSegDigit& right, uint8_t progress) -{ - SevenSegDigit result; - - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { - result.Segment[iSegment] = left.Segment[iSegment] + - (((static_cast(right.Segment[iSegment]) - left.Segment[iSegment]) * static_cast(progress) + 1) >> 8); + result.Segment[iSegment] = left.Segment[iSegment] + ((right.Segment[iSegment] - left.Segment[iSegment]) * progress); } return result; } - diff --git a/lib/NeoPixelBus/src/internal/colors/SegmentDigit.h b/lib/NeoPixelBus/src/internal/SegmentDigit.h similarity index 76% rename from lib/NeoPixelBus/src/internal/colors/SegmentDigit.h rename to lib/NeoPixelBus/src/internal/SegmentDigit.h index abf8649ce7..a7fe452e81 100644 --- a/lib/NeoPixelBus/src/internal/colors/SegmentDigit.h +++ b/lib/NeoPixelBus/src/internal/SegmentDigit.h @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include + enum LedSegment { LedSegment_A, @@ -105,7 +107,7 @@ struct SevenSegDigit // ------------------------------------------------------------------------ bool operator==(const SevenSegDigit& other) const { - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { if (Segment[iSegment] != other.Segment[iSegment]) { @@ -120,48 +122,12 @@ struct SevenSegDigit return !(*this == other); }; - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order of the Segments - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - return Segment[idx]; - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t& operator[](size_t idx) - { - return Segment[idx]; - } - // ------------------------------------------------------------------------ // CalculateBrightness will calculate the overall brightness // NOTE: This is a simple linear brightness // ------------------------------------------------------------------------ uint8_t CalculateBrightness() const; - // ------------------------------------------------------------------------ - // Dim will return a new SevenSegDigit that is blended to off with the given ratio - // ratio - (0-255) where 255 will return the original brightness and 0 will return off - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - SevenSegDigit Dim(uint8_t ratio) const; - - // ------------------------------------------------------------------------ - // Brighten will return a new SevenSegDigit that is blended to full bright with the given ratio - // ratio - (0-255) where 255 will return the original brightness and 0 will return full brightness - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - SevenSegDigit Brighten(uint8_t ratio) const; - // ------------------------------------------------------------------------ // Darken will adjust the color by the given delta toward black // NOTE: This is a simple linear change @@ -185,23 +151,19 @@ struct SevenSegDigit // weighted linearly between them // ------------------------------------------------------------------------ static SevenSegDigit LinearBlend(const SevenSegDigit& left, const SevenSegDigit& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static SevenSegDigit LinearBlend(const SevenSegDigit& left, const SevenSegDigit& right, uint8_t progress); uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) { auto total = 0; - for (uint8_t segment = LedSegment_A; segment < Count - 2; segment++) + for (uint8_t segment = LedSegment_A; segment < SegmentCount - 2; segment++) { total += Segment[segment] * settings.SegmentTenthMilliAmpere / Max; } - total += Segment[Count - 2] * settings.DecimalTenthMilliAmpere / Max; - total += Segment[Count - 1] * settings.SpecialTenthMilliAmpere / Max; + total += Segment[SegmentCount - 2] * settings.DecimalTenthMilliAmpere / Max; + total += Segment[SegmentCount - 1] * settings.SpecialTenthMilliAmpere / Max; return total; } @@ -287,8 +249,8 @@ struct SevenSegDigit // segment members (0-255) where each represents the segment location // and the value defines the brightnes (0) is off and (255) is full brightness // ------------------------------------------------------------------------ - static const uint8_t Count = 9; - uint8_t Segment[Count]; + static const uint8_t SegmentCount = 9; + uint8_t Segment[SegmentCount]; const static uint8_t Max = 255; @@ -301,25 +263,5 @@ struct SevenSegDigit protected: void init(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness); - - inline static uint8_t _elementDim(uint8_t value, uint8_t ratio) - { - return (static_cast(value) * (static_cast(ratio) + 1)) >> 8; - } - - inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio) - { - uint16_t element = ((static_cast(value) + 1) << 8) / (static_cast(ratio) + 1); - - if (element > Max) - { - element = Max; - } - else - { - element -= 1; - } - return element; - } }; diff --git a/lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImple.h b/lib/NeoPixelBus/src/internal/TwoWireBitBangImple.h similarity index 87% rename from lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImple.h rename to lib/NeoPixelBus/src/internal/TwoWireBitBangImple.h index d45eff05c0..eede5f9cce 100644 --- a/lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImple.h +++ b/lib/NeoPixelBus/src/internal/TwoWireBitBangImple.h @@ -26,7 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" class TwoWireBitBangImple { @@ -63,18 +62,6 @@ class TwoWireBitBangImple digitalWrite(_pinData, LOW); } - void transmitBit(uint8_t bit) - { - // set data bit on pin - digitalWrite(_pinData, bit); - - // set clock high as data is ready - digitalWrite(_pinClock, HIGH); - - // set clock low as data pin is changed - digitalWrite(_pinClock, LOW); - } - void transmitByte(uint8_t data) { for (int bit = 7; bit >= 0; bit--) @@ -101,7 +88,7 @@ class TwoWireBitBangImple } } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } diff --git a/lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImpleAvr.h b/lib/NeoPixelBus/src/internal/TwoWireBitBangImpleAvr.h similarity index 84% rename from lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImpleAvr.h rename to lib/NeoPixelBus/src/internal/TwoWireBitBangImpleAvr.h index 79e47ae50a..5b475ac5fd 100644 --- a/lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImpleAvr.h +++ b/lib/NeoPixelBus/src/internal/TwoWireBitBangImpleAvr.h @@ -26,7 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" class TwoWireBitBangImple { @@ -68,28 +67,6 @@ class TwoWireBitBangImple digitalWrite(_pinData, LOW); } - void transmitBit(uint8_t bit) - { - // set data bit on pin - // digitalWrite(_pinData, bit); // HIGH : LOW - if (bit) - { - *_portData |= _pinMaskData; - } - else - { - *_portData &= ~_pinMaskData; - } - - // set clock high as data is ready - // digitalWrite(_pinClock, HIGH); - *_portClock |= _pinMaskClock; - - // set clock low as data pin is changed - // digitalWrite(_pinClock, LOW); - *_portClock &= ~_pinMaskClock; - } - void transmitByte(uint8_t data) { for (int bit = 7; bit >= 0; bit--) @@ -126,7 +103,7 @@ class TwoWireBitBangImple } } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } diff --git a/lib/NeoPixelBus/src/internal/methods/TwoWireHspiImple.h b/lib/NeoPixelBus/src/internal/TwoWireHspiImple.h similarity index 96% rename from lib/NeoPixelBus/src/internal/methods/TwoWireHspiImple.h rename to lib/NeoPixelBus/src/internal/TwoWireHspiImple.h index bdacd38e81..5a96bd5a97 100644 --- a/lib/NeoPixelBus/src/internal/methods/TwoWireHspiImple.h +++ b/lib/NeoPixelBus/src/internal/TwoWireHspiImple.h @@ -27,8 +27,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #include template class TwoWireHspiImple @@ -83,7 +81,7 @@ template class TwoWireHspiImple _hspi->writeBytes(const_cast(data), dataSize); } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _speed.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/methods/TwoWireSpiImple.h b/lib/NeoPixelBus/src/internal/TwoWireSpiImple.h similarity index 78% rename from lib/NeoPixelBus/src/internal/methods/TwoWireSpiImple.h rename to lib/NeoPixelBus/src/internal/TwoWireSpiImple.h index 2a1244b728..906d86b8f9 100644 --- a/lib/NeoPixelBus/src/internal/methods/TwoWireSpiImple.h +++ b/lib/NeoPixelBus/src/internal/TwoWireSpiImple.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #include class SpiSpeed40Mhz @@ -36,51 +34,29 @@ class SpiSpeed40Mhz typedef NeoNoSettings SettingsObject; SpiSpeed40Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 40000000L; }; -class SpiSpeed30Mhz -{ -public: - typedef NeoNoSettings SettingsObject; - SpiSpeed30Mhz() {}; - - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} - - static const uint32_t Clock = 30000000L; -}; - class SpiSpeed20Mhz { public: typedef NeoNoSettings SettingsObject; SpiSpeed20Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 20000000L; }; -class SpiSpeed15Mhz -{ -public: - typedef NeoNoSettings SettingsObject; - SpiSpeed15Mhz() {}; - - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} - - static const uint32_t Clock = 15000000L; -}; - class SpiSpeed10Mhz { public: typedef NeoNoSettings SettingsObject; SpiSpeed10Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 10000000L; }; @@ -91,7 +67,7 @@ class SpiSpeed5Mhz typedef NeoNoSettings SettingsObject; SpiSpeed5Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 5000000L; }; @@ -102,7 +78,7 @@ class SpiSpeed2Mhz typedef NeoNoSettings SettingsObject; SpiSpeed2Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 2000000L; }; @@ -113,7 +89,7 @@ class SpiSpeed1Mhz typedef NeoNoSettings SettingsObject; SpiSpeed1Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 1000000L; }; @@ -124,7 +100,7 @@ class SpiSpeed500Khz typedef NeoNoSettings SettingsObject; SpiSpeed500Khz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 500000L; }; @@ -148,7 +124,7 @@ class SpiSpeedHz Clock(10000000) {}; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { Clock = settings.Clock; } @@ -217,7 +193,7 @@ template class TwoWireSpiImple #endif } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _speed.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/methods/Ws2801GenericMethod.h b/lib/NeoPixelBus/src/internal/Ws2801GenericMethod.h similarity index 79% rename from lib/NeoPixelBus/src/internal/methods/Ws2801GenericMethod.h rename to lib/NeoPixelBus/src/internal/Ws2801GenericMethod.h index 3065cc0600..24521c6f6d 100644 --- a/lib/NeoPixelBus/src/internal/methods/Ws2801GenericMethod.h +++ b/lib/NeoPixelBus/src/internal/Ws2801GenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -104,12 +102,6 @@ template class Ws2801MethodBase _endTime = micros(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -120,7 +112,7 @@ template class Ws2801MethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } @@ -133,20 +125,20 @@ template class Ws2801MethodBase uint8_t* _data; // Holds LED color values }; -typedef Ws2801MethodBase Ws2801Method; +typedef Ws2801MethodBase NeoWs2801Method; #if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) #include "TwoWireSpiImple.h" -typedef Ws2801MethodBase> Ws2801Spi20MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi10MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi5MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi2MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi1MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi500KhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi20MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi10MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi5MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi2MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi1MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi500KhzMethod; -typedef Ws2801MethodBase> Ws2801SpiHzMethod; +typedef Ws2801MethodBase> NeoWs2801SpiHzMethod; -typedef Ws2801Spi10MhzMethod Ws2801SpiMethod; +typedef NeoWs2801Spi10MhzMethod NeoWs2801SpiMethod; #endif diff --git a/lib/NeoPixelBus/src/internal/buffers/LayoutMapCallback.h b/lib/NeoPixelBus/src/internal/buffers/LayoutMapCallback.h deleted file mode 100644 index d822f1883e..0000000000 --- a/lib/NeoPixelBus/src/internal/buffers/LayoutMapCallback.h +++ /dev/null @@ -1,41 +0,0 @@ -/*------------------------------------------------------------------------- -LayoutMapCallback - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - - -#if defined(NEOPIXEBUS_NO_STL) - -typedef uint16_t(*LayoutMapCallback)(int16_t x, int16_t y); - -#else - -#undef max -#undef min -#include -typedef std::function LayoutMapCallback; - -#endif \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBufferProgmemMethod.h b/lib/NeoPixelBus/src/internal/buffers/NeoBufferProgmemMethod.h deleted file mode 100644 index b03b72d3db..0000000000 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBufferProgmemMethod.h +++ /dev/null @@ -1,126 +0,0 @@ -/*------------------------------------------------------------------------- -NeoBufferProgmemMethod - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -template class NeoBufferProgmemMethod -{ -public: - NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) : - _width(width), - _height(height), - _pixels(pixels) - { - } - - operator NeoBufferContext() - { - return NeoBufferContext(Pixels(), PixelsSize()); - } - - const uint8_t* Pixels() const - { - return reinterpret_cast(_pixels); - }; - - size_t PixelsSize() const - { - return PixelSize() * PixelCount(); - }; - - size_t PixelSize() const - { - return T_COLOR_FEATURE::PixelSize; - }; - - uint16_t PixelCount() const - { - return _width * _height; - }; - - uint16_t Width() const - { - return _width; - }; - - uint16_t Height() const - { - return _height; - }; - - void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) - { - // PROGMEM is read only, this will do nothing - }; - - void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color) - { - // PROGMEM is read only, this will do nothing - }; - - typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const - { - if (indexPixel >= PixelCount()) - { - // Pixel # is out of bounds, this will get converted to a - // color object type initialized to 0 (black) - return 0; - } - - return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); - }; - - typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const - { - if (x < 0 || x >= _width || y < 0 || y >= _height) - { - // Pixel # is out of bounds, this will get converted to a - // color object type initialized to 0 (black) - return 0; - } - - uint16_t indexPixel = x + y * _width; - return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); - }; - - void ClearTo(typename T_COLOR_FEATURE::ColorObject color) - { - // PROGMEM is read only, this will do nothing - }; - - void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - T_COLOR_FEATURE::movePixelsInc_P(pPixelDest, pPixelSrc, count); - } - - typedef typename T_COLOR_FEATURE::ColorObject ColorObject; - typedef T_COLOR_FEATURE ColorFeature; - -private: - const uint16_t _width; - const uint16_t _height; - PGM_VOID_P _pixels; -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoShaderNop.h b/lib/NeoPixelBus/src/internal/buffers/NeoShaderNop.h deleted file mode 100644 index c7ca2e02b2..0000000000 --- a/lib/NeoPixelBus/src/internal/buffers/NeoShaderNop.h +++ /dev/null @@ -1,53 +0,0 @@ -/*------------------------------------------------------------------------- -NeoShaderNop - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template 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; - }; -}; - diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGamma.h b/lib/NeoPixelBus/src/internal/colors/NeoGamma.h deleted file mode 100644 index d2f1b93fc5..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGamma.h +++ /dev/null @@ -1,81 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGamma class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -// use one of the gamma method classes as a converter for this template class -// T_METHOD - -// NeoGammaEquationMethod -// NeoGammaCieLabEquationMethod -// NeoGammaTableMethod -// NeoGammaNullMethod -// NeoGammaInvert -// -template class NeoGamma -{ -public: - static RgbColor Correct(const RgbColor& original) - { - return RgbColor(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B)); - } - - static RgbwColor Correct(const RgbwColor& original) - { - return RgbwColor(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B), - T_METHOD::Correct(original.W) ); - } - - static Rgb48Color Correct(const Rgb48Color& original) - { - return Rgb48Color(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B)); - } - - static Rgbw64Color Correct(const Rgbw64Color& original) - { - return Rgbw64Color(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B), - T_METHOD::Correct(original.W)); - } - - static RgbwwColor Correct(const RgbwwColor& original) - { - return RgbwwColor(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B), - T_METHOD::Correct(original.WW), - T_METHOD::Correct(original.CW)); - } -}; - - - diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaCieLabEquationMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaCieLabEquationMethod.h deleted file mode 100644 index 6603677e5b..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaCieLabEquationMethod.h +++ /dev/null @@ -1,41 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaCieLabEquationMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -// Alternative equation to provide at least one official model for specific LEDs -class NeoGammaCieLabEquationMethod -{ -public: - static uint8_t Correct(uint8_t value) - { - return static_cast(255.0f * NeoEase::GammaCieLab(value / 255.0f) + 0.5f); - } - static uint16_t Correct(uint16_t value) - { - return static_cast(65535.0f * NeoEase::GammaCieLab(value / 65535.0f) + 0.5f); - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.cpp b/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.cpp deleted file mode 100644 index 383b39fbe2..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGamma classes are used to correct RGB colors for human eye gamma levels - -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 -. --------------------------------------------------------------------------*/ - -#include -#include "../NeoUtil.h" -#include "NeoGammaDynamicTableMethod.h" - - -uint8_t NeoGammaDynamicTableMethod::_table[256] = { 0 }; -NeoGammaDynamicTableMethod::NeoGamma16LowHint* NeoGammaDynamicTableMethod::_hints = nullptr; -uint8_t NeoGammaDynamicTableMethod::_hintsCount = 0; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.h deleted file mode 100644 index 2ccc9fedff..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.h +++ /dev/null @@ -1,226 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaDynamicTableMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -#if defined(NEOPIXEBUS_NO_STL) - -typedef float(*GammaCalcFunction)(float unitValue); - -#else - -#undef max -#undef min -#include -typedef std::function GammaCalcFunction; - -#endif - -class NeoGammaDynamicTableMethod -{ -protected: - struct NeoGamma16LowHint - { - uint8_t pos; - uint8_t count; - }; - -public: - static uint8_t Correct(uint8_t value) - { - return _table[value]; - } - - static uint16_t Correct(uint16_t value) - { - // since a single monolithic table would be an unreasonable memory usage - // this will use a hybrid of two tables, the base 255 table for the hibyte - // and a smaller table with hints on how to use the table for certain values - // and the left over values some simple calculations to approximate the final - // 16 bit value as compared to the equation - uint8_t hi = (value >> 8); - uint16_t lo = (value & 0x00ff); - uint8_t hiResult = _table[hi]; - uint16_t lowResult = 0; - - if (hi < _hintsCount) - { - // use _hints table to calculate a reasonable lowbyte - lowResult = (lo + _hints[hi].pos * 256) / _hints[hi].count; - } - else if (hi == 255) - { - // last entry is always linear - lowResult = lo; - } - else - { - // check the _table for duplicate or jumps to adjust the range of lowbyte - if (hiResult == _table[hi - 1]) - { - // this result is an upper duplicate - lowResult = (lo >> 1) | 0x80; // lo / 2 + 128 - } - else - { - uint8_t delta = _table[hi + 1] - hiResult; - - if (delta == 0) - { - // this result is a lower duplicate - lowResult = (lo >> 1); // lo / 2 - } - else if (delta == 1) - { - // this result is incremental and thus linear - lowResult = lo; - } - else - { - // this result jumps by more than one, so need to spread across - lowResult = delta * lo; - } - } - - } - - return (static_cast(hiResult) << 8) + lowResult; - } - - static void Initialize(GammaCalcFunction calc, bool optimize16Bit = false) - { - if (_hints) - { - delete [] _hints; - _hints = nullptr; - } - - // first, iterate and fill 8 bit table - for (uint16_t entry = 0; entry < 256; entry++) - { - _table[entry] = static_cast(255.0f * calc(entry / 255.0f) + 0.5f); - } - - // no optimization, so no 16 bit hints table - if (optimize16Bit) - { - NeoGamma16LowHint hints[256]; - - // now walk table creating an optimized hint table for 16bit - // approximation - // There is an assumption that lower values have series of duplicates and - // upper values at worst have two values the same - // - uint16_t entryStart = 0; - uint16_t entryEnd = 0; - uint16_t entryLastTriplet = 0; - - while (entryStart < 255) - { - uint8_t value = _table[entryStart]; - - while (value == _table[entryEnd] && entryEnd < 255) - { - entryEnd++; - } - - if (entryEnd == entryStart) - { - // no more duplicates, no need to continue - break; - } - - uint8_t pos = 0; - uint8_t count = entryEnd - entryStart; - - if (count >= 3) - { - // remember the last triplet + series - // as we don't need hints after this - // there can be paired duplicates after and before this - entryLastTriplet = entryEnd; - } - - // fill hints with known duplicate value - while (entryStart != entryEnd) - { - hints[entryStart].count = count; - hints[entryStart].pos = pos; - entryStart++; - pos++; - } - } - // create static hint table and copy temp table to it - _hintsCount = entryLastTriplet; // only need to last triplet - _hints = new NeoGamma16LowHint[_hintsCount]; - memcpy(_hints, hints, sizeof(NeoGamma16LowHint) * _hintsCount); - } - } - - // SerialDumpTables is used if you want to generate your own static gamma table class - // rather than use this dynamically generated table. Just capture the serial output - // and use as your initializers for your tables - static void SerialDumpTables() - { - Serial.println(); - Serial.println("8 bit:"); - for (uint16_t entry = 0; entry < 256; entry++) - { - if (entry % 16 == 0) - { - Serial.println(); - } - Serial.print(_table[entry]); - Serial.print(", "); - } - - Serial.println(); - Serial.println(); - Serial.print("16 bit: hintsCount = "); - Serial.println(_hintsCount); - if (_hints) - { - for (uint8_t hint = 0; hint < _hintsCount; hint++) - { - if (hint % 16 == 0) - { - Serial.println(); - } - Serial.print("{"); - Serial.print(_hints[hint].pos); - Serial.print(","); - Serial.print(_hints[hint].count); - Serial.print("}, "); - } - } - Serial.println(); - } - -private: - static uint8_t _table[256]; - static NeoGamma16LowHint* _hints; - static uint8_t _hintsCount; -}; diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaInvertMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaInvertMethod.h deleted file mode 100644 index f28bdef2b5..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaInvertMethod.h +++ /dev/null @@ -1,48 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaInvertMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -// use one of the gamma method classes as a base converter for this template class -// T_METHOD - -// NeoGammaEquationMethod -// NeoGammaCieLabEquationMethod -// NeoGammaTableMethod -// NeoGammaNullMethod -// -template class NeoGammaInvertMethod -{ -public: - static uint8_t Correct(uint8_t value) - { - return ~T_METHOD::Correct(value); - } - - static uint16_t Correct(uint16_t value) - { - return ~T_METHOD::Correct(value); - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaNullMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaNullMethod.h deleted file mode 100644 index d1d4436bf3..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaNullMethod.h +++ /dev/null @@ -1,42 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaNullMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -// no gamma correction at all -class NeoGammaNullMethod -{ -public: - static uint8_t Correct(uint8_t value) - { - return value; - } - - static uint16_t Correct(uint16_t value) - { - return value; - } -}; diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.h deleted file mode 100644 index 4874a44045..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.h +++ /dev/null @@ -1,113 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaTableMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -// NeoGammaTableMethod uses 256 bytes of memory, but is significantly faster -class NeoGammaTableMethod -{ -protected: - struct NeoGamma16LowHint - { - uint8_t pos; - uint8_t count; - }; - -public: - static uint8_t Correct(uint8_t value) - { - return _table[value]; - } - - static uint16_t Correct(uint16_t value) - { - // since a single monolithic table would be an unreasonable memory usage - // this will use a hybrid of two tables, the base 255 table for the hibyte - // and a smaller table with hints on how to use the table for certain values - // and the left over values some simple calculations to approximate the final - // 16 bit value as compared to the equation - static const NeoGamma16LowHint _hints[] = { - {0,16}, {1,16}, {2,16}, {3,16}, {4,16}, {5,16}, {6,16}, {7,16}, {8,16}, {9,16}, {10,16}, {11,16}, {12,16}, {13,16}, {14,16}, {15,16}, - {0,10}, {1,10}, {2,10}, {3,10}, {4,10}, {5,10}, {6,10}, {7,10}, {8,10}, {9,10}, {0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}, - {0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}, {0,4}, {1,4}, {2,4}, {3,4}, {0,4}, {1,4}, {2,4}, {3,4}, {0,3}, {1,3}, - {2,3}, {0,4}, {1,4}, {2,4}, {3,4}, {0,3}, {1,3}, {2,3}, {0,3}, {1,3}, {2,3}, {0,2}, {1,2}, {0,3}, {1,3}, {2,3}, - {0,2}, {1,2}, {0,2}, {1,2}, {0,3}, {1,3}, {2,3}, {0,2}, {1,2} - }; - - uint8_t hi = (value >> 8); - uint16_t lo = (value & 0x00ff); - uint8_t hiResult = _table[hi]; - uint16_t lowResult = 0; - - if (hi < countof(_hints)) - { - // use _hints table to calculate a reasonable lowbyte - lowResult = (lo + _hints[hi].pos * 256) / _hints[hi].count; - } - else if (hi == 255) - { - // last entry is always linear - lowResult = lo; - } - else - { - // check the _table for duplicate or jumps to adjust the range of lowbyte - if (hiResult == _table[hi - 1]) - { - // this result is an upper duplicate - lowResult = (lo >> 1) | 0x80; // lo / 2 + 128 - } - else - { - uint8_t delta = _table[hi + 1] - hiResult; - - if (delta == 0) - { - // this result is a lower duplicate - lowResult = (lo >> 1); // lo / 2 - } - else if (delta == 1) - { - // this result is incremental and thus linear - lowResult = lo; - } - else - { - // this result jumps by more than one, so need to spread across - lowResult = delta * lo; - } - } - - } - - return (static_cast(hiResult) << 8) + lowResult; - } - - -private: - static const uint8_t _table[256]; - -}; diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColorBase.h b/lib/NeoPixelBus/src/internal/colors/RgbColorBase.h deleted file mode 100644 index aef9d9a899..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/RgbColorBase.h +++ /dev/null @@ -1,69 +0,0 @@ -/*------------------------------------------------------------------------- -RgbColorBase provides a RGB color object common support - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -struct HslColor; -struct HsbColor; -struct HtmlColor; -struct Rgb16Color; - -struct RgbColorBase -{ - -protected: - static float _CalcColor(float p, float q, float t); - - static void _HslToRgb(const HslColor& color, float* r, float* g, float* b); - - static void _HsbToRgb(const HsbColor& color, float* r, float* g, float* b); - - template static T_RESULT _Compare( - const T_COLOR& left, - const T_COLOR& right, - T_RESULT epsilon) - { - T_RESULT result = 0; - T_RESULT resultAbs = 0; - - for (size_t elem = 0; elem < T_COLOR::Count; elem++) - { - T_RESULT delta = static_cast(left[elem]) - right[elem]; - T_RESULT deltaAbs = abs(delta); - - if (deltaAbs > resultAbs) - { - resultAbs = deltaAbs; - result = delta; - } - } - - if (resultAbs > epsilon) - { - return result; - } - return 0; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColorIndexes.h b/lib/NeoPixelBus/src/internal/colors/RgbColorIndexes.h deleted file mode 100644 index ea2bac0bfc..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/RgbColorIndexes.h +++ /dev/null @@ -1,35 +0,0 @@ -/*------------------------------------------------------------------------- -RgbColorIndexes provides constants for color element vector access on - RGB(w) Color Objects - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -const uint8_t ColorIndexR = 0; -const uint8_t ColorIndexG = 1; -const uint8_t ColorIndexB = 2; -const uint8_t ColorIndexW = 3; -const uint8_t ColorIndexWW = 3; // warmer white -const uint8_t ColorIndexCW = 4; // cooler white \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.cpp b/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.cpp deleted file mode 100644 index e90f7af734..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/*------------------------------------------------------------------------- -Rgbw64Color provides a color object that can be directly consumed by NeoPixelBus - -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 -. --------------------------------------------------------------------------*/ - -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" -#include "RgbwColor.h" -#include "Rgb48Color.h" -#include "HslColor.h" -#include "HsbColor.h" -#include "Rgbw64Color.h" -#include "HtmlColor.h" - -Rgbw64Color::Rgbw64Color(const HslColor& color) -{ - Rgb48Color rgbColor(color); - *this = rgbColor; -} - -Rgbw64Color::Rgbw64Color(const HsbColor& color) -{ - Rgb48Color rgbColor(color); - *this = rgbColor; -} - -uint16_t Rgbw64Color::CalculateBrightness() const -{ - uint16_t colorB = static_cast((static_cast(R) + static_cast(G) + static_cast(B)) / 3); - if (W > colorB) - { - return W; - } - else - { - return colorB; - } -} - -Rgbw64Color Rgbw64Color::Dim(uint16_t ratio) const -{ - // specifically avoids float math - return Rgbw64Color(_elementDim(R, ratio), _elementDim(G, ratio), _elementDim(B, ratio), _elementDim(W, ratio)); -} - -Rgbw64Color Rgbw64Color::Brighten(uint16_t ratio) const -{ - // specifically avoids float math - return Rgbw64Color(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio), _elementBrighten(W, ratio)); -} - -void Rgbw64Color::Darken(uint16_t delta) -{ - if (R > delta) - { - R -= delta; - } - else - { - R = 0; - } - - if (G > delta) - { - G -= delta; - } - else - { - G = 0; - } - - if (B > delta) - { - B -= delta; - } - else - { - B = 0; - } - - if (W > delta) - { - W -= delta; - } - else - { - W = 0; - } -} - -void Rgbw64Color::Lighten(uint16_t delta) -{ - if (IsColorLess()) - { - if (W < Max - delta) - { - W += delta; - } - else - { - W = Max; - } - } - else - { - if (R < Max - delta) - { - R += delta; - } - else - { - R = Max; - } - - if (G < Max - delta) - { - G += delta; - } - else - { - G = Max; - } - - if (B < Max - delta) - { - B += delta; - } - else - { - B = Max; - } - } -} - -Rgbw64Color Rgbw64Color::LinearBlend(const Rgbw64Color& left, const Rgbw64Color& right, float progress) -{ - return Rgbw64Color( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress), - left.W + ((static_cast(right.W) - left.W) * progress) ); -} -Rgbw64Color Rgbw64Color::LinearBlend(const Rgbw64Color& left, const Rgbw64Color& right, uint8_t progress) -{ - return Rgbw64Color(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8), - left.W + (((static_cast(right.W) - left.W) * static_cast(progress) + 1) >> 8)); -} - -Rgbw64Color Rgbw64Color::BilinearBlend(const Rgbw64Color& c00, - const Rgbw64Color& c01, - const Rgbw64Color& c10, - const Rgbw64Color& c11, - float x, - float y) -{ - float v00 = (1.0f - x) * (1.0f - y); - float v10 = x * (1.0f - y); - float v01 = (1.0f - x) * y; - float v11 = x * y; - - return Rgbw64Color( - c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11, - c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11, - c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11, - c00.W * v00 + c10.W * v10 + c01.W * v01 + c11.W * v11 ); -} \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.h b/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.h deleted file mode 100644 index 9729740d86..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.h +++ /dev/null @@ -1,348 +0,0 @@ -/*------------------------------------------------------------------------- -Rgbw64Color provides a color object that can be directly consumed by NeoPixelBus - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -struct RgbColor; -struct HslColor; -struct HsbColor; - -// ------------------------------------------------------------------------ -// Rgbw64Color represents a color object that is represented by Red, Green, Blue -// component values and an extra White component. It contains helpful color -// routines to manipulate the color. -// ------------------------------------------------------------------------ -struct Rgbw64Color : RgbColorBase -{ - typedef NeoRgbwCurrentSettings SettingsObject; - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using R, G, B, W values (0-65535) - // ------------------------------------------------------------------------ - Rgbw64Color(uint16_t r, uint16_t g, uint16_t b, uint16_t w = 0) : - R(r), G(g), B(b), W(w) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbColor using a single brightness value (0-65535) - // This works well for creating gray tone colors - // (0) = black, (65535) = white, (32768) = gray - // ------------------------------------------------------------------------ - Rgbw64Color(uint16_t brightness) : - R(0), G(0), B(0), W(brightness) - { - }; - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using RgbColor - // ------------------------------------------------------------------------ - Rgbw64Color(const RgbColor& color) - { - *this = Rgb48Color(color); - }; - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using Rgb48Color - // ------------------------------------------------------------------------ - Rgbw64Color(const Rgb48Color& color) : - R(color.R), - G(color.G), - B(color.B), - W(0) - { - }; - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using RgbwColor - // ------------------------------------------------------------------------ - Rgbw64Color(const RgbwColor& color) - { - // x16 = map(x8, 0, 255, 0, 65535); // refactors to just * 257 - R = (uint16_t)color.R * 257; // 257 = MAXUINT16/MAXUINT8 = 65535/255 - G = (uint16_t)color.G * 257; - B = (uint16_t)color.B * 257; - W = (uint16_t)color.W * 257; - }; - - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using HtmlColor - // ------------------------------------------------------------------------ - Rgbw64Color(const HtmlColor& color) - { - *this = RgbwColor(color); - } - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using HslColor - // ------------------------------------------------------------------------ - Rgbw64Color(const HslColor& color); - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using HsbColor - // ------------------------------------------------------------------------ - Rgbw64Color(const HsbColor& color); - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color that will have its values set in latter operations - // CAUTION: The R,G,B, W members are not initialized and may not be consistent - // ------------------------------------------------------------------------ - Rgbw64Color() - { - }; - - // ------------------------------------------------------------------------ - // Comparison operators - // ------------------------------------------------------------------------ - bool operator==(const Rgbw64Color& other) const - { - return (R == other.R && G == other.G && B == other.B && W == other.W); - }; - - bool operator!=(const Rgbw64Color& other) const - { - return !(*this == other); - }; - - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int32_t CompareTo(const Rgbw64Color& other, uint16_t epsilon = 256) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int32_t Compare(const Rgbw64Color& left, const Rgbw64Color& right, uint16_t epsilon = 256) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - default: - return W; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint16_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - default: - return W; - } - } - - // ------------------------------------------------------------------------ - // Returns if the color is grey, all values are equal other than white - // ------------------------------------------------------------------------ - bool IsMonotone() const - { - return (R == B && R == G); - }; - - // ------------------------------------------------------------------------ - // Returns if the color components are all zero, the white component maybe - // anything - // ------------------------------------------------------------------------ - bool IsColorLess() const - { - return (R == 0 && B == 0 && G == 0); - }; - - // ------------------------------------------------------------------------ - // CalculateBrightness will calculate the overall brightness - // NOTE: This is a simple linear brightness - // ------------------------------------------------------------------------ - uint16_t CalculateBrightness() const; - - // ------------------------------------------------------------------------ - // Dim will return a new color that is blended to black with the given ratio - // ratio - (0-65535) where 65535 will return the original color and 0 will return black - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgbw64Color Dim(uint16_t ratio) const; - - // ------------------------------------------------------------------------ - // Dim will return a new color that is blended to black with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return black - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgbw64Color Dim(uint8_t ratio) const - { - uint16_t expanded = ratio << 8; - return Dim(expanded); - } - - // ------------------------------------------------------------------------ - // Brighten will return a new color that is blended to white with the given ratio - // ratio - (0-65535) where 65535 will return the original color and 0 will return white - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgbw64Color Brighten(uint16_t ratio) const; - - // ------------------------------------------------------------------------ - // Brighten will return a new color that is blended to white with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return white - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgbw64Color Brighten(uint8_t ratio) const - { - uint16_t expanded = ratio << 8; - return Brighten(expanded); - } - - // ------------------------------------------------------------------------ - // Darken will adjust the color by the given delta toward black - // NOTE: This is a simple linear change - // delta - (0-65535) the amount to dim the color - // ------------------------------------------------------------------------ - void Darken(uint16_t delta); - - // ------------------------------------------------------------------------ - // Lighten will adjust the color by the given delta toward white - // NOTE: This is a simple linear change - // delta - (0-65535) the amount to lighten the color - // ------------------------------------------------------------------------ - void Lighten(uint16_t delta); - - // ------------------------------------------------------------------------ - // LinearBlend between two colors by the amount defined by progress variable - // left - the color to start the blend at - // right - the color to end the blend at - // progress - (0.0 - 1.0) value where 0 will return left and 1.0 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static Rgbw64Color LinearBlend(const Rgbw64Color& left, const Rgbw64Color& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static Rgbw64Color LinearBlend(const Rgbw64Color& left, const Rgbw64Color& right, uint8_t progress); - - // ------------------------------------------------------------------------ - // BilinearBlend between four colors by the amount defined by 2d variable - // c00 - upper left quadrant color - // c01 - upper right quadrant color - // c10 - lower left quadrant color - // c11 - lower right quadrant color - // x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space - // y - unit value (0.0 - 1.0) that defines the blend progress in vertical space - // ------------------------------------------------------------------------ - static Rgbw64Color BilinearBlend(const Rgbw64Color& c00, - const Rgbw64Color& c01, - const Rgbw64Color& c10, - const Rgbw64Color& c11, - float x, - float y); - - uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) - { - auto total = 0; - - total += R * settings.RedTenthMilliAmpere / Max; - total += G * settings.GreenTenthMilliAmpere / Max; - total += B * settings.BlueTenthMilliAmpere / Max; - total += W * settings.WhiteTenthMilliAmpere / Max; - - return total; - } - - // ------------------------------------------------------------------------ - // Red, Green, Blue, White color members (0-65535) where - // (0,0,0,0) is black and (65535,65535,65535, 0) and (0,0,0,65535) is white - // Note (65535,65535,65535,65535) is extreme bright white - // ------------------------------------------------------------------------ - uint16_t R; - uint16_t G; - uint16_t B; - uint16_t W; - - const static uint16_t Max = 65535; - const static size_t Count = 4; // four elements in [] - -private: - inline static uint16_t _elementDim(uint16_t value, uint16_t ratio) - { - return (static_cast(value) * (static_cast(ratio) + 1)) >> 16; - } - - inline static uint16_t _elementBrighten(uint16_t value, uint16_t ratio) - { - uint32_t element = ((static_cast(value) + 1) << 16) / (static_cast(ratio) + 1); - - if (element > Max) - { - element = Max; - } - else - { - element -= 1; - } - return element; - } -}; - diff --git a/lib/NeoPixelBus/src/internal/colors/RgbwwColor.cpp b/lib/NeoPixelBus/src/internal/colors/RgbwwColor.cpp deleted file mode 100644 index 9751bc2602..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/RgbwwColor.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/*------------------------------------------------------------------------- -RgbwwColor provides a color object that can be directly consumed by NeoPixelBus - -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 -. --------------------------------------------------------------------------*/ - -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" -#include "RgbwColor.h" -#include "Rgb48Color.h" -#include "HslColor.h" -#include "HsbColor.h" -#include "HtmlColor.h" - -#include "RgbwwColor.h" - -RgbwwColor::RgbwwColor(const HtmlColor& color) -{ - uint32_t temp = color.Color; - B = (temp & 0xff); - temp = temp >> 8; - G = (temp & 0xff); - temp = temp >> 8; - R = (temp & 0xff); - temp = temp >> 8; - WW = (temp & 0xff); - CW = WW; -}; - -RgbwwColor::RgbwwColor(const HslColor& color) -{ - RgbColor rgbColor(color); - *this = rgbColor; -} - -RgbwwColor::RgbwwColor(const HsbColor& color) -{ - RgbColor rgbColor(color); - *this = rgbColor; -} - -uint8_t RgbwwColor::CalculateBrightness() const -{ - uint8_t colorB = static_cast((static_cast(R) + static_cast(G) + static_cast(B)) / 3); - uint8_t whiteB = static_cast((static_cast(WW) + static_cast(CW)) / 2); - - return (whiteB > colorB) ? whiteB : colorB; -} - -RgbwwColor RgbwwColor::Dim(uint8_t ratio) const -{ - // specifically avoids float math - return RgbwwColor(_elementDim(R, ratio), - _elementDim(G, ratio), - _elementDim(B, ratio), - _elementDim(WW, ratio), - _elementDim(CW, ratio)); -} - -RgbwwColor RgbwwColor::Brighten(uint8_t ratio) const -{ - // specifically avoids float math - return RgbwwColor(_elementBrighten(R, ratio), - _elementBrighten(G, ratio), - _elementBrighten(B, ratio), - _elementBrighten(WW, ratio), - _elementBrighten(CW, ratio)); -} - -void RgbwwColor::Darken(uint8_t delta) -{ - if (R > delta) - { - R -= delta; - } - else - { - R = 0; - } - - if (G > delta) - { - G -= delta; - } - else - { - G = 0; - } - - if (B > delta) - { - B -= delta; - } - else - { - B = 0; - } - - if (WW > delta) - { - WW -= delta; - } - else - { - WW = 0; - } - - if (CW > delta) - { - CW -= delta; - } - else - { - CW = 0; - } -} - -void RgbwwColor::Lighten(uint8_t delta) -{ - if (IsColorLess()) - { - if (WW < 255 - delta) - { - WW += delta; - } - else - { - WW = 255; - } - - if (CW < 255 - delta) - { - CW += delta; - } - else - { - CW = 255; - } - } - else - { - if (R < 255 - delta) - { - R += delta; - } - else - { - R = 255; - } - - if (G < 255 - delta) - { - G += delta; - } - else - { - G = 255; - } - - if (B < 255 - delta) - { - B += delta; - } - else - { - B = 255; - } - } -} - -RgbwwColor RgbwwColor::LinearBlend(const RgbwwColor& left, const RgbwwColor& right, float progress) -{ - return RgbwwColor( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress), - left.WW + ((static_cast(right.WW) - left.WW) * progress), - left.CW + ((static_cast(right.CW) - left.CW) * progress)); -} - -RgbwwColor RgbwwColor::LinearBlend(const RgbwwColor& left, const RgbwwColor& right, uint8_t progress) -{ - return RgbwwColor(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8), - left.WW + (((static_cast(right.WW) - left.WW) * static_cast(progress) + 1) >> 8), - left.CW + (((static_cast(right.CW) - left.CW) * static_cast(progress) + 1) >> 8)); -} - -RgbwwColor RgbwwColor::BilinearBlend(const RgbwwColor& c00, - const RgbwwColor& c01, - const RgbwwColor& c10, - const RgbwwColor& c11, - float x, - float y) -{ - float v00 = (1.0f - x) * (1.0f - y); - float v10 = x * (1.0f - y); - float v01 = (1.0f - x) * y; - float v11 = x * y; - - return RgbwwColor( - c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11, - c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11, - c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11, - c00.WW * v00 + c10.WW * v10 + c01.WW * v01 + c11.WW * v11, - c00.CW * v00 + c10.CW * v10 + c01.CW * v01 + c11.CW * v11); -} \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/RgbwwColor.h b/lib/NeoPixelBus/src/internal/colors/RgbwwColor.h deleted file mode 100644 index 8833e783d5..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/RgbwwColor.h +++ /dev/null @@ -1,325 +0,0 @@ -/*------------------------------------------------------------------------- -RgbwwColor provides a color object that can be directly consumed by NeoPixelBus - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -struct RgbColor; -struct HslColor; -struct HsbColor; - -// ------------------------------------------------------------------------ -// RgbwwColor represents a color object that is represented by Red, Green, Blue -// component values and two extra White components. -// While the white components are labeled as WW (warm) and CW (cool), they can be -// considered as the "warmer" and "cooler" whites of your LEDs; so that if yours -// have Nuetral and Cool, you could consider the WW as your nuetral. -// It contains helpful color routines to manipulate the color. -// ------------------------------------------------------------------------ -struct RgbwwColor : RgbColorBase -{ - typedef NeoRgbwwCurrentSettings SettingsObject; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using R, G, B, WW, CW values (0-255) - // ------------------------------------------------------------------------ - RgbwwColor(uint8_t r, uint8_t g, uint8_t b, uint8_t warmW = 0, uint8_t coolW = 0) : - R(r), G(g), B(b), WW(warmW), CW(coolW) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using a single brightness value (0-255) - // This works well for creating gray tone colors - // (0) = black, (255) = white, (128) = gray - // ------------------------------------------------------------------------ - RgbwwColor(uint8_t brightness) : - R(0), G(0), B(0), WW(brightness), CW(brightness) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using RgbColor - // ------------------------------------------------------------------------ - RgbwwColor(const RgbColor& color) : - R(color.R), - G(color.G), - B(color.B), - WW(0), - CW(0) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using RgbwColor - // ------------------------------------------------------------------------ - RgbwwColor(const RgbwColor& color) : - R(color.R), - G(color.G), - B(color.B), - WW(color.W), - CW(color.W) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using HtmlColor - // ------------------------------------------------------------------------ - RgbwwColor(const HtmlColor& color); - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using HslColor - // ------------------------------------------------------------------------ - RgbwwColor(const HslColor& color); - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using HsbColor - // ------------------------------------------------------------------------ - RgbwwColor(const HsbColor& color); - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor that will have its values set in latter operations - // CAUTION: The R,G,B, WW, CW members are not initialized and may not be consistent - // ------------------------------------------------------------------------ - RgbwwColor() - { - }; - - // ------------------------------------------------------------------------ - // Comparison operators - // ------------------------------------------------------------------------ - bool operator==(const RgbwwColor& other) const - { - return (R == other.R && G == other.G && B == other.B && WW == other.WW && CW == other.CW); - }; - - bool operator!=(const RgbwwColor& other) const - { - return !(*this == other); - }; - - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int16_t CompareTo(const RgbwwColor& other, uint8_t epsilon = 1) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int16_t Compare(const RgbwwColor& left, const RgbwwColor& right, uint8_t epsilon = 1) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B,WW,CW - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - case 3: - return WW; - default: - return CW; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B,WW,CW - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - case 3: - return WW; - default: - return CW; - } - } - - // ------------------------------------------------------------------------ - // Returns if the color is grey, all values are equal other than whites - // ------------------------------------------------------------------------ - bool IsMonotone() const - { - return (R == B && R == G); - }; - - // ------------------------------------------------------------------------ - // Returns if the color components are all zero, the white components maybe - // anything - // ------------------------------------------------------------------------ - bool IsColorLess() const - { - return (R == 0 && B == 0 && G == 0); - }; - - // ------------------------------------------------------------------------ - // CalculateBrightness will calculate the overall brightness - // NOTE: This is a simple linear brightness - // ------------------------------------------------------------------------ - uint8_t CalculateBrightness() const; - - // ------------------------------------------------------------------------ - // Dim will return a new color that is blended to black with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return black - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - RgbwwColor Dim(uint8_t ratio) const; - - // ------------------------------------------------------------------------ - // Brighten will return a new color that is blended to white with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return white - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - RgbwwColor Brighten(uint8_t ratio) const; - - // ------------------------------------------------------------------------ - // Darken will adjust the color by the given delta toward black - // NOTE: This is a simple linear change - // delta - (0-255) the amount to dim the color - // ------------------------------------------------------------------------ - void Darken(uint8_t delta); - - // ------------------------------------------------------------------------ - // Lighten will adjust the color by the given delta toward white - // NOTE: This is a simple linear change - // delta - (0-255) the amount to lighten the color - // ------------------------------------------------------------------------ - void Lighten(uint8_t delta); - - // ------------------------------------------------------------------------ - // LinearBlend between two colors by the amount defined by progress variable - // left - the color to start the blend at - // right - the color to end the blend at - // progress - (0.0 - 1.0) value where 0 will return left and 1.0 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static RgbwwColor LinearBlend(const RgbwwColor& left, const RgbwwColor& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static RgbwwColor LinearBlend(const RgbwwColor& left, const RgbwwColor& right, uint8_t progress); - - // ------------------------------------------------------------------------ - // BilinearBlend between four colors by the amount defined by 2d variable - // c00 - upper left quadrant color - // c01 - upper right quadrant color - // c10 - lower left quadrant color - // c11 - lower right quadrant color - // x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space - // y - unit value (0.0 - 1.0) that defines the blend progress in vertical space - // ------------------------------------------------------------------------ - static RgbwwColor BilinearBlend(const RgbwwColor& c00, - const RgbwwColor& c01, - const RgbwwColor& c10, - const RgbwwColor& c11, - float x, - float y); - - uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) - { - auto total = 0; - - total += R * settings.RedTenthMilliAmpere / Max; - total += G * settings.GreenTenthMilliAmpere / Max; - total += B * settings.BlueTenthMilliAmpere / Max; - total += WW * settings.WarmWhiteTenthMilliAmpere / Max; - total += CW * settings.CoolWhiteTenthMilliAmpere / Max; - - return total; - } - - // ------------------------------------------------------------------------ - // Red, Green, Blue, Warm White, Cool White color members (0-255) where - // (0,0,0,0,0) is black and - // (255,255,255, 0, 0) is a white - // (0,0,0,255,0) is warm white and - // (0,0,0,0,255) is cool white and - // Note (255,255,255,255,255) is extreme bright white - // ------------------------------------------------------------------------ - uint8_t R; - uint8_t G; - uint8_t B; - uint8_t WW; - uint8_t CW; - - const static uint8_t Max = 255; - const static size_t Count = 5; // four elements in [] - -private: - inline static uint8_t _elementDim(uint8_t value, uint8_t ratio) - { - return (static_cast(value) * (static_cast(ratio) + 1)) >> 8; - } - - inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio) - { - uint16_t element = ((static_cast(value) + 1) << 8) / (static_cast(ratio) + 1); - - if (element > Max) - { - element = Max; - } - else - { - element -= 1; - } - return element; - } -}; - diff --git a/lib/NeoPixelBus/src/internal/features/DotStarL4ByteFeature.h b/lib/NeoPixelBus/src/internal/features/DotStarL4ByteFeature.h deleted file mode 100644 index 0e6a0b17f6..0000000000 --- a/lib/NeoPixelBus/src/internal/features/DotStarL4ByteFeature.h +++ /dev/null @@ -1,70 +0,0 @@ -/*------------------------------------------------------------------------- -DotStarL4Feature provides feature base class to describe color order for - 3 color but 4 byte features when used with DotStars, exposing Luminance as W - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class DotStarL4Feature : - public NeoByteElements<4, RgbwColor, uint32_t> -{ -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[V_IC_1]; - *p++ = color[V_IC_2]; - *p = color[V_IC_3]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color.W = (*p++) & 0x1F; // mask out upper three bits - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *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[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p); - - return color; - } - -}; diff --git a/lib/NeoPixelBus/src/internal/features/DotStarLrgbFeatures.h b/lib/NeoPixelBus/src/internal/features/DotStarLrgbFeatures.h deleted file mode 100644 index 17c6d4f708..0000000000 --- a/lib/NeoPixelBus/src/internal/features/DotStarLrgbFeatures.h +++ /dev/null @@ -1,65 +0,0 @@ -/*------------------------------------------------------------------------- -DotStarLrgbFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with DotStars - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class DotStarLrgbFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarLrbgFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - - -class DotStarLgrbFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarLgbrFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - - -class DotStarLbrgFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarLbgrFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/DotStarRgbFeatures.h b/lib/NeoPixelBus/src/internal/features/DotStarRgbFeatures.h deleted file mode 100644 index 158e579d7f..0000000000 --- a/lib/NeoPixelBus/src/internal/features/DotStarRgbFeatures.h +++ /dev/null @@ -1,65 +0,0 @@ -/*------------------------------------------------------------------------- -DotStarRbgFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with DotStars - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class DotStarRgbFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarRbgFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - - -class DotStarGbrFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarGrbFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - - -class DotStarBrgFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarBgrFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/DotStarX4ByteFeature.h b/lib/NeoPixelBus/src/internal/features/DotStarX4ByteFeature.h deleted file mode 100644 index 2d2aeb71fb..0000000000 --- a/lib/NeoPixelBus/src/internal/features/DotStarX4ByteFeature.h +++ /dev/null @@ -1,70 +0,0 @@ -/*------------------------------------------------------------------------- -DotStarX4Feature provides feature base class to describe color order for - 3 color but 4 byte features when used with DotStars - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class DotStarX4Feature : - public NeoByteElements<4, RgbColor, uint32_t> -{ -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[V_IC_1]; - *p++ = color[V_IC_2]; - *p = color[V_IC_3]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - p++; // ignore the first byte - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *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[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p); - - return color; - } - -}; diff --git a/lib/NeoPixelBus/src/internal/features/Lpd6803RgbFeatures.h b/lib/NeoPixelBus/src/internal/features/Lpd6803RgbFeatures.h deleted file mode 100644 index 15e8fa52c0..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Lpd6803RgbFeatures.h +++ /dev/null @@ -1,52 +0,0 @@ -/*------------------------------------------------------------------------- -Lpd6803RgbFeature provides feature class to describe color order and -color depth for NeoPixelBus template class when used with DotStar like chips - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class Lpd6803RgbFeature : - public Neo2Byte555Feature, - public NeoElementsNoSettings -{ -}; - - -class Lpd6803GrbFeature : - public Neo2Byte555Feature, - public NeoElementsNoSettings -{ -}; - -class Lpd6803GbrFeature : - public Neo2Byte555Feature, - public NeoElementsNoSettings -{ -}; - -class Lpd6803BrgFeature : - public Neo2Byte555Feature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/Lpd8806RgbFeatures.h b/lib/NeoPixelBus/src/internal/features/Lpd8806RgbFeatures.h deleted file mode 100644 index e800a1f996..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Lpd8806RgbFeatures.h +++ /dev/null @@ -1,39 +0,0 @@ -/*------------------------------------------------------------------------- -Lpd8806RgbFeatures provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with DotStar like chips - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class Lpd8806GrbFeature : - public Neo3Byte777Feature, - public NeoElementsNoSettings -{ -}; - -class Lpd8806BrgFeature : - public Neo3Byte777Feature, - public NeoElementsNoSettings -{ -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo2Byte555Feature.h b/lib/NeoPixelBus/src/internal/features/Neo2Byte555Feature.h deleted file mode 100644 index a9fca0d3fb..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo2Byte555Feature.h +++ /dev/null @@ -1,89 +0,0 @@ -/*------------------------------------------------------------------------- -Neo2Byte555Feature provides feature base classes to describe color elements -with 555 encoding for NeoPixelBus Color Feature template classes - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class Neo2Byte555Feature : - public NeoByteElements<2, RgbColor, uint16_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - uint16_t color555; - - encodePixel(&color555, color); - *p++ = color555 >> 8; - *p = color555 & 0xff; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - uint16_t color555; - - color555 = ((*p++) << 8); - color555 |= (*p); - - decodePixel(&color, color555); - - 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); - - uint16_t color555; - - color555 = (pgm_read_byte(p++) << 8); - color555 |= pgm_read_byte(p); - - decodePixel(&color, color555); - - return color; - } - -protected: - static void encodePixel(uint16_t* color555, const ColorObject& color) - { - *color555 = (0x8000 | - ((color[V_IC_1] & 0xf8) << 7) | - ((color[V_IC_2] & 0xf8) << 2) | - ((color[V_IC_3] & 0xf8) >> 3)); - } - - static void decodePixel(ColorObject* color, uint16_t color555) - { - (*color)[V_IC_2] = (color555 >> 2) & 0xf8; - (*color)[V_IC_3] = (color555 << 3) & 0xf8; - (*color)[V_IC_1] = (color555 >> 7) & 0xf8; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo3Byte777Feature.h b/lib/NeoPixelBus/src/internal/features/Neo3Byte777Feature.h deleted file mode 100644 index 1ce703161d..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo3Byte777Feature.h +++ /dev/null @@ -1,67 +0,0 @@ -/*------------------------------------------------------------------------- -Neo3Byte777Feature provides feature base class to describe color order for - 3 byte features that only support 7 bits per element - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class Neo3Byte777Feature : - public NeoByteElements<3, RgbColor, uint8_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = (color[V_IC_1] >> 1) | 0x80; - *p++ = (color[V_IC_2] >> 1) | 0x80; - *p = (color[V_IC_3] >> 1) | 0x80; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = (*p++) << 1; - color[V_IC_2] = (*p++) << 1; - color[V_IC_3] = (*p) << 1; - - return color; - } - - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = (pgm_read_byte(p++)) << 1; - color[V_IC_2] = (pgm_read_byte(p++)) << 1; - color[V_IC_3] = (pgm_read_byte(p)) << 1; - - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo3ByteFeature.h b/lib/NeoPixelBus/src/internal/features/Neo3ByteFeature.h deleted file mode 100644 index d6a228fdd8..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo3ByteFeature.h +++ /dev/null @@ -1,67 +0,0 @@ -/*------------------------------------------------------------------------- -Neo3ByteFeature provides feature base class to describe color order for - 3 byte features - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class Neo3ByteFeature : - public NeoByteElements<3, RgbColor, uint8_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = color[V_IC_1]; - *p++ = color[V_IC_2]; - *p = color[V_IC_3]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *p; - - return color; - } - - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p); - - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo3WordFeature.h b/lib/NeoPixelBus/src/internal/features/Neo3WordFeature.h deleted file mode 100644 index 4d74092688..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo3WordFeature.h +++ /dev/null @@ -1,77 +0,0 @@ -/*------------------------------------------------------------------------- -Neo3WordFeature provides feature base class to describe color order for - 3 Word features - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class Neo3WordFeature : - public NeoWordElements<6, Rgb48Color, uint16_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // due to endianness the byte order must be copied to output - *p++ = color[V_IC_1] >> 8; - *p++ = color[V_IC_1] & 0xff; - *p++ = color[V_IC_2] >> 8; - *p++ = color[V_IC_2] & 0xff; - *p++ = color[V_IC_3] >> 8; - *p = color[V_IC_3] & 0xff; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // due to endianness the byte order must be copied to output - color[V_IC_1] = (static_cast(*p++) << 8); - color[V_IC_1] |= *p++; - color[V_IC_2] = (static_cast(*p++) << 8); - color[V_IC_2] |= *p++; - color[V_IC_3] = (static_cast(*p++) << 8); - color[V_IC_3] |= *p; - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); - - // PROGMEM unit of storage expected to be the same size as color element - // so no endianness issues to worry about - color[V_IC_1] = pgm_read_word(p++); - color[V_IC_2] = pgm_read_word(p++); - color[V_IC_3] = pgm_read_word(p); - - return color; - } - - }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo4ByteFeature.h b/lib/NeoPixelBus/src/internal/features/Neo4ByteFeature.h deleted file mode 100644 index eea734c763..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo4ByteFeature.h +++ /dev/null @@ -1,69 +0,0 @@ -/*------------------------------------------------------------------------- -Neo4ByteFeature provides feature base class to describe color order for - 6 byte features that only use the first 5 bytes - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class Neo4ByteFeature : - public NeoByteElements<4, RgbwColor, uint32_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = color[V_IC_1]; - *p++ = color[V_IC_2]; - *p++ = color[V_IC_3]; - *p = color[V_IC_4]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *p++; - color[V_IC_4] = *p; - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p++); - color[V_IC_4] = pgm_read_byte(p); - - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo4WordFeature.h b/lib/NeoPixelBus/src/internal/features/Neo4WordFeature.h deleted file mode 100644 index fe3d3ad80a..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo4WordFeature.h +++ /dev/null @@ -1,82 +0,0 @@ -/*------------------------------------------------------------------------- -Neo4WordFeature provides feature base class to describe color order for - 4 Word features - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class Neo4WordFeature : - public NeoWordElements<8, Rgbw64Color, uint32_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // due to endianness the byte order must be copied to output - *p++ = color[V_IC_1] >> 8; - *p++ = color[V_IC_1] & 0xff; - *p++ = color[V_IC_2] >> 8; - *p++ = color[V_IC_2] & 0xff; - *p++ = color[V_IC_3] >> 8; - *p++ = color[V_IC_3] & 0xff; - *p++ = color[V_IC_4] >> 8; - *p = color[V_IC_4] & 0xff; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // due to endianness the byte order must be copied to output - color[V_IC_1] = (static_cast(*p++) << 8); - color[V_IC_1] |= *p++; - color[V_IC_2] = (static_cast(*p++) << 8); - color[V_IC_2] |= *p++; - color[V_IC_3] = (static_cast(*p++) << 8); - color[V_IC_3] |= *p++; - color[V_IC_4] = (static_cast(*p++) << 8); - color[V_IC_4] |= *p; - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); - - // PROGMEM unit of storage expected to be the same size as color element - // so no endianness issues to worry about - color[V_IC_1] = pgm_read_word(p++); - color[V_IC_2] = pgm_read_word(p++); - color[V_IC_3] = pgm_read_word(p++); - color[V_IC_4] = pgm_read_word(p); - - return color; - } - - }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo6xByteFeature.h b/lib/NeoPixelBus/src/internal/features/Neo6xByteFeature.h deleted file mode 100644 index 9b732c604a..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo6xByteFeature.h +++ /dev/null @@ -1,76 +0,0 @@ -/*------------------------------------------------------------------------- -Neo6xByteFeature provides feature base class to describe color order for - 6 byte features that only use the first 5 bytes - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class Neo6xByteFeature : - public NeoByteElements<6, RgbwwColor, uint16_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = color[V_IC_1]; - *p++ = color[V_IC_2]; - *p++ = color[V_IC_3]; - *p++ = color[V_IC_4]; - *p++ = color[V_IC_5]; - - *p = 0x00; // X - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *p++; - color[V_IC_4] = *p++; - color[V_IC_5] = *p; - // ignore the x - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p++); - color[V_IC_4] = pgm_read_byte(p++); - color[V_IC_5] = pgm_read_byte(p); - // ignore the x - - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo6xxByteFeature.h b/lib/NeoPixelBus/src/internal/features/Neo6xxByteFeature.h deleted file mode 100644 index 6b5bdec25a..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo6xxByteFeature.h +++ /dev/null @@ -1,73 +0,0 @@ -/*------------------------------------------------------------------------- -Neo6xxByteFeature provides feature base class to describe color order for - 6 byte features that only use the first 4 bytes - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -template -class Neo6xxByteFeature : - public NeoByteElements<6, RgbwColor, uint16_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = color[V_IC_1]; - *p++ = color[V_IC_2]; - *p++ = color[V_IC_3]; - *p++ = color[V_IC_4]; - // zero the xx, this maybe unnecessary though, but its thorough - *p++ = 0x00; - *p = 0x00; // X - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *p++; - color[V_IC_4] = *p; - // ignore the xx - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p++); - color[V_IC_4] = pgm_read_byte(p); - // ignore the xx - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/NeoAbcdefgpsSegmentFeature.h b/lib/NeoPixelBus/src/internal/features/NeoAbcdefgpsSegmentFeature.h deleted file mode 100644 index 940abd847c..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoAbcdefgpsSegmentFeature.h +++ /dev/null @@ -1,72 +0,0 @@ -/*------------------------------------------------------------------------- -NeoAbcdefgpsSegmentFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with seven segment display - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -// Abcdefgps byte order -class NeoAbcdefgpsSegmentFeature : - public NeoByteElements<9, SevenSegDigit, uint8_t>, - public NeoElementsNoSettings -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count; - for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) - { - *p++ = color.Segment[iSegment]; - } - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count; - - for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) - { - color.Segment[iSegment] = *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); - uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count; - - for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) - { - color.Segment[iSegment] = pgm_read_byte(p++); - } - - return color; - } - -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/NeoBacedfpgsSegmentFeature.h b/lib/NeoPixelBus/src/internal/features/NeoBacedfpgsSegmentFeature.h deleted file mode 100644 index 9a36f85bd8..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoBacedfpgsSegmentFeature.h +++ /dev/null @@ -1,93 +0,0 @@ -/*------------------------------------------------------------------------- -NeoBacedfpgsSegmentFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with seven segment display - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -// BACEDF.G+ byte order -class NeoBacedfpgsSegmentFeature : - public NeoByteElements<9, SevenSegDigit, uint8_t>, - public NeoElementsNoSettings -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // Segment Digit is Abcdefgps order - *p++ = color.Segment[LedSegment_B]; - *p++ = color.Segment[LedSegment_A]; - *p++ = color.Segment[LedSegment_C]; - - *p++ = color.Segment[LedSegment_E]; - *p++ = color.Segment[LedSegment_D]; - *p++ = color.Segment[LedSegment_F]; - - *p++ = color.Segment[LedSegment_Decimal]; - *p++ = color.Segment[LedSegment_G]; - *p++ = color.Segment[LedSegment_Custom]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color.Segment[LedSegment_B] = *p++; - color.Segment[LedSegment_A] = *p++; - color.Segment[LedSegment_C] = *p++; - - color.Segment[LedSegment_E] = *p++; - color.Segment[LedSegment_D] = *p++; - color.Segment[LedSegment_F] = *p++; - - color.Segment[LedSegment_Decimal] = *p++; - color.Segment[LedSegment_G] = *p++; - color.Segment[LedSegment_Custom] = *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.Segment[LedSegment_B] = pgm_read_byte(p++); - color.Segment[LedSegment_A] = pgm_read_byte(p++); - color.Segment[LedSegment_C] = pgm_read_byte(p++); - - color.Segment[LedSegment_E] = pgm_read_byte(p++); - color.Segment[LedSegment_D] = pgm_read_byte(p++); - color.Segment[LedSegment_F] = pgm_read_byte(p++); - - color.Segment[LedSegment_Decimal] = pgm_read_byte(p++); - color.Segment[LedSegment_G] = pgm_read_byte(p++); - color.Segment[LedSegment_Custom] = pgm_read_byte(p++); - - return color; - } - -}; diff --git a/lib/NeoPixelBus/src/internal/features/NeoByteElements.h b/lib/NeoPixelBus/src/internal/features/NeoByteElements.h deleted file mode 100644 index 3075bdc5d5..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoByteElements.h +++ /dev/null @@ -1,139 +0,0 @@ -/*------------------------------------------------------------------------- -NeoByteElements provides feature base classes to describe color elements -for NeoPixelBus Color Feature template classes - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -// NeoElementsBase contains common methods used by features to map and -// copy pixel memory data in native stream format -// -// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream -// T_COLOR_OBJECT - the primary color object used to represent a pixel -// T_COPY - (uint8_t/uint16_t/uint32_t) the base type to use when copying/moving -template -class NeoElementsBase -{ -public: - static const size_t PixelSize = V_PIXEL_SIZE; - typedef T_COLOR_OBJECT ColorObject; - - static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) - { - return pPixels + indexPixel * PixelSize; - } - static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) - { - return pPixels + indexPixel * PixelSize; - } - - static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - T_COPY* pDest = reinterpret_cast(pPixelDest); - T_COPY* pEnd = pDest + (count * PixelSize / sizeof(T_COPY)); - const T_COPY* pEndSrc = reinterpret_cast(pPixelSrc) + PixelSize / sizeof(T_COPY); - - while (pDest < pEnd) - { - const T_COPY* pSrc = reinterpret_cast(pPixelSrc); - while (pSrc < pEndSrc) - { - *pDest++ = *pSrc++; - } - } - } - - static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - const T_COPY* pSrc = reinterpret_cast(pPixelSrc); - T_COPY* pDest = reinterpret_cast(pPixelDest); - T_COPY* pEnd = pDest + (count * PixelSize / sizeof(T_COPY)); - - while (pDest < pEnd) - { - *pDest++ = *pSrc++; - } - } - - static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - const T_COPY* pSrc = reinterpret_cast(pPixelSrc); - const T_COPY* pSrcBack = pSrc + (count * PixelSize / sizeof(T_COPY)); - T_COPY* pDest = reinterpret_cast(pPixelDest); - T_COPY* pDestBack = pDest + (count * PixelSize / sizeof(T_COPY)); - - while (pDestBack > pDest) - { - *--pDestBack = *--pSrcBack; - } - } -}; - -// NeoByteElements is used for 8bit color element types and less -// -// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream -// T_COLOR_OBJECT - the primary color object used to represent a pixel -// T_COPY - (uint8_t/uint16_t/uint32_t) the base type to use when copying/moving -template -class NeoByteElements : public NeoElementsBase -{ -public: - - static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) - { - uint8_t* pEnd = pPixelDest + (count * NeoElementsBase::PixelSize); - const uint8_t* pSrc = reinterpret_cast(pPixelSrc); - - while (pPixelDest < pEnd) - { - *pPixelDest++ = pgm_read_byte(pSrc++); - } - } -}; - -// NeoWordElements is used for 16bit color element types -// -// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream -// T_COLOR_OBJECT - the primary color object used to represent a pixel -// T_COPY - (uint16_t/uint32_t) the base type to use when copying/moving -template -class NeoWordElements : public NeoElementsBase -{ -public: - - static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) - { - uint16_t* pDest = reinterpret_cast(pPixelDest); - uint16_t* pEnd = pDest + (count * NeoElementsBase::PixelSize / sizeof(uint16_t)); - const uint16_t* pSrc = reinterpret_cast(pPixelSrc); - - while (pDest < pEnd) - { - *pDest++ = pgm_read_word(pSrc++); - } - } -}; - - diff --git a/lib/NeoPixelBus/src/internal/features/NeoElementsNoSettings.h b/lib/NeoPixelBus/src/internal/features/NeoElementsNoSettings.h deleted file mode 100644 index 39827721de..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoElementsNoSettings.h +++ /dev/null @@ -1,49 +0,0 @@ -/*------------------------------------------------------------------------- -NeoElementsNoSettings provides feature base classes to describe a - no settings feature - -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 -. --------------------------------------------------------------------------*/ -#pragma once -#include "../NeoUtil.h" - -class NeoElementsNoSettings -{ -public: - typedef NeoNoSettings SettingsObject; - static const size_t SettingsSize = 0; - - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) - { - } - - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } - - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgb48Features.h b/lib/NeoPixelBus/src/internal/features/NeoRgb48Features.h deleted file mode 100644 index c9a2165619..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgb48Features.h +++ /dev/null @@ -1,63 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgb48Feature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class NeoRgb48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoRbg48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGrb48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGbr48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBgr48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBrg48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoRgbFeatures.h deleted file mode 100644 index ec4cb06529..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbFeatures.h +++ /dev/null @@ -1,64 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class NeoRgbFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoRbgFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGbrFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGrbFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBgrFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBrgFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbcwxFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoRgbcwxFeatures.h deleted file mode 100644 index 42f475cbf5..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbcwxFeatures.h +++ /dev/null @@ -1,33 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbcwxFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class NeoGrbcwxFeature : - public Neo6xByteFeature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbw64Features.h b/lib/NeoPixelBus/src/internal/features/NeoRgbw64Features.h deleted file mode 100644 index b04e76f5b5..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbw64Features.h +++ /dev/null @@ -1,66 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbw64Feature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 -. --------------------------------------------------------------------------*/ -#pragma once - - -class NeoRgbw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoRbgw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGbrw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGrbw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBgrw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBrgw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - - diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbwFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoRgbwFeatures.h deleted file mode 100644 index 9d92a59252..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbwFeatures.h +++ /dev/null @@ -1,63 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbwFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class NeoRgbwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoRbgwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGbrwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGrbwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBgrwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBrgwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbwxxFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoRgbwxxFeatures.h deleted file mode 100644 index c27af05996..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbwxxFeatures.h +++ /dev/null @@ -1,33 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbwxxFeatures provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class NeoRgbwxxFeature : - public Neo6xxByteFeature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/NeoSm168xxFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoSm168xxFeatures.h deleted file mode 100644 index 1ce33b5032..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoSm168xxFeatures.h +++ /dev/null @@ -1,305 +0,0 @@ -/*------------------------------------------------------------------------- -NeoSm168xxFeatures provides feature classes to describe color order and -color depth for NeoPixelBus template class specific to the SM168xx chips/leds - -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 -. --------------------------------------------------------------------------*/ -#pragma once -/* -3 channel RGB -SM16803P 1.8~60mA << need spec sheet to get accurate implementation -SM16813PB 1.8~19mA -SM16823E 60~350mA -4 channel RGBW -SM16804PB 1.5~60mA << need spec sheet to get accurate implementation -SM16804EB 1.8~19mA -SM16824E 60~350mA -*/ - -#include "../NeoUtil.h" - -class NeoSm168x3SettingsBase : public NeoRgbCurrentSettings -{ -public: - NeoSm168x3SettingsBase(uint8_t redGain, - uint8_t greenGain, - uint8_t blueGain, - uint16_t redCurrent, - uint16_t greenCurrent, - uint16_t blueCurrent) : - NeoRgbCurrentSettings(redCurrent, greenCurrent, blueCurrent), - RedGain(redGain & 0x0f), - GreenGain(greenGain & 0x0f), - BlueGain(blueGain & 0x0f) {} - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return RedGain; - case 1: - return GreenGain; - default: - return BlueGain; - } - } - - const uint8_t RedGain : 4; - const uint8_t GreenGain : 4; - const uint8_t BlueGain : 4; -}; - -template -class NeoSm16803pbSettings : public NeoSm168x3SettingsBase -{ -public: - NeoSm16803pbSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain) : - NeoSm168x3SettingsBase(redGain, - greenGain, - blueGain, - CurrentLookup[redGain], - CurrentLookup[greenGain], - CurrentLookup[blueGain]) - { - } - - void Encode(uint8_t* encoded) const - { - // 0RGB 4 bits each - *encoded++ = operator[](V_IC_1); - *encoded = operator[](V_IC_2) << 4 | operator[](V_IC_3); - } - -protected: - static constexpr uint8_t CurrentLookup[16] = { - 18, 30, 41, 53, 64, 76, 87, 99, - 110, 133, 145, 156, 168, 179, 190}; -}; - -template -class NeoSm16823eSettings : public NeoSm168x3SettingsBase -{ -public: - NeoSm16823eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint16_t resisterOhms) : - NeoSm168x3SettingsBase(redGain, - greenGain, - blueGain, - calcCurrent(resisterOhms, redGain), - calcCurrent(resisterOhms, greenGain), - calcCurrent(resisterOhms, blueGain)), - extROhms(resisterOhms) - { - } - - void Encode(uint8_t* encoded) const - { - // RGB0 4 bits each - *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2); - *encoded = operator[](V_IC_3) << 4; - } - -protected: - const uint16_t extROhms; - - static uint16_t calcCurrent(const uint16_t ohms, const uint8_t gain) - { - uint16_t mA = (967 * (240 + (gain * 32)) / ohms); // from spec sheet, gain 0-15 instead - return mA * 10; // return tenths of mA - } -}; - -// RGBW versions - -class NeoSm168x4SettingsBase : public NeoRgbwCurrentSettings -{ -public: - NeoSm168x4SettingsBase(uint8_t redGain, - uint8_t greenGain, - uint8_t blueGain, - uint8_t whiteGain, - uint16_t redCurrent, - uint16_t greenCurrent, - uint16_t blueCurrent, - uint16_t whiteCurrent) : - NeoRgbwCurrentSettings(redCurrent, greenCurrent, blueCurrent, whiteCurrent), - RedGain(redGain & 0x0f), - GreenGain(greenGain & 0x0f), - BlueGain(blueGain & 0x0f), - WhiteGain(whiteGain & 0x0f) {} - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return RedGain; - case 1: - return GreenGain; - case 2: - return BlueGain; - default: - return WhiteGain; - } - } - - const uint8_t RedGain : 4; - const uint8_t GreenGain : 4; - const uint8_t BlueGain : 4; - const uint8_t WhiteGain : 4; -}; - -template -class NeoSm16804ebSettings : public NeoSm168x4SettingsBase -{ -public: - NeoSm16804ebSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain) : - NeoSm168x4SettingsBase(redGain, - greenGain, - blueGain, - whiteGain, - CurrentLookup[redGain], - CurrentLookup[greenGain], - CurrentLookup[blueGain], - CurrentLookup[whiteGain]) - { - } - - void Encode(uint8_t* encoded) const - { - // RGBW 4 bits each - *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2); - *encoded = operator[](V_IC_3) << 4 | operator[](V_IC_4); - } - -protected: - static constexpr uint8_t CurrentLookup[16] = { - 18, 30, 41, 53, 64, 76, 87, 99, - 110, 133, 145, 156, 168, 179, 190 }; -}; - -template -class NeoSm16824eSettings : public NeoSm168x4SettingsBase -{ -public: - NeoSm16824eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain, uint16_t resisterOhms) : - NeoSm168x4SettingsBase(redGain, - greenGain, - blueGain, - whiteGain, - calcCurrent(resisterOhms, redGain), - calcCurrent(resisterOhms, greenGain), - calcCurrent(resisterOhms, blueGain), - calcCurrent(resisterOhms, whiteGain)), - extROhms(resisterOhms) - { - } - - void Encode(uint8_t* encoded) const - { - // RGBW 4 bits each - *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2); - *encoded = operator[](V_IC_3) << 4 | operator[](V_IC_4); - } - -protected: - const uint16_t extROhms; - - static uint16_t calcCurrent(const uint16_t ohms, const uint8_t gain) - { - uint16_t mA = (1100 * (240 + (gain * 32)) / ohms); // from spec sheet, gain 0-15 instead - return mA * 10; // return tenths of mA - } - -}; - -// CAUTION: Make sure ColorIndex order for Neo4ByteFeature matches T_SETTINGS -template -class NeoRgbwSm168x4Elements : - public Neo4ByteFeature -{ -public: - typedef T_SETTINGS SettingsObject; - static const size_t SettingsSize = 2; - - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) - { - // settings are at the end of the data stream - uint8_t* pDest = pData + sizeData - SettingsSize; - - settings.Encode(pDest); - } - - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } - - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } -}; - -// CAUTION: Make sure ColorIndex order for Neo3ByteFeature matches T_SETTINGS -template class NeoRgbSm168x3Elements : - public Neo3ByteFeature -{ -public: - typedef T_SETTINGS SettingsObject; - static const size_t SettingsSize = 2; - - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) - { - // settings are at the end of the data stream - uint8_t* pDest = pData + sizeData - SettingsSize; - - settings.Encode(pDest); - } - - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } - - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } -}; - -// FIXME 2023-08-08 tonhuisman: Space added between >> to avoid compiler warning -typedef NeoRgbSm168x3Elements > NeoRgbSm16803pbFeature; -typedef NeoRgbSm168x3Elements > NeoRgbSm16823eFeature; -typedef NeoRgbwSm168x4Elements > NeoRgbwSm16804ebFeature; -typedef NeoRgbwSm168x4Elements > NeoRgbwSm16824eFeature; - - diff --git a/lib/NeoPixelBus/src/internal/features/P9813BgrFeature.h b/lib/NeoPixelBus/src/internal/features/P9813BgrFeature.h deleted file mode 100644 index c81fda676a..0000000000 --- a/lib/NeoPixelBus/src/internal/features/P9813BgrFeature.h +++ /dev/null @@ -1,77 +0,0 @@ -/*------------------------------------------------------------------------- -P9813BgrFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with P9813s - -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 -. --------------------------------------------------------------------------*/ -#pragma once - - -class P9813BgrFeature : - public NeoByteElements<4, RgbColor, uint32_t>, - public NeoElementsNoSettings -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = 0xC0 | ((~color.B & 0xC0) >> 2) | ((~color.G & 0xC0) >> 4) | ((~color.R & 0xC0) >> 6); - *p++ = color.B; - *p++ = color.G; - *p = color.R; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - p++; // ignore the first byte - color.B = *p++; - color.G = *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.B = pgm_read_byte(p++); - color.G = pgm_read_byte(p++); - color.R = pgm_read_byte(p); - - return color; - } - -}; - - - - - - diff --git a/lib/NeoPixelBus/src/internal/methods/DotStarEsp32DmaSpiMethod.h b/lib/NeoPixelBus/src/internal/methods/DotStarEsp32DmaSpiMethod.h deleted file mode 100644 index 9da2cdf60b..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/DotStarEsp32DmaSpiMethod.h +++ /dev/null @@ -1,334 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for DotStars using Esp32, DMA and SPI (APA102). - -Written by Michael C. Miller. -DotStarEsp32DmaSpiMethod written by Louis Beaudoin (Pixelvation) - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "../NeoUtil.h" - -#include "driver/spi_master.h" - -// API and type use require newer IDF versions -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 1) - -template class DotStarEsp32DmaSpiMethodBase -{ -public: - typedef typename T_SPISPEED::SettingsObject SettingsObject; - - DotStarEsp32DmaSpiMethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizeStartFrame(4 * T_SPIBUS::ParallelBits), - _sizePixelData(pixelCount * elementSize + settingsSize), - _sizeEndFrame((pixelCount + 15) / 16 * T_SPIBUS::ParallelBits) // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes) - { - _spiBufferSize = _sizeStartFrame + _sizePixelData + _sizeEndFrame; - - // must have a 4 byte aligned buffer for i2s - uint32_t alignment = _spiBufferSize % 4; - if (alignment) - { - _spiBufferSize += 4 - alignment; - } - - _data = static_cast(malloc(_spiBufferSize)); - _dmadata = static_cast(heap_caps_malloc(_spiBufferSize, MALLOC_CAP_DMA)); - - // data cleared later in NeoPixelBus::Begin() - } - - // Support constructor specifying pins by ignoring pins - DotStarEsp32DmaSpiMethodBase(uint8_t, uint8_t, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - DotStarEsp32DmaSpiMethodBase(pixelCount, elementSize, settingsSize) - { - } - - ~DotStarEsp32DmaSpiMethodBase() - { - if (_spiHandle) - { - deinitSpiDevice(); - esp_err_t ret = spi_bus_free(T_SPIBUS::SpiHostDevice); - ESP_ERROR_CHECK(ret); - } - free(_data); - heap_caps_free(_dmadata); - _spiHandle = NULL; - } - - bool IsReadyToUpdate() const - { - spi_transaction_t t; - spi_transaction_t* tptr = &t; - - esp_err_t ret = spi_device_get_trans_result(_spiHandle, &tptr, 0); - - // we are ready if prev result is back (ESP_OK) or if we got a timeout and - // transaction length of 0 (we didn't start a transaction) - return (ret == ESP_OK || (ret == ESP_ERR_TIMEOUT && 0 == _spiTransaction.length)); - } - - void Initialize(int8_t sck, int8_t dat0, int8_t dat1, int8_t dat2, int8_t dat3, int8_t dat4, int8_t dat5, int8_t dat6, int8_t dat7, int8_t ss) - { - memset(_data, 0x00, _sizeStartFrame); - memset(_data + _sizeStartFrame + _sizePixelData, 0x00, _spiBufferSize - (_sizeStartFrame + _sizePixelData)); - - _ssPin = ss; - - esp_err_t ret; - spi_bus_config_t buscfg = { 0 }; - - buscfg.sclk_io_num = sck; - buscfg.data0_io_num = dat0; - buscfg.data1_io_num = dat1; - buscfg.data2_io_num = dat2; - buscfg.data3_io_num = dat3; - buscfg.data4_io_num = dat4; - buscfg.data5_io_num = dat5; - buscfg.data6_io_num = dat6; - buscfg.data7_io_num = dat7; - buscfg.max_transfer_sz = _spiBufferSize; - if (T_SPIBUS::ParallelBits == 8) - { - buscfg.flags = SPICOMMON_BUSFLAG_OCTAL; - } - - //Initialize the SPI bus - ret = spi_bus_initialize(T_SPIBUS::SpiHostDevice, &buscfg, SPI_DMA_CH_AUTO); - ESP_ERROR_CHECK(ret); - - _spiTransaction = { 0 }; - initSpiDevice(); - } - - void Initialize(int8_t sck, int8_t dat0, int8_t dat1, int8_t dat2, int8_t dat3, int8_t ss) - { - Initialize(sck, dat0, dat1, dat2, dat3, -1, -1, -1, -1, ss); - } - - void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) - { - Initialize(sck, mosi, miso, -1, -1, ss); - } - - // If pins aren't specified, initialize bus with just the default SCK and MOSI pins for the SPI peripheral (no SS, no >1-bit pins) - void Initialize() - { -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - if (T_SPIBUS::SpiHostDevice == VSPI_HOST) - { - Initialize(SCK, -1, MOSI, -1, -1, -1); - } - else - { - Initialize(14, -1, 13, -1, -1, -1); - } -#else - Initialize(SCK, -1, MOSI, -1, -1, -1); -#endif - } - - void Update(bool) - { - while(!IsReadyToUpdate()) - { - portYIELD(); - } - - memcpy(_dmadata, _data, _spiBufferSize); - - _spiTransaction = { 0 }; - _spiTransaction.length = (_spiBufferSize) * 8; // in bits not bytes! - - if (T_SPIBUS::ParallelBits == 1) - { - _spiTransaction.flags = 0; - } - if (T_SPIBUS::ParallelBits == 2) - { - _spiTransaction.flags = SPI_TRANS_MODE_DIO; - } - if (T_SPIBUS::ParallelBits == 4) - { - _spiTransaction.flags = SPI_TRANS_MODE_QIO; - } - if (T_SPIBUS::ParallelBits == 8) - { - _spiTransaction.flags = SPI_TRANS_MODE_OCT; - } - _spiTransaction.tx_buffer = _dmadata; - - esp_err_t ret = spi_device_queue_trans(_spiHandle, &_spiTransaction, 0); //Transmit! - ESP_ERROR_CHECK(ret); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data + _sizeStartFrame; - }; - - size_t getDataSize() const - { - return _sizePixelData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - _speed.applySettings(settings); - if (_spiHandle) - { - deinitSpiDevice(); - initSpiDevice(); - } - } - -private: - void initSpiDevice() - { - spi_device_interface_config_t devcfg = {0}; - - devcfg.clock_speed_hz = _speed.Clock; - devcfg.mode = 0; //SPI mode 0 - devcfg.spics_io_num = _ssPin; //CS pin - devcfg.queue_size = 1; - if (T_SPIBUS::ParallelBits == 1) - { - devcfg.flags = 0; - } - if (T_SPIBUS::ParallelBits >= 2) - { - devcfg.flags = SPI_DEVICE_HALFDUPLEX; - } - - //Allocate the LEDs on the SPI bus - esp_err_t ret = spi_bus_add_device(T_SPIBUS::SpiHostDevice, &devcfg, &_spiHandle); - ESP_ERROR_CHECK(ret); - } - - void deinitSpiDevice() - { - while(!IsReadyToUpdate()); - esp_err_t ret = spi_bus_remove_device(_spiHandle); - ESP_ERROR_CHECK(ret); - } - - const size_t _sizeStartFrame; - const size_t _sizePixelData; // Size of '_data' buffer below, minus (_sizeStartFrame + _sizeEndFrame) - const size_t _sizeEndFrame; - - size_t _spiBufferSize; - uint8_t* _data; // Holds start/end frames and LED color values - uint8_t* _dmadata; // Holds start/end frames and LED color values - spi_device_handle_t _spiHandle = NULL; - spi_transaction_t _spiTransaction; - T_SPISPEED _speed; - int8_t _ssPin; -}; - - -// Unfortunately we have a bit of a mess with SPI bus names across different version of the ESP32 -// e.g ESP32 has SPI, HSPI, and VSPI (1, 2, and 3), ESP32-S2 has SPI, FSPI, and HSPI (1, 2, and 3) -// and the S3 and C3 dropped the silly names entirely and just uses SPI1, SPI2, and SPI3. -// -// SPI1 can be only be used by ESP32 and supports up to 4 bit -// SPI2 supports up to 4 bit output across all of those devices (!) and supports 8 bit on S2 and S3 -// SPI3 supports up to 4 bit output on ESP32 and S3, and 1 bit only on the S2 - -enum spi_bus_width_t { - WIDTH1 = 1, - WIDTH2 = 2, - WIDTH4 = 4, - WIDTH8 = 8, -}; - -template -struct Esp32SpiBus -{ - const static spi_host_device_t SpiHostDevice = bus; - const static int ParallelBits = bits; -}; - -// Define all valid ESP32 SPI Buses with a default speed - -// SPI1 -- ESP32 Only -#if defined(CONFIG_IDF_TARGET_ESP32) -typedef Esp32SpiBus Esp32Spi1Bus; -typedef Esp32SpiBus Esp32Spi12BitBus; -typedef Esp32SpiBus Esp32Spi14BitBus; - -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi1Method; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi12BitMethod; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi14BitMethod; -#endif - -// SPI2 -typedef Esp32SpiBus Esp32Spi2Bus; -typedef Esp32SpiBus Esp32Spi22BitBus; -typedef Esp32SpiBus Esp32Spi24BitBus; -#if SOC_SPI_SUPPORT_OCT -typedef Esp32SpiBus Esp32Spi28BitBus; -#endif - -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi2Method; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi22BitMethod; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi24BitMethod; -#if SOC_SPI_SUPPORT_OCT -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi28BitMethod; -#endif - - -// SPI3 -#if (defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S3)) -typedef Esp32SpiBus Esp32Spi3Bus; -typedef Esp32SpiBus Esp32Spi32BitBus; -typedef Esp32SpiBus Esp32Spi34BitBus; - -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi3Method; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi32BitMethod; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi34BitMethod; -#endif - -#if defined(CONFIG_IDF_TARGET_ESP32S2) -typedef Esp32SpiBus Esp32Spi3Bus; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi3Method; -#endif - -// Default SpiDma methods if we don't care about bus. It's nice that every single ESP32 out there -// supports up to 4 bits on SPI2 - -typedef DotStarEsp32DmaSpi2Method DotStarEsp32DmaSpiMethod; -typedef DotStarEsp32DmaSpi22BitMethod DotStarEsp32DmaSpi2BitMethod; -typedef DotStarEsp32DmaSpi24BitMethod DotStarEsp32DmaSpi4BitMethod; -#if SOC_SPI_SUPPORT_OCT -typedef DotStarEsp32DmaSpi28BitMethod DotStarEsp32DmaSpi8BitMethod; -#endif - -#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 1) \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.c b/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.c deleted file mode 100644 index 5893d19d48..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.c +++ /dev/null @@ -1,671 +0,0 @@ -// 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 "sdkconfig.h" // this sets useful config symbols, like CONFIG_IDF_TARGET_ESP32C3 - -// ESP32 C3 & S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - - - -#include -#include -#include "stdlib.h" - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "freertos/queue.h" - - -#if ESP_IDF_VERSION_MAJOR>=4 -#include "esp_intr_alloc.h" -#else -#include "esp_intr.h" -#endif - -#include "rom/lldesc.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" -#if defined(CONFIG_IDF_TARGET_ESP32) -/* included here for ESP-IDF v4.x compatibility */ -#include "soc/dport_reg.h" -#endif -#include "soc/sens_reg.h" -#include "driver/gpio.h" -#include "driver/i2s.h" - -#if !defined(CONFIG_IDF_TARGET_ESP32S3) -#include "driver/dac.h" -#endif - -#include "Esp32_i2s.h" -#include "esp32-hal.h" - -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, bool parallel_mode, size_t bytes_per_sample); - -#define MATRIX_DETACH_OUT_SIG 0x100 - -#if ESP_IDF_VERSION_MAJOR<=4 -#define I2S_BASE_CLK (160000000L) -#endif - -#define I2S_DMA_BLOCK_COUNT_DEFAULT 0 -// 20 bytes gives us enough time if we use single stage idle -// But it can't be longer due to non-parrallel mode and 50us reset time -// there just isn't enough silence at the end to fill more than 20 bytes -#define I2S_DMA_SILENCE_SIZE 20 // 4 byte increments -#define I2S_DMA_SILENCE_BLOCK_COUNT_FRONT 2 // two front -#define I2S_DMA_SILENCE_BLOCK_COUNT_BACK 1 // one back, required for non parallel - -typedef struct -{ - i2s_dev_t* bus; - int8_t ws; - int8_t bck; - int8_t out; - int8_t in; - - intr_handle_t isr_handle; - lldesc_t* dma_items; - size_t dma_count; - - volatile uint32_t is_sending_data; -} i2s_bus_t; - -// is_sending_data values -#define I2s_Is_Idle 0 -#define I2s_Is_Pending 1 -#define I2s_Is_Sending 2 - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) -static i2s_bus_t I2S[I2S_NUM_MAX] = -{ - {&I2S0, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle}, - {&I2S1, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle} -}; -#else -static i2s_bus_t I2S[I2S_NUM_MAX] = -{ - {&I2S0, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle} -}; -#endif - -void IRAM_ATTR i2sDmaISR(void* arg); - -inline void dmaItemInit(lldesc_t* item, uint8_t* posData, size_t sizeData, lldesc_t* itemNext) -{ - item->eof = 0; - item->owner = 1; - item->sosf = 0; - item->offset = 0; - item->buf = posData; - item->size = sizeData; - item->length = sizeData; - item->qe.stqe_next = itemNext; -} - -bool i2sInitDmaItems(uint8_t bus_num, uint8_t* data, size_t dataSize) -{ - if (bus_num >= I2S_NUM_MAX) - { - return false; - } - - size_t dmaCount = I2S[bus_num].dma_count; - - if (I2S[bus_num].dma_items == NULL) - { - I2S[bus_num].dma_items = (lldesc_t*)heap_caps_malloc(dmaCount * sizeof(lldesc_t), MALLOC_CAP_DMA); - if (I2S[bus_num].dma_items == NULL) - { - log_e("MEM ERROR!"); - return false; - } - } - - lldesc_t* itemFirst = &I2S[bus_num].dma_items[0]; - lldesc_t* item = itemFirst; -// lldesc_t* itemsEnd = itemFirst + I2S[bus_num].dma_count; - lldesc_t* itemNext = item + 1; - size_t dataLeft = dataSize; - uint8_t* pos = data; - // at the end of the data is the encoded silence reset - uint8_t* posSilence = data + dataSize - I2S_DMA_SILENCE_SIZE; - - // front two are silent items used for looping to micmic single fire - // default to looping - dmaItemInit(item, posSilence, I2S_DMA_SILENCE_SIZE, itemNext); - dmaItemInit(itemNext, posSilence, I2S_DMA_SILENCE_SIZE, item); - item = itemNext; - itemNext++; - - // init blocks with avialable data - // - while (dataLeft) - { - item = itemNext; - itemNext++; - - size_t blockSize = dataLeft; - if (blockSize > I2S_DMA_MAX_DATA_LEN) - { - blockSize = I2S_DMA_MAX_DATA_LEN; - } - dataLeft -= blockSize; - - dmaItemInit(item, pos, blockSize, itemNext); - - pos += blockSize; - } - - // last data item is EOF to manage send state using EOF ISR - item->eof = 1; - - // last block, the back silent item, loops to front - item = itemNext; - dmaItemInit(item, posSilence, I2S_DMA_SILENCE_SIZE, itemFirst); - - return true; -} - -bool i2sDeinitDmaItems(uint8_t bus_num) -{ - if (bus_num >= I2S_NUM_MAX) - { - return false; - } - - heap_caps_free(I2S[bus_num].dma_items); - I2S[bus_num].dma_items = NULL; - - return true; -} - -// normal 4, 10, 63, 12, 16 - -esp_err_t i2sSetClock(uint8_t bus_num, - uint8_t div_num, // 4 13 - uint8_t div_b, // 10 20 - uint8_t div_a, // 63 63 - uint8_t bck, // 12 60 or 7 - uint8_t bits) // 16 8 -{ - if (bus_num >= I2S_NUM_MAX || div_a > 63 || div_b > 63 || bck > 63) - { - return ESP_FAIL; - } - - //log_i("i2sSetClock bus %u, clkm_div_num %u, clk_div_a %u, clk_div_b %u, bck_div_num %u, bits_mod %u", - // bus_num, - // div_num, - // div_a, - // div_b, - // bck, - // bits); - - i2s_dev_t* i2s = I2S[bus_num].bus; - - typeof(i2s->clkm_conf) clkm_conf; - - clkm_conf.val = 0; - -#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) - clkm_conf.clk_sel = 2; // APPL = 1 APB = 2 - clkm_conf.clk_en = 1; // examples of i2s show this being set if sel is set to 2 -#else - clkm_conf.clka_en = 0; -#endif - - clkm_conf.clkm_div_a = div_a; - clkm_conf.clkm_div_b = div_b; - clkm_conf.clkm_div_num = div_num; - i2s->clkm_conf.val = clkm_conf.val; - - typeof(i2s->sample_rate_conf) sample_rate_conf; - sample_rate_conf.val = 0; - sample_rate_conf.tx_bck_div_num = bck; - sample_rate_conf.rx_bck_div_num = bck; - sample_rate_conf.tx_bits_mod = bits; - sample_rate_conf.rx_bits_mod = bits; - i2s->sample_rate_conf.val = sample_rate_conf.val; - - return ESP_OK; -} - -void i2sSetPins(uint8_t bus_num, - int8_t out, - int8_t parallel, - int8_t busSampleSize, - bool invert) -{ - if (bus_num >= I2S_NUM_MAX) - { - return; - } - - if (out >= 0) - { - uint32_t i2sSignal; - - pinMode(out, OUTPUT); - -#if defined(CONFIG_IDF_TARGET_ESP32S2) - - // S2 only has one bus - // - // in parallel mode - // 8bit mode : I2S0O_DATA_OUT16_IDX ~I2S0O_DATA_OUT23_IDX - // 16bit mode : I2S0O_DATA_OUT8_IDX ~I2S0O_DATA_OUT23_IDX - // 24bit mode : I2S0O_DATA_OUT0_IDX ~I2S0O_DATA_OUT23_IDX - if (parallel == -1) - { - i2sSignal = I2S0O_DATA_OUT23_IDX; - } - else if (busSampleSize == 1) - { - i2sSignal = I2S0O_DATA_OUT16_IDX + parallel; - } - else if (busSampleSize == 2) - { - i2sSignal = I2S0O_DATA_OUT8_IDX + parallel; - } - else - { - i2sSignal = I2S0O_DATA_OUT0_IDX + parallel; - } - -#else - if (bus_num == 0) - { - // in parallel mode - // 0-7 bits : I2S0O_DATA_OUT16_IDX ~I2S0O_DATA_OUT23_IDX - // 8-15 bits : I2S0O_DATA_OUT8_IDX ~I2S0O_DATA_OUT23_IDX - // 16-23 bits : I2S0O_DATA_OUT0_IDX ~I2S0O_DATA_OUT23_IDX - if (parallel == -1) - { - i2sSignal = I2S0O_DATA_OUT23_IDX; - } - else if (parallel < 8) - { - i2sSignal = I2S0O_DATA_OUT16_IDX + parallel; - } - else if (parallel < 16) - { - i2sSignal = I2S0O_DATA_OUT8_IDX + parallel - 8; - } - else - { - i2sSignal = I2S0O_DATA_OUT0_IDX + parallel - 16; - } - } - else - { - if (parallel == -1) - { - i2sSignal = I2S1O_DATA_OUT23_IDX; - } - else - { - i2sSignal = I2S1O_DATA_OUT0_IDX + parallel; - } - } -#endif - //log_i("i2sSetPins bus %u, i2sSignal %u, pin %u, mux %u", - // bus_num, - // i2sSignal, - // out, - // parallel); - gpio_matrix_out(out, i2sSignal, invert, false); - } -} - -void i2sSetClkWsPins(uint8_t bus_num, - int8_t outClk, - bool invertClk, - int8_t outWs, - bool invertWs) -{ - - if (bus_num >= I2S_NUM_MAX) - { - return; - } - - uint32_t i2sSignalClk = I2S0O_BCK_OUT_IDX; - uint32_t i2sSignalWs = I2S0O_WS_OUT_IDX; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) - if (bus_num == 1) - { - i2sSignalClk = I2S1O_BCK_OUT_IDX; - i2sSignalWs = I2S1O_WS_OUT_IDX; - } -#endif - - if (outClk >= 0) - { - pinMode(outClk, OUTPUT); - gpio_matrix_out(outClk, i2sSignalClk, invertClk, false); - } - - if (outWs >= 0) - { - pinMode(outWs, OUTPUT); - gpio_matrix_out(outWs, i2sSignalWs, invertWs, false); - } -} - -bool i2sWriteDone(uint8_t bus_num) -{ - if (bus_num >= I2S_NUM_MAX) - { - return false; - } - - return (I2S[bus_num].is_sending_data == I2s_Is_Idle); -} - -void i2sInit(uint8_t bus_num, - bool parallel_mode, - size_t bytes_per_sample, - uint32_t sample_rate, - i2s_tx_chan_mod_t chan_mod, - i2s_tx_fifo_mod_t fifo_mod, - size_t dma_count, - uint8_t* data, - size_t dataSize) -{ - if (bus_num >= I2S_NUM_MAX) - { - return; - } - - I2S[bus_num].dma_count = dma_count + - I2S_DMA_SILENCE_BLOCK_COUNT_FRONT + - I2S_DMA_SILENCE_BLOCK_COUNT_BACK; - - if (!i2sInitDmaItems(bus_num, data, dataSize)) - { - return; - } - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) - if (bus_num) - { - periph_module_enable(PERIPH_I2S1_MODULE); - } - else -#endif - { - 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 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; - - // 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; - - - // set parallel (LCD) mode - { - typeof(i2s->conf2) conf2; - conf2.val = 0; - conf2.lcd_en = parallel_mode; - conf2.lcd_tx_wrx2_en = 0; // parallel_mode; // ((parallel_mode) && (bytes_per_sample == 2)); - i2s->conf2.val = conf2.val; - } - - // Enable and configure DMA - { - typeof(i2s->lc_conf) lc_conf; - lc_conf.val = 0; - lc_conf.out_eof_mode = 1; - i2s->lc_conf.val = lc_conf.val; - } - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - i2s->pdm_conf.pcm2pdm_conv_en = 0; - i2s->pdm_conf.pdm2pcm_conv_en = 0; -#endif - // SET_PERI_REG_BITS(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, 0x1, RTC_CNTL_SOC_CLK_SEL_S); - - { - typeof(i2s->fifo_conf) fifo_conf; - - fifo_conf.val = 0; - fifo_conf.rx_fifo_mod_force_en = 1; - fifo_conf.tx_fifo_mod_force_en = 1; - fifo_conf.tx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel - fifo_conf.rx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel - fifo_conf.rx_data_num = 32; //Thresholds. - fifo_conf.tx_data_num = 32; - - i2s->fifo_conf.val = fifo_conf.val; - } - - // $REVIEW old code didn't set this - { - typeof(i2s->conf1) conf1; - conf1.val = 0; - conf1.tx_stop_en = 0; - conf1.tx_pcm_bypass = 1; - i2s->conf1.val = conf1.val; - } - - { - typeof(i2s->conf_chan) conf_chan; - conf_chan.val = 0; - conf_chan.tx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left - conf_chan.rx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left - i2s->conf_chan.val = conf_chan.val; - } - - { - typeof(i2s->conf) conf; - conf.val = 0; - conf.tx_msb_shift = !parallel_mode; // 0:DAC/PCM, 1:I2S - conf.tx_right_first = 0; // parallel_mode?; - i2s->conf.val = conf.val; - } - - i2s->timing.val = 0; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - i2s->pdm_conf.rx_pdm_en = 0; - i2s->pdm_conf.tx_pdm_en = 0; -#endif - - - i2sSetSampleRate(bus_num, sample_rate, parallel_mode, bytes_per_sample); - - /* */ - //Reset FIFO/DMA -> needed? Doesn't dma_reset/fifo_reset do this? - i2s->lc_conf.in_rst=1; i2s->lc_conf.out_rst=1; i2s->lc_conf.ahbm_rst=1; i2s->lc_conf.ahbm_fifo_rst=1; - i2s->lc_conf.in_rst=0; i2s->lc_conf.out_rst=0; i2s->lc_conf.ahbm_rst=0; i2s->lc_conf.ahbm_fifo_rst=0; - i2s->conf.tx_reset=1; i2s->conf.tx_fifo_reset=1; i2s->conf.rx_fifo_reset=1; - i2s->conf.tx_reset=0; i2s->conf.tx_fifo_reset=0; i2s->conf.rx_fifo_reset=0; - /* */ - - // enable intr in cpu // - int i2sIntSource; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) - if (bus_num == 1) { - i2sIntSource = ETS_I2S1_INTR_SOURCE; - } - else -#endif - { - i2sIntSource = ETS_I2S0_INTR_SOURCE; - } - - esp_intr_alloc(i2sIntSource, 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; - -/* ??? */ - // Enable and configure DMA - { - typeof(i2s->lc_conf) lc_conf; - lc_conf.val = 0; - lc_conf.out_data_burst_en = 1; - lc_conf.indscr_burst_en = 1; - i2s->lc_conf.val = lc_conf.val; - } -/* */ - 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); -} - -void i2sDeinit(uint8_t bus_num) -{ - i2sDeinitDmaItems(bus_num); -} - -esp_err_t i2sSetSampleRate(uint8_t bus_num, uint32_t rate, bool parallel_mode, size_t bytes_per_sample) -{ - if (bus_num >= I2S_NUM_MAX) - { - return ESP_FAIL; - } - - uint8_t bck = 12; - - // parallel mode needs a higher sample rate - // - if (parallel_mode) - { -#if defined(CONFIG_IDF_TARGET_ESP32S2) - rate *= bytes_per_sample; - bck *= bytes_per_sample; - - //rate /= bytes_per_sample; - //bck /= bytes_per_sample; -#else - rate *= bytes_per_sample; -#endif - } - - // 160,000,000L / (100,000 * 384) - double clkmdiv = (double)I2S_BASE_CLK / ((rate * 384) + 1); - if (clkmdiv > 256.0) - { - log_e("rate is too low"); - return ESP_FAIL; - } - else if (clkmdiv < 2.0) - { - log_e("rate is too fast, clkmdiv = %f (%u, %u, %u)", - clkmdiv, - rate, - parallel_mode, - bytes_per_sample); - return ESP_FAIL; - } - - // calc integer and franctional for more precise timing - // - uint8_t clkmInteger = clkmdiv; - uint8_t clkmFraction = (clkmdiv - clkmInteger) * 63.0; - - i2sSetClock(bus_num, clkmInteger, clkmFraction, 63, bck, bytes_per_sample * 8); - - return ESP_OK; -} - -void IRAM_ATTR i2sDmaISR(void* arg) -{ - i2s_bus_t* i2s = (i2s_bus_t*)(arg); - - if (i2s->bus->int_st.out_eof) - { - // lldesc_t* item = (lldesc_t*)(i2s->bus->out_eof_des_addr); - if (i2s->is_sending_data != I2s_Is_Idle) - { - // the second item (last of the two front silent items) is - // silent looping item - lldesc_t* itemLoop = &i2s->dma_items[0]; - lldesc_t* itemLoopBreaker = itemLoop + 1; - // set to loop on silent items - itemLoopBreaker->qe.stqe_next = itemLoop; - - i2s->is_sending_data = I2s_Is_Idle; - } - } - - i2s->bus->int_clr.val = i2s->bus->int_st.val; -} - -bool i2sWrite(uint8_t bus_num) -{ - if (bus_num >= I2S_NUM_MAX) - { - return false; - } - - // the second item (last of the two front silent items) is - // silent looping item - lldesc_t* itemLoopBreaker = &I2S[bus_num].dma_items[1]; - lldesc_t* itemLoopNext = itemLoopBreaker + 1; - - // set to NOT loop on silent items - itemLoopBreaker->qe.stqe_next = itemLoopNext; - - I2S[bus_num].is_sending_data = I2s_Is_Sending; - - return true; -} - -#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -#endif // defined(ARDUINO_ARCH_ESP32) - diff --git a/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.h b/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.h deleted file mode 100644 index 9f961d3489..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -// ESP32C3/S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - -#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, - bool parallel_mode, - size_t bytes_per_sample, - uint32_t sample_rate, - i2s_tx_chan_mod_t chan_mod, - i2s_tx_fifo_mod_t fifo_mod, - size_t dma_count, - uint8_t* data, - size_t dataSize); -void i2sDeinit(uint8_t bus_num); -void i2sSetPins(uint8_t bus_num, - int8_t out, - int8_t parallel, - int8_t busSampleSize, - bool invert); -void i2sSetClkWsPins(uint8_t bus_num, - int8_t outClk, - bool invertClk, - int8_t outWs, - bool invertWs); -bool i2sWrite(uint8_t bus_num); -bool i2sWriteDone(uint8_t bus_num); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/NeoPixelBus/src/internal/methods/Mbi6033GenericMethod.h b/lib/NeoPixelBus/src/internal/methods/Mbi6033GenericMethod.h deleted file mode 100644 index 21688e13ff..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Mbi6033GenericMethod.h +++ /dev/null @@ -1,208 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Mbi6033s using general Pins. - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "../NeoUtil.h" -// must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set -#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) -#include "TwoWireBitBangImpleAvr.h" -#else -#include "TwoWireBitBangImple.h" -#endif - - -template class Mbi6033MethodBase -{ -public: - typedef typename T_TWOWIRE::SettingsObject SettingsObject; - - Mbi6033MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _countChips(NeoUtil::RoundUp(pixelCount * elementSize, c_countBytesPerChip) / c_countBytesPerChip), - _sizeData(_countChips * c_countBytesPerChip + settingsSize), - _pinClock(pinClock), - _wire(pinClock, pinData) - { - _data = static_cast(malloc(_sizeData)); - // data cleared later in Begin() - } - -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) - Mbi6033MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Mbi6033MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize) - { - } -#endif - - ~Mbi6033MethodBase() - { - free(_data); - } - - bool IsReadyToUpdate() const - { - return true; // clock driven chips 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) - { - _pinClock = sck; - _wire.begin(sck, miso, mosi, ss); - } -#endif - - void Initialize() - { - _wire.begin(); - } - - void Update(bool) - { - // non current header format: - // 8 bits: command (0xf3) = non current header mode - // 14 bits: sync (0x0000) - // 14 bits: length (count chips - 1) - // 8 bits: configuration (0x02) - // bits (6-4) refresh rate divider bits (0 for fastest) - // bit (1) on or off - // 4 bits: header code name X1 (0x0) - const uint16_t chipLength = _countChips - 1; - const uint8_t headerFrame[6] = { 0xf3, - 0x00, - static_cast(chipLength >> 12), - static_cast((chipLength >> 4) & 0xff), - static_cast((chipLength << 4) & 0xff), - 0x20 }; - - // prefix protocol, >21us clock low, clock high, >21us clock low - // expecting at least 21us since last call to show - // but using hardware SPI won't allow messing with clock - // directly like this... - //delayMicroseconds(c_usResetTime); - //digitalWrite(_pinClock, HIGH); - //digitalWrite(_pinClock, LOW); - //delayMicroseconds(c_usResetTime); - - _wire.beginTransaction(); - - // reset by toggle of clock - delayMicroseconds(c_usResetTime); - _wire.transmitBit(0); // Our Two Wire BitBang supports this - delayMicroseconds(c_usResetTime); - - // header frame - _wire.transmitBytes(headerFrame, sizeof(headerFrame)); - - // data: - // 24 bytes per chip of data (12 16 bit values) - _wire.transmitBytes(_data, _sizeData); - - _wire.endTransaction(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - _wire.applySettings(settings); - } - -private: - // while spec states 4 RGB * 16 bit values, - // its really 12 channels * 16 bit values, as they could - // be wired how ever the circuit is built, like 3 RGBW - static const uint16_t c_countBytesPerChip = 24; // twelve 16 bit values - static const uint16_t c_usResetTime = 21; - - const uint16_t _countChips; // not pixels, driver chips - const size_t _sizeData; // Size of '_data' buffer below - - uint8_t _pinClock; - T_TWOWIRE _wire; - uint8_t* _data; // Holds LED color values -}; - -typedef Mbi6033MethodBase Mbi6033Method; - -/* Due to reset model by these chips needing to control clock, we can't use hardware SPI -* as neither the normal SPI exposes a single bit send nor does it allow direct clock pulses -* using digitalWrite. If a generalized solution could be found, then this could be enabled -* -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) -#include "TwoWireSpiImple.h" -typedef Mbi6033MethodBase> Mbi6033Spi40MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi20MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi10MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi5MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi2MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi1MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi500KhzMethod; -typedef Mbi6033MethodBase> Mbi6033SpiHzMethod; - -typedef Mbi6033Spi10MhzMethod Mbi6033SpiMethod; -#endif - -#if defined(ARDUINO_ARCH_ESP32) -// Give option to use Vspi alias of Spi class if wanting to specify which SPI peripheral is used on the ESP32 -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi40MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi20MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi10MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi5MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi2MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi1MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi500KhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32VspiHzMethod; - -typedef Mbi6033Spi10MhzMethod Mbi6033Esp32VspiMethod; - -#include "TwoWireHspiImple.h" -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi40MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi20MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi10MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi5MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi2MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi1MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi500KhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32HspiHzMethod; - -typedef Mbi6033Esp32Hspi10MhzMethod Mbi6033Esp32HspiMethod; -#endif -*/ \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h b/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h deleted file mode 100644 index 335be8fd71..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h +++ /dev/null @@ -1,763 +0,0 @@ -#pragma once - -/*------------------------------------------------------------------------- -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 -. --------------------------------------------------------------------------*/ - -#include "../NeoUtil.h" - -// ESP32C3/S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - -extern "C" -{ -#include "Esp32_i2s.h" -} - -#pragma once - -// ESP32 Endian Map -// uint16_t -// 1234 -// 3412 -// uint32_t -// 12345678 -// 78563412 -// uint64_t -// 0123456789abcdef -// efcdab8967452301 - -// -// true size of mux channel, 8 bit -// -class NeoEspI2sMuxBusSize8Bit -{ -public: - NeoEspI2sMuxBusSize8Bit() {}; - - const static size_t MuxBusDataSize = 1; - - static void EncodeIntoDma(uint8_t* dmaBuffer, const uint8_t* data, size_t sizeData, uint8_t muxId) - { -#if defined(CONFIG_IDF_TARGET_ESP32S2) - // 1234 - order - // 3412 = actual due to endianness - // 00000001 - const uint32_t EncodedZeroBit = 0x00000100; - // 00010101 - const uint32_t EncodedOneBit = 0x01000101; -#else - // 8 channel bits layout for DMA 32bit value - // note, right to left - // mux bus bit/id 76543210 76543210 76543210 76543210 - // encode bit # 3 2 1 0 - // value zero 0 0 0 1 - // value one 0 1 1 1 - // - // due to indianness between peripheral and cpu, bytes within the words are swapped in the const - // 1234 - order - // 3412 = actual due to endianness - // 00000001 - const uint32_t EncodedZeroBit = 0x00010000; - // 00010101 - const uint32_t EncodedOneBit = 0x01010001; -#endif - - uint32_t* pDma = reinterpret_cast(dmaBuffer); - const uint8_t* pEnd = data + sizeData; - - for (const uint8_t* pPixel = data; pPixel < pEnd; pPixel++) - { - uint8_t value = *pPixel; - - for (uint8_t bit = 0; bit < 8; bit++) - { - uint32_t dma = *(pDma); - - dma |= (((value & 0x80) ? EncodedOneBit : EncodedZeroBit) << (muxId)); - *(pDma++) = dma; - value <<= 1; - } - } - } -}; - -// -// true size of mux channel, 16 bit -// -class NeoEspI2sMuxBusSize16Bit -{ -public: - NeoEspI2sMuxBusSize16Bit() {}; - - const static size_t MuxBusDataSize = 2; - - static void EncodeIntoDma(uint8_t* dmaBuffer, const uint8_t* data, size_t sizeData, uint8_t muxId) - { -#if defined(CONFIG_IDF_TARGET_ESP32S2) - // 1234 5678 - order - // 3412 7856 = actual due to endianness - // not swap 0000000000000001 - const uint64_t EncodedZeroBit64 = 0x0000000000010000; - // no swap 0000000100010001 - const uint64_t EncodedOneBit64 = 0x0001000000010001; - // can be shifted by 8! - Fillx16(dmaBuffer, - data, - sizeData, - muxId, - EncodedZeroBit64, - EncodedOneBit64); -#else - - // 16 channel bits layout for DMA 64bit value - // note, right to left, destination is 32bit chunks - // due to indianness between peripheral and cpu, - // bytes within the words are swapped and words within dwords - // in the literal constants - // { } { } - // 0123 4567 89ab cdef - order of bytes in literal constant - // efcd ab89 6745 2301 - order of memory on ESP32 due to Endianness - // 6745 2301 efcd ab89 - 32bit dest means only map using 32bits so swap upper and lower - // - // Due to final bit locations, can't shift encoded one bit - // either left more than 7 or right more than 7 so we have to - // split the updates and use different encodings - if (muxId < 8) - { - // endian + dest swap 0000000000000001 - const uint64_t EncodedZeroBit64 = 0x0000000001000000; - // endian + dest swap 0000000100010001 - const uint64_t EncodedOneBit64 = 0x0100000001000100; - // cant be shifted by 8! - Fillx16(dmaBuffer, - data, - sizeData, - muxId, - EncodedZeroBit64, - EncodedOneBit64); - } - else - { - // endian + dest swap 0000000000000001 - // then pre shift by 8 0000000000000100 - const uint64_t EncodedZeroBit64 = 0x0000000000010000; - // endian + dest swap 0000000100010001 - // then pre shift by 8 0000010001000100 - const uint64_t EncodedOneBit64 = 0x0001000000010001; - Fillx16(dmaBuffer, - data, - sizeData, - muxId - 8, // preshifted - EncodedZeroBit64, - EncodedOneBit64); - } -#endif - } - -protected: - static void Fillx16(uint8_t* dmaBuffer, - const uint8_t* data, - size_t sizeData, - uint8_t muxShift, - const uint64_t EncodedZeroBit64, - const uint64_t EncodedOneBit64) - { - uint64_t* pDma64 = reinterpret_cast(dmaBuffer); - const uint8_t* pEnd = data + sizeData; - - for (const uint8_t* pPixel = data; pPixel < pEnd; pPixel++) - { - uint8_t value = *pPixel; - - for (uint8_t bit = 0; bit < 8; bit++) - { - uint64_t dma64 = *(pDma64); - - dma64 |= (((value & 0x80) ? EncodedOneBit64 : EncodedZeroBit64) << (muxShift)); - *(pDma64++) = dma64; - value <<= 1; - } - } - } -}; - -// -// tracks mux channels used and if updated -// -// T_FLAG - type used to store bit flags, UINT8_t for 8 channels, UINT16_t for 16 -// T_MUXSIZE - true size of mux channel = NeoEspI2sMuxBusSize8Bit or NeoEspI2sMuxBusSize16Bit -// -template class NeoEspI2sMuxMap : public T_MUXSIZE -{ -public: - const static uint8_t InvalidMuxId = -1; - const static size_t BusMaxCount = sizeof(T_FLAG) * 8; - - size_t MaxBusDataSize; // max size of stream data from any single mux bus - T_FLAG UpdateMap; // bitmap flags of mux buses to track update state - T_FLAG UpdateMapMask; // mask to used bits in s_UpdateMap - T_FLAG BusCount; // count of mux buses - - // as a static instance, all members get initialized to zero - // and the constructor is called at inconsistent time to other globals - // so its not useful to have or rely on, - // but without it presence they get zeroed far too late - NeoEspI2sMuxMap() - // //: - // //MaxBusDataSize(0), - // //UpdateMap(0), - // //UpdateMapMask(0), - // //BusCount(0) - { - } - - uint8_t RegisterNewMuxBus(const size_t dataSize) - { - // find first available bus id - uint8_t muxId = 0; - while (muxId < BusMaxCount) - { - T_FLAG muxIdField = (1 << muxId); - if ((UpdateMapMask & muxIdField) == 0) - { - // complete registration - BusCount++; - UpdateMapMask |= muxIdField; - if (dataSize > MaxBusDataSize) - { - MaxBusDataSize = dataSize; - } - break; - } - muxId++; - } - if (muxId == BusMaxCount) - { - log_e("exceded channel limit of %u on bus", BusMaxCount); - } - return muxId; - } - - - bool DeregisterMuxBus(uint8_t muxId) - { - T_FLAG muxIdField = (1 << muxId); - if (UpdateMapMask & muxIdField) - { - // complete deregistration - BusCount--; - UpdateMapMask &= ~muxIdField; - if (UpdateMapMask == 0) - { - return true; - } - } - return false; - } - - bool IsAllMuxBusesUpdated() - { - return (UpdateMap == UpdateMapMask); - } - - bool IsNoMuxBusesUpdate() - { - return (UpdateMap == 0); - } - - void MarkMuxBusUpdated(uint8_t muxId) - { - UpdateMap |= (1 << muxId); - } - - void ResetMuxBusesUpdated() - { - UpdateMap = 0; - } - - void Reset() - { - MaxBusDataSize = 0; - UpdateMap = 0; - UpdateMapMask = 0; - BusCount = 0; - } -}; - -// -// Implementation of a Double Buffered version of a I2sContext -// Manages the underlying I2S details including the buffer(s) -// This creates a front buffer that can be filled while actively sending -// the back buffer, thus improving async operation of the i2s DMA. -// Note that the back buffer must be DMA memory, a limited resource, so -// the front buffer uses normal memory and copies rather than swap pointers -// -// T_MUXMAP - NeoEspI2sMuxMap - tracking class for mux state -// -template class NeoEspI2sDblBuffContext -{ -public: - const static size_t DmaBitsPerPixelBit = 4; - - size_t I2sBufferSize; // total size of I2sBuffer - uint8_t* I2sBuffer; // holds the DMA buffer that is referenced by I2sBufDesc - uint8_t* I2sEditBuffer; // hold a editable buffer that is copied to I2sBuffer - T_MUXMAP MuxMap; - - // as a static instance, all members get initialized to zero - // and the constructor is called at inconsistent time to other globals - // so its not useful to have or rely on, - // but without it presence they get zeroed far too late - NeoEspI2sDblBuffContext() - // //: - // //I2sBufferSize(0), - // //I2sBuffer(nullptr), - // //I2sEditBuffer(nullptr), - // //MuxMap() - { - } - - void Construct(const uint8_t busNumber, uint32_t i2sSampleRate) - { - // construct only once on first time called - if (I2sBuffer == nullptr) - { - // MuxMap.MaxBusDataSize = max size in bytes of a single channel - // DmaBitsPerPixelBit = how many dma bits/byte are needed for each source (pixel) bit/byte - // T_MUXMAP::MuxBusDataSize = the true size of data for selected mux mode (not exposed size as i2s0 only supports 16bit mode) - I2sBufferSize = MuxMap.MaxBusDataSize * 8 * DmaBitsPerPixelBit * T_MUXMAP::MuxBusDataSize; - - // must have a 4 byte aligned buffer for i2s - uint32_t alignment = I2sBufferSize % 4; - if (alignment) - { - I2sBufferSize += 4 - alignment; - } - - size_t dmaBlockCount = (I2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN; - - I2sBuffer = static_cast(heap_caps_malloc(I2sBufferSize, MALLOC_CAP_DMA)); - if (I2sBuffer == nullptr) - { - log_e("send buffer memory allocation failure (size %u)", - I2sBufferSize); - } - memset(I2sBuffer, 0x00, I2sBufferSize); - - I2sEditBuffer = static_cast(malloc(I2sBufferSize)); - if (I2sEditBuffer == nullptr) - { - log_e("edit buffer memory allocation failure (size %u)", - I2sBufferSize); - } - memset(I2sEditBuffer, 0x00, I2sBufferSize); - - i2sInit(busNumber, - true, - T_MUXMAP::MuxBusDataSize, - i2sSampleRate, -#if defined(CONFIG_IDF_TARGET_ESP32S2) -// using these modes on ESP32S2 actually allows it to function -// in both x8 and x16 - I2S_CHAN_STEREO, - I2S_FIFO_16BIT_DUAL, -#else -// but they won't work on ESP32 in parallel mode, but these will - I2S_CHAN_RIGHT_TO_LEFT, - I2S_FIFO_16BIT_SINGLE, -#endif - dmaBlockCount, - I2sBuffer, - I2sBufferSize); - } - } - - void Destruct(const uint8_t busNumber) - { - if (I2sBuffer == nullptr) - { - return; - } - - i2sSetPins(busNumber, -1, -1, -1, false); - i2sDeinit(busNumber); - - free(I2sEditBuffer); - heap_caps_free(I2sBuffer); - - I2sBufferSize = 0; - I2sBuffer = nullptr; - I2sEditBuffer = nullptr; - - MuxMap.Reset(); - } -}; - -// -// Implementation of the low level interface into i2s mux bus -// -// T_BUSCONTEXT - the context to use, currently only NeoEspI2sDblBuffContext but there is -// a plan to provide one that doesn't implement the front buffer but would be less -// async as it would have to wait until the last frame was completely sent before -// updating and new data -// T_BUS - the bus id, NeoEsp32I2sBusZero, NeoEsp32I2sBusOne -// -template class NeoEsp32I2sMuxBus -{ -public: - NeoEsp32I2sMuxBus() : - _muxId(s_context.MuxMap.InvalidMuxId) - { - } - - void RegisterNewMuxBus(size_t dataSize) - { - _muxId = s_context.MuxMap.RegisterNewMuxBus(dataSize); - } - - void Initialize(uint8_t pin, uint32_t i2sSampleRate, bool invert) - { - s_context.Construct(T_BUS::I2sBusNumber, i2sSampleRate); - i2sSetPins(T_BUS::I2sBusNumber, pin, _muxId, s_context.MuxMap.MuxBusDataSize, invert); - } - - void DeregisterMuxBus(uint8_t pin) - { - if (s_context.MuxMap.DeregisterMuxBus(_muxId)) - { - s_context.Destruct(T_BUS::I2sBusNumber); - } - - // disconnect muxed pin - gpio_matrix_out(pin, 0x100, false, false); - pinMode(pin, INPUT); - - _muxId = s_context.MuxMap.InvalidMuxId; - } - - void StartWrite() - { - if (s_context.MuxMap.IsAllMuxBusesUpdated()) - { - s_context.MuxMap.ResetMuxBusesUpdated(); - - // wait for not actively sending data - while (!IsWriteDone()) - { - yield(); - } - // copy edit buffer to sending buffer - memcpy(s_context.I2sBuffer, s_context.I2sEditBuffer, s_context.I2sBufferSize); - i2sWrite(T_BUS::I2sBusNumber); - } - } - - bool IsWriteDone() const - { - return i2sWriteDone(T_BUS::I2sBusNumber); - } - - void FillBuffers(const uint8_t* data, size_t sizeData) - { - if (s_context.MuxMap.IsNoMuxBusesUpdate()) - { - // clear all the data in preperation for each mux channel to add - memset(s_context.I2sEditBuffer, 0x00, s_context.I2sBufferSize); - } - - s_context.MuxMap.EncodeIntoDma(s_context.I2sEditBuffer, - data, - sizeData, - _muxId ); - - s_context.MuxMap.MarkMuxBusUpdated(_muxId); - } - - void MarkUpdated() - { - s_context.MuxMap.MarkMuxBusUpdated(_muxId); - } - -private: - static T_BUSCONTEXT s_context; - uint8_t _muxId; -}; - -template T_BUSCONTEXT NeoEsp32I2sMuxBus::s_context = T_BUSCONTEXT(); - -// -// wrapping layer of the i2s mux bus as a NeoMethod -// -// T_SPEED - NeoEsp32I2sSpeed* (ex NeoEsp32I2sSpeedWs2812x) used to define output signal form -// T_BUS - NeoEsp32I2sMuxBus, the bus to use -// T_INVERT - NeoEsp32I2sNotInverted or NeoEsp32I2sInverted, will invert output signal -// -template class NeoEsp32I2sXMethodBase -{ -public: - typedef NeoNoSettings SettingsObject; - - NeoEsp32I2sXMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizeData(pixelCount * elementSize + settingsSize), - _pin(pin), - _bus() - { - _bus.RegisterNewMuxBus(_sizeData + T_SPEED::ResetTimeUs / T_SPEED::ByteSendTimeUs); - } - - ~NeoEsp32I2sXMethodBase() - { - while (!_bus.IsWriteDone()) - { - yield(); - } - - _bus.DeregisterMuxBus(_pin); - - free(_data); - } - - bool IsReadyToUpdate() const - { - return _bus.IsWriteDone(); - } - - void Initialize() - { - _bus.Initialize(_pin, T_SPEED::I2sSampleRate, T_INVERT::Inverted); - - _data = static_cast(malloc(_sizeData)); - if (_data == nullptr) - { - log_e("front buffer memory allocation failure"); - } - // data cleared later in Begin() - } - - void Update(bool) - { - _bus.FillBuffers(_data, _sizeData); - _bus.StartWrite(); // only triggers actual write after all mux busses have updated - } - - bool AlwaysUpdate() - { - // this method requires update to be called even if no changes to method buffer - // as edit buffer is always cleared and then copied to send buffer and all - // mux bus needs to included - return true; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - } - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - } - -private: - const size_t _sizeData; // Size of '_data' buffer - const uint8_t _pin; // output pin number - - T_BUS _bus; // holds instance for mux bus support - uint8_t* _data; // Holds LED color values -}; - -#if defined(CONFIG_IDF_TARGET_ESP32S2) - -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusZero> NeoEsp32I2s0Mux8Bus; -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusZero> NeoEsp32I2s0Mux16Bus; - -#else - -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusZero> NeoEsp32I2s0Mux8Bus; -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusZero> NeoEsp32I2s0Mux16Bus; - - -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusOne> NeoEsp32I2s1Mux8Bus; -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusOne> NeoEsp32I2s1Mux16Bus; - -#endif - -// NORMAL -// - -// I2s0x8 -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Ws2812xMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Sk6812Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1814Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1829Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1914Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8800KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8400KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Apa106Method; - -typedef NeoEsp32I2s0X8Ws2812xMethod NeoEsp32I2s0X8Ws2813Method; -typedef NeoEsp32I2s0X8Ws2812xMethod NeoEsp32I2s0X8Ws2812dMethod; -typedef NeoEsp32I2s0X8Ws2812xMethod NeoEsp32I2s0X8Ws2811Method; -typedef NeoEsp32I2s0X8Ws2812xMethod NeoEsp32I2s0X8Ws2816Method; -typedef NeoEsp32I2s0X8800KbpsMethod NeoEsp32I2s0X8Ws2812Method; -typedef NeoEsp32I2s0X8Sk6812Method NeoEsp32I2s0X8Lc8812Method; - -// I2s0x16 -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Ws2812xMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Sk6812Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1814Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1829Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1914Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16800KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16400KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Apa106Method; - -typedef NeoEsp32I2s0X16Ws2812xMethod NeoEsp32I2s0X16Ws2813Method; -typedef NeoEsp32I2s0X16Ws2812xMethod NeoEsp32I2s0X16Ws2812dMethod; -typedef NeoEsp32I2s0X16Ws2812xMethod NeoEsp32I2s0X16Ws2811Method; -typedef NeoEsp32I2s0X16Ws2812xMethod NeoEsp32I2s0X16Ws2816Method; -typedef NeoEsp32I2s0X16800KbpsMethod NeoEsp32I2s0X16Ws2812Method; -typedef NeoEsp32I2s0X16Sk6812Method NeoEsp32I2s0X16Lc8812Method; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) - -// I2s1x8 -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Ws2812xMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Sk6812Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1814Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1829Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1914Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8800KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8400KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Apa106Method; - -typedef NeoEsp32I2s1X8Ws2812xMethod NeoEsp32I2s1X8Ws2813Method; -typedef NeoEsp32I2s1X8Ws2812xMethod NeoEsp32I2s1X8Ws2812dMethod; -typedef NeoEsp32I2s1X8Ws2812xMethod NeoEsp32I2s1X8Ws2811Method; -typedef NeoEsp32I2s1X8Ws2812xMethod NeoEsp32I2s1X8Ws2816Method; -typedef NeoEsp32I2s1X8800KbpsMethod NeoEsp32I2s1X8Ws2812Method; -typedef NeoEsp32I2s1X8Sk6812Method NeoEsp32I2s1X8Lc8812Method; - -// I2s1x16 -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Ws2812xMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Sk6812Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1814Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1829Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1914Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16800KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16400KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Apa106Method; - -typedef NeoEsp32I2s1X16Ws2812xMethod NeoEsp32I2s1X16Ws2813Method; -typedef NeoEsp32I2s1X16Ws2812xMethod NeoEsp32I2s1X16Ws2812dMethod; -typedef NeoEsp32I2s1X16Ws2812xMethod NeoEsp32I2s1X16Ws2811Method; -typedef NeoEsp32I2s1X16Ws2812xMethod NeoEsp32I2s1X16Ws2816Method; -typedef NeoEsp32I2s1X16800KbpsMethod NeoEsp32I2s1X16Ws2812Method; -typedef NeoEsp32I2s1X16Sk6812Method NeoEsp32I2s1X16Lc8812Method; - - -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) - -// INVERTED -// -// I2s0x8 INVERTED -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Ws2812xInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Sk6812InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1814InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1829InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1914InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8800KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8400KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Apa106InvertedMethod; - -typedef NeoEsp32I2s0X8Ws2812xInvertedMethod NeoEsp32I2s0X8Ws2813InvertedMethod; -typedef NeoEsp32I2s0X8Ws2812xInvertedMethod NeoEsp32I2s0X8Ws2812xInvertedMethod; -typedef NeoEsp32I2s0X8Ws2812xInvertedMethod NeoEsp32I2s0X8Ws2811InvertedMethod; -typedef NeoEsp32I2s0X8Ws2812xInvertedMethod NeoEsp32I2s0X8Ws2816InvertedMethod; -typedef NeoEsp32I2s0X8800KbpsInvertedMethod NeoEsp32I2s0X8Ws2812InvertedMethod; -typedef NeoEsp32I2s0X8Sk6812InvertedMethod NeoEsp32I2s0X8Lc8812InvertedMethod; - - -// I2s0x16 INVERTED -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Ws2812xInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Sk6812InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1814InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1829InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1914InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16800KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16400KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Apa106InvertedMethod; - -typedef NeoEsp32I2s0X16Ws2812xInvertedMethod NeoEsp32I2s0X16Ws2813InvertedMethod; -typedef NeoEsp32I2s0X16Ws2812xInvertedMethod NeoEsp32I2s0X16Ws2812xInvertedMethod; -typedef NeoEsp32I2s0X16Ws2812xInvertedMethod NeoEsp32I2s0X16Ws2811InvertedMethod; -typedef NeoEsp32I2s0X16Ws2812xInvertedMethod NeoEsp32I2s0X16Ws2816InvertedMethod; -typedef NeoEsp32I2s0X16800KbpsInvertedMethod NeoEsp32I2s0X16Ws2812InvertedMethod; -typedef NeoEsp32I2s0X16Sk6812InvertedMethod NeoEsp32I2s0X16Lc8812InvertedMethod; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) - -// I2s1x8 INVERTED -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Ws2812xInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Sk6812InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1814InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1829InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1914InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8800KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8400KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Apa106InvertedMethod; - -typedef NeoEsp32I2s1X8Ws2812xInvertedMethod NeoEsp32I2s1X8Ws2813InvertedMethod; -typedef NeoEsp32I2s1X8Ws2812xInvertedMethod NeoEsp32I2s1X8Ws2812xInvertedMethod; -typedef NeoEsp32I2s1X8Ws2812xInvertedMethod NeoEsp32I2s1X8Ws2811InvertedMethod; -typedef NeoEsp32I2s1X8Ws2812xInvertedMethod NeoEsp32I2s1X8Ws2816InvertedMethod; -typedef NeoEsp32I2s1X8800KbpsInvertedMethod NeoEsp32I2s1X8Ws2812InvertedMethod; -typedef NeoEsp32I2s1X8Sk6812InvertedMethod NeoEsp32I2s1X8Lc8812InvertedMethod; - -// I2s1x16 INVERTED -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Ws2812xInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Sk6812InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1814InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1829InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1914InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16800KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16400KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Apa106InvertedMethod; - -typedef NeoEsp32I2s1X16Ws2812xInvertedMethod NeoEsp32I2s1X16Ws2813InvertedMethod; -typedef NeoEsp32I2s1X16Ws2812xInvertedMethod NeoEsp32I2s1X16Ws2812xInvertedMethod; -typedef NeoEsp32I2s1X16Ws2812xInvertedMethod NeoEsp32I2s1X16Ws2811InvertedMethod; -typedef NeoEsp32I2s1X16Ws2812xInvertedMethod NeoEsp32I2s1X16Ws2816InvertedMethod; -typedef NeoEsp32I2s1X16800KbpsInvertedMethod NeoEsp32I2s1X16Ws2812InvertedMethod; -typedef NeoEsp32I2s1X16Sk6812InvertedMethod NeoEsp32I2s1X16Lc8812InvertedMethod; - -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) - -#endif // defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266DmaMethod.h b/lib/NeoPixelBus/src/internal/methods/NeoEsp8266DmaMethod.h deleted file mode 100644 index 85d39dc37a..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266DmaMethod.h +++ /dev/null @@ -1,437 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266. - - -Written by Michael C. Miller. -Thanks to g3gg0.de for porting the initial DMA support which lead to this. -Thanks to github/cnlohr for the original work on DMA support, which opend -all our minds to a better way (located at https://github.com/cnlohr/esp8266ws2812i2s). - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "../NeoUtil.h" - -#ifdef ARDUINO_ARCH_ESP8266 -#include "NeoEsp8266I2sMethodCore.h" - -class NeoEsp8266DmaSpeedBase -{ -public: - static const uint8_t IdleLevel = 0; - static uint16_t Convert(uint8_t value) - { - const uint16_t bitpatterns[16] = - { - 0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110, - 0b1000111010001000, 0b1000111010001110, 0b1000111011101000, 0b1000111011101110, - 0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110, - 0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110, - }; - - return bitpatterns[value]; - } -}; - -class NeoEsp8266DmaInvertedSpeedBase -{ -public: - static const uint8_t IdleLevel = 1; - static uint16_t Convert(uint8_t value) - { - const uint16_t bitpatterns[16] = - { - 0b0111011101110111, 0b0111011101110001, 0b0111011100010111, 0b0111011100010001, - 0b0111000101110111, 0b0111000101110001, 0b0111000100010111, 0b0111000100010001, - 0b0001011101110111, 0b0001011101110001, 0b0001011100010111, 0b0001011100010001, - 0b0001000101110111, 0b0001000101110001, 0b0001000100010111, 0b0001000100010001, - }; - - return bitpatterns[value]; - } -}; - -class NeoEsp8266DmaSpeed800KbpsBase : public NeoEsp8266DmaSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 5; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed -}; - -class NeoEsp8266DmaSpeedWs2812x : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 300; -}; - -class NeoEsp8266DmaSpeedSk6812 : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 80; -}; - -class NeoEsp8266DmaInvertedSpeedTm1814 : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 200; -}; - -class NeoEsp8266DmaInvertedSpeedTm1829 : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 200; -}; - -class NeoEsp8266DmaSpeed800Kbps : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 50; -}; - -class NeoEsp8266DmaSpeed400Kbps : public NeoEsp8266DmaSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 10; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - 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 NeoEsp8266DmaSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 4; // 0-63 - const static uint32_t I2sBaseClockDivisor = 17; // 0-63 - const static uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element - const static uint32_t ResetTimeUs = 50; -}; - -class NeoEsp8266DmaSpeedIntertek : public NeoEsp8266DmaSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 5; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element - const static uint32_t ResetTimeUs = 12470; - const static uint32_t InterPixelTimeUs = 20; -}; - -class NeoEsp8266DmaInvertedSpeed800KbpsBase : public NeoEsp8266DmaInvertedSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 5; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed -}; - -class NeoEsp8266DmaInvertedSpeedWs2812x : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 300; -}; - -class NeoEsp8266DmaInvertedSpeedSk6812 : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 80; -}; - -class NeoEsp8266DmaSpeedTm1814 : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 200; -}; - -class NeoEsp8266DmaSpeedTm1829 : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 200; -}; - -class NeoEsp8266DmaInvertedSpeed800Kbps : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 50; -}; - -class NeoEsp8266DmaInvertedSpeed400Kbps : public NeoEsp8266DmaInvertedSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 10; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - 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 NeoEsp8266DmaInvertedSpeedApa106 : public NeoEsp8266DmaInvertedSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 4; // 0-63 - const static uint32_t I2sBaseClockDivisor = 17; // 0-63 - const static uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element - const static uint32_t ResetTimeUs = 50; -}; - -class NeoEsp8266DmaInvertedSpeedIntertek : public NeoEsp8266DmaInvertedSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 5; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed - const static uint32_t ResetTimeUs = 12470; - const static uint32_t InterPixelTimeUs = 20; -}; - -template class NeoEsp8266DmaEncode : public T_SPEED -{ -public: - static size_t SpacingPixelSize(size_t sizePixel) - { - return sizePixel; - } - - static void FillBuffers(uint8_t* i2sBuffer, - const uint8_t* data, - size_t sizeData, - MAYBE_UNUSED size_t sizePixel) - { - uint16_t* pDma = (uint16_t*)i2sBuffer; - const uint8_t* pEnd = data + sizeData; - for (const uint8_t* pData = data; pData < pEnd; pData++) - { - *(pDma++) = T_SPEED::Convert(((*pData) & 0x0f)); - *(pDma++) = T_SPEED::Convert(((*pData) >> 4) & 0x0f); - } - } -}; - -template class NeoEsp8266DmaPixelSpacingEncode : public T_SPEED -{ -public: - static size_t SpacingPixelSize(size_t sizePixel) - { - return sizePixel + T_SPEED::InterPixelTimeUs / T_SPEED::ByteSendTimeUs; - } - - static void FillBuffers(uint8_t* i2sBuffer, - const uint8_t* data, - size_t sizeData, - size_t sizePixel) - { - uint16_t* pDma = (uint16_t*)i2sBuffer; - const uint8_t* pEnd = data + sizeData; - uint8_t element = 0; - for (const uint8_t* pData = data; pData < pEnd; pData++) - { - *(pDma++) = T_SPEED::Convert(((*pData) & 0x0f)); - *(pDma++) = T_SPEED::Convert(((*pData) >> 4) & 0x0f); - - element++; - if (element == sizePixel) - { - element = 0; - - for (uint8_t padding = 0; - padding < (T_SPEED::InterPixelTimeUs / T_SPEED::ByteSendTimeUs); - padding++) - { - *(pDma++) = T_SPEED::IdleLevel * 0xffff; - *(pDma++) = T_SPEED::IdleLevel * 0xffff; - } - } - } - } -}; - -template class NeoEsp8266DmaMethodBase : NeoEsp8266I2sMethodCore -{ -public: - typedef NeoNoSettings SettingsObject; - - NeoEsp8266DmaMethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizePixel(elementSize), - _sizeData(pixelCount * elementSize + settingsSize) - { - size_t dmaPixelSize = DmaBytesPerPixelBytes * T_ENCODER::SpacingPixelSize(_sizePixel); - size_t dmaSettingsSize = DmaBytesPerPixelBytes * settingsSize; - - size_t i2sBufferSize = pixelCount * dmaPixelSize + dmaSettingsSize; - // size is rounded up to nearest c_I2sByteBoundarySize - i2sBufferSize = NeoUtil::RoundUp(i2sBufferSize, c_I2sByteBoundarySize); - - // calculate a buffer size that takes reset amount of time - size_t i2sResetSize = T_ENCODER::ResetTimeUs * DmaBytesPerPixelBytes / T_ENCODER::ByteSendTimeUs; - // size is rounded up to nearest c_I2sByteBoundarySize - i2sResetSize = NeoUtil::RoundUp(i2sResetSize, c_I2sByteBoundarySize); - size_t is2BufMaxBlockSize = (c_maxDmaBlockSize / dmaPixelSize) * dmaPixelSize; - - _data = static_cast(malloc(_sizeData)); - // data cleared later in Begin() - - AllocateI2s(i2sBufferSize, i2sResetSize, is2BufMaxBlockSize, T_ENCODER::IdleLevel); - } - - NeoEsp8266DmaMethodBase(MAYBE_UNUSED uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - NeoEsp8266DmaMethodBase(pixelCount, elementSize, settingsSize) - { - } - - ~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_ENCODER::ResetTimeUs) * waits)) - { - yield(); - } - - FreeI2s(); - - free(_data); - } - - bool IsReadyToUpdate() const - { - return IsIdle(); - } - - void Initialize() - { - InitializeI2s(T_ENCODER::I2sClockDivisor, T_ENCODER::I2sBaseClockDivisor); - } - - void IRAM_ATTR Update(bool) - { - // wait for not actively sending data - while (!IsReadyToUpdate()) - { - yield(); - } - T_ENCODER::FillBuffers(_i2sBuffer, _data, _sizeData, _sizePixel); - - WriteI2s(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - } - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - } - -private: - // due to encoding required for i2s, we need 4 bytes to encode the pulses - static const uint16_t DmaBytesPerPixelBytes = 4; - - const size_t _sizePixel; // size of a pixel in _data - const size_t _sizeData; // Size of '_data' buffer - uint8_t* _data; // Holds LED color values - - uint32_t getPixelTime() const - { - return (T_ENCODER::ByteSendTimeUs * GetSendSize() / DmaBytesPerPixelBytes); - }; - -}; - - - -// normal -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaWs2812xMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaSk6812Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaTm1814Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaTm1829Method; -typedef NeoEsp8266DmaTm1814Method NeoEsp8266DmaTm1914Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266Dma800KbpsMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266Dma400KbpsMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaApa106Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaIntertekMethod; - - -// inverted -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedWs2812xMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedSk6812Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedTm1814Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedTm1829Method; -typedef NeoEsp8266DmaInvertedTm1814Method NeoEsp8266DmaInvertedTm1914Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInverted800KbpsMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInverted400KbpsMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedApa106Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedIntertekMethod; - -// Dma method is the default method for Esp8266 -typedef NeoEsp8266DmaWs2812xMethod NeoWs2813Method; -typedef NeoEsp8266DmaWs2812xMethod NeoWs2812xMethod; -typedef NeoEsp8266Dma800KbpsMethod NeoWs2812Method; -typedef NeoEsp8266DmaWs2812xMethod NeoWs2811Method; -typedef NeoEsp8266DmaWs2812xMethod NeoWs2816Method; -typedef NeoEsp8266DmaSk6812Method NeoSk6812Method; -typedef NeoEsp8266DmaTm1814Method NeoTm1814Method; -typedef NeoEsp8266DmaTm1829Method NeoTm1829Method; -typedef NeoEsp8266DmaTm1914Method NeoTm1914Method; -typedef NeoEsp8266DmaSk6812Method NeoLc8812Method; -typedef NeoEsp8266DmaApa106Method NeoApa106Method; -typedef NeoEsp8266DmaIntertekMethod NeoIntertekMethod; - -typedef NeoEsp8266DmaWs2812xMethod Neo800KbpsMethod; -typedef NeoEsp8266Dma400KbpsMethod Neo400KbpsMethod; - -// inverted -typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2813InvertedMethod; -typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2812xInvertedMethod; -typedef NeoEsp8266DmaInverted800KbpsMethod NeoWs2812InvertedMethod; -typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2811InvertedMethod; -typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2816InvertedMethod; -typedef NeoEsp8266DmaInvertedSk6812Method NeoSk6812InvertedMethod; -typedef NeoEsp8266DmaInvertedTm1814Method NeoTm1814InvertedMethod; -typedef NeoEsp8266DmaInvertedTm1829Method NeoTm1829InvertedMethod; -typedef NeoEsp8266DmaInvertedTm1914Method NeoTm1914InvertedMethod; -typedef NeoEsp8266DmaInvertedSk6812Method NeoLc8812InvertedMethod; -typedef NeoEsp8266DmaInvertedApa106Method NeoApa106InvertedMethod; -typedef NeoEsp8266DmaInvertedIntertekMethod NeoInvertedIntertekMethod; - -typedef NeoEsp8266DmaInvertedWs2812xMethod Neo800KbpsInvertedMethod; -typedef NeoEsp8266DmaInverted400KbpsMethod Neo400KbpsInvertedMethod; -#endif diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sDmx512Method.h b/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sDmx512Method.h deleted file mode 100644 index 798bb0929f..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sDmx512Method.h +++ /dev/null @@ -1,354 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266. - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "../NeoUtil.h" - -#ifdef ARDUINO_ARCH_ESP8266 -#include "NeoEsp8266I2sMethodCore.h" - - -class NeoEsp8266I2sDmx512SpeedBase -{ -public: - // 4 us bit send, 250Kbps - static const uint32_t I2sClockDivisor = 20; // 0-63 - static const uint32_t I2sBaseClockDivisor = 32; // 0-63 - static const uint32_t ByteSendTimeUs = 44; // us it takes to send a single pixel element of 11 bits - static const uint32_t BreakMabUs = 96; // Break min 92, Mab min 12 - static const size_t BreakMabSize = 4; // roundupby((BreakMabUs/4us)/8,4) count of bytes needed for the Break+Mab timing - static const uint32_t MtbpUs = 11; // Mtbp, min 0, buy we use at least one byte of space (8*1.35) - static const size_t MtbpSize = 1; // (MtbpUs/1.35)/8 count of bytes needed for the Mtbp timing - // DMX requires the first slot to be zero - static const size_t HeaderSize = 1; -}; - -class NeoEsp8266I2sDmx512Speed : public NeoEsp8266I2sDmx512SpeedBase -{ -public: - static const uint8_t MtbpLevel = 0x1; // high - static const uint8_t StartBit = 0b00000000; - static const uint8_t StopBits = 0b00000011; - static const uint32_t Break = 0x00000000; // Break - static const uint32_t BreakMab = 0x00000007; // Break + Mab - - static uint8_t Convert(uint8_t value) - { - // DMX requires LSB order - return NeoUtil::Reverse8Bits( value ); - } -}; - -class NeoEsp8266I2sDmx512InvertedSpeed : public NeoEsp8266I2sDmx512SpeedBase -{ -public: - static const uint8_t MtbpLevel = 0x00; // low - static const uint8_t StartBit = 0b00000001; - static const uint8_t StopBits = 0b00000000; - static const uint32_t Break = 0xffffffff; // Break - static const uint32_t BreakMab = 0xfffffff8; // Break + Mab - - static uint8_t Convert(uint8_t value) - { - // DMX requires LSB order - return NeoUtil::Reverse8Bits( ~value ); - } -}; - - -class NeoEsp8266I2sWs2821SpeedBase -{ -public: - // 1.35 us bit send, 750Kbps - static const uint32_t I2sClockDivisor = 27; // 0-63 - static const uint32_t I2sBaseClockDivisor = 8; // 0-63 - static const uint32_t ByteSendTimeUs = 15; // us it takes to send a single pixel element of 11 bits - static const uint32_t BreakMabUs = 92; // Break min 88, Mab min 4 - static const size_t BreakMabSize = 12; // roundupby((BreakMabUs/1.35)/8,4) count of bytes needed for the Break+Mab timing - static const uint32_t MtbpUs = 88; // Mtbp, min 88 - static const size_t MtbpSize = 9; // (MtbpUs/1.35)/8 count of bytes needed for the Mtbp timing - - // DMX/WS2821 requires the first slot to be zero - static const size_t HeaderSize = 1; -}; - -class NeoEsp8266I2sWs2821Speed : public NeoEsp8266I2sWs2821SpeedBase -{ -public: - static const uint8_t MtbpLevel = 0x1; // high - static const uint8_t StartBit = 0b00000000; - static const uint8_t StopBits = 0b00000011; - static const uint32_t Break = 0x00000000; // Break - static const uint32_t BreakMab = 0x00000007; // Break + Mab (4~12us/1.35us) - - static uint8_t Convert(uint8_t value) - { - // DMX requires LSB order - return NeoUtil::Reverse8Bits(value); - } -}; - -class NeoEsp8266I2sWs2821InvertedSpeed : public NeoEsp8266I2sWs2821SpeedBase -{ -public: - static const uint8_t MtbpLevel = 0x00; // low - static const uint8_t StartBit = 0b00000001; - static const uint8_t StopBits = 0b00000000; - static const uint32_t Break = 0xffffffff; // Break - static const uint32_t BreakMab = 0xfffffff8; // Break + Mab - - static uint8_t Convert(uint8_t value) - { - // DMX requires LSB order - return NeoUtil::Reverse8Bits(~value); - } -}; - -template class NeoEsp8266I2sDmx512MethodBase : NeoEsp8266I2sMethodCore -{ -public: - typedef NeoNoSettings SettingsObject; - - NeoEsp8266I2sDmx512MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizeData(pixelCount * elementSize + settingsSize + T_SPEED::HeaderSize) - { - size_t dmaPixelBits = I2sBitsPerPixelBytes * elementSize; - size_t dmaSettingsBits = I2sBitsPerPixelBytes * (settingsSize + T_SPEED::HeaderSize); - - // bits + half rounding byte of bits / bits per byte - size_t i2sBufferSize = (pixelCount * dmaPixelBits + dmaSettingsBits + 4) / 8; - - i2sBufferSize = i2sBufferSize + T_SPEED::BreakMabSize; - - // size is rounded up to nearest c_I2sByteBoundarySize - i2sBufferSize = NeoUtil::RoundUp(i2sBufferSize, c_I2sByteBoundarySize); - - // size of a looping silent space rounded up to nearest c_I2sByteBoundarySize - size_t i2sResetSize = NeoUtil::RoundUp(T_SPEED::MtbpSize, c_I2sByteBoundarySize); - - // protocol limits use of full block size to c_I2sByteBoundarySize - size_t is2BufMaxBlockSize = (c_maxDmaBlockSize / c_I2sByteBoundarySize) * c_I2sByteBoundarySize; - - _data = static_cast(malloc(_sizeData)); - // first "slot" cleared due to protocol requiring it to be zero - memset(_data, 0x00, 1); - - AllocateI2s(i2sBufferSize, i2sResetSize, is2BufMaxBlockSize, T_SPEED::MtbpLevel); - } - - NeoEsp8266I2sDmx512MethodBase(MAYBE_UNUSED uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - NeoEsp8266I2sDmx512MethodBase(pixelCount, elementSize, settingsSize) - { - } - - ~NeoEsp8266I2sDmx512MethodBase() - { - 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::MtbpUs) * waits)) - { - yield(); - } - - FreeI2s(); - - free(_data); - } - - bool IsReadyToUpdate() const - { - return IsIdle(); - } - - void Initialize() - { - InitializeI2s(T_SPEED::I2sClockDivisor, T_SPEED::I2sBaseClockDivisor); - } - - void IRAM_ATTR Update(bool) - { - // wait for not actively sending data - while (!IsReadyToUpdate()) - { - yield(); - } - FillBuffers(); - - WriteI2s(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data + T_SPEED::HeaderSize; - }; - - size_t getDataSize() const - { - return _sizeData - T_SPEED::HeaderSize; - } - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - } - -private: - // given 11 sending bits per pixel byte, - static const uint16_t I2sBitsPerPixelBytes = 11; - - const size_t _sizeData; // Size of '_data' buffer - uint8_t* _data; // Holds LED color values - - // encodes the data with start and stop bits - // input buffer is bytes - // output stream is uint31_t - static void Encoder(const uint8_t* pSrc, const uint8_t* pSrcEnd, - uint32_t* pOutput, const uint32_t* pOutputEnd) - { - static const uint32_t Mtbp = 0xffffffff * T_SPEED::MtbpLevel; - const uint8_t* pData = pSrc; - - int8_t outputBit = 32; - uint32_t output = 0; - - // DATA stream, one start, two stop - while (pData < pSrcEnd) - { - uint8_t data = T_SPEED::Convert( *(pData++) ); - - if (outputBit > 10) - { - // simple - outputBit -= 1; - output |= T_SPEED::StartBit << outputBit; - - outputBit -= 8; - output |= data << outputBit; - - outputBit -= 2; - output |= T_SPEED::StopBits << outputBit; - } - else - { - // split across an output uint32_t - // handle start bit - if (outputBit < 1) - { - *(pOutput++) = output; - output = 0; - outputBit += 32; - } - outputBit -= 1; - output |= (T_SPEED::StartBit << outputBit); - - // handle data bits - if (outputBit < 8) - { - output |= data >> (8 - outputBit); - - *(pOutput++) = output; - output = 0; - outputBit += 32; - } - outputBit -= 8; - output |= data << outputBit; - - // handle stop bits - if (outputBit < 2) - { - output |= T_SPEED::StopBits >> (2 - outputBit); - - *(pOutput++) = output; - output = 0; - outputBit += 32; - } - outputBit -= 2; - output |= T_SPEED::StopBits << outputBit; - } - } - if (outputBit > 0) - { - // padd last output uint32_t with Mtbp - output |= Mtbp >> (32 - outputBit); - *(pOutput++) = output; - } - // fill the rest of the output with Mtbp - while (pOutput < pOutputEnd) - { - *(pOutput++) = Mtbp; - } - } - - - void FillBuffers() - { - uint32_t* pDma32 = reinterpret_cast(_i2sBuffer); - const uint32_t* pDma32End = reinterpret_cast(_i2sBuffer + _i2sBufferSize); - - // first insert Break space as needed - for (size_t count = 1; - count < (T_SPEED::BreakMabSize/sizeof(T_SPEED::Break)); - count++) - { - *(pDma32++) = T_SPEED::Break; - } - // then tail of break with mab - *(pDma32++) = T_SPEED::BreakMab; - - Encoder(_data, _data + _sizeData, pDma32, pDma32End); - } - - uint32_t getPixelTime() const - { - return (T_SPEED::ByteSendTimeUs * this->_sizeData); - }; - -}; - - -// normal -typedef NeoEsp8266I2sDmx512MethodBase NeoEsp8266Dmx512Method; -typedef NeoEsp8266I2sDmx512MethodBase NeoEsp8266Ws2821Method; - -// inverted -typedef NeoEsp8266I2sDmx512MethodBase NeoEsp8266Dmx512InvertedMethod; -typedef NeoEsp8266I2sDmx512MethodBase NeoEsp8266Ws2821InvertedMethod; - -#endif diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.h b/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.h deleted file mode 100644 index db67126ed8..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.h +++ /dev/null @@ -1,362 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266. - -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 -. --------------------------------------------------------------------------*/ - -#pragma once -#ifdef ARDUINO_ARCH_ESP8266 - -#include "Arduino.h" - -extern "C" -{ -#include "osapi.h" -#include "ets_sys.h" - -#include "i2s_reg.h" - -#ifdef ARDUINO_ESP8266_MAJOR //this define was added in ESP8266 Arduino Core version v3.0.1 -#include "core_esp8266_i2s.h" //for Arduino core >= 3.0.1 -#else -#include "i2s.h" //for Arduino core <= 3.0.0 -#endif - -#include "eagle_soc.h" -#include "esp8266_peri.h" -#include "slc_register.h" - -#include "osapi.h" -#include "ets_sys.h" -#include "user_interface.h" - -#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 -} - -struct slc_queue_item -{ - uint32 blocksize : 12; - uint32 datalen : 12; - uint32 unused : 5; - uint32 sub_sof : 1; - uint32 eof : 1; - uint32 owner : 1; - uint8* buf_ptr; - struct slc_queue_item* next_link_ptr; -}; - -enum NeoDmaState -{ - NeoDmaState_Idle, - NeoDmaState_Pending, - NeoDmaState_Sending -}; - -const uint16_t c_maxDmaBlockSize = 4095; - -const uint8_t c_I2sPin = 3; // due to I2S hardware, the pin used is restricted to this - -class NeoEsp8266I2sMethodCore -{ -private: - static const uint8_t c_StateBlockCount = 2; - static const size_t c_StateDataSize = 4; // mulitples of c_I2sByteBoundarySize - - // i2s sends 4 byte elements, - static const uint16_t c_I2sByteBoundarySize = 4; - -protected: - static NeoEsp8266I2sMethodCore* s_this; // for the ISR - - volatile NeoDmaState _dmaState; - - slc_queue_item* _i2sBufDesc; // dma block descriptors - uint16_t _i2sBufDescCount; // count of block descriptors in _i2sBufDesc - - size_t _i2sBufferSize; // total size of _i2sBuffer - uint8_t* _i2sBuffer; // holds the DMA buffer that is referenced by _i2sBufDesc - - size_t _i2sIdleDataTotalSize; // total size of represented zeroes, mulitple uses of _i2sIdleData - size_t _i2sIdleDataSize; // size of _i2sIdleData - uint8_t* _i2sIdleData; - - uint16_t _is2BufMaxBlockSize; // max size based on size of a pixel of a single block - - size_t GetSendSize() const - { - return _i2sBufferSize + _i2sIdleDataTotalSize; - } - - // This routine is called as soon as the DMA routine has something to tell us. All we - // handle here is the RX_EOF_INT status, which indicate the DMA has sent a buffer whose - // descriptor has the 'EOF' field set to 1. - // in the case of this code, the second to last state descriptor - static void IRAM_ATTR i2s_slc_isr(void) - { - ETS_SLC_INTR_DISABLE(); - - uint32_t slc_intr_status = SLCIS; - - SLCIC = 0xFFFFFFFF; - - if ((slc_intr_status & SLCIRXEOF) && s_this) - { - if (s_this->_dmaState != NeoDmaState_Idle) - { - // first two items are the state blocks - slc_queue_item* itemLoop = s_this->_i2sBufDesc; - slc_queue_item* itemLoopBreaker = itemLoop + 1; - // set to loop on idle items - itemLoopBreaker->next_link_ptr = itemLoop; - - s_this->_dmaState = NeoDmaState_Idle; - } - } - - ETS_SLC_INTR_ENABLE(); - } - - NeoEsp8266I2sMethodCore() - { }; - - void AllocateI2s(const size_t i2sBufferSize, // expected multiples of c_I2sByteBoundarySize - const size_t i2sZeroesSize, // expected multiples of c_I2sByteBoundarySize - const size_t is2BufMaxBlockSize, - const uint8_t idleLevel) - { - _i2sBufferSize = i2sBufferSize; - _i2sIdleDataTotalSize = i2sZeroesSize; - _i2sIdleDataSize = _i2sIdleDataTotalSize; - - size_t countIdleQueueItems = 1; - if (_i2sIdleDataSize > 256) - { - // reuse a single idle data buffer of 256 with multiple dma slc_queue_items - countIdleQueueItems = _i2sIdleDataSize / 256 + 1; - _i2sIdleDataSize = 256; - } - else - { - _i2sIdleDataSize = NeoUtil::RoundUp(_i2sIdleDataSize, c_I2sByteBoundarySize); - } - _is2BufMaxBlockSize = is2BufMaxBlockSize; - - _i2sBuffer = static_cast(malloc(_i2sBufferSize)); - // no need to initialize it, it gets overwritten on every send - _i2sIdleData = static_cast(malloc(_i2sIdleDataSize)); - memset(_i2sIdleData, idleLevel * 0xff, _i2sIdleDataSize); - - _i2sBufDescCount = (_i2sBufferSize / _is2BufMaxBlockSize) + 1 + - countIdleQueueItems + - c_StateBlockCount; // need more for state/latch blocks - - _i2sBufDesc = (slc_queue_item*)malloc(_i2sBufDescCount * sizeof(slc_queue_item)); - - s_this = this; // store this for the ISR - } - - void FreeI2s() - { - StopI2s(); - - s_this = nullptr; - pinMode(c_I2sPin, INPUT); - - free(_i2sBuffer); - free(_i2sBufDesc); - free(_i2sIdleData); - } - - bool IsIdle() const - { - return (_dmaState == NeoDmaState_Idle); - } - - - void DmaItemInit(slc_queue_item* item, uint8_t* data, size_t sizeData, slc_queue_item* itemNext) - { - item->owner = 1; - item->eof = 0; // no need to trigger interrupt generally - item->sub_sof = 0; - item->datalen = sizeData; - item->blocksize = sizeData; - item->buf_ptr = data; - item->unused = 0; - item->next_link_ptr = itemNext; - } - - void InitializeI2s(const uint32_t i2sClockDivisor, const uint32_t i2sBaseClockDivisor) - { - StopI2s(); - - pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA - - uint8_t* is2Buffer = _i2sBuffer; - uint8_t* is2BufferEnd = _i2sBuffer + _i2sBufferSize; - uint32_t is2BufferSize; - uint16_t indexDesc = 0; - - // prepare the two state/latch descriptors - uint16_t stateDataSize = min(c_StateDataSize, _i2sIdleDataSize); - while (indexDesc < c_StateBlockCount) - { - DmaItemInit(&_i2sBufDesc[indexDesc], _i2sIdleData, stateDataSize, &(_i2sBufDesc[indexDesc + 1])); - - indexDesc++; - } - - // prepare main data block decriptors that point into our one static dma buffer - is2BufferSize = _i2sBufferSize; - while (is2Buffer < is2BufferEnd) - { - uint32_t blockSize = (is2BufferSize > _is2BufMaxBlockSize) ? _is2BufMaxBlockSize : is2BufferSize; - - DmaItemInit(&_i2sBufDesc[indexDesc], is2Buffer, blockSize, &(_i2sBufDesc[indexDesc + 1])); - - is2Buffer += blockSize; - is2BufferSize -= blockSize; - indexDesc++; - } - - // last data item triggers EOF ISR - _i2sBufDesc[indexDesc - 1].eof = 1; - - // prepare idle block decriptors that point into our one idle dma buffer - is2BufferSize = _i2sIdleDataTotalSize; - while (indexDesc < _i2sBufDescCount) - { - uint32_t blockSize = (is2BufferSize > _i2sIdleDataSize) ? _i2sIdleDataSize : is2BufferSize; - - DmaItemInit(&_i2sBufDesc[indexDesc], _i2sIdleData, blockSize, &(_i2sBufDesc[indexDesc + 1])); - - is2Buffer += blockSize; - is2BufferSize -= blockSize; - indexDesc++; - } - - // the last item will loop to the first item - _i2sBufDesc[indexDesc - 1].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[0])); - - // the last state block will loop to the first state block by defualt - _i2sBufDesc[c_StateBlockCount - 1].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[0])); - - // setup the rest of i2s DMA - // - ETS_SLC_INTR_DISABLE(); - - // start off in idel state as that is what it will be all setup to be - // for the interrupt - _dmaState = NeoDmaState_Idle; - - SLCC0 |= SLCRXLR | SLCTXLR; - SLCC0 &= ~(SLCRXLR | SLCTXLR); - SLCIC = 0xFFFFFFFF; - - // Configure DMA - SLCC0 &= ~(SLCMM << SLCM); // clear DMA MODE - SLCC0 |= (1 << SLCM); // set DMA MODE to 1 - SLCRXDC |= SLCBINR | SLCBTNR; // enable INFOR_NO_REPLACE and TOKEN_NO_REPLACE - SLCRXDC &= ~(SLCBRXFE | SLCBRXEM | SLCBRXFM); // disable RX_FILL, RX_EOF_MODE and RX_FILL_MODE - - // Feed DMA the 1st buffer desc addr - // To send data to the I2S subsystem, counter-intuitively we use the RXLINK part, not the TXLINK as you might - // 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 - // 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 - // 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 - - ETS_SLC_INTR_ENABLE(); - - //Start transmission - SLCTXL |= SLCTXLS; - SLCRXL |= SLCRXLS; - - I2S_CLK_ENABLE(); - I2SIC = 0x3F; - I2SIE = 0; - - //Reset I2S - I2SC &= ~(I2SRST); - I2SC |= I2SRST; - I2SC &= ~(I2SRST); - - // Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only) - I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM) | (I2SRXFMM << I2SRXFM)); - I2SFC |= I2SDE; //Enable DMA - // Set RX/TX CHAN_MOD=0 - I2SCC &= ~((I2STXCMM << I2STXCM) | (I2SRXCMM << I2SRXCM)); - - // set the rate - uint32_t i2s_clock_div = i2sClockDivisor & I2SCDM; - uint8_t i2s_bck_div = i2sBaseClockDivisor & I2SBDM; - - //!trans master, !bits mod, rece slave mod, rece msb shift, right first, msb right - 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 WriteI2s() - { - // first two items are the state blocks - slc_queue_item* itemLoopBreaker = &(_i2sBufDesc[1]); - slc_queue_item* itemData = itemLoopBreaker + 1; - - // set to NOT loop on idle items - itemLoopBreaker->next_link_ptr = itemData; - - _dmaState = NeoDmaState_Sending; - } - - void StopI2s() - { - 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 - SLCRXL &= ~(SLCRXLAM << SLCRXLA); // clear RX descriptor address - - pinMode(c_I2sPin, INPUT); - } -}; - -#endif // ARDUINO_ARCH_ESP8266 \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEspBitBangMethod.h b/lib/NeoPixelBus/src/internal/methods/NeoEspBitBangMethod.h deleted file mode 100644 index b641646bee..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEspBitBangMethod.h +++ /dev/null @@ -1,366 +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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "../NeoUtil.h" - -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - -#if defined(ARDUINO_ARCH_ESP8266) -#include -#endif -#if defined(CONFIG_IDF_TARGET_ESP32C3) -#define CYCLES_LOOPTEST (1) // adjustment due to loop exit test instruction cycles -#elif defined(CONFIG_IDF_TARGET_ESP32S3) -#define CYCLES_LOOPTEST (2) // adjustment due to loop exit test instruction cycles -#else -#define CYCLES_LOOPTEST (4) // adjustment due to loop exit test instruction cycles -#endif - -extern void neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, - const uint8_t* end, - uint8_t pin, - uint32_t t0h, - uint32_t t1h, - uint32_t period, - size_t sizePixel, - uint32_t tSpacing, - bool invert); - - -class NeoEspNotInverted -{ -public: - const static uint8_t IdleLevel = LOW; -}; - -class NeoEspInverted -{ -public: - const static uint8_t IdleLevel = HIGH; -}; - -class NeoEspBitBangSpeedWs2811 -{ -public: - const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us - const static uint32_t T1H = (F_CPU / 1052632 - CYCLES_LOOPTEST); // 0.95us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 300; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeedWs2812x -{ -public: - const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 300; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeedSk6812 -{ -public: - const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 80; - const static uint32_t TInterPixel = 0; -}; - -// Tm1814 normal is inverted signal -class NeoEspBitBangSpeedTm1814 -{ -public: - const static uint32_t T0H = (F_CPU / 2916666 - CYCLES_LOOPTEST); // 0.35us - const static uint32_t T1H = (F_CPU / 1666666 - CYCLES_LOOPTEST); // 0.75us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 200; - const static uint32_t TInterPixel = 0; -}; - -// Tm1829 normal is inverted signal -class NeoEspBitBangSpeedTm1829 -{ -public: - const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 200; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeed800Kbps -{ -public: - const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 50; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeed400Kbps -{ -public: - const static uint32_t T0H = (F_CPU / 2000000 - CYCLES_LOOPTEST); - const static uint32_t T1H = (F_CPU / 833333 - CYCLES_LOOPTEST); - const static uint32_t Period = (F_CPU / 400000 - CYCLES_LOOPTEST); - - static const uint32_t ResetTimeUs = 50; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeedApa106 -{ -public: - const static uint32_t T0H = (F_CPU / 2857143 - CYCLES_LOOPTEST); // 0.35us - const static uint32_t T1H = (F_CPU / 740741 - CYCLES_LOOPTEST); // 1.35 - const static uint32_t Period = (F_CPU / 606061 - CYCLES_LOOPTEST); // 1.65us - - static const uint32_t ResetTimeUs = 50; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeedIntertek -{ -public: - const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - const static uint32_t ResetTimeUs = 12470; - const static uint32_t TInterPixel = (F_CPU / 50000); // 20us -}; - - -template class NeoEspBitBangEncode : public T_SPEED, public T_INVERTED -{ -public: - static void WritePixels(uint8_t pin, - const uint8_t* data, - size_t sizeData, - size_t sizePixel) - { - neoEspBitBangWriteSpacingPixels(data, - data + sizeData, - pin, - T_SPEED::T0H, - T_SPEED::T1H, - T_SPEED::Period, - sizePixel, - T_SPEED::TInterPixel, - T_INVERTED::IdleLevel); - } -}; - -template class NeoEspBitBangMethodBase -{ -public: - typedef NeoNoSettings SettingsObject; - - NeoEspBitBangMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizePixel(elementSize), - _sizeData(pixelCount * elementSize + settingsSize), - _pin(pin) - { - pinMode(pin, OUTPUT); - - _data = static_cast(malloc(_sizeData)); - // data cleared later in Begin() - } - - ~NeoEspBitBangMethodBase() - { - pinMode(_pin, INPUT); - - free(_data); - } - - bool IsReadyToUpdate() const - { - uint32_t delta = micros() - _endTime; - - return (delta >= T_ENCODER::ResetTimeUs); - } - - void Initialize() - { - digitalWrite(_pin, T_ENCODER::IdleLevel); - - _endTime = micros(); - } - - 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 - // 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 (!IsReadyToUpdate()) - { - yield(); // allows for system yield if needed - } - - // 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_ENCODER::WritePixels(_pin, - _data, - _sizeData, - _sizePixel); - -#if defined(ARDUINO_ARCH_ESP32) - portEXIT_CRITICAL(&updateMux); -#else - interrupts(); -#endif - - // save EOD time for latch on next call - _endTime = micros(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - } - -private: - const size_t _sizePixel; // size of a pixel in _data - const size_t _sizeData; // Size of '_data' buffer below - const uint8_t _pin; // output pin number - - uint32_t _endTime; // Latch timing reference - uint8_t* _data; // Holds LED color values -}; - - -#if defined(ARDUINO_ARCH_ESP32) - -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangWs2811Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangWs2812xMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangSk6812Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangTm1814Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangTm1829Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBang800KbpsMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBang400KbpsMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangApa106Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangIntertekMethod; - -typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2813Method; -typedef NeoEsp32BitBang800KbpsMethod NeoEsp32BitBangWs2812Method; -typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2816Method; -typedef NeoEsp32BitBangTm1814Method NeoEsp32BitBangTm1914Method; -typedef NeoEsp32BitBangSk6812Method NeoEsp32BitBangLc8812Method; - -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangWs2811InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangWs2812xInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangSk6812InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangTm1814InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangTm1829InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBang800KbpsInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBang400KbpsInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangApa106InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangIntertekInvertedMethod; - -typedef NeoEsp32BitBangWs2812xInvertedMethod NeoEsp32BitBangWs2813InvertedMethod; -typedef NeoEsp32BitBang800KbpsInvertedMethod NeoEsp32BitBangWs2812InvertedMethod; -typedef NeoEsp32BitBangWs2812xInvertedMethod NeoEsp32BitBangWs2816InvertedMethod; -typedef NeoEsp32BitBangTm1814InvertedMethod NeoEsp32BitBangTm1914InvertedMethod; -typedef NeoEsp32BitBangSk6812InvertedMethod NeoEsp32BitBangLc8812InvertedMethod; - -#else // defined(ARDUINO_ARCH_ESP8266) - -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangWs2811Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangWs2812xMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangSk6812Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangTm1814Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangTm1829Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBang800KbpsMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBang400KbpsMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangApa106Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangIntertekMethod; - -typedef NeoEsp8266BitBangWs2812xMethod NeoEsp8266BitBangWs2813Method; -typedef NeoEsp8266BitBang800KbpsMethod NeoEsp8266BitBangWs2812Method; -typedef NeoEsp8266BitBangWs2812xMethod NeoEsp8266BitBangWs2816Method; -typedef NeoEsp8266BitBangTm1814Method NeoEsp8266BitBangTm1914Method; -typedef NeoEsp8266BitBangSk6812Method NeoEsp8266BitBangLc8812Method; - -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangWs2811InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangWs2812xInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangSk6812InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangTm1814InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangTm1829InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBang800KbpsInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBang400KbpsInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangApa106InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangIntertekInvertedMethod; - -typedef NeoEsp8266BitBangWs2812xInvertedMethod NeoEsp8266BitBangWs2813InvertedMethod; -typedef NeoEsp8266BitBang800KbpsInvertedMethod NeoEsp8266BitBangWs2812InvertedMethod; -typedef NeoEsp8266BitBangWs2812xInvertedMethod NeoEsp8266BitBangWs2816InvertedMethod; -typedef NeoEsp8266BitBangTm1814InvertedMethod NeoEsp8266BitBangTm1914InvertedMethod; -typedef NeoEsp8266BitBangSk6812InvertedMethod NeoEsp8266BitBangLc8812InvertedMethod; - -#endif // defined(ARDUINO_ARCH_ESP32) - -// ESP bitbang doesn't have defaults and should avoided except for testing - -#endif // defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) diff --git a/lib/NeoPixelBus/src/internal/methods/Sm16716GenericMethod.h b/lib/NeoPixelBus/src/internal/methods/Sm16716GenericMethod.h deleted file mode 100644 index 800080ca56..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Sm16716GenericMethod.h +++ /dev/null @@ -1,140 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for SM16716 using general Pins - -Written by Michael C. Miller. -Contributed by Ivo H (ivoh95) - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "../NeoUtil.h" - -// must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set -#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) -#include "TwoWireBitBangImpleAvr.h" -#else -#include "TwoWireBitBangImple.h" -#endif - - -template class Sm16716MethodBase -{ -public: - typedef typename T_TWOWIRE::SettingsObject SettingsObject; - - Sm16716MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizeData(pixelCount* elementSize + settingsSize), - _sizeFrame(6), // 48 bits - _wire(pinClock, pinData) - { - _data = static_cast(malloc(_sizeData)); - memset(_data, 0, _sizeData); - } - -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) - Sm16716MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Sm16716MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize) - { - } -#endif - - ~Sm16716MethodBase() - { - free(_data); - } - - bool IsReadyToUpdate() const - { - return true; // dot stars don't have a required delay - } - -#if defined(ARDUINO_ARCH_ESP32) - // can't support hardware SPI due to weird extra bits - //void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) - //{ - // _wire.begin(sck, miso, mosi, ss); - //} -#endif - - void Initialize() - { - _wire.begin(); - } - - void Update(bool) - { - _wire.beginTransaction(); - - // start frame - for (size_t frameBytes = 0; frameBytes < _sizeFrame; frameBytes++) - { - _wire.transmitByte(0x00); - } - _wire.transmitBit(LOW); - _wire.transmitBit(LOW); // two extra 0s to make the 50 0 header - _wire.transmitBit(HIGH); // one to start the led frame - - for (size_t pixel = 0; pixel < (_sizeData / 3); pixel++) - { - _wire.transmitByte(_data[pixel]); - _wire.transmitByte(_data[pixel + 1]); - _wire.transmitByte(_data[pixel + 2]); - _wire.transmitBit(HIGH); //show the color and start the next frame - } - - _wire.endTransaction(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - _wire.applySettings(settings); - } - -private: - const size_t _sizeData; // Size of '_data' buffer below - const size_t _sizeFrame; - - T_TWOWIRE _wire; - uint8_t* _data; // Holds LED color values -}; - -// can ONLY support our bitbang for wire due to requirement for custom transmitBit method -// to handle not byte oriented data stream -// -typedef Sm16716MethodBase Sm16716Method; diff --git a/lib/NeoPixelBus/src/internal/methods/Tlc5947GenericMethod.h b/lib/NeoPixelBus/src/internal/methods/Tlc5947GenericMethod.h deleted file mode 100644 index 1b58f6b6e3..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Tlc5947GenericMethod.h +++ /dev/null @@ -1,222 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Tlc5947 24 channel PWM controller using general Pins. - -Written by Michael C. Miller. -Written by Dennis Kasprzyk. - -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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "../NeoUtil.h" - -// must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set -#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) -#include "TwoWireBitBangImpleAvr.h" -#else -#include "TwoWireBitBangImple.h" -#endif - -#define TLC5947_MODULE_PWM_CHANNEL_COUNT 24 - -class Tlc5947Converter8Bit -{ -public: - static const size_t sizeChannel = 1; - static void ConvertFrame(uint8_t* sendBufferPtr, uint8_t* channelPtr) - { - // Write 2 channels into 3 bytes scaling 8-bit to 12-bit per channel - for (int indexChannel = 0; indexChannel < TLC5947_MODULE_PWM_CHANNEL_COUNT; indexChannel += 2) - { - uint8_t ch1 = *channelPtr--; - uint8_t ch2 = *channelPtr--; - - *sendBufferPtr++ = ch1; - *sendBufferPtr++ = (ch1 & 0xf0) | (ch2 >> 4); - *sendBufferPtr++ = ((ch2 << 4) & 0xf0) | (ch2 >> 4); - } - } -}; - -class Tlc5947Converter16Bit -{ -public: - static const size_t sizeChannel = 2; - static void ConvertFrame(uint8_t* sendBufferPtr, uint8_t* sourceBufferPtr) - { - uint16_t* channelPtr = (uint16_t*)sourceBufferPtr; - - // Write 2 channels into 3 bytes using upper 12-bit of each channel - for (int indexChannel = 0; indexChannel < TLC5947_MODULE_PWM_CHANNEL_COUNT; indexChannel += 2) - { - uint8_t ch1 = *channelPtr--; - uint8_t ch2 = *channelPtr--; - - *sendBufferPtr++ = ch1 >> 8; - *sendBufferPtr++ = (ch1 & 0xf0) | (ch2 >> 12); - *sendBufferPtr++ = ch2 >> 4; - } - } -}; - - -template class Tlc5947MethodBase -{ -public: - typedef typename T_TWOWIRE::SettingsObject SettingsObject; - - // 24 channel * 12 bit - static const size_t sizeSendBuffer = 36; - - Tlc5947MethodBase(uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint8_t pinOutputEnable, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _countModule((pixelCount * elementSize + TLC5947_MODULE_PWM_CHANNEL_COUNT - 1) / TLC5947_MODULE_PWM_CHANNEL_COUNT), - _sizeData(_countModule * TLC5947_MODULE_PWM_CHANNEL_COUNT + settingsSize), - _wire(pinClock, pinData), - _pinLatch(pinLatch), - _pinOutputEnable(pinOutputEnable) - { - _data = static_cast(malloc(_sizeData)); - pinMode(pinLatch, OUTPUT); - pinMode(pinOutputEnable, OUTPUT); - digitalWrite(pinOutputEnable, HIGH); - } - - Tlc5947MethodBase(uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Tlc5947MethodBase(pinClock, pinData, pinLatch, -1, pixelCount, elementSize, settingsSize) - { - } - -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) - Tlc5947MethodBase(uint8_t pinLatch, uint8_t pinOutputEnable, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Tlc5947MethodBase(SCK, MOSI, pinLatch, pinOutputEnable, pixelCount, elementSize, settingsSize) - { - } - - Tlc5947MethodBase(uint8_t pinLatch, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Tlc5947MethodBase(SCK, MOSI, pinLatch, -1, pixelCount, elementSize, settingsSize) - { - } -#endif - - ~Tlc5947MethodBase() - { - free(_data); - pinMode(_pinLatch, INPUT); - pinMode(_pinOutputEnable, INPUT); - } - - bool IsReadyToUpdate() const - { - 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) - { - _wire.begin(sck, miso, mosi, ss); - } -#endif - - void Initialize() - { - _wire.begin(); - memset(_data, 0, _sizeData); - } - - void Update(bool) - { - - digitalWrite(_pinOutputEnable, HIGH); - - digitalWrite(_pinLatch, LOW); - _wire.beginTransaction(); - - // We need to write the channels in reverse order. Get a Pointer to the last channel. - uint8_t* lastChannelPtr = _data + ((_countModule * TLC5947_MODULE_PWM_CHANNEL_COUNT - 1) * T_BITCONVERT::sizeChannel); - for (uint16_t countSend = 0; countSend < _countModule; countSend++) - { - // We pass a pointer to the last channel and ConvertFrame reads the channels backwards - T_BITCONVERT::ConvertFrame(_sendBuffer, lastChannelPtr); - _wire.transmitBytes(_sendBuffer, sizeSendBuffer); - lastChannelPtr -= TLC5947_MODULE_PWM_CHANNEL_COUNT * T_BITCONVERT::sizeChannel; - } - - _wire.endTransaction(); - digitalWrite(_pinLatch, HIGH); - digitalWrite(_pinLatch, LOW); - digitalWrite(_pinOutputEnable, LOW); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - _wire.applySettings(settings); - } - -private: - const uint16_t _countModule; // Number of tlc5947 modules - const size_t _sizeData; // Size of '_data' buffer below - - T_TWOWIRE _wire; - uint8_t* _data; // Holds LED color values - uint8_t _sendBuffer[sizeSendBuffer]; // Holds channel values for one module - uint8_t _pinLatch; - uint8_t _pinOutputEnable; -}; - -typedef Tlc5947MethodBase Tlc5947Method; -typedef Tlc5947MethodBase Tlc5947Method16Bit; - -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) -#include "TwoWireSpiImple.h" - -// for standalone -typedef Tlc5947MethodBase> Tlc5947Spi30MhzMethod; -typedef Tlc5947MethodBase> Tlc5947Spi30MhzMethod16Bit; - -// for cascaded devices -typedef Tlc5947MethodBase> Tlc5947Spi15MhzMethod; -typedef Tlc5947MethodBase> Tlc5947Spi15MhzMethod16Bit; - -typedef Tlc5947MethodBase> Tlc5947SpiMethod; -typedef Tlc5947MethodBase> Tlc5947SpiMethod16Bit; - - -#endif - - - diff --git a/lib/NeoPixelBus/src/internal/topologies/ColumnMajorAlternatingLayout.h b/lib/NeoPixelBus/src/internal/topologies/ColumnMajorAlternatingLayout.h deleted file mode 100644 index ef2da56bd1..0000000000 --- a/lib/NeoPixelBus/src/internal/topologies/ColumnMajorAlternatingLayout.h +++ /dev/null @@ -1,144 +0,0 @@ -/*------------------------------------------------------------------------- -ColumnMajorAlternatingLayout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -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 -. --------------------------------------------------------------------------*/ -#pragma once - - -class ColumnMajorAlternatingLayout; -class ColumnMajorAlternating180Layout; - -class ColumnMajorAlternatingTilePreference -{ -public: - typedef ColumnMajorAlternatingLayout EvenRowEvenColumnLayout; - typedef ColumnMajorAlternatingLayout EvenRowOddColumnLayout; - typedef ColumnMajorAlternating180Layout OddRowEvenColumnLayout; - typedef ColumnMajorAlternating180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 07 08 15 -// 01 06 09 14 -// 02 05 10 13 -// 03 04 11 12 -// -class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t index = x * height; - - if (x & 0x0001) - { - index += ((height - 1) - y); - } - else - { - index += y; - } - return index; - } -}; - -// layout example of 4x4 -// 03 02 01 00 -// 04 05 06 07 -// 11 10 09 08 -// 12 13 14 15 -// -class ColumnMajorAlternating90Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - uint16_t index = y * width; - - if (y & 0x0001) - { - index += x; - } - else - { - index += ((width - 1) - x); - } - return index; - } -}; - -// layout example of 4x4 -// 12 11 04 03 -// 13 10 05 02 -// 14 09 06 01 -// 15 08 07 00 -// -class ColumnMajorAlternating180Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t mx = ((width - 1) - x); - uint16_t index = mx * height; - - if (mx & 0x0001) - { - index += y; - } - else - { - index += ((height - 1) - y); - } - return index; - } -}; - -// layout example of 4x4 -// 15 14 13 12 -// 08 09 10 11 -// 07 06 05 04 -// 00 01 02 03 -// -class ColumnMajorAlternating270Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t my = ((height - 1) - y); - uint16_t index = my * width; - - if (my & 0x0001) - { - index += ((width - 1) - x); - } - else - { - index += x; - } - return index; - } -}; diff --git a/lib/NeoPixelBus/src/internal/topologies/ColumnMajorLayout.h b/lib/NeoPixelBus/src/internal/topologies/ColumnMajorLayout.h deleted file mode 100644 index 242fd00c13..0000000000 --- a/lib/NeoPixelBus/src/internal/topologies/ColumnMajorLayout.h +++ /dev/null @@ -1,104 +0,0 @@ -/*------------------------------------------------------------------------- -ColumnMajorLayout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -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 -. --------------------------------------------------------------------------*/ -#pragma once - - -class ColumnMajorLayout; -class ColumnMajor90Layout; -class ColumnMajor180Layout; -class ColumnMajor270Layout; - -class ColumnMajorTilePreference -{ -public: - typedef ColumnMajorLayout EvenRowEvenColumnLayout; - typedef ColumnMajor270Layout EvenRowOddColumnLayout; - typedef ColumnMajor90Layout OddRowEvenColumnLayout; - typedef ColumnMajor180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 04 08 12 -// 01 05 09 13 -// 02 06 10 14 -// 03 07 11 15 -// -class ColumnMajorLayout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - return x * height + y; - } -}; - -// layout example of 4x4 -// 03 02 01 00 -// 07 06 05 04 -// 11 10 09 08 -// 15 14 13 12 -// -class ColumnMajor90Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - return (width - 1 - x) + y * width; - } -}; - -// layout example of 4x4 -// 15 11 07 03 -// 14 10 06 02 -// 13 09 05 01 -// 12 08 04 00 -// -class ColumnMajor180Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) * height + (height - 1 - y); - } -}; - -// layout example of 4x4 -// 12 13 14 15 -// 08 09 10 11 -// 04 05 06 07 -// 00 01 02 03 -// -class ColumnMajor270Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return x + (height - 1 - y) * width; - } -}; diff --git a/lib/NeoPixelBus/src/internal/topologies/RowMajorAlternatingLayout.h b/lib/NeoPixelBus/src/internal/topologies/RowMajorAlternatingLayout.h deleted file mode 100644 index 09a23c7127..0000000000 --- a/lib/NeoPixelBus/src/internal/topologies/RowMajorAlternatingLayout.h +++ /dev/null @@ -1,144 +0,0 @@ -/*------------------------------------------------------------------------- -RowMajorAlternatingLayout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -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 -. --------------------------------------------------------------------------*/ -#pragma once - - -class RowMajorAlternating270Layout; -class RowMajorAlternating90Layout; - -class RowMajorAlternatingTilePreference -{ -public: - typedef RowMajorAlternating270Layout EvenRowEvenColumnLayout; - typedef RowMajorAlternating270Layout EvenRowOddColumnLayout; - typedef RowMajorAlternating90Layout OddRowEvenColumnLayout; - typedef RowMajorAlternating90Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 01 02 03 -// 07 06 05 04 -// 08 09 10 11 -// 15 14 13 12 -// -class RowMajorAlternatingLayout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - uint16_t index = y * width; - - if (y & 0x0001) - { - index += ((width - 1) - x); - } - else - { - index += x; - } - return index; - } -}; - -// layout example of 4x4 -// 15 08 07 00 -// 14 09 06 01 -// 13 10 05 02 -// 12 11 04 03 -// -class RowMajorAlternating90Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t mx = ((width - 1) - x); - uint16_t index = mx * height; - - if (mx & 0x0001) - { - index += ((height - 1) - y); - } - else - { - index += y; - } - return index; - } -}; - -// layout example of 4x4 -// 12 13 14 15 -// 11 10 09 08 -// 04 05 06 07 -// 03 02 01 00 -// -class RowMajorAlternating180Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t my = ((height - 1) - y); - uint16_t index = my * width; - - if (my & 0x0001) - { - index += x; - } - else - { - index += ((width - 1) - x); - } - return index; - } -}; - -// layout example of 4x4 -// 03 04 11 12 -// 02 05 10 13 -// 01 06 09 14 -// 00 07 08 15 -// -class RowMajorAlternating270Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t index = x * height; - - if (x & 0x0001) - { - index += y; - } - else - { - index += ((height - 1) - y); - } - return index; - } -}; diff --git a/lib/NeoPixelBus/src/internal/topologies/RowMajorLayout.h b/lib/NeoPixelBus/src/internal/topologies/RowMajorLayout.h deleted file mode 100644 index 90a6f65305..0000000000 --- a/lib/NeoPixelBus/src/internal/topologies/RowMajorLayout.h +++ /dev/null @@ -1,103 +0,0 @@ -/*------------------------------------------------------------------------- -RowMajorLayout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -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 -. --------------------------------------------------------------------------*/ -#pragma once - -class RowMajorLayout; -class RowMajor90Layout; -class RowMajor180Layout; -class RowMajor270Layout; - -class RowMajorTilePreference -{ -public: - typedef RowMajorLayout EvenRowEvenColumnLayout; - typedef RowMajor270Layout EvenRowOddColumnLayout; - typedef RowMajor90Layout OddRowEvenColumnLayout; - typedef RowMajor180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 01 02 03 -// 04 05 06 07 -// 08 09 10 11 -// 12 13 14 15 -// -class RowMajorLayout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - return x + y * width; - } -}; - -// layout example of 4x4 -// 12 08 04 00 -// 13 09 05 01 -// 14 10 06 02 -// 15 11 07 03 -// -class RowMajor90Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) * height + y; - } -}; - -// layout example of 4x4 -// 15 14 13 12 -// 11 10 09 08 -// 07 06 05 04 -// 03 02 01 00 -// -class RowMajor180Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) + (height - 1 - y) * width; - } -}; - -// layout example of 4x4 -// 03 07 11 15 -// 02 06 10 14 -// 01 05 09 13 -// 00 04 08 12 -// -class RowMajor270Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - return x * height + (height - 1 - y); - } -}; From f3e0191fc90084b19f0b5e062916595380294aa9 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Thu, 26 Oct 2023 22:14:51 +0200 Subject: [PATCH 04/25] [NeoPixel] Add changelogs for applying NeoPixelBus_wrapper library --- lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h | 2 ++ src/_P038_NeoPixel.ino | 1 + src/_P041_NeoClock.ino | 6 ++++++ src/_P042_Candle.ino | 1 + src/_P070_NeoPixel_Clock.ino | 5 +++++ 5 files changed, 15 insertions(+) diff --git a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h index ba814302c7..1ad7126a94 100644 --- a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h +++ b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h @@ -42,6 +42,8 @@ #include #include +// 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library + // Matrix layout information is passed in the 'matrixType' parameter for // each constructor (the parameter immediately following is the LED type // from NeoPixel.h). diff --git a/src/_P038_NeoPixel.ino b/src/_P038_NeoPixel.ino index ad5b66d692..b9bfd1fa6f 100644 --- a/src/_P038_NeoPixel.ino +++ b/src/_P038_NeoPixel.ino @@ -7,6 +7,7 @@ // ####################################################################################################### // Changelog: +// 2023-10-26, tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library // 2022-12-26, tonhuisman: Set initial brightness with default value 255, and allow 'only' values 1..255 // 2022-11-06, tonhuisman: Add Initial and Max brightness settings, and NeoPixelBright[,0..255] command, 0 = initial // Code optimizations diff --git a/src/_P041_NeoClock.ino b/src/_P041_NeoClock.ino index 260ce7d318..e0e804a33b 100644 --- a/src/_P041_NeoClock.ino +++ b/src/_P041_NeoClock.ino @@ -3,6 +3,12 @@ //####################################################################################################### //#################################### Plugin 041: NeoPixel clock ####################################### //####################################################################################################### + +/** Changelog: + * 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library + * 2023-10 tonhuisman: Add changelog. + */ + #include diff --git a/src/_P042_Candle.ino b/src/_P042_Candle.ino index bcb309c321..3334ca0ee8 100644 --- a/src/_P042_Candle.ino +++ b/src/_P042_Candle.ino @@ -9,6 +9,7 @@ // Wifi Candle for ESPEasy by Dominik Schmidt (10.2016) /** Changelog: + * 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library * 2023-01-21 tonhuisman: Move to PluginStruct_base to enable multi-instance use of this plugin * 2023-01-21 tonhuisman: Further refactor and improve code, including GH feedback * Add setting for Led Count, defaults to 20 (was fixed size) diff --git a/src/_P070_NeoPixel_Clock.ino b/src/_P070_NeoPixel_Clock.ino index c759a94210..9415b32f45 100644 --- a/src/_P070_NeoPixel_Clock.ino +++ b/src/_P070_NeoPixel_Clock.ino @@ -7,6 +7,11 @@ // #################################### Plugin 070: NeoPixel ring clock ####################################### // ####################################################################################################### +/** Changelog: + * 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library + * 2023-10 tonhuisman: Add changelog. + */ + // A clock that uses a strip/ring of 60 WS2812 NeoPixel LEDs as display for a classic clock. // The hours are RED, the minutes are GREEN, the seconds are BLUE and the hour marks are WHITE. From 43c66734da6cfe9783159f97f30f6ba176e902f8 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Thu, 26 Oct 2023 22:30:27 +0200 Subject: [PATCH 05/25] [Build] Fix pygit2 version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4a4dc0318c..5e3d45768c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ platformio>=6.1.9 -pygit2>=1.10.1 +pygit2==1.13.1 From 2871fc90fe0bc524f888377009fbcc1fee4e7076 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Thu, 26 Oct 2023 22:42:36 +0200 Subject: [PATCH 06/25] [Build] Fix pygit2 version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5e3d45768c..309528dae7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ platformio>=6.1.9 -pygit2==1.13.1 +pygit2==1.12.1 From e6cecc37fc0d48d1c8d18096e6365235195433c8 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 27 Oct 2023 20:34:30 +0200 Subject: [PATCH 07/25] [Build] Restore pygit2 version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 309528dae7..4a4dc0318c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ platformio>=6.1.9 -pygit2==1.12.1 +pygit2>=1.10.1 From a6a55d5161936f5418a62d31cc4e10bcbda0276e Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 27 Oct 2023 20:46:11 +0200 Subject: [PATCH 08/25] [Build] Try older/current version of pip --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 580eb5e132..bc82f0bafd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,7 +85,7 @@ jobs: run: | sudo apt-get update sudo apt install binutils build-essential libffi-dev libgit2-dev - pip3 install --upgrade pip + # pip3 install --upgrade pip pip install -r requirements.txt platformio update - name: Build and archive From b000c58c9dc6e080157f69be903c6ec19b76b06c Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 27 Oct 2023 21:01:06 +0200 Subject: [PATCH 09/25] [Build] Explicit version of libgit2 --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc82f0bafd..164d862f90 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,8 +84,8 @@ jobs: - name: Dependencies run: | sudo apt-get update - sudo apt install binutils build-essential libffi-dev libgit2-dev - # pip3 install --upgrade pip + sudo apt install binutils build-essential libffi-dev libgit2-dev=1.7.1 + pip3 install --upgrade pip pip install -r requirements.txt platformio update - name: Build and archive From 02b41360eb3174f25c5d9a89a1663c474b486437 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 27 Oct 2023 21:04:42 +0200 Subject: [PATCH 10/25] [Build] Undo changes --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 164d862f90..580eb5e132 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,7 +84,7 @@ jobs: - name: Dependencies run: | sudo apt-get update - sudo apt install binutils build-essential libffi-dev libgit2-dev=1.7.1 + sudo apt install binutils build-essential libffi-dev libgit2-dev pip3 install --upgrade pip pip install -r requirements.txt platformio update From 3f86d2e141d676f8f5db155bb6ae74a823879d90 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 27 Oct 2023 21:22:22 +0200 Subject: [PATCH 11/25] [ESP-IDF5.1] Fix build issue on older IDF based builds --- lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.cpp | 4 ++-- lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h | 2 +- lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp | 1 + lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h | 8 +++----- lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h | 8 ++++---- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.cpp b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.cpp index c8525e09dc..2a756934f8 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.cpp +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.cpp @@ -28,12 +28,12 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include + +#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR < 5 && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2) #include "NeoSettings.h" #include "NeoBusChannel.h" #include "NeoEsp32RmtMethod.h" -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2) - // translate NeoPixelBuffer into RMT buffer // this is done on the fly so we don't require a send buffer in raw RMT format diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h index e804cc2a7e..3cc86d19a4 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h @@ -29,7 +29,7 @@ License along with NeoPixel. If not, see #pragma once -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2) +#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR < 5 && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2) /* General Reference documentation for the APIs used in this implementation LOW LEVEL: (what is actually used) diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp index 4279fef9cc..2d0e741a1d 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp @@ -1,3 +1,4 @@ +#if ESP_IDF_VERSION_MAJOR >= 5 && defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C2) #include "../internal/NeoEsp32RmtMethod_idf5.h" #if ESP_IDF_VERSION_MAJOR >= 5 diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h index 5807f46309..01d45866eb 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h @@ -29,9 +29,7 @@ License along with NeoPixel. If not, see #pragma once -#if ESP_IDF_VERSION_MAJOR >= 5 - -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C2) +#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR >= 5 && !defined(CONFIG_IDF_TARGET_ESP32C2) /* General Reference documentation for the APIs used in this implementation LOW LEVEL: (what is actually used) @@ -369,9 +367,9 @@ class NeoEsp32RmtChannelN { public: NeoEsp32RmtChannelN(NeoBusChannel channel) : - RmtChannelNumber(RmtChannelNumber) + RmtChannelNumber(nullptr) { - RmtChannelNumber = NULL; + //RmtChannelNumber = NULL; }; NeoEsp32RmtChannelN() = delete; // no default constructor rmt_channel_handle_t RmtChannelNumber = NULL; diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h b/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h index 826d6ef99c..a6c3adc23c 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h @@ -28,7 +28,7 @@ License along with NeoPixel. If not, see #pragma once -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR >= 5 #if (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6)) && !defined(HSPI_HOST) // HSPI_HOST depreciated in C3 @@ -37,7 +37,7 @@ License along with NeoPixel. If not, see #include -extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); // TODO: Remove all Addlogs +// extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); // TODO: Remove all Addlogs extern "C" { @@ -329,7 +329,7 @@ template class NeoEsp32SpiMethodBase _spi_strip->bytes_per_pixel = bytes_per_pixel; _spi_strip->strip_len = _pixelCount; - AddLog(2,"SPI:initialized with error code: %u on pin: %u",ret, _pin); + // AddLog(2,"SPI:initialized with error code: %u on pin: %u",ret, _pin); return; err: if (_spi_strip) { @@ -341,7 +341,7 @@ template class NeoEsp32SpiMethodBase } free(_spi_strip); } - AddLog(2,"SPI-Error:initialized with error code: %u on pin: %u",ret, _pin); + // AddLog(2,"SPI-Error:initialized with error code: %u on pin: %u",ret, _pin); return; } From f503b186ac3822bc4996190d8d4aa2473b50f9cc Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 27 Oct 2023 21:27:21 +0200 Subject: [PATCH 12/25] [Neopixel] Fixes and improvements --- lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp | 5 ----- lib/NeoPixelBus_wrapper/README.md | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp index 2d0e741a1d..467a6247fe 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp @@ -1,10 +1,6 @@ #if ESP_IDF_VERSION_MAJOR >= 5 && defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C2) #include "../internal/NeoEsp32RmtMethod_idf5.h" -#if ESP_IDF_VERSION_MAJOR >= 5 - -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C2) - size_t rmt_encode_led_strip(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state) { @@ -110,4 +106,3 @@ esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rm #endif -#endif // if ESP_IDF_VERSION_MAJOR >= 5 diff --git a/lib/NeoPixelBus_wrapper/README.md b/lib/NeoPixelBus_wrapper/README.md index 1ac59f7fea..8e03098e27 100644 --- a/lib/NeoPixelBus_wrapper/README.md +++ b/lib/NeoPixelBus_wrapper/README.md @@ -2,7 +2,7 @@ **NeoPixelBus_wrapper**: A minimal wrapper to replace Adafruit_NeoPixel API to use Makuna's NeoPixelBus API. -(c) 2023, Ton Huisman for ESPEasy. +(c) 2023, Ton Huisman for [ESPEasy](https://github.com/letscontrolit/ESPEasy). ### How to use From 98ee5357d7051de2178f04e08af7ad9404e19b31 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 27 Oct 2023 22:42:46 +0200 Subject: [PATCH 13/25] [Build] Freeze pip dependencies --- requirements.txt | 127 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4a4dc0318c..830f15d560 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,125 @@ -platformio>=6.1.9 -pygit2>=1.10.1 +aiofiles==23.1.0 +aiohttp==3.8.1 +aiohttp-retry==2.4.6 +aiosignal==1.2.0 +ajsonrpc==1.2.0 +alabaster==0.7.12 +anyio==3.6.1 +appdirs==1.4.4 +asgiref==3.5.2 +async-timeout==4.0.2 +asyncssh==2.10.0 +atpublic==3.0.1 +attrs==21.4.0 +Babel==2.9.1 +bitstring==4.0.2 +bottle==0.12.21 +certifi==2021.10.8 +cffi==1.15.0 +charset-normalizer==2.0.7 +click==8.1.3 +colorama==0.4.4 +commonmark==0.9.1 +configobj==5.0.6 +cryptography==36.0.2 +desktop-notifier==3.4.2 +dictdiffer==0.9.0 +diskcache==5.4.0 +distro==1.7.0 +docutils==0.17.1 +dpath==2.0.6 +dulwich==0.20.35 +dvc==2.10.1 +dvc-render==0.0.4 +ecdsa==0.18.0 +esbonio==0.14.1 +esptool==4.6 +flatten-dict==0.4.2 +flufl.lock==7.0 +frozenlist==1.3.0 +fsspec==2022.3.0 +ftfy==6.1.1 +funcy==1.17 +future==0.18.2 +gitdb==4.0.9 +GitPython==3.1.27 +grandalf==0.6 +h11==0.13.0 +idna==3.3 +ifaddr==0.1.7 +imagesize==1.2.0 +Jinja2==3.0.2 +livereload==2.6.3 +mailchecker==4.1.14 +MarkupSafe==2.0.1 +marshmallow==3.19.0 +multidict==6.0.2 +nanotime==0.5.2 +networkx==2.8 +packaging==21.0 +pathspec==0.9.0 +phonenumbers==8.12.46 +platformio==6.1.9 +psutil==5.9.0 +pycparser==2.21 +pydantic==1.8.2 +pydot==1.4.2 +pyelftools==0.29 +pygit2==1.12.1 +pygls==0.11.3 +Pygments==2.10.0 +pygtrie==2.4.2 +pyparsing==2.4.7 +pyserial==3.5 +pyspellchecker==0.6.3 +python-benedict==0.25.0 +python-dateutil==2.8.2 +python-fsutil==0.6.0 +python-slugify==6.1.1 +pytz==2021.3 +PyYAML==6.0 +recommonmark==0.7.1 +reedsolo==1.7.0 +requests==2.26.0 +rich==12.2.0 +ruamel.yaml==0.17.21 +ruamel.yaml.clib==0.2.6 +scmrepo==0.0.16 +SCons==4.5.2 +semantic-version==2.10.0 +shortuuid==1.0.8 +shtab==1.5.3 +six==1.16.0 +smmap==5.0.0 +sniffio==1.2.0 +snowballstemmer==2.1.0 +Sphinx==4.5.0 +sphinx-autobuild==2021.3.14 +sphinx-bootstrap-theme==0.8.1 +sphinxcontrib-applehelp==1.0.2 +sphinxcontrib-devhelp==1.0.2 +sphinxcontrib-htmlhelp==2.0.0 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.3 +sphinxcontrib-serializinghtml==1.1.5 +sphinxcontrib-websupport==1.2.4 +starlette==0.28.0 +tabulate==0.9.0 +tasmota-metrics==0.3.3 +text-unidecode==1.3 +toml==0.10.2 +tornado==6.1 +tqdm==4.64.0 +typeguard==2.13.3 +typing_extensions==4.1.1 +urllib3==1.26.7 +uvicorn==0.22.0 +voluptuous==0.13.1 +wcwidth==0.2.5 +winsdk==1.0.0b7 +wsproto==1.2.0 +xmltodict==0.12.0 +yarl==1.7.2 +zc.lockfile==2.0 +zeroconf==0.38.6 +zopfli==0.2.2 From e85784000dc5f4b41233a97bbcca6ffdba767fdd Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 27 Oct 2023 22:59:29 +0200 Subject: [PATCH 14/25] [Build] Undo changes --- requirements.txt | 127 +---------------------------------------------- 1 file changed, 2 insertions(+), 125 deletions(-) diff --git a/requirements.txt b/requirements.txt index 830f15d560..3cd41b3baf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,125 +1,2 @@ -aiofiles==23.1.0 -aiohttp==3.8.1 -aiohttp-retry==2.4.6 -aiosignal==1.2.0 -ajsonrpc==1.2.0 -alabaster==0.7.12 -anyio==3.6.1 -appdirs==1.4.4 -asgiref==3.5.2 -async-timeout==4.0.2 -asyncssh==2.10.0 -atpublic==3.0.1 -attrs==21.4.0 -Babel==2.9.1 -bitstring==4.0.2 -bottle==0.12.21 -certifi==2021.10.8 -cffi==1.15.0 -charset-normalizer==2.0.7 -click==8.1.3 -colorama==0.4.4 -commonmark==0.9.1 -configobj==5.0.6 -cryptography==36.0.2 -desktop-notifier==3.4.2 -dictdiffer==0.9.0 -diskcache==5.4.0 -distro==1.7.0 -docutils==0.17.1 -dpath==2.0.6 -dulwich==0.20.35 -dvc==2.10.1 -dvc-render==0.0.4 -ecdsa==0.18.0 -esbonio==0.14.1 -esptool==4.6 -flatten-dict==0.4.2 -flufl.lock==7.0 -frozenlist==1.3.0 -fsspec==2022.3.0 -ftfy==6.1.1 -funcy==1.17 -future==0.18.2 -gitdb==4.0.9 -GitPython==3.1.27 -grandalf==0.6 -h11==0.13.0 -idna==3.3 -ifaddr==0.1.7 -imagesize==1.2.0 -Jinja2==3.0.2 -livereload==2.6.3 -mailchecker==4.1.14 -MarkupSafe==2.0.1 -marshmallow==3.19.0 -multidict==6.0.2 -nanotime==0.5.2 -networkx==2.8 -packaging==21.0 -pathspec==0.9.0 -phonenumbers==8.12.46 -platformio==6.1.9 -psutil==5.9.0 -pycparser==2.21 -pydantic==1.8.2 -pydot==1.4.2 -pyelftools==0.29 -pygit2==1.12.1 -pygls==0.11.3 -Pygments==2.10.0 -pygtrie==2.4.2 -pyparsing==2.4.7 -pyserial==3.5 -pyspellchecker==0.6.3 -python-benedict==0.25.0 -python-dateutil==2.8.2 -python-fsutil==0.6.0 -python-slugify==6.1.1 -pytz==2021.3 -PyYAML==6.0 -recommonmark==0.7.1 -reedsolo==1.7.0 -requests==2.26.0 -rich==12.2.0 -ruamel.yaml==0.17.21 -ruamel.yaml.clib==0.2.6 -scmrepo==0.0.16 -SCons==4.5.2 -semantic-version==2.10.0 -shortuuid==1.0.8 -shtab==1.5.3 -six==1.16.0 -smmap==5.0.0 -sniffio==1.2.0 -snowballstemmer==2.1.0 -Sphinx==4.5.0 -sphinx-autobuild==2021.3.14 -sphinx-bootstrap-theme==0.8.1 -sphinxcontrib-applehelp==1.0.2 -sphinxcontrib-devhelp==1.0.2 -sphinxcontrib-htmlhelp==2.0.0 -sphinxcontrib-jsmath==1.0.1 -sphinxcontrib-qthelp==1.0.3 -sphinxcontrib-serializinghtml==1.1.5 -sphinxcontrib-websupport==1.2.4 -starlette==0.28.0 -tabulate==0.9.0 -tasmota-metrics==0.3.3 -text-unidecode==1.3 -toml==0.10.2 -tornado==6.1 -tqdm==4.64.0 -typeguard==2.13.3 -typing_extensions==4.1.1 -urllib3==1.26.7 -uvicorn==0.22.0 -voluptuous==0.13.1 -wcwidth==0.2.5 -winsdk==1.0.0b7 -wsproto==1.2.0 -xmltodict==0.12.0 -yarl==1.7.2 -zc.lockfile==2.0 -zeroconf==0.38.6 -zopfli==0.2.2 +platformio>=6.1.9 +pygit2>=1.10.1 \ No newline at end of file From e172745b079b173d59df59a06f2f45879442ec96 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 28 Oct 2023 10:26:38 +0200 Subject: [PATCH 15/25] [Build] Try fix failing pygit2 install --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 580eb5e132..e4274f2a54 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,6 +86,7 @@ jobs: sudo apt-get update sudo apt install binutils build-essential libffi-dev libgit2-dev pip3 install --upgrade pip + pip install wheel pip install -r requirements.txt platformio update - name: Build and archive From 021f7ea4daabb1f70e3d114a095c1f555d85b657 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 28 Oct 2023 10:38:26 +0200 Subject: [PATCH 16/25] [Build] Try older Python version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e4274f2a54..f5849a2f13 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: - python-version: '3.x' + python-version: '3.11' - uses: actions/cache@v3 with: path: ~/.cache/pip From 1f447d2b84c04f7ba62437c249e59e5a2f5f59b8 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 28 Oct 2023 11:16:54 +0200 Subject: [PATCH 17/25] [Neopixel] Fix fall-through return value --- lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp index 09d2d1739d..304beb3cbb 100644 --- a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp +++ b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp @@ -112,6 +112,8 @@ uint32_t NeoPixelBus_wrapper::getPixelColor(uint16_t n) { color = neopixels_grbw->GetPixelColor(n); return Color(color.R, color.G, color.B, color.W); } + + return 0u; // Fall-through value... } #endif // ifndef _NEOPIXELBUS_WRAPPER_CPP From 9695519cce9cffb241291e9ac24039a6b3a0fb5e Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 28 Oct 2023 11:19:30 +0200 Subject: [PATCH 18/25] [Build] Fix some cherry-pick diffs --- lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp | 3 +-- lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h | 2 -- platformio_core_defs.ini | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp index 467a6247fe..9ca1cddd3b 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp @@ -104,5 +104,4 @@ esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rm return ret; } -#endif - +#endif \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h index 01d45866eb..d0fc0d8fae 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h @@ -799,5 +799,3 @@ typedef NeoEsp32Rmt6400KbpsInvertedMethod Neo400KbpsInvertedMethod; #endif // defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) #endif - -#endif // if ESP_IDF_VERSION_MAJOR >= 5 \ No newline at end of file diff --git a/platformio_core_defs.ini b/platformio_core_defs.ini index 453413849d..31a4a23689 100644 --- a/platformio_core_defs.ini +++ b/platformio_core_defs.ini @@ -250,6 +250,7 @@ build_flags = -DESP32_STAGE -DCONFIG_PM_ENABLE -DCONFIG_FREERTOS_USE_TICKLESS_IDLE=1 -DCONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3 + -DNEOPIXEL_ESP32_RMT_DEFAULT -I$PROJECT_DIR/src/include -include "sdkconfig.h" -include "ESPEasy_config.h" From 5090808325f3f1d13135f07c2322b233b5b7ce7d Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 28 Oct 2023 16:28:40 +0200 Subject: [PATCH 19/25] [NeopixelWrapper] Code optimization --- lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp index 304beb3cbb..54c5c9dc77 100644 --- a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp +++ b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp @@ -102,14 +102,12 @@ void NeoPixelBus_wrapper::setPixelColor(uint16_t pxl, uint32_t NeoPixelBus_wrapper::getPixelColor(uint16_t n) { if (nullptr != neopixels_grb) { - RgbColor color; - color = neopixels_grb->GetPixelColor(n); + const RgbColor color = neopixels_grb->GetPixelColor(n); return Color(color.R, color.G, color.B); } if (nullptr != neopixels_grbw) { - RgbwColor color; - color = neopixels_grbw->GetPixelColor(n); + const RgbwColor color = neopixels_grbw->GetPixelColor(n); return Color(color.R, color.G, color.B, color.W); } From 455f771ecf5cfb52e924942dbc462bd854e8e658 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 4 Nov 2023 14:26:09 +0100 Subject: [PATCH 20/25] [Lib] Adafruit_NeoMatrix: Fix includes --- lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp index 7a1fa1f801..2b0746ee82 100644 --- a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp +++ b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp @@ -48,8 +48,7 @@ */ #include "gamma.h" -#include -#include +#include "Adafruit_NeoMatrix.h" #ifdef __AVR__ #include #elif defined(ESP8266) From d8d79e9cdd239f55afa047d231c87911b452c08e Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 4 Nov 2023 14:26:43 +0100 Subject: [PATCH 21/25] [Lib] Remove Adafruit_NeoPixel from repo --- .../.github/ISSUE_TEMPLATE.md | 46 - .../.github/PULL_REQUEST_TEMPLATE.md | 26 - .../.github/workflows/githubci.yml | 29 - lib/Adafruit_NeoPixel/.gitignore | 4 - lib/Adafruit_NeoPixel/.travis.yml | 11 - lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp | 3441 ----------------- lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h | 410 -- lib/Adafruit_NeoPixel/CONTRIBUTING.md | 13 - lib/Adafruit_NeoPixel/COPYING | 165 - lib/Adafruit_NeoPixel/README.md | 157 - lib/Adafruit_NeoPixel/esp.c | 178 - lib/Adafruit_NeoPixel/esp8266.c | 86 - .../RGBWstrandtest/.esp8266.test.skip | 0 .../RGBWstrandtest/.trinket.test.skip | 0 .../RGBWstrandtest/RGBWstrandtest.ino | 177 - .../.arduinoble.test.only | 0 .../StrandtestArduinoBLE/.none.test.only | 0 .../examples/StrandtestArduinoBLE/.test.skip | 0 .../StrandtestArduinoBLE.ino | 231 -- .../.arduinoble.test.only | 0 .../.none.test.only | 0 .../StrandtestArduinoBLECallback/.test.skip | 0 .../StrandtestArduinoBLECallback.ino | 239 -- .../StrandtestBLE/.arduinoble.test.only | 0 .../examples/StrandtestBLE/.none.test.only | 0 .../examples/StrandtestBLE/.test.skip | 0 .../examples/StrandtestBLE/BLESerial.cpp | 133 - .../examples/StrandtestBLE/BLESerial.h | 46 - .../examples/StrandtestBLE/StrandtestBLE.ino | 192 - .../StrandtestBLE_nodelay/.none.test.only | 1 - .../StrandtestBLE_nodelay/BLESerial.cpp | 133 - .../StrandtestBLE_nodelay/BLESerial.h | 46 - .../StrandtestBLE_nodelay.ino | 198 - .../examples/buttoncycler/.esp8266.test.skip | 0 .../examples/buttoncycler/buttoncycler.ino | 164 - .../examples/simple/.esp8266.test.skip | 0 .../examples/simple/simple.ino | 50 - .../simple_new_operator/.esp8266.test.skip | 0 .../simple_new_operator.ino | 67 - .../examples/strandtest/.esp8266.test.skip | 0 .../examples/strandtest/strandtest.ino | 143 - .../strandtest_nodelay/.esp8266.test.skip | 1 - .../strandtest_nodelay/strandtest_nodelay.ino | 186 - .../strandtest_wheel/.esp8266.test.skip | 0 .../strandtest_wheel/strandtest_wheel.ino | 134 - lib/Adafruit_NeoPixel/kendyte_k210.c | 74 - lib/Adafruit_NeoPixel/keywords.txt | 72 - lib/Adafruit_NeoPixel/library.properties | 10 - lib/Adafruit_NeoPixel/rp2040.c | 53 - lib/Adafruit_NeoPixel/rp2040_pio.h | 63 - 50 files changed, 6979 deletions(-) delete mode 100644 lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md delete mode 100644 lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md delete mode 100644 lib/Adafruit_NeoPixel/.github/workflows/githubci.yml delete mode 100644 lib/Adafruit_NeoPixel/.gitignore delete mode 100644 lib/Adafruit_NeoPixel/.travis.yml delete mode 100644 lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp delete mode 100644 lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h delete mode 100644 lib/Adafruit_NeoPixel/CONTRIBUTING.md delete mode 100644 lib/Adafruit_NeoPixel/COPYING delete mode 100644 lib/Adafruit_NeoPixel/README.md delete mode 100644 lib/Adafruit_NeoPixel/esp.c delete mode 100644 lib/Adafruit_NeoPixel/esp8266.c delete mode 100644 lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.esp8266.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.trinket.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.arduinoble.test.only delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.none.test.only delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.arduinoble.test.only delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.none.test.only delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE/.arduinoble.test.only delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE/.none.test.only delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE/.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h delete mode 100644 lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/buttoncycler/.esp8266.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/simple/.esp8266.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/simple/simple.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/simple_new_operator/.esp8266.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/simple_new_operator/simple_new_operator.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/strandtest/.esp8266.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/strandtest/strandtest.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino delete mode 100644 lib/Adafruit_NeoPixel/examples/strandtest_wheel/.esp8266.test.skip delete mode 100644 lib/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino delete mode 100644 lib/Adafruit_NeoPixel/kendyte_k210.c delete mode 100644 lib/Adafruit_NeoPixel/keywords.txt delete mode 100644 lib/Adafruit_NeoPixel/library.properties delete mode 100644 lib/Adafruit_NeoPixel/rp2040.c delete mode 100644 lib/Adafruit_NeoPixel/rp2040_pio.h diff --git a/lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md b/lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index f0e26146fa..0000000000 --- a/lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,46 +0,0 @@ -Thank you for opening an issue on an Adafruit Arduino library repository. To -improve the speed of resolution please review the following guidelines and -common troubleshooting steps below before creating the issue: - -- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use - the forums at http://forums.adafruit.com to ask questions and troubleshoot why - something isn't working as expected. In many cases the problem is a common issue - that you will more quickly receive help from the forum community. GitHub issues - are meant for known defects in the code. If you don't know if there is a defect - in the code then start with troubleshooting on the forum first. - -- **If following a tutorial or guide be sure you didn't miss a step.** Carefully - check all of the steps and commands to run have been followed. Consult the - forum if you're unsure or have questions about steps in a guide/tutorial. - -- **For Arduino projects check these very common issues to ensure they don't apply**: - - - For uploading sketches or communicating with the board make sure you're using - a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes - very hard to tell the difference between a data and charge cable! Try using the - cable with other devices or swapping to another cable to confirm it is not - the problem. - - - **Be sure you are supplying adequate power to the board.** Check the specs of - your board and plug in an external power supply. In many cases just - plugging a board into your computer is not enough to power it and other - peripherals. - - - **Double check all soldering joints and connections.** Flakey connections - cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. - - - **Ensure you are using an official Arduino or Adafruit board.** We can't - guarantee a clone board will have the same functionality and work as expected - with this code and don't support them. - -If you're sure this issue is a defect in the code and checked the steps above -please fill in the following fields to provide enough troubleshooting information. -You may delete the guideline and text above to just leave the following details: - -- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** - -- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO - VERSION HERE** - -- List the steps to reproduce the problem below (if possible attach a sketch or - copy the sketch code in too): **LIST REPRO STEPS BELOW** diff --git a/lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md b/lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7b641eb862..0000000000 --- a/lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,26 +0,0 @@ -Thank you for creating a pull request to contribute to Adafruit's GitHub code! -Before you open the request please review the following guidelines and tips to -help it be more easily integrated: - -- **Describe the scope of your change--i.e. what the change does and what parts - of the code were modified.** This will help us understand any risks of integrating - the code. - -- **Describe any known limitations with your change.** For example if the change - doesn't apply to a supported platform of the library please mention it. - -- **Please run any tests or examples that can exercise your modified code.** We - strive to not break users of the code and running tests/examples helps with this - process. - -Thank you again for contributing! We will try to test and integrate the change -as soon as we can, but be aware we have many GitHub repositories to manage and -can't immediately respond to every request. There is no need to bump or check in -on a pull request (it will clutter the discussion of the request). - -Also don't be worried if the request is closed or not integrated--sometimes the -priorities of Adafruit's GitHub code (education, ease of use) might not match the -priorities of the pull request. Don't fret, the open source community thrives on -forks and GitHub makes it easy to keep your changes in a forked repo. - -After reviewing the guidelines above you can delete this text from the pull request. diff --git a/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml b/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml deleted file mode 100644 index 2ff3d65477..0000000000 --- a/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Arduino Library CI - -on: [pull_request, push, repository_dispatch] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/setup-python@v1 - with: - python-version: '3.x' - - uses: actions/checkout@v2 - - uses: actions/checkout@v2 - with: - repository: adafruit/ci-arduino - path: ci - - - name: pre-install - run: bash ci/actions_install.sh - - - name: test platforms - run: python3 ci/build_platform.py main_platforms - - - name: doxygen - env: - GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} - PRETTYNAME : "Adafruit NeoPixel Library" - run: bash ci/doxy_gen_and_deploy.sh diff --git a/lib/Adafruit_NeoPixel/.gitignore b/lib/Adafruit_NeoPixel/.gitignore deleted file mode 100644 index c2a26c0383..0000000000 --- a/lib/Adafruit_NeoPixel/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Our handy .gitignore for automation ease -Doxyfile* -doxygen_sqlite3.db -html diff --git a/lib/Adafruit_NeoPixel/.travis.yml b/lib/Adafruit_NeoPixel/.travis.yml deleted file mode 100644 index f4b943074f..0000000000 --- a/lib/Adafruit_NeoPixel/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: c -sudo: false -before_install: - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) -script: - - build_main_platforms - - build_platform trinket -notifications: - email: - on_success: change - on_failure: change diff --git a/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp b/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp deleted file mode 100644 index d1a260a777..0000000000 --- a/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp +++ /dev/null @@ -1,3441 +0,0 @@ -/*! - * @file Adafruit_NeoPixel.cpp - * - * @mainpage Arduino Library for driving Adafruit NeoPixel addressable LEDs, - * FLORA RGB Smart Pixels and compatible devicess -- WS2811, WS2812, WS2812B, - * SK6812, etc. - * - * @section intro_sec Introduction - * - * This is the documentation for Adafruit's NeoPixel library for the - * Arduino platform, allowing a broad range of microcontroller boards - * (most AVR boards, many ARM devices, ESP8266 and ESP32, among others) - * to control Adafruit NeoPixels, FLORA RGB Smart Pixels and compatible - * devices -- WS2811, WS2812, WS2812B, SK6812, etc. - * - * Adafruit invests time and resources providing this open source code, - * please support Adafruit and open-source hardware by purchasing products - * from Adafruit! - * - * @section author Author - * - * Written by Phil "Paint Your Dragon" Burgess for Adafruit Industries, - * with contributions by PJRC, Michael Miller and other members of the - * open source community. - * - * @section license License - * - * This file is part of the Adafruit_NeoPixel library. - * - * Adafruit_NeoPixel 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. - * - * Adafruit_NeoPixel 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 - * . - * - */ - -#include "Adafruit_NeoPixel.h" - -#if defined(TARGET_LPC1768) -#include -#endif - -#if defined(NRF52) || defined(NRF52_SERIES) -#include "nrf.h" - -// Interrupt is only disabled if there is no PWM device available -// Note: Adafruit Bluefruit nrf52 does not use this option -//#define NRF52_DISABLE_INT -#endif - -#if defined(ARDUINO_ARCH_NRF52840) -#if defined __has_include -#if __has_include() -#include -#endif -#endif -#endif - -/*! - @brief NeoPixel constructor when length, pin and pixel type are known - at compile-time. - @param n Number of NeoPixels in strand. - @param p Arduino pin number which will drive the NeoPixel data in. - @param t Pixel type -- add together NEO_* constants defined in - Adafruit_NeoPixel.h, for example NEO_GRB+NEO_KHZ800 for - NeoPixels expecting an 800 KHz (vs 400 KHz) data stream - with color bytes expressed in green, red, blue order per - pixel. - @return Adafruit_NeoPixel object. Call the begin() function before use. -*/ -Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, int16_t p, neoPixelType t) - : begun(false), brightness(0), pixels(NULL), endTime(0) { - updateType(t); - updateLength(n); - setPin(p); -#if defined(ARDUINO_ARCH_RP2040) - // Find a free SM on one of the PIO's - sm = pio_claim_unused_sm(pio, false); // don't panic - // Try pio1 if SM not found - if (sm < 0) { - pio = pio1; - sm = pio_claim_unused_sm(pio, true); // panic if no SM is free - } - init = true; -#endif -} - -/*! - @brief "Empty" NeoPixel constructor when length, pin and/or pixel type - are not known at compile-time, and must be initialized later with - updateType(), updateLength() and setPin(). - @return Adafruit_NeoPixel object. Call the begin() function before use. - @note This function is deprecated, here only for old projects that - may still be calling it. New projects should instead use the - 'new' keyword with the first constructor syntax (length, pin, - type). -*/ -Adafruit_NeoPixel::Adafruit_NeoPixel() - : -#if defined(NEO_KHZ400) - is800KHz(true), -#endif - begun(false), numLEDs(0), numBytes(0), pin(-1), brightness(0), - pixels(NULL), rOffset(1), gOffset(0), bOffset(2), wOffset(1), endTime(0) { -} - -/*! - @brief Deallocate Adafruit_NeoPixel object, set data pin back to INPUT. -*/ -Adafruit_NeoPixel::~Adafruit_NeoPixel() { - free(pixels); - if (pin >= 0) - pinMode(pin, INPUT); -} - -/*! - @brief Configure NeoPixel pin for output. -*/ -void Adafruit_NeoPixel::begin(void) { - if (pin >= 0) { - pinMode(pin, OUTPUT); - digitalWrite(pin, LOW); - } - begun = true; -} - -/*! - @brief Change the length of a previously-declared Adafruit_NeoPixel - strip object. Old data is deallocated and new data is cleared. - Pin number and pixel format are unchanged. - @param n New length of strip, in pixels. - @note This function is deprecated, here only for old projects that - may still be calling it. New projects should instead use the - 'new' keyword with the first constructor syntax (length, pin, - type). -*/ -void Adafruit_NeoPixel::updateLength(uint16_t n) { - free(pixels); // Free existing data (if any) - - // Allocate new data -- note: ALL PIXELS ARE CLEARED - numBytes = n * ((wOffset == rOffset) ? 3 : 4); - if ((pixels = (uint8_t *)malloc(numBytes))) { - memset(pixels, 0, numBytes); - numLEDs = n; - } else { - numLEDs = numBytes = 0; - } -} - -/*! - @brief Change the pixel format of a previously-declared - Adafruit_NeoPixel strip object. If format changes from one of - the RGB variants to an RGBW variant (or RGBW to RGB), the old - data will be deallocated and new data is cleared. Otherwise, - the old data will remain in RAM and is not reordered to the - new format, so it's advisable to follow up with clear(). - @param t Pixel type -- add together NEO_* constants defined in - Adafruit_NeoPixel.h, for example NEO_GRB+NEO_KHZ800 for - NeoPixels expecting an 800 KHz (vs 400 KHz) data stream - with color bytes expressed in green, red, blue order per - pixel. - @note This function is deprecated, here only for old projects that - may still be calling it. New projects should instead use the - 'new' keyword with the first constructor syntax - (length, pin, type). -*/ -void Adafruit_NeoPixel::updateType(neoPixelType t) { - bool oldThreeBytesPerPixel = (wOffset == rOffset); // false if RGBW - - wOffset = (t >> 6) & 0b11; // See notes in header file - rOffset = (t >> 4) & 0b11; // regarding R/G/B/W offsets - gOffset = (t >> 2) & 0b11; - bOffset = t & 0b11; -#if defined(NEO_KHZ400) - is800KHz = (t < 256); // 400 KHz flag is 1<<8 -#endif - - // If bytes-per-pixel has changed (and pixel data was previously - // allocated), re-allocate to new size. Will clear any data. - if (pixels) { - bool newThreeBytesPerPixel = (wOffset == rOffset); - if (newThreeBytesPerPixel != oldThreeBytesPerPixel) - updateLength(numLEDs); - } -} - -// RP2040 specific driver -#if defined(ARDUINO_ARCH_RP2040) -void Adafruit_NeoPixel::rp2040Init(uint8_t pin, bool is800KHz) -{ - uint offset = pio_add_program(pio, &ws2812_program); - - if (is800KHz) - { - // 800kHz, 8 bit transfers - ws2812_program_init(pio, sm, offset, pin, 800000, 8); - } - else - { - // 400kHz, 8 bit transfers - ws2812_program_init(pio, sm, offset, pin, 400000, 8); - } -} -// Not a user API -void Adafruit_NeoPixel::rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) -{ - if (this->init) - { - // On first pass through initialise the PIO - rp2040Init(pin, is800KHz); - this->init = false; - } - - while(numBytes--) - // Bits for transmission must be shifted to top 8 bits - pio_sm_put_blocking(pio, sm, ((uint32_t)*pixels++)<< 24); -} - -#endif - -#if defined(ESP8266) -// ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution -extern "C" IRAM_ATTR void espShow(uint8_t pin, uint8_t *pixels, - uint32_t numBytes, boolean is800KHz); -#elif defined(ESP32) -extern "C" void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, - boolean is800KHz); -#endif // ESP8266 - -#if defined(K210) -#define KENDRYTE_K210 1 -#endif - -#if defined(KENDRYTE_K210) -extern "C" void k210Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, - boolean is800KHz); -#endif // KENDRYTE_K210 -/*! - @brief Transmit pixel data in RAM to NeoPixels. - @note On most architectures, interrupts are temporarily disabled in - order to achieve the correct NeoPixel signal timing. This means - that the Arduino millis() and micros() functions, which require - interrupts, will lose small intervals of time whenever this - function is called (about 30 microseconds per RGB pixel, 40 for - RGBW pixels). There's no easy fix for this, but a few - specialized alternative or companion libraries exist that use - very device-specific peripherals to work around it. -*/ -void Adafruit_NeoPixel::show(void) { - - if (!pixels) - return; - - // Data latch = 300+ 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 (!canShow()) - ; - // endTime is a private member (rather than global var) so that multiple - // instances on different pins can be quickly issued in succession (each - // instance doesn't delay the next). - - // In order to make this code runtime-configurable to work with any pin, - // SBI/CBI instructions are eschewed in favor of full PORT writes via the - // OUT or ST instructions. It relies on two facts: that peripheral - // functions (such as PWM) take precedence on output pins, so our PORT- - // wide writes won't interfere, and that interrupts are globally disabled - // while data is being issued to the LEDs, so no other code will be - // accessing the PORT. The code takes an initial 'snapshot' of the PORT - // state, computes 'pin high' and 'pin low' values, and writes these back - // to the PORT register as needed. - - // NRF52 may use PWM + DMA (if available), may not need to disable interrupt - // ESP32 may not disable interrupts because espShow() uses RMT which tries to acquire locks -#if !(defined(NRF52) || defined(NRF52_SERIES) || defined(ESP32)) - noInterrupts(); // Need 100% focus on instruction timing -#endif - -#if defined(__AVR__) - // AVR MCUs -- ATmega & ATtiny (no XMEGA) --------------------------------- - - volatile uint16_t i = numBytes; // Loop counter - volatile uint8_t *ptr = pixels, // Pointer to next byte - b = *ptr++, // Current byte value - hi, // PORT w/output bit set high - lo; // PORT w/output bit set low - - // Hand-tuned assembly code issues data to the LED drivers at a specific - // rate. There's separate code for different CPU speeds (8, 12, 16 MHz) - // for both the WS2811 (400 KHz) and WS2812 (800 KHz) drivers. The - // datastream timing for the LED drivers allows a little wiggle room each - // way (listed in the datasheets), so the conditions for compiling each - // case are set up for a range of frequencies rather than just the exact - // 8, 12 or 16 MHz values, permitting use with some close-but-not-spot-on - // devices (e.g. 16.5 MHz DigiSpark). The ranges were arrived at based - // on the datasheet figures and have not been extensively tested outside - // the canonical 8/12/16 MHz speeds; there's no guarantee these will work - // close to the extremes (or possibly they could be pushed further). - // Keep in mind only one CPU speed case actually gets compiled; the - // resulting program isn't as massive as it might look from source here. - -// 8 MHz(ish) AVR --------------------------------------------------------- -#if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - - volatile uint8_t n1, n2 = 0; // First, next bits out - - // Squeezing an 800 KHz stream out of an 8 MHz chip requires code - // specific to each PORT register. - - // 10 instruction clocks per bit: HHxxxxxLLL - // OUT instructions: ^ ^ ^ (T=0,2,7) - - // PORTD OUTPUT ---------------------------------------------------- - -#if defined(PORTD) -#if defined(PORTB) || defined(PORTC) || defined(PORTF) - if (port == &PORTD) { -#endif // defined(PORTB/C/F) - - hi = PORTD | pinMask; - lo = PORTD & ~pinMask; - n1 = lo; - if (b & 0x80) - n1 = hi; - - // Dirty trick: RJMPs proceeding to the next instruction are used - // to delay two clock cycles in one instruction word (rather than - // using two NOPs). This was necessary in order to squeeze the - // loop down to exactly 64 words -- the maximum possible for a - // relative branch. - - asm volatile( - "headD:" - "\n\t" // Clk Pseudocode - // Bit 7: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n2] , %[lo]" - "\n\t" // 1 n2 = lo - "out %[port] , %[n1]" - "\n\t" // 1 PORT = n1 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 6" - "\n\t" // 1-2 if(b & 0x40) - "mov %[n2] , %[hi]" - "\n\t" // 0-1 n2 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 6: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n1] , %[lo]" - "\n\t" // 1 n1 = lo - "out %[port] , %[n2]" - "\n\t" // 1 PORT = n2 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 5" - "\n\t" // 1-2 if(b & 0x20) - "mov %[n1] , %[hi]" - "\n\t" // 0-1 n1 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 5: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n2] , %[lo]" - "\n\t" // 1 n2 = lo - "out %[port] , %[n1]" - "\n\t" // 1 PORT = n1 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 4" - "\n\t" // 1-2 if(b & 0x10) - "mov %[n2] , %[hi]" - "\n\t" // 0-1 n2 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 4: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n1] , %[lo]" - "\n\t" // 1 n1 = lo - "out %[port] , %[n2]" - "\n\t" // 1 PORT = n2 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 3" - "\n\t" // 1-2 if(b & 0x08) - "mov %[n1] , %[hi]" - "\n\t" // 0-1 n1 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 3: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n2] , %[lo]" - "\n\t" // 1 n2 = lo - "out %[port] , %[n1]" - "\n\t" // 1 PORT = n1 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 2" - "\n\t" // 1-2 if(b & 0x04) - "mov %[n2] , %[hi]" - "\n\t" // 0-1 n2 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 2: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n1] , %[lo]" - "\n\t" // 1 n1 = lo - "out %[port] , %[n2]" - "\n\t" // 1 PORT = n2 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 1" - "\n\t" // 1-2 if(b & 0x02) - "mov %[n1] , %[hi]" - "\n\t" // 0-1 n1 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 1: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n2] , %[lo]" - "\n\t" // 1 n2 = lo - "out %[port] , %[n1]" - "\n\t" // 1 PORT = n1 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 0" - "\n\t" // 1-2 if(b & 0x01) - "mov %[n2] , %[hi]" - "\n\t" // 0-1 n2 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "sbiw %[count], 1" - "\n\t" // 2 i-- (don't act on Z flag yet) - // Bit 0: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n1] , %[lo]" - "\n\t" // 1 n1 = lo - "out %[port] , %[n2]" - "\n\t" // 1 PORT = n2 - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 0x80) - "mov %[n1] , %[hi]" - "\n\t" // 0-1 n1 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "brne headD" - "\n" // 2 while(i) (Z flag set above) - : [byte] "+r"(b), [n1] "+r"(n1), [n2] "+r"(n2), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTD)), [ptr] "e"(ptr), [hi] "r"(hi), - [lo] "r"(lo)); - -#if defined(PORTB) || defined(PORTC) || defined(PORTF) - } else // other PORT(s) -#endif // defined(PORTB/C/F) -#endif // defined(PORTD) - - // PORTB OUTPUT ---------------------------------------------------- - -#if defined(PORTB) -#if defined(PORTD) || defined(PORTC) || defined(PORTF) - if (port == &PORTB) { -#endif // defined(PORTD/C/F) - - // Same as above, just switched to PORTB and stripped of comments. - hi = PORTB | pinMask; - lo = PORTB & ~pinMask; - n1 = lo; - if (b & 0x80) - n1 = hi; - - asm volatile( - "headB:" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 6" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 5" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 4" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 3" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 2" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 1" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 0" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "brne headB" - "\n" - : [byte] "+r"(b), [n1] "+r"(n1), [n2] "+r"(n2), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTB)), [ptr] "e"(ptr), [hi] "r"(hi), - [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTC) || defined(PORTF) - } -#endif -#if defined(PORTC) || defined(PORTF) - else -#endif // defined(PORTC/F) -#endif // defined(PORTB) - - // PORTC OUTPUT ---------------------------------------------------- - -#if defined(PORTC) -#if defined(PORTD) || defined(PORTB) || defined(PORTF) - if (port == &PORTC) { -#endif // defined(PORTD/B/F) - - // Same as above, just switched to PORTC and stripped of comments. - hi = PORTC | pinMask; - lo = PORTC & ~pinMask; - n1 = lo; - if (b & 0x80) - n1 = hi; - - asm volatile( - "headC:" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 6" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 5" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 4" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 3" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 2" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 1" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 0" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "brne headC" - "\n" - : [byte] "+r"(b), [n1] "+r"(n1), [n2] "+r"(n2), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTC)), [ptr] "e"(ptr), [hi] "r"(hi), - [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTB) || defined(PORTF) - } -#endif // defined(PORTD/B/F) -#if defined(PORTF) - else -#endif -#endif // defined(PORTC) - - // PORTF OUTPUT ---------------------------------------------------- - -#if defined(PORTF) -#if defined(PORTD) || defined(PORTB) || defined(PORTC) - if (port == &PORTF) { -#endif // defined(PORTD/B/C) - - hi = PORTF | pinMask; - lo = PORTF & ~pinMask; - n1 = lo; - if (b & 0x80) - n1 = hi; - - asm volatile( - "headF:" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 6" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 5" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 4" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 3" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 2" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 1" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 0" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "brne headF" - "\n" - : [byte] "+r"(b), [n1] "+r"(n1), [n2] "+r"(n2), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTF)), [ptr] "e"(ptr), [hi] "r"(hi), - [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTB) || defined(PORTC) - } -#endif // defined(PORTD/B/C) -#endif // defined(PORTF) - -#if defined(NEO_KHZ400) - } else { // end 800 KHz, do 400 KHz - - // Timing is more relaxed; unrolling the inner loop for each bit is - // not necessary. Still using the peculiar RJMPs as 2X NOPs, not out - // of need but just to trim the code size down a little. - // This 400-KHz-datastream-on-8-MHz-CPU code is not quite identical - // to the 800-on-16 code later -- the hi/lo timing between WS2811 and - // WS2812 is not simply a 2:1 scale! - - // 20 inst. clocks per bit: HHHHxxxxxxLLLLLLLLLL - // ST instructions: ^ ^ ^ (T=0,4,10) - - volatile uint8_t next, bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile("head20:" - "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" - "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 128) - "mov %[next], %[hi]" - "\n\t" // 0-1 next = hi (T = 4) - "st %a[port], %[next]" - "\n\t" // 2 PORT = next (T = 6) - "mov %[next] , %[lo]" - "\n\t" // 1 next = lo (T = 7) - "dec %[bit]" - "\n\t" // 1 bit-- (T = 8) - "breq nextbyte20" - "\n\t" // 1-2 if(bit == 0) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 10) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 12) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 14) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 16) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 18) - "rjmp head20" - "\n\t" // 2 -> head20 (next bit out) - "nextbyte20:" - "\n\t" // (T = 10) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 12) - "nop" - "\n\t" // 1 nop (T = 13) - "ldi %[bit] , 8" - "\n\t" // 1 bit = 8 (T = 14) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 16) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 18) - "brne head20" - "\n" // 2 if(i != 0) -> (next byte) - : [port] "+e"(port), [byte] "+r"(b), [bit] "+r"(bit), - [next] "+r"(next), [count] "+w"(i) - : [hi] "r"(hi), [lo] "r"(lo), [ptr] "e"(ptr)); - } -#endif // NEO_KHZ400 - -// 12 MHz(ish) AVR -------------------------------------------------------- -#elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - - // In the 12 MHz case, an optimized 800 KHz datastream (no dead time - // between bytes) requires a PORT-specific loop similar to the 8 MHz - // code (but a little more relaxed in this case). - - // 15 instruction clocks per bit: HHHHxxxxxxLLLLL - // OUT instructions: ^ ^ ^ (T=0,4,10) - - volatile uint8_t next; - - // PORTD OUTPUT ---------------------------------------------------- - -#if defined(PORTD) -#if defined(PORTB) || defined(PORTC) || defined(PORTF) - if (port == &PORTD) { -#endif // defined(PORTB/C/F) - - hi = PORTD | pinMask; - lo = PORTD & ~pinMask; - next = lo; - if (b & 0x80) - next = hi; - - // Don't "optimize" the OUT calls into the bitTime subroutine; - // we're exploiting the RCALL and RET as 3- and 4-cycle NOPs! - asm volatile("headD:" - "\n\t" // (T = 0) - "out %[port], %[hi]" - "\n\t" // (T = 1) - "rcall bitTimeD" - "\n\t" // Bit 7 (T = 15) - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 6 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 5 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 4 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 3 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 2 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 1 - // Bit 0: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi (T = 1) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 3) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 5) - "out %[port] , %[next]" - "\n\t" // 1 PORT = next (T = 6) - "mov %[next] , %[lo]" - "\n\t" // 1 next = lo (T = 7) - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 0x80) (T = 8) - "mov %[next] , %[hi]" - "\n\t" // 0-1 next = hi (T = 9) - "nop" - "\n\t" // 1 (T = 10) - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo (T = 11) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 13) - "brne headD" - "\n\t" // 2 if(i != 0) -> (next byte) - "rjmp doneD" - "\n\t" - "bitTimeD:" - "\n\t" // nop nop nop (T = 4) - "out %[port], %[next]" - "\n\t" // 1 PORT = next (T = 5) - "mov %[next], %[lo]" - "\n\t" // 1 next = lo (T = 6) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 7) - "sbrc %[byte], 7" - "\n\t" // 1-2 if(b & 0x80) (T = 8) - "mov %[next], %[hi]" - "\n\t" // 0-1 next = hi (T = 9) - "nop" - "\n\t" // 1 (T = 10) - "out %[port], %[lo]" - "\n\t" // 1 PORT = lo (T = 11) - "ret" - "\n\t" // 4 nop nop nop nop (T = 15) - "doneD:" - "\n" - : [byte] "+r"(b), [next] "+r"(next), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTD)), [ptr] "e"(ptr), - [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(PORTB) || defined(PORTC) || defined(PORTF) - } else // other PORT(s) -#endif // defined(PORTB/C/F) -#endif // defined(PORTD) - - // PORTB OUTPUT ---------------------------------------------------- - -#if defined(PORTB) -#if defined(PORTD) || defined(PORTC) || defined(PORTF) - if (port == &PORTB) { -#endif // defined(PORTD/C/F) - - hi = PORTB | pinMask; - lo = PORTB & ~pinMask; - next = lo; - if (b & 0x80) - next = hi; - - // Same as above, just set for PORTB & stripped of comments - asm volatile("headB:" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "rjmp .+0" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "out %[port] , %[next]" - "\n\t" - "mov %[next] , %[lo]" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[next] , %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "brne headB" - "\n\t" - "rjmp doneB" - "\n\t" - "bitTimeB:" - "\n\t" - "out %[port], %[next]" - "\n\t" - "mov %[next], %[lo]" - "\n\t" - "rol %[byte]" - "\n\t" - "sbrc %[byte], 7" - "\n\t" - "mov %[next], %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port], %[lo]" - "\n\t" - "ret" - "\n\t" - "doneB:" - "\n" - : [byte] "+r"(b), [next] "+r"(next), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTB)), [ptr] "e"(ptr), - [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTC) || defined(PORTF) - } -#endif -#if defined(PORTC) || defined(PORTF) - else -#endif // defined(PORTC/F) -#endif // defined(PORTB) - - // PORTC OUTPUT ---------------------------------------------------- - -#if defined(PORTC) -#if defined(PORTD) || defined(PORTB) || defined(PORTF) - if (port == &PORTC) { -#endif // defined(PORTD/B/F) - - hi = PORTC | pinMask; - lo = PORTC & ~pinMask; - next = lo; - if (b & 0x80) - next = hi; - - // Same as above, just set for PORTC & stripped of comments - asm volatile("headC:" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "rjmp .+0" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "out %[port] , %[next]" - "\n\t" - "mov %[next] , %[lo]" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[next] , %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "brne headC" - "\n\t" - "rjmp doneC" - "\n\t" - "bitTimeC:" - "\n\t" - "out %[port], %[next]" - "\n\t" - "mov %[next], %[lo]" - "\n\t" - "rol %[byte]" - "\n\t" - "sbrc %[byte], 7" - "\n\t" - "mov %[next], %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port], %[lo]" - "\n\t" - "ret" - "\n\t" - "doneC:" - "\n" - : [byte] "+r"(b), [next] "+r"(next), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTC)), [ptr] "e"(ptr), - [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTB) || defined(PORTF) - } -#endif // defined(PORTD/B/F) -#if defined(PORTF) - else -#endif -#endif // defined(PORTC) - - // PORTF OUTPUT ---------------------------------------------------- - -#if defined(PORTF) -#if defined(PORTD) || defined(PORTB) || defined(PORTC) - if (port == &PORTF) { -#endif // defined(PORTD/B/C) - - hi = PORTF | pinMask; - lo = PORTF & ~pinMask; - next = lo; - if (b & 0x80) - next = hi; - - // Same as above, just set for PORTF & stripped of comments - asm volatile("headF:" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "rjmp .+0" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "out %[port] , %[next]" - "\n\t" - "mov %[next] , %[lo]" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[next] , %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "brne headF" - "\n\t" - "rjmp doneC" - "\n\t" - "bitTimeC:" - "\n\t" - "out %[port], %[next]" - "\n\t" - "mov %[next], %[lo]" - "\n\t" - "rol %[byte]" - "\n\t" - "sbrc %[byte], 7" - "\n\t" - "mov %[next], %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port], %[lo]" - "\n\t" - "ret" - "\n\t" - "doneC:" - "\n" - : [byte] "+r"(b), [next] "+r"(next), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTF)), [ptr] "e"(ptr), - [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTB) || defined(PORTC) - } -#endif // defined(PORTD/B/C) -#endif // defined(PORTF) - -#if defined(NEO_KHZ400) - } else { // 400 KHz - - // 30 instruction clocks per bit: HHHHHHxxxxxxxxxLLLLLLLLLLLLLLL - // ST instructions: ^ ^ ^ (T=0,6,15) - - volatile uint8_t next, bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile("head30:" - "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" - "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 128) - "mov %[next], %[hi]" - "\n\t" // 0-1 next = hi (T = 4) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 6) - "st %a[port], %[next]" - "\n\t" // 2 PORT = next (T = 8) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 10) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 12) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 14) - "nop" - "\n\t" // 1 nop (T = 15) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 17) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 19) - "dec %[bit]" - "\n\t" // 1 bit-- (T = 20) - "breq nextbyte30" - "\n\t" // 1-2 if(bit == 0) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 22) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 24) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 26) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 28) - "rjmp head30" - "\n\t" // 2 -> head30 (next bit out) - "nextbyte30:" - "\n\t" // (T = 22) - "nop" - "\n\t" // 1 nop (T = 23) - "ldi %[bit] , 8" - "\n\t" // 1 bit = 8 (T = 24) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 26) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 28) - "brne head30" - "\n" // 1-2 if(i != 0) -> (next byte) - : [port] "+e"(port), [byte] "+r"(b), [bit] "+r"(bit), - [next] "+r"(next), [count] "+w"(i) - : [hi] "r"(hi), [lo] "r"(lo), [ptr] "e"(ptr)); - } -#endif // NEO_KHZ400 - -// 16 MHz(ish) AVR -------------------------------------------------------- -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - - // WS2811 and WS2812 have different hi/lo duty cycles; this is - // similar but NOT an exact copy of the prior 400-on-8 code. - - // 20 inst. clocks per bit: HHHHHxxxxxxxxLLLLLLL - // ST instructions: ^ ^ ^ (T=0,5,13) - - volatile uint8_t next, bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile("head20:" - "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" - "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte], 7" - "\n\t" // 1-2 if(b & 128) - "mov %[next], %[hi]" - "\n\t" // 0-1 next = hi (T = 4) - "dec %[bit]" - "\n\t" // 1 bit-- (T = 5) - "st %a[port], %[next]" - "\n\t" // 2 PORT = next (T = 7) - "mov %[next] , %[lo]" - "\n\t" // 1 next = lo (T = 8) - "breq nextbyte20" - "\n\t" // 1-2 if(bit == 0) (from dec above) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 10) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 12) - "nop" - "\n\t" // 1 nop (T = 13) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 15) - "nop" - "\n\t" // 1 nop (T = 16) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 18) - "rjmp head20" - "\n\t" // 2 -> head20 (next bit out) - "nextbyte20:" - "\n\t" // (T = 10) - "ldi %[bit] , 8" - "\n\t" // 1 bit = 8 (T = 11) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 13) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 15) - "nop" - "\n\t" // 1 nop (T = 16) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 18) - "brne head20" - "\n" // 2 if(i != 0) -> (next byte) - : [port] "+e"(port), [byte] "+r"(b), [bit] "+r"(bit), - [next] "+r"(next), [count] "+w"(i) - : [ptr] "e"(ptr), [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(NEO_KHZ400) - } else { // 400 KHz - - // The 400 KHz clock on 16 MHz MCU is the most 'relaxed' version. - - // 40 inst. clocks per bit: HHHHHHHHxxxxxxxxxxxxLLLLLLLLLLLLLLLLLLLL - // ST instructions: ^ ^ ^ (T=0,8,20) - - volatile uint8_t next, bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile("head40:" - "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" - "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 128) - "mov %[next] , %[hi]" - "\n\t" // 0-1 next = hi (T = 4) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 6) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 8) - "st %a[port], %[next]" - "\n\t" // 2 PORT = next (T = 10) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 12) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 14) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 16) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 18) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 20) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 22) - "nop" - "\n\t" // 1 nop (T = 23) - "mov %[next] , %[lo]" - "\n\t" // 1 next = lo (T = 24) - "dec %[bit]" - "\n\t" // 1 bit-- (T = 25) - "breq nextbyte40" - "\n\t" // 1-2 if(bit == 0) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 27) - "nop" - "\n\t" // 1 nop (T = 28) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 30) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 32) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 34) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 36) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 38) - "rjmp head40" - "\n\t" // 2 -> head40 (next bit out) - "nextbyte40:" - "\n\t" // (T = 27) - "ldi %[bit] , 8" - "\n\t" // 1 bit = 8 (T = 28) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 30) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 32) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 34) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 36) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 38) - "brne head40" - "\n" // 1-2 if(i != 0) -> (next byte) - : [port] "+e"(port), [byte] "+r"(b), [bit] "+r"(bit), - [next] "+r"(next), [count] "+w"(i) - : [ptr] "e"(ptr), [hi] "r"(hi), [lo] "r"(lo)); - } -#endif // NEO_KHZ400 - -#else -#error "CPU SPEED NOT SUPPORTED" -#endif // end F_CPU ifdefs on __AVR__ - - // END AVR ---------------------------------------------------------------- - -#elif defined(__arm__) - - // ARM MCUs -- Teensy 3.0, 3.1, LC, Arduino Due, RP2040 ------------------- - -#if defined(ARDUINO_ARCH_RP2040) - // Use PIO - rp2040Show(pin, pixels, numBytes, is800KHz); - -#elif defined(TEENSYDUINO) && \ - defined(KINETISK) // Teensy 3.0, 3.1, 3.2, 3.5, 3.6 -#define CYCLES_800_T0H (F_CPU / 4000000) -#define CYCLES_800_T1H (F_CPU / 1250000) -#define CYCLES_800 (F_CPU / 800000) -#define CYCLES_400_T0H (F_CPU / 2000000) -#define CYCLES_400_T1H (F_CPU / 833333) -#define CYCLES_400 (F_CPU / 400000) - - uint8_t *p = pixels, *end = p + numBytes, pix, mask; - volatile uint8_t *set = portSetRegister(pin), *clr = portClearRegister(pin); - uint32_t cyc; - - ARM_DEMCR |= ARM_DEMCR_TRCENA; - ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - cyc = ARM_DWT_CYCCNT + CYCLES_800; - while (p < end) { - pix = *p++; - for (mask = 0x80; mask; mask >>= 1) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800) - ; - cyc = ARM_DWT_CYCCNT; - *set = 1; - if (pix & mask) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T1H) - ; - } else { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T0H) - ; - } - *clr = 1; - } - } - while (ARM_DWT_CYCCNT - cyc < CYCLES_800) - ; -#if defined(NEO_KHZ400) - } else { // 400 kHz bitstream - cyc = ARM_DWT_CYCCNT + CYCLES_400; - while (p < end) { - pix = *p++; - for (mask = 0x80; mask; mask >>= 1) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400) - ; - cyc = ARM_DWT_CYCCNT; - *set = 1; - if (pix & mask) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T1H) - ; - } else { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T0H) - ; - } - *clr = 1; - } - } - while (ARM_DWT_CYCCNT - cyc < CYCLES_400) - ; - } -#endif // NEO_KHZ400 - -#elif defined(TEENSYDUINO) && (defined(__IMXRT1052__) || defined(__IMXRT1062__)) -#define CYCLES_800_T0H (F_CPU_ACTUAL / 4000000) -#define CYCLES_800_T1H (F_CPU_ACTUAL / 1250000) -#define CYCLES_800 (F_CPU_ACTUAL / 800000) -#define CYCLES_400_T0H (F_CPU_ACTUAL / 2000000) -#define CYCLES_400_T1H (F_CPU_ACTUAL / 833333) -#define CYCLES_400 (F_CPU_ACTUAL / 400000) - - uint8_t *p = pixels, *end = p + numBytes, pix, mask; - volatile uint32_t *set = portSetRegister(pin), *clr = portClearRegister(pin); - uint32_t cyc, msk = digitalPinToBitMask(pin); - - ARM_DEMCR |= ARM_DEMCR_TRCENA; - ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - cyc = ARM_DWT_CYCCNT + CYCLES_800; - while (p < end) { - pix = *p++; - for (mask = 0x80; mask; mask >>= 1) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800) - ; - cyc = ARM_DWT_CYCCNT; - *set = msk; - if (pix & mask) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T1H) - ; - } else { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T0H) - ; - } - *clr = msk; - } - } - while (ARM_DWT_CYCCNT - cyc < CYCLES_800) - ; -#if defined(NEO_KHZ400) - } else { // 400 kHz bitstream - cyc = ARM_DWT_CYCCNT + CYCLES_400; - while (p < end) { - pix = *p++; - for (mask = 0x80; mask; mask >>= 1) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400) - ; - cyc = ARM_DWT_CYCCNT; - *set = msk; - if (pix & mask) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T1H) - ; - } else { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T0H) - ; - } - *clr = msk; - } - } - while (ARM_DWT_CYCCNT - cyc < CYCLES_400) - ; - } -#endif // NEO_KHZ400 - -#elif defined(TEENSYDUINO) && defined(__MKL26Z64__) // Teensy-LC - -#if F_CPU == 48000000 - uint8_t *p = pixels, pix, count, dly, bitmask = digitalPinToBitMask(pin); - volatile uint8_t *reg = portSetRegister(pin); - uint32_t num = numBytes; - asm volatile("L%=_begin:" - "\n\t" - "ldrb %[pix], [%[p], #0]" - "\n\t" - "lsl %[pix], #24" - "\n\t" - "movs %[count], #7" - "\n\t" - "L%=_loop:" - "\n\t" - "lsl %[pix], #1" - "\n\t" - "bcs L%=_loop_one" - "\n\t" - "L%=_loop_zero:" - "\n\t" - "strb %[bitmask], [%[reg], #0]" - "\n\t" - "movs %[dly], #4" - "\n\t" - "L%=_loop_delay_T0H:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_loop_delay_T0H" - "\n\t" - "strb %[bitmask], [%[reg], #4]" - "\n\t" - "movs %[dly], #13" - "\n\t" - "L%=_loop_delay_T0L:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_loop_delay_T0L" - "\n\t" - "b L%=_next" - "\n\t" - "L%=_loop_one:" - "\n\t" - "strb %[bitmask], [%[reg], #0]" - "\n\t" - "movs %[dly], #13" - "\n\t" - "L%=_loop_delay_T1H:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_loop_delay_T1H" - "\n\t" - "strb %[bitmask], [%[reg], #4]" - "\n\t" - "movs %[dly], #4" - "\n\t" - "L%=_loop_delay_T1L:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_loop_delay_T1L" - "\n\t" - "nop" - "\n\t" - "L%=_next:" - "\n\t" - "sub %[count], #1" - "\n\t" - "bne L%=_loop" - "\n\t" - "lsl %[pix], #1" - "\n\t" - "bcs L%=_last_one" - "\n\t" - "L%=_last_zero:" - "\n\t" - "strb %[bitmask], [%[reg], #0]" - "\n\t" - "movs %[dly], #4" - "\n\t" - "L%=_last_delay_T0H:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_last_delay_T0H" - "\n\t" - "strb %[bitmask], [%[reg], #4]" - "\n\t" - "movs %[dly], #10" - "\n\t" - "L%=_last_delay_T0L:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_last_delay_T0L" - "\n\t" - "b L%=_repeat" - "\n\t" - "L%=_last_one:" - "\n\t" - "strb %[bitmask], [%[reg], #0]" - "\n\t" - "movs %[dly], #13" - "\n\t" - "L%=_last_delay_T1H:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_last_delay_T1H" - "\n\t" - "strb %[bitmask], [%[reg], #4]" - "\n\t" - "movs %[dly], #1" - "\n\t" - "L%=_last_delay_T1L:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_last_delay_T1L" - "\n\t" - "nop" - "\n\t" - "L%=_repeat:" - "\n\t" - "add %[p], #1" - "\n\t" - "sub %[num], #1" - "\n\t" - "bne L%=_begin" - "\n\t" - "L%=_done:" - "\n\t" - : [p] "+r"(p), [pix] "=&r"(pix), [count] "=&r"(count), - [dly] "=&r"(dly), [num] "+r"(num) - : [bitmask] "r"(bitmask), [reg] "r"(reg)); -#else -#error "Sorry, only 48 MHz is supported, please set Tools > CPU Speed to 48 MHz" -#endif // F_CPU == 48000000 - - // Begin of support for nRF52 based boards ------------------------- - -#elif defined(NRF52) || defined(NRF52_SERIES) -// [[[Begin of the Neopixel NRF52 EasyDMA implementation -// by the Hackerspace San Salvador]]] -// This technique uses the PWM peripheral on the NRF52. The PWM uses the -// EasyDMA feature included on the chip. This technique loads the duty -// cycle configuration for each cycle when the PWM is enabled. For this -// to work we need to store a 16 bit configuration for each bit of the -// RGB(W) values in the pixel buffer. -// Comparator values for the PWM were hand picked and are guaranteed to -// be 100% organic to preserve freshness and high accuracy. Current -// parameters are: -// * PWM Clock: 16Mhz -// * Minimum step time: 62.5ns -// * Time for zero in high (T0H): 0.31ms -// * Time for one in high (T1H): 0.75ms -// * Cycle time: 1.25us -// * Frequency: 800Khz -// For 400Khz we just double the calculated times. -// ---------- BEGIN Constants for the EasyDMA implementation ----------- -// The PWM starts the duty cycle in LOW. To start with HIGH we -// need to set the 15th bit on each register. - -// WS2812 (rev A) timing is 0.35 and 0.7us -//#define MAGIC_T0H 5UL | (0x8000) // 0.3125us -//#define MAGIC_T1H 12UL | (0x8000) // 0.75us - -// WS2812B (rev B) timing is 0.4 and 0.8 us -#define MAGIC_T0H 6UL | (0x8000) // 0.375us -#define MAGIC_T1H 13UL | (0x8000) // 0.8125us - -// WS2811 (400 khz) timing is 0.5 and 1.2 -#define MAGIC_T0H_400KHz 8UL | (0x8000) // 0.5us -#define MAGIC_T1H_400KHz 19UL | (0x8000) // 1.1875us - -// For 400Khz, we double value of CTOPVAL -#define CTOPVAL 20UL // 1.25us -#define CTOPVAL_400KHz 40UL // 2.5us - -// ---------- END Constants for the EasyDMA implementation ------------- -// -// If there is no device available an alternative cycle-counter -// implementation is tried. -// The nRF52 runs with a fixed clock of 64Mhz. The alternative -// implementation is the same as the one used for the Teensy 3.0/1/2 but -// with the Nordic SDK HAL & registers syntax. -// The number of cycles was hand picked and is guaranteed to be 100% -// organic to preserve freshness and high accuracy. -// ---------- BEGIN Constants for cycle counter implementation --------- -#define CYCLES_800_T0H 18 // ~0.36 uS -#define CYCLES_800_T1H 41 // ~0.76 uS -#define CYCLES_800 71 // ~1.25 uS - -#define CYCLES_400_T0H 26 // ~0.50 uS -#define CYCLES_400_T1H 70 // ~1.26 uS -#define CYCLES_400 156 // ~2.50 uS - // ---------- END of Constants for cycle counter implementation -------- - - // To support both the SoftDevice + Neopixels we use the EasyDMA - // feature from the NRF25. However this technique implies to - // generate a pattern and store it on the memory. The actual - // memory used in bytes corresponds to the following formula: - // totalMem = numBytes*8*2+(2*2) - // The two additional bytes at the end are needed to reset the - // sequence. - // - // If there is not enough memory, we will fall back to cycle counter - // using DWT - uint32_t pattern_size = - numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t); - uint16_t *pixels_pattern = NULL; - - NRF_PWM_Type *pwm = NULL; - - // Try to find a free PWM device, which is not enabled - // and has no connected pins - NRF_PWM_Type *PWM[] = { - NRF_PWM0, - NRF_PWM1, - NRF_PWM2 -#if defined(NRF_PWM3) - , - NRF_PWM3 -#endif - }; - - for (unsigned int device = 0; device < (sizeof(PWM) / sizeof(PWM[0])); - device++) { - if ((PWM[device]->ENABLE == 0) && - (PWM[device]->PSEL.OUT[0] & PWM_PSEL_OUT_CONNECT_Msk) && - (PWM[device]->PSEL.OUT[1] & PWM_PSEL_OUT_CONNECT_Msk) && - (PWM[device]->PSEL.OUT[2] & PWM_PSEL_OUT_CONNECT_Msk) && - (PWM[device]->PSEL.OUT[3] & PWM_PSEL_OUT_CONNECT_Msk)) { - pwm = PWM[device]; - break; - } - } - - // only malloc if there is PWM device available - if (pwm != NULL) { -#if defined(ARDUINO_NRF52_ADAFRUIT) // use thread-safe malloc - pixels_pattern = (uint16_t *)rtos_malloc(pattern_size); -#else - pixels_pattern = (uint16_t *)malloc(pattern_size); -#endif - } - - // Use the identified device to choose the implementation - // If a PWM device is available use DMA - if ((pixels_pattern != NULL) && (pwm != NULL)) { - uint16_t pos = 0; // bit position - - for (uint16_t n = 0; n < numBytes; n++) { - uint8_t pix = pixels[n]; - - for (uint8_t mask = 0x80; mask > 0; mask >>= 1) { -#if defined(NEO_KHZ400) - if (!is800KHz) { - pixels_pattern[pos] = - (pix & mask) ? MAGIC_T1H_400KHz : MAGIC_T0H_400KHz; - } else -#endif - { - pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H; - } - - pos++; - } - } - - // Zero padding to indicate the end of que sequence - pixels_pattern[pos++] = 0 | (0x8000); // Seq end - pixels_pattern[pos++] = 0 | (0x8000); // Seq end - - // Set the wave mode to count UP - pwm->MODE = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos); - - // Set the PWM to use the 16MHz clock - pwm->PRESCALER = - (PWM_PRESCALER_PRESCALER_DIV_1 << PWM_PRESCALER_PRESCALER_Pos); - - // Setting of the maximum count - // but keeping it on 16Mhz allows for more granularity just - // in case someone wants to do more fine-tuning of the timing. -#if defined(NEO_KHZ400) - if (!is800KHz) { - pwm->COUNTERTOP = (CTOPVAL_400KHz << PWM_COUNTERTOP_COUNTERTOP_Pos); - } else -#endif - { - pwm->COUNTERTOP = (CTOPVAL << PWM_COUNTERTOP_COUNTERTOP_Pos); - } - - // Disable loops, we want the sequence to repeat only once - pwm->LOOP = (PWM_LOOP_CNT_Disabled << PWM_LOOP_CNT_Pos); - - // On the "Common" setting the PWM uses the same pattern for the - // for supported sequences. The pattern is stored on half-word - // of 16bits - pwm->DECODER = (PWM_DECODER_LOAD_Common << PWM_DECODER_LOAD_Pos) | - (PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos); - - // Pointer to the memory storing the patter - pwm->SEQ[0].PTR = (uint32_t)(pixels_pattern) << PWM_SEQ_PTR_PTR_Pos; - - // Calculation of the number of steps loaded from memory. - pwm->SEQ[0].CNT = (pattern_size / sizeof(uint16_t)) << PWM_SEQ_CNT_CNT_Pos; - - // The following settings are ignored with the current config. - pwm->SEQ[0].REFRESH = 0; - pwm->SEQ[0].ENDDELAY = 0; - - // The Neopixel implementation is a blocking algorithm. DMA - // allows for non-blocking operation. To "simulate" a blocking - // operation we enable the interruption for the end of sequence - // and block the execution thread until the event flag is set by - // the peripheral. - // pwm->INTEN |= (PWM_INTEN_SEQEND0_Enabled<PSEL.OUT[0] = g_APinDescription[pin].name; -#else - pwm->PSEL.OUT[0] = g_ADigitalPinMap[pin]; -#endif - - // Enable the PWM - pwm->ENABLE = 1; - - // After all of this and many hours of reading the documentation - // we are ready to start the sequence... - pwm->EVENTS_SEQEND[0] = 0; - pwm->TASKS_SEQSTART[0] = 1; - - // But we have to wait for the flag to be set. - while (!pwm->EVENTS_SEQEND[0]) { -#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_NRF52840) - yield(); -#endif - } - - // Before leave we clear the flag for the event. - pwm->EVENTS_SEQEND[0] = 0; - - // We need to disable the device and disconnect - // all the outputs before leave or the device will not - // be selected on the next call. - // TODO: Check if disabling the device causes performance issues. - pwm->ENABLE = 0; - - pwm->PSEL.OUT[0] = 0xFFFFFFFFUL; - -#if defined(ARDUINO_NRF52_ADAFRUIT) // use thread-safe free - rtos_free(pixels_pattern); -#else - free(pixels_pattern); -#endif - } // End of DMA implementation - // --------------------------------------------------------------------- - else { -#ifndef ARDUINO_ARCH_NRF52840 -// Fall back to DWT -#if defined(ARDUINO_NRF52_ADAFRUIT) - // Bluefruit Feather 52 uses freeRTOS - // Critical Section is used since it does not block SoftDevice execution - taskENTER_CRITICAL(); -#elif defined(NRF52_DISABLE_INT) - // If you are using the Bluetooth SoftDevice we advise you to not disable - // the interrupts. Disabling the interrupts even for short periods of time - // causes the SoftDevice to stop working. - // Disable the interrupts only in cases where you need high performance for - // the LEDs and if you are not using the EasyDMA feature. - __disable_irq(); -#endif - - NRF_GPIO_Type *nrf_port = (NRF_GPIO_Type *)digitalPinToPort(pin); - uint32_t pinMask = digitalPinToBitMask(pin); - - uint32_t CYCLES_X00 = CYCLES_800; - uint32_t CYCLES_X00_T1H = CYCLES_800_T1H; - uint32_t CYCLES_X00_T0H = CYCLES_800_T0H; - -#if defined(NEO_KHZ400) - if (!is800KHz) { - CYCLES_X00 = CYCLES_400; - CYCLES_X00_T1H = CYCLES_400_T1H; - CYCLES_X00_T0H = CYCLES_400_T0H; - } -#endif - - // Enable DWT in debug core - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; - - // Tries to re-send the frame if is interrupted by the SoftDevice. - while (1) { - uint8_t *p = pixels; - - uint32_t cycStart = DWT->CYCCNT; - uint32_t cyc = 0; - - for (uint16_t n = 0; n < numBytes; n++) { - uint8_t pix = *p++; - - for (uint8_t mask = 0x80; mask; mask >>= 1) { - while (DWT->CYCCNT - cyc < CYCLES_X00) - ; - cyc = DWT->CYCCNT; - - nrf_port->OUTSET |= pinMask; - - if (pix & mask) { - while (DWT->CYCCNT - cyc < CYCLES_X00_T1H) - ; - } else { - while (DWT->CYCCNT - cyc < CYCLES_X00_T0H) - ; - } - - nrf_port->OUTCLR |= pinMask; - } - } - while (DWT->CYCCNT - cyc < CYCLES_X00) - ; - - // If total time longer than 25%, resend the whole data. - // Since we are likely to be interrupted by SoftDevice - if ((DWT->CYCCNT - cycStart) < (8 * numBytes * ((CYCLES_X00 * 5) / 4))) { - break; - } - - // re-send need 300us delay - delayMicroseconds(300); - } - -// Enable interrupts again -#if defined(ARDUINO_NRF52_ADAFRUIT) - taskEXIT_CRITICAL(); -#elif defined(NRF52_DISABLE_INT) - __enable_irq(); -#endif -#endif - } - // END of NRF52 implementation - -#elif defined(__SAMD21E17A__) || defined(__SAMD21G18A__) || \ - defined(__SAMD21E18A__) || defined(__SAMD21J18A__) || \ - defined (__SAMD11C14A__) - // Arduino Zero, Gemma/Trinket M0, SODAQ Autonomo - // and others - // Tried this with a timer/counter, couldn't quite get adequate - // resolution. So yay, you get a load of goofball NOPs... - - uint8_t *ptr, *end, p, bitMask, portNum; - uint32_t pinMask; - - portNum = g_APinDescription[pin].ulPort; - pinMask = 1ul << g_APinDescription[pin].ulPin; - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - - volatile uint32_t *set = &(PORT->Group[portNum].OUTSET.reg), - *clr = &(PORT->Group[portNum].OUTCLR.reg); - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - for (;;) { - *set = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;"); - if (p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop;"); - *clr = pinMask; - } else { - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop;"); - } - if (bitMask >>= 1) { - asm("nop; nop; nop; nop; nop; nop; nop; nop; nop;"); - } else { - if (ptr >= end) - break; - p = *ptr++; - bitMask = 0x80; - } - } -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - for (;;) { - *set = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"); - if (p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop;"); - *clr = pinMask; - } else { - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop;"); - } - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - if (bitMask >>= 1) { - asm("nop; nop; nop; nop; nop; nop; nop;"); - } else { - if (ptr >= end) - break; - p = *ptr++; - bitMask = 0x80; - } - } - } -#endif - -//---- -#elif defined(XMC1100_XMC2GO) || defined(XMC1100_H_BRIDGE2GO) || defined(XMC1100_Boot_Kit) || defined(XMC1300_Boot_Kit) - - // XMC1100/1200/1300 with ARM Cortex M0 are running with 32MHz, XMC1400 runs with 48MHz so may not work - // Tried this with a timer/counter, couldn't quite get adequate - // resolution. So yay, you get a load of goofball NOPs... - - uint8_t *ptr, *end, p, bitMask, portNum; - uint32_t pinMask; - - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - - XMC_GPIO_PORT_t* XMC_port = mapping_port_pin[ pin ].port; - uint8_t XMC_pin = mapping_port_pin[ pin ].pin; - - uint32_t omrhigh = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_HIGH << XMC_pin; - uint32_t omrlow = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_LOW << XMC_pin; - -#ifdef NEO_KHZ400 // 800 KHz check needed only if 400 KHz support enabled - if(is800KHz) { -#endif - for(;;) { - XMC_port->OMR = omrhigh; - asm("nop; nop; nop; nop;"); - if(p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop;"); - XMC_port->OMR = omrlow; - } else { - XMC_port->OMR = omrlow; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop;"); - } - if(bitMask >>= 1) { - asm("nop; nop; nop; nop; nop;"); - } else { - if(ptr >= end) break; - p = *ptr++; - bitMask = 0x80; - } - } -#ifdef NEO_KHZ400 // untested code - } else { // 400 KHz bitstream - for(;;) { - XMC_port->OMR = omrhigh; - asm("nop; nop; nop; nop; nop;"); - if(p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop;"); - XMC_port->OMR = omrlow; - } else { - XMC_port->OMR = omrlow; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop;"); - } - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - if(bitMask >>= 1) { - asm("nop; nop; nop;"); - } else { - if(ptr >= end) break; - p = *ptr++; - bitMask = 0x80; - } - } - } - -#endif -//---- - -//---- -#elif defined(XMC4700_Relax_Kit) || defined(XMC4800_Relax_Kit) - -// XMC4700 and XMC4800 with ARM Cortex M4 are running with 144MHz -// Tried this with a timer/counter, couldn't quite get adequate -// resolution. So yay, you get a load of goofball NOPs... - -uint8_t *ptr, *end, p, bitMask, portNum; -uint32_t pinMask; - -ptr = pixels; -end = ptr + numBytes; -p = *ptr++; -bitMask = 0x80; - -XMC_GPIO_PORT_t* XMC_port = mapping_port_pin[ pin ].port; -uint8_t XMC_pin = mapping_port_pin[ pin ].pin; - -uint32_t omrhigh = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_HIGH << XMC_pin; -uint32_t omrlow = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_LOW << XMC_pin; - -#ifdef NEO_KHZ400 // 800 KHz check needed only if 400 KHz support enabled -if(is800KHz) { -#endif - - for(;;) { - XMC_port->OMR = omrhigh; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop;"); - if(p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - XMC_port->OMR = omrlow; - } else { - XMC_port->OMR = omrlow; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - } - if(bitMask >>= 1) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - } else { - if(ptr >= end) break; - p = *ptr++; - bitMask = 0x80; - } - } - - -#ifdef NEO_KHZ400 - } else { // 400 KHz bitstream - // ToDo! - } -#endif -//---- - -#elif defined(__SAMD51__) // M4 - - uint8_t *ptr, *end, p, bitMask, portNum, bit; - uint32_t pinMask; - - portNum = g_APinDescription[pin].ulPort; - pinMask = 1ul << g_APinDescription[pin].ulPin; - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - - volatile uint32_t *set = &(PORT->Group[portNum].OUTSET.reg), - *clr = &(PORT->Group[portNum].OUTCLR.reg); - - // SAMD51 overclock-compatible timing is only a mild abomination. - // It uses SysTick for a consistent clock reference regardless of - // optimization / cache settings. That's the good news. The bad news, - // since SysTick->VAL is a volatile type it's slow to access...and then, - // with the SysTick interval that Arduino sets up (1 ms), this would - // require a subtract and MOD operation for gauging elapsed time, and - // all taken in combination that lacks adequate temporal resolution - // for NeoPixel timing. So a kind of horrible thing is done here... - // since interrupts are turned off anyway and it's generally accepted - // by now that we're gonna lose track of time in the NeoPixel lib, - // the SysTick timer is reconfigured for a period matching the NeoPixel - // bit timing (either 800 or 400 KHz) and we watch SysTick->VAL very - // closely (just a threshold, no subtract or MOD or anything) and that - // seems to work just well enough. When finished, the SysTick - // peripheral is set back to its original state. - - uint32_t t0, t1, top, ticks, saveLoad = SysTick->LOAD, saveVal = SysTick->VAL; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - top = (uint32_t)(F_CPU * 0.00000125); // Bit hi + lo = 1.25 uS - t0 = top - (uint32_t)(F_CPU * 0.00000040); // 0 = 0.4 uS hi - t1 = top - (uint32_t)(F_CPU * 0.00000080); // 1 = 0.8 uS hi -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - top = (uint32_t)(F_CPU * 0.00000250); // Bit hi + lo = 2.5 uS - t0 = top - (uint32_t)(F_CPU * 0.00000050); // 0 = 0.5 uS hi - t1 = top - (uint32_t)(F_CPU * 0.00000120); // 1 = 1.2 uS hi - } -#endif - - SysTick->LOAD = top; // Config SysTick for NeoPixel bit freq - SysTick->VAL = top; // Set to start value (counts down) - (void)SysTick->VAL; // Dummy read helps sync up 1st bit - - for (;;) { - *set = pinMask; // Set output high - ticks = (p & bitMask) ? t1 : t0; // SysTick threshold, - while (SysTick->VAL > ticks) - ; // wait for it - *clr = pinMask; // Set output low - if (!(bitMask >>= 1)) { // Next bit for this byte...done? - if (ptr >= end) - break; // If last byte sent, exit loop - p = *ptr++; // Fetch next byte - bitMask = 0x80; // Reset bitmask - } - while (SysTick->VAL <= ticks) - ; // Wait for rollover to 'top' - } - - SysTick->LOAD = saveLoad; // Restore SysTick rollover to 1 ms - SysTick->VAL = saveVal; // Restore SysTick value - -#elif defined(ARDUINO_STM32_FEATHER) // FEATHER WICED (120MHz) - - // Tried this with a timer/counter, couldn't quite get adequate - // resolution. So yay, you get a load of goofball NOPs... - - uint8_t *ptr, *end, p, bitMask; - uint32_t pinMask; - - pinMask = BIT(PIN_MAP[pin].gpio_bit); - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - - volatile uint16_t *set = &(PIN_MAP[pin].gpio_device->regs->BSRRL); - volatile uint16_t *clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH); - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - for (;;) { - if (p & bitMask) { // ONE - // High 800ns - *set = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop;"); - // Low 450ns - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop;"); - } else { // ZERO - // High 400ns - *set = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop;"); - // Low 850ns - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop;"); - } - if (bitMask >>= 1) { - // Move on to the next pixel - asm("nop;"); - } else { - if (ptr >= end) - break; - p = *ptr++; - bitMask = 0x80; - } - } -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - // ToDo! - } -#endif - -#elif defined(TARGET_LPC1768) - uint8_t *ptr, *end, p, bitMask; - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - for (;;) { - if (p & bitMask) { - // data ONE high - // min: 550 typ: 700 max: 5,500 - gpio_set(pin); - time::delay_ns(550); - // min: 450 typ: 600 max: 5,000 - gpio_clear(pin); - time::delay_ns(450); - } else { - // data ZERO high - // min: 200 typ: 350 max: 500 - gpio_set(pin); - time::delay_ns(200); - // data low - // min: 450 typ: 600 max: 5,000 - gpio_clear(pin); - time::delay_ns(450); - } - if (bitMask >>= 1) { - // Move on to the next pixel - asm("nop;"); - } else { - if (ptr >= end) - break; - p = *ptr++; - bitMask = 0x80; - } - } -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - // ToDo! - } -#endif -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) - uint8_t *p = pixels, *end = p + numBytes, pix = *p++, mask = 0x80; - uint32_t cyc; - uint32_t saveLoad = SysTick->LOAD, saveVal = SysTick->VAL; -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - uint32_t top = (F_CPU / 800000); // 1.25µs - uint32_t t0 = top - (F_CPU / 2500000); // 0.4µs - uint32_t t1 = top - (F_CPU / 1250000); // 0.8µs - SysTick->LOAD = top - 1; // Config SysTick for NeoPixel bit freq - SysTick->VAL = 0; // Set to start value - for (;;) { - LL_GPIO_SetOutputPin(gpioPort, gpioPin); - cyc = (pix & mask) ? t1 : t0; - while (SysTick->VAL > cyc) - ; - LL_GPIO_ResetOutputPin(gpioPort, gpioPin); - if (!(mask >>= 1)) { - if (p >= end) - break; - pix = *p++; - mask = 0x80; - } - while (SysTick->VAL <= cyc) - ; - } -#if defined(NEO_KHZ400) - } else { // 400 kHz bitstream - uint32_t top = (F_CPU / 400000); // 2.5µs - uint32_t t0 = top - (F_CPU / 2000000); // 0.5µs - uint32_t t1 = top - (F_CPU / 833333); // 1.2µs - SysTick->LOAD = top - 1; // Config SysTick for NeoPixel bit freq - SysTick->VAL = 0; // Set to start value - for (;;) { - LL_GPIO_SetOutputPin(gpioPort, gpioPin); - cyc = (pix & mask) ? t1 : t0; - while (SysTick->VAL > cyc) - ; - LL_GPIO_ResetOutputPin(gpioPort, gpioPin); - if (!(mask >>= 1)) { - if (p >= end) - break; - pix = *p++; - mask = 0x80; - } - while (SysTick->VAL <= cyc) - ; - } - } -#endif // NEO_KHZ400 - SysTick->LOAD = saveLoad; // Restore SysTick rollover to 1 ms - SysTick->VAL = saveVal; // Restore SysTick value -#elif defined(NRF51) - uint8_t *p = pixels, pix, count, mask; - int32_t num = numBytes; - unsigned int bitmask = (1 << g_ADigitalPinMap[pin]); - // https://github.com/sandeepmistry/arduino-nRF5/blob/dc53980c8bac27898fca90d8ecb268e11111edc1/variants/BBCmicrobit/variant.cpp - - volatile unsigned int *reg = (unsigned int *)(0x50000000UL + 0x508); - - // https://github.com/sandeepmistry/arduino-nRF5/blob/dc53980c8bac27898fca90d8ecb268e11111edc1/cores/nRF5/SDK/components/device/nrf51.h - // http://www.iot-programmer.com/index.php/books/27-micro-bit-iot-in-c/chapters-micro-bit-iot-in-c/47-micro-bit-iot-in-c-fast-memory-mapped-gpio?showall=1 - // https://github.com/Microsoft/pxt-neopixel/blob/master/sendbuffer.asm - - asm volatile( - // "cpsid i" ; disable irq - - // b .start - "b L%=_start" - "\n\t" - // .nextbit: ; C0 - "L%=_nextbit:" - "\n\t" //; C0 - // str r1, [r3, #0] ; pin := hi C2 - "strb %[bitmask], [%[reg], #0]" - "\n\t" //; pin := hi C2 - // tst r6, r0 ; C3 - "tst %[mask], %[pix]" - "\n\t" // ; C3 - // bne .islate ; C4 - "bne L%=_islate" - "\n\t" //; C4 - // str r1, [r2, #0] ; pin := lo C6 - "strb %[bitmask], [%[reg], #4]" - "\n\t" //; pin := lo C6 - // .islate: - "L%=_islate:" - "\n\t" - // lsrs r6, r6, #1 ; r6 >>= 1 C7 - "lsr %[mask], %[mask], #1" - "\n\t" //; r6 >>= 1 C7 - // bne .justbit ; C8 - "bne L%=_justbit" - "\n\t" //; C8 - - // ; not just a bit - need new byte - // adds r4, #1 ; r4++ C9 - "add %[p], #1" - "\n\t" //; r4++ C9 - // subs r5, #1 ; r5-- C10 - "sub %[num], #1" - "\n\t" //; r5-- C10 - // bcc .stop ; if (r5<0) goto .stop C11 - "bcc L%=_stop" - "\n\t" //; if (r5<0) goto .stop C11 - // .start: - "L%=_start:" - // movs r6, #0x80 ; reset mask C12 - "movs %[mask], #0x80" - "\n\t" //; reset mask C12 - // nop ; C13 - "nop" - "\n\t" //; C13 - - // .common: ; C13 - "L%=_common:" - "\n\t" //; C13 - // str r1, [r2, #0] ; pin := lo C15 - "strb %[bitmask], [%[reg], #4]" - "\n\t" //; pin := lo C15 - // ; always re-load byte - it just fits with the cycles better this way - // ldrb r0, [r4, #0] ; r0 := *r4 C17 - "ldrb %[pix], [%[p], #0]" - "\n\t" //; r0 := *r4 C17 - // b .nextbit ; C20 - "b L%=_nextbit" - "\n\t" //; C20 - - // .justbit: ; C10 - "L%=_justbit:" - "\n\t" //; C10 - // ; no nops, branch taken is already 3 cycles - // b .common ; C13 - "b L%=_common" - "\n\t" //; C13 - - // .stop: - "L%=_stop:" - "\n\t" - // str r1, [r2, #0] ; pin := lo - "strb %[bitmask], [%[reg], #4]" - "\n\t" //; pin := lo - // cpsie i ; enable irq - - : [p] "+r"(p), [pix] "=&r"(pix), [count] "=&r"(count), [mask] "=&r"(mask), - [num] "+r"(num) - : [bitmask] "r"(bitmask), [reg] "r"(reg)); - -#elif defined(__SAM3X8E__) // Arduino Due - -#define SCALE VARIANT_MCK / 2UL / 1000000UL -#define INST (2UL * F_CPU / VARIANT_MCK) -#define TIME_800_0 ((int)(0.40 * SCALE + 0.5) - (5 * INST)) -#define TIME_800_1 ((int)(0.80 * SCALE + 0.5) - (5 * INST)) -#define PERIOD_800 ((int)(1.25 * SCALE + 0.5) - (5 * INST)) -#define TIME_400_0 ((int)(0.50 * SCALE + 0.5) - (5 * INST)) -#define TIME_400_1 ((int)(1.20 * SCALE + 0.5) - (5 * INST)) -#define PERIOD_400 ((int)(2.50 * SCALE + 0.5) - (5 * INST)) - - int pinMask, time0, time1, period, t; - Pio *port; - volatile WoReg *portSet, *portClear, *timeValue, *timeReset; - uint8_t *p, *end, pix, mask; - - pmc_set_writeprotect(false); - pmc_enable_periph_clk((uint32_t)TC3_IRQn); - TC_Configure(TC1, 0, - TC_CMR_WAVE | TC_CMR_WAVSEL_UP | TC_CMR_TCCLKS_TIMER_CLOCK1); - TC_Start(TC1, 0); - - pinMask = g_APinDescription[pin].ulPin; // Don't 'optimize' these into - port = g_APinDescription[pin].pPort; // declarations above. Want to - portSet = &(port->PIO_SODR); // burn a few cycles after - portClear = &(port->PIO_CODR); // starting timer to minimize - timeValue = &(TC1->TC_CHANNEL[0].TC_CV); // the initial 'while'. - timeReset = &(TC1->TC_CHANNEL[0].TC_CCR); - p = pixels; - end = p + numBytes; - pix = *p++; - mask = 0x80; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - time0 = TIME_800_0; - time1 = TIME_800_1; - period = PERIOD_800; -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - time0 = TIME_400_0; - time1 = TIME_400_1; - period = PERIOD_400; - } -#endif - - for (t = time0;; t = time0) { - if (pix & mask) - t = time1; - while (*timeValue < (unsigned)period) - ; - *portSet = pinMask; - *timeReset = TC_CCR_CLKEN | TC_CCR_SWTRG; - while (*timeValue < (unsigned)t) - ; - *portClear = pinMask; - if (!(mask >>= 1)) { // This 'inside-out' loop logic utilizes - if (p >= end) - break; // idle time to minimize inter-byte delays. - pix = *p++; - mask = 0x80; - } - } - while (*timeValue < (unsigned)period) - ; // Wait for last bit - TC_Stop(TC1, 0); - -#endif // end Due - - // END ARM ---------------------------------------------------------------- - -#elif defined(ESP8266) || defined(ESP32) - - // ESP8266 ---------------------------------------------------------------- - - // ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution - espShow(pin, pixels, numBytes, is800KHz); - -#elif defined(KENDRYTE_K210) - - k210Show(pin, pixels, numBytes, is800KHz); - -#elif defined(__ARDUINO_ARC__) - - // Arduino 101 ----------------------------------------------------------- - -#define NOPx7 \ - { \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - } - - PinDescription *pindesc = &g_APinDescription[pin]; - register uint32_t loop = - 8 * numBytes; // one loop to handle all bytes and all bits - register uint8_t *p = pixels; - register uint32_t currByte = (uint32_t)(*p); - register uint32_t currBit = 0x80 & currByte; - register uint32_t bitCounter = 0; - register uint32_t first = 1; - - // The loop is unusual. Very first iteration puts all the way LOW to the wire - // - constant LOW does not affect NEOPIXEL, so there is no visible effect - // displayed. During that very first iteration CPU caches instructions in the - // loop. Because of the caching process, "CPU slows down". NEOPIXEL pulse is - // very time sensitive that's why we let the CPU cache first and we start - // regular pulse from 2nd iteration - if (pindesc->ulGPIOType == SS_GPIO) { - register uint32_t reg = pindesc->ulGPIOBase + SS_GPIO_SWPORTA_DR; - uint32_t reg_val = __builtin_arc_lr((volatile uint32_t)reg); - register uint32_t reg_bit_high = reg_val | (1 << pindesc->ulGPIOId); - register uint32_t reg_bit_low = reg_val & ~(1 << pindesc->ulGPIOId); - - loop += 1; // include first, special iteration - while (loop--) { - if (!first) { - currByte <<= 1; - bitCounter++; - } - - // 1 is >550ns high and >450ns low; 0 is 200..500ns high and >450ns low - __builtin_arc_sr(first ? reg_bit_low : reg_bit_high, - (volatile uint32_t)reg); - if (currBit) { // ~400ns HIGH (740ns overall) - NOPx7 NOPx7 - } - // ~340ns HIGH - NOPx7 __builtin_arc_nop(); - - // 820ns LOW; per spec, max allowed low here is 5000ns */ - __builtin_arc_sr(reg_bit_low, (volatile uint32_t)reg); - NOPx7 NOPx7 - - if (bitCounter >= 8) { - bitCounter = 0; - currByte = (uint32_t)(*++p); - } - - currBit = 0x80 & currByte; - first = 0; - } - } else if (pindesc->ulGPIOType == SOC_GPIO) { - register uint32_t reg = pindesc->ulGPIOBase + SOC_GPIO_SWPORTA_DR; - uint32_t reg_val = MMIO_REG_VAL(reg); - register uint32_t reg_bit_high = reg_val | (1 << pindesc->ulGPIOId); - register uint32_t reg_bit_low = reg_val & ~(1 << pindesc->ulGPIOId); - - loop += 1; // include first, special iteration - while (loop--) { - if (!first) { - currByte <<= 1; - bitCounter++; - } - MMIO_REG_VAL(reg) = first ? reg_bit_low : reg_bit_high; - if (currBit) { // ~430ns HIGH (740ns overall) - NOPx7 NOPx7 __builtin_arc_nop(); - } - // ~310ns HIGH - NOPx7 - - // 850ns LOW; per spec, max allowed low here is 5000ns */ - MMIO_REG_VAL(reg) = reg_bit_low; - NOPx7 NOPx7 - - if (bitCounter >= 8) { - bitCounter = 0; - currByte = (uint32_t)(*++p); - } - - currBit = 0x80 & currByte; - first = 0; - } - } - -#else -#error Architecture not supported -#endif - - // END ARCHITECTURE SELECT ------------------------------------------------ - -#if !(defined(NRF52) || defined(NRF52_SERIES) || defined(ESP32)) - interrupts(); -#endif - - endTime = micros(); // Save EOD time for latch on next call -} - -/*! - @brief Set/change the NeoPixel output pin number. Previous pin, - if any, is set to INPUT and the new pin is set to OUTPUT. - @param p Arduino pin number (-1 = no pin). -*/ -void Adafruit_NeoPixel::setPin(int16_t p) { - if (begun && (pin >= 0)) - pinMode(pin, INPUT); // Disable existing out pin - pin = p; - if (begun) { - pinMode(p, OUTPUT); - digitalWrite(p, LOW); - } -#if defined(__AVR__) - port = portOutputRegister(digitalPinToPort(p)); - pinMask = digitalPinToBitMask(p); -#endif -#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) - gpioPort = digitalPinToPort(p); - gpioPin = STM_LL_GPIO_PIN(digitalPinToPinName(p)); -#endif -} - -/*! - @brief Set a pixel's color using separate red, green and blue - components. If using RGBW pixels, white will be set to 0. - @param n Pixel index, starting from 0. - @param r Red brightness, 0 = minimum (off), 255 = maximum. - @param g Green brightness, 0 = minimum (off), 255 = maximum. - @param b Blue brightness, 0 = minimum (off), 255 = maximum. -*/ -void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint8_t r, uint8_t g, - uint8_t b) { - - if (n < numLEDs) { - if (brightness) { // See notes in setBrightness() - r = (r * brightness) >> 8; - g = (g * brightness) >> 8; - b = (b * brightness) >> 8; - } - uint8_t *p; - if (wOffset == rOffset) { // Is an RGB-type strip - p = &pixels[n * 3]; // 3 bytes per pixel - } else { // Is a WRGB-type strip - p = &pixels[n * 4]; // 4 bytes per pixel - p[wOffset] = 0; // But only R,G,B passed -- set W to 0 - } - p[rOffset] = r; // R,G,B always stored - p[gOffset] = g; - p[bOffset] = b; - } -} - -/*! - @brief Set a pixel's color using separate red, green, blue and white - components (for RGBW NeoPixels only). - @param n Pixel index, starting from 0. - @param r Red brightness, 0 = minimum (off), 255 = maximum. - @param g Green brightness, 0 = minimum (off), 255 = maximum. - @param b Blue brightness, 0 = minimum (off), 255 = maximum. - @param w White brightness, 0 = minimum (off), 255 = maximum, ignored - if using RGB pixels. -*/ -void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint8_t r, uint8_t g, - uint8_t b, uint8_t w) { - - if (n < numLEDs) { - if (brightness) { // See notes in setBrightness() - r = (r * brightness) >> 8; - g = (g * brightness) >> 8; - b = (b * brightness) >> 8; - w = (w * brightness) >> 8; - } - uint8_t *p; - if (wOffset == rOffset) { // Is an RGB-type strip - p = &pixels[n * 3]; // 3 bytes per pixel (ignore W) - } else { // Is a WRGB-type strip - p = &pixels[n * 4]; // 4 bytes per pixel - p[wOffset] = w; // Store W - } - p[rOffset] = r; // Store R,G,B - p[gOffset] = g; - p[bOffset] = b; - } -} - -/*! - @brief Set a pixel's color using a 32-bit 'packed' RGB or RGBW value. - @param n Pixel index, starting from 0. - @param c 32-bit color value. Most significant byte is white (for RGBW - pixels) or ignored (for RGB pixels), next is red, then green, - and least significant byte is blue. -*/ -void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint32_t c) { - if (n < numLEDs) { - uint8_t *p, r = (uint8_t)(c >> 16), g = (uint8_t)(c >> 8), b = (uint8_t)c; - if (brightness) { // See notes in setBrightness() - r = (r * brightness) >> 8; - g = (g * brightness) >> 8; - b = (b * brightness) >> 8; - } - if (wOffset == rOffset) { - p = &pixels[n * 3]; - } else { - p = &pixels[n * 4]; - uint8_t w = (uint8_t)(c >> 24); - p[wOffset] = brightness ? ((w * brightness) >> 8) : w; - } - p[rOffset] = r; - p[gOffset] = g; - p[bOffset] = b; - } -} - -/*! - @brief Fill all or part of the NeoPixel strip with a color. - @param c 32-bit color value. Most significant byte is white (for - RGBW pixels) or ignored (for RGB pixels), next is red, - then green, and least significant byte is blue. If all - arguments are unspecified, this will be 0 (off). - @param first Index of first pixel to fill, starting from 0. Must be - in-bounds, no clipping is performed. 0 if unspecified. - @param count Number of pixels to fill, as a positive value. Passing - 0 or leaving unspecified will fill to end of strip. -*/ -void Adafruit_NeoPixel::fill(uint32_t c, uint16_t first, uint16_t count) { - uint16_t i, end; - - if (first >= numLEDs) { - return; // If first LED is past end of strip, nothing to do - } - - // Calculate the index ONE AFTER the last pixel to fill - if (count == 0) { - // Fill to end of strip - end = numLEDs; - } else { - // Ensure that the loop won't go past the last pixel - end = first + count; - if (end > numLEDs) - end = numLEDs; - } - - for (i = first; i < end; i++) { - this->setPixelColor(i, c); - } -} - -/*! - @brief Convert hue, saturation and value into a packed 32-bit RGB color - that can be passed to setPixelColor() or other RGB-compatible - functions. - @param hue An unsigned 16-bit value, 0 to 65535, representing one full - loop of the color wheel, which allows 16-bit hues to "roll - over" while still doing the expected thing (and allowing - more precision than the wheel() function that was common to - prior NeoPixel examples). - @param sat Saturation, 8-bit value, 0 (min or pure grayscale) to 255 - (max or pure hue). Default of 255 if unspecified. - @param val Value (brightness), 8-bit value, 0 (min / black / off) to - 255 (max or full brightness). Default of 255 if unspecified. - @return Packed 32-bit RGB with the most significant byte set to 0 -- the - white element of WRGB pixels is NOT utilized. Result is linearly - but not perceptually correct, so you may want to pass the result - through the gamma32() function (or your own gamma-correction - operation) else colors may appear washed out. This is not done - automatically by this function because coders may desire a more - refined gamma-correction function than the simplified - one-size-fits-all operation of gamma32(). Diffusing the LEDs also - really seems to help when using low-saturation colors. -*/ -uint32_t Adafruit_NeoPixel::ColorHSV(uint16_t hue, uint8_t sat, uint8_t val) { - - uint8_t r, g, b; - - // Remap 0-65535 to 0-1529. Pure red is CENTERED on the 64K rollover; - // 0 is not the start of pure red, but the midpoint...a few values above - // zero and a few below 65536 all yield pure red (similarly, 32768 is the - // midpoint, not start, of pure cyan). The 8-bit RGB hexcone (256 values - // each for red, green, blue) really only allows for 1530 distinct hues - // (not 1536, more on that below), but the full unsigned 16-bit type was - // chosen for hue so that one's code can easily handle a contiguous color - // wheel by allowing hue to roll over in either direction. - hue = (hue * 1530L + 32768) / 65536; - // Because red is centered on the rollover point (the +32768 above, - // essentially a fixed-point +0.5), the above actually yields 0 to 1530, - // where 0 and 1530 would yield the same thing. Rather than apply a - // costly modulo operator, 1530 is handled as a special case below. - - // So you'd think that the color "hexcone" (the thing that ramps from - // pure red, to pure yellow, to pure green and so forth back to red, - // yielding six slices), and with each color component having 256 - // possible values (0-255), might have 1536 possible items (6*256), - // but in reality there's 1530. This is because the last element in - // each 256-element slice is equal to the first element of the next - // slice, and keeping those in there this would create small - // discontinuities in the color wheel. So the last element of each - // slice is dropped...we regard only elements 0-254, with item 255 - // being picked up as element 0 of the next slice. Like this: - // Red to not-quite-pure-yellow is: 255, 0, 0 to 255, 254, 0 - // Pure yellow to not-quite-pure-green is: 255, 255, 0 to 1, 255, 0 - // Pure green to not-quite-pure-cyan is: 0, 255, 0 to 0, 255, 254 - // and so forth. Hence, 1530 distinct hues (0 to 1529), and hence why - // the constants below are not the multiples of 256 you might expect. - - // Convert hue to R,G,B (nested ifs faster than divide+mod+switch): - if (hue < 510) { // Red to Green-1 - b = 0; - if (hue < 255) { // Red to Yellow-1 - r = 255; - g = hue; // g = 0 to 254 - } else { // Yellow to Green-1 - r = 510 - hue; // r = 255 to 1 - g = 255; - } - } else if (hue < 1020) { // Green to Blue-1 - r = 0; - if (hue < 765) { // Green to Cyan-1 - g = 255; - b = hue - 510; // b = 0 to 254 - } else { // Cyan to Blue-1 - g = 1020 - hue; // g = 255 to 1 - b = 255; - } - } else if (hue < 1530) { // Blue to Red-1 - g = 0; - if (hue < 1275) { // Blue to Magenta-1 - r = hue - 1020; // r = 0 to 254 - b = 255; - } else { // Magenta to Red-1 - r = 255; - b = 1530 - hue; // b = 255 to 1 - } - } else { // Last 0.5 Red (quicker than % operator) - r = 255; - g = b = 0; - } - - // Apply saturation and value to R,G,B, pack into 32-bit result: - uint32_t v1 = 1 + val; // 1 to 256; allows >>8 instead of /255 - uint16_t s1 = 1 + sat; // 1 to 256; same reason - uint8_t s2 = 255 - sat; // 255 to 0 - return ((((((r * s1) >> 8) + s2) * v1) & 0xff00) << 8) | - (((((g * s1) >> 8) + s2) * v1) & 0xff00) | - (((((b * s1) >> 8) + s2) * v1) >> 8); -} - -/*! - @brief Query the color of a previously-set pixel. - @param n Index of pixel to read (0 = first). - @return 'Packed' 32-bit RGB or WRGB value. Most significant byte is white - (for RGBW pixels) or 0 (for RGB pixels), next is red, then green, - and least significant byte is blue. - @note If the strip brightness has been changed from the default value - of 255, the color read from a pixel may not exactly match what - was previously written with one of the setPixelColor() functions. - This gets more pronounced at lower brightness levels. -*/ -uint32_t Adafruit_NeoPixel::getPixelColor(uint16_t n) const { - if (n >= numLEDs) - return 0; // Out of bounds, return no color. - - uint8_t *p; - - if (wOffset == rOffset) { // Is RGB-type device - p = &pixels[n * 3]; - if (brightness) { - // Stored color was decimated by setBrightness(). Returned value - // attempts to scale back to an approximation of the original 24-bit - // value used when setting the pixel color, but there will always be - // some error -- those bits are simply gone. Issue is most - // pronounced at low brightness levels. - return (((uint32_t)(p[rOffset] << 8) / brightness) << 16) | - (((uint32_t)(p[gOffset] << 8) / brightness) << 8) | - ((uint32_t)(p[bOffset] << 8) / brightness); - } else { - // No brightness adjustment has been made -- return 'raw' color - return ((uint32_t)p[rOffset] << 16) | ((uint32_t)p[gOffset] << 8) | - (uint32_t)p[bOffset]; - } - } else { // Is RGBW-type device - p = &pixels[n * 4]; - if (brightness) { // Return scaled color - return (((uint32_t)(p[wOffset] << 8) / brightness) << 24) | - (((uint32_t)(p[rOffset] << 8) / brightness) << 16) | - (((uint32_t)(p[gOffset] << 8) / brightness) << 8) | - ((uint32_t)(p[bOffset] << 8) / brightness); - } else { // Return raw color - return ((uint32_t)p[wOffset] << 24) | ((uint32_t)p[rOffset] << 16) | - ((uint32_t)p[gOffset] << 8) | (uint32_t)p[bOffset]; - } - } -} - -/*! - @brief Adjust output brightness. Does not immediately affect what's - currently displayed on the LEDs. The next call to show() will - refresh the LEDs at this level. - @param b Brightness setting, 0=minimum (off), 255=brightest. - @note This was intended for one-time use in one's setup() function, - not as an animation effect in itself. Because of the way this - library "pre-multiplies" LED colors in RAM, changing the - brightness is often a "lossy" operation -- what you write to - pixels isn't necessary the same as what you'll read back. - Repeated brightness changes using this function exacerbate the - problem. Smart programs therefore treat the strip as a - write-only resource, maintaining their own state to render each - frame of an animation, not relying on read-modify-write. -*/ -void Adafruit_NeoPixel::setBrightness(uint8_t b) { - // Stored brightness value is different than what's passed. - // This simplifies the actual scaling math later, allowing a fast - // 8x8-bit multiply and taking the MSB. 'brightness' is a uint8_t, - // adding 1 here may (intentionally) roll over...so 0 = max brightness - // (color values are interpreted literally; no scaling), 1 = min - // brightness (off), 255 = just below max brightness. - uint8_t newBrightness = b + 1; - if (newBrightness != brightness) { // Compare against prior value - // Brightness has changed -- re-scale existing data in RAM, - // This process is potentially "lossy," especially when increasing - // brightness. The tight timing in the WS2811/WS2812 code means there - // aren't enough free cycles to perform this scaling on the fly as data - // is issued. So we make a pass through the existing color data in RAM - // and scale it (subsequent graphics commands also work at this - // brightness level). If there's a significant step up in brightness, - // the limited number of steps (quantization) in the old data will be - // quite visible in the re-scaled version. For a non-destructive - // change, you'll need to re-render the full strip data. C'est la vie. - uint8_t c, *ptr = pixels, - oldBrightness = brightness - 1; // De-wrap old brightness value - uint16_t scale; - if (oldBrightness == 0) - scale = 0; // Avoid /0 - else if (b == 255) - scale = 65535 / oldBrightness; - else - scale = (((uint16_t)newBrightness << 8) - 1) / oldBrightness; - for (uint16_t i = 0; i < numBytes; i++) { - c = *ptr; - *ptr++ = (c * scale) >> 8; - } - brightness = newBrightness; - } -} - -/*! - @brief Retrieve the last-set brightness value for the strip. - @return Brightness value: 0 = minimum (off), 255 = maximum. -*/ -uint8_t Adafruit_NeoPixel::getBrightness(void) const { return brightness - 1; } - -/*! - @brief Fill the whole NeoPixel strip with 0 / black / off. -*/ -void Adafruit_NeoPixel::clear(void) { memset(pixels, 0, numBytes); } - -// A 32-bit variant of gamma8() that applies the same function -// to all components of a packed RGB or WRGB value. -uint32_t Adafruit_NeoPixel::gamma32(uint32_t x) { - uint8_t *y = (uint8_t *)&x; - // All four bytes of a 32-bit value are filtered even if RGB (not WRGB), - // to avoid a bunch of shifting and masking that would be necessary for - // properly handling different endianisms (and each byte is a fairly - // trivial operation, so it might not even be wasting cycles vs a check - // and branch for the RGB case). In theory this might cause trouble *if* - // someone's storing information in the unused most significant byte - // of an RGB value, but this seems exceedingly rare and if it's - // encountered in reality they can mask values going in or coming out. - for (uint8_t i = 0; i < 4; i++) - y[i] = gamma8(y[i]); - return x; // Packed 32-bit return -} - -/*! - @brief Fill NeoPixel strip with one or more cycles of hues. - Everyone loves the rainbow swirl so much, now it's canon! - @param first_hue Hue of first pixel, 0-65535, representing one full - cycle of the color wheel. Each subsequent pixel will - be offset to complete one or more cycles over the - length of the strip. - @param reps Number of cycles of the color wheel over the length - of the strip. Default is 1. Negative values can be - used to reverse the hue order. - @param saturation Saturation (optional), 0-255 = gray to pure hue, - default = 255. - @param brightness Brightness/value (optional), 0-255 = off to max, - default = 255. This is distinct and in combination - with any configured global strip brightness. - @param gammify If true (default), apply gamma correction to colors - for better appearance. -*/ -void Adafruit_NeoPixel::rainbow(uint16_t first_hue, int8_t reps, - uint8_t saturation, uint8_t brightness, bool gammify) { - for (uint16_t i=0; i. - * - */ - -#ifndef ADAFRUIT_NEOPIXEL_H -#define ADAFRUIT_NEOPIXEL_H - -#ifdef ARDUINO -#if (ARDUINO >= 100) -#include -#else -#include -#include -#endif - -#ifdef USE_TINYUSB // For Serial when selecting TinyUSB -#include -#endif - -#endif - -#ifdef TARGET_LPC1768 -#include -#endif - -#if defined(ARDUINO_ARCH_RP2040) -#include -#include "hardware/pio.h" -#include "hardware/clocks.h" -#include "rp2040_pio.h" -#endif - -// The order of primary colors in the NeoPixel data stream can vary among -// device types, manufacturers and even different revisions of the same -// item. The third parameter to the Adafruit_NeoPixel constructor encodes -// the per-pixel byte offsets of the red, green and blue primaries (plus -// white, if present) in the data stream -- the following #defines provide -// an easier-to-use named version for each permutation. e.g. NEO_GRB -// indicates a NeoPixel-compatible device expecting three bytes per pixel, -// with the first byte transmitted containing the green value, second -// containing red and third containing blue. The in-memory representation -// of a chain of NeoPixels is the same as the data-stream order; no -// re-ordering of bytes is required when issuing data to the chain. -// Most of these values won't exist in real-world devices, but it's done -// this way so we're ready for it (also, if using the WS2811 driver IC, -// one might have their pixels set up in any weird permutation). - -// Bits 5,4 of this value are the offset (0-3) from the first byte of a -// pixel to the location of the red color byte. Bits 3,2 are the green -// offset and 1,0 are the blue offset. If it is an RGBW-type device -// (supporting a white primary in addition to R,G,B), bits 7,6 are the -// offset to the white byte...otherwise, bits 7,6 are set to the same value -// as 5,4 (red) to indicate an RGB (not RGBW) device. -// i.e. binary representation: -// 0bWWRRGGBB for RGBW devices -// 0bRRRRGGBB for RGB - -// RGB NeoPixel permutations; white and red offsets are always same -// Offset: W R G B -#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) ///< Transmit as R,G,B -#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G -#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B -#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,R -#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) ///< Transmit as B,R,G -#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,R - -// RGBW NeoPixel permutations; all 4 offsets are distinct -// Offset: W R G B -#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) ///< Transmit as W,R,G,B -#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) ///< Transmit as W,R,B,G -#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) ///< Transmit as W,G,R,B -#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) ///< Transmit as W,G,B,R -#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) ///< Transmit as W,B,R,G -#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) ///< Transmit as W,B,G,R - -#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) ///< Transmit as R,W,G,B -#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) ///< Transmit as R,W,B,G -#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) ///< Transmit as R,G,W,B -#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) ///< Transmit as R,G,B,W -#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) ///< Transmit as R,B,W,G -#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G,W - -#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) ///< Transmit as G,W,R,B -#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) ///< Transmit as G,W,B,R -#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) ///< Transmit as G,R,W,B -#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B,W -#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,W,R -#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,R,W - -#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) ///< Transmit as B,W,R,G -#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) ///< Transmit as B,W,G,R -#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) ///< Transmit as B,R,W,G -#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) ///< Transmit as B,R,G,W -#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,W,R -#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,R,W - -// Add NEO_KHZ400 to the color order value to indicate a 400 KHz device. -// All but the earliest v1 NeoPixels expect an 800 KHz data stream, this is -// the default if unspecified. Because flash space is very limited on ATtiny -// devices (e.g. Trinket, Gemma), v1 NeoPixels aren't handled by default on -// those chips, though it can be enabled by removing the ifndef/endif below, -// but code will be bigger. Conversely, can disable the NEO_KHZ400 line on -// other MCUs to remove v1 support and save a little space. - -#define NEO_KHZ800 0x0000 ///< 800 KHz data transmission -#ifndef __AVR_ATtiny85__ -#define NEO_KHZ400 0x0100 ///< 400 KHz data transmission -#endif - -// If 400 KHz support is enabled, the third parameter to the constructor -// requires a 16-bit value (in order to select 400 vs 800 KHz speed). -// If only 800 KHz is enabled (as is default on ATtiny), an 8-bit value -// is sufficient to encode pixel color order, saving some space. - -#ifdef NEO_KHZ400 -typedef uint16_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor -#else -typedef uint8_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor -#endif - -// These two tables are declared outside the Adafruit_NeoPixel class -// because some boards may require oldschool compilers that don't -// handle the C++11 constexpr keyword. - -/* A PROGMEM (flash mem) table containing 8-bit unsigned sine wave (0-255). - Copy & paste this snippet into a Python REPL to regenerate: -import math -for x in range(256): - print("{:3},".format(int((math.sin(x/128.0*math.pi)+1.0)*127.5+0.5))), - if x&15 == 15: print -*/ -static const uint8_t PROGMEM _NeoPixelSineTable[256] = { - 128, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170, - 173, 176, 179, 182, 185, 188, 190, 193, 196, 198, 201, 203, 206, 208, 211, - 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 238, 240, - 241, 243, 244, 245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254, - 254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251, - 250, 250, 249, 248, 246, 245, 244, 243, 241, 240, 238, 237, 235, 234, 232, - 230, 228, 226, 224, 222, 220, 218, 215, 213, 211, 208, 206, 203, 201, 198, - 196, 193, 190, 188, 185, 182, 179, 176, 173, 170, 167, 165, 162, 158, 155, - 152, 149, 146, 143, 140, 137, 134, 131, 128, 124, 121, 118, 115, 112, 109, - 106, 103, 100, 97, 93, 90, 88, 85, 82, 79, 76, 73, 70, 67, 65, - 62, 59, 57, 54, 52, 49, 47, 44, 42, 40, 37, 35, 33, 31, 29, - 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, 10, 9, 7, 6, - 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, 10, 11, - 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37, - 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76, - 79, 82, 85, 88, 90, 93, 97, 100, 103, 106, 109, 112, 115, 118, 121, - 124}; - -/* Similar to above, but for an 8-bit gamma-correction table. - Copy & paste this snippet into a Python REPL to regenerate: -import math -gamma=2.6 -for x in range(256): - print("{:3},".format(int(math.pow((x)/255.0,gamma)*255.0+0.5))), - if x&15 == 15: print -*/ -static const uint8_t PROGMEM _NeoPixelGammaTable[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, - 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, - 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, - 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, - 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, - 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, - 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81, - 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96, 97, 99, 100, 102, - 103, 105, 106, 108, 109, 111, 112, 114, 115, 117, 119, 120, 122, 124, 125, - 127, 129, 130, 132, 134, 136, 137, 139, 141, 143, 145, 146, 148, 150, 152, - 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, - 184, 186, 188, 191, 193, 195, 197, 199, 202, 204, 206, 209, 211, 213, 215, - 218, 220, 223, 225, 227, 230, 232, 235, 237, 240, 242, 245, 247, 250, 252, - 255}; - -/*! - @brief Class that stores state and functions for interacting with - Adafruit NeoPixels and compatible devices. -*/ -class Adafruit_NeoPixel { - -public: - // Constructor: number of LEDs, pin number, LED type - Adafruit_NeoPixel(uint16_t n, int16_t pin = 6, - neoPixelType type = NEO_GRB + NEO_KHZ800); - Adafruit_NeoPixel(void); - ~Adafruit_NeoPixel(); - - void begin(void); - void show(void); - void setPin(int16_t p); - void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b); - void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w); - void setPixelColor(uint16_t n, uint32_t c); - void fill(uint32_t c = 0, uint16_t first = 0, uint16_t count = 0); - void setBrightness(uint8_t); - void clear(void); - void updateLength(uint16_t n); - void updateType(neoPixelType t); - /*! - @brief Check whether a call to show() will start sending data - immediately or will 'block' for a required interval. NeoPixels - require a short quiet time (about 300 microseconds) after the - last bit is received before the data 'latches' and new data can - start being received. Usually one's sketch is implicitly using - this time to generate a new frame of animation...but if it - finishes very quickly, this function could be used to see if - there's some idle time available for some low-priority - concurrent task. - @return 1 or true if show() will start sending immediately, 0 or false - if show() would block (meaning some idle time is available). - */ - bool canShow(void) { - // It's normal and possible for endTime to exceed micros() if the - // 32-bit clock counter has rolled over (about every 70 minutes). - // Since both are uint32_t, a negative delta correctly maps back to - // positive space, and it would seem like the subtraction below would - // suffice. But a problem arises if code invokes show() very - // infrequently...the micros() counter may roll over MULTIPLE times in - // that interval, the delta calculation is no longer correct and the - // next update may stall for a very long time. The check below resets - // the latch counter if a rollover has occurred. This can cause an - // extra delay of up to 300 microseconds in the rare case where a - // show() call happens precisely around the rollover, but that's - // neither likely nor especially harmful, vs. other code that might - // stall for 30+ minutes, or having to document and frequently remind - // and/or provide tech support explaining an unintuitive need for - // show() calls at least once an hour. - uint32_t now = micros(); - if (endTime > now) { - endTime = now; - } - return (now - endTime) >= 300L; - } - /*! - @brief Get a pointer directly to the NeoPixel data buffer in RAM. - Pixel data is stored in a device-native format (a la the NEO_* - constants) and is not translated here. Applications that access - this buffer will need to be aware of the specific data format - and handle colors appropriately. - @return Pointer to NeoPixel buffer (uint8_t* array). - @note This is for high-performance applications where calling - setPixelColor() on every single pixel would be too slow (e.g. - POV or light-painting projects). There is no bounds checking - on the array, creating tremendous potential for mayhem if one - writes past the ends of the buffer. Great power, great - responsibility and all that. - */ - uint8_t *getPixels(void) const { return pixels; }; - uint8_t getBrightness(void) const; - /*! - @brief Retrieve the pin number used for NeoPixel data output. - @return Arduino pin number (-1 if not set). - */ - int16_t getPin(void) const { return pin; }; - /*! - @brief Return the number of pixels in an Adafruit_NeoPixel strip object. - @return Pixel count (0 if not set). - */ - uint16_t numPixels(void) const { return numLEDs; } - uint32_t getPixelColor(uint16_t n) const; - /*! - @brief An 8-bit integer sine wave function, not directly compatible - with standard trigonometric units like radians or degrees. - @param x Input angle, 0-255; 256 would loop back to zero, completing - the circle (equivalent to 360 degrees or 2 pi radians). - One can therefore use an unsigned 8-bit variable and simply - add or subtract, allowing it to overflow/underflow and it - still does the expected contiguous thing. - @return Sine result, 0 to 255, or -128 to +127 if type-converted to - a signed int8_t, but you'll most likely want unsigned as this - output is often used for pixel brightness in animation effects. - */ - static uint8_t sine8(uint8_t x) { - return pgm_read_byte(&_NeoPixelSineTable[x]); // 0-255 in, 0-255 out - } - /*! - @brief An 8-bit gamma-correction function for basic pixel brightness - adjustment. Makes color transitions appear more perceptially - correct. - @param x Input brightness, 0 (minimum or off/black) to 255 (maximum). - @return Gamma-adjusted brightness, can then be passed to one of the - setPixelColor() functions. This uses a fixed gamma correction - exponent of 2.6, which seems reasonably okay for average - NeoPixels in average tasks. If you need finer control you'll - need to provide your own gamma-correction function instead. - */ - static uint8_t gamma8(uint8_t x) { - return pgm_read_byte(&_NeoPixelGammaTable[x]); // 0-255 in, 0-255 out - } - /*! - @brief Convert separate red, green and blue values into a single - "packed" 32-bit RGB color. - @param r Red brightness, 0 to 255. - @param g Green brightness, 0 to 255. - @param b Blue brightness, 0 to 255. - @return 32-bit packed RGB value, which can then be assigned to a - variable for later use or passed to the setPixelColor() - function. Packed RGB format is predictable, regardless of - LED strand color order. - */ - static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) { - return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; - } - /*! - @brief Convert separate red, green, blue and white values into a - single "packed" 32-bit WRGB color. - @param r Red brightness, 0 to 255. - @param g Green brightness, 0 to 255. - @param b Blue brightness, 0 to 255. - @param w White brightness, 0 to 255. - @return 32-bit packed WRGB value, which can then be assigned to a - variable for later use or passed to the setPixelColor() - function. Packed WRGB format is predictable, regardless of - LED strand color order. - */ - static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { - return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; - } - static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255); - /*! - @brief A gamma-correction function for 32-bit packed RGB or WRGB - colors. Makes color transitions appear more perceptially - correct. - @param x 32-bit packed RGB or WRGB color. - @return Gamma-adjusted packed color, can then be passed in one of the - setPixelColor() functions. Like gamma8(), this uses a fixed - gamma correction exponent of 2.6, which seems reasonably okay - for average NeoPixels in average tasks. If you need finer - control you'll need to provide your own gamma-correction - function instead. - */ - static uint32_t gamma32(uint32_t x); - - void rainbow(uint16_t first_hue = 0, int8_t reps = 1, - uint8_t saturation = 255, uint8_t brightness = 255, - bool gammify = true); - -private: -#if defined(ARDUINO_ARCH_RP2040) - void rp2040Init(uint8_t pin, bool is800KHz); - void rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz); -#endif - -protected: -#ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled... - bool is800KHz; ///< true if 800 KHz pixels -#endif - bool begun; ///< true if begin() previously called - uint16_t numLEDs; ///< Number of RGB LEDs in strip - uint16_t numBytes; ///< Size of 'pixels' buffer below - int16_t pin; ///< Output pin number (-1 if not yet set) - uint8_t brightness; ///< Strip brightness 0-255 (stored as +1) - uint8_t *pixels; ///< Holds LED color values (3 or 4 bytes each) - uint8_t rOffset; ///< Red index within each 3- or 4-byte pixel - uint8_t gOffset; ///< Index of green byte - uint8_t bOffset; ///< Index of blue byte - uint8_t wOffset; ///< Index of white (==rOffset if no white) - uint32_t endTime; ///< Latch timing reference -#ifdef __AVR__ - volatile uint8_t *port; ///< Output PORT register - uint8_t pinMask; ///< Output PORT bitmask -#endif -#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) - GPIO_TypeDef *gpioPort; ///< Output GPIO PORT - uint32_t gpioPin; ///< Output GPIO PIN -#endif -#if defined(ARDUINO_ARCH_RP2040) - PIO pio = pio0; - int sm = 0; - bool init = true; -#endif -}; - -#endif // ADAFRUIT_NEOPIXEL_H diff --git a/lib/Adafruit_NeoPixel/CONTRIBUTING.md b/lib/Adafruit_NeoPixel/CONTRIBUTING.md deleted file mode 100644 index aa753894e5..0000000000 --- a/lib/Adafruit_NeoPixel/CONTRIBUTING.md +++ /dev/null @@ -1,13 +0,0 @@ -# Contribution Guidelines - -This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work. The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/adafruit/Adafruit_NeoPixel/issues/new) while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community. - -The following are some guidelines to observe when creating issues or PRs: - -- Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas - -- [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets - -- Use reasonable titles; refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile: - -- Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library diff --git a/lib/Adafruit_NeoPixel/COPYING b/lib/Adafruit_NeoPixel/COPYING deleted file mode 100644 index 65c5ca88a6..0000000000 --- a/lib/Adafruit_NeoPixel/COPYING +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - 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. diff --git a/lib/Adafruit_NeoPixel/README.md b/lib/Adafruit_NeoPixel/README.md deleted file mode 100644 index eff1337119..0000000000 --- a/lib/Adafruit_NeoPixel/README.md +++ /dev/null @@ -1,157 +0,0 @@ -# Adafruit NeoPixel Library [![Build Status](https://github.com/adafruit/Adafruit_NeoPixel/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_NeoPixel/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_NeoPixel/html/index.html) - -Arduino library for controlling single-wire-based LED pixels and strip such as the [Adafruit 60 LED/meter Digital LED strip][strip], the [Adafruit FLORA RGB Smart Pixel][flora], the [Adafruit Breadboard-friendly RGB Smart Pixel][pixel], the [Adafruit NeoPixel Stick][stick], and the [Adafruit NeoPixel Shield][shield]. - -After downloading, rename folder to 'Adafruit_NeoPixel' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->Adafruit_NeoPixel->strandtest sketch. - -Compatibility notes: Port A is not supported on any AVR processors at this time - -[flora]: http://adafruit.com/products/1060 -[strip]: http://adafruit.com/products/1138 -[pixel]: http://adafruit.com/products/1312 -[stick]: http://adafruit.com/products/1426 -[shield]: http://adafruit.com/products/1430 - ---- - -## Installation - -### First Method - -![image](https://user-images.githubusercontent.com/36513474/68967967-3e37f480-0803-11ea-91d9-601848c306ee.png) - -1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries -1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. -1. Then search for Neopixel strip using the search bar. -1. Click on the text area and then select the specific version and install it. - -### Second Method - -1. Navigate to the [Releases page](https://github.com/adafruit/Adafruit_NeoPixel/releases). -1. Download the latest release. -1. Extract the zip file -1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library - -## Features - -- ### Simple to use - - Controlling NeoPixels “from scratch” is quite a challenge, so we provide a library letting you focus on the fun and interesting bits. - -- ### Give back - - The library is free; you don’t have to pay for anything. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! - -- ### Supported Chipsets - - We have included code for the following chips - sometimes these break for exciting reasons that we can't control in which case please open an issue! - - - AVR ATmega and ATtiny (any 8-bit) - 8 MHz, 12 MHz and 16 MHz - - Teensy 3.x and LC - - Arduino Due - - Arduino 101 - - ATSAMD21 (Arduino Zero/M0 and other SAMD21 boards) @ 48 MHz - - ATSAMD51 @ 120 MHz - - Adafruit STM32 Feather @ 120 MHz - - ESP8266 any speed - - ESP32 any speed - - Nordic nRF52 (Adafruit Feather nRF52), nRF51 (micro:bit) - - Infineon XMC1100 BootKit @ 32 MHz - - Infineon XMC1100 2Go @ 32 MHz - - Infineon XMC1300 BootKit @ 32 MHz - - Infineon XMC4700 RelaxKit, XMC4800 RelaxKit, XMC4800 IoT Amazon FreeRTOS Kit @ 144 MHz - - Check forks for other architectures not listed here! - -- ### GNU Lesser General Public License - - Adafruit_NeoPixel 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. - -## Functions - -- begin() -- updateLength() -- updateType() -- show() -- delay_ns() -- setPin() -- setPixelColor() -- fill() -- ColorHSV() -- getPixelColor() -- setBrightness() -- getBrightness() -- clear() -- gamma32() - -## Examples - -There are many examples implemented in this library. One of the examples is below. You can find other examples [here](https://github.com/adafruit/Adafruit_NeoPixel/tree/master/examples) - -### Simple - -```Cpp -#include -#ifdef __AVR__ - #include -#endif -#define PIN 6 -#define NUMPIXELS 16 - -Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); -#define DELAYVAL 500 - -void setup() { -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - - pixels.begin(); -} - -void loop() { - pixels.clear(); - - for(int i=0; i -#include "driver/rmt.h" - -#if defined(ESP_IDF_VERSION) -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) -#define HAS_ESP_IDF_4 -#endif -#endif - -// This code is adapted from the ESP-IDF v3.4 RMT "led_strip" example, altered -// to work with the Arduino version of the ESP-IDF (3.2) - -#define WS2812_T0H_NS (400) -#define WS2812_T0L_NS (850) -#define WS2812_T1H_NS (800) -#define WS2812_T1L_NS (450) - -#define WS2811_T0H_NS (500) -#define WS2811_T0L_NS (2000) -#define WS2811_T1H_NS (1200) -#define WS2811_T1L_NS (1300) - -static uint32_t t0h_ticks = 0; -static uint32_t t1h_ticks = 0; -static uint32_t t0l_ticks = 0; -static uint32_t t1l_ticks = 0; - -// Limit the number of RMT channels available for the Neopixels. Defaults to all -// channels (8 on ESP32, 4 on ESP32-S2 and S3). Redefining this value will free -// any channels with a higher number for other uses, such as IR send-and-recieve -// libraries. Redefine as 1 to restrict Neopixels to only a single channel. -#define ADAFRUIT_RMT_CHANNEL_MAX RMT_CHANNEL_MAX - -#define RMT_LL_HW_BASE (&RMT) - -bool rmt_reserved_channels[ADAFRUIT_RMT_CHANNEL_MAX]; - -static void IRAM_ATTR ws2812_rmt_adapter(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; - } - const rmt_item32_t bit0 = {{{ t0h_ticks, 1, t0l_ticks, 0 }}}; //Logical 0 - const rmt_item32_t bit1 = {{{ t1h_ticks, 1, t1l_ticks, 0 }}}; //Logical 1 - size_t size = 0; - size_t num = 0; - uint8_t *psrc = (uint8_t *)src; - rmt_item32_t *pdest = dest; - while (size < src_size && num < wanted_num) { - for (int i = 0; i < 8; i++) { - // MSB first - if (*psrc & (1 << (7 - i))) { - pdest->val = bit1.val; - } else { - pdest->val = bit0.val; - } - num++; - pdest++; - } - size++; - psrc++; - } - *translated_size = size; - *item_num = num; -} - -void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { - // Reserve channel - rmt_channel_t channel = ADAFRUIT_RMT_CHANNEL_MAX; - for (size_t i = 0; i < ADAFRUIT_RMT_CHANNEL_MAX; i++) { - if (!rmt_reserved_channels[i]) { - rmt_reserved_channels[i] = true; - channel = i; - break; - } - } - if (channel == ADAFRUIT_RMT_CHANNEL_MAX) { - // Ran out of channels! - return; - } - -#if defined(HAS_ESP_IDF_4) - rmt_config_t config = RMT_DEFAULT_CONFIG_TX(pin, channel); - config.clk_div = 2; -#else - // Match default TX config from ESP-IDF version 3.4 - rmt_config_t config = { - .rmt_mode = RMT_MODE_TX, - .channel = channel, - .gpio_num = pin, - .clk_div = 2, - .mem_block_num = 1, - .tx_config = { - .carrier_freq_hz = 38000, - .carrier_level = RMT_CARRIER_LEVEL_HIGH, - .idle_level = RMT_IDLE_LEVEL_LOW, - .carrier_duty_percent = 33, - .carrier_en = false, - .loop_en = false, - .idle_output_en = true, - } - }; -#endif - rmt_config(&config); - rmt_driver_install(config.channel, 0, 0); - - // Convert NS timings to ticks - uint32_t counter_clk_hz = 0; - -#if defined(HAS_ESP_IDF_4) - rmt_get_counter_clock(channel, &counter_clk_hz); -#else - // this emulates the rmt_get_counter_clock() function from ESP-IDF 3.4 - if (RMT_LL_HW_BASE->conf_ch[config.channel].conf1.ref_always_on == RMT_BASECLK_REF) { - uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt; - uint32_t div = div_cnt == 0 ? 256 : div_cnt; - counter_clk_hz = REF_CLK_FREQ / (div); - } else { - uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt; - uint32_t div = div_cnt == 0 ? 256 : div_cnt; - counter_clk_hz = APB_CLK_FREQ / (div); - } -#endif - - // NS to tick converter - float ratio = (float)counter_clk_hz / 1e9; - - if (is800KHz) { - t0h_ticks = (uint32_t)(ratio * WS2812_T0H_NS); - t0l_ticks = (uint32_t)(ratio * WS2812_T0L_NS); - t1h_ticks = (uint32_t)(ratio * WS2812_T1H_NS); - t1l_ticks = (uint32_t)(ratio * WS2812_T1L_NS); - } else { - t0h_ticks = (uint32_t)(ratio * WS2811_T0H_NS); - t0l_ticks = (uint32_t)(ratio * WS2811_T0L_NS); - t1h_ticks = (uint32_t)(ratio * WS2811_T1H_NS); - t1l_ticks = (uint32_t)(ratio * WS2811_T1L_NS); - } - - // Initialize automatic timing translator - rmt_translator_init(config.channel, ws2812_rmt_adapter); - - // Write and wait to finish - rmt_write_sample(config.channel, pixels, (size_t)numBytes, true); - rmt_wait_tx_done(config.channel, pdMS_TO_TICKS(100)); - - // Free channel again - rmt_driver_uninstall(config.channel); - rmt_reserved_channels[channel] = false; - - gpio_set_direction(pin, GPIO_MODE_OUTPUT); -} - -#endif diff --git a/lib/Adafruit_NeoPixel/esp8266.c b/lib/Adafruit_NeoPixel/esp8266.c deleted file mode 100644 index 51c3f3c8a3..0000000000 --- a/lib/Adafruit_NeoPixel/esp8266.c +++ /dev/null @@ -1,86 +0,0 @@ -// This is a mash-up of the Due show() code + insights from Michael Miller's -// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus -// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution. - -#if defined(ESP8266) - -#include -#ifdef ESP8266 -#include -#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; -} - -#ifdef ESP8266 -IRAM_ATTR void espShow( - uint8_t pin, uint8_t *pixels, uint32_t numBytes, __attribute__((unused)) boolean is800KHz) { -#else -void espShow( - uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { -#endif - -#define CYCLES_800_T0H (F_CPU / 2500001) // 0.4us -#define CYCLES_800_T1H (F_CPU / 1250001) // 0.8us -#define CYCLES_800 (F_CPU / 800001) // 1.25us per bit -#define CYCLES_400_T0H (F_CPU / 2000000) // 0.5uS -#define CYCLES_400_T1H (F_CPU / 833333) // 1.2us -#define CYCLES_400 (F_CPU / 400000) // 2.5us per bit - - uint8_t *p, *end, pix, mask; - uint32_t t, time0, time1, period, c, startTime; - -#ifdef ESP8266 - uint32_t pinMask; - pinMask = _BV(pin); -#endif - - p = pixels; - end = p + numBytes; - pix = *p++; - mask = 0x80; - startTime = 0; - -#ifdef NEO_KHZ400 - if(is800KHz) { -#endif - time0 = CYCLES_800_T0H; - time1 = CYCLES_800_T1H; - period = CYCLES_800; -#ifdef NEO_KHZ400 - } else { // 400 KHz bitstream - time0 = CYCLES_400_T0H; - time1 = CYCLES_400_T1H; - period = CYCLES_400; - } -#endif - - for(t = time0;; t = time0) { - if(pix & mask) t = time1; // Bit high duration - while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start -#ifdef ESP8266 - GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high -#else - gpio_set_level(pin, HIGH); -#endif - startTime = c; // Save start time - while(((c = _getCycleCount()) - startTime) < t); // Wait high duration -#ifdef ESP8266 - GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low -#else - gpio_set_level(pin, LOW); -#endif - if(!(mask >>= 1)) { // Next bit/byte - if(p >= end) break; - pix = *p++; - mask = 0x80; - } - } - while((_getCycleCount() - startTime) < period); // Wait for last bit -} - -#endif // ESP8266 diff --git a/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.trinket.test.skip b/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.trinket.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino b/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino deleted file mode 100644 index 95335cdfce..0000000000 --- a/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino +++ /dev/null @@ -1,177 +0,0 @@ -// NeoPixel test program showing use of the WHITE channel for RGBW -// pixels only (won't look correct on regular RGB NeoPixel strips). - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -// On a Trinket or Gemma we suggest changing this to 1: -#define LED_PIN 6 - -// How many NeoPixels are attached to the Arduino? -#define LED_COUNT 60 - -// NeoPixel brightness, 0 (min) to 255 (max) -#define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255) - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - strip.setBrightness(BRIGHTNESS); -} - -void loop() { - // Fill along the length of the strip in various colors... - colorWipe(strip.Color(255, 0, 0) , 50); // Red - colorWipe(strip.Color( 0, 255, 0) , 50); // Green - colorWipe(strip.Color( 0, 0, 255) , 50); // Blue - colorWipe(strip.Color( 0, 0, 0, 255), 50); // True white (not RGB white) - - whiteOverRainbow(75, 5); - - pulseWhite(5); - - rainbowFade2White(3, 3, 1); -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - for(int i=0; i= strip.numPixels()) whiteLength = strip.numPixels() - 1; - - int head = whiteLength - 1; - int tail = 0; - int loops = 3; - int loopNum = 0; - uint32_t lastTime = millis(); - uint32_t firstPixelHue = 0; - - for(;;) { // Repeat forever (or until a 'break' or 'return') - for(int i=0; i= tail) && (i <= head)) || // If between head & tail... - ((tail > head) && ((i >= tail) || (i <= head)))) { - strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white - } else { // else set rainbow - int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); - strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); - } - } - - strip.show(); // Update strip with new contents - // There's no delay here, it just runs full-tilt until the timer and - // counter combination below runs out. - - firstPixelHue += 40; // Advance just a little along the color wheel - - if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail? - if(++head >= strip.numPixels()) { // Advance head, wrap around - head = 0; - if(++loopNum >= loops) return; - } - if(++tail >= strip.numPixels()) { // Advance tail, wrap around - tail = 0; - } - lastTime = millis(); // Save time of last movement - } - } -} - -void pulseWhite(uint8_t wait) { - for(int j=0; j<256; j++) { // Ramp up from 0 to 255 - // Fill entire strip with white at gamma-corrected brightness level 'j': - strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); - strip.show(); - delay(wait); - } - - for(int j=255; j>=0; j--) { // Ramp down from 255 to 0 - strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); - strip.show(); - delay(wait); - } -} - -void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) { - int fadeVal=0, fadeMax=100; - - // Hue of first pixel runs 'rainbowLoops' complete loops through the color - // wheel. Color wheel has a range of 65536 but it's OK if we roll over, so - // just count from 0 to rainbowLoops*65536, using steps of 256 so we - // advance around the wheel at a decent clip. - for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536; - firstPixelHue += 256) { - - for(int i=0; i= ((rainbowLoops-1) * 65536)) { // Last loop, - if(fadeVal > 0) fadeVal--; // fade out - } else { - fadeVal = fadeMax; // Interim loop, make sure fade is at max - } - } - - for(int k=0; k=0; j--) { // Ramp down 255 to 0 - strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); - strip.show(); - } - } - - delay(500); // Pause 1/2 second -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.arduinoble.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.arduinoble.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.none.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.none.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.test.skip b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino deleted file mode 100644 index 80e02d21b3..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino +++ /dev/null @@ -1,231 +0,0 @@ -/**************************************************************************** - * This example is based on StrandtestBLE example and adapts it to use - * the new ArduinoBLE library. - * - * https://github.com/arduino-libraries/ArduinoBLE - * - * Supported boards: - * Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - * - * You can use a generic BLE central app, like LightBlue (iOS and Android) or - * nRF Connect (Android), to interact with the services and characteristics - * created in this sketch. - * - * This example code is in the public domain. - * - */ -#include - -#define PIN 15 // Pin where NeoPixels are connected - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -uint8_t rgb_values[3]; - -#include - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service - -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - -void setup() -{ - Serial.begin(115200); - Serial.println("Hello World!"); - - // custom services and characteristics can be added as well - // begin initialization - if (!BLE.begin()) - { - Serial.println("starting BLE failed!"); - - while (1) - ; - } - - Serial.print("Peripheral address: "); - Serial.println(BLE.address()); - - // set advertised local name and service UUID: - BLE.setLocalName("LED"); - BLE.setAdvertisedService(ledService); - - // add the characteristic to the service - ledService.addCharacteristic(switchCharacteristic); - - // add service - BLE.addService(ledService); - - // set the initial value for the characeristic: - switchCharacteristic.writeValue(0); - - // start advertising - BLE.advertise(); - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - - pinMode(PIN, OUTPUT); - digitalWrite(PIN, LOW); - -} - -void loop() -{ - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) - { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - - // while the central is still connected to peripheral: - while (central.connected()) - { - // if the remote device wrote to the characteristic, - // use the value to control the LED: - if (switchCharacteristic.written()) - { - switch (switchCharacteristic.value()) - { - case 'a': - colorWipe(strip.Color(255, 0, 0), 20); // Red - break; - case 'b': - colorWipe(strip.Color(0, 255, 0), 20); // Green - break; - case 'c': - colorWipe(strip.Color(0, 0, 255), 20); // Blue - break; - case 'd': - theaterChase(strip.Color(255, 0, 0), 20); // Red - break; - case 'e': - theaterChase(strip.Color(0, 255, 0), 20); // Green - break; - case 'f': - theaterChase(strip.Color(255, 0, 255), 20); // Cyan - break; - case 'g': - rainbow(10); - break; - case 'h': - theaterChaseRainbow(20); - break; - } - } - } - } -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) -{ - for (int i = 0; i < strip.numPixels(); i++) - { // For each pixel in strip... - strip.setPixelColor(i, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - delay(wait); // Pause for a moment - } -} - -// Theater-marquee-style chasing lights. Pass in a color (32-bit value, -// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) -// between frames. -void theaterChase(uint32_t color, int wait) -{ - for (int a = 0; a < 10; a++) - { // Repeat 10 times... - for (int b = 0; b < 3; b++) - { // 'b' counts from 0 to 2... - strip.clear(); // Set all pixels in RAM to 0 (off) - // 'c' counts up from 'b' to end of strip in steps of 3... - for (int c = b; c < strip.numPixels(); c += 3) - { - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - } - } -} - -// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. -void rainbow(int wait) -{ - // Hue of first pixel runs 5 complete loops through the color wheel. - // Color wheel has a range of 65536 but it's OK if we roll over, so - // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time - // means we'll make 5*65536/256 = 1280 passes through this outer loop: - for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) - { - for (int i = 0; i < strip.numPixels(); i++) - { // For each pixel in strip... - // Offset pixel hue by an amount to make one full revolution of the - // color wheel (range of 65536) along the length of the strip - // (strip.numPixels() steps): - int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); - // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or - // optionally add saturation and value (brightness) (each 0 to 255). - // Here we're using just the single-argument hue variant. The result - // is passed through strip.gamma32() to provide 'truer' colors - // before assigning to each pixel: - strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - } -} - -// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames. -void theaterChaseRainbow(int wait) -{ - int firstPixelHue = 0; // First pixel starts at red (hue 0) - for (int a = 0; a < 30; a++) - { // Repeat 30 times... - for (int b = 0; b < 3; b++) - { // 'b' counts from 0 to 2... - strip.clear(); // Set all pixels in RAM to 0 (off) - // 'c' counts up from 'b' to end of strip in increments of 3... - for (int c = b; c < strip.numPixels(); c += 3) - { - // hue of pixel 'c' is offset by an amount to make one full - // revolution of the color wheel (range 65536) along the length - // of the strip (strip.numPixels() steps): - int hue = firstPixelHue + c * 65536L / strip.numPixels(); - uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.arduinoble.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.arduinoble.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.none.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.none.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.test.skip b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino deleted file mode 100644 index b986943ae4..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino +++ /dev/null @@ -1,239 +0,0 @@ -/**************************************************************************** - * This example is based on StrandtestArduinoBLE example to make use of - * callbacks features of the ArduinoBLE library. - * - * https://github.com/arduino-libraries/ArduinoBLE - * - * Supported boards: - * Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - * - * You can use a generic BLE central app, like LightBlue (iOS and Android) or - * nRF Connect (Android), to interact with the services and characteristics - * created in this sketch. - * - * This example code is in the public domain. - * - */ -#include - -#define PIN 15 // Pin where NeoPixels are connected - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -uint8_t rgb_values[3]; - -#include - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service - -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - -void setup() -{ - Serial.begin(115200); - Serial.println("Hello World!"); - - // custom services and characteristics can be added as well - // begin initialization - if (!BLE.begin()) - { - Serial.println("starting BLE failed!"); - - while (1) - ; - } - - Serial.print("Peripheral address: "); - Serial.println(BLE.address()); - - // set advertised local name and service UUID: - BLE.setLocalName("LEDCallback"); - BLE.setAdvertisedService(ledService); - - // add the characteristic to the service - ledService.addCharacteristic(switchCharacteristic); - - // add service - BLE.addService(ledService); - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - - // assign event handlers for characteristic - switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); - // set the initial value for the characeristic: - switchCharacteristic.writeValue(0); - - // start advertising - BLE.advertise(); - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - - pinMode(PIN, OUTPUT); - digitalWrite(PIN, LOW); -} - -void loop() -{ - // poll for BLE events - BLE.poll(); -} - -void blePeripheralConnectHandler(BLEDevice central) -{ - // central connected event handler - Serial.print("Connected event, central: "); - Serial.println(central.address()); -} - -void blePeripheralDisconnectHandler(BLEDevice central) -{ - // central disconnected event handler - Serial.print("Disconnected event, central: "); - Serial.println(central.address()); -} - -void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) -{ - // central wrote new value to characteristic, update LED - Serial.print("Characteristic event, written: "); - - switch (switchCharacteristic.value()) - { - case 'a': - colorWipe(strip.Color(255, 0, 0), 20); // Red - break; - case 'b': - colorWipe(strip.Color(0, 255, 0), 20); // Green - break; - case 'c': - colorWipe(strip.Color(0, 0, 255), 20); // Blue - break; - case 'd': - theaterChase(strip.Color(255, 0, 0), 20); // Red - break; - case 'e': - theaterChase(strip.Color(0, 255, 0), 20); // Green - break; - case 'f': - theaterChase(strip.Color(255, 0, 255), 20); // Cyan - break; - case 'g': - rainbow(10); - break; - case 'h': - theaterChaseRainbow(20); - break; - } -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) -{ - for (int i = 0; i < strip.numPixels(); i++) - { // For each pixel in strip... - strip.setPixelColor(i, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - delay(wait); // Pause for a moment - } -} - -// Theater-marquee-style chasing lights. Pass in a color (32-bit value, -// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) -// between frames. -void theaterChase(uint32_t color, int wait) -{ - for (int a = 0; a < 10; a++) - { // Repeat 10 times... - for (int b = 0; b < 3; b++) - { // 'b' counts from 0 to 2... - strip.clear(); // Set all pixels in RAM to 0 (off) - // 'c' counts up from 'b' to end of strip in steps of 3... - for (int c = b; c < strip.numPixels(); c += 3) - { - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - } - } -} - -// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. -void rainbow(int wait) -{ - // Hue of first pixel runs 5 complete loops through the color wheel. - // Color wheel has a range of 65536 but it's OK if we roll over, so - // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time - // means we'll make 5*65536/256 = 1280 passes through this outer loop: - for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) - { - for (int i = 0; i < strip.numPixels(); i++) - { // For each pixel in strip... - // Offset pixel hue by an amount to make one full revolution of the - // color wheel (range of 65536) along the length of the strip - // (strip.numPixels() steps): - int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); - // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or - // optionally add saturation and value (brightness) (each 0 to 255). - // Here we're using just the single-argument hue variant. The result - // is passed through strip.gamma32() to provide 'truer' colors - // before assigning to each pixel: - strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - } -} - -// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames. -void theaterChaseRainbow(int wait) -{ - int firstPixelHue = 0; // First pixel starts at red (hue 0) - for (int a = 0; a < 30; a++) - { // Repeat 30 times... - for (int b = 0; b < 3; b++) - { // 'b' counts from 0 to 2... - strip.clear(); // Set all pixels in RAM to 0 (off) - // 'c' counts up from 'b' to end of strip in increments of 3... - for (int c = b; c < strip.numPixels(); c += 3) - { - // hue of pixel 'c' is offset by an amount to make one full - // revolution of the color wheel (range 65536) along the length - // of the strip (strip.numPixels() steps): - int hue = firstPixelHue + c * 65536L / strip.numPixels(); - uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.arduinoble.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.arduinoble.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.none.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.none.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.test.skip b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp deleted file mode 100644 index d1693dec86..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "BLESerial.h" - -// #define BLE_SERIAL_DEBUG - -BLESerial* BLESerial::_instance = NULL; - -BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) : - BLEPeripheral(req, rdy, rst) -{ - this->_txCount = 0; - this->_rxHead = this->_rxTail = 0; - this->_flushed = 0; - BLESerial::_instance = this; - - addAttribute(this->_uartService); - addAttribute(this->_uartNameDescriptor); - setAdvertisedServiceUuid(this->_uartService.uuid()); - addAttribute(this->_rxCharacteristic); - addAttribute(this->_rxNameDescriptor); - this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received); - addAttribute(this->_txCharacteristic); - addAttribute(this->_txNameDescriptor); -} - -void BLESerial::begin(...) { - BLEPeripheral::begin(); - #ifdef BLE_SERIAL_DEBUG - Serial.println(F("BLESerial::begin()")); - #endif -} - -void BLESerial::poll() { - if (millis() < this->_flushed + 100) { - BLEPeripheral::poll(); - } else { - flush(); - } -} - -void BLESerial::end() { - this->_rxCharacteristic.setEventHandler(BLEWritten, NULL); - this->_rxHead = this->_rxTail = 0; - flush(); - BLEPeripheral::disconnect(); -} - -int BLESerial::available(void) { - BLEPeripheral::poll(); - int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::available() = ")); - Serial.println(retval); - #endif - return retval; -} - -int BLESerial::peek(void) { - BLEPeripheral::poll(); - if (this->_rxTail == this->_rxHead) return -1; - uint8_t byte = this->_rxBuffer[this->_rxTail]; - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::peek() = ")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.println(byte, HEX); - #endif - return byte; -} - -int BLESerial::read(void) { - BLEPeripheral::poll(); - if (this->_rxTail == this->_rxHead) return -1; - this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer); - uint8_t byte = this->_rxBuffer[this->_rxTail]; - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::read() = ")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.println(byte, HEX); - #endif - return byte; -} - -void BLESerial::flush(void) { - if (this->_txCount == 0) return; - this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount); - this->_flushed = millis(); - this->_txCount = 0; - BLEPeripheral::poll(); - #ifdef BLE_SERIAL_DEBUG - Serial.println(F("BLESerial::flush()")); - #endif -} - -size_t BLESerial::write(uint8_t byte) { - BLEPeripheral::poll(); - if (this->_txCharacteristic.subscribed() == false) return 0; - this->_txBuffer[this->_txCount++] = byte; - if (this->_txCount == sizeof(this->_txBuffer)) flush(); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::write(")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.print(byte, HEX); - Serial.println(F(") = 1")); - #endif - return 1; -} - -BLESerial::operator bool() { - bool retval = BLEPeripheral::connected(); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::operator bool() = ")); - Serial.println(retval); - #endif - return retval; -} - -void BLESerial::_received(const uint8_t* data, size_t size) { - for (int i = 0; i < size; i++) { - this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer); - this->_rxBuffer[this->_rxHead] = data[i]; - } - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::received(")); - for (int i = 0; i < size; i++) Serial.print((char) data[i]); - Serial.println(F(")")); - #endif -} - -void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) { - BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength()); -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h deleted file mode 100644 index 01904c7885..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _BLE_SERIAL_H_ -#define _BLE_SERIAL_H_ - -#include -#include - -class BLESerial : public BLEPeripheral, public Stream -{ - public: - BLESerial(unsigned char req, unsigned char rdy, unsigned char rst); - - void begin(...); - void poll(); - void end(); - - virtual int available(void); - virtual int peek(void); - virtual int read(void); - virtual void flush(void); - virtual size_t write(uint8_t byte); - using Print::write; - virtual operator bool(); - - private: - unsigned long _flushed; - static BLESerial* _instance; - - size_t _rxHead; - size_t _rxTail; - size_t _rxCount() const; - uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; - size_t _txCount; - uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; - - BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E"); - BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART"); - BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); - BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)"); - BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); - BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)"); - - void _received(const uint8_t* data, size_t size); - static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic); -}; - -#endif diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino deleted file mode 100644 index 593b35b6d5..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** - * This example was developed by the Hackerspace San Salvador to demonstrate - * the simultaneous use of the NeoPixel library and the Bluetooth SoftDevice. - * To compile this example you'll need to add support for the NRF52 based - * following the instructions at: - * https://github.com/sandeepmistry/arduino-nRF5 - * Or adding the following URL to the board manager URLs on Arduino preferences: - * https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json - * Then you can install the BLEPeripheral library avaiable at: - * https://github.com/sandeepmistry/arduino-BLEPeripheral - * To test it, compile this example and use the UART module from the nRF - * Toolbox App for Android. Edit the interface and send the characters - * 'a' to 'i' to switch the animation. - * There is a delay because this example blocks the thread of execution but - * the change will be shown after the current animation ends. (This might - * take a couple of seconds) - * For more info write us at: info _at- teubi.co - */ -#include -#include -#include "BLESerial.h" -#include - -#define PIN 15 // Pin where NeoPixels are connected - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -// define pins (varies per shield/board) -#define BLE_REQ 10 -#define BLE_RDY 2 -#define BLE_RST 9 - -// create ble serial instance, see pinouts above -BLESerial BLESerial(BLE_REQ, BLE_RDY, BLE_RST); - -uint8_t current_state = 0; -uint8_t rgb_values[3]; - -void setup() { - Serial.begin(115200); - Serial.println("Hello World!"); - // custom services and characteristics can be added as well - BLESerial.setLocalName("UART_HS"); - BLESerial.begin(); - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - - //pinMode(PIN, OUTPUT); - //digitalWrite(PIN, LOW); - - current_state = 'a'; -} - -void loop() { - while(BLESerial.available()) { - uint8_t character = BLESerial.read(); - switch(character) { - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - current_state = character; - break; - }; - } - switch(current_state) { - case 'a': - colorWipe(strip.Color(255, 0, 0), 20); // Red - break; - case 'b': - colorWipe(strip.Color( 0, 255, 0), 20); // Green - break; - case 'c': - colorWipe(strip.Color( 0, 0, 255), 20); // Blue - break; - case 'd': - theaterChase(strip.Color(255, 0, 0), 20); // Red - break; - case 'e': - theaterChase(strip.Color( 0, 255, 0), 20); // Green - break; - case 'f': - theaterChase(strip.Color(255, 0, 255), 20); // Cyan - break; - case 'g': - rainbow(10); - break; - case 'h': - theaterChaseRainbow(20); - break; - } -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - for(int i=0; i RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only deleted file mode 100644 index 8b13789179..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp b/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp deleted file mode 100644 index d1693dec86..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "BLESerial.h" - -// #define BLE_SERIAL_DEBUG - -BLESerial* BLESerial::_instance = NULL; - -BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) : - BLEPeripheral(req, rdy, rst) -{ - this->_txCount = 0; - this->_rxHead = this->_rxTail = 0; - this->_flushed = 0; - BLESerial::_instance = this; - - addAttribute(this->_uartService); - addAttribute(this->_uartNameDescriptor); - setAdvertisedServiceUuid(this->_uartService.uuid()); - addAttribute(this->_rxCharacteristic); - addAttribute(this->_rxNameDescriptor); - this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received); - addAttribute(this->_txCharacteristic); - addAttribute(this->_txNameDescriptor); -} - -void BLESerial::begin(...) { - BLEPeripheral::begin(); - #ifdef BLE_SERIAL_DEBUG - Serial.println(F("BLESerial::begin()")); - #endif -} - -void BLESerial::poll() { - if (millis() < this->_flushed + 100) { - BLEPeripheral::poll(); - } else { - flush(); - } -} - -void BLESerial::end() { - this->_rxCharacteristic.setEventHandler(BLEWritten, NULL); - this->_rxHead = this->_rxTail = 0; - flush(); - BLEPeripheral::disconnect(); -} - -int BLESerial::available(void) { - BLEPeripheral::poll(); - int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::available() = ")); - Serial.println(retval); - #endif - return retval; -} - -int BLESerial::peek(void) { - BLEPeripheral::poll(); - if (this->_rxTail == this->_rxHead) return -1; - uint8_t byte = this->_rxBuffer[this->_rxTail]; - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::peek() = ")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.println(byte, HEX); - #endif - return byte; -} - -int BLESerial::read(void) { - BLEPeripheral::poll(); - if (this->_rxTail == this->_rxHead) return -1; - this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer); - uint8_t byte = this->_rxBuffer[this->_rxTail]; - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::read() = ")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.println(byte, HEX); - #endif - return byte; -} - -void BLESerial::flush(void) { - if (this->_txCount == 0) return; - this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount); - this->_flushed = millis(); - this->_txCount = 0; - BLEPeripheral::poll(); - #ifdef BLE_SERIAL_DEBUG - Serial.println(F("BLESerial::flush()")); - #endif -} - -size_t BLESerial::write(uint8_t byte) { - BLEPeripheral::poll(); - if (this->_txCharacteristic.subscribed() == false) return 0; - this->_txBuffer[this->_txCount++] = byte; - if (this->_txCount == sizeof(this->_txBuffer)) flush(); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::write(")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.print(byte, HEX); - Serial.println(F(") = 1")); - #endif - return 1; -} - -BLESerial::operator bool() { - bool retval = BLEPeripheral::connected(); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::operator bool() = ")); - Serial.println(retval); - #endif - return retval; -} - -void BLESerial::_received(const uint8_t* data, size_t size) { - for (int i = 0; i < size; i++) { - this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer); - this->_rxBuffer[this->_rxHead] = data[i]; - } - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::received(")); - for (int i = 0; i < size; i++) Serial.print((char) data[i]); - Serial.println(F(")")); - #endif -} - -void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) { - BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength()); -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h b/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h deleted file mode 100644 index 01904c7885..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _BLE_SERIAL_H_ -#define _BLE_SERIAL_H_ - -#include -#include - -class BLESerial : public BLEPeripheral, public Stream -{ - public: - BLESerial(unsigned char req, unsigned char rdy, unsigned char rst); - - void begin(...); - void poll(); - void end(); - - virtual int available(void); - virtual int peek(void); - virtual int read(void); - virtual void flush(void); - virtual size_t write(uint8_t byte); - using Print::write; - virtual operator bool(); - - private: - unsigned long _flushed; - static BLESerial* _instance; - - size_t _rxHead; - size_t _rxTail; - size_t _rxCount() const; - uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; - size_t _txCount; - uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; - - BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E"); - BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART"); - BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); - BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)"); - BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); - BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)"); - - void _received(const uint8_t* data, size_t size); - static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic); -}; - -#endif diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino b/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino deleted file mode 100644 index 20c924d014..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** - * This example was developed by the Hackerspace San Salvador to demonstrate - * the simultaneous use of the NeoPixel library and the Bluetooth SoftDevice. - * To compile this example you'll need to add support for the NRF52 based - * following the instructions at: - * https://github.com/sandeepmistry/arduino-nRF5 - * Or adding the following URL to the board manager URLs on Arduino preferences: - * https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json - * Then you can install the BLEPeripheral library avaiable at: - * https://github.com/sandeepmistry/arduino-BLEPeripheral - * To test it, compile this example and use the UART module from the nRF - * Toolbox App for Android. Edit the interface and send the characters - * 'a' to 'i' to switch the animation. - * There is a no delay because this example does not block the threads execution - * so the change will be shown immediately and will not need to wait for the current - * animation to end. - * For more info write us at: info _at- teubi.co - */ -#include -#include -#include "BLESerial.h" -#include - -#define PIN 15 // Pin where NeoPixels are connected - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -// define pins (varies per shield/board) -#define BLE_REQ 10 -#define BLE_RDY 2 -#define BLE_RST 9 - -// create ble serial instance, see pinouts above -BLESerial BLESerial(BLE_REQ, BLE_RDY, BLE_RST); - -uint8_t current_state = 0; -uint8_t rgb_values[3]; - -void setup() { - Serial.begin(115200); - Serial.println("Hello World!"); - // custom services and characteristics can be added as well - BLESerial.setLocalName("UART_HS"); - BLESerial.begin(); - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - - //pinMode(PIN, OUTPUT); - //digitalWrite(PIN, LOW); - - current_state = 'a'; -} - -void loop() { - while(BLESerial.available()) { - uint8_t character = BLESerial.read(); - switch(character) { - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - current_state = character; - break; - }; - } - switch(current_state) { - case 'a': - colorWipe(strip.Color(255, 0, 0), 20); // Red - break; - case 'b': - colorWipe(strip.Color( 0, 255, 0), 20); // Green - break; - case 'c': - colorWipe(strip.Color( 0, 0, 255), 20); // Blue - break; - case 'd': - theaterChase(strip.Color(255, 0, 0), 20); // Red - break; - case 'e': - theaterChase(strip.Color( 0, 255, 0), 20); // Green - break; - case 'f': - theaterChase(strip.Color(255, 0, 255), 20); // Cyan - break; - case 'g': - rainbow(10); - break; - case 'h': - theaterChaseRainbow(20); - break; - } -} - -// Some functions of our own for creating animated effects ----------------- - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - pixelCurrent++; // Advance current pixel - if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED - pixelCurrent = 0; -} - -// Theater-marquee-style chasing lights. Pass in a color (32-bit value, -// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) -// between frames. -void theaterChase(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i = 0; i < pixelNumber; i++) { - strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM) - } - strip.show(); // Update strip to match - for(int i=0; i < pixelNumber; i+3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM) - } - pixelQueue++; // Advance current pixel - if(pixelQueue >= 3) - pixelQueue = 0; // Loop the pattern from the first LED -} - -// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. -void rainbow(uint8_t wait) { - if(pixelInterval != wait) - pixelInterval = wait; - for(uint16_t i=0; i < pixelNumber; i++) { - strip.setPixelColor(i, Wheel((i + pixelCycle) & 255)); // Update delay time - } - strip.show(); // Update strip to match - pixelCycle++; // Advance current cycle - if(pixelCycle >= 256) - pixelCycle = 0; // Loop the cycle back to the begining -} - -//Theatre-style crawling lights with rainbow effect -void theaterChaseRainbow(uint8_t wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i=0; i < pixelNumber; i+3) { - strip.setPixelColor(i + pixelQueue, Wheel((i + pixelCycle) % 255)); // Update delay time - } - strip.show(); - for(int i=0; i < pixelNumber; i+3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Update delay time - } - pixelQueue++; // Advance current queue - pixelCycle++; // Advance current cycle - if(pixelQueue >= 3) - pixelQueue = 0; // Loop - if(pixelCycle >= 256) - pixelCycle = 0; // Loop -} - -// Input a value 0 to 255 to get a color value. -// The colours are a transition r - g - b - back to r. -uint32_t Wheel(byte WheelPos) { - WheelPos = 255 - WheelPos; - if(WheelPos < 85) { - return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); - } - if(WheelPos < 170) { - WheelPos -= 85; - return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); - } - WheelPos -= 170; - return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); -} diff --git a/lib/Adafruit_NeoPixel/examples/buttoncycler/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/buttoncycler/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino b/lib/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino deleted file mode 100644 index f6d87edcb3..0000000000 --- a/lib/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino +++ /dev/null @@ -1,164 +0,0 @@ -// Simple demonstration on using an input device to trigger changes on your -// NeoPixels. Wire a momentary push button to connect from ground to a -// digital IO pin. When the button is pressed it will change to a new pixel -// animation. Initial state has all pixels off -- press the button once to -// start the first animation. As written, the button does not interrupt an -// animation in-progress, it works only when idle. - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Digital IO pin connected to the button. This will be driven with a -// pull-up resistor so the switch pulls the pin to ground momentarily. -// On a high -> low transition the button press logic will execute. -#define BUTTON_PIN 2 - -#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels. - -#define PIXEL_COUNT 16 // Number of NeoPixels - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -boolean oldState = HIGH; -int mode = 0; // Currently-active animation mode, 0-9 - -void setup() { - pinMode(BUTTON_PIN, INPUT_PULLUP); - strip.begin(); // Initialize NeoPixel strip object (REQUIRED) - strip.show(); // Initialize all pixels to 'off' -} - -void loop() { - // Get current button state. - boolean newState = digitalRead(BUTTON_PIN); - - // Check if state changed from high to low (button press). - if((newState == LOW) && (oldState == HIGH)) { - // Short delay to debounce button. - delay(20); - // Check if button is still low after debounce. - newState = digitalRead(BUTTON_PIN); - if(newState == LOW) { // Yes, still low - if(++mode > 8) mode = 0; // Advance to next mode, wrap around after #8 - switch(mode) { // Start the new animation... - case 0: - colorWipe(strip.Color( 0, 0, 0), 50); // Black/off - break; - case 1: - colorWipe(strip.Color(255, 0, 0), 50); // Red - break; - case 2: - colorWipe(strip.Color( 0, 255, 0), 50); // Green - break; - case 3: - colorWipe(strip.Color( 0, 0, 255), 50); // Blue - break; - case 4: - theaterChase(strip.Color(127, 127, 127), 50); // White - break; - case 5: - theaterChase(strip.Color(127, 0, 0), 50); // Red - break; - case 6: - theaterChase(strip.Color( 0, 0, 127), 50); // Blue - break; - case 7: - rainbow(10); - break; - case 8: - theaterChaseRainbow(50); - break; - } - } - } - - // Set the last-read button state to the old state. - oldState = newState; -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - for(int i=0; i RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/simple/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/simple/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/simple/simple.ino b/lib/Adafruit_NeoPixel/examples/simple/simple.ino deleted file mode 100644 index 09f458ecbe..0000000000 --- a/lib/Adafruit_NeoPixel/examples/simple/simple.ino +++ /dev/null @@ -1,50 +0,0 @@ -// NeoPixel Ring simple sketch (c) 2013 Shae Erisson -// Released under the GPLv3 license to match the rest of the -// Adafruit NeoPixel library - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -#define PIN 6 // On Trinket or Gemma, suggest changing this to 1 - -// How many NeoPixels are attached to the Arduino? -#define NUMPIXELS 16 // Popular NeoPixel ring size - -// When setting up the NeoPixel library, we tell it how many pixels, -// and which pin to use to send signals. Note that for older NeoPixel -// strips you might need to change the third parameter -- see the -// strandtest example for more information on possible values. -Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); - -#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels - -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) -} - -void loop() { - pixels.clear(); // Set all pixel colors to 'off' - - // The first NeoPixel in a strand is #0, second is 1, all the way up - // to the count of pixels minus one. - for(int i=0; i -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -int pin = 6; // On Trinket or Gemma, suggest changing this to 1 - -// How many NeoPixels are attached to the Arduino? -int numPixels = 16; // Popular NeoPixel ring size - -// NeoPixel color format & data rate. See the strandtest example for -// information on possible values. -int pixelFormat = NEO_GRB + NEO_KHZ800; - -// Rather than declaring the whole NeoPixel object here, we just create -// a pointer for one, which we'll then allocate later... -Adafruit_NeoPixel *pixels; - -#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels - -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - // Right about here is where we could read 'pin', 'numPixels' and/or - // 'pixelFormat' from EEPROM or a file on SD or whatever. This is a simple - // example and doesn't do that -- those variables are just set to fixed - // values at the top of this code -- but this is where it would happen. - - // Then create a new NeoPixel object dynamically with these values: - pixels = new Adafruit_NeoPixel(numPixels, pin, pixelFormat); - - // Going forward from here, code works almost identically to any other - // NeoPixel example, but instead of the dot operator on function calls - // (e.g. pixels.begin()), we instead use pointer indirection (->) like so: - pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - // You'll see more of this in the loop() function below. -} - -void loop() { - pixels->clear(); // Set all pixel colors to 'off' - - // The first NeoPixel in a strand is #0, second is 1, all the way up - // to the count of pixels minus one. - for(int i=0; iColor() takes RGB values, from 0,0,0 up to 255,255,255 - // Here we're using a moderately bright green color: - pixels->setPixelColor(i, pixels->Color(0, 150, 0)); - - pixels->show(); // Send the updated pixel colors to the hardware. - - delay(DELAYVAL); // Pause before next pass through loop - } -} diff --git a/lib/Adafruit_NeoPixel/examples/strandtest/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/strandtest/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/strandtest/strandtest.ino b/lib/Adafruit_NeoPixel/examples/strandtest/strandtest.ino deleted file mode 100644 index f4554cc82a..0000000000 --- a/lib/Adafruit_NeoPixel/examples/strandtest/strandtest.ino +++ /dev/null @@ -1,143 +0,0 @@ -// A basic everyday NeoPixel strip test program. - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -// On a Trinket or Gemma we suggest changing this to 1: -#define LED_PIN 6 - -// How many NeoPixels are attached to the Arduino? -#define LED_COUNT 60 - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - - -// setup() function -- runs once at startup -------------------------------- - -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) -} - - -// loop() function -- runs repeatedly as long as board is on --------------- - -void loop() { - // Fill along the length of the strip in various colors... - colorWipe(strip.Color(255, 0, 0), 50); // Red - colorWipe(strip.Color( 0, 255, 0), 50); // Green - colorWipe(strip.Color( 0, 0, 255), 50); // Blue - - // Do a theater marquee effect in various colors... - theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness - theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness - theaterChase(strip.Color( 0, 0, 127), 50); // Blue, half brightness - - rainbow(10); // Flowing rainbow cycle along the whole strip - theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant -} - - -// Some functions of our own for creating animated effects ----------------- - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - for(int i=0; i RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip deleted file mode 100644 index 8b13789179..0000000000 --- a/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino b/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino deleted file mode 100644 index 9c392e2be7..0000000000 --- a/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino +++ /dev/null @@ -1,186 +0,0 @@ -// A non-blocking everyday NeoPixel strip test program. - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -// On a Trinket or Gemma we suggest changing this to 1: -#ifdef ESP32 -// Cannot use 6 as output for ESP. Pins 6-11 are connected to SPI flash. Use 16 instead. -#define LED_PIN 16 -#else -#define LED_PIN 6 -#endif - -// How many NeoPixels are attached to the Arduino? -#define LED_COUNT 60 - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -unsigned long pixelPrevious = 0; // Previous Pixel Millis -unsigned long patternPrevious = 0; // Previous Pattern Millis -int patternCurrent = 0; // Current Pattern Number -int patternInterval = 5000; // Pattern Interval (ms) -int pixelInterval = 50; // Pixel Interval (ms) -int pixelQueue = 0; // Pattern Pixel Queue -int pixelCycle = 0; // Pattern Pixel Cycle -uint16_t pixelCurrent = 0; // Pattern Current Pixel Number -uint16_t pixelNumber = LED_COUNT; // Total Number of Pixels - -// setup() function -- runs once at startup -------------------------------- -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) -} - -// loop() function -- runs repeatedly as long as board is on --------------- -void loop() { - unsigned long currentMillis = millis(); // Update current time - if((currentMillis - patternPrevious) >= patternInterval) { // Check for expired time - patternPrevious = currentMillis; - patternCurrent++; // Advance to next pattern - if(patternCurrent >= 7) - patternCurrent = 0; - } - - if(currentMillis - pixelPrevious >= pixelInterval) { // Check for expired time - pixelPrevious = currentMillis; // Run current frame - switch (patternCurrent) { - case 7: - theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant - break; - case 6: - rainbow(10); // Flowing rainbow cycle along the whole strip - break; - case 5: - theaterChase(strip.Color(0, 0, 127), 50); // Blue - break; - case 4: - theaterChase(strip.Color(127, 0, 0), 50); // Red - break; - case 3: - theaterChase(strip.Color(127, 127, 127), 50); // White - break; - case 2: - colorWipe(strip.Color(0, 0, 255), 50); // Blue - break; - case 1: - colorWipe(strip.Color(0, 255, 0), 50); // Green - break; - default: - colorWipe(strip.Color(255, 0, 0), 50); // Red - break; - } - } -} - -// Some functions of our own for creating animated effects ----------------- - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - pixelCurrent++; // Advance current pixel - if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED - pixelCurrent = 0; -} - -// Theater-marquee-style chasing lights. Pass in a color (32-bit value, -// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) -// between frames. -void theaterChase(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i = 0; i < pixelNumber; i++) { - strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM) - } - strip.show(); // Update strip to match - for(int i=0; i < pixelNumber; i+=3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM) - } - pixelQueue++; // Advance current pixel - if(pixelQueue >= 3) - pixelQueue = 0; // Loop the pattern from the first LED -} - -// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. -void rainbow(uint8_t wait) { - if(pixelInterval != wait) - pixelInterval = wait; - for(uint16_t i=0; i < pixelNumber; i++) { - strip.setPixelColor(i, Wheel((i + pixelCycle) & 255)); // Update delay time - } - strip.show(); // Update strip to match - pixelCycle++; // Advance current cycle - if(pixelCycle >= 256) - pixelCycle = 0; // Loop the cycle back to the begining -} - -//Theatre-style crawling lights with rainbow effect -void theaterChaseRainbow(uint8_t wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i=0; i < pixelNumber; i+=3) { - strip.setPixelColor(i + pixelQueue, Wheel((i + pixelCycle) % 255)); // Update delay time - } - strip.show(); - for(int i=0; i < pixelNumber; i+=3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Update delay time - } - pixelQueue++; // Advance current queue - pixelCycle++; // Advance current cycle - if(pixelQueue >= 3) - pixelQueue = 0; // Loop - if(pixelCycle >= 256) - pixelCycle = 0; // Loop -} - -// Input a value 0 to 255 to get a color value. -// The colours are a transition r - g - b - back to r. -uint32_t Wheel(byte WheelPos) { - WheelPos = 255 - WheelPos; - if(WheelPos < 85) { - return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); - } - if(WheelPos < 170) { - WheelPos -= 85; - return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); - } - WheelPos -= 170; - return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); -} diff --git a/lib/Adafruit_NeoPixel/examples/strandtest_wheel/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/strandtest_wheel/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino b/lib/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino deleted file mode 100644 index c0ca41edcb..0000000000 --- a/lib/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino +++ /dev/null @@ -1,134 +0,0 @@ -#include -#ifdef __AVR__ - #include -#endif - -#define PIN 6 - -// Parameter 1 = number of pixels in strip -// Parameter 2 = Arduino pin number (most are valid) -// Parameter 3 = pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) -Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800); - -// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across -// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input -// and minimize distance between Arduino and first pixel. Avoid connecting -// on a live circuit...if you must, connect GND first. - -void setup() { - // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket - #if defined (__AVR_ATtiny85__) - if (F_CPU == 16000000) clock_prescale_set(clock_div_1); - #endif - // End of trinket special code - - strip.begin(); - strip.setBrightness(50); - strip.show(); // Initialize all pixels to 'off' -} - -void loop() { - // Some example procedures showing how to display to the pixels: - colorWipe(strip.Color(255, 0, 0), 50); // Red - colorWipe(strip.Color(0, 255, 0), 50); // Green - colorWipe(strip.Color(0, 0, 255), 50); // Blue -//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW - // Send a theater pixel chase in... - theaterChase(strip.Color(127, 127, 127), 50); // White - theaterChase(strip.Color(127, 0, 0), 50); // Red - theaterChase(strip.Color(0, 0, 127), 50); // Blue - - rainbow(20); - rainbowCycle(20); - theaterChaseRainbow(50); -} - -// Fill the dots one after the other with a color -void colorWipe(uint32_t c, uint8_t wait) { - for(uint16_t i=0; i -#include "sysctl.h" - -void k210Show( - uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) -{ - -#define CYCLES_800_T0H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 2500000) // 0.4us -#define CYCLES_800_T1H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1250000) // 0.8us -#define CYCLES_800 (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 800000) // 1.25us per bit -#define CYCLES_400_T0H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 2000000) // 0.5uS -#define CYCLES_400_T1H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 833333) // 1.2us -#define CYCLES_400 (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 400000) // 2.5us per bit - - uint8_t *p, *end, pix, mask; - uint32_t t, time0, time1, period, c, startTime; - - p = pixels; - end = p + numBytes; - pix = *p++; - mask = 0x80; - startTime = 0; - -#ifdef NEO_KHZ400 - if (is800KHz) - { -#endif - time0 = CYCLES_800_T0H; - time1 = CYCLES_800_T1H; - period = CYCLES_800; -#ifdef NEO_KHZ400 - } - else - { // 400 KHz bitstream - time0 = CYCLES_400_T0H; - time1 = CYCLES_400_T1H; - period = CYCLES_400; - } -#endif - - for (t = time0;; t = time0) - { - if (pix & mask) - t = time1; // Bit high duration - while (((c = read_cycle()) - startTime) < period) - ; // Wait for bit start - digitalWrite(pin, HIGH); - startTime = c; // Save start time - while (((c = read_cycle()) - startTime) < t) - ; // Wait high duration - digitalWrite(pin, LOW); - - if (!(mask >>= 1)) - { // Next bit/byte - if (p >= end) - break; - pix = *p++; - mask = 0x80; - } - } - while ((read_cycle() - startTime) < period) - ; // Wait for last bit -} - -#endif // KENDRYTE_K210 diff --git a/lib/Adafruit_NeoPixel/keywords.txt b/lib/Adafruit_NeoPixel/keywords.txt deleted file mode 100644 index 4003ede9dc..0000000000 --- a/lib/Adafruit_NeoPixel/keywords.txt +++ /dev/null @@ -1,72 +0,0 @@ -####################################### -# Syntax Coloring Map For Adafruit_NeoPixel -####################################### -# Class -####################################### - -Adafruit_NeoPixel KEYWORD1 - -####################################### -# Methods and Functions -####################################### - -begin KEYWORD2 -show KEYWORD2 -setPin KEYWORD2 -setPixelColor KEYWORD2 -fill KEYWORD2 -setBrightness KEYWORD2 -clear KEYWORD2 -updateLength KEYWORD2 -updateType KEYWORD2 -canShow KEYWORD2 -getPixels KEYWORD2 -getBrightness KEYWORD2 -getPin KEYWORD2 -numPixels KEYWORD2 -getPixelColor KEYWORD2 -sine8 KEYWORD2 -gamma8 KEYWORD2 -Color KEYWORD2 -ColorHSV KEYWORD2 -gamma32 KEYWORD2 - -####################################### -# Constants -####################################### - -NEO_COLMASK LITERAL1 -NEO_SPDMASK LITERAL1 -NEO_KHZ800 LITERAL1 -NEO_KHZ400 LITERAL1 -NEO_RGB LITERAL1 -NEO_RBG LITERAL1 -NEO_GRB LITERAL1 -NEO_GBR LITERAL1 -NEO_BRG LITERAL1 -NEO_BGR LITERAL1 -NEO_WRGB LITERAL1 -NEO_WRBG LITERAL1 -NEO_WGRB LITERAL1 -NEO_WGBR LITERAL1 -NEO_WBRG LITERAL1 -NEO_WBGR LITERAL1 -NEO_RWGB LITERAL1 -NEO_RWBG LITERAL1 -NEO_RGWB LITERAL1 -NEO_RGBW LITERAL1 -NEO_RBWG LITERAL1 -NEO_RBGW LITERAL1 -NEO_GWRB LITERAL1 -NEO_GWBR LITERAL1 -NEO_GRWB LITERAL1 -NEO_GRBW LITERAL1 -NEO_GBWR LITERAL1 -NEO_GBRW LITERAL1 -NEO_BWRG LITERAL1 -NEO_BWGR LITERAL1 -NEO_BRWG LITERAL1 -NEO_BRGW LITERAL1 -NEO_BGWR LITERAL1 -NEO_BGRW LITERAL1 - diff --git a/lib/Adafruit_NeoPixel/library.properties b/lib/Adafruit_NeoPixel/library.properties deleted file mode 100644 index 7bbd4889ca..0000000000 --- a/lib/Adafruit_NeoPixel/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=Adafruit NeoPixel -version=1.10.6 -author=Adafruit -maintainer=Adafruit -sentence=Arduino library for controlling single-wire-based LED pixels and strip. -paragraph=Arduino library for controlling single-wire-based LED pixels and strip. -category=Display -url=https://github.com/adafruit/Adafruit_NeoPixel -architectures=* -includes=Adafruit_NeoPixel.h diff --git a/lib/Adafruit_NeoPixel/rp2040.c b/lib/Adafruit_NeoPixel/rp2040.c deleted file mode 100644 index 388a43bf2b..0000000000 --- a/lib/Adafruit_NeoPixel/rp2040.c +++ /dev/null @@ -1,53 +0,0 @@ -// This sketch is based on the SDK example here: -// https://github.com/raspberrypi/pico-examples/tree/master/pio/ws2812 - -/** - Copyright (c) 2020 Raspberry Pi (Trading) Ltd. - - SPDX-License-Identifier: BSD-3-Clause -*/ - -#if defined(ARDUINO_ARCH_RP2040) - -#include -#include "hardware/pio.h" -#include "hardware/clocks.h" - -#include "rp2040_pio.h" - -void rp2040Init(uint8_t pin, bool is800KHz) -{ - // todo get free sm - PIO pio = pio0; - int sm = 0; - uint offset = pio_add_program(pio, &ws2812_program); - - if (is800KHz) - { - // 800kHz, 8 bit transfers - ws2812_program_init(pio, sm, offset, pin, 800000, 8); - } - else - { - // 400kHz, 8 bit transfers - ws2812_program_init(pio, sm, offset, pin, 400000, 8); - } -} - -void rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) -{ - static bool init = true; - - if (init) - { - // On first pass through initialise the PIO - rp2040Init(pin, is800KHz); - init = false; - } - - while(numBytes--) - // Bits for transmission must be shifted to top 8 bits - pio_sm_put_blocking(pio0, 0, ((uint32_t)*pixels++)<< 24); -} - -#endif // KENDRYTE_K210 diff --git a/lib/Adafruit_NeoPixel/rp2040_pio.h b/lib/Adafruit_NeoPixel/rp2040_pio.h deleted file mode 100644 index f7ccd46de0..0000000000 --- a/lib/Adafruit_NeoPixel/rp2040_pio.h +++ /dev/null @@ -1,63 +0,0 @@ -// -------------------------------------------------- // -// This file is autogenerated by pioasm; do not edit! // -// -------------------------------------------------- // - -// Unless you know what you are doing... -// Lines 47 and 52 have been edited to set transmit bit count - -#if !PICO_NO_HARDWARE -#include "hardware/pio.h" -#endif - -// ------ // -// ws2812 // -// ------ // - -#define ws2812_wrap_target 0 -#define ws2812_wrap 3 - -#define ws2812_T1 2 -#define ws2812_T2 5 -#define ws2812_T3 3 - -static const uint16_t ws2812_program_instructions[] = { - // .wrap_target - 0x6221, // 0: out x, 1 side 0 [2] - 0x1123, // 1: jmp !x, 3 side 1 [1] - 0x1400, // 2: jmp 0 side 1 [4] - 0xa442, // 3: nop side 0 [4] - // .wrap -}; - -#if !PICO_NO_HARDWARE -static const struct pio_program ws2812_program = { - .instructions = ws2812_program_instructions, - .length = 4, - .origin = -1, -}; - -static inline pio_sm_config ws2812_program_get_default_config(uint offset) { - pio_sm_config c = pio_get_default_sm_config(); - sm_config_set_wrap(&c, offset + ws2812_wrap_target, offset + ws2812_wrap); - sm_config_set_sideset(&c, 1, false, false); - return c; -} - -#include "hardware/clocks.h" -static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, - float freq, uint bits) { - pio_gpio_init(pio, pin); - pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); - pio_sm_config c = ws2812_program_get_default_config(offset); - sm_config_set_sideset_pins(&c, pin); - sm_config_set_out_shift(&c, false, true, - bits); // <----<<< Length changed to "bits" - sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); - int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3; - float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit); - sm_config_set_clkdiv(&c, div); - pio_sm_init(pio, sm, offset, &c); - pio_sm_set_enabled(pio, sm, true); -} - -#endif From 7b8ebd71a43af7e5ea624b381eaa427acce48836 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 4 Nov 2023 14:28:02 +0100 Subject: [PATCH 22/25] [P131] Fix variable initialization, call begin() to start the NeoPixels --- src/src/PluginStructs/P131_data_struct.cpp | 5 +++-- src/src/PluginStructs/P131_data_struct.h | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/src/PluginStructs/P131_data_struct.cpp b/src/src/PluginStructs/P131_data_struct.cpp index 6ee9273b7e..7ec03ebab1 100644 --- a/src/src/PluginStructs/P131_data_struct.cpp +++ b/src/src/PluginStructs/P131_data_struct.cpp @@ -119,6 +119,7 @@ bool P131_data_struct::plugin_init(struct EventStruct *event) { if (success) { gfxHelper->initialize(); gfxHelper->setRotation(_rotation); + matrix->begin(); matrix->setBrightness(std::min(_maxbright, _brightness)); // Set brightness, so we don't get blinded by the light matrix->fillScreen(_bgcolor); // fill screen with black color matrix->show(); // Update the display @@ -264,8 +265,8 @@ void P131_data_struct::display_content(struct EventStruct *event, bool scrollOnly, uint8_t line) { if (isInitialized() && (nullptr != gfxHelper)) { - int16_t yPos = 0; - bool useVal = gfxHelper->getValidation(); + int16_t yPos = 0; + const bool useVal = gfxHelper->getValidation(); gfxHelper->setValidation(false); // Ignore validation to enable scrolling uint8_t x = 0; diff --git a/src/src/PluginStructs/P131_data_struct.h b/src/src/PluginStructs/P131_data_struct.h index 2c990c416a..4909822e7e 100644 --- a/src/src/PluginStructs/P131_data_struct.h +++ b/src/src/PluginStructs/P131_data_struct.h @@ -142,19 +142,20 @@ struct P131_data_struct : public PluginTaskData_base { Adafruit_NeoMatrix *matrix = nullptr; AdafruitGFX_helper *gfxHelper = nullptr; - uint8_t _matrixWidth = 8; - uint8_t _matrixHeight = 8; - uint8_t _tileWidth = 1; - uint8_t _tileHeight = 1; - int8_t _pin = -1; - uint8_t _matrixType = NEO_MATRIX_TOP | NEO_MATRIX_LEFT | NEO_MATRIX_ROWS | NEO_MATRIX_PROGRESSIVE; - uint8_t _ledType = NEO_TILE_TOP | NEO_TILE_LEFT | NEO_TILE_ROWS | NEO_TILE_PROGRESSIVE; - uint8_t _rotation = 0; - uint8_t _fontscaling = 1; - AdaGFXTextPrintMode _textmode = AdaGFXTextPrintMode::ContinueToNextLine; + uint8_t _matrixWidth = 8; + uint8_t _matrixHeight = 8; + uint8_t _tileWidth = 1; + uint8_t _tileHeight = 1; + int8_t _pin = -1; + uint8_t _matrixType = NEO_MATRIX_TOP | NEO_MATRIX_LEFT | NEO_MATRIX_ROWS | NEO_MATRIX_PROGRESSIVE | + NEO_TILE_TOP | NEO_TILE_LEFT | NEO_TILE_ROWS | NEO_TILE_PROGRESSIVE; + uint8_t _rotation = 0; + uint8_t _fontscaling = 1; + AdaGFXTextPrintMode _textmode = AdaGFXTextPrintMode::ContinueToNextLine; String _commandTrigger; uint8_t _brightness = 40; uint8_t _maxbright = 255; + neoPixelType _ledType = NEO_GRB + NEO_KHZ800; uint16_t _fgcolor = ADAGFX_WHITE; uint16_t _bgcolor = ADAGFX_BLACK; From 639a6cc8bb4beffaa6db5199e923a9cd8024e56c Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 4 Nov 2023 15:39:32 +0100 Subject: [PATCH 23/25] [P041] Uncrustify source, minor improvements --- src/_P041_NeoClock.ino | 347 ++++++++++++++++++++++++----------------- 1 file changed, 200 insertions(+), 147 deletions(-) diff --git a/src/_P041_NeoClock.ino b/src/_P041_NeoClock.ino index e0e804a33b..85a4ed5d5e 100644 --- a/src/_P041_NeoClock.ino +++ b/src/_P041_NeoClock.ino @@ -1,181 +1,185 @@ #include "_Plugin_Helper.h" #ifdef USES_P041 -//####################################################################################################### -//#################################### Plugin 041: NeoPixel clock ####################################### -//####################################################################################################### + +// ####################################################################################################### +// #################################### Plugin 041: NeoPixel clock ####################################### +// ####################################################################################################### /** Changelog: + * 2023-11-04 tonhuisman: Formatted source using Uncrustify + * Update display at plugin start (no need to wait for the first minute to pass) + * Minor improvements * 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library * 2023-10 tonhuisman: Add changelog. */ -#include +# include -#define NUM_LEDS 114 +# define NUM_LEDS 114 -uint8_t Plugin_041_red = 0; +uint8_t Plugin_041_red = 0; uint8_t Plugin_041_green = 0; -uint8_t Plugin_041_blue = 0; +uint8_t Plugin_041_blue = 0; -NeoPixelBus_wrapper *Plugin_041_pixels; +NeoPixelBus_wrapper *Plugin_041_pixels = nullptr; -#define PLUGIN_041 -#define PLUGIN_ID_041 41 -#define PLUGIN_NAME_041 "Output - NeoPixel (Word Clock)" -#define PLUGIN_VALUENAME1_041 "Clock" +# define PLUGIN_041 +# define PLUGIN_ID_041 41 +# define PLUGIN_NAME_041 "Output - NeoPixel (Word Clock)" +# define PLUGIN_VALUENAME1_041 "Clock" boolean Plugin_041(uint8_t function, struct EventStruct *event, String& string) { boolean success = false; switch (function) { - case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_041; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 0; - Device[deviceCount].SendDataOption = false; - break; - } + { + Device[++deviceCount].Number = PLUGIN_ID_041; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = false; + Device[deviceCount].ValueCount = 0; + Device[deviceCount].SendDataOption = false; + break; + } case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_041); - break; - } + { + string = F(PLUGIN_NAME_041); + break; + } case PLUGIN_GET_DEVICEVALUENAMES: - { - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_041)); - break; - } + { + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_041)); + break; + } case PLUGIN_GET_DEVICEGPIONAMES: - { - event->String1 = formatGpioName_output(F("Data")); - break; - } + { + event->String1 = formatGpioName_output(F("Data")); + break; + } case PLUGIN_WEBFORM_LOAD: - { - addFormNumericBox(F("Red"), F("red"), PCONFIG(0), 0, 255); - addFormNumericBox(F("Green"), F("green"), PCONFIG(1), 0, 255); - addFormNumericBox(F("Blue"), F("blue"), PCONFIG(2), 0, 255); - success = true; - break; - } + { + addFormNumericBox(F("Red"), F("red"), PCONFIG(0), 0, 255); + addFormNumericBox(F("Green"), F("green"), PCONFIG(1), 0, 255); + addFormNumericBox(F("Blue"), F("blue"), PCONFIG(2), 0, 255); + success = true; + break; + } case PLUGIN_WEBFORM_SAVE: - { - PCONFIG(0) = getFormItemInt(F("red")); - PCONFIG(1) = getFormItemInt(F("green")); - PCONFIG(2) = getFormItemInt(F("blue")); - Plugin_041_red = PCONFIG(0); - Plugin_041_green = PCONFIG(1); - Plugin_041_blue = PCONFIG(2); - success = true; - break; - } + { + PCONFIG(0) = getFormItemInt(F("red")); + PCONFIG(1) = getFormItemInt(F("green")); + PCONFIG(2) = getFormItemInt(F("blue")); + success = true; + break; + } case PLUGIN_INIT: + { + Plugin_041_red = PCONFIG(0); + Plugin_041_green = PCONFIG(1); + Plugin_041_blue = PCONFIG(2); + + if (Plugin_041_pixels == nullptr) { - if (Plugin_041_pixels == nullptr) - { - Plugin_041_pixels = new (std::nothrow) NeoPixelBus_wrapper(NUM_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); - if (Plugin_041_pixels != nullptr) { - Plugin_041_pixels->begin(); // This initializes the NeoPixel library. - } + Plugin_041_pixels = new (std::nothrow) NeoPixelBus_wrapper(NUM_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); + + if (Plugin_041_pixels != nullptr) { + Plugin_041_pixels->begin(); // This initializes the NeoPixel library. + Plugin_041_update(); } - Plugin_041_red = PCONFIG(0); - Plugin_041_green = PCONFIG(1); - Plugin_041_blue = PCONFIG(2); - success = Plugin_041_pixels != nullptr; - break; } + success = Plugin_041_pixels != nullptr; + break; + } case PLUGIN_EXIT: - { - if (Plugin_041_pixels != nullptr) { - delete Plugin_041_pixels; - Plugin_041_pixels = nullptr; - } - break; + { + if (Plugin_041_pixels != nullptr) { + delete Plugin_041_pixels; + Plugin_041_pixels = nullptr; } + break; + } case PLUGIN_CLOCK_IN: + { + Plugin_041_update(); + success = true; + break; + } + + case PLUGIN_ONCE_A_SECOND: + { + // int ldrVal = map(analogRead(A0), 0, 1023, 15, 245); + // serialPrint("LDR value: "); + // serialPrintln(ldrVal); + // Plugin_041_pixels->setBrightness(255-ldrVal); + // Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. + success = true; + break; + } + + case PLUGIN_WRITE: + { + String cmd = parseString(string, 1); + + if (equals(cmd, F("neoclockcolor"))) { + Plugin_041_red = event->Par1; + Plugin_041_green = event->Par2; + Plugin_041_blue = event->Par3; Plugin_041_update(); success = true; - break; } - case PLUGIN_ONCE_A_SECOND: + if (equals(cmd, F("neotestall"))) { - //int ldrVal = map(analogRead(A0), 0, 1023, 15, 245); - //serialPrint("LDR value: "); - //serialPrintln(ldrVal); - //Plugin_041_pixels->setBrightness(255-ldrVal); - //Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. + for (int i = 0; i < NUM_LEDS; i++) { + Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(event->Par1, event->Par2, event->Par3)); + } + Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. success = true; - break; } - case PLUGIN_WRITE: + if (equals(cmd, F("neotestloop"))) { - String cmd = parseString(string, 1); - if (cmd.equalsIgnoreCase(F("NeoClockColor"))) + for (int i = 0; i < NUM_LEDS; i++) { - Plugin_041_red = event->Par1; - Plugin_041_green = event->Par2; - Plugin_041_blue = event->Par3; - Plugin_041_update(); - success = true; - } - - if (cmd.equalsIgnoreCase(F("NeoTestAll"))) - { - for (int i = 0; i < NUM_LEDS; i++) - Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(event->Par1, event->Par2, event->Par3)); + resetAndBlack(); + Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(event->Par1, event->Par2, event->Par3)); Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. - success = true; + delay(200); } - - if (cmd.equalsIgnoreCase(F("NeoTestLoop"))) - { - for (int i = 0; i < NUM_LEDS; i++) - { - resetAndBlack(); - Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(event->Par1, event->Par2, event->Par3)); - Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. - delay(200); - } - success = true; - } - - break; + success = true; } + break; + } } return success; } void Plugin_041_update() { - uint8_t Hours = node_time.hour(); + uint8_t Hours = node_time.hour(); uint8_t Minutes = node_time.minute(); + resetAndBlack(); timeToStrip(Hours, Minutes); Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. } - void resetAndBlack() { for (int i = 0; i < NUM_LEDS; i++) { Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(0, 0, 0)); @@ -189,46 +193,48 @@ void pushToStrip(int ledId) { void timeToStrip(uint8_t hours, uint8_t minutes) { pushIT_IS(); - //show minutes - if (minutes >= 5 && minutes < 10) { + + // show minutes + if ((minutes >= 5) && (minutes < 10)) { pushFIVE1(); pushAFTER(); - } else if (minutes >= 10 && minutes < 15) { + } else if ((minutes >= 10) && (minutes < 15)) { pushTEN1(); pushAFTER(); - } else if (minutes >= 15 && minutes < 20) { + } else if ((minutes >= 15) && (minutes < 20)) { pushQUATER(); pushAFTER(); - } else if (minutes >= 20 && minutes < 25) { + } else if ((minutes >= 20) && (minutes < 25)) { pushTEN1(); pushFOR(); pushHALF(); - } else if (minutes >= 25 && minutes < 30) { + } else if ((minutes >= 25) && (minutes < 30)) { pushFIVE1(); pushFOR(); pushHALF(); - } else if (minutes >= 30 && minutes < 35) { + } else if ((minutes >= 30) && (minutes < 35)) { pushHALF(); - } else if (minutes >= 35 && minutes < 40) { + } else if ((minutes >= 35) && (minutes < 40)) { pushFIVE1(); pushAFTER(); pushHALF(); - } else if (minutes >= 40 && minutes < 45) { + } else if ((minutes >= 40) && (minutes < 45)) { pushTEN1(); pushAFTER(); pushHALF(); - } else if (minutes >= 45 && minutes < 50) { + } else if ((minutes >= 45) && (minutes < 50)) { pushQUATER(); pushFOR(); - } else if (minutes >= 50 && minutes < 55) { + } else if ((minutes >= 50) && (minutes < 55)) { pushTEN1(); pushFOR(); - } else if (minutes >= 55 && minutes < 60) { + } else if ((minutes >= 55) && (minutes < 60)) { pushFIVE1(); pushFOR(); } int singleMinutes = minutes % 5; + switch (singleMinutes) { case 1: pushM_ONE(); @@ -249,17 +255,20 @@ void timeToStrip(uint8_t hours, uint8_t minutes) pushM_FOUR(); break; } + if (hours >= 12) { hours -= 12; } + if (hours == 12) { hours = 0; } + if (minutes >= 20) { hours++; } - //show hours + // show hours switch (hours) { case 1: pushONE(); @@ -299,135 +308,179 @@ void timeToStrip(uint8_t hours, uint8_t minutes) pushTWELVE(); break; } - //show HOUR + + // show HOUR if (minutes < 5) { pushHOURE(); } } -void pushToStrip(const int* ids, size_t count) { +void pushToStrip(const int *ids, size_t count) { for (size_t i = 0; i < count; ++i) { pushToStrip(ids[i]); } } - void pushM_ONE() { pushToStrip(0); } + void pushM_TWO() { pushToStrip(12); } + void pushM_THREE() { pushToStrip(101); } + void pushM_FOUR() { pushToStrip(113); } + void pushIT_IS() { - constexpr int ids[] = {1, 2, 3, 5, 6}; + constexpr int ids[] = { 1, 2, 3, 5, 6 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushAFTER() { - constexpr int ids[] = {36, 37, 38, 39}; + constexpr int ids[] = { 36, 37, 38, 39 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushQUATER() { - constexpr int ids[] = {30, 31, 32, 33, 34}; + constexpr int ids[] = { 30, 31, 32, 33, 34 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushFOR() { - constexpr int ids[] = {41, 42, 43, 44}; + constexpr int ids[] = { 41, 42, 43, 44 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushHALF() { - constexpr int ids[] = {50, 51, 52, 53}; + constexpr int ids[] = { 50, 51, 52, 53 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushONE() { - constexpr int ids[] = {63, 64, 65}; + constexpr int ids[] = { 63, 64, 65 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTWO() { - constexpr int ids[] = {64, 65, 66, 67}; + constexpr int ids[] = { 64, 65, 66, 67 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTHREE() { - constexpr int ids[] = {109, 110, 111, 112}; + constexpr int ids[] = { 109, 110, 111, 112 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushFOUR() { - constexpr int ids[] = {57, 58, 59, 60}; + constexpr int ids[] = { 57, 58, 59, 60 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushFIVE1() { - constexpr int ids[] = {8, 9, 10, 11}; + constexpr int ids[] = { 8, 9, 10, 11 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushFIVE2() { - constexpr int ids[] = {92, 93, 94, 95}; + constexpr int ids[] = { 92, 93, 94, 95 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushSIX() { - constexpr int ids[] = {69, 88, 91}; + constexpr int ids[] = { 69, 88, 91 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushSEVEN() { - constexpr int ids[] = {69, 70, 71, 72, 73}; + constexpr int ids[] = { 69, 70, 71, 72, 73 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushEIGHT() { - constexpr int ids[] = {97, 98, 99, 100}; + constexpr int ids[] = { 97, 98, 99, 100 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushNINE() { - constexpr int ids[] = {73, 74, 75, 76, 77}; + constexpr int ids[] = { 73, 74, 75, 76, 77 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTEN() { - constexpr int ids[] = {54, 59, 76, 81}; + constexpr int ids[] = { 54, 59, 76, 81 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTEN1() { - constexpr int ids[] = {25, 26, 27, 28}; + constexpr int ids[] = { 25, 26, 27, 28 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushELEVEN() { - constexpr int ids[] = {107, 108, 109}; + constexpr int ids[] = { 107, 108, 109 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTWELVE() { - constexpr int ids[] = {82, 83, 84, 85, 86, 87}; + constexpr int ids[] = { 82, 83, 84, 85, 86, 87 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTWENTY() { - constexpr int ids[] = {16, 17, 18, 19, 20, 21, 22}; + constexpr int ids[] = { 16, 17, 18, 19, 20, 21, 22 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } void pushHOURE() { - constexpr int ids[] = {102,103,104}; + constexpr int ids[] = { 102, 103, 104 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } From 546937a060ed647db3260b667bf6a53c6d7a3483 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 4 Nov 2023 15:40:40 +0100 Subject: [PATCH 24/25] [P042] Fix initializations to avoid crash at start, minor improvements --- src/src/PluginStructs/P042_data_struct.cpp | 9 ++++----- src/src/PluginStructs/P042_data_struct.h | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/src/PluginStructs/P042_data_struct.cpp b/src/src/PluginStructs/P042_data_struct.cpp index f260491b4b..5f76ff71a2 100644 --- a/src/src/PluginStructs/P042_data_struct.cpp +++ b/src/src/PluginStructs/P042_data_struct.cpp @@ -22,7 +22,6 @@ bool P042_data_struct::plugin_init(struct EventStruct *event) { Candle_blue = P042_CONFIG_BLUE; Candle_bright = P042_CONFIG_BRIGHTNESS; Candle_pxlcnt = P042_CONFIG_PIXELCOUNT; - Candle_pxlcnt = P042_CONFIG_PIXELCOUNT; segment = Candle_pxlcnt / 4; if ((Candle_red == 0) && (Candle_green == 0) && (Candle_blue == 0)) { @@ -31,16 +30,16 @@ bool P042_data_struct::plugin_init(struct EventStruct *event) { Candle_type = static_cast(P042_CONFIG_CANDLETYPE); Candle_color = static_cast(P042_CONFIG_COLORTYPE); - if (!Candle_pixels || (GPIO_Set == false)) { + if ((nullptr == Candle_pixels) || !GPIO_Set) { GPIO_Set = validGpio(CONFIG_PIN1); if (GPIO_Set) { - if (Candle_pixels) { + if (nullptr != Candle_pixels) { delete Candle_pixels; } Candle_pixels = new (std::nothrow) NeoPixelBus_wrapper(P042_CONFIG_PIXELCOUNT, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); - if (Candle_pixels != nullptr) { + if (nullptr != Candle_pixels) { SetPixelsBlack(); Candle_pixels->setBrightness(Candle_bright); Candle_pixels->begin(); @@ -55,7 +54,7 @@ bool P042_data_struct::plugin_init(struct EventStruct *event) { } } - return Candle_pixels != nullptr; + return nullptr != Candle_pixels; } bool P042_data_struct::plugin_read(struct EventStruct *event) { diff --git a/src/src/PluginStructs/P042_data_struct.h b/src/src/PluginStructs/P042_data_struct.h index d89d5884c8..b039708104 100644 --- a/src/src/PluginStructs/P042_data_struct.h +++ b/src/src/PluginStructs/P042_data_struct.h @@ -5,7 +5,7 @@ #ifdef USES_P042 -#include +# include # define P042_NUM_PIXEL 20 // Defines the default amount of LED Pixels @@ -98,9 +98,9 @@ struct P042_data_struct : public PluginTaskData_base { // global variables unsigned long Candle_Update = 0; word Candle_Temp[3] = { 0 }; // Temp variables - boolean GPIO_Set = false; + bool GPIO_Set = false; - NeoPixelBus_wrapper *Candle_pixels; + NeoPixelBus_wrapper *Candle_pixels = nullptr; }; From 166745692ed78dec701e700fe12e70be5f015781 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 4 Nov 2023 15:41:02 +0100 Subject: [PATCH 25/25] [P070] Minor improvements --- src/src/PluginStructs/P070_data_struct.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/src/PluginStructs/P070_data_struct.cpp b/src/src/PluginStructs/P070_data_struct.cpp index 090c714982..81fad24a16 100644 --- a/src/src/PluginStructs/P070_data_struct.cpp +++ b/src/src/PluginStructs/P070_data_struct.cpp @@ -18,7 +18,7 @@ void P070_data_struct::reset() { } void P070_data_struct::init(struct EventStruct *event) { - if (!Plugin_070_pixels) + if (nullptr == Plugin_070_pixels) { Plugin_070_pixels = new (std::nothrow) NeoPixelBus_wrapper(NUMBER_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800);