diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..b77f844 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,53 @@ +## Contributing to Teensy41_AsyncTCP + +### Reporting Bugs + +Please report bugs in [Teensy41_AsyncTCP](https://github.com/khoih-prog/Teensy41_AsyncTCP/issues/new) if you find them. + +However, before reporting a bug please check through the following: + +* [Existing Open Issues](https://github.com/khoih-prog/Teensy41_AsyncTCP/issues) - someone might have already encountered this. + +If you don't find anything, please [open a new issue](https://github.com/khoih-prog/Teensy41_AsyncTCP/issues/new). + +### How to submit a bug report + +Please ensure to specify the following: + +* Arduino IDE version (e.g. 1.8.19) or Platform.io version +* `Teensyduino` Core Version (e.g. Teensy core v1.56) +* Contextual information (e.g. what you were trying to achieve) +* Simplest possible steps to reproduce +* Anything that might be relevant in your opinion, such as: + * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` + * Network configuration + + +### Example + +``` +Arduino IDE version: 1.8.19 +Teensyduino Core Version 1.56 +OS: Ubuntu 20.04 LTS +Linux xy-Inspiron-3593 5.13.0-35-generic #40~20.04.1-Ubuntu SMP Mon Mar 7 09:18:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux + +Context: +I encountered an endless loop while trying to connect to Local WiFi. + +Steps to reproduce: +1. ... +2. ... +3. ... +4. ... +``` + +### Sending Feature Requests + +Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. + +There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/Teensy41_AsyncTCP/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. + +### Sending Pull Requests + +Pull Requests with changes and fixes are also welcome! + diff --git a/LICENSE b/LICENSE index f288702..65c5ca8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,674 +1,165 @@ - GNU GENERAL PUBLIC LICENSE + GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + 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 -. + + 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/Packages_Patches/hardware/teensy/avr/boards.txt b/Packages_Patches/hardware/teensy/avr/boards.txt new file mode 100644 index 0000000..693927f --- /dev/null +++ b/Packages_Patches/hardware/teensy/avr/boards.txt @@ -0,0 +1,1798 @@ +menu.usb=USB Type +menu.speed=CPU Speed +menu.opt=Optimize +menu.keys=Keyboard Layout + + +# TODO: consider whether these compiler warnings are worthwhile +# -Wno-error=unused-function +# -Wno-error=unused-but-set-variable +# -Wno-error=unused-variable +# -Wno-unused-parameter +# -Wno-unused-but-set-parameter +# -Wno-sign-compare + + +teensy41.name=Teensy 4.1 +#teensy41.upload.maximum_size=8126464 +teensy41.build.board=TEENSY41 +teensy41.build.flags.ld=-Wl,--gc-sections,--relax "-T{build.core.path}/imxrt1062_t41.ld" +#teensy41.upload.maximum_data_size=524288 +teensy41.upload.tool=teensyloader +teensy41.upload.protocol=halfkay +teensy41.build.core=teensy4 +teensy41.build.mcu=imxrt1062 +teensy41.build.warn_data_percentage=99 +teensy41.build.toolchain=arm/bin/ +teensy41.build.command.gcc=arm-none-eabi-gcc +teensy41.build.command.g++=arm-none-eabi-g++ +teensy41.build.command.ar=arm-none-eabi-gcc-ar +teensy41.build.command.objcopy=arm-none-eabi-objcopy +teensy41.build.command.objdump=arm-none-eabi-objdump +teensy41.build.command.linker=arm-none-eabi-gcc +teensy41.build.command.size=arm-none-eabi-size +teensy41.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib +teensy41.build.flags.dep=-MMD +teensy41.build.flags.optimize=-Os +teensy41.build.flags.cpu=-mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 +teensy41.build.flags.defs=-D__IMXRT1062__ -DTEENSYDUINO=156 +teensy41.build.flags.cpp=-std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing +teensy41.build.flags.c= +teensy41.build.flags.S=-x assembler-with-cpp +teensy41.build.flags.libs=-larm_cortexM7lfsp_math -lm -lstdc++ +teensy41.serial.restart_cmd=false +teensy41.menu.usb.serial=Serial +teensy41.menu.usb.serial.build.usbtype=USB_SERIAL +teensy41.menu.usb.serial2=Dual Serial +teensy41.menu.usb.serial2.build.usbtype=USB_DUAL_SERIAL +teensy41.menu.usb.serial3=Triple Serial +teensy41.menu.usb.serial3.build.usbtype=USB_TRIPLE_SERIAL +teensy41.menu.usb.keyboard=Keyboard +teensy41.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY +teensy41.menu.usb.keyboard.fake_serial=teensy_gateway +teensy41.menu.usb.touch=Keyboard + Touch Screen +teensy41.menu.usb.touch.build.usbtype=USB_TOUCHSCREEN +teensy41.menu.usb.touch.fake_serial=teensy_gateway +teensy41.menu.usb.hidtouch=Keyboard + Mouse + Touch Screen +teensy41.menu.usb.hidtouch.build.usbtype=USB_HID_TOUCHSCREEN +teensy41.menu.usb.hidtouch.fake_serial=teensy_gateway +teensy41.menu.usb.hid=Keyboard + Mouse + Joystick +teensy41.menu.usb.hid.build.usbtype=USB_HID +teensy41.menu.usb.hid.fake_serial=teensy_gateway +teensy41.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensy41.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensy41.menu.usb.midi=MIDI +teensy41.menu.usb.midi.build.usbtype=USB_MIDI +teensy41.menu.usb.midi.fake_serial=teensy_gateway +teensy41.menu.usb.midi4=MIDIx4 +teensy41.menu.usb.midi4.build.usbtype=USB_MIDI4 +teensy41.menu.usb.midi4.fake_serial=teensy_gateway +teensy41.menu.usb.midi16=MIDIx16 +teensy41.menu.usb.midi16.build.usbtype=USB_MIDI16 +teensy41.menu.usb.midi16.fake_serial=teensy_gateway +teensy41.menu.usb.serialmidi=Serial + MIDI +teensy41.menu.usb.serialmidi.build.usbtype=USB_MIDI_SERIAL +teensy41.menu.usb.serialmidi4=Serial + MIDIx4 +teensy41.menu.usb.serialmidi4.build.usbtype=USB_MIDI4_SERIAL +teensy41.menu.usb.serialmidi16=Serial + MIDIx16 +teensy41.menu.usb.serialmidi16.build.usbtype=USB_MIDI16_SERIAL +teensy41.menu.usb.audio=Audio +teensy41.menu.usb.audio.build.usbtype=USB_AUDIO +teensy41.menu.usb.audio.fake_serial=teensy_gateway +teensy41.menu.usb.serialmidiaudio=Serial + MIDI + Audio +teensy41.menu.usb.serialmidiaudio.build.usbtype=USB_MIDI_AUDIO_SERIAL +teensy41.menu.usb.serialmidi16audio=Serial + MIDIx16 + Audio +teensy41.menu.usb.serialmidi16audio.build.usbtype=USB_MIDI16_AUDIO_SERIAL +teensy41.menu.usb.mtp=MTP Disk (Experimental) +teensy41.menu.usb.mtp.build.usbtype=USB_MTPDISK +teensy41.menu.usb.mtp.fake_serial=teensy_gateway +teensy41.menu.usb.rawhid=Raw HID +teensy41.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensy41.menu.usb.rawhid.fake_serial=teensy_gateway +teensy41.menu.usb.flightsim=Flight Sim Controls +teensy41.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensy41.menu.usb.flightsim.fake_serial=teensy_gateway +teensy41.menu.usb.flightsimjoystick=Flight Sim Controls + Joystick +teensy41.menu.usb.flightsimjoystick.build.usbtype=USB_FLIGHTSIM_JOYSTICK +teensy41.menu.usb.flightsimjoystick.fake_serial=teensy_gateway +#teensy41.menu.usb.disable=No USB +#teensy41.menu.usb.disable.build.usbtype=USB_DISABLED + +teensy41.menu.speed.600=600 MHz +teensy41.menu.speed.528=528 MHz +teensy41.menu.speed.450=450 MHz +teensy41.menu.speed.396=396 MHz +teensy41.menu.speed.150=150 MHz +teensy41.menu.speed.24=24 MHz +teensy41.menu.speed.720=720 MHz (overclock) +teensy41.menu.speed.816=816 MHz (overclock) +teensy41.menu.speed.912=912 MHz (overclock, cooling req'd) +teensy41.menu.speed.960=960 MHz (overclock, cooling req'd) +teensy41.menu.speed.1008=1.008 GHz (overclock, cooling req'd) +teensy41.menu.speed.1008.build.fcpu=1008000000 +teensy41.menu.speed.960.build.fcpu=960000000 +teensy41.menu.speed.912.build.fcpu=912000000 +teensy41.menu.speed.816.build.fcpu=816000000 +teensy41.menu.speed.720.build.fcpu=720000000 +teensy41.menu.speed.600.build.fcpu=600000000 +teensy41.menu.speed.528.build.fcpu=528000000 +teensy41.menu.speed.450.build.fcpu=450000000 +teensy41.menu.speed.396.build.fcpu=396000000 +teensy41.menu.speed.150.build.fcpu=150000000 +teensy41.menu.speed.24.build.fcpu=24000000 + +teensy41.menu.opt.o2std=Faster +teensy41.menu.opt.o2std.build.flags.optimize=-O2 +teensy41.menu.opt.o2std.build.flags.ldspecs= +#teensy41.menu.opt.o2lto=Faster with LTO +#teensy41.menu.opt.o2lto.build.flags.optimize=-O2 -flto -fno-fat-lto-objects +#teensy41.menu.opt.o2lto.build.flags.ldspecs=-fuse-linker-plugin +teensy41.menu.opt.o1std=Fast +teensy41.menu.opt.o1std.build.flags.optimize=-O1 +teensy41.menu.opt.o1std.build.flags.ldspecs= +#teensy41.menu.opt.o1lto=Fast with LTO +#teensy41.menu.opt.o1lto.build.flags.optimize=-O1 -flto -fno-fat-lto-objects +#teensy41.menu.opt.o1lto.build.flags.ldspecs=-fuse-linker-plugin +teensy41.menu.opt.o3std=Fastest +teensy41.menu.opt.o3std.build.flags.optimize=-O3 +teensy41.menu.opt.o3std.build.flags.ldspecs= +#teensy41.menu.opt.o3purestd=Fastest + pure-code +#teensy41.menu.opt.o3purestd.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ +#teensy41.menu.opt.o3purestd.build.flags.ldspecs= +#teensy41.menu.opt.o3lto=Fastest with LTO +#teensy41.menu.opt.o3lto.build.flags.optimize=-O3 -flto -fno-fat-lto-objects +#teensy41.menu.opt.o3lto.build.flags.ldspecs=-fuse-linker-plugin +#teensy41.menu.opt.o3purelto=Fastest + pure-code with LTO +#teensy41.menu.opt.o3purelto.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ -flto -fno-fat-lto-objects +#teensy41.menu.opt.o3purelto.build.flags.ldspecs=-fuse-linker-plugin +teensy41.menu.opt.ogstd=Debug +teensy41.menu.opt.ogstd.build.flags.optimize=-Og +teensy41.menu.opt.ogstd.build.flags.ldspecs= +#teensy41.menu.opt.oglto=Debug with LTO +#teensy41.menu.opt.oglto.build.flags.optimize=-Og -flto -fno-fat-lto-objects +#teensy41.menu.opt.oglto.build.flags.ldspecs=-fuse-linker-plugin +teensy41.menu.opt.osstd=Smallest Code +teensy41.menu.opt.osstd.build.flags.optimize=-Os --specs=nano.specs +teensy41.menu.opt.osstd.build.flags.ldspecs= +#teensy41.menu.opt.oslto=Smallest Code with LTO +#teensy41.menu.opt.oslto.build.flags.optimize=-Os -flto -fno-fat-lto-objects --specs=nano.specs +#teensy41.menu.opt.oslto.build.flags.ldspecs=-fuse-linker-plugin + +teensy41.menu.keys.en-us=US English +teensy41.menu.keys.en-us.build.keylayout=US_ENGLISH +teensy41.menu.keys.fr-ca=Canadian French +teensy41.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensy41.menu.keys.xx-ca=Canadian Multilingual +teensy41.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensy41.menu.keys.cz-cz=Czech +teensy41.menu.keys.cz-cz.build.keylayout=CZECH +teensy41.menu.keys.da-da=Danish +teensy41.menu.keys.da-da.build.keylayout=DANISH +teensy41.menu.keys.fi-fi=Finnish +teensy41.menu.keys.fi-fi.build.keylayout=FINNISH +teensy41.menu.keys.fr-fr=French +teensy41.menu.keys.fr-fr.build.keylayout=FRENCH +teensy41.menu.keys.fr-be=French Belgian +teensy41.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensy41.menu.keys.fr-ch=French Swiss +teensy41.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensy41.menu.keys.de-de=German +teensy41.menu.keys.de-de.build.keylayout=GERMAN +teensy41.menu.keys.de-dm=German (Mac) +teensy41.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensy41.menu.keys.de-ch=German Swiss +teensy41.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensy41.menu.keys.is-is=Icelandic +teensy41.menu.keys.is-is.build.keylayout=ICELANDIC +teensy41.menu.keys.en-ie=Irish +teensy41.menu.keys.en-ie.build.keylayout=IRISH +teensy41.menu.keys.it-it=Italian +teensy41.menu.keys.it-it.build.keylayout=ITALIAN +teensy41.menu.keys.no-no=Norwegian +teensy41.menu.keys.no-no.build.keylayout=NORWEGIAN +teensy41.menu.keys.pt-pt=Portuguese +teensy41.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensy41.menu.keys.pt-br=Portuguese Brazilian +teensy41.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensy41.menu.keys.rs-rs=Serbian (Latin Only) +teensy41.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensy41.menu.keys.es-es=Spanish +teensy41.menu.keys.es-es.build.keylayout=SPANISH +teensy41.menu.keys.es-mx=Spanish Latin America +teensy41.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensy41.menu.keys.sv-se=Swedish +teensy41.menu.keys.sv-se.build.keylayout=SWEDISH +teensy41.menu.keys.tr-tr=Turkish (partial) +teensy41.menu.keys.tr-tr.build.keylayout=TURKISH +teensy41.menu.keys.en-gb=United Kingdom +teensy41.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensy41.menu.keys.usint=US International +teensy41.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + + + +teensyMM.name=Teensy MicroMod +#teensyMM.upload.maximum_size=16515072 +teensyMM.build.board=TEENSY_MICROMOD +teensyMM.build.flags.ld=-Wl,--gc-sections,--relax "-T{build.core.path}/imxrt1062_mm.ld" +#teensyMM.upload.maximum_data_size=524288 +#teensyMM.upload.maximum_data_size=1048576 +teensyMM.upload.tool=teensyloader +teensyMM.upload.protocol=halfkay +teensyMM.build.core=teensy4 +teensyMM.build.mcu=imxrt1062 +teensyMM.build.warn_data_percentage=99 +teensyMM.build.toolchain=arm/bin/ +teensyMM.build.command.gcc=arm-none-eabi-gcc +teensyMM.build.command.g++=arm-none-eabi-g++ +teensyMM.build.command.ar=arm-none-eabi-gcc-ar +teensyMM.build.command.objcopy=arm-none-eabi-objcopy +teensyMM.build.command.objdump=arm-none-eabi-objdump +teensyMM.build.command.linker=arm-none-eabi-gcc +teensyMM.build.command.size=arm-none-eabi-size +teensyMM.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib +teensyMM.build.flags.dep=-MMD +teensyMM.build.flags.optimize=-Os +teensyMM.build.flags.cpu=-mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 +teensyMM.build.flags.defs=-D__IMXRT1062__ -DTEENSYDUINO=156 +teensyMM.build.flags.cpp=-std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing +teensyMM.build.flags.c= +teensyMM.build.flags.S=-x assembler-with-cpp +teensyMM.build.flags.libs=-larm_cortexM7lfsp_math -lm -lstdc++ +teensyMM.serial.restart_cmd=false +teensyMM.menu.usb.serial=Serial +teensyMM.menu.usb.serial.build.usbtype=USB_SERIAL +teensyMM.menu.usb.serial2=Dual Serial +teensyMM.menu.usb.serial2.build.usbtype=USB_DUAL_SERIAL +teensyMM.menu.usb.serial3=Triple Serial +teensyMM.menu.usb.serial3.build.usbtype=USB_TRIPLE_SERIAL +teensyMM.menu.usb.keyboard=Keyboard +teensyMM.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY +teensyMM.menu.usb.keyboard.fake_serial=teensy_gateway +teensyMM.menu.usb.touch=Keyboard + Touch Screen +teensyMM.menu.usb.touch.build.usbtype=USB_TOUCHSCREEN +teensyMM.menu.usb.touch.fake_serial=teensy_gateway +teensyMM.menu.usb.hidtouch=Keyboard + Mouse + Touch Screen +teensyMM.menu.usb.hidtouch.build.usbtype=USB_HID_TOUCHSCREEN +teensyMM.menu.usb.hidtouch.fake_serial=teensy_gateway +teensyMM.menu.usb.hid=Keyboard + Mouse + Joystick +teensyMM.menu.usb.hid.build.usbtype=USB_HID +teensyMM.menu.usb.hid.fake_serial=teensy_gateway +teensyMM.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensyMM.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensyMM.menu.usb.midi=MIDI +teensyMM.menu.usb.midi.build.usbtype=USB_MIDI +teensyMM.menu.usb.midi.fake_serial=teensy_gateway +teensyMM.menu.usb.midi4=MIDIx4 +teensyMM.menu.usb.midi4.build.usbtype=USB_MIDI4 +teensyMM.menu.usb.midi4.fake_serial=teensy_gateway +teensyMM.menu.usb.midi16=MIDIx16 +teensyMM.menu.usb.midi16.build.usbtype=USB_MIDI16 +teensyMM.menu.usb.midi16.fake_serial=teensy_gateway +teensyMM.menu.usb.serialmidi=Serial + MIDI +teensyMM.menu.usb.serialmidi.build.usbtype=USB_MIDI_SERIAL +teensyMM.menu.usb.serialmidi4=Serial + MIDIx4 +teensyMM.menu.usb.serialmidi4.build.usbtype=USB_MIDI4_SERIAL +teensyMM.menu.usb.serialmidi16=Serial + MIDIx16 +teensyMM.menu.usb.serialmidi16.build.usbtype=USB_MIDI16_SERIAL +teensyMM.menu.usb.audio=Audio +teensyMM.menu.usb.audio.build.usbtype=USB_AUDIO +teensyMM.menu.usb.audio.fake_serial=teensy_gateway +teensyMM.menu.usb.serialmidiaudio=Serial + MIDI + Audio +teensyMM.menu.usb.serialmidiaudio.build.usbtype=USB_MIDI_AUDIO_SERIAL +teensyMM.menu.usb.serialmidi16audio=Serial + MIDIx16 + Audio +teensyMM.menu.usb.serialmidi16audio.build.usbtype=USB_MIDI16_AUDIO_SERIAL +teensyMM.menu.usb.mtp=MTP Disk (Experimental) +teensyMM.menu.usb.mtp.build.usbtype=USB_MTPDISK +teensyMM.menu.usb.mtp.fake_serial=teensy_gateway +teensyMM.menu.usb.rawhid=Raw HID +teensyMM.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensyMM.menu.usb.rawhid.fake_serial=teensy_gateway +teensyMM.menu.usb.flightsim=Flight Sim Controls +teensyMM.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensyMM.menu.usb.flightsim.fake_serial=teensy_gateway +teensyMM.menu.usb.flightsimjoystick=Flight Sim Controls + Joystick +teensyMM.menu.usb.flightsimjoystick.build.usbtype=USB_FLIGHTSIM_JOYSTICK +teensyMM.menu.usb.flightsimjoystick.fake_serial=teensy_gateway +#teensyMM.menu.usb.disable=No USB +#teensyMM.menu.usb.disable.build.usbtype=USB_DISABLED + +teensyMM.menu.speed.600=600 MHz +teensyMM.menu.speed.528=528 MHz +teensyMM.menu.speed.450=450 MHz +teensyMM.menu.speed.396=396 MHz +teensyMM.menu.speed.150=150 MHz +teensyMM.menu.speed.24=24 MHz +teensyMM.menu.speed.720=720 MHz (overclock) +teensyMM.menu.speed.816=816 MHz (overclock) +teensyMM.menu.speed.912=912 MHz (overclock, cooling req'd) +teensyMM.menu.speed.960=960 MHz (overclock, cooling req'd) +teensyMM.menu.speed.1008=1.008 GHz (overclock, cooling req'd) +teensyMM.menu.speed.1008.build.fcpu=1008000000 +teensyMM.menu.speed.960.build.fcpu=960000000 +teensyMM.menu.speed.912.build.fcpu=912000000 +teensyMM.menu.speed.816.build.fcpu=816000000 +teensyMM.menu.speed.720.build.fcpu=720000000 +teensyMM.menu.speed.600.build.fcpu=600000000 +teensyMM.menu.speed.528.build.fcpu=528000000 +teensyMM.menu.speed.450.build.fcpu=450000000 +teensyMM.menu.speed.396.build.fcpu=396000000 +teensyMM.menu.speed.150.build.fcpu=150000000 +teensyMM.menu.speed.24.build.fcpu=24000000 + +teensyMM.menu.opt.o2std=Faster +teensyMM.menu.opt.o2std.build.flags.optimize=-O2 +teensyMM.menu.opt.o2std.build.flags.ldspecs= +#teensyMM.menu.opt.o2lto=Faster with LTO +#teensyMM.menu.opt.o2lto.build.flags.optimize=-O2 -flto -fno-fat-lto-objects +#teensyMM.menu.opt.o2lto.build.flags.ldspecs=-fuse-linker-plugin +teensyMM.menu.opt.o1std=Fast +teensyMM.menu.opt.o1std.build.flags.optimize=-O1 +teensyMM.menu.opt.o1std.build.flags.ldspecs= +#teensyMM.menu.opt.o1lto=Fast with LTO +#teensyMM.menu.opt.o1lto.build.flags.optimize=-O1 -flto -fno-fat-lto-objects +#teensyMM.menu.opt.o1lto.build.flags.ldspecs=-fuse-linker-plugin +teensyMM.menu.opt.o3std=Fastest +teensyMM.menu.opt.o3std.build.flags.optimize=-O3 +teensyMM.menu.opt.o3std.build.flags.ldspecs= +#teensyMM.menu.opt.o3purestd=Fastest + pure-code +#teensyMM.menu.opt.o3purestd.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ +#teensyMM.menu.opt.o3purestd.build.flags.ldspecs= +#teensyMM.menu.opt.o3lto=Fastest with LTO +#teensyMM.menu.opt.o3lto.build.flags.optimize=-O3 -flto -fno-fat-lto-objects +#teensyMM.menu.opt.o3lto.build.flags.ldspecs=-fuse-linker-plugin +#teensyMM.menu.opt.o3purelto=Fastest + pure-code with LTO +#teensyMM.menu.opt.o3purelto.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ -flto -fno-fat-lto-objects +#teensyMM.menu.opt.o3purelto.build.flags.ldspecs=-fuse-linker-plugin +teensyMM.menu.opt.ogstd=Debug +teensyMM.menu.opt.ogstd.build.flags.optimize=-Og +teensyMM.menu.opt.ogstd.build.flags.ldspecs= +#teensyMM.menu.opt.oglto=Debug with LTO +#teensyMM.menu.opt.oglto.build.flags.optimize=-Og -flto -fno-fat-lto-objects +#teensyMM.menu.opt.oglto.build.flags.ldspecs=-fuse-linker-plugin +teensyMM.menu.opt.osstd=Smallest Code +teensyMM.menu.opt.osstd.build.flags.optimize=-Os --specs=nano.specs +teensyMM.menu.opt.osstd.build.flags.ldspecs= +#teensyMM.menu.opt.oslto=Smallest Code with LTO +#teensyMM.menu.opt.oslto.build.flags.optimize=-Os -flto -fno-fat-lto-objects --specs=nano.specs +#teensyMM.menu.opt.oslto.build.flags.ldspecs=-fuse-linker-plugin + +teensyMM.menu.keys.en-us=US English +teensyMM.menu.keys.en-us.build.keylayout=US_ENGLISH +teensyMM.menu.keys.fr-ca=Canadian French +teensyMM.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensyMM.menu.keys.xx-ca=Canadian Multilingual +teensyMM.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensyMM.menu.keys.cz-cz=Czech +teensyMM.menu.keys.cz-cz.build.keylayout=CZECH +teensyMM.menu.keys.da-da=Danish +teensyMM.menu.keys.da-da.build.keylayout=DANISH +teensyMM.menu.keys.fi-fi=Finnish +teensyMM.menu.keys.fi-fi.build.keylayout=FINNISH +teensyMM.menu.keys.fr-fr=French +teensyMM.menu.keys.fr-fr.build.keylayout=FRENCH +teensyMM.menu.keys.fr-be=French Belgian +teensyMM.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensyMM.menu.keys.fr-ch=French Swiss +teensyMM.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensyMM.menu.keys.de-de=German +teensyMM.menu.keys.de-de.build.keylayout=GERMAN +teensyMM.menu.keys.de-dm=German (Mac) +teensyMM.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensyMM.menu.keys.de-ch=German Swiss +teensyMM.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensyMM.menu.keys.is-is=Icelandic +teensyMM.menu.keys.is-is.build.keylayout=ICELANDIC +teensyMM.menu.keys.en-ie=Irish +teensyMM.menu.keys.en-ie.build.keylayout=IRISH +teensyMM.menu.keys.it-it=Italian +teensyMM.menu.keys.it-it.build.keylayout=ITALIAN +teensyMM.menu.keys.no-no=Norwegian +teensyMM.menu.keys.no-no.build.keylayout=NORWEGIAN +teensyMM.menu.keys.pt-pt=Portuguese +teensyMM.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensyMM.menu.keys.pt-br=Portuguese Brazilian +teensyMM.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensyMM.menu.keys.rs-rs=Serbian (Latin Only) +teensyMM.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensyMM.menu.keys.es-es=Spanish +teensyMM.menu.keys.es-es.build.keylayout=SPANISH +teensyMM.menu.keys.es-mx=Spanish Latin America +teensyMM.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensyMM.menu.keys.sv-se=Swedish +teensyMM.menu.keys.sv-se.build.keylayout=SWEDISH +teensyMM.menu.keys.tr-tr=Turkish (partial) +teensyMM.menu.keys.tr-tr.build.keylayout=TURKISH +teensyMM.menu.keys.en-gb=United Kingdom +teensyMM.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensyMM.menu.keys.usint=US International +teensyMM.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + + + +teensy40.name=Teensy 4.0 +#teensy40.upload.maximum_size=2031616 +teensy40.build.board=TEENSY40 +teensy40.build.flags.ld=-Wl,--gc-sections,--relax "-T{build.core.path}/imxrt1062.ld" +#teensy40.upload.maximum_data_size=524288 +#teensy40.upload.maximum_data_size=1048576 +teensy40.upload.tool=teensyloader +teensy40.upload.protocol=halfkay +teensy40.build.core=teensy4 +teensy40.build.mcu=imxrt1062 +teensy40.build.warn_data_percentage=99 +teensy40.build.toolchain=arm/bin/ +teensy40.build.command.gcc=arm-none-eabi-gcc +teensy40.build.command.g++=arm-none-eabi-g++ +teensy40.build.command.ar=arm-none-eabi-gcc-ar +teensy40.build.command.objcopy=arm-none-eabi-objcopy +teensy40.build.command.objdump=arm-none-eabi-objdump +teensy40.build.command.linker=arm-none-eabi-gcc +teensy40.build.command.size=arm-none-eabi-size +teensy40.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib +teensy40.build.flags.dep=-MMD +teensy40.build.flags.optimize=-Os +teensy40.build.flags.cpu=-mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 +teensy40.build.flags.defs=-D__IMXRT1062__ -DTEENSYDUINO=156 +teensy40.build.flags.cpp=-std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing +teensy40.build.flags.c= +teensy40.build.flags.S=-x assembler-with-cpp +teensy40.build.flags.libs=-larm_cortexM7lfsp_math -lm -lstdc++ +teensy40.serial.restart_cmd=false +teensy40.menu.usb.serial=Serial +teensy40.menu.usb.serial.build.usbtype=USB_SERIAL +teensy40.menu.usb.serial2=Dual Serial +teensy40.menu.usb.serial2.build.usbtype=USB_DUAL_SERIAL +teensy40.menu.usb.serial3=Triple Serial +teensy40.menu.usb.serial3.build.usbtype=USB_TRIPLE_SERIAL +teensy40.menu.usb.keyboard=Keyboard +teensy40.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY +teensy40.menu.usb.keyboard.fake_serial=teensy_gateway +teensy40.menu.usb.touch=Keyboard + Touch Screen +teensy40.menu.usb.touch.build.usbtype=USB_TOUCHSCREEN +teensy40.menu.usb.touch.fake_serial=teensy_gateway +teensy40.menu.usb.hidtouch=Keyboard + Mouse + Touch Screen +teensy40.menu.usb.hidtouch.build.usbtype=USB_HID_TOUCHSCREEN +teensy40.menu.usb.hidtouch.fake_serial=teensy_gateway +teensy40.menu.usb.hid=Keyboard + Mouse + Joystick +teensy40.menu.usb.hid.build.usbtype=USB_HID +teensy40.menu.usb.hid.fake_serial=teensy_gateway +teensy40.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensy40.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensy40.menu.usb.midi=MIDI +teensy40.menu.usb.midi.build.usbtype=USB_MIDI +teensy40.menu.usb.midi.fake_serial=teensy_gateway +teensy40.menu.usb.midi4=MIDIx4 +teensy40.menu.usb.midi4.build.usbtype=USB_MIDI4 +teensy40.menu.usb.midi4.fake_serial=teensy_gateway +teensy40.menu.usb.midi16=MIDIx16 +teensy40.menu.usb.midi16.build.usbtype=USB_MIDI16 +teensy40.menu.usb.midi16.fake_serial=teensy_gateway +teensy40.menu.usb.serialmidi=Serial + MIDI +teensy40.menu.usb.serialmidi.build.usbtype=USB_MIDI_SERIAL +teensy40.menu.usb.serialmidi4=Serial + MIDIx4 +teensy40.menu.usb.serialmidi4.build.usbtype=USB_MIDI4_SERIAL +teensy40.menu.usb.serialmidi16=Serial + MIDIx16 +teensy40.menu.usb.serialmidi16.build.usbtype=USB_MIDI16_SERIAL +teensy40.menu.usb.audio=Audio +teensy40.menu.usb.audio.build.usbtype=USB_AUDIO +teensy40.menu.usb.audio.fake_serial=teensy_gateway +teensy40.menu.usb.serialmidiaudio=Serial + MIDI + Audio +teensy40.menu.usb.serialmidiaudio.build.usbtype=USB_MIDI_AUDIO_SERIAL +teensy40.menu.usb.serialmidi16audio=Serial + MIDIx16 + Audio +teensy40.menu.usb.serialmidi16audio.build.usbtype=USB_MIDI16_AUDIO_SERIAL +teensy40.menu.usb.mtp=MTP Disk (Experimental) +teensy40.menu.usb.mtp.build.usbtype=USB_MTPDISK +teensy40.menu.usb.mtp.fake_serial=teensy_gateway +teensy40.menu.usb.rawhid=Raw HID +teensy40.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensy40.menu.usb.rawhid.fake_serial=teensy_gateway +teensy40.menu.usb.flightsim=Flight Sim Controls +teensy40.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensy40.menu.usb.flightsim.fake_serial=teensy_gateway +teensy40.menu.usb.flightsimjoystick=Flight Sim Controls + Joystick +teensy40.menu.usb.flightsimjoystick.build.usbtype=USB_FLIGHTSIM_JOYSTICK +teensy40.menu.usb.flightsimjoystick.fake_serial=teensy_gateway +#teensy40.menu.usb.disable=No USB +#teensy40.menu.usb.disable.build.usbtype=USB_DISABLED + +teensy40.menu.speed.600=600 MHz +teensy40.menu.speed.528=528 MHz +teensy40.menu.speed.450=450 MHz +teensy40.menu.speed.396=396 MHz +teensy40.menu.speed.150=150 MHz +teensy40.menu.speed.24=24 MHz +teensy40.menu.speed.720=720 MHz (overclock) +teensy40.menu.speed.816=816 MHz (overclock) +teensy40.menu.speed.912=912 MHz (overclock, cooling req'd) +teensy40.menu.speed.960=960 MHz (overclock, cooling req'd) +teensy40.menu.speed.1008=1.008 GHz (overclock, cooling req'd) +teensy40.menu.speed.1008.build.fcpu=1008000000 +teensy40.menu.speed.960.build.fcpu=960000000 +teensy40.menu.speed.912.build.fcpu=912000000 +teensy40.menu.speed.816.build.fcpu=816000000 +teensy40.menu.speed.720.build.fcpu=720000000 +teensy40.menu.speed.600.build.fcpu=600000000 +teensy40.menu.speed.528.build.fcpu=528000000 +teensy40.menu.speed.450.build.fcpu=450000000 +teensy40.menu.speed.396.build.fcpu=396000000 +teensy40.menu.speed.150.build.fcpu=150000000 +teensy40.menu.speed.24.build.fcpu=24000000 + +teensy40.menu.opt.o2std=Faster +teensy40.menu.opt.o2std.build.flags.optimize=-O2 +teensy40.menu.opt.o2std.build.flags.ldspecs= +#teensy40.menu.opt.o2lto=Faster with LTO +#teensy40.menu.opt.o2lto.build.flags.optimize=-O2 -flto -fno-fat-lto-objects +#teensy40.menu.opt.o2lto.build.flags.ldspecs=-fuse-linker-plugin +teensy40.menu.opt.o1std=Fast +teensy40.menu.opt.o1std.build.flags.optimize=-O1 +teensy40.menu.opt.o1std.build.flags.ldspecs= +#teensy40.menu.opt.o1lto=Fast with LTO +#teensy40.menu.opt.o1lto.build.flags.optimize=-O1 -flto -fno-fat-lto-objects +#teensy40.menu.opt.o1lto.build.flags.ldspecs=-fuse-linker-plugin +teensy40.menu.opt.o3std=Fastest +teensy40.menu.opt.o3std.build.flags.optimize=-O3 +teensy40.menu.opt.o3std.build.flags.ldspecs= +#teensy40.menu.opt.o3purestd=Fastest + pure-code +#teensy40.menu.opt.o3purestd.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ +#teensy40.menu.opt.o3purestd.build.flags.ldspecs= +#teensy40.menu.opt.o3lto=Fastest with LTO +#teensy40.menu.opt.o3lto.build.flags.optimize=-O3 -flto -fno-fat-lto-objects +#teensy40.menu.opt.o3lto.build.flags.ldspecs=-fuse-linker-plugin +#teensy40.menu.opt.o3purelto=Fastest + pure-code with LTO +#teensy40.menu.opt.o3purelto.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ -flto -fno-fat-lto-objects +#teensy40.menu.opt.o3purelto.build.flags.ldspecs=-fuse-linker-plugin +teensy40.menu.opt.ogstd=Debug +teensy40.menu.opt.ogstd.build.flags.optimize=-Og +teensy40.menu.opt.ogstd.build.flags.ldspecs= +#teensy40.menu.opt.oglto=Debug with LTO +#teensy40.menu.opt.oglto.build.flags.optimize=-Og -flto -fno-fat-lto-objects +#teensy40.menu.opt.oglto.build.flags.ldspecs=-fuse-linker-plugin +teensy40.menu.opt.osstd=Smallest Code +teensy40.menu.opt.osstd.build.flags.optimize=-Os --specs=nano.specs +teensy40.menu.opt.osstd.build.flags.ldspecs= +#teensy40.menu.opt.oslto=Smallest Code with LTO +#teensy40.menu.opt.oslto.build.flags.optimize=-Os -flto -fno-fat-lto-objects --specs=nano.specs +#teensy40.menu.opt.oslto.build.flags.ldspecs=-fuse-linker-plugin + +teensy40.menu.keys.en-us=US English +teensy40.menu.keys.en-us.build.keylayout=US_ENGLISH +teensy40.menu.keys.fr-ca=Canadian French +teensy40.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensy40.menu.keys.xx-ca=Canadian Multilingual +teensy40.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensy40.menu.keys.cz-cz=Czech +teensy40.menu.keys.cz-cz.build.keylayout=CZECH +teensy40.menu.keys.da-da=Danish +teensy40.menu.keys.da-da.build.keylayout=DANISH +teensy40.menu.keys.fi-fi=Finnish +teensy40.menu.keys.fi-fi.build.keylayout=FINNISH +teensy40.menu.keys.fr-fr=French +teensy40.menu.keys.fr-fr.build.keylayout=FRENCH +teensy40.menu.keys.fr-be=French Belgian +teensy40.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensy40.menu.keys.fr-ch=French Swiss +teensy40.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensy40.menu.keys.de-de=German +teensy40.menu.keys.de-de.build.keylayout=GERMAN +teensy40.menu.keys.de-dm=German (Mac) +teensy40.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensy40.menu.keys.de-ch=German Swiss +teensy40.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensy40.menu.keys.is-is=Icelandic +teensy40.menu.keys.is-is.build.keylayout=ICELANDIC +teensy40.menu.keys.en-ie=Irish +teensy40.menu.keys.en-ie.build.keylayout=IRISH +teensy40.menu.keys.it-it=Italian +teensy40.menu.keys.it-it.build.keylayout=ITALIAN +teensy40.menu.keys.no-no=Norwegian +teensy40.menu.keys.no-no.build.keylayout=NORWEGIAN +teensy40.menu.keys.pt-pt=Portuguese +teensy40.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensy40.menu.keys.pt-br=Portuguese Brazilian +teensy40.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensy40.menu.keys.rs-rs=Serbian (Latin Only) +teensy40.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensy40.menu.keys.es-es=Spanish +teensy40.menu.keys.es-es.build.keylayout=SPANISH +teensy40.menu.keys.es-mx=Spanish Latin America +teensy40.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensy40.menu.keys.sv-se=Swedish +teensy40.menu.keys.sv-se.build.keylayout=SWEDISH +teensy40.menu.keys.tr-tr=Turkish (partial) +teensy40.menu.keys.tr-tr.build.keylayout=TURKISH +teensy40.menu.keys.en-gb=United Kingdom +teensy40.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensy40.menu.keys.usint=US International +teensy40.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + +teensy36.name=Teensy 3.6 +teensy36.upload.maximum_size=1048576 +teensy36.upload.maximum_data_size=262144 +teensy36.upload.tool=teensyloader +teensy36.upload.protocol=halfkay +teensy36.build.board=TEENSY36 +teensy36.build.core=teensy3 +teensy36.build.mcu=mk66fx1m0 +teensy36.build.warn_data_percentage=99 +teensy36.build.toolchain=arm/bin/ +teensy36.build.command.gcc=arm-none-eabi-gcc +teensy36.build.command.g++=arm-none-eabi-g++ +teensy36.build.command.ar=arm-none-eabi-gcc-ar +teensy36.build.command.objcopy=arm-none-eabi-objcopy +teensy36.build.command.objdump=arm-none-eabi-objdump + +# KH, Fix linker error when using STL library +#teensy36.build.command.linker=arm-none-eabi-gcc +teensy36.build.command.linker=arm-none-eabi-g++ + +teensy36.build.command.size=arm-none-eabi-size +teensy36.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access +teensy36.build.flags.dep=-MMD +teensy36.build.flags.optimize=-Os +teensy36.build.flags.cpu=-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant +teensy36.build.flags.defs=-D__MK66FX1M0__ -DTEENSYDUINO=156 +teensy36.build.flags.cpp=-fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti +teensy36.build.flags.c= +teensy36.build.flags.S=-x assembler-with-cpp +teensy36.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk66fx1m0.ld" +teensy36.build.flags.libs=-larm_cortexM4lf_math -lm -lstdc++ +teensy36.serial.restart_cmd=false +teensy36.menu.usb.serial=Serial +teensy36.menu.usb.serial.build.usbtype=USB_SERIAL +teensy36.menu.usb.serial2=Dual Serial +teensy36.menu.usb.serial2.build.usbtype=USB_DUAL_SERIAL +teensy36.menu.usb.serial3=Triple Serial +teensy36.menu.usb.serial3.build.usbtype=USB_TRIPLE_SERIAL +teensy36.menu.usb.keyboard=Keyboard +teensy36.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY +teensy36.menu.usb.keyboard.fake_serial=teensy_gateway +teensy36.menu.usb.touch=Keyboard + Touch Screen +teensy36.menu.usb.touch.build.usbtype=USB_TOUCHSCREEN +teensy36.menu.usb.touch.fake_serial=teensy_gateway +teensy36.menu.usb.hidtouch=Keyboard + Mouse + Touch Screen +teensy36.menu.usb.hidtouch.build.usbtype=USB_HID_TOUCHSCREEN +teensy36.menu.usb.hidtouch.fake_serial=teensy_gateway +teensy36.menu.usb.hid=Keyboard + Mouse + Joystick +teensy36.menu.usb.hid.build.usbtype=USB_HID +teensy36.menu.usb.hid.fake_serial=teensy_gateway +teensy36.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensy36.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensy36.menu.usb.midi=MIDI +teensy36.menu.usb.midi.build.usbtype=USB_MIDI +teensy36.menu.usb.midi.fake_serial=teensy_gateway +teensy36.menu.usb.midi4=MIDIx4 +teensy36.menu.usb.midi4.build.usbtype=USB_MIDI4 +teensy36.menu.usb.midi4.fake_serial=teensy_gateway +teensy36.menu.usb.midi16=MIDIx16 +teensy36.menu.usb.midi16.build.usbtype=USB_MIDI16 +teensy36.menu.usb.midi16.fake_serial=teensy_gateway +teensy36.menu.usb.serialmidi=Serial + MIDI +teensy36.menu.usb.serialmidi.build.usbtype=USB_MIDI_SERIAL +teensy36.menu.usb.serialmidi4=Serial + MIDIx4 +teensy36.menu.usb.serialmidi4.build.usbtype=USB_MIDI4_SERIAL +teensy36.menu.usb.serialmidi16=Serial + MIDIx16 +teensy36.menu.usb.serialmidi16.build.usbtype=USB_MIDI16_SERIAL +teensy36.menu.usb.audio=Audio +teensy36.menu.usb.audio.build.usbtype=USB_AUDIO +teensy36.menu.usb.audio.fake_serial=teensy_gateway +teensy36.menu.usb.serialmidiaudio=Serial + MIDI + Audio +teensy36.menu.usb.serialmidiaudio.build.usbtype=USB_MIDI_AUDIO_SERIAL +teensy36.menu.usb.serialmidi16audio=Serial + MIDIx16 + Audio +teensy36.menu.usb.serialmidi16audio.build.usbtype=USB_MIDI16_AUDIO_SERIAL +teensy36.menu.usb.mtp=MTP Disk (Experimental) +teensy36.menu.usb.mtp.build.usbtype=USB_MTPDISK +teensy36.menu.usb.mtp.fake_serial=teensy_gateway +teensy36.menu.usb.rawhid=Raw HID +teensy36.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensy36.menu.usb.rawhid.fake_serial=teensy_gateway +teensy36.menu.usb.flightsim=Flight Sim Controls +teensy36.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensy36.menu.usb.flightsim.fake_serial=teensy_gateway +teensy36.menu.usb.flightsimjoystick=Flight Sim Controls + Joystick +teensy36.menu.usb.flightsimjoystick.build.usbtype=USB_FLIGHTSIM_JOYSTICK +teensy36.menu.usb.flightsimjoystick.fake_serial=teensy_gateway +teensy36.menu.usb.everything=All of the Above +teensy36.menu.usb.everything.build.usbtype=USB_EVERYTHING +teensy36.menu.usb.disable=No USB +teensy36.menu.usb.disable.build.usbtype=USB_DISABLED + +teensy36.menu.speed.180=180 MHz +teensy36.menu.speed.168=168 MHz +teensy36.menu.speed.144=144 MHz +teensy36.menu.speed.120=120 MHz +teensy36.menu.speed.96=96 MHz +teensy36.menu.speed.72=72 MHz +teensy36.menu.speed.48=48 MHz +teensy36.menu.speed.24=24 MHz +teensy36.menu.speed.16=16 MHz (No USB) +teensy36.menu.speed.8=8 MHz (No USB) +teensy36.menu.speed.4=4 MHz (No USB) +teensy36.menu.speed.2=2 MHz (No USB) +teensy36.menu.speed.192=192 MHz (overclock) +teensy36.menu.speed.216=216 MHz (overclock) +teensy36.menu.speed.240=240 MHz (overclock) +teensy36.menu.speed.256=256 MHz (overclock) +teensy36.menu.speed.256.build.fcpu=256000000 +teensy36.menu.speed.240.build.fcpu=240000000 +teensy36.menu.speed.216.build.fcpu=216000000 +teensy36.menu.speed.192.build.fcpu=192000000 +teensy36.menu.speed.180.build.fcpu=180000000 +teensy36.menu.speed.168.build.fcpu=168000000 +teensy36.menu.speed.144.build.fcpu=144000000 +teensy36.menu.speed.120.build.fcpu=120000000 +teensy36.menu.speed.96.build.fcpu=96000000 +teensy36.menu.speed.72.build.fcpu=72000000 +teensy36.menu.speed.48.build.fcpu=48000000 +teensy36.menu.speed.24.build.fcpu=24000000 +teensy36.menu.speed.16.build.fcpu=16000000 +teensy36.menu.speed.8.build.fcpu=8000000 +teensy36.menu.speed.4.build.fcpu=4000000 +teensy36.menu.speed.2.build.fcpu=2000000 + +teensy36.menu.opt.o2std=Faster +teensy36.menu.opt.o2std.build.flags.optimize=-O2 +teensy36.menu.opt.o2std.build.flags.ldspecs= +teensy36.menu.opt.o2lto=Faster with LTO +teensy36.menu.opt.o2lto.build.flags.optimize=-O2 -flto -fno-fat-lto-objects +teensy36.menu.opt.o2lto.build.flags.ldspecs=-fuse-linker-plugin +teensy36.menu.opt.o1std=Fast +teensy36.menu.opt.o1std.build.flags.optimize=-O1 +teensy36.menu.opt.o1std.build.flags.ldspecs= +teensy36.menu.opt.o1lto=Fast with LTO +teensy36.menu.opt.o1lto.build.flags.optimize=-O1 -flto -fno-fat-lto-objects +teensy36.menu.opt.o1lto.build.flags.ldspecs=-fuse-linker-plugin +teensy36.menu.opt.o3std=Fastest +teensy36.menu.opt.o3std.build.flags.optimize=-O3 +teensy36.menu.opt.o3std.build.flags.ldspecs= +teensy36.menu.opt.o3purestd=Fastest + pure-code +teensy36.menu.opt.o3purestd.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ +teensy36.menu.opt.o3purestd.build.flags.ldspecs= +teensy36.menu.opt.o3lto=Fastest with LTO +teensy36.menu.opt.o3lto.build.flags.optimize=-O3 -flto -fno-fat-lto-objects +teensy36.menu.opt.o3lto.build.flags.ldspecs=-fuse-linker-plugin +teensy36.menu.opt.o3purelto=Fastest + pure-code with LTO +teensy36.menu.opt.o3purelto.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ -flto -fno-fat-lto-objects +teensy36.menu.opt.o3purelto.build.flags.ldspecs=-fuse-linker-plugin +teensy36.menu.opt.ogstd=Debug +teensy36.menu.opt.ogstd.build.flags.optimize=-Og +teensy36.menu.opt.ogstd.build.flags.ldspecs= +teensy36.menu.opt.oglto=Debug with LTO +teensy36.menu.opt.oglto.build.flags.optimize=-Og -flto -fno-fat-lto-objects +teensy36.menu.opt.oglto.build.flags.ldspecs=-fuse-linker-plugin +teensy36.menu.opt.osstd=Smallest Code +teensy36.menu.opt.osstd.build.flags.optimize=-Os --specs=nano.specs +teensy36.menu.opt.osstd.build.flags.ldspecs= +teensy36.menu.opt.oslto=Smallest Code with LTO +teensy36.menu.opt.oslto.build.flags.optimize=-Os -flto -fno-fat-lto-objects --specs=nano.specs +teensy36.menu.opt.oslto.build.flags.ldspecs=-fuse-linker-plugin + +teensy36.menu.keys.en-us=US English +teensy36.menu.keys.en-us.build.keylayout=US_ENGLISH +teensy36.menu.keys.fr-ca=Canadian French +teensy36.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensy36.menu.keys.xx-ca=Canadian Multilingual +teensy36.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensy36.menu.keys.cz-cz=Czech +teensy36.menu.keys.cz-cz.build.keylayout=CZECH +teensy36.menu.keys.da-da=Danish +teensy36.menu.keys.da-da.build.keylayout=DANISH +teensy36.menu.keys.fi-fi=Finnish +teensy36.menu.keys.fi-fi.build.keylayout=FINNISH +teensy36.menu.keys.fr-fr=French +teensy36.menu.keys.fr-fr.build.keylayout=FRENCH +teensy36.menu.keys.fr-be=French Belgian +teensy36.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensy36.menu.keys.fr-ch=French Swiss +teensy36.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensy36.menu.keys.de-de=German +teensy36.menu.keys.de-de.build.keylayout=GERMAN +teensy36.menu.keys.de-dm=German (Mac) +teensy36.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensy36.menu.keys.de-ch=German Swiss +teensy36.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensy36.menu.keys.is-is=Icelandic +teensy36.menu.keys.is-is.build.keylayout=ICELANDIC +teensy36.menu.keys.en-ie=Irish +teensy36.menu.keys.en-ie.build.keylayout=IRISH +teensy36.menu.keys.it-it=Italian +teensy36.menu.keys.it-it.build.keylayout=ITALIAN +teensy36.menu.keys.no-no=Norwegian +teensy36.menu.keys.no-no.build.keylayout=NORWEGIAN +teensy36.menu.keys.pt-pt=Portuguese +teensy36.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensy36.menu.keys.pt-br=Portuguese Brazilian +teensy36.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensy36.menu.keys.rs-rs=Serbian (Latin Only) +teensy36.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensy36.menu.keys.es-es=Spanish +teensy36.menu.keys.es-es.build.keylayout=SPANISH +teensy36.menu.keys.es-mx=Spanish Latin America +teensy36.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensy36.menu.keys.sv-se=Swedish +teensy36.menu.keys.sv-se.build.keylayout=SWEDISH +teensy36.menu.keys.tr-tr=Turkish (partial) +teensy36.menu.keys.tr-tr.build.keylayout=TURKISH +teensy36.menu.keys.en-gb=United Kingdom +teensy36.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensy36.menu.keys.usint=US International +teensy36.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + +teensy35.name=Teensy 3.5 +teensy35.upload.maximum_size=524288 +teensy35.upload.maximum_data_size=262136 +teensy35.upload.tool=teensyloader +teensy35.upload.protocol=halfkay +teensy35.build.board=TEENSY35 +teensy35.build.core=teensy3 +teensy35.build.mcu=mk64fx512 +teensy35.build.warn_data_percentage=98 +teensy35.build.toolchain=arm/bin/ +teensy35.build.command.gcc=arm-none-eabi-gcc +teensy35.build.command.g++=arm-none-eabi-g++ +teensy35.build.command.ar=arm-none-eabi-gcc-ar +teensy35.build.command.objcopy=arm-none-eabi-objcopy +teensy35.build.command.objdump=arm-none-eabi-objdump + +# KH, Fix linker error when using STL library +#teensy35.build.command.linker=arm-none-eabi-gcc +teensy35.build.command.linker=arm-none-eabi-g++ + +teensy35.build.command.size=arm-none-eabi-size +teensy35.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access +teensy35.build.flags.dep=-MMD +teensy35.build.flags.optimize=-Os +teensy35.build.flags.cpu=-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant +teensy35.build.flags.defs=-D__MK64FX512__ -DTEENSYDUINO=156 +teensy35.build.flags.cpp=-fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti +teensy35.build.flags.c= +teensy35.build.flags.S=-x assembler-with-cpp +teensy35.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk64fx512.ld" +teensy35.build.flags.libs=-larm_cortexM4lf_math -lm -lstdc++ +teensy35.serial.restart_cmd=false +teensy35.menu.usb.serial=Serial +teensy35.menu.usb.serial.build.usbtype=USB_SERIAL +teensy35.menu.usb.serial2=Dual Serial +teensy35.menu.usb.serial2.build.usbtype=USB_DUAL_SERIAL +teensy35.menu.usb.serial3=Triple Serial +teensy35.menu.usb.serial3.build.usbtype=USB_TRIPLE_SERIAL +teensy35.menu.usb.keyboard=Keyboard +teensy35.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY +teensy35.menu.usb.keyboard.fake_serial=teensy_gateway +teensy35.menu.usb.touch=Keyboard + Touch Screen +teensy35.menu.usb.touch.build.usbtype=USB_TOUCHSCREEN +teensy35.menu.usb.touch.fake_serial=teensy_gateway +teensy35.menu.usb.hidtouch=Keyboard + Mouse + Touch Screen +teensy35.menu.usb.hidtouch.build.usbtype=USB_HID_TOUCHSCREEN +teensy35.menu.usb.hidtouch.fake_serial=teensy_gateway +teensy35.menu.usb.hid=Keyboard + Mouse + Joystick +teensy35.menu.usb.hid.build.usbtype=USB_HID +teensy35.menu.usb.hid.fake_serial=teensy_gateway +teensy35.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensy35.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensy35.menu.usb.midi=MIDI +teensy35.menu.usb.midi.build.usbtype=USB_MIDI +teensy35.menu.usb.midi.fake_serial=teensy_gateway +teensy35.menu.usb.midi4=MIDIx4 +teensy35.menu.usb.midi4.build.usbtype=USB_MIDI4 +teensy35.menu.usb.midi4.fake_serial=teensy_gateway +teensy35.menu.usb.midi16=MIDIx16 +teensy35.menu.usb.midi16.build.usbtype=USB_MIDI16 +teensy35.menu.usb.midi16.fake_serial=teensy_gateway +teensy35.menu.usb.serialmidi=Serial + MIDI +teensy35.menu.usb.serialmidi.build.usbtype=USB_MIDI_SERIAL +teensy35.menu.usb.serialmidi4=Serial + MIDIx4 +teensy35.menu.usb.serialmidi4.build.usbtype=USB_MIDI4_SERIAL +teensy35.menu.usb.serialmidi16=Serial + MIDIx16 +teensy35.menu.usb.serialmidi16.build.usbtype=USB_MIDI16_SERIAL +teensy35.menu.usb.audio=Audio +teensy35.menu.usb.audio.build.usbtype=USB_AUDIO +teensy35.menu.usb.audio.fake_serial=teensy_gateway +teensy35.menu.usb.serialmidiaudio=Serial + MIDI + Audio +teensy35.menu.usb.serialmidiaudio.build.usbtype=USB_MIDI_AUDIO_SERIAL +teensy35.menu.usb.serialmidi16audio=Serial + MIDIx16 + Audio +teensy35.menu.usb.serialmidi16audio.build.usbtype=USB_MIDI16_AUDIO_SERIAL +teensy35.menu.usb.mtp=MTP Disk (Experimental) +teensy35.menu.usb.mtp.build.usbtype=USB_MTPDISK +teensy35.menu.usb.mtp.fake_serial=teensy_gateway +teensy35.menu.usb.rawhid=Raw HID +teensy35.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensy35.menu.usb.rawhid.fake_serial=teensy_gateway +teensy35.menu.usb.flightsim=Flight Sim Controls +teensy35.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensy35.menu.usb.flightsim.fake_serial=teensy_gateway +teensy35.menu.usb.flightsimjoystick=Flight Sim Controls + Joystick +teensy35.menu.usb.flightsimjoystick.build.usbtype=USB_FLIGHTSIM_JOYSTICK +teensy35.menu.usb.flightsimjoystick.fake_serial=teensy_gateway +teensy35.menu.usb.everything=All of the Above +teensy35.menu.usb.everything.build.usbtype=USB_EVERYTHING +teensy35.menu.usb.disable=No USB +teensy35.menu.usb.disable.build.usbtype=USB_DISABLED + +teensy35.menu.speed.120=120 MHz +teensy35.menu.speed.96=96 MHz +teensy35.menu.speed.72=72 MHz +teensy35.menu.speed.48=48 MHz +teensy35.menu.speed.24=24 MHz +teensy35.menu.speed.16=16 MHz (No USB) +teensy35.menu.speed.8=8 MHz (No USB) +teensy35.menu.speed.4=4 MHz (No USB) +teensy35.menu.speed.2=2 MHz (No USB) +teensy35.menu.speed.144=144 MHz (overclock) +teensy35.menu.speed.168=168 MHz (overclock) +teensy35.menu.speed.168.build.fcpu=168000000 +teensy35.menu.speed.144.build.fcpu=144000000 +teensy35.menu.speed.120.build.fcpu=120000000 +teensy35.menu.speed.96.build.fcpu=96000000 +teensy35.menu.speed.72.build.fcpu=72000000 +teensy35.menu.speed.48.build.fcpu=48000000 +teensy35.menu.speed.24.build.fcpu=24000000 +teensy35.menu.speed.16.build.fcpu=16000000 +teensy35.menu.speed.8.build.fcpu=8000000 +teensy35.menu.speed.4.build.fcpu=4000000 +teensy35.menu.speed.2.build.fcpu=2000000 + +teensy35.menu.opt.o2std=Faster +teensy35.menu.opt.o2std.build.flags.optimize=-O2 +teensy35.menu.opt.o2std.build.flags.ldspecs= +teensy35.menu.opt.o2lto=Faster with LTO +teensy35.menu.opt.o2lto.build.flags.optimize=-O2 -flto -fno-fat-lto-objects +teensy35.menu.opt.o2lto.build.flags.ldspecs=-fuse-linker-plugin +teensy35.menu.opt.o1std=Fast +teensy35.menu.opt.o1std.build.flags.optimize=-O1 +teensy35.menu.opt.o1std.build.flags.ldspecs= +teensy35.menu.opt.o1lto=Fast with LTO +teensy35.menu.opt.o1lto.build.flags.optimize=-O1 -flto -fno-fat-lto-objects +teensy35.menu.opt.o1lto.build.flags.ldspecs=-fuse-linker-plugin +teensy35.menu.opt.o3std=Fastest +teensy35.menu.opt.o3std.build.flags.optimize=-O3 +teensy35.menu.opt.o3std.build.flags.ldspecs= +teensy35.menu.opt.o3purestd=Fastest + pure-code +teensy35.menu.opt.o3purestd.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ +teensy35.menu.opt.o3purestd.build.flags.ldspecs= +teensy35.menu.opt.o3lto=Fastest with LTO +teensy35.menu.opt.o3lto.build.flags.optimize=-O3 -flto -fno-fat-lto-objects +teensy35.menu.opt.o3lto.build.flags.ldspecs=-fuse-linker-plugin +teensy35.menu.opt.o3purelto=Fastest + pure-code with LTO +teensy35.menu.opt.o3purelto.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ -flto -fno-fat-lto-objects +teensy35.menu.opt.o3purelto.build.flags.ldspecs=-fuse-linker-plugin +teensy35.menu.opt.ogstd=Debug +teensy35.menu.opt.ogstd.build.flags.optimize=-Og +teensy35.menu.opt.ogstd.build.flags.ldspecs= +teensy35.menu.opt.oglto=Debug with LTO +teensy35.menu.opt.oglto.build.flags.optimize=-Og -flto -fno-fat-lto-objects +teensy35.menu.opt.oglto.build.flags.ldspecs=-fuse-linker-plugin +teensy35.menu.opt.osstd=Smallest Code +teensy35.menu.opt.osstd.build.flags.optimize=-Os --specs=nano.specs +teensy35.menu.opt.osstd.build.flags.ldspecs= +teensy35.menu.opt.oslto=Smallest Code with LTO +teensy35.menu.opt.oslto.build.flags.optimize=-Os -flto -fno-fat-lto-objects --specs=nano.specs +teensy35.menu.opt.oslto.build.flags.ldspecs=-fuse-linker-plugin + +teensy35.menu.keys.en-us=US English +teensy35.menu.keys.en-us.build.keylayout=US_ENGLISH +teensy35.menu.keys.fr-ca=Canadian French +teensy35.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensy35.menu.keys.xx-ca=Canadian Multilingual +teensy35.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensy35.menu.keys.cz-cz=Czech +teensy35.menu.keys.cz-cz.build.keylayout=CZECH +teensy35.menu.keys.da-da=Danish +teensy35.menu.keys.da-da.build.keylayout=DANISH +teensy35.menu.keys.fi-fi=Finnish +teensy35.menu.keys.fi-fi.build.keylayout=FINNISH +teensy35.menu.keys.fr-fr=French +teensy35.menu.keys.fr-fr.build.keylayout=FRENCH +teensy35.menu.keys.fr-be=French Belgian +teensy35.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensy35.menu.keys.fr-ch=French Swiss +teensy35.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensy35.menu.keys.de-de=German +teensy35.menu.keys.de-de.build.keylayout=GERMAN +teensy35.menu.keys.de-dm=German (Mac) +teensy35.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensy35.menu.keys.de-ch=German Swiss +teensy35.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensy35.menu.keys.is-is=Icelandic +teensy35.menu.keys.is-is.build.keylayout=ICELANDIC +teensy35.menu.keys.en-ie=Irish +teensy35.menu.keys.en-ie.build.keylayout=IRISH +teensy35.menu.keys.it-it=Italian +teensy35.menu.keys.it-it.build.keylayout=ITALIAN +teensy35.menu.keys.no-no=Norwegian +teensy35.menu.keys.no-no.build.keylayout=NORWEGIAN +teensy35.menu.keys.pt-pt=Portuguese +teensy35.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensy35.menu.keys.pt-br=Portuguese Brazilian +teensy35.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensy35.menu.keys.rs-rs=Serbian (Latin Only) +teensy35.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensy35.menu.keys.es-es=Spanish +teensy35.menu.keys.es-es.build.keylayout=SPANISH +teensy35.menu.keys.es-mx=Spanish Latin America +teensy35.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensy35.menu.keys.sv-se=Swedish +teensy35.menu.keys.sv-se.build.keylayout=SWEDISH +teensy35.menu.keys.tr-tr=Turkish (partial) +teensy35.menu.keys.tr-tr.build.keylayout=TURKISH +teensy35.menu.keys.en-gb=United Kingdom +teensy35.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensy35.menu.keys.usint=US International +teensy35.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + +teensy31.name=Teensy 3.2 / 3.1 +teensy31.upload.maximum_size=262144 +teensy31.upload.maximum_data_size=65536 +teensy31.upload.tool=teensyloader +teensy31.upload.protocol=halfkay +teensy31.build.board=TEENSY32 +teensy31.build.core=teensy3 +teensy31.build.mcu=mk20dx256 +teensy31.build.warn_data_percentage=97 +teensy31.build.toolchain=arm/bin/ +teensy31.build.command.gcc=arm-none-eabi-gcc +teensy31.build.command.g++=arm-none-eabi-g++ +teensy31.build.command.ar=arm-none-eabi-gcc-ar +teensy31.build.command.objcopy=arm-none-eabi-objcopy +teensy31.build.command.objdump=arm-none-eabi-objdump + +# KH, Fix linker error when using STL library +#teensy31.build.command.linker=arm-none-eabi-gcc +teensy31.build.command.linker=arm-none-eabi-g++ + +teensy31.build.command.size=arm-none-eabi-size +teensy31.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access +teensy31.build.flags.dep=-MMD +teensy31.build.flags.optimize=-Os +teensy31.build.flags.cpu=-mthumb -mcpu=cortex-m4 -fsingle-precision-constant +teensy31.build.flags.defs=-D__MK20DX256__ -DTEENSYDUINO=156 +teensy31.build.flags.cpp=-fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti +teensy31.build.flags.c= +teensy31.build.flags.S=-x assembler-with-cpp +teensy31.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk20dx256.ld" +teensy31.build.flags.libs=-larm_cortexM4l_math -lm -lstdc++ +teensy31.serial.restart_cmd=false +teensy31.menu.usb.serial=Serial +teensy31.menu.usb.serial.build.usbtype=USB_SERIAL +teensy31.menu.usb.serial2=Dual Serial +teensy31.menu.usb.serial2.build.usbtype=USB_DUAL_SERIAL +teensy31.menu.usb.serial3=Triple Serial +teensy31.menu.usb.serial3.build.usbtype=USB_TRIPLE_SERIAL +teensy31.menu.usb.keyboard=Keyboard +teensy31.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY +teensy31.menu.usb.keyboard.fake_serial=teensy_gateway +teensy31.menu.usb.touch=Keyboard + Touch Screen +teensy31.menu.usb.touch.build.usbtype=USB_TOUCHSCREEN +teensy31.menu.usb.touch.fake_serial=teensy_gateway +teensy31.menu.usb.hidtouch=Keyboard + Mouse + Touch Screen +teensy31.menu.usb.hidtouch.build.usbtype=USB_HID_TOUCHSCREEN +teensy31.menu.usb.hidtouch.fake_serial=teensy_gateway +teensy31.menu.usb.hid=Keyboard + Mouse + Joystick +teensy31.menu.usb.hid.build.usbtype=USB_HID +teensy31.menu.usb.hid.fake_serial=teensy_gateway +teensy31.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensy31.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensy31.menu.usb.midi=MIDI +teensy31.menu.usb.midi.build.usbtype=USB_MIDI +teensy31.menu.usb.midi.fake_serial=teensy_gateway +teensy31.menu.usb.midi4=MIDIx4 +teensy31.menu.usb.midi4.build.usbtype=USB_MIDI4 +teensy31.menu.usb.midi4.fake_serial=teensy_gateway +teensy31.menu.usb.midi16=MIDIx16 +teensy31.menu.usb.midi16.build.usbtype=USB_MIDI16 +teensy31.menu.usb.midi16.fake_serial=teensy_gateway +teensy31.menu.usb.serialmidi=Serial + MIDI +teensy31.menu.usb.serialmidi.build.usbtype=USB_MIDI_SERIAL +teensy31.menu.usb.serialmidi4=Serial + MIDIx4 +teensy31.menu.usb.serialmidi4.build.usbtype=USB_MIDI4_SERIAL +teensy31.menu.usb.serialmidi16=Serial + MIDIx16 +teensy31.menu.usb.serialmidi16.build.usbtype=USB_MIDI16_SERIAL +teensy31.menu.usb.audio=Audio +teensy31.menu.usb.audio.build.usbtype=USB_AUDIO +teensy31.menu.usb.audio.fake_serial=teensy_gateway +teensy31.menu.usb.serialmidiaudio=Serial + MIDI + Audio +teensy31.menu.usb.serialmidiaudio.build.usbtype=USB_MIDI_AUDIO_SERIAL +teensy31.menu.usb.serialmidi16audio=Serial + MIDIx16 + Audio +teensy31.menu.usb.serialmidi16audio.build.usbtype=USB_MIDI16_AUDIO_SERIAL +teensy31.menu.usb.mtp=MTP Disk (Experimental) +teensy31.menu.usb.mtp.build.usbtype=USB_MTPDISK +teensy31.menu.usb.mtp.fake_serial=teensy_gateway +teensy31.menu.usb.rawhid=Raw HID +teensy31.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensy31.menu.usb.rawhid.fake_serial=teensy_gateway +teensy31.menu.usb.flightsim=Flight Sim Controls +teensy31.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensy31.menu.usb.flightsim.fake_serial=teensy_gateway +teensy31.menu.usb.flightsimjoystick=Flight Sim Controls + Joystick +teensy31.menu.usb.flightsimjoystick.build.usbtype=USB_FLIGHTSIM_JOYSTICK +teensy31.menu.usb.flightsimjoystick.fake_serial=teensy_gateway +teensy31.menu.usb.everything=All of the Above +teensy31.menu.usb.everything.build.usbtype=USB_EVERYTHING +teensy31.menu.usb.disable=No USB +teensy31.menu.usb.disable.build.usbtype=USB_DISABLED + +teensy31.menu.speed.96=96 MHz (overclock) +teensy31.menu.speed.72=72 MHz +teensy31.menu.speed.48=48 MHz +teensy31.menu.speed.24=24 MHz +teensy31.menu.speed.16=16 MHz (No USB) +teensy31.menu.speed.8=8 MHz (No USB) +teensy31.menu.speed.4=4 MHz (No USB) +teensy31.menu.speed.2=2 MHz (No USB) +teensy31.menu.speed.120=120 MHz (overclock) +#uncomment these if you want to try faster overclocking +#teensy31.menu.speed.144=144 MHz (overclock) +#teensy31.menu.speed.168=168 MHz (overclock) +teensy31.menu.speed.168.build.fcpu=168000000 +teensy31.menu.speed.144.build.fcpu=144000000 +teensy31.menu.speed.120.build.fcpu=120000000 +teensy31.menu.speed.96.build.fcpu=96000000 +teensy31.menu.speed.72.build.fcpu=72000000 +teensy31.menu.speed.48.build.fcpu=48000000 +teensy31.menu.speed.24.build.fcpu=24000000 +teensy31.menu.speed.16.build.fcpu=16000000 +teensy31.menu.speed.8.build.fcpu=8000000 +teensy31.menu.speed.4.build.fcpu=4000000 +teensy31.menu.speed.2.build.fcpu=2000000 + +teensy31.menu.opt.o2std=Faster +teensy31.menu.opt.o2std.build.flags.optimize=-O2 +teensy31.menu.opt.o2std.build.flags.ldspecs= +teensy31.menu.opt.o2lto=Faster with LTO +teensy31.menu.opt.o2lto.build.flags.optimize=-O2 -flto -fno-fat-lto-objects +teensy31.menu.opt.o2lto.build.flags.ldspecs=-fuse-linker-plugin +teensy31.menu.opt.o1std=Fast +teensy31.menu.opt.o1std.build.flags.optimize=-O1 +teensy31.menu.opt.o1std.build.flags.ldspecs= +teensy31.menu.opt.o1lto=Fast with LTO +teensy31.menu.opt.o1lto.build.flags.optimize=-O1 -flto -fno-fat-lto-objects +teensy31.menu.opt.o1lto.build.flags.ldspecs=-fuse-linker-plugin +teensy31.menu.opt.o3std=Fastest +teensy31.menu.opt.o3std.build.flags.optimize=-O3 +teensy31.menu.opt.o3std.build.flags.ldspecs= +teensy31.menu.opt.o3purestd=Fastest + pure-code +teensy31.menu.opt.o3purestd.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ +teensy31.menu.opt.o3purestd.build.flags.ldspecs= +teensy31.menu.opt.o3lto=Fastest with LTO +teensy31.menu.opt.o3lto.build.flags.optimize=-O3 -flto -fno-fat-lto-objects +teensy31.menu.opt.o3lto.build.flags.ldspecs=-fuse-linker-plugin +teensy31.menu.opt.o3purelto=Fastest + pure-code with LTO +teensy31.menu.opt.o3purelto.build.flags.optimize=-O3 -mpure-code -D__PURE_CODE__ -flto -fno-fat-lto-objects +teensy31.menu.opt.o3purelto.build.flags.ldspecs=-fuse-linker-plugin +teensy31.menu.opt.ogstd=Debug +teensy31.menu.opt.ogstd.build.flags.optimize=-Og +teensy31.menu.opt.ogstd.build.flags.ldspecs= +teensy31.menu.opt.oglto=Debug with LTO +teensy31.menu.opt.oglto.build.flags.optimize=-Og -flto -fno-fat-lto-objects +teensy31.menu.opt.oglto.build.flags.ldspecs=-fuse-linker-plugin +teensy31.menu.opt.osstd=Smallest Code +teensy31.menu.opt.osstd.build.flags.optimize=-Os --specs=nano.specs +teensy31.menu.opt.osstd.build.flags.ldspecs= +teensy31.menu.opt.oslto=Smallest Code with LTO +teensy31.menu.opt.oslto.build.flags.optimize=-Os -flto -fno-fat-lto-objects --specs=nano.specs +teensy31.menu.opt.oslto.build.flags.ldspecs=-fuse-linker-plugin + +teensy31.menu.keys.en-us=US English +teensy31.menu.keys.en-us.build.keylayout=US_ENGLISH +teensy31.menu.keys.fr-ca=Canadian French +teensy31.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensy31.menu.keys.xx-ca=Canadian Multilingual +teensy31.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensy31.menu.keys.cz-cz=Czech +teensy31.menu.keys.cz-cz.build.keylayout=CZECH +teensy31.menu.keys.da-da=Danish +teensy31.menu.keys.da-da.build.keylayout=DANISH +teensy31.menu.keys.fi-fi=Finnish +teensy31.menu.keys.fi-fi.build.keylayout=FINNISH +teensy31.menu.keys.fr-fr=French +teensy31.menu.keys.fr-fr.build.keylayout=FRENCH +teensy31.menu.keys.fr-be=French Belgian +teensy31.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensy31.menu.keys.fr-ch=French Swiss +teensy31.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensy31.menu.keys.de-de=German +teensy31.menu.keys.de-de.build.keylayout=GERMAN +teensy31.menu.keys.de-dm=German (Mac) +teensy31.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensy31.menu.keys.de-ch=German Swiss +teensy31.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensy31.menu.keys.is-is=Icelandic +teensy31.menu.keys.is-is.build.keylayout=ICELANDIC +teensy31.menu.keys.en-ie=Irish +teensy31.menu.keys.en-ie.build.keylayout=IRISH +teensy31.menu.keys.it-it=Italian +teensy31.menu.keys.it-it.build.keylayout=ITALIAN +teensy31.menu.keys.no-no=Norwegian +teensy31.menu.keys.no-no.build.keylayout=NORWEGIAN +teensy31.menu.keys.pt-pt=Portuguese +teensy31.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensy31.menu.keys.pt-br=Portuguese Brazilian +teensy31.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensy31.menu.keys.rs-rs=Serbian (Latin Only) +teensy31.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensy31.menu.keys.es-es=Spanish +teensy31.menu.keys.es-es.build.keylayout=SPANISH +teensy31.menu.keys.es-mx=Spanish Latin America +teensy31.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensy31.menu.keys.sv-se=Swedish +teensy31.menu.keys.sv-se.build.keylayout=SWEDISH +teensy31.menu.keys.tr-tr=Turkish (partial) +teensy31.menu.keys.tr-tr.build.keylayout=TURKISH +teensy31.menu.keys.en-gb=United Kingdom +teensy31.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensy31.menu.keys.usint=US International +teensy31.menu.keys.usint.build.keylayout=US_INTERNATIONAL + +teensy31.vid.0=0x16C0 +teensy31.vid.1=0x16C0 +teensy31.vid.2=0x16C0 +teensy31.vid.3=0x16C0 +teensy31.vid.4=0x16C0 +teensy31.pid.0=0x0483 +teensy31.pid.1=0x0487 +teensy31.pid.2=0x0489 +teensy31.pid.3=0x048A +teensy31.pid.4=0x0476 + +teensy30.name=Teensy 3.0 +teensy30.upload.maximum_size=131072 +teensy30.upload.maximum_data_size=16384 +teensy30.upload.tool=teensyloader +teensy30.upload.protocol=halfkay +teensy30.build.board=TEENSY30 +teensy30.build.core=teensy3 +teensy30.build.mcu=mk20dx128 +teensy30.build.warn_data_percentage=94 +teensy30.build.toolchain=arm/bin/ +teensy30.build.command.gcc=arm-none-eabi-gcc +teensy30.build.command.g++=arm-none-eabi-g++ +teensy30.build.command.ar=arm-none-eabi-gcc-ar +teensy30.build.command.objcopy=arm-none-eabi-objcopy +teensy30.build.command.objdump=arm-none-eabi-objdump + +# KH, Fix linker error when using STL library +#teensy30.build.command.linker=arm-none-eabi-gcc +teensy30.build.command.linker=arm-none-eabi-g++ + +teensy30.build.command.size=arm-none-eabi-size +teensy30.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access +teensy30.build.flags.dep=-MMD +teensy30.build.flags.optimize=-Os +teensy30.build.flags.cpu=-mthumb -mcpu=cortex-m4 -fsingle-precision-constant +teensy30.build.flags.defs=-D__MK20DX128__ -DTEENSYDUINO=156 +teensy30.build.flags.cpp=-fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti +teensy30.build.flags.c= +teensy30.build.flags.S=-x assembler-with-cpp +teensy30.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk20dx128.ld" +teensy30.build.flags.ldspecs=--specs=nano.specs +teensy30.build.flags.libs=-larm_cortexM4l_math -lm -lstdc++ +teensy30.serial.restart_cmd=false + +teensy30.menu.usb.serial=Serial +teensy30.menu.usb.serial.build.usbtype=USB_SERIAL +teensy30.menu.usb.keyboard=Keyboard +teensy30.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY +teensy30.menu.usb.keyboard.fake_serial=teensy_gateway +teensy30.menu.usb.hid=Keyboard + Mouse + Joystick +teensy30.menu.usb.hid.build.usbtype=USB_HID +teensy30.menu.usb.hid.fake_serial=teensy_gateway +teensy30.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensy30.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensy30.menu.usb.touch=Keyboard + Touch Screen +teensy30.menu.usb.touch.build.usbtype=USB_TOUCHSCREEN +teensy30.menu.usb.touch.fake_serial=teensy_gateway +teensy30.menu.usb.midi=MIDI +teensy30.menu.usb.midi.build.usbtype=USB_MIDI +teensy30.menu.usb.midi.fake_serial=teensy_gateway +teensy30.menu.usb.midi4=MIDIx4 +teensy30.menu.usb.midi4.build.usbtype=USB_MIDI4 +teensy30.menu.usb.midi4.fake_serial=teensy_gateway +teensy30.menu.usb.serialmidi=Serial + MIDI +teensy30.menu.usb.serialmidi.build.usbtype=USB_MIDI_SERIAL +teensy30.menu.usb.serialmidi4=Serial + MIDIx4 +teensy30.menu.usb.serialmidi4.build.usbtype=USB_MIDI4_SERIAL +teensy30.menu.usb.audio=Audio +teensy30.menu.usb.audio.build.usbtype=USB_AUDIO +teensy30.menu.usb.audio.fake_serial=teensy_gateway +teensy30.menu.usb.serialmidiaudio=Serial + MIDI + Audio +teensy30.menu.usb.serialmidiaudio.build.usbtype=USB_MIDI_AUDIO_SERIAL +teensy30.menu.usb.mtp=MTP Disk (Experimental) +teensy30.menu.usb.mtp.build.usbtype=USB_MTPDISK +teensy30.menu.usb.mtp.fake_serial=teensy_gateway +teensy30.menu.usb.rawhid=Raw HID +teensy30.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensy30.menu.usb.rawhid.fake_serial=teensy_gateway +teensy30.menu.usb.flightsim=Flight Sim Controls +teensy30.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensy30.menu.usb.flightsim.fake_serial=teensy_gateway +teensy30.menu.usb.disable=No USB +teensy30.menu.usb.disable.build.usbtype=USB_DISABLED + +teensy30.menu.speed.96=96 MHz (overclock) +teensy30.menu.speed.48=48 MHz +teensy30.menu.speed.24=24 MHz +teensy30.menu.speed.96.build.fcpu=96000000 +teensy30.menu.speed.48.build.fcpu=48000000 +teensy30.menu.speed.24.build.fcpu=24000000 + +teensy30.menu.opt.o2std=Faster +teensy30.menu.opt.o2std.build.flags.optimize=-O2 +teensy30.menu.opt.o2std.build.flags.ldspecs= +teensy30.menu.opt.o2lto=Faster with LTO +teensy30.menu.opt.o2lto.build.flags.optimize=-O2 -flto -fno-fat-lto-objects +teensy30.menu.opt.o2lto.build.flags.ldspecs=-fuse-linker-plugin +teensy30.menu.opt.o1std=Fast +teensy30.menu.opt.o1std.build.flags.optimize=-O1 +teensy30.menu.opt.o1std.build.flags.ldspecs= +teensy30.menu.opt.o1lto=Fast with LTO +teensy30.menu.opt.o1lto.build.flags.optimize=-O1 -flto -fno-fat-lto-objects +teensy30.menu.opt.o1lto.build.flags.ldspecs=-fuse-linker-plugin +teensy30.menu.opt.o3std=Fastest +teensy30.menu.opt.o3std.build.flags.optimize=-O3 +teensy30.menu.opt.o3std.build.flags.ldspecs= +teensy30.menu.opt.o3lto=Fastest with LTO +teensy30.menu.opt.o3lto.build.flags.optimize=-O3 -flto -fno-fat-lto-objects +teensy30.menu.opt.o3lto.build.flags.ldspecs=-fuse-linker-plugin +teensy30.menu.opt.ogstd=Debug +teensy30.menu.opt.ogstd.build.flags.optimize=-Og +teensy30.menu.opt.ogstd.build.flags.ldspecs= +teensy30.menu.opt.oglto=Debug with LTO +teensy30.menu.opt.oglto.build.flags.optimize=-Og -flto -fno-fat-lto-objects +teensy30.menu.opt.oglto.build.flags.ldspecs=-fuse-linker-plugin +teensy30.menu.opt.osstd=Smallest Code +teensy30.menu.opt.osstd.build.flags.optimize=-Os --specs=nano.specs +teensy30.menu.opt.osstd.build.flags.ldspecs= +teensy30.menu.opt.oslto=Smallest Code with LTO +teensy30.menu.opt.oslto.build.flags.optimize=-Os -flto -fno-fat-lto-objects --specs=nano.specs +teensy30.menu.opt.oslto.build.flags.ldspecs=-fuse-linker-plugin + +teensy30.menu.keys.en-us=US English +teensy30.menu.keys.en-us.build.keylayout=US_ENGLISH +teensy30.menu.keys.fr-ca=Canadian French +teensy30.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensy30.menu.keys.xx-ca=Canadian Multilingual +teensy30.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensy30.menu.keys.cz-cz=Czech +teensy30.menu.keys.cz-cz.build.keylayout=CZECH +teensy30.menu.keys.da-da=Danish +teensy30.menu.keys.da-da.build.keylayout=DANISH +teensy30.menu.keys.fi-fi=Finnish +teensy30.menu.keys.fi-fi.build.keylayout=FINNISH +teensy30.menu.keys.fr-fr=French +teensy30.menu.keys.fr-fr.build.keylayout=FRENCH +teensy30.menu.keys.fr-be=French Belgian +teensy30.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensy30.menu.keys.fr-ch=French Swiss +teensy30.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensy30.menu.keys.de-de=German +teensy30.menu.keys.de-de.build.keylayout=GERMAN +teensy30.menu.keys.de-dm=German (Mac) +teensy30.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensy30.menu.keys.de-ch=German Swiss +teensy30.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensy30.menu.keys.is-is=Icelandic +teensy30.menu.keys.is-is.build.keylayout=ICELANDIC +teensy30.menu.keys.en-ie=Irish +teensy30.menu.keys.en-ie.build.keylayout=IRISH +teensy30.menu.keys.it-it=Italian +teensy30.menu.keys.it-it.build.keylayout=ITALIAN +teensy30.menu.keys.no-no=Norwegian +teensy30.menu.keys.no-no.build.keylayout=NORWEGIAN +teensy30.menu.keys.pt-pt=Portuguese +teensy30.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensy30.menu.keys.pt-br=Portuguese Brazilian +teensy30.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensy30.menu.keys.rs-rs=Serbian (Latin Only) +teensy30.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensy30.menu.keys.es-es=Spanish +teensy30.menu.keys.es-es.build.keylayout=SPANISH +teensy30.menu.keys.es-mx=Spanish Latin America +teensy30.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensy30.menu.keys.sv-se=Swedish +teensy30.menu.keys.sv-se.build.keylayout=SWEDISH +teensy30.menu.keys.tr-tr=Turkish (partial) +teensy30.menu.keys.tr-tr.build.keylayout=TURKISH +teensy30.menu.keys.en-gb=United Kingdom +teensy30.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensy30.menu.keys.usint=US International +teensy30.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + +teensyLC.name=Teensy LC +teensyLC.upload.maximum_size=63488 +teensyLC.upload.maximum_data_size=8192 +teensyLC.upload.tool=teensyloader +teensyLC.upload.protocol=halfkay +teensyLC.build.board=TEENSYLC +teensyLC.build.core=teensy3 +teensyLC.build.mcu=mkl26z64 +teensyLC.build.warn_data_percentage=88 +teensyLC.build.toolchain=arm/bin/ +teensyLC.build.command.gcc=arm-none-eabi-gcc +teensyLC.build.command.g++=arm-none-eabi-g++ +teensyLC.build.command.ar=arm-none-eabi-gcc-ar +teensyLC.build.command.objcopy=arm-none-eabi-objcopy +teensyLC.build.command.objdump=arm-none-eabi-objdump + +# KH, Fix linker error when using STL library +#teensyLC.build.command.linker=arm-none-eabi-gcc +teensyLC.build.command.linker=arm-none-eabi-g++ + +teensyLC.build.command.size=arm-none-eabi-size +teensyLC.build.flags.common=-g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access +teensyLC.build.flags.dep=-MMD +teensyLC.build.flags.cpu=-mthumb -mcpu=cortex-m0plus -fsingle-precision-constant +teensyLC.build.flags.defs=-D__MKL26Z64__ -DTEENSYDUINO=156 +teensyLC.build.flags.cpp=-fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti +teensyLC.build.flags.c= +teensyLC.build.flags.S=-x assembler-with-cpp +teensyLC.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mkl26z64.ld" +teensyLC.build.flags.libs=-larm_cortexM0l_math -lm -lstdc++ +teensyLC.serial.restart_cmd=false +teensyLC.menu.usb.serial=Serial +teensyLC.menu.usb.serial.build.usbtype=USB_SERIAL +teensyLC.menu.usb.serial2=Dual Serial +teensyLC.menu.usb.serial2.build.usbtype=USB_DUAL_SERIAL +teensyLC.menu.usb.serial3=Triple Serial +teensyLC.menu.usb.serial3.build.usbtype=USB_TRIPLE_SERIAL +teensyLC.menu.usb.keyboard=Keyboard +teensyLC.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY +teensyLC.menu.usb.keyboard.fake_serial=teensy_gateway +teensyLC.menu.usb.hid=Keyboard + Mouse + Joystick +teensyLC.menu.usb.hid.build.usbtype=USB_HID +teensyLC.menu.usb.hid.fake_serial=teensy_gateway +teensyLC.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensyLC.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensyLC.menu.usb.touch=Keyboard + Touch Screen +teensyLC.menu.usb.touch.build.usbtype=USB_TOUCHSCREEN +teensyLC.menu.usb.touch.fake_serial=teensy_gateway +teensyLC.menu.usb.midi=MIDI +teensyLC.menu.usb.midi.build.usbtype=USB_MIDI +teensyLC.menu.usb.midi.fake_serial=teensy_gateway +teensyLC.menu.usb.midi4=MIDIx4 +teensyLC.menu.usb.midi4.build.usbtype=USB_MIDI4 +teensyLC.menu.usb.midi4.fake_serial=teensy_gateway +teensyLC.menu.usb.serialmidi=Serial + MIDI +teensyLC.menu.usb.serialmidi.build.usbtype=USB_MIDI_SERIAL +teensyLC.menu.usb.serialmidi4=Serial + MIDIx4 +teensyLC.menu.usb.serialmidi4.build.usbtype=USB_MIDI4_SERIAL +teensyLC.menu.usb.mtp=MTP Disk (Experimental) +teensyLC.menu.usb.mtp.build.usbtype=USB_MTPDISK +teensyLC.menu.usb.mtp.fake_serial=teensy_gateway +teensyLC.menu.usb.rawhid=Raw HID +teensyLC.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensyLC.menu.usb.rawhid.fake_serial=teensy_gateway +teensyLC.menu.usb.flightsim=Flight Sim Controls +teensyLC.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensyLC.menu.usb.flightsim.fake_serial=teensy_gateway +teensyLC.menu.usb.disable=No USB +teensyLC.menu.usb.disable.build.usbtype=USB_DISABLED + +teensyLC.menu.speed.48=48 MHz +teensyLC.menu.speed.24=24 MHz +teensyLC.menu.speed.48.build.fcpu=48000000 +teensyLC.menu.speed.24.build.fcpu=24000000 + +teensyLC.menu.opt.osstd=Smallest Code +teensyLC.menu.opt.osstd.build.flags.optimize=-Os --specs=nano.specs +teensyLC.menu.opt.osstd.build.flags.ldspecs= +teensyLC.menu.opt.oslto=Smallest Code with LTO +teensyLC.menu.opt.oslto.build.flags.optimize=-Os -flto -fno-fat-lto-objects --specs=nano.specs +teensyLC.menu.opt.oslto.build.flags.ldspecs=-fuse-linker-plugin +teensyLC.menu.opt.ogstd=Debug +teensyLC.menu.opt.ogstd.build.flags.optimize=-Og +teensyLC.menu.opt.ogstd.build.flags.ldspecs= +teensyLC.menu.opt.oglto=Debug with LTO +teensyLC.menu.opt.oglto.build.flags.optimize=-Og -flto -fno-fat-lto-objects +teensyLC.menu.opt.oglto.build.flags.ldspecs=-fuse-linker-plugin +teensyLC.menu.opt.o3std=Fastest +teensyLC.menu.opt.o3std.build.flags.optimize=-O3 +teensyLC.menu.opt.o3std.build.flags.ldspecs= +teensyLC.menu.opt.o3lto=Fastest with LTO +teensyLC.menu.opt.o3lto.build.flags.optimize=-O3 -flto -fno-fat-lto-objects +teensyLC.menu.opt.o3lto.build.flags.ldspecs=-fuse-linker-plugin +teensyLC.menu.opt.o2std=Faster +teensyLC.menu.opt.o2std.build.flags.optimize=-O2 +teensyLC.menu.opt.o2std.build.flags.ldspecs= +teensyLC.menu.opt.o2lto=Faster with LTO +teensyLC.menu.opt.o2lto.build.flags.optimize=-O2 -flto -fno-fat-lto-objects +teensyLC.menu.opt.o2lto.build.flags.ldspecs=-fuse-linker-plugin +teensyLC.menu.opt.o1std=Fast +teensyLC.menu.opt.o1std.build.flags.optimize=-O1 +teensyLC.menu.opt.o1std.build.flags.ldspecs= +teensyLC.menu.opt.o1lto=Fast with LTO +teensyLC.menu.opt.o1lto.build.flags.optimize=-O1 -flto -fno-fat-lto-objects +teensyLC.menu.opt.o1lto.build.flags.ldspecs=-fuse-linker-plugin + +teensyLC.menu.keys.en-us=US English +teensyLC.menu.keys.en-us.build.keylayout=US_ENGLISH +teensyLC.menu.keys.fr-ca=Canadian French +teensyLC.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensyLC.menu.keys.xx-ca=Canadian Multilingual +teensyLC.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensyLC.menu.keys.cz-cz=Czech +teensyLC.menu.keys.cz-cz.build.keylayout=CZECH +teensyLC.menu.keys.da-da=Danish +teensyLC.menu.keys.da-da.build.keylayout=DANISH +teensyLC.menu.keys.fi-fi=Finnish +teensyLC.menu.keys.fi-fi.build.keylayout=FINNISH +teensyLC.menu.keys.fr-fr=French +teensyLC.menu.keys.fr-fr.build.keylayout=FRENCH +teensyLC.menu.keys.fr-be=French Belgian +teensyLC.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensyLC.menu.keys.fr-ch=French Swiss +teensyLC.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensyLC.menu.keys.de-de=German +teensyLC.menu.keys.de-de.build.keylayout=GERMAN +teensyLC.menu.keys.de-dm=German (Mac) +teensyLC.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensyLC.menu.keys.de-ch=German Swiss +teensyLC.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensyLC.menu.keys.is-is=Icelandic +teensyLC.menu.keys.is-is.build.keylayout=ICELANDIC +teensyLC.menu.keys.en-ie=Irish +teensyLC.menu.keys.en-ie.build.keylayout=IRISH +teensyLC.menu.keys.it-it=Italian +teensyLC.menu.keys.it-it.build.keylayout=ITALIAN +teensyLC.menu.keys.no-no=Norwegian +teensyLC.menu.keys.no-no.build.keylayout=NORWEGIAN +teensyLC.menu.keys.pt-pt=Portuguese +teensyLC.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensyLC.menu.keys.pt-br=Portuguese Brazilian +teensyLC.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensyLC.menu.keys.rs-rs=Serbian (Latin Only) +teensyLC.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensyLC.menu.keys.es-es=Spanish +teensyLC.menu.keys.es-es.build.keylayout=SPANISH +teensyLC.menu.keys.es-mx=Spanish Latin America +teensyLC.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensyLC.menu.keys.sv-se=Swedish +teensyLC.menu.keys.sv-se.build.keylayout=SWEDISH +teensyLC.menu.keys.tr-tr=Turkish (partial) +teensyLC.menu.keys.tr-tr.build.keylayout=TURKISH +teensyLC.menu.keys.en-gb=United Kingdom +teensyLC.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensyLC.menu.keys.usint=US International +teensyLC.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + +teensypp2.name=Teensy++ 2.0 +teensypp2.upload.maximum_size=130048 +teensypp2.upload.maximum_data_size=8192 +teensypp2.upload.tool=teensyloader +teensypp2.upload.protocol=halfkay +teensypp2.build.board=TEENSY2PP +teensypp2.build.core=teensy +teensypp2.build.mcu=at90usb1286 +teensypp2.build.warn_data_percentage=94 +teensypp2.build.toolchain=avr/bin/ +teensypp2.build.command.gcc=avr-gcc +teensypp2.build.command.g++=avr-g++ +teensypp2.build.command.ar=avr-ar +teensypp2.build.command.objcopy=avr-objcopy +teensypp2.build.command.objdump=avr-objdump +teensypp2.build.command.linker=avr-gcc +teensypp2.build.command.size=avr-size +teensypp2.build.flags.common=-g -Wall -ffunction-sections -fdata-sections +teensypp2.build.flags.dep=-MMD +teensypp2.build.flags.optimize=-Os +teensypp2.build.flags.cpu=-mmcu=at90usb1286 +teensypp2.build.flags.defs=-DTEENSYDUINO=156 -DARDUINO_ARCH_AVR +teensypp2.build.flags.cpp=-fno-exceptions -fpermissive -felide-constructors -std=gnu++11 +teensypp2.build.flags.c= +teensypp2.build.flags.S=-x assembler-with-cpp +teensypp2.build.flags.ld=-Wl,--gc-sections,--relax +teensypp2.build.flags.ldspecs= +teensypp2.build.flags.libs=-lm +teensypp2.build.serial_number=true +teensypp2.serial.restart_cmd=true + +teensypp2.menu.usb.serial=Serial +teensypp2.menu.usb.serial.build.usbtype=USB_SERIAL +teensypp2.menu.usb.hid=Keyboard + Mouse + Joystick +teensypp2.menu.usb.hid.build.usbtype=USB_HID +teensypp2.menu.usb.hid.fake_serial=teensy_gateway +teensypp2.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensypp2.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensypp2.menu.usb.int_disk=Disk(Internal) + Keyboard +teensypp2.menu.usb.int_disk.build.usbtype=USB_DISK +teensypp2.menu.usb.int_disk.fake_serial=teensy_gateway +teensypp2.menu.usb.int_disk.build.elfpatch=mktinyfat +teensypp2.menu.usb.sd_disk=Disk(SD Card) + Keyboard +teensypp2.menu.usb.sd_disk.build.usbtype=USB_DISK_SDFLASH +teensypp2.menu.usb.sd_disk.fake_serial=teensy_gateway +teensypp2.menu.usb.midi=MIDI +teensypp2.menu.usb.midi.build.usbtype=USB_MIDI +teensypp2.menu.usb.midi.fake_serial=teensy_gateway +teensypp2.menu.usb.rawhid=Raw HID +teensypp2.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensypp2.menu.usb.rawhid.fake_serial=teensy_gateway +teensypp2.menu.usb.flightsim=Flight Sim Controls +teensypp2.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensypp2.menu.usb.flightsim.fake_serial=teensy_gateway +teensypp2.menu.speed.16=16 MHz +teensypp2.menu.speed.8=8 MHz +teensypp2.menu.speed.4=4 MHz +teensypp2.menu.speed.2=2 MHz +teensypp2.menu.speed.1=1 MHz +teensypp2.menu.speed.16.build.fcpu=16000000L +teensypp2.menu.speed.8.build.fcpu=8000000L +teensypp2.menu.speed.4.build.fcpu=4000000L +teensypp2.menu.speed.2.build.fcpu=2000000L +teensypp2.menu.speed.1.build.fcpu=1000000L + +teensypp2.menu.keys.en-us=US English +teensypp2.menu.keys.en-us.build.keylayout=US_ENGLISH +teensypp2.menu.keys.fr-ca=Canadian French +teensypp2.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensypp2.menu.keys.xx-ca=Canadian Multilingual +teensypp2.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensypp2.menu.keys.cz-cz=Czech +teensypp2.menu.keys.cz-cz.build.keylayout=CZECH +teensypp2.menu.keys.da-da=Danish +teensypp2.menu.keys.da-da.build.keylayout=DANISH +teensypp2.menu.keys.fi-fi=Finnish +teensypp2.menu.keys.fi-fi.build.keylayout=FINNISH +teensypp2.menu.keys.fr-fr=French +teensypp2.menu.keys.fr-fr.build.keylayout=FRENCH +teensypp2.menu.keys.fr-be=French Belgian +teensypp2.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensypp2.menu.keys.fr-ch=French Swiss +teensypp2.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensypp2.menu.keys.de-de=German +teensypp2.menu.keys.de-de.build.keylayout=GERMAN +teensypp2.menu.keys.de-dm=German (Mac) +teensypp2.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensypp2.menu.keys.de-ch=German Swiss +teensypp2.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensypp2.menu.keys.is-is=Icelandic +teensypp2.menu.keys.is-is.build.keylayout=ICELANDIC +teensypp2.menu.keys.en-ie=Irish +teensypp2.menu.keys.en-ie.build.keylayout=IRISH +teensypp2.menu.keys.it-it=Italian +teensypp2.menu.keys.it-it.build.keylayout=ITALIAN +teensypp2.menu.keys.no-no=Norwegian +teensypp2.menu.keys.no-no.build.keylayout=NORWEGIAN +teensypp2.menu.keys.pt-pt=Portuguese +teensypp2.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensypp2.menu.keys.pt-br=Portuguese Brazilian +teensypp2.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensypp2.menu.keys.rs-rs=Serbian (Latin Only) +teensypp2.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensypp2.menu.keys.es-es=Spanish +teensypp2.menu.keys.es-es.build.keylayout=SPANISH +teensypp2.menu.keys.es-mx=Spanish Latin America +teensypp2.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensypp2.menu.keys.sv-se=Swedish +teensypp2.menu.keys.sv-se.build.keylayout=SWEDISH +teensypp2.menu.keys.tr-tr=Turkish (partial) +teensypp2.menu.keys.tr-tr.build.keylayout=TURKISH +teensypp2.menu.keys.en-gb=United Kingdom +teensypp2.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensypp2.menu.keys.usint=US International +teensypp2.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + +teensy2.name=Teensy 2.0 +teensy2.upload.maximum_size=32256 +teensy2.upload.maximum_data_size=2560 +teensy2.upload.tool=teensyloader +teensy2.upload.protocol=halfkay +teensy2.build.board=TEENSY2 +teensy2.build.core=teensy +teensy2.build.mcu=atmega32u4 +teensy2.build.warn_data_percentage=80 +teensy2.build.toolchain=avr/bin/ +teensy2.build.command.gcc=avr-gcc +teensy2.build.command.g++=avr-g++ +teensy2.build.command.ar=avr-ar +teensy2.build.command.objcopy=avr-objcopy +teensy2.build.command.objdump=avr-objdump +teensy2.build.command.linker=avr-gcc +teensy2.build.command.size=avr-size +teensy2.build.flags.common=-g -Wall -ffunction-sections -fdata-sections +teensy2.build.flags.dep=-MMD +teensy2.build.flags.optimize=-Os +teensy2.build.flags.cpu=-mmcu=atmega32u4 +teensy2.build.flags.defs=-DTEENSYDUINO=156 -DARDUINO_ARCH_AVR +teensy2.build.flags.cpp=-fno-exceptions -fpermissive -felide-constructors -std=gnu++11 +teensy2.build.flags.c= +teensy2.build.flags.S=-x assembler-with-cpp +teensy2.build.flags.ld=-Wl,--gc-sections,--relax +teensy2.build.flags.ldspecs= +teensy2.build.flags.libs=-lm +teensy2.build.serial_number=true +teensy2.serial.restart_cmd=true + +teensy2.menu.usb.serial=Serial +teensy2.menu.usb.serial.build.usbtype=USB_SERIAL +teensy2.menu.usb.hid=Keyboard + Mouse + Joystick +teensy2.menu.usb.hid.build.usbtype=USB_HID +teensy2.menu.usb.hid.fake_serial=teensy_gateway +teensy2.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick +teensy2.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID +teensy2.menu.usb.int_disk=Disk(Internal) + Keyboard +teensy2.menu.usb.int_disk.build.usbtype=USB_DISK +teensy2.menu.usb.int_disk.fake_serial=teensy_gateway +teensy2.menu.usb.int_disk.build.elfpatch=mktinyfat +teensy2.menu.usb.sd_disk=Disk(SD Card) + Keyboard +teensy2.menu.usb.sd_disk.build.usbtype=USB_DISK_SDFLASH +teensy2.menu.usb.sd_disk.fake_serial=teensy_gateway +teensy2.menu.usb.midi=MIDI +teensy2.menu.usb.midi.build.usbtype=USB_MIDI +teensy2.menu.usb.midi.fake_serial=teensy_gateway +teensy2.menu.usb.rawhid=Raw HID +teensy2.menu.usb.rawhid.build.usbtype=USB_RAWHID +teensy2.menu.usb.rawhid.fake_serial=teensy_gateway +teensy2.menu.usb.flightsim=Flight Sim Controls +teensy2.menu.usb.flightsim.build.usbtype=USB_FLIGHTSIM +teensy2.menu.usb.flightsim.fake_serial=teensy_gateway +teensy2.menu.speed.16=16 MHz +teensy2.menu.speed.8=8 MHz +teensy2.menu.speed.4=4 MHz +teensy2.menu.speed.2=2 MHz +teensy2.menu.speed.1=1 MHz +teensy2.menu.speed.16.build.fcpu=16000000L +teensy2.menu.speed.8.build.fcpu=8000000L +teensy2.menu.speed.4.build.fcpu=4000000L +teensy2.menu.speed.2.build.fcpu=2000000L +teensy2.menu.speed.1.build.fcpu=1000000L + +teensy2.menu.keys.en-us=US English +teensy2.menu.keys.en-us.build.keylayout=US_ENGLISH +teensy2.menu.keys.fr-ca=Canadian French +teensy2.menu.keys.fr-ca.build.keylayout=CANADIAN_FRENCH +teensy2.menu.keys.xx-ca=Canadian Multilingual +teensy2.menu.keys.xx-ca.build.keylayout=CANADIAN_MULTILINGUAL +teensy2.menu.keys.cz-cz=Czech +teensy2.menu.keys.cz-cz.build.keylayout=CZECH +teensy2.menu.keys.da-da=Danish +teensy2.menu.keys.da-da.build.keylayout=DANISH +teensy2.menu.keys.fi-fi=Finnish +teensy2.menu.keys.fi-fi.build.keylayout=FINNISH +teensy2.menu.keys.fr-fr=French +teensy2.menu.keys.fr-fr.build.keylayout=FRENCH +teensy2.menu.keys.fr-be=French Belgian +teensy2.menu.keys.fr-be.build.keylayout=FRENCH_BELGIAN +teensy2.menu.keys.fr-ch=French Swiss +teensy2.menu.keys.fr-ch.build.keylayout=FRENCH_SWISS +teensy2.menu.keys.de-de=German +teensy2.menu.keys.de-de.build.keylayout=GERMAN +teensy2.menu.keys.de-dm=German (Mac) +teensy2.menu.keys.de-dm.build.keylayout=GERMAN_MAC +teensy2.menu.keys.de-ch=German Swiss +teensy2.menu.keys.de-ch.build.keylayout=GERMAN_SWISS +teensy2.menu.keys.is-is=Icelandic +teensy2.menu.keys.is-is.build.keylayout=ICELANDIC +teensy2.menu.keys.en-ie=Irish +teensy2.menu.keys.en-ie.build.keylayout=IRISH +teensy2.menu.keys.it-it=Italian +teensy2.menu.keys.it-it.build.keylayout=ITALIAN +teensy2.menu.keys.no-no=Norwegian +teensy2.menu.keys.no-no.build.keylayout=NORWEGIAN +teensy2.menu.keys.pt-pt=Portuguese +teensy2.menu.keys.pt-pt.build.keylayout=PORTUGUESE +teensy2.menu.keys.pt-br=Portuguese Brazilian +teensy2.menu.keys.pt-br.build.keylayout=PORTUGUESE_BRAZILIAN +teensy2.menu.keys.rs-rs=Serbian (Latin Only) +teensy2.menu.keys.rs-rs.build.keylayout=SERBIAN_LATIN_ONLY +teensy2.menu.keys.es-es=Spanish +teensy2.menu.keys.es-es.build.keylayout=SPANISH +teensy2.menu.keys.es-mx=Spanish Latin America +teensy2.menu.keys.es-mx.build.keylayout=SPANISH_LATIN_AMERICA +teensy2.menu.keys.sv-se=Swedish +teensy2.menu.keys.sv-se.build.keylayout=SWEDISH +teensy2.menu.keys.tr-tr=Turkish (partial) +teensy2.menu.keys.tr-tr.build.keylayout=TURKISH +teensy2.menu.keys.en-gb=United Kingdom +teensy2.menu.keys.en-gb.build.keylayout=UNITED_KINGDOM +teensy2.menu.keys.usint=US International +teensy2.menu.keys.usint.build.keylayout=US_INTERNATIONAL + + diff --git a/Packages_Patches/hardware/teensy/avr/cores/teensy/Stream.cpp b/Packages_Patches/hardware/teensy/avr/cores/teensy/Stream.cpp new file mode 100644 index 0000000..6c78ed5 --- /dev/null +++ b/Packages_Patches/hardware/teensy/avr/cores/teensy/Stream.cpp @@ -0,0 +1,446 @@ +/* + Stream.cpp - adds parsing methods to Stream class + Copyright (c) 2008 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Created July 2011 + parsing functions based on TextFinder library by Michael Margolis + */ + +#include + +#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait +#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field + +// private method to read stream with timeout +int Stream::timedRead() +{ + int c; + unsigned long startMillis = millis(); + + do + { + c = read(); + + if (c >= 0) + return c; + + yield(); + } while (millis() - startMillis < _timeout); + + Serial.print(("timedRead timeout = ")); + Serial.println(_timeout); + + return -1; // -1 indicates timeout +} + +// private method to peek stream with timeout +int Stream::timedPeek() +{ + int c; + unsigned long startMillis = millis(); + + do + { + c = peek(); + + if (c >= 0) + return c; + + yield(); + } while (millis() - startMillis < _timeout); + + return -1; // -1 indicates timeout +} + +// returns peek of the next digit in the stream or -1 if timeout +// discards non-numeric characters +int Stream::peekNextDigit() +{ + int c; + + while (1) + { + c = timedPeek(); + + if (c < 0) + return c; // timeout + + if (c == '-') + return c; + + if (c >= '0' && c <= '9') + return c; + + read(); // discard non-numeric + } +} + +// Public Methods +////////////////////////////////////////////////////////////// + +void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait +{ + _timeout = timeout; +} + +// find returns true if the target string is found +bool Stream::find(const char *target) +{ + return findUntil(target, NULL); +} + +// reads data from the stream until the target string of given length is found +// returns true if target string is found, false if timed out +bool Stream::find(const char *target, size_t length) +{ + return findUntil(target, length, NULL, 0); +} + +// as find but search ends if the terminator string is found +bool Stream::findUntil(const char *target, const char *terminator) +{ + if (target == nullptr) + return true; + + size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator); + + return findUntil(target, strlen(target), terminator, tlen); +} + +// reads data from the stream until the target string of the given length is found +// search terminated if the terminator string is found +// returns true if target string is found, false if terminated or timed out +bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen) +{ + size_t index = 0; // maximum target string length is 64k bytes! + size_t termIndex = 0; + int c; + + if ( target == nullptr) + return true; + + if ( *target == 0) + return true; // return true if target is a null string + + if (terminator == nullptr) + termLen = 0; + + while ( (c = timedRead()) > 0) + { + if ( c == target[index]) + { + //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); + if (++index >= targetLen) + { + // return true if all chars in the target match + return true; + } + } + else + { + index = 0; // reset index if any char does not match + } + + if (termLen > 0 && c == terminator[termIndex]) + { + if (++termIndex >= termLen) + return false; // return false if terminate string found before target string + } + else + termIndex = 0; + } + + return false; +} + + +// returns the first valid (long) integer value from the current position. +// initial characters that are not digits (or the minus sign) are skipped +// function is terminated by the first character that is not a digit. +long Stream::parseInt() +{ + return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) +} + +// as above but a given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +long Stream::parseInt(char skipChar) +{ + boolean isNegative = false; + long value = 0; + int c; + + c = peekNextDigit(); + + // ignore non numeric leading characters + if (c < 0) + return 0; // zero returned if timeout + + do + { + if (c == skipChar) + ; // ignore this charactor + else if (c == '-') + isNegative = true; + else if (c >= '0' && c <= '9') // is c a digit? + value = value * 10 + c - '0'; + + read(); // consume the character we got with peek + c = timedPeek(); + } + while ( (c >= '0' && c <= '9') || c == skipChar ); + + if (isNegative) + value = -value; + + return value; +} + + +// as parseInt but returns a floating point value +float Stream::parseFloat() +{ + return parseFloat(NO_SKIP_CHAR); +} + +// as above but the given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +float Stream::parseFloat(char skipChar) +{ + boolean isNegative = false; + boolean isFraction = false; + long value = 0; + int c; + float fraction = 1.0; + + c = peekNextDigit(); + + // ignore non numeric leading characters + if (c < 0) + return 0; // zero returned if timeout + + do + { + if (c == skipChar) + ; // ignore + else if (c == '-') + isNegative = true; + else if (c == '.') + isFraction = true; + else if (c >= '0' && c <= '9') + { + // is c a digit? + value = value * 10 + c - '0'; + + if (isFraction) + fraction *= 0.1f; + } + + read(); // consume the character we got with peek + c = timedPeek(); + } + while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar ); + + if (isNegative) + value = -value; + + if (isFraction) + return value * fraction; + else + return value; +} + +// read characters from stream into buffer +// terminates if length characters have been read, or timeout (see setTimeout) +// returns the number of characters placed in the buffer +// the buffer is NOT null terminated. +// +size_t Stream::readBytes(char *buffer, size_t length) +{ + if (buffer == nullptr) + return 0; + + size_t count = 0; + + while (count < length) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; + } + + *buffer++ = (char)c; + count++; + } + + return count; +} + + +// as readBytes with terminator character +// terminates if length characters have been read, timeout, or if the terminator character detected +// returns the number of characters placed in the buffer (0 means no valid data found) + +size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) +{ + if (buffer == nullptr) + return 0; + + if (length < 1) + return 0; + + length--; + size_t index = 0; + + while (index < length) + { + int c = timedRead(); + + if (c == terminator) + break; + + if (c < 0) + { + setReadError(); + break; + } + + *buffer++ = (char)c; + index++; + } + + *buffer = 0; + return index; // return number of characters, not including null terminator +} + +#if 1 +// From nRF52 + +String Stream::readString(size_t max) +{ + String ret; + int c = timedRead(); + + while (c >= 0) + { + ret += (char)c; + c = timedRead(); + } + + return ret; +} + +char readStringBuffer[2048]; + +char* Stream::readCharsUntil(char terminator, size_t max) +{ + uint16_t offset = 0; + + int c = timedRead(); + + readStringBuffer[offset++] = c; + + while (c >= 0 && c != terminator) + { + c = timedRead(); + + readStringBuffer[offset++] = c; + } + + readStringBuffer[offset] = 0; + + return readStringBuffer; +} + +String Stream::readStringUntil(char terminator, size_t max) +{ + String ret; + uint16_t offset = 0; + + int c = timedRead(); + + readStringBuffer[offset++] = c; + + while (c >= 0 && c != terminator) + { + c = timedRead(); + + readStringBuffer[offset++] = c; + } + + readStringBuffer[offset] = 0; + + ret = String(readStringBuffer); + + return String(readStringBuffer); +} + +#else + +String Stream::readString(size_t max) +{ + String str; + size_t length = 0; + + while (length < max) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; // timeout + } + + if (c == 0) + break; + + str += (char)c; + length++; + } + + return str; +} + +String Stream::readStringUntil(char terminator, size_t max) +{ + String str; + size_t length = 0; + + while (length < max) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; // timeout + } + + if (c == 0 || c == terminator) + break; + + str += (char)c; + length++; + } + + return str; +} +#endif diff --git a/Packages_Patches/hardware/teensy/avr/cores/teensy/Stream.h b/Packages_Patches/hardware/teensy/avr/cores/teensy/Stream.h new file mode 100644 index 0000000..e63330a --- /dev/null +++ b/Packages_Patches/hardware/teensy/avr/cores/teensy/Stream.h @@ -0,0 +1,149 @@ +/* + Stream.h - base class for character-based streams. + Copyright (c) 2010 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Stream_h +#define Stream_h + +#include +#include "Print.h" + +class Stream : public Print +{ + public: + constexpr Stream() : _timeout(1000), read_error(0) {} + virtual int available() = 0; + virtual int read() = 0; + virtual int peek() = 0; + + void setTimeout(unsigned long timeout); + bool find(const char *target); + + bool find(const uint8_t *target) + { + return find ((const char *)target); + } + + bool find(const String &target) + { + return find(target.c_str()); + } + + bool find(const char *target, size_t length); + + bool find(const uint8_t *target, size_t length) + { + return find ((const char *)target, length); + } + + bool find(const String &target, size_t length) + { + return find(target.c_str(), length); + } + + bool findUntil(const char *target, const char *terminator); + + bool findUntil(const uint8_t *target, const char *terminator) + { + return findUntil((const char *)target, terminator); + } + + bool findUntil(const String &target, const char *terminator) + { + return findUntil(target.c_str(), terminator); + } + + bool findUntil(const char *target, const String &terminator) + { + return findUntil(target, terminator.c_str()); + } + + bool findUntil(const String &target, const String &terminator) + { + return findUntil(target.c_str(), terminator.c_str()); + } + + bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); + + bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) + { + return findUntil((const char *)target, targetLen, terminate, termLen); + } + + bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen); + bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen); + bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen); + + long parseInt(); + long parseInt(char skipChar); + + float parseFloat(); + float parseFloat(char skipChar); + + size_t readBytes(char *buffer, size_t length); + + size_t readBytes(uint8_t *buffer, size_t length) + { + return readBytes((char *)buffer, length); + } + + size_t readBytesUntil(char terminator, char *buffer, size_t length); + + size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) + { + return readBytesUntil(terminator, (char *)buffer, length); + } + + //////////////////////////////////////////////////////////// + String readString(size_t max = 512); + String readStringUntil(char terminator, size_t max = 512); + + // KH, to not use String + char* readCharsUntil(char terminator, size_t max = 512); + //////////////////////////////////////////////////////////// + + int getReadError() + { + return read_error; + } + + void clearReadError() + { + setReadError(0); + } + + protected: + void setReadError(int err = 1) + { + read_error = err; + } + + unsigned long _timeout; + + // KH + int timedRead(); + int timedPeek(); + int peekNextDigit(); + ////// + + private: + char read_error; +}; + +#endif + diff --git a/Packages_Patches/hardware/teensy/avr/cores/teensy3/Stream.cpp b/Packages_Patches/hardware/teensy/avr/cores/teensy3/Stream.cpp new file mode 100644 index 0000000..6c78ed5 --- /dev/null +++ b/Packages_Patches/hardware/teensy/avr/cores/teensy3/Stream.cpp @@ -0,0 +1,446 @@ +/* + Stream.cpp - adds parsing methods to Stream class + Copyright (c) 2008 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Created July 2011 + parsing functions based on TextFinder library by Michael Margolis + */ + +#include + +#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait +#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field + +// private method to read stream with timeout +int Stream::timedRead() +{ + int c; + unsigned long startMillis = millis(); + + do + { + c = read(); + + if (c >= 0) + return c; + + yield(); + } while (millis() - startMillis < _timeout); + + Serial.print(("timedRead timeout = ")); + Serial.println(_timeout); + + return -1; // -1 indicates timeout +} + +// private method to peek stream with timeout +int Stream::timedPeek() +{ + int c; + unsigned long startMillis = millis(); + + do + { + c = peek(); + + if (c >= 0) + return c; + + yield(); + } while (millis() - startMillis < _timeout); + + return -1; // -1 indicates timeout +} + +// returns peek of the next digit in the stream or -1 if timeout +// discards non-numeric characters +int Stream::peekNextDigit() +{ + int c; + + while (1) + { + c = timedPeek(); + + if (c < 0) + return c; // timeout + + if (c == '-') + return c; + + if (c >= '0' && c <= '9') + return c; + + read(); // discard non-numeric + } +} + +// Public Methods +////////////////////////////////////////////////////////////// + +void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait +{ + _timeout = timeout; +} + +// find returns true if the target string is found +bool Stream::find(const char *target) +{ + return findUntil(target, NULL); +} + +// reads data from the stream until the target string of given length is found +// returns true if target string is found, false if timed out +bool Stream::find(const char *target, size_t length) +{ + return findUntil(target, length, NULL, 0); +} + +// as find but search ends if the terminator string is found +bool Stream::findUntil(const char *target, const char *terminator) +{ + if (target == nullptr) + return true; + + size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator); + + return findUntil(target, strlen(target), terminator, tlen); +} + +// reads data from the stream until the target string of the given length is found +// search terminated if the terminator string is found +// returns true if target string is found, false if terminated or timed out +bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen) +{ + size_t index = 0; // maximum target string length is 64k bytes! + size_t termIndex = 0; + int c; + + if ( target == nullptr) + return true; + + if ( *target == 0) + return true; // return true if target is a null string + + if (terminator == nullptr) + termLen = 0; + + while ( (c = timedRead()) > 0) + { + if ( c == target[index]) + { + //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); + if (++index >= targetLen) + { + // return true if all chars in the target match + return true; + } + } + else + { + index = 0; // reset index if any char does not match + } + + if (termLen > 0 && c == terminator[termIndex]) + { + if (++termIndex >= termLen) + return false; // return false if terminate string found before target string + } + else + termIndex = 0; + } + + return false; +} + + +// returns the first valid (long) integer value from the current position. +// initial characters that are not digits (or the minus sign) are skipped +// function is terminated by the first character that is not a digit. +long Stream::parseInt() +{ + return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) +} + +// as above but a given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +long Stream::parseInt(char skipChar) +{ + boolean isNegative = false; + long value = 0; + int c; + + c = peekNextDigit(); + + // ignore non numeric leading characters + if (c < 0) + return 0; // zero returned if timeout + + do + { + if (c == skipChar) + ; // ignore this charactor + else if (c == '-') + isNegative = true; + else if (c >= '0' && c <= '9') // is c a digit? + value = value * 10 + c - '0'; + + read(); // consume the character we got with peek + c = timedPeek(); + } + while ( (c >= '0' && c <= '9') || c == skipChar ); + + if (isNegative) + value = -value; + + return value; +} + + +// as parseInt but returns a floating point value +float Stream::parseFloat() +{ + return parseFloat(NO_SKIP_CHAR); +} + +// as above but the given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +float Stream::parseFloat(char skipChar) +{ + boolean isNegative = false; + boolean isFraction = false; + long value = 0; + int c; + float fraction = 1.0; + + c = peekNextDigit(); + + // ignore non numeric leading characters + if (c < 0) + return 0; // zero returned if timeout + + do + { + if (c == skipChar) + ; // ignore + else if (c == '-') + isNegative = true; + else if (c == '.') + isFraction = true; + else if (c >= '0' && c <= '9') + { + // is c a digit? + value = value * 10 + c - '0'; + + if (isFraction) + fraction *= 0.1f; + } + + read(); // consume the character we got with peek + c = timedPeek(); + } + while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar ); + + if (isNegative) + value = -value; + + if (isFraction) + return value * fraction; + else + return value; +} + +// read characters from stream into buffer +// terminates if length characters have been read, or timeout (see setTimeout) +// returns the number of characters placed in the buffer +// the buffer is NOT null terminated. +// +size_t Stream::readBytes(char *buffer, size_t length) +{ + if (buffer == nullptr) + return 0; + + size_t count = 0; + + while (count < length) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; + } + + *buffer++ = (char)c; + count++; + } + + return count; +} + + +// as readBytes with terminator character +// terminates if length characters have been read, timeout, or if the terminator character detected +// returns the number of characters placed in the buffer (0 means no valid data found) + +size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) +{ + if (buffer == nullptr) + return 0; + + if (length < 1) + return 0; + + length--; + size_t index = 0; + + while (index < length) + { + int c = timedRead(); + + if (c == terminator) + break; + + if (c < 0) + { + setReadError(); + break; + } + + *buffer++ = (char)c; + index++; + } + + *buffer = 0; + return index; // return number of characters, not including null terminator +} + +#if 1 +// From nRF52 + +String Stream::readString(size_t max) +{ + String ret; + int c = timedRead(); + + while (c >= 0) + { + ret += (char)c; + c = timedRead(); + } + + return ret; +} + +char readStringBuffer[2048]; + +char* Stream::readCharsUntil(char terminator, size_t max) +{ + uint16_t offset = 0; + + int c = timedRead(); + + readStringBuffer[offset++] = c; + + while (c >= 0 && c != terminator) + { + c = timedRead(); + + readStringBuffer[offset++] = c; + } + + readStringBuffer[offset] = 0; + + return readStringBuffer; +} + +String Stream::readStringUntil(char terminator, size_t max) +{ + String ret; + uint16_t offset = 0; + + int c = timedRead(); + + readStringBuffer[offset++] = c; + + while (c >= 0 && c != terminator) + { + c = timedRead(); + + readStringBuffer[offset++] = c; + } + + readStringBuffer[offset] = 0; + + ret = String(readStringBuffer); + + return String(readStringBuffer); +} + +#else + +String Stream::readString(size_t max) +{ + String str; + size_t length = 0; + + while (length < max) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; // timeout + } + + if (c == 0) + break; + + str += (char)c; + length++; + } + + return str; +} + +String Stream::readStringUntil(char terminator, size_t max) +{ + String str; + size_t length = 0; + + while (length < max) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; // timeout + } + + if (c == 0 || c == terminator) + break; + + str += (char)c; + length++; + } + + return str; +} +#endif diff --git a/Packages_Patches/hardware/teensy/avr/cores/teensy3/Stream.h b/Packages_Patches/hardware/teensy/avr/cores/teensy3/Stream.h new file mode 100644 index 0000000..e63330a --- /dev/null +++ b/Packages_Patches/hardware/teensy/avr/cores/teensy3/Stream.h @@ -0,0 +1,149 @@ +/* + Stream.h - base class for character-based streams. + Copyright (c) 2010 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Stream_h +#define Stream_h + +#include +#include "Print.h" + +class Stream : public Print +{ + public: + constexpr Stream() : _timeout(1000), read_error(0) {} + virtual int available() = 0; + virtual int read() = 0; + virtual int peek() = 0; + + void setTimeout(unsigned long timeout); + bool find(const char *target); + + bool find(const uint8_t *target) + { + return find ((const char *)target); + } + + bool find(const String &target) + { + return find(target.c_str()); + } + + bool find(const char *target, size_t length); + + bool find(const uint8_t *target, size_t length) + { + return find ((const char *)target, length); + } + + bool find(const String &target, size_t length) + { + return find(target.c_str(), length); + } + + bool findUntil(const char *target, const char *terminator); + + bool findUntil(const uint8_t *target, const char *terminator) + { + return findUntil((const char *)target, terminator); + } + + bool findUntil(const String &target, const char *terminator) + { + return findUntil(target.c_str(), terminator); + } + + bool findUntil(const char *target, const String &terminator) + { + return findUntil(target, terminator.c_str()); + } + + bool findUntil(const String &target, const String &terminator) + { + return findUntil(target.c_str(), terminator.c_str()); + } + + bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); + + bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) + { + return findUntil((const char *)target, targetLen, terminate, termLen); + } + + bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen); + bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen); + bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen); + + long parseInt(); + long parseInt(char skipChar); + + float parseFloat(); + float parseFloat(char skipChar); + + size_t readBytes(char *buffer, size_t length); + + size_t readBytes(uint8_t *buffer, size_t length) + { + return readBytes((char *)buffer, length); + } + + size_t readBytesUntil(char terminator, char *buffer, size_t length); + + size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) + { + return readBytesUntil(terminator, (char *)buffer, length); + } + + //////////////////////////////////////////////////////////// + String readString(size_t max = 512); + String readStringUntil(char terminator, size_t max = 512); + + // KH, to not use String + char* readCharsUntil(char terminator, size_t max = 512); + //////////////////////////////////////////////////////////// + + int getReadError() + { + return read_error; + } + + void clearReadError() + { + setReadError(0); + } + + protected: + void setReadError(int err = 1) + { + read_error = err; + } + + unsigned long _timeout; + + // KH + int timedRead(); + int timedPeek(); + int peekNextDigit(); + ////// + + private: + char read_error; +}; + +#endif + diff --git a/Packages_Patches/hardware/teensy/avr/cores/teensy4/Stream.cpp b/Packages_Patches/hardware/teensy/avr/cores/teensy4/Stream.cpp new file mode 100644 index 0000000..6c78ed5 --- /dev/null +++ b/Packages_Patches/hardware/teensy/avr/cores/teensy4/Stream.cpp @@ -0,0 +1,446 @@ +/* + Stream.cpp - adds parsing methods to Stream class + Copyright (c) 2008 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Created July 2011 + parsing functions based on TextFinder library by Michael Margolis + */ + +#include + +#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait +#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field + +// private method to read stream with timeout +int Stream::timedRead() +{ + int c; + unsigned long startMillis = millis(); + + do + { + c = read(); + + if (c >= 0) + return c; + + yield(); + } while (millis() - startMillis < _timeout); + + Serial.print(("timedRead timeout = ")); + Serial.println(_timeout); + + return -1; // -1 indicates timeout +} + +// private method to peek stream with timeout +int Stream::timedPeek() +{ + int c; + unsigned long startMillis = millis(); + + do + { + c = peek(); + + if (c >= 0) + return c; + + yield(); + } while (millis() - startMillis < _timeout); + + return -1; // -1 indicates timeout +} + +// returns peek of the next digit in the stream or -1 if timeout +// discards non-numeric characters +int Stream::peekNextDigit() +{ + int c; + + while (1) + { + c = timedPeek(); + + if (c < 0) + return c; // timeout + + if (c == '-') + return c; + + if (c >= '0' && c <= '9') + return c; + + read(); // discard non-numeric + } +} + +// Public Methods +////////////////////////////////////////////////////////////// + +void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait +{ + _timeout = timeout; +} + +// find returns true if the target string is found +bool Stream::find(const char *target) +{ + return findUntil(target, NULL); +} + +// reads data from the stream until the target string of given length is found +// returns true if target string is found, false if timed out +bool Stream::find(const char *target, size_t length) +{ + return findUntil(target, length, NULL, 0); +} + +// as find but search ends if the terminator string is found +bool Stream::findUntil(const char *target, const char *terminator) +{ + if (target == nullptr) + return true; + + size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator); + + return findUntil(target, strlen(target), terminator, tlen); +} + +// reads data from the stream until the target string of the given length is found +// search terminated if the terminator string is found +// returns true if target string is found, false if terminated or timed out +bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen) +{ + size_t index = 0; // maximum target string length is 64k bytes! + size_t termIndex = 0; + int c; + + if ( target == nullptr) + return true; + + if ( *target == 0) + return true; // return true if target is a null string + + if (terminator == nullptr) + termLen = 0; + + while ( (c = timedRead()) > 0) + { + if ( c == target[index]) + { + //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); + if (++index >= targetLen) + { + // return true if all chars in the target match + return true; + } + } + else + { + index = 0; // reset index if any char does not match + } + + if (termLen > 0 && c == terminator[termIndex]) + { + if (++termIndex >= termLen) + return false; // return false if terminate string found before target string + } + else + termIndex = 0; + } + + return false; +} + + +// returns the first valid (long) integer value from the current position. +// initial characters that are not digits (or the minus sign) are skipped +// function is terminated by the first character that is not a digit. +long Stream::parseInt() +{ + return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) +} + +// as above but a given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +long Stream::parseInt(char skipChar) +{ + boolean isNegative = false; + long value = 0; + int c; + + c = peekNextDigit(); + + // ignore non numeric leading characters + if (c < 0) + return 0; // zero returned if timeout + + do + { + if (c == skipChar) + ; // ignore this charactor + else if (c == '-') + isNegative = true; + else if (c >= '0' && c <= '9') // is c a digit? + value = value * 10 + c - '0'; + + read(); // consume the character we got with peek + c = timedPeek(); + } + while ( (c >= '0' && c <= '9') || c == skipChar ); + + if (isNegative) + value = -value; + + return value; +} + + +// as parseInt but returns a floating point value +float Stream::parseFloat() +{ + return parseFloat(NO_SKIP_CHAR); +} + +// as above but the given skipChar is ignored +// this allows format characters (typically commas) in values to be ignored +float Stream::parseFloat(char skipChar) +{ + boolean isNegative = false; + boolean isFraction = false; + long value = 0; + int c; + float fraction = 1.0; + + c = peekNextDigit(); + + // ignore non numeric leading characters + if (c < 0) + return 0; // zero returned if timeout + + do + { + if (c == skipChar) + ; // ignore + else if (c == '-') + isNegative = true; + else if (c == '.') + isFraction = true; + else if (c >= '0' && c <= '9') + { + // is c a digit? + value = value * 10 + c - '0'; + + if (isFraction) + fraction *= 0.1f; + } + + read(); // consume the character we got with peek + c = timedPeek(); + } + while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar ); + + if (isNegative) + value = -value; + + if (isFraction) + return value * fraction; + else + return value; +} + +// read characters from stream into buffer +// terminates if length characters have been read, or timeout (see setTimeout) +// returns the number of characters placed in the buffer +// the buffer is NOT null terminated. +// +size_t Stream::readBytes(char *buffer, size_t length) +{ + if (buffer == nullptr) + return 0; + + size_t count = 0; + + while (count < length) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; + } + + *buffer++ = (char)c; + count++; + } + + return count; +} + + +// as readBytes with terminator character +// terminates if length characters have been read, timeout, or if the terminator character detected +// returns the number of characters placed in the buffer (0 means no valid data found) + +size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) +{ + if (buffer == nullptr) + return 0; + + if (length < 1) + return 0; + + length--; + size_t index = 0; + + while (index < length) + { + int c = timedRead(); + + if (c == terminator) + break; + + if (c < 0) + { + setReadError(); + break; + } + + *buffer++ = (char)c; + index++; + } + + *buffer = 0; + return index; // return number of characters, not including null terminator +} + +#if 1 +// From nRF52 + +String Stream::readString(size_t max) +{ + String ret; + int c = timedRead(); + + while (c >= 0) + { + ret += (char)c; + c = timedRead(); + } + + return ret; +} + +char readStringBuffer[2048]; + +char* Stream::readCharsUntil(char terminator, size_t max) +{ + uint16_t offset = 0; + + int c = timedRead(); + + readStringBuffer[offset++] = c; + + while (c >= 0 && c != terminator) + { + c = timedRead(); + + readStringBuffer[offset++] = c; + } + + readStringBuffer[offset] = 0; + + return readStringBuffer; +} + +String Stream::readStringUntil(char terminator, size_t max) +{ + String ret; + uint16_t offset = 0; + + int c = timedRead(); + + readStringBuffer[offset++] = c; + + while (c >= 0 && c != terminator) + { + c = timedRead(); + + readStringBuffer[offset++] = c; + } + + readStringBuffer[offset] = 0; + + ret = String(readStringBuffer); + + return String(readStringBuffer); +} + +#else + +String Stream::readString(size_t max) +{ + String str; + size_t length = 0; + + while (length < max) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; // timeout + } + + if (c == 0) + break; + + str += (char)c; + length++; + } + + return str; +} + +String Stream::readStringUntil(char terminator, size_t max) +{ + String str; + size_t length = 0; + + while (length < max) + { + int c = timedRead(); + + if (c < 0) + { + setReadError(); + break; // timeout + } + + if (c == 0 || c == terminator) + break; + + str += (char)c; + length++; + } + + return str; +} +#endif diff --git a/Packages_Patches/hardware/teensy/avr/cores/teensy4/Stream.h b/Packages_Patches/hardware/teensy/avr/cores/teensy4/Stream.h new file mode 100644 index 0000000..e63330a --- /dev/null +++ b/Packages_Patches/hardware/teensy/avr/cores/teensy4/Stream.h @@ -0,0 +1,149 @@ +/* + Stream.h - base class for character-based streams. + Copyright (c) 2010 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Stream_h +#define Stream_h + +#include +#include "Print.h" + +class Stream : public Print +{ + public: + constexpr Stream() : _timeout(1000), read_error(0) {} + virtual int available() = 0; + virtual int read() = 0; + virtual int peek() = 0; + + void setTimeout(unsigned long timeout); + bool find(const char *target); + + bool find(const uint8_t *target) + { + return find ((const char *)target); + } + + bool find(const String &target) + { + return find(target.c_str()); + } + + bool find(const char *target, size_t length); + + bool find(const uint8_t *target, size_t length) + { + return find ((const char *)target, length); + } + + bool find(const String &target, size_t length) + { + return find(target.c_str(), length); + } + + bool findUntil(const char *target, const char *terminator); + + bool findUntil(const uint8_t *target, const char *terminator) + { + return findUntil((const char *)target, terminator); + } + + bool findUntil(const String &target, const char *terminator) + { + return findUntil(target.c_str(), terminator); + } + + bool findUntil(const char *target, const String &terminator) + { + return findUntil(target, terminator.c_str()); + } + + bool findUntil(const String &target, const String &terminator) + { + return findUntil(target.c_str(), terminator.c_str()); + } + + bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); + + bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) + { + return findUntil((const char *)target, targetLen, terminate, termLen); + } + + bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen); + bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen); + bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen); + + long parseInt(); + long parseInt(char skipChar); + + float parseFloat(); + float parseFloat(char skipChar); + + size_t readBytes(char *buffer, size_t length); + + size_t readBytes(uint8_t *buffer, size_t length) + { + return readBytes((char *)buffer, length); + } + + size_t readBytesUntil(char terminator, char *buffer, size_t length); + + size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) + { + return readBytesUntil(terminator, (char *)buffer, length); + } + + //////////////////////////////////////////////////////////// + String readString(size_t max = 512); + String readStringUntil(char terminator, size_t max = 512); + + // KH, to not use String + char* readCharsUntil(char terminator, size_t max = 512); + //////////////////////////////////////////////////////////// + + int getReadError() + { + return read_error; + } + + void clearReadError() + { + setReadError(0); + } + + protected: + void setReadError(int err = 1) + { + read_error = err; + } + + unsigned long _timeout; + + // KH + int timedRead(); + int timedPeek(); + int peekNextDigit(); + ////// + + private: + char read_error; +}; + +#endif + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a87f729 --- /dev/null +++ b/README.md @@ -0,0 +1,381 @@ +# Teensy41_AsyncTCP + +[![arduino-library-badge](https://www.ardu-badge.com/badge/Teensy41_AsyncTCP.svg?)](https://www.ardu-badge.com/Teensy41_AsyncTCP) +[![GitHub release](https://img.shields.io/github/release/khoih-prog/Teensy41_AsyncTCP.svg)](https://github.com/khoih-prog/Teensy41_AsyncTCP/releases) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) +[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/Teensy41_AsyncTCP.svg)](http://github.com/khoih-prog/Teensy41_AsyncTCP/issues) + +Donate to my libraries using BuyMeACoffee + + +--- +--- + +## Table of contents + +* [Why do we need this Teensy41_AsyncTCP library](#why-do-we-need-this-Teensy41_AsyncTCP-library) + * [Features](#features) + * [Why Async is better](#why-async-is-better) + * [Currently supported Boards](#currently-supported-boards) +* [Changelog](changelog.md) +* [Prerequisites](#prerequisites) +* [Installation](#installation) + * [Use Arduino Library Manager](#use-arduino-library-manager) + * [Manual Install](#manual-install) + * [VS Code & PlatformIO](#vs-code--platformio) +* [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error) +* [Orignal documentation](#Orignal-documentation) +* [Examples](#examples) + * [1. multiFileProject](examples/multiFileProject) +* [Debug Terminal Output Samples](#debug-terminal-output-samples) + * [1. FullyFeatured_QNEthernet on TEENSY 4.1 using DHCP](#1-FullyFeatured_QNEthernet-on-TEENSY-41-using-DHCP) + * [2. FullyFeatured_QNEthernet on TEENSY 4.1 using StaticIP](#2-FullyFeatured_QNEthernet-on-TEENSY-41-using-StaticIP) +* [Debug](#debug) +* [Troubleshooting](#troubleshooting) +* [Issues](#issues) +* [TO DO](#to-do) +* [DONE](#done) +* [Contributions and Thanks](#contributions-and-thanks) +* [Contributing](#contributing) +* [License](#license) +* [Copyright](#copyright) + +--- +--- + + +### Why do we need this [Teensy41_AsyncTCP library](https://github.com/khoih-prog/Teensy41_AsyncTCP) + +#### Features + +This library is based on, modified from: + +1. [Hristo Gochkov's ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) +2. [Hristo Gochkov's AsyncTCP](https://github.com/me-no-dev/AsyncTCP) + +to apply the better and faster **asynchronous** feature of the **powerful** [ESPAsyncTCP Library](https://github.com/me-no-dev/ESPAsyncTCP) without SSL to Teensy 4.1 using LwIP-based [QNEthernet Library](https://github.com/ssilverman/QNEthernet), and will be the base for future or current and more advanced Async libraries, such as [AsyncHTTPRequest](https://github.com/khoih-prog/AsyncHTTPRequest), [AsyncHTTPSRequest](https://github.com/khoih-prog/AsyncHTTPSRequest), [AsyncMQTT_Generic](https://github.com/khoih-prog/AsyncMQTT_Generic), Teensy41_AsyncWebServer, Teensy41_AsyncUDP, Teensy41_AsyncDNSServer, Teensy41_AsyncTCP_SSL, etc. + + +#### Why Async is better + +- Using asynchronous network means that you can handle **more than one connection at the same time** +- **You are called once the request is ready and parsed** +- When you send the response, you are **immediately ready** to handle other connections while the server is taking care of sending the response in the background +- **Speed is OMG** +- **Easy to use API, HTTP Basic and Digest MD5 Authentication (default), ChunkedResponse** +- Easily extensible to handle **any type of content** +- Supports Continue 100 +- **Async WebSocket plugin offering different locations without extra servers or ports** +- Async EventSource (Server-Sent Events) plugin to send events to the browser +- URL Rewrite plugin for conditional and permanent url rewrites +- ServeStatic plugin that supports cache, Last-Modified, default index and more +- Simple template processing engine to handle templates + + +### Currently supported Boards + +1. **Teensy 4.1 using QNEthernet Library** + + +--- +--- + +## Prerequisites + + 1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest) + 2. [`Teensy core v1.56+`](https://www.pjrc.com/teensy/td_download.html) for Teensy 4.1 + 3. [`QNEthernet Library version v0.13.0+`](https://github.com/ssilverman/QNEthernet) for Teensy 4.1 built-in Ethernet. + +--- +--- + +## Installation + +### Use Arduino Library Manager + +The best and easiest way is to use `Arduino Library Manager`. Search for [**Teensy41_AsyncTCP**](https://github.com/khoih-prog/Teensy41_AsyncTCP), then select / install the latest version. +You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/badge/Teensy41_AsyncTCP.svg?)](https://www.ardu-badge.com/Teensy41_AsyncTCP) for more detailed instructions. + +### Manual Install + +Another way to install is to: + +1. Navigate to [**Teensy41_AsyncTCP**](https://github.com/khoih-prog/Teensy41_AsyncTCP) page. +2. Download the latest release `Teensy41_AsyncTCP-master.zip`. +3. Extract the zip file to `Teensy41_AsyncTCP-master` directory +4. Copy whole `Teensy41_AsyncTCP-master` folder to Arduino libraries' directory such as `~/Arduino/libraries/`. + +### VS Code & PlatformIO + +1. Install [VS Code](https://code.visualstudio.com/) +2. Install [PlatformIO](https://platformio.org/platformio-ide) +3. Install [**Teensy41_AsyncTCP** library](https://registry.platformio.org/libraries/khoih-prog/Teensy41_AsyncTCP) by using [Library Manager](https://registry.platformio.org/libraries/khoih-prog/Teensy41_AsyncTCP/installation). Search for **Teensy41_AsyncTCP** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22) +4. Use included [platformio.ini](platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html) + +--- +--- + +### HOWTO Fix `Multiple Definitions` Linker Error + +The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases. + +You can include this `.hpp` file + +``` +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include "Teensy41_AsyncTCP.hpp" //https://github.com/khoih-prog/Teensy41_AsyncTCP +``` + +in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error + +``` +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error +#include "Teensy41_AsyncTCP.h" //https://github.com/khoih-prog/Teensy41_AsyncTCP +``` + +Check the new [**multiFileProject** example](examples/multiFileProject) for a `HOWTO` demo. + + +--- +--- + + +## Orignal documentation + +Check [AsyncTCP Library](https://github.com/me-no-dev/AsyncTCP) + +This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for **Teensy 4.1 using QNEthernet Library**. + +--- +--- + + +### Examples + + 1. [multiFileProject](examples/multiFileProject). + +--- +--- + +### Debug Terminal Output Samples + +#### 1. FullyFeatured_QNEthernet on TEENSY 4.1 using DHCP + +Following is the debug terminal when running example [FullyFeatured_QNEthernet](https://github.com/khoih-prog/AsyncMQTT_Generic/tree/main/examples/QNEthernet/FullyFeatured_QNEthernet) on **Teensy 4.1 using QNEthernet Library** to demonstrate the operation of Async MQTT request, relied on [Teensy41_AsyncTCP Library](https://github.com/khoih-prog/Teensy41_AsyncTCP) + + +``` +Starting FullyFeatured_QNEthernet on TEENSY 4.1 +AsyncMQTT_Generic v1.3.0 for Teensy 4.1 QNEthernet +Initialize Ethernet using DHCP => Connected! IP address:192.168.2.107 +Connecting to MQTT... +Connected to MQTT broker: broker.emqx.io, port: 1883 +PubTopic: async-mqtt/Teensy41_QNEthernet_Pub +************************************************ +Session present: 0 +Subscribing at QoS 2, packetId: 1 +Publishing at QoS 0 +Publishing at QoS 1, packetId: 2 +Publishing at QoS 2, packetId: 3 +************************************************ +Subscribe acknowledged. + packetId: 1 + qos: 2 +Publish received. + topic: async-mqtt/Teensy41_QNEthernet_Pub + message: Teensy41_QNEthernet_Pub Test3 + qos: 2 + dup: 0 + retain: 1 + len: 29 + index: 0 + total: 29 +Publish acknowledged. + packetId: 2 +Publish received. + topic: async-mqtt/Teensy41_QNEthernet_Pub + message: Teensy41_QNEthernet_Pub Test1 + qos: 0 + dup: 0 + retain: 0 + len: 29 + index: 0 + total: 29 +Publish received. + topic: async-mqtt/Teensy41_QNEthernet_Pub + message: Teensy41_QNEthernet_Pub Test2 + qos: 1 + dup: 0 + retain: 0 + len: 29 + index: 0 + total: 29 +Publish received. + topic: async-mqtt/Teensy41_QNEthernet_Pub + message: Teensy41_QNEthernet_Pub Test3 + qos: 2 + dup: 0 + retain: 0 + len: 29 + index: 0 + total: 29 +Publish acknowledged. + packetId: 3 +``` + +--- + +### 2. FullyFeatured_QNEthernet on TEENSY 4.1 using StaticIP + +Following is the debug terminal when running example [FullyFeatured_QNEthernet](https://github.com/khoih-prog/AsyncMQTT_Generic/tree/main/examples/QNEthernet/FullyFeatured_QNEthernet) on **Teensy 4.1 using QNEthernet Library** to demonstrate the operation of Async MQTT request, relied on [Teensy41_AsyncTCP Library](https://github.com/khoih-prog/Teensy41_AsyncTCP) + +``` +Starting FullyFeatured_QNEthernet on TEENSY 4.1 +AsyncMQTT_Generic v1.3.0 for Teensy 4.1 QNEthernet +Initialize Ethernet using static IP => Connected! IP address:192.168.2.222 +Connecting to MQTT... +Connected to MQTT broker: broker.emqx.io, port: 1883 +PubTopic: async-mqtt/Teensy41_QNEthernet_Pub +************************************************ +Session present: 0 +Subscribing at QoS 2, packetId: 1 +Publishing at QoS 0 +Publishing at QoS 1, packetId: 2 +Publishing at QoS 2, packetId: 3 +************************************************ +Subscribe acknowledged. + packetId: 1 + qos: 2 +Publish received. + topic: async-mqtt/Teensy41_QNEthernet_Pub + message: Teensy41_QNEthernet_Pub Test3 + qos: 2 + dup: 0 + retain: 1 + len: 29 + index: 0 + total: 29 +Publish acknowledged. + packetId: 2 +Publish received. + topic: async-mqtt/Teensy41_QNEthernet_Pub + message: Teensy41_QNEthernet_Pub Test1 + qos: 0 + dup: 0 + retain: 0 + len: 29 + index: 0 + total: 29 +Publish received. + topic: async-mqtt/Teensy41_QNEthernet_Pub + message: Teensy41_QNEthernet_Pub Test2 + qos: 1 + dup: 0 + retain: 0 + len: 29 + index: 0 + total: 29 +Publish received. + topic: async-mqtt/Teensy41_QNEthernet_Pub + message: Teensy41_QNEthernet_Pub Test3 + qos: 2 + dup: 0 + retain: 0 + len: 29 + index: 0 + total: 29 +Publish acknowledged. + packetId: 3 +``` + + +--- +--- + +### Debug + +Debug is enabled by default on Serial. + +You can also change the debugging level `_TEENSY41_ASYNC_TCP_LOGLEVEL_` from 0 to 4 in the sketch. +```cpp +#define _TEENSY41_ASYNC_TCP_LOGLEVEL_ 1 +``` + +--- + +### Troubleshooting + +If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards. + +Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions. + + +--- +--- + +### Issues + +Submit issues to: [Teensy41_AsyncTCP issues](https://github.com/khoih-prog/Teensy41_AsyncTCP/issues) + +--- + +## TO DO + +1. Search for bug and improvement. +2. `Teensy41_AsyncTCP_SSL` library for **Teensy 4.1 using QNEthernet Library** +3. Permit both TLS/SSL and non-TLS/SSL + +--- + +## DONE + +1. Add support to **Teensy 4.1 using QNEthernet Library** +2. Add Table of Contents +3. Add debug feature +4. Use `h-only` style library +5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project to avoid `multiple-definitions` linker error + + +--- +--- + +### Contributions and Thanks + +Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library. + +### Contributions and Thanks + +1. Based on and modified from [Hristo Gochkov's AsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP). Many thanks to [Hristo Gochkov](https://github.com/me-no-dev) for great [ESPAsyncTCP Library](https://github.com/me-no-dev/ESPAsyncTCP) and [AsyncTCP Library](https://github.com/me-no-dev/AsyncTCP) + + + + + +
me-no-dev
⭐️⭐️ Hristo Gochkov

+ +--- + +## Contributing + +If you want to contribute to this project: + +- Report bugs and errors +- Ask for enhancements +- Create issues and pull requests +- Tell other people about this library + +--- +--- + +### License + +- The library is licensed under [LGPLv3](https://github.com/khoih-prog/Teensy41_AsyncTCP/blob/main/LICENSE) + +--- + +## Copyright + +- Copyright 2016- Hristo Gochkov +- Copyright 2022- Khoi Hoang + + diff --git a/README.md.orig b/README.md.orig new file mode 100644 index 0000000..0df3055 --- /dev/null +++ b/README.md.orig @@ -0,0 +1,64 @@ +# STM32AsyncTCP + +This is as "close as possible" port of the well-known [ArduinoIDE library ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) and I am of course immensely grateful to its author "me-no-dev" for his huge contribution to the community. + +I have tried to make as few changes as possible, so that other Arduino libs that rely on ESPAsyncTCP can be ported with zero(ish) effort. It is testament to the quality and solidity of ESPAsyncTCP, the genius of the ArduinoUDE team and the STM32Duino library authors that this port didn't take long at all, and went *far* more smoothly and easily than I had expected. + +The intended target is STM32-NUCLEO boards under ArduinoIDE using the ST-approved boards manager list, [version 1.9.0](https://github.com/stm32duino) + +It has been tested *solely* on STM32-NUCLEOF429ZI + +and requires these libraries: (follow links) + +* [LwIP](https://github.com/stm32duino/LwIP) +* [STM32Ethernet](https://github.com/stm32duino/STM32Ethernet) + +So if it runs on any other board, or under any other development scenarios, then it is more by luck than judgment and I am unable to comment or assist, so.... + +## Important point + +The library is intimately dependent upon the target platform's LwIP installation. The STM32 implementation of LwIP is *very* different from both the ESP8266 and ESP32 version in terms of number of buffers, MTU size TCP_MSS size etc...so if you are going to try to post anything, *make sure* it does not assume anything re the installation. + +The first lib I tried to port "on top" of ESPAsyncTCP sent six short messages, EITHER relying on the fact that the send queue on ESP/LwIP has 8 "slots" configured and knowing that the lib would amalgamate them into one packet... OR (*far* more likely) not having a clue about why or how any of it actually worked. + +The STM32 installation has only 2x slots. Hence the above code just failed with "out of memory(!)" and refused to even connect, because there was no error-checking. Of course on HIS setup, if it ever fails, your net is down so it can't connect anyway, so why check? + +Also that *type* of problem does not always automatically start working once platform differences have been resolved, sometimes code will need to be rewritten if it "accidentally" or carlesssly renders itself implementation-dependent. The above example - if well/properly written - wouldn't have failed in the first place...let alone then alerted me to the several dozen other things wrong with it.. :) + +Anyway: You have been warned :) Assume nothing! + +To use, change any occurence of `ESPAsyncTCP.h` to `STM32AsyncTCP.h` + +## This is almost* a "straight lift" of the orignal documentation + +For ESP32 look [HERE](https://github.com/me-no-dev/AsyncTCP) + +[![Join the chat at https://gitter.im/me-no-dev/ESPAsyncWebServer](https://badges.gitter.im/me-no-dev/ESPAsyncWebServer.svg)](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP8266 MCUs. + +This library is the base for [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) + +## AsyncClient and AsyncServer +The base classes on which everything else is built. They expose all possible scenarios, but are really raw and require more skills to use. + +## AsyncPrinter +This class can be used to send data like any other ```Print``` interface (```Serial``` for example). +The object then can be used outside of the Async callbacks (the loop) and receive asynchronously data using ```onData```. The object can be checked if the underlying ```AsyncClient```is connected, or hook to the ```onDisconnect``` callback. + +## AsyncTCPbuffer +This class is really similar to the ```AsyncPrinter```, but it differs in the fact that it can buffer some of the incoming data. + +## SyncClient +It is exactly what it sounds like. This is a standard, blocking TCP Client, similar to the one included in ```ESP8266WiFi``` + +## Libraries and projects that use AsyncTCP +- [ESP Async Web Server](https://github.com/me-no-dev/ESPAsyncWebServer) + +- [Async MQTT client](https://github.com/marvinroger/async-mqtt-client) + + * *Personally I would avoid AsynMqttClient like the plague - there are so many fatal bugs in it, that **it is not fit for purpose**. For a list of 16 of those bugs, [read this](https://github.com/philbowles/PangolinMQTT/blob/master/docs/bugs.md)* + +- [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets) +- [ESP8266 Smart Home](https://github.com/baruch/esp8266_smart_home) +- [KBox Firmware](https://github.com/sarfata/kbox-firmware) diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..433de2f --- /dev/null +++ b/changelog.md @@ -0,0 +1,24 @@ +# Teensy41_AsyncTCP client for ESP8266, ESP32, etc. + +[![arduino-library-badge](https://www.ardu-badge.com/badge/Teensy41_AsyncTCP.svg?)](https://www.ardu-badge.com/Teensy41_AsyncTCP) +[![GitHub release](https://img.shields.io/github/release/khoih-prog/Teensy41_AsyncTCP.svg)](https://github.com/khoih-prog/Teensy41_AsyncTCP/releases) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) +[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/Teensy41_AsyncTCP.svg)](http://github.com/khoih-prog/Teensy41_AsyncTCP/issues) + +--- +--- + +## Table of Contents + +* [Changelog](#changelog) + * [Initial Releases v1.0.0](#Initial-Releases-v100) + +--- +--- + +## Changelog + +### Initial Releases v1.0.0 + +1. Initial porting and coding to support **Teensy 4.1 using QNEthernet Library** +2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project to avoid `multiple-definitions` linker error diff --git a/examples/multiFileProject/multiFileProject.cpp b/examples/multiFileProject/multiFileProject.cpp new file mode 100644 index 0000000..f9d4c3d --- /dev/null +++ b/examples/multiFileProject/multiFileProject.cpp @@ -0,0 +1,13 @@ +/**************************************************************************************************************************** + multiFileProject.cpp + For ESP32 + + AsyncTCP_SSL is a library for the ESP32 + + Built by Khoi Hoang https://github.com/khoih-prog/AsyncTCP_SSL + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#include "multiFileProject.h" diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h new file mode 100644 index 0000000..429bdc5 --- /dev/null +++ b/examples/multiFileProject/multiFileProject.h @@ -0,0 +1,18 @@ +/**************************************************************************************************************************** + multiFileProject.h + For ESP32 + + AsyncTCP_SSL is a library for the ESP32 + + Built by Khoi Hoang https://github.com/khoih-prog/AsyncTCP_SSL + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#pragma once + +#define _TEENSY41_ASYNC_TCP_LOGLEVEL_ 1 + +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include "Teensy41_AsyncTCP.hpp" diff --git a/examples/multiFileProject/multiFileProject.ino b/examples/multiFileProject/multiFileProject.ino new file mode 100644 index 0000000..b4ca7c2 --- /dev/null +++ b/examples/multiFileProject/multiFileProject.ino @@ -0,0 +1,57 @@ +/**************************************************************************************************************************** + multiFileProject.ino + For ESP32 + + AsyncTCP_SSL is a library for the ESP32 + + Built by Khoi Hoang https://github.com/khoih-prog/AsyncTCP_SSL + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#if 1 +#if ( defined(CORE_TEENSY) && defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41) ) + // For Teensy 4.1 + #define BOARD_TYPE "TEENSY 4.1" + // Use true for NativeEthernet Library, false if using other Ethernet libraries + #define USE_NATIVE_ETHERNET false + #define USE_QN_ETHERNET true +#else + #error Only Teensy 4.1 supported +#endif +#endif + +#define TEENSY41_ASYNC_TCP_VERSION_MIN_TARGET "Teensy41_AsyncTCP v1.0.0" +#define TEENSY41_ASYNC_TCP_VERSION_MIN 1000000 + +#include "multiFileProject.h" + +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include "Teensy41_AsyncTCP.h" + +void setup() +{ + Serial.begin(115200); + while (!Serial); + + delay(500); + + Serial.println("\nStart multiFileProject"); + Serial.println(TEENSY41_ASYNC_TCP_VERSION); + +#if defined(TEENSY41_ASYNC_TCP_VERSION_MIN) + if (TEENSY41_ASYNC_TCP_VERSION_INT < TEENSY41_ASYNC_TCP_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(TEENSY41_ASYNC_TCP_VERSION_MIN_TARGET); + } +#endif + + Serial.print("You're OK now"); +} + +void loop() +{ + // put your main code here, to run repeatedly: +} diff --git a/library.json b/library.json new file mode 100644 index 0000000..2d8f040 --- /dev/null +++ b/library.json @@ -0,0 +1,37 @@ +{ + "name":"Teensy41_AsyncTCP", + "version": "1.0.0", + "description":"Asynchronous TCP Library for Teensy 4.1 using QNEthernet. This library is the base for future Async support for many current or future libraries, such as AsyncHTTPRequest, AsyncHTTPSRequest, AsyncMQTT_Generic, Teensy41_AsyncWebServer, Teensy41_AsyncUDP, Teensy41_AsyncDNSServer, Teensy41_AsyncTCP_SSL", + "keywords":"async, tcp, teensy, teensy41, teensy-41, qnethernet, lwip", + "authors": + [ + { + "name": "Hristo Gochkov", + "url": "https://github.com/me-no-dev" + }, + { + "name": "Khoi Hoang", + "url": "https://github.com/khoih-prog", + "email": "khoih-dot-prog@gmail.com", + "maintainer": true + } + ], + "repository": + { + "type": "git", + "url": "https://github.com/khoih-prog/Teensy41_AsyncTCP.git" + }, + "homepage": "https://github.com/khoih-prog/Teensy41_AsyncTCP", + "export": { + "exclude": [ + "linux", + "extras", + "tests" + ] + }, + "license": "LGPL-3.0", + "frameworks": "*", + "platforms": ["teensy", "avr"], + "examples": "examples/*/*/*.ino", + "headers": ["Teensy41_AsyncTCP.h", "Teensy41_AsyncTCP.hpp"] +} diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..9c4f89f --- /dev/null +++ b/library.properties @@ -0,0 +1,11 @@ +name=Teensy41_AsyncTCP +version=1.0.0 +author=Hristo Gochkov, Khoi Hoang +maintainer=Khoi Hoang +sentence=Async TCP Library for Teensy 4.1 using QNEthernet +paragraph=This library is the base for future Async support for many current or future libraries, such as AsyncHTTPRequest, AsyncHTTPSRequest, AsyncMQTT_Generic, Teensy41_AsyncWebServer, Teensy41_AsyncUDP, Teensy41_AsyncDNSServer, Teensy41_AsyncTCP_SSL +category=Communication +url=https://github.com/khoih-prog/Teensy41_AsyncTCP +license=LGPLv3 +architectures=teensy, avr +includes=Teensy41_AsyncTCP.h, Teensy41_AsyncTCP.hpp diff --git a/platformio/platformio.ini b/platformio/platformio.ini new file mode 100644 index 0000000..497cceb --- /dev/null +++ b/platformio/platformio.ini @@ -0,0 +1,53 @@ +;PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +; ============================================================ +; chose environment: +; teensy + +; ============================================================ +default_envs = teensy + +[env] +; ============================================================ +; Serial configuration +; choose upload speed, serial-monitor speed +; ============================================================ +upload_speed = 921600 +;upload_port = COM11 +;monitor_speed = 9600 +;monitor_port = COM11 + +; Checks for the compatibility with frameworks and dev/platforms +lib_compat_mode = strict + +lib_deps = +; PlatformIO 4.x + +; PlatformIO 5.x + + +build_flags = +; set your build_flags + +[env:STM32] +platform = teensy +framework = arduino + +; ============================================================ +; Choose your board by uncommenting one of the following lines +; ============================================================ + +; ============================================================ +; Board configuration Many more Boards to be filled +; ============================================================ + + diff --git a/src/AsyncPrinter.hpp b/src/AsyncPrinter.hpp new file mode 100644 index 0000000..7ab0e11 --- /dev/null +++ b/src/AsyncPrinter.hpp @@ -0,0 +1,88 @@ +/**************************************************************************************************************************** + AsyncPrinter.hpp + + Asynchronous TCP library for Espressif MCUs + + Copyright (c) 2016 Hristo Gochkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published bythe 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_PRINTER_HPP_ +#define _TEENSY41_ASYNC_PRINTER_HPP_ + +#include "Arduino.h" + +#include "Teensy41_AsyncTCP.hpp" + +#include "cbuf.hpp" + +class AsyncPrinter; + +typedef std::function ApDataHandler; +typedef std::function ApCloseHandler; + +class AsyncPrinter: public Print +{ + private: + AsyncClient *_client; + ApDataHandler _data_cb; + void *_data_arg; + ApCloseHandler _close_cb; + void *_close_arg; + cbuf *_tx_buffer; + size_t _tx_buffer_size; + + void _onConnect(AsyncClient *c); + + public: + AsyncPrinter *next; + + AsyncPrinter(); + AsyncPrinter(AsyncClient *client, size_t txBufLen = TCP_MSS); + + virtual ~AsyncPrinter(); + + int connect(IPAddress ip, uint16_t port); + int connect(const char *host, uint16_t port); + + void onData(ApDataHandler cb, void *arg); + void onClose(ApCloseHandler cb, void *arg); + + operator bool(); + AsyncPrinter & operator=(const AsyncPrinter &other); + + size_t write(uint8_t data); + size_t write(const uint8_t *data, size_t len); + + bool connected(); + void close(); + + size_t _sendBuffer(); + void _onData(void *data, size_t len); + void _on_close(); + void _attachCallbacks(); +}; + +#endif // _TEENSY41_ASYNC_PRINTER_HPP_ diff --git a/src/AsyncPrinter_Impl.h b/src/AsyncPrinter_Impl.h new file mode 100644 index 0000000..ad6fb72 --- /dev/null +++ b/src/AsyncPrinter_Impl.h @@ -0,0 +1,326 @@ +/**************************************************************************************************************************** + AsyncPrinter_Impl.h + + Asynchronous TCP library for Espressif MCUs + + Copyright (c) 2016 Hristo Gochkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published bythe 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_PRINTER_IMPL_H_ +#define _TEENSY41_ASYNC_PRINTER_IMPL_H_ + +AsyncPrinter::AsyncPrinter() + : _client(NULL) + , _data_cb(NULL) + , _data_arg(NULL) + , _close_cb(NULL) + , _close_arg(NULL) + , _tx_buffer(NULL) + , _tx_buffer_size(TCP_MSS) + , next(NULL) +{} + +AsyncPrinter::AsyncPrinter(AsyncClient *client, size_t txBufLen) + : _client(client) + , _data_cb(NULL) + , _data_arg(NULL) + , _close_cb(NULL) + , _close_arg(NULL) + , _tx_buffer(NULL) + , _tx_buffer_size(txBufLen) + , next(NULL) +{ + _attachCallbacks(); + _tx_buffer = new (std::nothrow) cbuf(_tx_buffer_size); + + if (_tx_buffer == NULL) + { + //What should we do? + } +} + +AsyncPrinter::~AsyncPrinter() +{ + _on_close(); +} + +void AsyncPrinter::onData(ApDataHandler cb, void *arg) +{ + _data_cb = cb; + _data_arg = arg; +} + +void AsyncPrinter::onClose(ApCloseHandler cb, void *arg) +{ + _close_cb = cb; + _close_arg = arg; +} + +int AsyncPrinter::connect(IPAddress ip, uint16_t port) +{ + if (_client != NULL && connected()) + return 0; + + _client = new (std::nothrow) AsyncClient(); + + if (_client == NULL) + { + T41_ASYNC_LOGERROR("AsyncPrinter::connect(ip): Error NULL _client"); + } + + _client->onConnect([](void *obj, AsyncClient * c) { + ((AsyncPrinter*)(obj))->_onConnect(c); + }, this); + + + if (_client->connect(ip, port)) + { + while (_client && _client->state() < 4) + delay(1); + + return connected(); + } + + return 0; +} + +int AsyncPrinter::connect(const char *host, uint16_t port) +{ + if (_client != NULL && connected()) + return 0; + + _client = new (std::nothrow) AsyncClient(); + + if (_client == NULL) + { + T41_ASYNC_LOGERROR("AsyncPrinter::connect(host): Error NULL _client"); + } + + _client->onConnect([](void *obj, AsyncClient * c) + { + ((AsyncPrinter*)(obj))->_onConnect(c); + }, this); + + if (_client->connect(host, port)) + { + while (_client && _client->state() < 4) + delay(1); + + return connected(); + } + + return 0; +} + +void AsyncPrinter::_onConnect(AsyncClient *c) +{ + (void) c; + + if (_tx_buffer != NULL) + { + cbuf *b = _tx_buffer; + _tx_buffer = NULL; + delete b; + } + + _tx_buffer = new (std::nothrow) cbuf(_tx_buffer_size); + + if (_tx_buffer) + { + T41_ASYNC_LOGERROR("AsyncPrinter::_onConnect: Error NULL _tx_buffer"); + } + + _attachCallbacks(); +} + +AsyncPrinter::operator bool() +{ + return connected(); +} + +AsyncPrinter & AsyncPrinter::operator=(const AsyncPrinter &other) +{ + if (_client != NULL) + { + _client->close(true); + _client = NULL; + } + + _tx_buffer_size = other._tx_buffer_size; + + if (_tx_buffer != NULL) + { + cbuf *b = _tx_buffer; + _tx_buffer = NULL; + delete b; + } + + _tx_buffer = new (std::nothrow) cbuf(other._tx_buffer_size); + + if (_tx_buffer == NULL) + { + T41_ASYNC_LOGERROR("AsyncPrinter:operator=: Error NULL _tx_buffer"); + } + + _client = other._client; + _attachCallbacks(); + + return *this; +} + +size_t AsyncPrinter::write(uint8_t data) +{ + return write(&data, 1); +} + +size_t AsyncPrinter::write(const uint8_t *data, size_t len) +{ + if (_tx_buffer == NULL || !connected()) + return 0; + + size_t toWrite = 0; + size_t toSend = len; + + while (_tx_buffer->room() < toSend) + { + toWrite = _tx_buffer->room(); + _tx_buffer->write((const char*)data, toWrite); + + while (connected() && !_client->canSend()) + delay(0); + + if (!connected()) + return 0; // or len - toSend; + + _sendBuffer(); + toSend -= toWrite; + } + + _tx_buffer->write((const char*)(data + (len - toSend)), toSend); + + while (connected() && !_client->canSend()) + delay(0); + + if (!connected()) + return 0; // or len - toSend; + + _sendBuffer(); + + return len; +} + +bool AsyncPrinter::connected() +{ + return (_client != NULL && _client->connected()); +} + +void AsyncPrinter::close() +{ + if (_client != NULL) + _client->close(true); +} + +size_t AsyncPrinter::_sendBuffer() +{ + size_t available = _tx_buffer->available(); + + if (!connected() || !_client->canSend() || available == 0) + return 0; + + size_t sendable = _client->space(); + + if (sendable < available) + available = sendable; + + char *out = new (std::nothrow) char[available]; + + if (out == NULL) + { + // Connection should be aborted instead + T41_ASYNC_LOGERROR("AsyncPrinter:_sendBuffer: Error NULL out"); + } + + _tx_buffer->read(out, available); + size_t sent = _client->write(out, available); + delete out; + + return sent; +} + +void AsyncPrinter::_onData(void *data, size_t len) +{ + if (_data_cb) + _data_cb(_data_arg, this, (uint8_t*)data, len); +} + +void AsyncPrinter::_on_close() +{ + if (_client != NULL) + { + _client = NULL; + } + + if (_tx_buffer != NULL) + { + cbuf *b = _tx_buffer; + _tx_buffer = NULL; + delete b; + } + + if (_close_cb) + _close_cb(_close_arg, this); +} + +void AsyncPrinter::_attachCallbacks() +{ + _client->onPoll([](void *obj, AsyncClient * c) + { + (void) c; + ((AsyncPrinter*)(obj))->_sendBuffer(); + }, this); + + _client->onAck([](void *obj, AsyncClient * c, size_t len, uint32_t time) + { + (void) c; + (void) len; + (void) time; + ((AsyncPrinter*)(obj))->_sendBuffer(); + }, this); + + _client->onDisconnect([](void *obj, AsyncClient * c) + { + ((AsyncPrinter*)(obj))->_on_close(); + delete c; + }, this); + + _client->onData([](void *obj, AsyncClient * c, void *data, size_t len) + { + (void) c; + ((AsyncPrinter*)(obj))->_onData(data, len); + }, this); +} + +#endif // _TEENSY41_ASYNC_PRINTER_IMPL_H_ diff --git a/src/SyncClient.hpp b/src/SyncClient.hpp new file mode 100644 index 0000000..51426fb --- /dev/null +++ b/src/SyncClient.hpp @@ -0,0 +1,161 @@ +/**************************************************************************************************************************** + SyncClient.hpp + + Asynchronous TCP library for Espressif MCUs + + Copyright (c) 2016 Hristo Gochkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published bythe 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_SYNC_CLIENT_HPP_ +#define _TEENSY41_ASYNC_TCP_SYNC_CLIENT_HPP_ + +#if defined(LWIP_NETIF_TX_SINGLE_PBUF) + #undef LWIP_NETIF_TX_SINGLE_PBUF + #define LWIP_NETIF_TX_SINGLE_PBUF 1 +#endif + +#include "Client.h" + +// Needed for Arduino core releases prior to 2.5.0, because of changes +// made to accommodate Arduino core 2.5.0 +// CONST was 1st defined in Core 2.5.0 in IPAddress.h +#ifndef CONST + #define CONST +#endif + +class cbuf; +class AsyncClient; + +class SyncClient: public Client +{ + private: + AsyncClient *_client; + cbuf *_tx_buffer; + size_t _tx_buffer_size; + cbuf *_rx_buffer; + int *_ref; + + size_t _sendBuffer(); + void _onData(void *data, size_t len); + void _onConnect(AsyncClient *c); + void _onDisconnect(); + void _attachCallbacks(); + void _attachCallbacks_Disconnect(); + void _attachCallbacks_AfterConnected(); + void _release(); + + public: + SyncClient(size_t txBufLen = TCP_MSS); + SyncClient(AsyncClient *client, size_t txBufLen = TCP_MSS); + virtual ~SyncClient(); + + int ref(); + int unref(); + + operator bool() + { + return connected(); + } + + SyncClient & operator=(const SyncClient &other); + +#if ASYNC_TCP_SSL_ENABLED + + int _connect(const IPAddress& ip, uint16_t port, bool secure); + + int connect(CONST IPAddress& ip, uint16_t port, bool secure) + { + return _connect(ip, port, secure); + } + + int connect(IPAddress ip, uint16_t port, bool secure) + { + return _connect(reinterpret_cast(ip), port, secure); + } + + int connect(const char *host, uint16_t port, bool secure); + + int connect(CONST IPAddress& ip, uint16_t port) + { + return _connect(ip, port, false); + } + + int connect(IPAddress ip, uint16_t port) + { + return _connect(reinterpret_cast(ip), port, false); + } + + int connect(const char *host, uint16_t port) + { + return connect(host, port, false); + } + +#else + + int _connect(const IPAddress& ip, uint16_t port); + + int connect(CONST IPAddress& ip, uint16_t port) + { + return _connect(ip, port); + } + + int connect(IPAddress ip, uint16_t port) + { + return _connect(reinterpret_cast(ip), port); + } + + int connect(const char *host, uint16_t port); + +#endif + + void setTimeout(uint32_t seconds); + + uint8_t status(); + uint8_t connected(); + + bool stop(unsigned int maxWaitMs); + bool flush(unsigned int maxWaitMs); + + void stop() + { + (void)stop(0); + } + + void flush() + { + (void)flush(0); + } + + size_t write(uint8_t data); + size_t write(const uint8_t *data, size_t len); + + int available(); + int peek(); + int read(); + int read(uint8_t *data, size_t len); +}; + +#endif // _TEENSY41_ASYNC_TCP_SYNC_CLIENT_HPP_ diff --git a/src/SyncClient_Impl.h b/src/SyncClient_Impl.h new file mode 100644 index 0000000..cf3b5ea --- /dev/null +++ b/src/SyncClient_Impl.h @@ -0,0 +1,590 @@ +/**************************************************************************************************************************** + SyncClient_Impl.h + + Asynchronous TCP library for Espressif MCUs + + Copyright (c) 2016 Hristo Gochkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published bythe 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_SYNC_CLIENT_IMPL_H_ +#define _TEENSY41_ASYNC_TCP_SYNC_CLIENT_IMPL_H_ + +#include "Arduino.h" +#include "SyncClient.hpp" + +#include "Teensy41_AsyncTCP.hpp" + +#include "cbuf.hpp" + +#define DEBUG_ESP_SYNC_CLIENT + +#if defined(DEBUG_ESP_SYNC_CLIENT) && !defined(SYNC_CLIENT_DEBUG) +#define SYNC_CLIENT_DEBUG( format, ...) DEBUG_GENERIC_P("[SYNC_CLIENT]", format, ##__VA_ARGS__) +#endif + +#ifndef SYNC_CLIENT_DEBUG +#define SYNC_CLIENT_DEBUG(...) do { (void)0;} while(false) +#endif + +/* + Without LWIP_NETIF_TX_SINGLE_PBUF, all tcp_writes default to "no copy". + Referenced data must be preserved and free-ed from the specified tcp_sent() + callback. Alternative, tcp_writes need to use the TCP_WRITE_FLAG_COPY + attribute. +*/ +static_assert(LWIP_NETIF_TX_SINGLE_PBUF, "Required, tcp_write() must always copy."); + +SyncClient::SyncClient(size_t txBufLen) + : _client(NULL) + , _tx_buffer(NULL) + , _tx_buffer_size(txBufLen) + , _rx_buffer(NULL) + , _ref(NULL) +{ + ref(); +} + +SyncClient::SyncClient(AsyncClient *client, size_t txBufLen) + : _client(client) + , _tx_buffer(new (std::nothrow) cbuf(txBufLen)) + , _tx_buffer_size(txBufLen) + , _rx_buffer(NULL) + , _ref(NULL) +{ + if (ref() > 0 && _client != NULL) + _attachCallbacks(); +} + +SyncClient::~SyncClient() +{ + if (0 == unref()) + _release(); +} + +void SyncClient::_release() +{ + if (_client != NULL) + { + _client->onData(NULL, NULL); + _client->onAck(NULL, NULL); + _client->onPoll(NULL, NULL); + _client->abort(); + _client = NULL; + } + + if (_tx_buffer != NULL) + { + cbuf *b = _tx_buffer; + _tx_buffer = NULL; + delete b; + } + + while (_rx_buffer != NULL) + { + cbuf *b = _rx_buffer; + _rx_buffer = _rx_buffer->next; + delete b; + } +} + +int SyncClient::ref() +{ + if (_ref == NULL) + { + _ref = new (std::nothrow) int; + + if (_ref != NULL) + *_ref = 0; + else + return -1; + } + + return (++*_ref); +} + +int SyncClient::unref() +{ + int count = -1; + + if (_ref != NULL) + { + count = --*_ref; + + if (0 == count) + { + delete _ref; + _ref = NULL; + } + } + + return count; +} + +#if ASYNC_TCP_SSL_ENABLED +int SyncClient::_connect(const IPAddress& ip, uint16_t port, bool secure) +#else +int SyncClient::_connect(const IPAddress& ip, uint16_t port) +#endif +{ + if (connected()) + return 0; + + if (_client != NULL) + delete _client; + + _client = new (std::nothrow) AsyncClient(); + + if (_client == NULL) + return 0; + + _client->onConnect([](void *obj, AsyncClient * c) + { + ((SyncClient*)(obj))->_onConnect(c); + }, this); + + _attachCallbacks_Disconnect(); + +#if ASYNC_TCP_SSL_ENABLED + if (_client->connect(ip, port, secure)) +#else + if (_client->connect(ip, port)) +#endif + { + while (_client != NULL && !_client->connected() && !_client->disconnecting()) + delay(1); + + return connected(); + } + + return 0; +} + +#if ASYNC_TCP_SSL_ENABLED +int SyncClient::connect(const char *host, uint16_t port, bool secure) +#else +int SyncClient::connect(const char *host, uint16_t port) +#endif +{ + if (connected()) + return 0; + + if (_client != NULL) + delete _client; + + _client = new (std::nothrow) AsyncClient(); + + if (_client == NULL) + return 0; + + _client->onConnect([](void *obj, AsyncClient * c) + { + ((SyncClient*)(obj))->_onConnect(c); + }, this); + + _attachCallbacks_Disconnect(); + +#if ASYNC_TCP_SSL_ENABLED + if (_client->connect(host, port, secure)) +#else + if (_client->connect(host, port)) +#endif + { + while (_client != NULL && !_client->connected() && !_client->disconnecting()) + delay(1); + + return connected(); + } + + return 0; +} + +//#define SYNCCLIENT_NEW_OPERATOR_EQUAL + +#ifdef SYNCCLIENT_NEW_OPERATOR_EQUAL +/* + New behavior for operator= + + Allow for the object to be placed on a queue and transfered to a new container + with buffers still in tact. Avoiding receive data drops. Transfers rx and tx + buffers. Supports return by value. + + Note, this is optional, the old behavior is the default. + +*/ +SyncClient & SyncClient::operator=(const SyncClient &other) +{ + int *rhsref = other._ref; + ++*rhsref; // Just in case the left and right side are the same object with different containers + + if (0 == unref()) + _release(); + + _ref = other._ref; + ref(); + + --*rhsref; + // Why do I not test _tx_buffer for != NULL and free? + // I allow for the lh target container, to be a copy of an active + // connection. Thus we are just reusing the container. + // The above unref() handles releaseing the previous client of the container. + _tx_buffer_size = other._tx_buffer_size; + _tx_buffer = other._tx_buffer; + _client = other._client; + + if (_client != NULL && _tx_buffer == NULL) + _tx_buffer = new (std::nothrow) cbuf(_tx_buffer_size); + + _rx_buffer = other._rx_buffer; + + if (_client) + _attachCallbacks(); + + return *this; +} + +#else // ! SYNCCLIENT_NEW_OPERATOR_EQUAL + +// This is the origianl logic with null checks +SyncClient & SyncClient::operator=(const SyncClient &other) +{ + if (_client != NULL) + { + _client->abort(); + _client->free(); + _client = NULL; + } + + _tx_buffer_size = other._tx_buffer_size; + + if (_tx_buffer != NULL) + { + cbuf *b = _tx_buffer; + _tx_buffer = NULL; + delete b; + } + + while (_rx_buffer != NULL) + { + cbuf *b = _rx_buffer; + _rx_buffer = b->next; + delete b; + } + + if (other._client != NULL) + _tx_buffer = new (std::nothrow) cbuf(other._tx_buffer_size); + + _client = other._client; + + if (_client) + _attachCallbacks(); + + return *this; +} +#endif + +void SyncClient::setTimeout(uint32_t seconds) +{ + if (_client != NULL) + _client->setRxTimeout(seconds); +} + +uint8_t SyncClient::status() +{ + if (_client == NULL) + return 0; + + return _client->state(); +} + +uint8_t SyncClient::connected() +{ + return (_client != NULL && _client->connected()); +} + +bool SyncClient::stop(unsigned int maxWaitMs) +{ + (void) maxWaitMs; + + if (_client != NULL) + _client->close(true); + + return true; +} + +size_t SyncClient::_sendBuffer() +{ + if (_client == NULL || _tx_buffer == NULL) + return 0; + + size_t available = _tx_buffer->available(); + + if (!connected() || !_client->canSend() || available == 0) + return 0; + + size_t sendable = _client->space(); + + if (sendable < available) + available = sendable; + + char *out = new (std::nothrow) char[available]; + + if (out == NULL) + return 0; + + _tx_buffer->read(out, available); + size_t sent = _client->write(out, available); + delete[] out; + + return sent; +} + +void SyncClient::_onData(void *data, size_t len) +{ + _client->ackLater(); + cbuf *b = new (std::nothrow) cbuf(len + 1); + + if (b != NULL) + { + b->write((const char *)data, len); + + if (_rx_buffer == NULL) + _rx_buffer = b; + else + { + cbuf *p = _rx_buffer; + + while (p->next != NULL) + p = p->next; + + p->next = b; + } + } + else + { + // We ran out of memory. This fail causes lost receive data. + // The connection should be closed in a manner that conveys something + // bad/abnormal has happened to the connection. Hence, we abort the + // connection to avoid possible data corruption. + // Note, callbacks maybe called. + _client->abort(); + } +} + +void SyncClient::_onDisconnect() +{ + if (_client != NULL) + { + _client = NULL; + } + + if (_tx_buffer != NULL) + { + cbuf *b = _tx_buffer; + _tx_buffer = NULL; + delete b; + } +} + +void SyncClient::_onConnect(AsyncClient *c) +{ + _client = c; + + if (_tx_buffer != NULL) + { + cbuf *b = _tx_buffer; + _tx_buffer = NULL; + delete b; + } + + _tx_buffer = new (std::nothrow) cbuf(_tx_buffer_size); + _attachCallbacks_AfterConnected(); +} + +void SyncClient::_attachCallbacks() +{ + _attachCallbacks_Disconnect(); + _attachCallbacks_AfterConnected(); +} + +void SyncClient::_attachCallbacks_AfterConnected() +{ + _client->onAck([](void *obj, AsyncClient * c, size_t len, uint32_t time) + { + (void) c; + (void) len; + (void) time; + + ((SyncClient*)(obj))->_sendBuffer(); + }, this); + + _client->onData([](void *obj, AsyncClient * c, void *data, size_t len) + { + (void) c; + ((SyncClient*)(obj))->_onData(data, len); + }, this); + + _client->onTimeout([](void *obj, AsyncClient * c, uint32_t time) + { + (void) obj; + (void) time; + c->close(); + }, this); +} + +void SyncClient::_attachCallbacks_Disconnect() +{ + _client->onDisconnect([](void *obj, AsyncClient * c) + { + ((SyncClient*)(obj))->_onDisconnect(); + delete c; + }, this); +} + +size_t SyncClient::write(uint8_t data) +{ + return write(&data, 1); +} + +size_t SyncClient::write(const uint8_t *data, size_t len) +{ + if (_tx_buffer == NULL || !connected()) + { + return 0; + } + + size_t toWrite = 0; + size_t toSend = len; + + while (_tx_buffer->room() < toSend) + { + toWrite = _tx_buffer->room(); + _tx_buffer->write((const char*)data, toWrite); + + while (connected() && !_client->canSend()) + delay(0); + + if (!connected()) + return 0; + + _sendBuffer(); + toSend -= toWrite; + } + + _tx_buffer->write((const char*)(data + (len - toSend)), toSend); + + if (connected() && _client->canSend()) + _sendBuffer(); + + return len; +} + +int SyncClient::available() +{ + if (_rx_buffer == NULL) + return 0; + + size_t a = 0; + cbuf *b = _rx_buffer; + + while (b != NULL) + { + a += b->available(); + b = b->next; + } + + return a; +} + +int SyncClient::peek() +{ + if (_rx_buffer == NULL) + return -1; + + return _rx_buffer->peek(); +} + +int SyncClient::read(uint8_t *data, size_t len) +{ + if (_rx_buffer == NULL) + return -1; + + size_t readSoFar = 0; + + while (_rx_buffer != NULL && (len - readSoFar) >= _rx_buffer->available()) + { + cbuf *b = _rx_buffer; + _rx_buffer = _rx_buffer->next; + size_t toRead = b->available(); + readSoFar += b->read((char*)(data + readSoFar), toRead); + + if (connected()) + { + _client->ack(b->size() - 1); + } + + delete b; + } + + if (_rx_buffer != NULL && readSoFar < len) + { + readSoFar += _rx_buffer->read((char*)(data + readSoFar), (len - readSoFar)); + } + + return readSoFar; +} + +int SyncClient::read() +{ + uint8_t res = 0; + + if (read(&res, 1) != 1) + return -1; + + return res; +} + +bool SyncClient::flush(unsigned int maxWaitMs) +{ + (void) maxWaitMs; + + if (_tx_buffer == NULL || !connected()) + return false; + + if (_tx_buffer->available()) + { + while (connected() && !_client->canSend()) + delay(0); + + if (_client == NULL || _tx_buffer == NULL) + return false; + + _sendBuffer(); + } + + return true; +} + +#endif // _TEENSY41_ASYNC_TCP_SYNC_CLIENT_IMPL_H_ diff --git a/src/Teensy41_AsyncTCP.h b/src/Teensy41_AsyncTCP.h new file mode 100644 index 0000000..5561fa6 --- /dev/null +++ b/src/Teensy41_AsyncTCP.h @@ -0,0 +1,86 @@ +/**************************************************************************************************************************** + Teensy41_AsyncTCP.h + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +/**************************************************************************************************************************** + Asynchronous TCP library for Espressif MCUs + + Copyright (c) 2016 Hristo Gochkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_H_ +#define _TEENSY41_ASYNC_TCP_H_ + +#if ( defined(CORE_TEENSY) && defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41) ) + // For Teensy 4.1 + #define BOARD_NAME "TEENSY 4.1" + // Use true for NativeEthernet Library, false if using other Ethernet libraries + #define USE_NATIVE_ETHERNET false + #define USE_QN_ETHERNET true +#else + #error Only Teensy 4.1 supported +#endif + +#include + +#ifndef ASYNC_TCP_SSL_ENABLED + #define ASYNC_TCP_SSL_ENABLED 0 +#endif + +#include +#include + +#include +#include + +#include +#include + +// KH, Not in use, keep for future +////////////////////// +//#include +//#include + +//#include +//#include +////////////////////// + + +#endif /* _TEENSY41_ASYNC_TCP_H_ */ diff --git a/src/Teensy41_AsyncTCP.hpp b/src/Teensy41_AsyncTCP.hpp new file mode 100644 index 0000000..49db4a4 --- /dev/null +++ b/src/Teensy41_AsyncTCP.hpp @@ -0,0 +1,454 @@ +/**************************************************************************************************************************** + Teensy41_AsyncTCP.hpp + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +/**************************************************************************************************************************** + Asynchronous TCP library for Espressif MCUs + + Copyright (c) 2016 Hristo Gochkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_HPP_ +#define _TEENSY41_ASYNC_TCP_HPP_ + +#define TEENSY41_ASYNC_TCP_VERSION "Teensy41_AsyncTCP v1.0.0" + +#define TEENSY41_ASYNC_TCP_VERSION_MAJOR 1 +#define TEENSY41_ASYNC_TCP_VERSION_MINOR 0 +#define TEENSY41_ASYNC_TCP_VERSION_PATCH 1 + +#define TEENSY41_ASYNC_TCP_VERSION_INT 1000000 + +#include + +#include "Teensy41_AsyncTCP_Debug.h" + +#include "IPAddress.h" +#include +#include + +extern "C" +{ + #include "lwip/ip_addr.h" + #include "lwip/err.h" + #include "lwip/err.h" + #include "lwip/tcp.h" + #include "lwip/pbuf.h" +}; + +class AsyncClient; +class AsyncServer; +class ACErrorTracker; + +#define ASYNC_MAX_ACK_TIME 5000 + +//will allocate new buffer to hold the data while sending (else will hold reference to the data given) +#define ASYNC_WRITE_FLAG_COPY 0x01 + +//will not send PSH flag, meaning that there should be more data to be sent before the application should react. +#define ASYNC_WRITE_FLAG_MORE 0x02 + +///////////////////////////////////////////////////////////////// + +struct tcp_pcb; + +#if ASYNC_TCP_SSL_ENABLED + struct SSL_; + typedef struct SSL_ SSL; + struct SSL_CTX_; + typedef struct SSL_CTX_ SSL_CTX; +#endif + +typedef std::function AcConnectHandler; +typedef std::function AcAckHandler; +typedef std::function AcErrorHandler; +typedef std::function AcDataHandler; +typedef std::function AcPacketHandler; +typedef std::function AcTimeoutHandler; +typedef std::function AsNotifyHandler; + +enum error_events +{ + EE_OK = 0, + EE_ABORTED, // Callback or foreground aborted connections + EE_ERROR_CB, // Stack initiated aborts via error Callbacks. + EE_CONNECTED_CB, + EE_RECV_CB, + EE_ACCEPT_CB, + EE_MAX +}; + +///////////////////////////////////////////////////////////////// +// DEBUG_MORE is for gathering more information on which CBs close events are +// occuring and count. +// #define DEBUG_MORE 1 + +class ACErrorTracker +{ + private: + AsyncClient *_client; + err_t _close_error; + int _errored; + + size_t _connectionId; + +#ifdef DEBUG_MORE + AsNotifyHandler _error_event_cb; + void* _error_event_cb_arg; +#endif + + protected: + friend class AsyncClient; + friend class AsyncServer; + +#ifdef DEBUG_MORE + void onErrorEvent(AsNotifyHandler cb, void *arg); +#endif + + void setConnectionId(size_t id) + { + _connectionId = id; + } + + size_t getConnectionId() + { + return _connectionId; + } + + void setCloseError(err_t e); + void setErrored(size_t errorEvent); + err_t getCallbackCloseError(); + + void clearClient() + { + if (_client) _client = NULL; + } + + public: + err_t getCloseError() const + { + return _close_error; + } + + bool hasClient() const + { + return (_client != NULL); + } + + ACErrorTracker(AsyncClient *c); + ~ACErrorTracker() {} +}; + +///////////////////////////////////////////////////////////////// + +class AsyncClient +{ + protected: + friend class AsyncTCPbuffer; + friend class AsyncServer; + + tcp_pcb* _pcb; + AcConnectHandler _connect_cb; + void* _connect_cb_arg; + AcConnectHandler _discard_cb; + void* _discard_cb_arg; + AcAckHandler _sent_cb; + void* _sent_cb_arg; + AcErrorHandler _error_cb; + void* _error_cb_arg; + AcDataHandler _recv_cb; + void* _recv_cb_arg; + AcPacketHandler _pb_cb; + void* _pb_cb_arg; + AcTimeoutHandler _timeout_cb; + void* _timeout_cb_arg; + AcConnectHandler _poll_cb; + void* _poll_cb_arg; + bool _pcb_busy; + +#if ASYNC_TCP_SSL_ENABLED + bool _pcb_secure; + bool _handshake_done; +#endif + + uint32_t _pcb_sent_at; + bool _close_pcb; + bool _ack_pcb; + uint32_t _tx_unacked_len; + uint32_t _tx_acked_len; + uint32_t _tx_unsent_len; + uint32_t _rx_ack_len; + uint32_t _rx_last_packet; + uint32_t _rx_since_timeout; + uint32_t _ack_timeout; + uint16_t _connect_port; + uint8_t _recv_pbuf_flags; + + std::shared_ptr _errorTracker; + + void _close(); + void _connected(std::shared_ptr& closeAbort, void* pcb, err_t err); + void _error(err_t err); + +#if ASYNC_TCP_SSL_ENABLED + void _ssl_error(int8_t err); +#endif + + void _poll(std::shared_ptr& closeAbort, tcp_pcb* pcb); + void _sent(std::shared_ptr& closeAbort, tcp_pcb* pcb, uint16_t len); + +#if LWIP_VERSION_MAJOR == 1 + void _dns_found(struct ip_addr *ipaddr); +#else + void _dns_found(ip_addr_t *p); +#endif + + static err_t _s_poll(void *arg, struct tcp_pcb *tpcb); + static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err); + static void _s_error(void *arg, err_t err); + static err_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len); + static err_t _s_connected(void* arg, void* tpcb, err_t err); + +#if LWIP_VERSION_MAJOR == 1 + static void _s_dns_found(const char *name, struct ip_addr *ipaddr, void *arg); +#else + static void _s_dns_found(const char *name, ip_addr_t *p, void *arg); +#endif + +#if ASYNC_TCP_SSL_ENABLED + static void _s_data(void *arg, struct tcp_pcb *tcp, uint8_t * data, size_t len); + static void _s_handshake(void *arg, struct tcp_pcb *tcp, SSL *ssl); + static void _s_ssl_error(void *arg, struct tcp_pcb *tcp, int8_t err); +#endif + + std::shared_ptr getACErrorTracker() const + { + return _errorTracker; + }; + + void setCloseError(err_t e) const + { + _errorTracker->setCloseError(e); + } + + ////////////////////////////////////////// + + public: + AsyncClient* prev; + AsyncClient* next; + +#if ASYNC_TCP_SSL_ENABLED + AsyncClient(tcp_pcb* pcb = 0, SSL_CTX * ssl_ctx = NULL); +#else + AsyncClient(tcp_pcb* pcb = 0); +#endif + + ~AsyncClient(); + + AsyncClient & operator=(const AsyncClient &other); + AsyncClient & operator+=(const AsyncClient &other); + + bool operator==(const AsyncClient &other); + + bool operator!=(const AsyncClient &other) + { + return !(*this == other); + } + +#if ASYNC_TCP_SSL_ENABLED + bool connect(IPAddress ip, uint16_t port, bool secure=false); + bool connect(const char* host, uint16_t port, bool secure=false); +#else + bool connect(IPAddress ip, uint16_t port); + bool connect(const char* host, uint16_t port); +#endif + void close(bool now = false); + void stop(); + void abort(); + bool free(); + + bool canSend();//ack is not pending + size_t space(); + size_t add(const char* data, size_t size, uint8_t apiflags=0);//add for sending + bool send();//send all data added with the method above + size_t ack(size_t len); //ack data that you have not acked using the method below + void ackLater(){ _ack_pcb = false; } //will not ack the current packet. Call from onData + bool isRecvPush(){ return !!(_recv_pbuf_flags & PBUF_FLAG_PUSH); } + +#if DEBUG_ESP_ASYNC_TCP + size_t getConnectionId() const { return _errorTracker->getConnectionId();} +#endif + +#if ASYNC_TCP_SSL_ENABLED + SSL *getSSL(); +#endif + + size_t write(const char* data); + + //only when canSend() == true + size_t write(const char* data, size_t size, uint8_t apiflags=0); + + uint8_t state(); + bool connecting(); + bool connected(); + bool disconnecting(); + bool disconnected(); + + //disconnected or disconnecting + bool freeable(); + + uint16_t getMss(); + uint32_t getRxTimeout(); + + //no RX data timeout for the connection in seconds + void setRxTimeout(uint32_t timeout); + + uint32_t getAckTimeout(); + + //no ACK timeout for the last sent packet in milliseconds + void setAckTimeout(uint32_t timeout); + void setNoDelay(bool nodelay); + bool getNoDelay(); + uint32_t getRemoteAddress(); + uint16_t getRemotePort(); + uint32_t getLocalAddress(); + uint16_t getLocalPort(); + + IPAddress remoteIP(); + uint16_t remotePort(); + IPAddress localIP(); + uint16_t localPort(); + + void onConnect(AcConnectHandler cb, void* arg = 0); //on successful connect + void onDisconnect(AcConnectHandler cb, void* arg = 0); //disconnected + void onAck(AcAckHandler cb, void* arg = 0); //ack received + void onError(AcErrorHandler cb, void* arg = 0); //unsuccessful connect or error + void onData(AcDataHandler cb, void* arg = 0); //data received (called if onPacket is not used) + void onPacket(AcPacketHandler cb, void* arg = 0); //data received + void onTimeout(AcTimeoutHandler cb, void* arg = 0); //ack timeout + void onPoll(AcConnectHandler cb, void* arg = 0); //every 125ms when connected + void ackPacket(struct pbuf * pb); + + const char * errorToString(err_t error); + const char * stateToString(); + + void _recv(std::shared_ptr& closeAbort, tcp_pcb* pcb, pbuf* pb, err_t err); + + err_t getCloseError() const + { + return _errorTracker->getCloseError(); + } +}; + +#if ASYNC_TCP_SSL_ENABLED + typedef std::function AcSSlFileHandler; + struct pending_pcb; +#endif + +///////////////////////////////////////////////////////////////// + +class AsyncServer +{ + protected: + uint16_t _port; + IPAddress _addr; + bool _noDelay; + tcp_pcb* _pcb; + AcConnectHandler _connect_cb; + void* _connect_cb_arg; + +#if ASYNC_TCP_SSL_ENABLED + struct pending_pcb * _pending; + SSL_CTX * _ssl_ctx; + AcSSlFileHandler _file_cb; + void* _file_cb_arg; +#endif + +#ifdef DEBUG_MORE + int _event_count[EE_MAX]; +#endif + + public: + AsyncServer(IPAddress addr, uint16_t port); + AsyncServer(uint16_t port); + + ~AsyncServer(); + + void onClient(AcConnectHandler cb, void* arg); + +#if ASYNC_TCP_SSL_ENABLED + void onSslFileRequest(AcSSlFileHandler cb, void* arg); + void beginSecure(const char *cert, const char *private_key_file, const char *password); +#endif + + void begin(); + void end(); + void setNoDelay(bool nodelay); + bool getNoDelay(); + uint8_t status(); + +#ifdef DEBUG_MORE + int getEventCount(size_t ee) const + { + return _event_count[ee]; + } +#endif + + protected: + err_t _accept(tcp_pcb* newpcb, err_t err); + static err_t _s_accept(void *arg, tcp_pcb* newpcb, err_t err); + +#ifdef DEBUG_MORE + int incEventCount(size_t ee) { return ++_event_count[ee];} +#endif + +#if ASYNC_TCP_SSL_ENABLED + int _cert(const char *filename, uint8_t **buf); + err_t _poll(tcp_pcb* pcb); + err_t _recv(tcp_pcb *pcb, struct pbuf *pb, err_t err); + static int _s_cert(void *arg, const char *filename, uint8_t **buf); + static err_t _s_poll(void *arg, struct tcp_pcb *tpcb); + static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err); +#endif +}; + +///////////////////////////////////////////////////////////////// + +#endif // _TEENSY41_ASYNC_TCP_HPP_ diff --git a/src/Teensy41_AsyncTCP_Buffer.hpp b/src/Teensy41_AsyncTCP_Buffer.hpp new file mode 100644 index 0000000..ad3fae8 --- /dev/null +++ b/src/Teensy41_AsyncTCP_Buffer.hpp @@ -0,0 +1,121 @@ +/**************************************************************************************************************************** + Teensy41_AsyncTCP_Buffer.hpp + + @file Teensy41_AsyncTCPbuffer.h + @date 22.01.2016 + @author Markus Sattler + + Copyright (c) 2015 Markus Sattler. All rights reserved. + This file is part of the Async TCP for ESP. + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published bythe 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_BUFFER_HPP_ +#define _TEENSY41_ASYNC_TCP_BUFFER_HPP_ + +#include +#include + +#include "Teensy41_AsyncTCP.hpp" + +#include "Teensy41_AsyncTCP_Debug.h" + +typedef enum +{ + ATB_RX_MODE_NONE, + ATB_RX_MODE_FREE, + ATB_RX_MODE_READ_BYTES, + ATB_RX_MODE_TERMINATOR, + ATB_RX_MODE_TERMINATOR_STRING +} atbRxMode_t; + +class AsyncTCPbuffer: public Print +{ + public: + + typedef std::function AsyncTCPbufferDataCb; + typedef std::function AsyncTCPbufferDoneCb; + typedef std::function AsyncTCPbufferDisconnectCb; + + AsyncTCPbuffer(AsyncClient* c); + virtual ~AsyncTCPbuffer(); + + size_t write(String & data); + size_t write(uint8_t data); + size_t write(const char* data); + size_t write(const char *data, size_t len); + size_t write(const uint8_t *data, size_t len); + + void flush(); + + void noCallback(); + + void readStringUntil(char terminator, String * str, AsyncTCPbufferDoneCb done); + + // TODO implement read terminator non string + //void readBytesUntil(char terminator, char *buffer, size_t length, AsyncTCPbufferDoneCb done); + //void readBytesUntil(char terminator, uint8_t *buffer, size_t length, AsyncTCPbufferDoneCb done); + + void readBytes(char *buffer, size_t length, AsyncTCPbufferDoneCb done); + void readBytes(uint8_t *buffer, size_t length, AsyncTCPbufferDoneCb done); + + // TODO implement + // void setTimeout(size_t timeout); + + void onData(AsyncTCPbufferDataCb cb); + void onDisconnect(AsyncTCPbufferDisconnectCb cb); + + IPAddress remoteIP(); + uint16_t remotePort(); + IPAddress localIP(); + uint16_t localPort(); + + bool connected(); + + void stop(); + void close(); + + protected: + AsyncClient* _client; + cbuf * _TXbufferRead; + cbuf * _TXbufferWrite; + cbuf * _RXbuffer; + atbRxMode_t _RXmode; + size_t _rxSize; + char _rxTerminator; + uint8_t * _rxReadBytesPtr; + String * _rxReadStringPtr; + + AsyncTCPbufferDataCb _cbRX; + AsyncTCPbufferDoneCb _cbDone; + AsyncTCPbufferDisconnectCb _cbDisconnect; + + void _attachCallbacks(); + void _sendBuffer(); + void _on_close(); + void _rxData(uint8_t *buf, size_t len); + size_t _handleRxBuffer(uint8_t *buf, size_t len); +}; + +#endif // _TEENSY41_ASYNC_TCP_BUFFER_HPP_ diff --git a/src/Teensy41_AsyncTCP_Buffer_Impl.h b/src/Teensy41_AsyncTCP_Buffer_Impl.h new file mode 100644 index 0000000..a775536 --- /dev/null +++ b/src/Teensy41_AsyncTCP_Buffer_Impl.h @@ -0,0 +1,711 @@ +/**************************************************************************************************************************** + Teensy41_AsyncTCP_Buffer_Impl.h + + @file Teensy41_AsyncTCPbuffer.cpp + @date 22.01.2016 + @author Markus Sattler + + Copyright (c) 2015 Markus Sattler. All rights reserved. + This file is part of the Async TCP for ESP. + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published bythe 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_BUFFER_IMPL_H_ +#define _TEENSY41_ASYNC_TCP_BUFFER_IMPL_H_ + +#include + +#include "Teensy41_AsyncTCP_Buffer.hpp" + + +AsyncTCPbuffer::AsyncTCPbuffer(AsyncClient* client) +{ + if (client == NULL) + { + T41_ASYNC_LOGERROR("AsyncTCPbuffer: Error NULL client"); + } + + _client = client; + _TXbufferWrite = new (std::nothrow) cbuf(TCP_MSS); + _TXbufferRead = _TXbufferWrite; + _RXbuffer = new (std::nothrow) cbuf(100); + _RXmode = ATB_RX_MODE_FREE; + _rxSize = 0; + _rxTerminator = 0x00; + _rxReadBytesPtr = NULL; + _rxReadStringPtr = NULL; + _cbDisconnect = NULL; + + _cbRX = NULL; + _cbDone = NULL; + _attachCallbacks(); +} + +AsyncTCPbuffer::~AsyncTCPbuffer() +{ + if (_client) + { + _client->close(); + } + + if (_RXbuffer) + { + delete _RXbuffer; + _RXbuffer = NULL; + } + + if (_TXbufferWrite) + { + // will be deleted in _TXbufferRead chain + _TXbufferWrite = NULL; + } + + if (_TXbufferRead) + { + cbuf * next = _TXbufferRead->next; + delete _TXbufferRead; + + while (next != NULL) + { + _TXbufferRead = next; + next = _TXbufferRead->next; + delete _TXbufferRead; + } + + _TXbufferRead = NULL; + } +} + +size_t AsyncTCPbuffer::write(String & data) +{ + return write(data.c_str(), data.length()); +} + +size_t AsyncTCPbuffer::write(uint8_t data) +{ + return write(&data, 1); +} + +size_t AsyncTCPbuffer::write(const char* data) +{ + return write((const uint8_t *) data, strlen(data)); +} + +size_t AsyncTCPbuffer::write(const char *data, size_t len) +{ + return write((const uint8_t *) data, len); +} + +/** + write data in to buffer and try to send the data + @param data + @param len + @return +*/ +size_t AsyncTCPbuffer::write(const uint8_t *data, size_t len) +{ + if (_TXbufferWrite == NULL || _client == NULL || !_client->connected() || data == NULL || len == 0) + { + return 0; + } + + size_t bytesLeft = len; + + while (bytesLeft) + { + size_t w = _TXbufferWrite->write((const char*) data, bytesLeft); + bytesLeft -= w; + data += w; + _sendBuffer(); + + // add new buffer since we have more data + if (_TXbufferWrite->full() && bytesLeft > 0) + { + cbuf * next = new (std::nothrow) cbuf(TCP_MSS); + + if (next == NULL) + { + T41_ASYNC_LOGERROR("AsyncTCPbuffer::write: Error out of Heap"); + } + else + { + T41_ASYNC_LOGDEBUG("AsyncTCPbuffer: new cbuf"); + } + + // add new buffer to chain (current cbuf) + _TXbufferWrite->next = next; + + // move ptr for next data + _TXbufferWrite = next; + } + } + + return len; +} + +/** + wait until all data has send out +*/ +void AsyncTCPbuffer::flush() +{ + while (!_TXbufferWrite->empty()) + { + while (connected() && !_client->canSend()) + { + delay(0); + } + + if (!connected()) + return; + + _sendBuffer(); + } +} + +void AsyncTCPbuffer::noCallback() +{ + _RXmode = ATB_RX_MODE_NONE; +} + +void AsyncTCPbuffer::readStringUntil(char terminator, String * str, AsyncTCPbufferDoneCb done) +{ + if (_client == NULL) + { + return; + } + + ASYNC_TCP_DEBUG("[A-TCP] readStringUntil terminator: %02X\n", terminator); + + _RXmode = ATB_RX_MODE_NONE; + _cbDone = done; + _rxReadStringPtr = str; + _rxTerminator = terminator; + _rxSize = 0; + _RXmode = ATB_RX_MODE_TERMINATOR_STRING; +} + +/* + void AsyncTCPbuffer::readBytesUntil(char terminator, char *buffer, size_t length, AsyncTCPbufferDoneCb done) + { + _RXmode = ATB_RX_MODE_NONE; + _cbDone = done; + _rxReadBytesPtr = (uint8_t *) buffer; + _rxTerminator = terminator; + _rxSize = length; + _RXmode = ATB_RX_MODE_TERMINATOR; + _handleRxBuffer(NULL, 0); + } + + void AsyncTCPbuffer::readBytesUntil(char terminator, uint8_t *buffer, size_t length, AsyncTCPbufferDoneCb done) + { + readBytesUntil(terminator, (char *) buffer, length, done); + } +*/ + +void AsyncTCPbuffer::readBytes(char *buffer, size_t length, AsyncTCPbufferDoneCb done) +{ + if (_client == NULL) + { + return; + } + + ASYNC_TCP_DEBUG("[A-TCP] readBytes length: %d\n", length); + + _RXmode = ATB_RX_MODE_NONE; + _cbDone = done; + _rxReadBytesPtr = (uint8_t *) buffer; + _rxSize = length; + _RXmode = ATB_RX_MODE_READ_BYTES; +} + +void AsyncTCPbuffer::readBytes(uint8_t *buffer, size_t length, AsyncTCPbufferDoneCb done) +{ + readBytes((char *) buffer, length, done); +} + +void AsyncTCPbuffer::onData(AsyncTCPbufferDataCb cb) +{ + if (_client == NULL) + { + return; + } + + ASYNC_TCP_DEBUG("[A-TCP] onData\n"); + + _RXmode = ATB_RX_MODE_NONE; + _cbDone = NULL; + _cbRX = cb; + _RXmode = ATB_RX_MODE_FREE; +} + +void AsyncTCPbuffer::onDisconnect(AsyncTCPbufferDisconnectCb cb) +{ + _cbDisconnect = cb; +} + +IPAddress AsyncTCPbuffer::remoteIP() +{ + if (!_client) + { + return IPAddress(0, 0, 0, 0); + } + + return _client->remoteIP(); +} + +uint16_t AsyncTCPbuffer::remotePort() +{ + if (!_client) + { + return 0; + } + + return _client->remotePort(); +} + +bool AsyncTCPbuffer::connected() +{ + if (!_client) + { + return false; + } + + return _client->connected(); +} + +void AsyncTCPbuffer::stop() +{ + + if (!_client) + { + return; + } + + _client->stop(); + _client = NULL; + + if (_cbDone) + { + switch (_RXmode) + { + case ATB_RX_MODE_READ_BYTES: + case ATB_RX_MODE_TERMINATOR: + case ATB_RX_MODE_TERMINATOR_STRING: + _RXmode = ATB_RX_MODE_NONE; + _cbDone(false, NULL); + break; + + default: + break; + } + } + _RXmode = ATB_RX_MODE_NONE; +} + +void AsyncTCPbuffer::close() +{ + stop(); +} + + +///-------------------------------- + +/** + attachCallbacks to AsyncClient class +*/ +void AsyncTCPbuffer::_attachCallbacks() +{ + if (!_client) + { + return; + } + + ASYNC_TCP_DEBUG("[A-TCP] attachCallbacks\n"); + + _client->onPoll([](void *obj, AsyncClient * c) + { + (void) c; + + AsyncTCPbuffer* b = ((AsyncTCPbuffer*)(obj)); + + if ((b->_TXbufferRead != NULL) && !b->_TXbufferRead->empty()) + { + b->_sendBuffer(); + } + + // if(!b->_RXbuffer->empty()) + // { + // b->_handleRxBuffer(NULL, 0); + // } + }, this); + + _client->onAck([](void *obj, AsyncClient * c, size_t len, uint32_t time) + { + (void) c; + (void) len; + (void) time; + + ASYNC_TCP_DEBUG("[A-TCP] onAck\n"); + + ((AsyncTCPbuffer*)(obj))->_sendBuffer(); + }, this); + + _client->onDisconnect([](void *obj, AsyncClient * c) + { + ASYNC_TCP_DEBUG("[A-TCP] onDisconnect\n"); + + AsyncTCPbuffer* b = ((AsyncTCPbuffer*)(obj)); + b->_client = NULL; + bool del = true; + + if (b->_cbDisconnect) + { + del = b->_cbDisconnect(b); + } + + delete c; + + if (del) + { + delete b; + } + }, this); + + _client->onData([](void *obj, AsyncClient * c, void *buf, size_t len) + { + (void) c; + + AsyncTCPbuffer* b = ((AsyncTCPbuffer*)(obj)); + b->_rxData((uint8_t *)buf, len); + }, this); + + _client->onTimeout([](void *obj, AsyncClient * c, uint32_t time) + { + (void) obj; + (void) time; + + ASYNC_TCP_DEBUG("[A-TCP] onTimeout\n"); + + c->close(); + }, this); + + ASYNC_TCP_DEBUG("[A-TCP] attachCallbacks Done.\n"); +} + +/** + send TX buffer if possible +*/ +void AsyncTCPbuffer::_sendBuffer() +{ + //ASYNC_TCP_DEBUG("[A-TCP] _sendBuffer...\n"); + + size_t available = _TXbufferRead->available(); + + if (available == 0 || _client == NULL || !_client->connected() || !_client->canSend()) + { + return; + } + + while (connected() && (_client->space() > 0) && (_TXbufferRead->available() > 0) && _client->canSend()) + { + + available = _TXbufferRead->available(); + + if (available > _client->space()) + { + available = _client->space(); + } + + char *out = new (std::nothrow) char[available]; + + if (out == NULL) + { + ASYNC_TCP_DEBUG("[A-TCP] to less heap, try later.\n"); + return; + } + + // read data from buffer + _TXbufferRead->peek(out, available); + + // send data + size_t send = _client->write((const char*) out, available); + + if (send != available) + { + ASYNC_TCP_DEBUG("[A-TCP] write failed send: %d available: %d \n", send, available); + + if (!connected()) + { + ASYNC_TCP_DEBUG("[A-TCP] incomplete transfer, connection lost.\n"); + } + } + + // remove really send data from buffer + _TXbufferRead->remove(send); + + // if buffer is empty and there is a other buffer in chain delete the empty one + if (_TXbufferRead->available() == 0 && _TXbufferRead->next != NULL) + { + cbuf * old = _TXbufferRead; + _TXbufferRead = _TXbufferRead->next; + delete old; + + ASYNC_TCP_DEBUG("[A-TCP] delete cbuf\n"); + } + + delete out; + } + +} + +/** + called on incoming data + @param buf + @param len +*/ +void AsyncTCPbuffer::_rxData(uint8_t *buf, size_t len) +{ + if (!_client || !_client->connected()) + { + ASYNC_TCP_DEBUG("[A-TCP] not connected!\n"); + + return; + } + + if (!_RXbuffer) + { + ASYNC_TCP_DEBUG("[A-TCP] _rxData no _RXbuffer!\n"); + + return; + } + + ASYNC_TCP_DEBUG("[A-TCP] _rxData len: %d RXmode: %d\n", len, _RXmode); + + size_t handled = 0; + + if (_RXmode != ATB_RX_MODE_NONE) + { + handled = _handleRxBuffer((uint8_t *) buf, len); + buf += handled; + len -= handled; + + // handle as much as possible before using the buffer + if (_RXbuffer->empty()) + { + while (_RXmode != ATB_RX_MODE_NONE && handled != 0 && len > 0) + { + handled = _handleRxBuffer(buf, len); + buf += handled; + len -= handled; + } + } + } + + if (len > 0) + { + if (_RXbuffer->room() < len) + { + // to less space + ASYNC_TCP_DEBUG("[A-TCP] _rxData buffer full try resize\n"); + + _RXbuffer->resizeAdd((len + _RXbuffer->room())); + + if (_RXbuffer->room() < len) + { + ASYNC_TCP_DEBUG("[A-TCP] _rxData buffer to full can only handle %d!!!\n", _RXbuffer->room()); + } + } + + _RXbuffer->write((const char *) (buf), len); + } + + if (!_RXbuffer->empty() && _RXmode != ATB_RX_MODE_NONE) + { + // handle as much as possible data in buffer + handled = _handleRxBuffer(NULL, 0); + + while (_RXmode != ATB_RX_MODE_NONE && handled != 0) + { + handled = _handleRxBuffer(NULL, 0); + } + } + + // clean up ram + if (_RXbuffer->empty() && _RXbuffer->room() != 100) + { + _RXbuffer->resize(100); + } +} + +size_t AsyncTCPbuffer::_handleRxBuffer(uint8_t *buf, size_t len) +{ + if (!_client || !_client->connected() || _RXbuffer == NULL) + { + return 0; + } + + ASYNC_TCP_DEBUG("[A-TCP] _handleRxBuffer len: %d RXmode: %d\n", len, _RXmode); + + size_t BufferAvailable = _RXbuffer->available(); + size_t r = 0; + + if (_RXmode == ATB_RX_MODE_NONE) + { + return 0; + } + else if (_RXmode == ATB_RX_MODE_FREE) + { + if (_cbRX == NULL) + { + return 0; + } + + if (BufferAvailable > 0) + { + uint8_t * b = new (std::nothrow) uint8_t[BufferAvailable]; + + if (b == NULL) + { + //TODO: What action should this be ? + T41_ASYNC_LOGERROR("AsyncTCPbuffer::_handleRxBuffer: Error NULL buffer"); + } + + _RXbuffer->peek((char *) b, BufferAvailable); + r = _cbRX(b, BufferAvailable); + _RXbuffer->remove(r); + } + + if (r == BufferAvailable && buf && (len > 0)) + { + return _cbRX(buf, len); + } + else + { + return 0; + } + + } + else if (_RXmode == ATB_RX_MODE_READ_BYTES) + { + if (_rxReadBytesPtr == NULL || _cbDone == NULL) + { + return 0; + } + + size_t newReadCount = 0; + + if (BufferAvailable) + { + r = _RXbuffer->read((char *) _rxReadBytesPtr, _rxSize); + _rxSize -= r; + _rxReadBytesPtr += r; + } + + if (_RXbuffer->empty() && (len > 0) && buf) + { + r = len; + + if (r > _rxSize) + { + r = _rxSize; + } + + memcpy(_rxReadBytesPtr, buf, r); + _rxReadBytesPtr += r; + _rxSize -= r; + newReadCount += r; + } + + if (_rxSize == 0) + { + _RXmode = ATB_RX_MODE_NONE; + _cbDone(true, NULL); + } + + // add left over bytes to Buffer + return newReadCount; + + } + else if (_RXmode == ATB_RX_MODE_TERMINATOR) + { + // TODO implement read terminator non string + } + else if (_RXmode == ATB_RX_MODE_TERMINATOR_STRING) + { + if (_rxReadStringPtr == NULL || _cbDone == NULL) + { + return 0; + } + + // handle Buffer + if (BufferAvailable > 0) + { + while (!_RXbuffer->empty()) + { + char c = _RXbuffer->read(); + + if (c == _rxTerminator || c == 0x00) + { + _RXmode = ATB_RX_MODE_NONE; + _cbDone(true, _rxReadStringPtr); + return 0; + } + else + { + (*_rxReadStringPtr) += c; + } + } + } + + if (_RXbuffer->empty() && (len > 0) && buf) + { + size_t newReadCount = 0; + + while (newReadCount < len) + { + char c = (char) * buf; + buf++; + newReadCount++; + + if (c == _rxTerminator || c == 0x00) + { + _RXmode = ATB_RX_MODE_NONE; + _cbDone(true, _rxReadStringPtr); + + return newReadCount; + } + else + { + (*_rxReadStringPtr) += c; + } + } + + return newReadCount; + } + } + + return 0; +} + +#endif // _TEENSY41_ASYNC_TCP_BUFFER_IMPL_H_ diff --git a/src/Teensy41_AsyncTCP_Debug.h b/src/Teensy41_AsyncTCP_Debug.h new file mode 100644 index 0000000..7e7eadc --- /dev/null +++ b/src/Teensy41_AsyncTCP_Debug.h @@ -0,0 +1,106 @@ +/**************************************************************************************************************************** + Teensy41_AsyncTCP_Debug.h + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_DEBUG_H +#define _TEENSY41_ASYNC_TCP_DEBUG_H + +#ifdef TEENSY41_ASYNC_TCP_DEBUG_PORT + #define DBG_PORT_T41_ASYNC TEENSY41_ASYNC_TCP_DEBUG_PORT +#else + #define DBG_PORT_T41_ASYNC Serial +#endif + +// Change _TEENSY41_ASYNC_TCP_LOGLEVEL_ to set tracing and logging verbosity +// 0: DISABLED: no logging +// 1: ERROR: errors +// 2: WARN: errors and warnings +// 3: INFO: errors, warnings and informational (default) +// 4: DEBUG: errors, warnings, informational and debug + +#ifndef _TEENSY41_ASYNC_TCP_LOGLEVEL_ + #define _TEENSY41_ASYNC_TCP_LOGLEVEL_ 1 +#endif + +///////////////////////////////////////////////////////// + +#define T41_ASYNC_PRINT_MARK T41_ASYNC_PRINT("[T41_ASYNC] ") +#define T41_ASYNC_PRINT_SP DBG_PORT_T41_ASYNC.print(" ") +#define T41_ASYNC_PRINT_SP0X DBG_PORT_T41_ASYNC.print(" 0x") + +#define T41_ASYNC_PRINT DBG_PORT_T41_ASYNC.print +#define T41_ASYNC_PRINTLN DBG_PORT_T41_ASYNC.println +#define T41_ASYNC_PRINTF DBG_PORT_T41_ASYNC.printf + +///////////////////////////////////////////////////////// + +#define ASYNC_TCP_DEBUG(...) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINTF(__VA_ARGS__); } +#define ASYNC_TCP_SSL_DEBUG(...) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINTF(__VA_ARGS__); } + +#define ASYNC_TCP_ASSERT( a ) do{ if(!(a)){T41_ASYNC_PRINTF("ASSERT: %s %u \n", __FILE__, __LINE__);}}while(0) + +///////////////////////////////////////////////////////// + +#define T41_ASYNC_LOGERROR(x) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>0) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINTLN(x); } +#define T41_ASYNC_LOGERROR0(x) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>0) { T41_ASYNC_PRINT(x); } +#define T41_ASYNC_LOGERROR1(x,y) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>0) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(y); } +#define T41_ASYNC_HEXLOGERROR1(x,y) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>0) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINTLN(y, HEX); } +#define T41_ASYNC_LOGERROR2(x,y,z) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>0) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(y); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(z); } +#define T41_ASYNC_HEXLOGERROR2(x,y,z) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>0) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINT(y, HEX); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINTLN(z, HEX); } +#define T41_ASYNC_LOGERROR3(x,y,z,w) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>0) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(y); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(z); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(w); } + +///////////////////////////////////////////////////////// + +#define T41_ASYNC_LOGWARN(x) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>1) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINTLN(x); } +#define T41_ASYNC_LOGWARN0(x) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>1) { T41_ASYNC_PRINT(x); } +#define T41_ASYNC_LOGWARN1(x,y) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>1) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(y); } +#define T41_ASYNC_HEXLOGWARN1(x,y) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>1) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINTLN(y, HEX); } +#define T41_ASYNC_LOGWARN2(x,y,z) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>1) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(y); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(z); } +#define T41_ASYNC_HEXLOGWARN2(x,y,z) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>1) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINT(y, HEX); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINTLN(z, HEX); } +#define T41_ASYNC_LOGWARN3(x,y,z,w) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>1) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(y); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(z); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(w); } + +///////////////////////////////////////////////////////// + +#define T41_ASYNC_LOGINFO(x) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>2) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINTLN(x); } +#define T41_ASYNC_LOGINFO0(x) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>2) { T41_ASYNC_PRINT(x); } +#define T41_ASYNC_LOGINFO1(x,y) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>2) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(y); } +#define T41_ASYNC_HEXLOGINFO1(x,y) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>2) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINTLN(y, HEX); } +#define T41_ASYNC_LOGINFO2(x,y,z) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>2) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(y); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(z); } +#define T41_ASYNC_HEXLOGINFO2(x,y,z) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>2) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINT(y, HEX); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINTLN(z, HEX); } +#define T41_ASYNC_LOGINFO3(x,y,z,w) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>2) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(y); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(z); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(w); } + +///////////////////////////////////////////////////////// + +#define T41_ASYNC_LOGDEBUG(x) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINTLN(x); } +#define T41_ASYNC_LOGDEBUG0(x) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINT(x); } +#define T41_ASYNC_LOGDEBUG1(x,y) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(y); } +#define T41_ASYNC_HEXLOGDEBUG1(x,y) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINTLN(y, HEX); } +#define T41_ASYNC_LOGDEBUG2(x,y,z) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(y); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(z); } +#define T41_ASYNC_HEXLOGDEBUG2(x,y,z) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINT(y, HEX); T41_ASYNC_PRINT_SP0X; T41_ASYNC_PRINTLN(z, HEX); } +#define T41_ASYNC_LOGDEBUG3(x,y,z,w) if(_TEENSY41_ASYNC_TCP_LOGLEVEL_>3) { T41_ASYNC_PRINT_MARK; T41_ASYNC_PRINT(x); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(y); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINT(z); T41_ASYNC_PRINT_SP; T41_ASYNC_PRINTLN(w); } + +///////////////////////////////////////////////////////// + +#endif // _TEENSY41_ASYNC_TCP_DEBUG_H diff --git a/src/Teensy41_AsyncTCP_Impl.h b/src/Teensy41_AsyncTCP_Impl.h new file mode 100644 index 0000000..5a2c83b --- /dev/null +++ b/src/Teensy41_AsyncTCP_Impl.h @@ -0,0 +1,1826 @@ +/**************************************************************************************************************************** + Teensy41_AsyncTCP_Impl.h + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +/**************************************************************************************************************************** + Asynchronous TCP library for Espressif MCUs + + Copyright (c) 2016 Hristo Gochkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + ============================================================================== + + Changes for July 2019 + + The operator "new ..." was changed to "new (std::nothrow) ...", which will + return NULL when the heap is out of memory. Without the change "soft WDT" + was the result, starting with Arduino ESP8266 Core 2.5.0. (Note, RE:"soft + WDT" - the error reporting may improve with core 2.6.) With proir core + versions the library appears to work fine. + ref: https://github.com/esp8266/Arduino/issues/6269#issue-464978944 + + To support newer lwIP versions and buffer models. All references to 1460 + were replaced with TCP_MSS. If TCP_MSS is not defined (exp. 1.4v lwIP) + 1460 is assumed. + + The Teensy41_AsyncTCP library should build for Arduino ESP8266 Core releases: + 2.3.0, 2.4.1, 2.4.2, 2.5.1, 2.5.2. It may still build with core versions + 2.4.0 and 2.5.0. I did not do any regression testing with these, since + they had too many issues and were quickly superseded. + + lwIP tcp_err() callback often resulted in crashes. The problem was a + tcp_err() would come in, while processing a send or receive in the + forground. The tcp_err() callback would be passed down to a client's + registered disconnect CB. A common problem with SyncClient and other + modules as well as some client code was: the freeing of Teensy41_AsyncTCP + AsyncClient objects via disconnect CB handlers while the library was + waiting for an operstion to finished. Attempts to access bad pointers + followed. For SyncClient this commonly occured during a call to delay(). + On return to SyncClient _client was invalid. Also the problem described by + issue #94 also surfaced + + Use of tcp_abort() required some very special handling and was very + challenging to make work without changing client API. ERR_ABRT can only be + used once on a return to lwIP for a given connection and since the + AsyncClient structure was sometimes deleted before returning to lwIP, the + state tracking became tricky. While ugly, a global variable for this + seemed to work; however, I abanded it when I saw a possible + reentrancy/concurrency issue. After several approaches I settled the + problem by creating "class ACErrorTracker" to manage the issue. + + + Additional Async Client considerations: + + The client sketch must always test if the connection is still up at loop() + entry and after the return of any function call, that may have done a + delay() or yield() or any Teensy41_AsyncTCPTCP library family call. For example, + the connection could be lost during a call to _client->write(...). Client + sketches that delete _client as part of their onDisconnect() handler must + be very careful as _client will become invalid after calls to delay(), + yield(), etc. + + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_IMPL_H_ +#define _TEENSY41_ASYNC_TCP_IMPL_H_ + +#include "Arduino.h" + +extern "C" +{ + #include "lwip/ip_addr.h" + #include "lwip/opt.h" + #include "lwip/tcp.h" + #include "lwip/inet.h" + #include "lwip/dns.h" + #include "lwip/init.h" +} + +/* + Async Client Error Return Tracker +*/ +// Assumption: callbacks are never called with err == ERR_ABRT; however, +// they may return ERR_ABRT. + +ACErrorTracker::ACErrorTracker(AsyncClient *c): + _client(c) + , _close_error(ERR_OK) + , _errored(EE_OK) +#ifdef DEBUG_MORE + , _error_event_cb(NULL) + , _error_event_cb_arg(NULL) +#endif +{} + +#ifdef DEBUG_MORE +/** + This is not necessary, but a start at gathering some statistics on + errored out connections. Used from AsyncServer. +*/ +void ACErrorTracker::onErrorEvent(AsNotifyHandler cb, void *arg) +{ + _error_event_cb = cb; + _error_event_cb_arg = arg; +} +#endif + +void ACErrorTracker::setCloseError(err_t e) +{ + if (e != ERR_OK) + ASYNC_TCP_DEBUG("ACErrorTracker::setCloseError() to: %s(%ld)\n", _client->errorToString(e), e); + + if (_errored == EE_OK) + _close_error = e; +} +/** + Called mainly by callback routines, called when err is not ERR_OK. + This prevents the possiblity of aborting an already errored out + connection. +*/ +void ACErrorTracker::setErrored(size_t errorEvent) +{ + if (EE_OK == _errored) + _errored = errorEvent; + +#ifdef DEBUG_MORE + if (_error_event_cb) + _error_event_cb(_error_event_cb_arg, errorEvent); +#endif +} +/** + Used by callback functions only. Used for proper ERR_ABRT return value + reporting. ERR_ABRT is only reported/returned once; thereafter ERR_OK + is always returned. +*/ +err_t ACErrorTracker::getCallbackCloseError() +{ + if (EE_OK != _errored) + return ERR_OK; + + if (ERR_ABRT == _close_error) + setErrored(EE_ABORTED); + + return _close_error; +} + +/* + Async TCP Client +*/ +#if DEBUG_ESP_ASYNC_TCP +static size_t _connectionCount = 0; +#endif + +#if ASYNC_TCP_SSL_ENABLED +AsyncClient::AsyncClient(tcp_pcb* pcb, SSL_CTX * ssl_ctx): +#else +AsyncClient::AsyncClient(tcp_pcb * pcb): +#endif + _connect_cb(0) + , _connect_cb_arg(0) + , _discard_cb(0) + , _discard_cb_arg(0) + , _sent_cb(0) + , _sent_cb_arg(0) + , _error_cb(0) + , _error_cb_arg(0) + , _recv_cb(0) + , _recv_cb_arg(0) + , _pb_cb(0) + , _pb_cb_arg(0) + , _timeout_cb(0) + , _timeout_cb_arg(0) + , _poll_cb(0) + , _poll_cb_arg(0) + , _pcb_busy(false) +#if ASYNC_TCP_SSL_ENABLED + , _pcb_secure(false) + , _handshake_done(true) +#endif + , _pcb_sent_at(0) + , _close_pcb(false) + , _ack_pcb(true) + , _tx_unacked_len(0) + , _tx_acked_len(0) + , _tx_unsent_len(0) + , _rx_ack_len(0) + , _rx_last_packet(0) + , _rx_since_timeout(0) + , _ack_timeout(ASYNC_MAX_ACK_TIME) + , _connect_port(0) + , _recv_pbuf_flags(0) + , _errorTracker(NULL) + , prev(NULL) + , next(NULL) +{ + _pcb = pcb; + + if (_pcb) + { + _rx_last_packet = millis(); + tcp_setprio(_pcb, TCP_PRIO_MIN); + tcp_arg(_pcb, this); + tcp_recv(_pcb, &_s_recv); + tcp_sent(_pcb, &_s_sent); + tcp_err(_pcb, &_s_error); + tcp_poll(_pcb, &_s_poll, 1); + +#if ASYNC_TCP_SSL_ENABLED + if (ssl_ctx) + { + if (tcp_ssl_new_server(_pcb, ssl_ctx) < 0) + { + _close(); + + return; + } + + tcp_ssl_arg(_pcb, this); + tcp_ssl_data(_pcb, &_s_data); + tcp_ssl_handshake(_pcb, &_s_handshake); + tcp_ssl_err(_pcb, &_s_ssl_error); + + _pcb_secure = true; + _handshake_done = false; + } +#endif + } + + _errorTracker = std::make_shared(this); + +#if DEBUG_ESP_ASYNC_TCP + _errorTracker->setConnectionId(++_connectionCount); +#endif +} + +AsyncClient::~AsyncClient() +{ + if (_pcb) + _close(); + + _errorTracker->clearClient(); +} + +inline void clearTcpCallbacks(tcp_pcb* pcb) +{ + tcp_arg(pcb, NULL); + tcp_sent(pcb, NULL); + tcp_recv(pcb, NULL); + tcp_err(pcb, NULL); + tcp_poll(pcb, NULL, 0); +} + +#if ASYNC_TCP_SSL_ENABLED +bool AsyncClient::connect(IPAddress ip, uint16_t port, bool secure) +#else +bool AsyncClient::connect(IPAddress ip, uint16_t port) +#endif +{ + if (_pcb) //already connected + return false; + + ip_addr_t addr; + addr.addr = ip; + +#if LWIP_VERSION_MAJOR == 1 + netif* interface = ip_route(&addr); + + if (!interface) + { + //no route to host + return false; + } +#endif + + tcp_pcb* pcb = tcp_new(); + + if (!pcb) + { //could not allocate pcb + return false; + } + + tcp_setprio(pcb, TCP_PRIO_MIN); + +#if ASYNC_TCP_SSL_ENABLED + _pcb_secure = secure; + _handshake_done = !secure; +#endif + + tcp_arg(pcb, this); + tcp_err(pcb, &_s_error); + size_t err = tcp_connect(pcb, &addr, port, (tcp_connected_fn)&_s_connected); + + return (ERR_OK == err); +} + +#if ASYNC_TCP_SSL_ENABLED +bool AsyncClient::connect(const char* host, uint16_t port, bool secure) +#else +bool AsyncClient::connect(const char* host, uint16_t port) +#endif +{ + ip_addr_t addr; + err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_s_dns_found, this); + + // printf("CNX GHBN err: %s(%ld)\n", errorToString(err), err); + + if (err == ERR_OK) + { +#if ASYNC_TCP_SSL_ENABLED + return connect(IPAddress(addr.addr), port, secure); +#else + return connect(IPAddress(addr.addr), port); +#endif + } + else if (err == ERR_INPROGRESS) + { +#if ASYNC_TCP_SSL_ENABLED + _pcb_secure = secure; + _handshake_done = !secure; +#endif + _connect_port = port; + + return true; + } + + return false; +} + +AsyncClient& AsyncClient::operator=(const AsyncClient& other) +{ + if (_pcb) + { + _close(); + } + + _errorTracker = other._errorTracker; + + // I am confused when "other._pcb" falls out of scope the destructor will + // close it? TODO: Look to see where this is used and how it might work. + _pcb = other._pcb; + + if (_pcb) + { + _rx_last_packet = millis(); + tcp_setprio(_pcb, TCP_PRIO_MIN); + tcp_arg(_pcb, this); + tcp_recv(_pcb, &_s_recv); + tcp_sent(_pcb, &_s_sent); + tcp_err(_pcb, &_s_error); + tcp_poll(_pcb, &_s_poll, 1); + +#if ASYNC_TCP_SSL_ENABLED + if (tcp_ssl_has(_pcb)) + { + _pcb_secure = true; + _handshake_done = false; + tcp_ssl_arg(_pcb, this); + tcp_ssl_data(_pcb, &_s_data); + tcp_ssl_handshake(_pcb, &_s_handshake); + tcp_ssl_err(_pcb, &_s_ssl_error); + } + else + { + _pcb_secure = false; + _handshake_done = true; + } +#endif + } + + return *this; +} + +bool AsyncClient::operator==(const AsyncClient &other) +{ + return (_pcb != NULL && other._pcb != NULL && (_pcb->remote_ip.addr == other._pcb->remote_ip.addr) && (_pcb->remote_port == other._pcb->remote_port)); +} + +void AsyncClient::abort() +{ + // Notes: + // 1) _pcb is set to NULL, so we cannot call tcp_abort() more than once. + // 2) setCloseError(ERR_ABRT) is only done here! + // 3) Using this abort() function guarantees only one tcp_abort() call is + // made and only one CB returns with ERR_ABORT. + // 4) After abort() is called from _close(), no callbacks with an err + // parameter will be called. eg. _recv(), _error(), _connected(). + // _close() will reset there CB handlers before calling. + // 5) A callback to _error(), will set _pcb to NULL, thus avoiding the + // of a 2nd call to tcp_abort(). + // 6) Callbacks to _recv() or _connected() with err set, will result in _pcb + // set to NULL. Thus, preventing possible calls later to tcp_abort(). + if (_pcb) + { + tcp_abort(_pcb); + _pcb = NULL; + setCloseError(ERR_ABRT); + } + + return; +} + +void AsyncClient::close(bool now) +{ + if (_pcb) + tcp_recved(_pcb, _rx_ack_len); + + if (now) + _close(); + else + _close_pcb = true; +} + +void AsyncClient::stop() +{ + close(false); +} + +bool AsyncClient::free() +{ + if (!_pcb) + return true; + + if (_pcb->state == 0 || _pcb->state > 4) + return true; + + return false; +} + +size_t AsyncClient::write(const char* data) +{ + if (data == NULL) + return 0; + + return write(data, strlen(data)); +} + +size_t AsyncClient::write(const char* data, size_t size, uint8_t apiflags) +{ + size_t will_send = add(data, size, apiflags); + + if (!will_send || !send()) + return 0; + + return will_send; +} + +void hexdump(const char* data, size_t size) +{ + //printf("ADDING len=%d room=%d",size); + //for(int i=0;i= 0) + { + _tx_unacked_len += sent; + return sent; + } + + _close(); + + return 0; + } +#endif + + size_t will_send = (room < size) ? room : size; + err_t err = tcp_write(_pcb, data, will_send, apiflags); + + //printf("_add: tcp_write() returned err: %s(%ld)\n", errorToString(err), err); + + if (err != ERR_OK) + { + return 0; + } + + _tx_unsent_len += will_send; + + return will_send; +} + +bool AsyncClient::send() +{ +#if ASYNC_TCP_SSL_ENABLED + if (_pcb_secure) + return true; +#endif + + err_t err = tcp_output(_pcb); + + // printf("send: tcp_output() returned err: %s(%ld)\n", errorToString(err), err); + + if (err == ERR_OK) + { + _pcb_busy = true; + _pcb_sent_at = millis(); + _tx_unacked_len += _tx_unsent_len; + _tx_unsent_len = 0; + return true; + } + + _tx_unsent_len = 0; + return false; +} + +size_t AsyncClient::ack(size_t len) +{ + if (len > _rx_ack_len) + len = _rx_ack_len; + + if (len) + tcp_recved(_pcb, len); + + _rx_ack_len -= len; + + return len; +} + +// Private Callbacks + +void AsyncClient::_connected(std::shared_ptr& errorTracker, void* pcb, err_t err) +{ + //(void)err; // LWIP v1.4 appears to always call with ERR_OK + // Documentation for 2.1.0 also says: + // "err - An unused error code, always ERR_OK currently ;-)" + // https://www.nongnu.org/lwip/2_1_x/tcp_8h.html#a939867106bd492caf2d85852fb7f6ae8 + // Based on that wording and emoji lets just handle it now. + // After all, the API does allow for an err != ERR_OK. + if (NULL == pcb || ERR_OK != err) + { + ASYNC_TCP_DEBUG("AsyncClient::_connected: [%u]:%s err: %s(%ld)\n", errorTracker->getConnectionId(), ((NULL == pcb) ? " NULL == pcb!," : ""), errorToString(err), err); + errorTracker->setCloseError(err); + errorTracker->setErrored(EE_CONNECTED_CB); + _pcb = reinterpret_cast(pcb); + + if (_pcb) + clearTcpCallbacks(_pcb); + + _pcb = NULL; + _error(err); + + return; + } + + _pcb = reinterpret_cast(pcb); + + if (_pcb) + { + _pcb_busy = false; + _rx_last_packet = millis(); + tcp_setprio(_pcb, TCP_PRIO_MIN); + tcp_recv(_pcb, &_s_recv); + tcp_sent(_pcb, &_s_sent); + tcp_poll(_pcb, &_s_poll, 1); + +#if ASYNC_TCP_SSL_ENABLED + + if (_pcb_secure) + { + if (tcp_ssl_new_client(_pcb) < 0) + { + _close(); + return; + } + + tcp_ssl_arg(_pcb, this); + tcp_ssl_data(_pcb, &_s_data); + tcp_ssl_handshake(_pcb, &_s_handshake); + tcp_ssl_err(_pcb, &_s_ssl_error); + } + } + + if (!_pcb_secure && _connect_cb) + _connect_cb(_connect_cb_arg, this); + +#else + + } + + if (_connect_cb) + _connect_cb(_connect_cb_arg, this); +#endif + + return; +} + +void AsyncClient::_close() +{ + if (_pcb) + { +#if ASYNC_TCP_SSL_ENABLED + if (_pcb_secure) + { + tcp_ssl_free(_pcb); + } +#endif + + clearTcpCallbacks(_pcb); + err_t err = tcp_close(_pcb); + + if (ERR_OK == err) + { + setCloseError(err); + } + else + { + abort(); + } + + _pcb = NULL; + + if (_discard_cb) + _discard_cb(_discard_cb_arg, this); + } + return; +} + +void AsyncClient::_error(err_t err) +{ + if (_pcb) + { +#if ASYNC_TCP_SSL_ENABLED + if (_pcb_secure) + { + tcp_ssl_free(_pcb); + } +#endif + + // At this callback _pcb is possible already freed. Thus, no calls are + // made to set to NULL other callbacks. + _pcb = NULL; + } + + if (_error_cb) + _error_cb(_error_cb_arg, this, err); + + if (_discard_cb) + _discard_cb(_discard_cb_arg, this); +} + +#if ASYNC_TCP_SSL_ENABLED +void AsyncClient::_ssl_error(int8_t err) +{ + if (_error_cb) + _error_cb(_error_cb_arg, this, err + 64); +} +#endif + +void AsyncClient::_sent(std::shared_ptr& errorTracker, tcp_pcb* pcb, uint16_t len) +{ + (void)pcb; + +#if ASYNC_TCP_SSL_ENABLED + if (_pcb_secure && !_handshake_done) + return; +#endif + + _rx_last_packet = millis(); + _tx_unacked_len -= len; + _tx_acked_len += len; + + ASYNC_TCP_DEBUG("AsyncClient::_sent[%u]: %4u, unacked=%4u, acked=%4u, space=%4u\n", errorTracker->getConnectionId(), len, _tx_unacked_len, _tx_acked_len, space()); + + if (_tx_unacked_len == 0) + { + _pcb_busy = false; + errorTracker->setCloseError(ERR_OK); + + if (_sent_cb) + { + _sent_cb(_sent_cb_arg, this, _tx_acked_len, (millis() - _pcb_sent_at)); + + if (!errorTracker->hasClient()) + return; + } + + _tx_acked_len = 0; + } + + return; +} + +void AsyncClient::_recv(std::shared_ptr& errorTracker, tcp_pcb* pcb, pbuf* pb, err_t err) +{ + // While lwIP v1.4 appears to always call with ERR_OK, 2.x lwIP may present + // a non-ERR_OK value. + // https://www.nongnu.org/lwip/2_1_x/tcp_8h.html#a780cfac08b02c66948ab94ea974202e8 + if (NULL == pcb || ERR_OK != err) { + ASYNC_TCP_DEBUG("AsyncClient::_recv[%u]:%s err: %s(%ld)\n", errorTracker->getConnectionId(), ((NULL == pcb) ? " NULL == pcb!," : ""), errorToString(err), err); + ASYNC_TCP_ASSERT(ERR_ABRT != err); + + errorTracker->setCloseError(err); + errorTracker->setErrored(EE_RECV_CB); + _pcb = pcb; + + if (_pcb) + clearTcpCallbacks(_pcb); + + _pcb = NULL; + + // I think we are safe from being called from an interrupt context. + // Best Hint that calling _error() is safe: + // https://www.nongnu.org/lwip/2_1_x/group__lwip__nosys.html + // "Feed incoming packets to netif->input(pbuf, netif) function from + // mainloop, not from interrupt context. You can allocate a Packet buffers + // (PBUF) in interrupt context and put them into a queue which is processed + // from mainloop." + // And the description of "Mainloop Mode" option 2: + // https://www.nongnu.org/lwip/2_1_x/pitfalls.html + // "2) Run lwIP in a mainloop. ... lwIP is ONLY called from mainloop + // callstacks here. The ethernet IRQ has to put received telegrams into a + // queue which is polled in the mainloop. Ensure lwIP is NEVER called from + // an interrupt, ...!" + // Based on these comments I am thinking tcp_recv_fn() is called + // from somebody's mainloop(), which could only have been reached from a + // delay like function or the Arduino sketch loop() function has returned. + // What I don't want is for the client sketch to delete the AsyncClient + // object via _error() while it is in the middle of using it. However, + // the client sketch must always test that the connection is still up + // at loop() entry and after the return of any function call, that may + // have done a delay() or yield(). + _error(err); + + return; + } + + if (pb == NULL) + { + ASYNC_TCP_DEBUG("AsyncClient::_recv[%u]: pb == NULL! Closing... %ld\n", errorTracker->getConnectionId(), err); + _close(); + return; + } + + _rx_last_packet = millis(); + errorTracker->setCloseError(ERR_OK); + +#if ASYNC_TCP_SSL_ENABLED + if (_pcb_secure) + { + ASYNC_TCP_DEBUG("AsyncClient::_recv[%u]: %d\n", getConnectionId(), pb->tot_len); + int read_bytes = tcp_ssl_read(pcb, pb); + + if (read_bytes < 0) + { + if (read_bytes != SSL_CLOSE_NOTIFY) + { + ASYNC_TCP_DEBUG("AsyncClient::_recv[%u] err: %d\n", getConnectionId(), read_bytes); + _close(); + } + } + + return; + } +#endif + while (pb != NULL) + { + // IF this callback function returns ERR_OK or ERR_ABRT + // then it is assummed we freed the pbufs. + // https://www.nongnu.org/lwip/2_1_x/group__tcp__raw.html#ga8afd0b316a87a5eeff4726dc95006ed0 + if (!errorTracker->hasClient()) + { + while (pb != NULL) + { + pbuf *b = pb; + pb = b->next; + b->next = NULL; + pbuf_free(b); + } + + return; + } + + //we should not ack before we assimilate the data + _ack_pcb = true; + pbuf *b = pb; + pb = b->next; + b->next = NULL; + + ASYNC_TCP_DEBUG("AsyncClient::_recv[%u]: %d%s\n", errorTracker->getConnectionId(), b->len, (b->flags & PBUF_FLAG_PUSH) ? ", PBUF_FLAG_PUSH" : ""); + + if (_pb_cb) + { + _pb_cb(_pb_cb_arg, this, b); + } + else + { + if (_recv_cb) + { + _recv_pbuf_flags = b->flags; + _recv_cb(_recv_cb_arg, this, b->payload, b->len); + } + + if (errorTracker->hasClient()) + { + if (!_ack_pcb) + _rx_ack_len += b->len; + else + tcp_recved(pcb, b->len); + } + + pbuf_free(b); + } + } + + return; +} + +void AsyncClient::_poll(std::shared_ptr& errorTracker, tcp_pcb* pcb) +{ + (void)pcb; + errorTracker->setCloseError(ERR_OK); + + // Close requested + if (_close_pcb) + { + _close_pcb = false; + _close(); + + return; + } + + uint32_t now = millis(); + + // ACK Timeout + if (_pcb_busy && _ack_timeout && (now - _pcb_sent_at) >= _ack_timeout) + { + _pcb_busy = false; + + if (_timeout_cb) + _timeout_cb(_timeout_cb_arg, this, (now - _pcb_sent_at)); + + return; + } + + // RX Timeout + if (_rx_since_timeout && (now - _rx_last_packet) >= (_rx_since_timeout * 1000)) + { + _close(); + + return; + } + +#if ASYNC_TCP_SSL_ENABLED + // SSL Handshake Timeout + if (_pcb_secure && !_handshake_done && (now - _rx_last_packet) >= 2000) + { + _close(); + + return; + } +#endif + + // Everything is fine + if (_poll_cb) + _poll_cb(_poll_cb_arg, this); + + return; +} + +#if LWIP_VERSION_MAJOR == 1 +void AsyncClient::_dns_found(struct ip_addr *ipaddr) +#else +void AsyncClient::_dns_found(ip_addr_t *p) +#endif +{ + if (p) + { +#if ASYNC_TCP_SSL_ENABLED + connect(IPAddress(ipaddr->addr), _connect_port, _pcb_secure); +#else + connect(IPAddress(p->addr), _connect_port); +#endif + } + else + { + if (_error_cb) + _error_cb(_error_cb_arg, this, -55); + + if (_discard_cb) + _discard_cb(_discard_cb_arg, this); + } +} + +// lwIP Callbacks +#if LWIP_VERSION_MAJOR == 1 +void AsyncClient::_s_dns_found(const char *name, const ip_addr *ipaddr, void *arg) +#else +void AsyncClient::_s_dns_found(const char *name, ip_addr_t *p, void *arg) +#endif +{ + (void)name; + + reinterpret_cast(arg)->_dns_found(p); +} + +err_t AsyncClient::_s_poll(void *arg, struct tcp_pcb *tpcb) +{ + AsyncClient *c = reinterpret_cast(arg); + std::shared_ptrerrorTracker = c->getACErrorTracker(); + c->_poll(errorTracker, tpcb); + + return errorTracker->getCallbackCloseError(); +} + +err_t AsyncClient::_s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err) +{ + AsyncClient *c = reinterpret_cast(arg); + auto errorTracker = c->getACErrorTracker(); + c->_recv(errorTracker, tpcb, pb, err); + + return errorTracker->getCallbackCloseError(); +} + +void AsyncClient::_s_error(void *arg, err_t err) +{ + AsyncClient *c = reinterpret_cast(arg); + auto errorTracker = c->getACErrorTracker(); + errorTracker->setCloseError(err); + errorTracker->setErrored(EE_ERROR_CB); + c->_error(err); +} + +err_t AsyncClient::_s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len) +{ + AsyncClient *c = reinterpret_cast(arg); + auto errorTracker = c->getACErrorTracker(); + c->_sent(errorTracker, tpcb, len); + + return errorTracker->getCallbackCloseError(); +} + +err_t AsyncClient::_s_connected(void* arg, void* tpcb, err_t err) +{ + AsyncClient *c = reinterpret_cast(arg); + auto errorTracker = c->getACErrorTracker(); + c->_connected(errorTracker, tpcb, err); + + return errorTracker->getCallbackCloseError(); +} + +#if ASYNC_TCP_SSL_ENABLED +void AsyncClient::_s_data(void *arg, struct tcp_pcb *tcp, uint8_t * data, size_t len) +{ + AsyncClient *c = reinterpret_cast(arg); + + if (c->_recv_cb) + c->_recv_cb(c->_recv_cb_arg, c, data, len); +} + +void AsyncClient::_s_handshake(void *arg, struct tcp_pcb *tcp, SSL *ssl) +{ + AsyncClient *c = reinterpret_cast(arg); + c->_handshake_done = true; + + if (c->_connect_cb) + c->_connect_cb(c->_connect_cb_arg, c); +} + +void AsyncClient::_s_ssl_error(void *arg, struct tcp_pcb *tcp, int8_t err) +{ + reinterpret_cast(arg)->_ssl_error(err); +} +#endif + +// Operators + +AsyncClient & AsyncClient::operator+=(const AsyncClient &other) +{ + if (next == NULL) + { + next = (AsyncClient*)(&other); + next->prev = this; + } + else + { + AsyncClient *c = next; + while (c->next != NULL) c = c->next; + c->next = (AsyncClient*)(&other); + c->next->prev = c; + } + + return *this; +} + +void AsyncClient::setRxTimeout(uint32_t timeout) +{ + _rx_since_timeout = timeout; +} + +uint32_t AsyncClient::getRxTimeout() +{ + return _rx_since_timeout; +} + +uint32_t AsyncClient::getAckTimeout() +{ + return _ack_timeout; +} + +void AsyncClient::setAckTimeout(uint32_t timeout) +{ + _ack_timeout = timeout; +} + +void AsyncClient::setNoDelay(bool nodelay) +{ + if (!_pcb) + return; + + if (nodelay) + tcp_nagle_disable(_pcb); + else + tcp_nagle_enable(_pcb); +} + +bool AsyncClient::getNoDelay() +{ + if (!_pcb) + return false; + + return tcp_nagle_disabled(_pcb); +} + +uint16_t AsyncClient::getMss() +{ + if (_pcb) + return tcp_mss(_pcb); + + return 0; +} + +uint32_t AsyncClient::getRemoteAddress() +{ + if (!_pcb) + return 0; + + return _pcb->remote_ip.addr; +} + +uint16_t AsyncClient::getRemotePort() +{ + if (!_pcb) + return 0; + + return _pcb->remote_port; +} + +uint32_t AsyncClient::getLocalAddress() +{ + if (!_pcb) + return 0; + + return _pcb->local_ip.addr; +} + +uint16_t AsyncClient::getLocalPort() +{ + if (!_pcb) + return 0; + + return _pcb->local_port; +} + +IPAddress AsyncClient::remoteIP() +{ + return IPAddress(getRemoteAddress()); +} + +uint16_t AsyncClient::remotePort() +{ + return getRemotePort(); +} + +IPAddress AsyncClient::localIP() +{ + return IPAddress(getLocalAddress()); +} + +uint16_t AsyncClient::localPort() +{ + return getLocalPort(); +} + +#if ASYNC_TCP_SSL_ENABLED +SSL * AsyncClient::getSSL() +{ + if (_pcb && _pcb_secure) + { + return tcp_ssl_get_ssl(_pcb); + } + + return NULL; +} +#endif + +uint8_t AsyncClient::state() +{ + if (!_pcb) + return 0; + + return _pcb->state; +} + +bool AsyncClient::connected() +{ + if (!_pcb) + return false; + +#if ASYNC_TCP_SSL_ENABLED + return _pcb->state == 4 && _handshake_done; +#else + return _pcb->state == 4; +#endif +} + +bool AsyncClient::connecting() +{ + if (!_pcb) + return false; + + return _pcb->state > 0 && _pcb->state < 4; +} + +bool AsyncClient::disconnecting() +{ + if (!_pcb) + return false; + + return _pcb->state > 4 && _pcb->state < 10; +} + +bool AsyncClient::disconnected() +{ + if (!_pcb) + return true; + + return _pcb->state == 0 || _pcb->state == 10; +} + +bool AsyncClient::freeable() +{ + if (!_pcb) + return true; + + return _pcb->state == 0 || _pcb->state > 4; +} + +bool AsyncClient::canSend() +{ + return !_pcb_busy && (space() > 0); +} + + +// Callback Setters + +void AsyncClient::onConnect(AcConnectHandler cb, void* arg) +{ + _connect_cb = cb; + _connect_cb_arg = arg; +} + +void AsyncClient::onDisconnect(AcConnectHandler cb, void* arg) +{ + _discard_cb = cb; + _discard_cb_arg = arg; +} + +void AsyncClient::onAck(AcAckHandler cb, void* arg) { + _sent_cb = cb; + _sent_cb_arg = arg; +} + +void AsyncClient::onError(AcErrorHandler cb, void* arg) +{ + _error_cb = cb; + _error_cb_arg = arg; +} + +void AsyncClient::onData(AcDataHandler cb, void* arg) +{ + _recv_cb = cb; + _recv_cb_arg = arg; +} + +void AsyncClient::onPacket(AcPacketHandler cb, void* arg) +{ + _pb_cb = cb; + _pb_cb_arg = arg; +} + +void AsyncClient::onTimeout(AcTimeoutHandler cb, void* arg) +{ + _timeout_cb = cb; + _timeout_cb_arg = arg; +} + +void AsyncClient::onPoll(AcConnectHandler cb, void* arg) +{ + _poll_cb = cb; + _poll_cb_arg = arg; +} + + +size_t AsyncClient::space() +{ +#if ASYNC_TCP_SSL_ENABLED + if ((_pcb != NULL) && (_pcb->state == 4) && _handshake_done) + { + uint16_t s = tcp_sndbuf(_pcb); + + if (_pcb_secure) + { +#ifdef AXTLS_2_0_0_SNDBUF + return tcp_ssl_sndbuf(_pcb); +#else + if (s >= 128) //safe approach + return s - 128; + + return 0; +#endif + } + + return s; + } +#else // ASYNC_TCP_SSL_ENABLED + if ((_pcb != NULL) && (_pcb->state == 4)) + { + return tcp_sndbuf(_pcb); + } +#endif // ASYNC_TCP_SSL_ENABLED + + return 0; +} + +void AsyncClient::ackPacket(struct pbuf * pb) +{ + if (!pb) + { + return; + } + + tcp_recved(_pcb, pb->len); + pbuf_free(pb); +} + +const char * AsyncClient::errorToString(err_t error) +{ + switch (error) + { + case ERR_OK: return "No error, everything OK"; + case ERR_MEM: return "Out of memory error"; + case ERR_BUF: return "Buffer error"; + case ERR_TIMEOUT: return "Timeout"; + case ERR_RTE: return "Routing problem"; + case ERR_INPROGRESS: return "Operation in progress"; + case ERR_VAL: return "Illegal value"; + case ERR_WOULDBLOCK: return "Operation would block"; + case ERR_ABRT: return "Connection aborted"; + case ERR_RST: return "Connection reset"; + case ERR_CLSD: return "Connection closed"; + case ERR_CONN: return "Not connected"; + case ERR_ARG: return "Illegal argument"; + case ERR_USE: return "Address in use"; + +#if defined(LWIP_VERSION_MAJOR) && (LWIP_VERSION_MAJOR > 1) + case ERR_ALREADY: return "Already connectioning"; +#endif + + case ERR_IF: return "Low-level netif error"; + case ERR_ISCONN: return "Connection already established"; + case -55: return "DNS failed"; + default: return "Unknown error"; + } +} + +const char * AsyncClient::stateToString() +{ + switch (state()) + { + case 0: return "Closed"; + case 1: return "Listen"; + case 2: return "SYN Sent"; + case 3: return "SYN Received"; + case 4: return "Established"; + case 5: return "FIN Wait 1"; + case 6: return "FIN Wait 2"; + case 7: return "Close Wait"; + case 8: return "Closing"; + case 9: return "Last ACK"; + case 10: return "Time Wait"; + default: return "UNKNOWN"; + } +} + +/* + Async TCP Server +*/ +struct pending_pcb +{ + tcp_pcb* pcb; + pbuf *pb; + struct pending_pcb * next; +}; + +AsyncServer::AsyncServer(IPAddress addr, uint16_t port) + : _port(port) + , _addr(addr) + , _noDelay(false) + , _pcb(0) + , _connect_cb(0) + , _connect_cb_arg(0) +#if ASYNC_TCP_SSL_ENABLED + , _pending(NULL) + , _ssl_ctx(NULL) + , _file_cb(0) + , _file_cb_arg(0) +#endif +{ +#ifdef DEBUG_MORE + for (size_t i = 0; i < EE_MAX; ++i) + _event_count[i] = 0; +#endif +} + +AsyncServer::AsyncServer(uint16_t port) + : _port(port) + , _addr((uint32_t) IPADDR_ANY) + , _noDelay(false) + , _pcb(0) + , _connect_cb(0) + , _connect_cb_arg(0) +#if ASYNC_TCP_SSL_ENABLED + , _pending(NULL) + , _ssl_ctx(NULL) + , _file_cb(0) + , _file_cb_arg(0) +#endif +{ +#ifdef DEBUG_MORE + for (size_t i = 0; i < EE_MAX; ++i) + _event_count[i] = 0; +#endif +} + +AsyncServer::~AsyncServer() +{ + end(); +} + +void AsyncServer::onClient(AcConnectHandler cb, void* arg) +{ + _connect_cb = cb; + _connect_cb_arg = arg; +} + +#if ASYNC_TCP_SSL_ENABLED +void AsyncServer::onSslFileRequest(AcSSlFileHandler cb, void* arg) +{ + _file_cb = cb; + _file_cb_arg = arg; +} +#endif + +void AsyncServer::begin() +{ + if (_pcb) + return; + + int8_t err; + tcp_pcb* pcb = tcp_new(); + + if (!pcb) + { + return; + } + + tcp_setprio(pcb, TCP_PRIO_MIN); + ip_addr_t local_addr; + local_addr.addr = (uint32_t) _addr; + err = tcp_bind(pcb, &local_addr, _port); + + // Failures are ERR_ISCONN or ERR_USE + if (err != ERR_OK) + { + tcp_close(pcb); + return; + } + + tcp_pcb* listen_pcb = tcp_listen(pcb); + + if (!listen_pcb) + { + tcp_close(pcb); + return; + } + + _pcb = listen_pcb; + tcp_arg(_pcb, (void*) this); + tcp_accept(_pcb, &_s_accept); +} + +#if ASYNC_TCP_SSL_ENABLED +void AsyncServer::beginSecure(const char *cert, const char *key, const char *password) +{ + if (_ssl_ctx) + { + return; + } + + tcp_ssl_file(_s_cert, this); + _ssl_ctx = tcp_ssl_new_server_ctx(cert, key, password); + + if (_ssl_ctx) + { + begin(); + } +} +#endif + +void AsyncServer::end() +{ + if (_pcb) + { + //cleanup all connections? + tcp_arg(_pcb, NULL); + tcp_accept(_pcb, NULL); + + if (tcp_close(_pcb) != ERR_OK) + { + tcp_abort(_pcb); + } + + _pcb = NULL; + } + +#if ASYNC_TCP_SSL_ENABLED + if (_ssl_ctx) + { + ssl_ctx_free(_ssl_ctx); + _ssl_ctx = NULL; + + if (_pending) + { + struct pending_pcb * p; + + while (_pending) + { + p = _pending; + _pending = _pending->next; + + if (p->pb) + { + pbuf_free(p->pb); + } + + free(p); + } + } + } +#endif +} + +void AsyncServer::setNoDelay(bool nodelay) +{ + _noDelay = nodelay; +} + +bool AsyncServer::getNoDelay() +{ + return _noDelay; +} + +uint8_t AsyncServer::status() +{ + if (!_pcb) + return 0; + + return _pcb->state; +} + +err_t AsyncServer::_accept(tcp_pcb* pcb, err_t err) +{ + //http://savannah.nongnu.org/bugs/?43739 + if (NULL == pcb || ERR_OK != err) + { + // https://www.nongnu.org/lwip/2_1_x/tcp_8h.html#a00517abce6856d6c82f0efebdafb734d + // An error code if there has been an error accepting. Only return ERR_ABRT + // if you have called tcp_abort from within the callback function! + // eg. 2.1.0 could call with error on failure to allocate pcb. + ASYNC_TCP_DEBUG("AsyncServer::_accept: %s err: %ld\n", ((NULL == pcb) ? " NULL == pcb!," : ""), err); + ASYNC_TCP_ASSERT(ERR_ABRT != err); + +#ifdef DEBUG_MORE + incEventCount(EE_ACCEPT_CB); +#endif + return ERR_OK; + } + + if (_connect_cb) + { +#if ASYNC_TCP_SSL_ENABLED + if (_noDelay || _ssl_ctx) +#else + if (_noDelay) +#endif + tcp_nagle_disable(pcb); + else + tcp_nagle_enable(pcb); + +#if ASYNC_TCP_SSL_ENABLED + if (_ssl_ctx) + { + if (tcp_ssl_has_client() || _pending) + { + struct pending_pcb * new_item = (struct pending_pcb*)malloc(sizeof(struct pending_pcb)); + + if (!new_item) + { + ASYNC_TCP_DEBUG("AsyncServer::_accept: ### malloc new pending failed!\n"); + + if (tcp_close(pcb) != ERR_OK) + { + tcp_abort(pcb); + + return ERR_ABRT; + } + + return ERR_OK; + } + + ASYNC_TCP_DEBUG("AsyncServer::_accept: ### put to wait: %d\n", _clients_waiting); + + new_item->pcb = pcb; + new_item->pb = NULL; + new_item->next = NULL; + tcp_setprio(_pcb, TCP_PRIO_MIN); + tcp_arg(pcb, this); + tcp_poll(pcb, &_s_poll, 1); + tcp_recv(pcb, &_s_recv); + + if (_pending == NULL) + { + _pending = new_item; + } + else + { + struct pending_pcb * p = _pending; + + while (p->next != NULL) + p = p->next; + + p->next = new_item; + } + } + else + { + AsyncClient *c = new (std::nothrow) AsyncClient(pcb, _ssl_ctx); + + if (c) + { + ASYNC_TCP_DEBUG("AsyncServer::_accept: [%u]: SSL connected\n", c->getConnectionId()); + + c->onConnect([this](void * arg, AsyncClient * c) + { + _connect_cb(_connect_cb_arg, c); + }, this); + } + else + { + ASYNC_TCP_DEBUG("AsyncServer::_accept: [_ssl_ctx]: new AsyncClient() failed, connection aborted!\n"); + + if (tcp_close(pcb) != ERR_OK) + { + tcp_abort(pcb); + return ERR_ABRT; + } + } + } + + return ERR_OK; + } + else + { + AsyncClient *c = new (std::nothrow) AsyncClient(pcb, NULL); +#else + AsyncClient *c = new (std::nothrow) AsyncClient(pcb); +#endif + + if (c) + { + auto errorTracker = c->getACErrorTracker(); + +#ifdef DEBUG_MORE + errorTracker->onErrorEvent( + [](void *obj, size_t ee) + { + ((AsyncServer*)(obj))->incEventCount(ee); + }, + this); +#endif + ASYNC_TCP_DEBUG("AsyncServer::_accept: [%u]: connected\n", errorTracker->getConnectionId()); + + _connect_cb(_connect_cb_arg, c); + + return errorTracker->getCallbackCloseError(); + } + else + { + ASYNC_TCP_DEBUG("AsyncServer::_accept: new AsyncClient() failed, connection aborted!\n"); + + if (tcp_close(pcb) != ERR_OK) + { + tcp_abort(pcb); + return ERR_ABRT; + } + } +#if ASYNC_TCP_SSL_ENABLED + } +#endif + } + + if (tcp_close(pcb) != ERR_OK) + { + tcp_abort(pcb); + + return ERR_ABRT; + } + + return ERR_OK; +} + +err_t AsyncServer::_s_accept(void *arg, tcp_pcb* pcb, err_t err) +{ + return reinterpret_cast(arg)->_accept(pcb, err); +} + +#if ASYNC_TCP_SSL_ENABLED +err_t AsyncServer::_poll(tcp_pcb* pcb) +{ + if (!tcp_ssl_has_client() && _pending) + { + struct pending_pcb * p = _pending; + + if (p->pcb == pcb) + { + _pending = _pending->next; + } + else + { + while (p->next && p->next->pcb != pcb) + p = p->next; + + if (!p->next) + return 0; + + struct pending_pcb * b = p->next; + p->next = b->next; + p = b; + } + + ASYNC_TCP_DEBUG("AsyncServer::_s_accept: ### remove from wait: %d\n", _clients_waiting); + AsyncClient *c = new (std::nothrow) AsyncClient(pcb, _ssl_ctx); + + if (c) + { + c->onConnect([this](void * arg, AsyncClient * c) + { + _connect_cb(_connect_cb_arg, c); + }, this); + + if (p->pb) + c->_recv(pcb, p->pb, 0); + } + + // Should there be error handling for when "new AsynClient" fails?? + free(p); + } + return ERR_OK; +} + +err_t AsyncServer::_recv(struct tcp_pcb *pcb, struct pbuf *pb, err_t err) +{ + if (!_pending) + return ERR_OK; + + struct pending_pcb * p; + + if (!pb) + { + ASYNC_TCP_DEBUG("AsyncServer::_recv: ### close from wait: %d\n", _clients_waiting); + p = _pending; + + if (p->pcb == pcb) + { + _pending = _pending->next; + } + else + { + while (p->next && p->next->pcb != pcb) + p = p->next; + + if (!p->next) + return 0; + + struct pending_pcb * b = p->next; + p->next = b->next; + p = b; + } + + if (p->pb) + { + pbuf_free(p->pb); + } + + free(p); + size_t err = tcp_close(pcb); + + if (err != ERR_OK) + { + tcp_abort(pcb); + return ERR_ABRT; + } + } + else + { + ASYNC_TCP_DEBUG("AsyncServer::_recv: ### wait _recv: %u %d\n", pb->tot_len, _clients_waiting); + + p = _pending; + + while (p && p->pcb != pcb) + p = p->next; + + if (p) + { + if (p->pb) + { + pbuf_chain(p->pb, pb); + } + else + { + p->pb = pb; + } + } + } + + return ERR_OK; +} + +int AsyncServer::_cert(const char *filename, uint8_t **buf) +{ + if (_file_cb) + { + return _file_cb(_file_cb_arg, filename, buf); + } + + *buf = 0; + return 0; +} + +int AsyncServer::_s_cert(void *arg, const char *filename, uint8_t **buf) +{ + return reinterpret_cast(arg)->_cert(filename, buf); +} + +err_t AsyncServer::_s_poll(void *arg, struct tcp_pcb *pcb) +{ + return reinterpret_cast(arg)->_poll(pcb); +} + +err_t AsyncServer::_s_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, err_t err) +{ + return reinterpret_cast(arg)->_recv(pcb, pb, err); +} +#endif + +#endif // _TEENSY41_ASYNC_TCP_IMPL_H_ diff --git a/src/cbuf.hpp b/src/cbuf.hpp new file mode 100644 index 0000000..d0a0b4a --- /dev/null +++ b/src/cbuf.hpp @@ -0,0 +1,89 @@ +/**************************************************************************************************************************** + cbuf.hpp + + cbuf.hpp - Circular buffer implementation + Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_CBUF_HPP_ +#define _TEENSY41_ASYNC_TCP_CBUF_HPP_ + +#include +#include +#include + +class cbuf +{ + public: + cbuf(size_t size); + ~cbuf(); + + size_t resizeAdd(size_t addSize); + size_t resize(size_t newSize); + size_t available() const; + size_t size(); + + size_t room() const; + + inline bool empty() const + { + return _begin == _end; + } + + inline bool full() const + { + return wrap_if_bufend(_end + 1) == _begin; + } + + int peek(); + size_t peek(char *dst, size_t size); + + int read(); + size_t read(char* dst, size_t size); + + size_t write(char c); + size_t write(const char* src, size_t size); + + void flush(); + size_t remove(size_t size); + + cbuf *next; + + private: + inline char* wrap_if_bufend(char* ptr) const + { + return (ptr == _bufend) ? _buf : ptr; + } + + size_t _size; + char* _buf; + const char* _bufend; + char* _begin; + char* _end; + +}; + +#endif // _TEENSY41_ASYNC_TCP_CBUF_HPP_ diff --git a/src/cbuf_Impl.h b/src/cbuf_Impl.h new file mode 100644 index 0000000..a2f4836 --- /dev/null +++ b/src/cbuf_Impl.h @@ -0,0 +1,238 @@ +/**************************************************************************************************************************** + cbuf_Impl.h + + cbuf.cpp - Circular buffer implementation + Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + Teensy41_AsyncTCP is a library for Teensy4.1 using LwIP-based QNEthernet + + Based on and modified from : + + 1) ESPAsyncTCP (https://github.com/me-no-dev/ESPAsyncTCP) + 2) AsyncTCP (https://github.com/me-no-dev/AsyncTCP) + + Built by Khoi Hoang https://github.com/khoih-prog/Teensy41_AsyncTCP + + 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. + + Version: 1.0.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/03/2022 Initial coding to support only Teensy4.1 using QNEthernet + *****************************************************************************************************************************/ + +#pragma once + +#ifndef _TEENSY41_ASYNC_TCP_CBUF_IMPL_H_ +#define _TEENSY41_ASYNC_TCP_CBUF_IMPL_H_ + +#include "cbuf.hpp" + +cbuf::cbuf(size_t size) : next(NULL), _size(size), _buf(new char[size]), _bufend(_buf + size), _begin(_buf), _end(_begin) +{ +} + +cbuf::~cbuf() +{ + delete[] _buf; +} + +size_t cbuf::resizeAdd(size_t addSize) +{ + return resize(_size + addSize); +} + +size_t cbuf::resize(size_t newSize) +{ + + size_t bytes_available = available(); + + // not lose any data + // if data can be lost use remove or flush before resize + if ((newSize <= bytes_available) || (newSize == _size)) + { + return _size; + } + + char *newbuf = new char[newSize]; + char *oldbuf = _buf; + + if (!newbuf) + { + return _size; + } + + if (_buf) + { + read(newbuf, bytes_available); + memset((newbuf + bytes_available), 0x00, (newSize - bytes_available)); + } + + _begin = newbuf; + _end = newbuf + bytes_available; + _bufend = newbuf + newSize; + _size = newSize; + + _buf = newbuf; + + delete[] oldbuf; + + return _size; +} + +size_t cbuf::available() const +{ + if (_end >= _begin) + { + return _end - _begin; + } + + return _size - (_begin - _end); +} + +size_t cbuf::size() +{ + return _size; +} + +size_t cbuf::room() const +{ + if (_end >= _begin) + { + return _size - (_end - _begin) - 1; + } + + return _begin - _end - 1; +} + +int cbuf::peek() +{ + if (empty()) + return -1; + + return static_cast(*_begin); +} + +size_t cbuf::peek(char *dst, size_t size) +{ + size_t bytes_available = available(); + size_t size_to_read = (size < bytes_available) ? size : bytes_available; + size_t size_read = size_to_read; + char * begin = _begin; + + if (_end < _begin && size_to_read > (size_t) (_bufend - _begin)) + { + size_t top_size = _bufend - _begin; + memcpy(dst, _begin, top_size); + begin = _buf; + size_to_read -= top_size; + dst += top_size; + } + + memcpy(dst, begin, size_to_read); + + return size_read; +} + +int cbuf::read() +{ + if (empty()) + return -1; + + char result = *_begin; + _begin = wrap_if_bufend(_begin + 1); + + return static_cast(result); +} + +size_t cbuf::read(char* dst, size_t size) +{ + size_t bytes_available = available(); + size_t size_to_read = (size < bytes_available) ? size : bytes_available; + size_t size_read = size_to_read; + + if (_end < _begin && size_to_read > (size_t) (_bufend - _begin)) + { + size_t top_size = _bufend - _begin; + + memcpy(dst, _begin, top_size); + _begin = _buf; + size_to_read -= top_size; + dst += top_size; + } + + memcpy(dst, _begin, size_to_read); + _begin = wrap_if_bufend(_begin + size_to_read); + + return size_read; +} + +size_t cbuf::write(char c) +{ + if (full()) + return 0; + + *_end = c; + _end = wrap_if_bufend(_end + 1); + + return 1; +} + +size_t cbuf::write(const char* src, size_t size) +{ + size_t bytes_available = room(); + size_t size_to_write = (size < bytes_available) ? size : bytes_available; + size_t size_written = size_to_write; + + if (_end >= _begin && size_to_write > (size_t) (_bufend - _end)) + { + size_t top_size = _bufend - _end; + + memcpy(_end, src, top_size); + _end = _buf; + size_to_write -= top_size; + src += top_size; + } + + memcpy(_end, src, size_to_write); + _end = wrap_if_bufend(_end + size_to_write); + + return size_written; +} + +void cbuf::flush() +{ + _begin = _buf; + _end = _buf; +} + +size_t cbuf::remove(size_t size) +{ + size_t bytes_available = available(); + + if (size >= bytes_available) + { + flush(); + return 0; + } + + size_t size_to_remove = (size < bytes_available) ? size : bytes_available; + + if (_end < _begin && size_to_remove > (size_t) (_bufend - _begin)) + { + size_t top_size = _bufend - _begin; + _begin = _buf; + size_to_remove -= top_size; + } + + _begin = wrap_if_bufend(_begin + size_to_remove); + + return available(); +} + +#endif // _TEENSY41_ASYNC_TCP_CBUF_IMPL_H_