diff --git a/README.md b/README.md index 2c965a8..0f21f59 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ # macusbdb Jeroen/Spritesmods "macusbfb" LPC1343 firmware for Macintosh 9" CRT driver board +The code in these directories isn't the best I ever wrote, but at the moment +it works good enough for my own purposes. Use at your own risk! +Contents: + +adb2usb/ : Code for the ADB to USB converter +adb2usb/adb2uart : Code for the uC that receives ADB +adb2usb/uart2usb : Code for the uC that sends the data over the USB bus +macusbfb : Firmware for the LPC1343 that a.o. controls the Macintosh CRT + +A few notes about the shortcomings of the current code: +- macusbfb works just fine, but leaks memory when unloaded or the display +device is unplugged. As long as you plug in the device and load the module, +you should be fine though. +- The adb2usb device seems to drop adb replies every now and then, resulting +in e.g. a stuck key. I still need to figure out why. Until then, pressing +the key a second time should make it work again + +As always, if you fix or expand something, I'd love to get a patch. + +Jeroen/Sprite_tm diff --git a/adb2usb/LICENSE b/adb2usb/LICENSE new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/adb2usb/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/adb2usb/adb2uart/Makefile b/adb2usb/adb2uart/Makefile new file mode 100644 index 0000000..b96c00a --- /dev/null +++ b/adb2usb/adb2uart/Makefile @@ -0,0 +1,267 @@ +# Hey Emacs, this is a -*- makefile -*- + +# AVR-GCC Makefile template, derived from the WinAVR template (which +# is public domain), believed to be neutral to any flavor of "make" +# (GNU make, BSD make, SysV make) + + +MCU = attiny2313 +FORMAT = ihex +TARGET = adb2uart +SRC = main.c adb.c +DEPS= +ASRC = +OPT = s + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 + +# Place -D or -U options here +CDEFS = + +# Place -I options here +CINCS = + + +CDEBUG = -g$(DEBUG) +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-inline-small-functions +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) +CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) $(CTUNING) + + +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs + + +#Additional libraries. + +# Minimalistic printf version +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min + +# Floating point printf version (requires MATH_LIB = -lm below) +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt + +#PRINTF_LIB = $(PRINTF_LIB_MIN) + +# Minimalistic scanf version +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min + +# Floating point + %[ scanf version (requires MATH_LIB = -lm below) +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt + +SCANF_LIB = + +#MATH_LIB = -lm + +# External memory options + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# used for variables (.data/.bss) and heap (malloc()). +#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# only used for heap (malloc()). +#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff + +EXTMEMOPTS = + +#LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref +LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) + + +# Programming support using avrdude. Settings and variables. + +#AVRDUDE_PROGRAMMER = bsd +AVRDUDE_PROGRAMMER = usbasp +AVRDUDE_PORT = /dev/parport0 + +AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep + + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +#AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level. Please use this when submitting bug +# reports about avrdude. See +# to submit bug reports. +#AVRDUDE_VERBOSE = -v -v + +AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER) -E noreset,vcc + + +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +MV = mv -f + +# Define all object files. +OBJ = $(DEPS) $(SRC:.c=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: build + +build: elf hex eep + +elf: $(TARGET).elf +hex: $(TARGET).hex +eep: $(TARGET).eep +lss: $(TARGET).lss +sym: $(TARGET).sym + + +# Program the device. +program: $(TARGET).hex $(TARGET).eep + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + +fw.h: firmware.bin + bin2c fw < firmware.bin > fw.h + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: $(TARGET).elf + $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof + + +extcoff: $(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + + +# Link: create ELF output file from object files. +$(TARGET).elf: $(OBJ) + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + + +# Compile: create object files from C source files. +.c.o: + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +# Target: clean project. +clean: + $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \ + $(TARGET).map $(TARGET).sym $(TARGET).lss \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) + + +.PHONY: all build elf hex eep lss sym program coff extcoff clean depend + + +# DO NOT DELETE THIS LINE -- make depend depends on it. +main.o: main.c /usr/lib/gcc/avr/4.3.4/../../../avr/include/util/delay.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/inttypes.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/stdint.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/util/delay_basic.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/io.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/sfr_defs.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/iotn2313.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/portpins.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/common.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/version.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/fuse.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/lock.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/interrupt.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/stdio.h \ + /usr/lib/gcc/avr/4.3.4/include/stdarg.h \ + /usr/lib/gcc/avr/4.3.4/include/stddef.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/pgmspace.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/string.h adb.h \ + scanadb2usb.h +adb.o: adb.c /usr/lib/gcc/avr/4.3.4/../../../avr/include/util/delay.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/inttypes.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/stdint.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/util/delay_basic.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/io.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/sfr_defs.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/iotn2313.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/portpins.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/common.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/version.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/fuse.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/lock.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/interrupt.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/stdio.h \ + /usr/lib/gcc/avr/4.3.4/include/stdarg.h \ + /usr/lib/gcc/avr/4.3.4/include/stddef.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/avr/pgmspace.h \ + /usr/lib/gcc/avr/4.3.4/../../../avr/include/string.h adb.h diff --git a/adb2usb/adb2uart/adb.c b/adb2usb/adb2uart/adb.c new file mode 100644 index 0000000..6d808b9 --- /dev/null +++ b/adb2usb/adb2uart/adb.c @@ -0,0 +1,153 @@ +/* +ADB to USB-converter, for a non-extended keyboard and a mouse +Copyright (C) 2010 Jeroen Domburg + +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 . +*/ +#define F_CPU 12000000 +#include +#include +#include +#include +#include +#include +#include "adb.h" + + +#define ADB_H() DDRB&=~(1<0) { + x--; + _delay_us(1); + } + if (x==0) return 0; + + //Delay for the low time of the start bit + _delay_us(40); + //Should be high again... + if (!ADBVAL) return 0; + //Wait till the line goes low again for the 1st databit. + while(ADBVAL && x>0) { + x--; + _delay_us(1); + } + if (x==0) return 0; + //Ok, all good. + return 1; +} + +static char adbGetBit(void) { + char res=0; + int x; +// DDRD|=(1<<3); +// PIND=(1<<3); + _delay_us(50); +// PIND=(1<<3); + if (ADBVAL) res=1; + x=80; + while(!ADBVAL && x>0) { + _delay_us(1); + x--; + } + while(ADBVAL && x>0) { + _delay_us(1); + x--; + } + if (x==0) return -1; + return res; +} + +static unsigned char adbGetByte(void) { + unsigned char ret, b, x; + for (x=0; x<8; x++) { + ret<<=1; + b=adbGetBit(); + if (b==-1) return 0xff; + if (b==1) ret|=1; + } + return ret; +} + + +int adbCommand(unsigned char cmd, unsigned char *data, int size) { + int x; + adbAttnSync(); + adbSendByte(cmd); + adbSendTlt(); + if (cmd&C_TALK) { + //Device writes data + if (!adbWaitStart()) return -1; + for (x=0; x, or by paper mail: + * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic + */ + + +struct scancode_list { + unsigned char xt; + unsigned char at2; + unsigned char at3; + unsigned char sun; + unsigned char usb; + unsigned char adb; + unsigned char code; +}; + +/* + * The base set common to all keyboards - the XT keyboard. + */ + +static struct scancode_list scancodes[] = { + + {0x01, 0x76, 0x08, 0x1d, 0x29, 0x35, 1}, /* Esc */ + {0x02, 0x16, 0x16, 0x1e, 0x1e, 0x12, 2}, /* 1 ! */ + {0x03, 0x1e, 0x1e, 0x1f, 0x1f, 0x13, 3}, /* 2 @ */ + {0x04, 0x26, 0x26, 0x20, 0x20, 0x14, 4}, /* 3 # */ + {0x05, 0x25, 0x25, 0x21, 0x21, 0x15, 5}, /* 4 $ */ + {0x06, 0x2e, 0x2e, 0x22, 0x22, 0x17, 6}, /* 5 % */ + {0x07, 0x36, 0x36, 0x23, 0x23, 0x16, 7}, /* 6 ^ */ + {0x08, 0x3d, 0x3d, 0x24, 0x24, 0x1a, 8}, /* 7 & */ + {0x09, 0x3e, 0x3e, 0x25, 0x25, 0x1c, 9}, /* 8 * */ + {0x0a, 0x46, 0x46, 0x26, 0x26, 0x19, 10}, /* 9 ( */ + {0x0b, 0x45, 0x45, 0x27, 0x27, 0x1d, 11}, /* 0 ) */ + {0x0c, 0x4e, 0x4e, 0x28, 0x2d, 0x1b, 12}, /* - _ */ + {0x0d, 0x55, 0x55, 0x29, 0x2e, 0x18, 13}, /* = + */ + {0x0e, 0x66, 0x66, 0x2b, 0x2a, 0x33, 14}, /* Backspace */ + {0x0f, 0x0d, 0x0d, 0x35, 0x2b, 0x30, 15}, /* Tab */ + {0x10, 0x15, 0x15, 0x36, 0x14, 0x0c, 16}, /* Q */ + {0x11, 0x1d, 0x1d, 0x37, 0x1a, 0x0d, 17}, /* W */ + {0x12, 0x24, 0x24, 0x38, 0x08, 0x0e, 18}, /* E */ + {0x13, 0x2d, 0x2d, 0x39, 0x15, 0x0f, 19}, /* R */ + {0x14, 0x2c, 0x2c, 0x3a, 0x17, 0x11, 20}, /* T */ + {0x15, 0x35, 0x35, 0x3b, 0x1c, 0x10, 21}, /* Y */ + {0x16, 0x3c, 0x3c, 0x3c, 0x18, 0x20, 22}, /* U */ + {0x17, 0x43, 0x43, 0x3d, 0x0c, 0x22, 23}, /* I */ + {0x18, 0x44, 0x44, 0x3e, 0x12, 0x1f, 24}, /* O */ + {0x19, 0x4d, 0x4d, 0x3f, 0x13, 0x23, 25}, /* P */ + {0x1a, 0x54, 0x54, 0x40, 0x2f, 0x21, 26}, /* [ { */ + {0x1b, 0x5b, 0x5b, 0x41, 0x30, 0x1e, 27}, /* ] } */ + {0x1c, 0x5a, 0x5a, 0x59, 0x28, 0x24, 28}, /* Enter */ + {0x1d, 0x14, 0x11, 0x4c, 0xe0, 0x36, 29}, /* Left Control */ + {0x1e, 0x1c, 0x1c, 0x4d, 0x04, 0x00, 30}, /* A */ + {0x1f, 0x1b, 0x1b, 0x4e, 0x16, 0x01, 31}, /* S */ + {0x20, 0x23, 0x23, 0x4f, 0x07, 0x02, 32}, /* D */ + {0x21, 0x2b, 0x2b, 0x50, 0x09, 0x03, 33}, /* F */ + {0x22, 0x34, 0x34, 0x51, 0x0a, 0x05, 34}, /* G */ + {0x23, 0x33, 0x33, 0x52, 0x0b, 0x04, 35}, /* H */ + {0x24, 0x3b, 0x3b, 0x53, 0x0d, 0x26, 36}, /* J */ + {0x25, 0x42, 0x42, 0x54, 0x0e, 0x28, 37}, /* K */ + {0x26, 0x4b, 0x4b, 0x55, 0x0f, 0x25, 38}, /* L */ + {0x27, 0x4c, 0x4c, 0x56, 0x33, 0x29, 39}, /* ; : */ + {0x28, 0x52, 0x52, 0x57, 0x34, 0x27, 40}, /* ' " */ + {0x29, 0x0e, 0x0e, 0x2a, 0x35, 0x32, 41}, /* ` ~ */ + {0x2a, 0x12, 0x12, 0x63, 0xe1, 0x38, 42}, /* Left Shift */ + {0x2b, 0x5d, 0x5c, 0x58, 0x31, 0x2a, 43}, /* \ | */ + { 0, 0, 0x53, 0, 0, 0, 43}, /* \ | */ + { 0, 0, 0x5d, 0, 0, 0, 43}, /* \ | */ + {0x2c, 0x1a, 0x1a, 0x64, 0x1d, 0x06, 44}, /* Z */ + {0x2d, 0x22, 0x22, 0x65, 0x1b, 0x07, 45}, /* X */ + {0x2e, 0x21, 0x21, 0x66, 0x06, 0x08, 46}, /* C */ + {0x2f, 0x2a, 0x2a, 0x67, 0x19, 0x09, 47}, /* V */ + {0x30, 0x32, 0x32, 0x68, 0x05, 0x0b, 48}, /* B */ + {0x31, 0x31, 0x31, 0x69, 0x11, 0x2d, 49}, /* N */ + {0x32, 0x3a, 0x3a, 0x6a, 0x10, 0x2e, 50}, /* M */ + {0x33, 0x41, 0x41, 0x6b, 0x36, 0x2b, 51}, /* , < */ + {0x34, 0x49, 0x49, 0x6c, 0x37, 0x2f, 52}, /* . > */ + {0x35, 0x4a, 0x4a, 0x6d, 0x38, 0x2c, 53}, /* / ? */ + {0x36, 0x59, 0x59, 0x6e, 0xe5, 0x7b, 54}, /* Right Shift */ + {0x37, 0x7c, 0x7e, 0x2f, 0x55, 0x43, 55}, /* KP * */ + {0x38, 0x11, 0x19, 0x13, 0xe2, 0x37, 56}, /* Left Alt */ + {0x39, 0x29, 0x29, 0x79, 0x2c, 0x31, 57}, /* Space */ + {0x3a, 0x58, 0x14, 0x77, 0x39, 0x39, 58}, /* Caps Lock */ + {0x3b, 0x05, 0x07, 0x05, 0x3a, 0x7a, 59}, /* F1 */ + {0x3c, 0x06, 0x0f, 0x06, 0x3b, 0x78, 60}, /* F2 */ + {0x3d, 0x04, 0x17, 0x08, 0x3c, 0x63, 61}, /* F3 */ + {0x3e, 0x0c, 0x1f, 0x0a, 0x3d, 0x76, 62}, /* F4 */ + {0x3f, 0x03, 0x27, 0x0c, 0x3e, 0x60, 63}, /* F5 */ + {0x40, 0x0b, 0x2f, 0x0e, 0x3f, 0x61, 64}, /* F6 */ + {0x41, 0x02, 0x37, 0x10, 0x40, 0x62, 65}, /* F7 */ + {0x42, 0x0a, 0x3f, 0x11, 0x41, 0x64, 66}, /* F8 */ + {0x43, 0x01, 0x47, 0x12, 0x42, 0x65, 67}, /* F9 */ + {0x44, 0x09, 0x4f, 0x07, 0x43, 0x6d, 68}, /* F10 */ + {0x45, 0x77, 0x76, 0x62, 0x53, 0x47, 69}, /* Num Lock */ + {0x46, 0x7e, 0x5f, 0x17, 0x47, 0x6b, 70}, /* Scroll Lock Break */ + {0x47, 0x6c, 0x6c, 0x44, 0x5f, 0x59, 71}, /* KP Home 7 */ + {0x48, 0x75, 0x75, 0x45, 0x60, 0x5b, 72}, /* KP Up 8 */ + {0x49, 0x7d, 0x7d, 0x46, 0x61, 0x5c, 73}, /* KP PgUp 9 */ + {0x4a, 0x7b, 0x84, 0x47, 0x56, 0x4e, 74}, /* KP - */ + {0x4b, 0x6b, 0x6b, 0x5b, 0x5c, 0x56, 75}, /* KP Left 4 */ + {0x4c, 0x73, 0x73, 0x5c, 0x5d, 0x57, 76}, /* KP 5 */ + {0x4d, 0x74, 0x74, 0x5d, 0x5e, 0x58, 77}, /* KP Right 6 */ + {0x4e, 0x79, 0x7c, 0x7d, 0x57, 0x45, 78}, /* KP + */ + {0x4f, 0x69, 0x69, 0x70, 0x59, 0x53, 79}, /* KP End 1 */ + {0x50, 0x72, 0x72, 0x71, 0x5a, 0x54, 80}, /* KP Down 2 */ + {0x51, 0x7a, 0x7a, 0x72, 0x5b, 0x55, 81}, /* KP PgDn 3 */ + {0x52, 0x70, 0x70, 0x5e, 0x62, 0x52, 82}, /* KP Ins 0 */ + {0x53, 0x71, 0x71, 0x32, 0x63, 0x41, 83}, /* KP Del . */ + +/* + * The most common extensions to the base. + */ + + { 0, 0x78, 0x56, 0x09, 0x44, 0x67, 87}, /* F11 */ + { 0, 0x07, 0x5e, 0x0b, 0x45, 0x6f, 88}, /* F12 */ + { 0, 0xda, 0x79, 0x5a, 0x58, 0x4c, 96}, /* KP Enter */ + { 0, 0xca, 0x77, 0x2e, 0x54, 0x4b, 98}, /* KP / */ + { 0, 0x91, 0x39, 0x0d, 0xe6, 0x7c, 100}, /* Right Alt (Graph) */ + { 0, 0, 0x58, 0, 0, 0, 100}, /* Alt Graph - Sun PS/2 Type 5 */ + { 0, 0xf1, 0x64, 0x42, 0x4c, 0x75, 111}, /* Delete */ + { 0, 0xfe, 0x62, 0x15, 0x48, 0x71, 119}, /* Pause Break */ + { 0, 0xf7, 0, 0, 0, 0, 119}, /* Alternate Pause Break */ + +/* + * The separate navigation keys + */ + + { 0, 0xec, 0x6e, 0x34, 0x4a, 0x73, 102}, /* Home */ + { 0, 0xf5, 0x63, 0x14, 0x52, 0x3e, 103}, /* Up */ + { 0, 0xfd, 0x6f, 0x60, 0x4b, 0x74, 104}, /* Page Up */ + { 0, 0xeb, 0x61, 0x18, 0x50, 0x3b, 105}, /* Left */ + { 0, 0xf4, 0x6a, 0x1c, 0x4f, 0x3c, 106}, /* Right */ + { 0, 0xe9, 0x65, 0x4a, 0x4d, 0x77, 107}, /* End */ + { 0, 0xf2, 0x60, 0x1b, 0x51, 0x3d, 108}, /* Down */ + { 0, 0xfa, 0x6d, 0x7b, 0x4e, 0x79, 109}, /* Page Down */ + { 0, 0xf0, 0x67, 0x2c, 0x49, 0x72, 110}, /* Insert */ + +/* + * The OS keys + */ + + { 0, 0x9f, 0x8b, 0x78, 0xe3, 0, 125}, /* Left Meta (Win, Apple, Amiga) */ + { 0, 0xa7, 0x8c, 0x7a, 0xe7, 0, 126}, /* Right Meta (Win, Apple, Amiga) */ + { 0, 0xaf, 0x8d, 0x43, 0x65, 0, 127}, /* Compose (Application) */ + +/* + * OS keys on a NCD PS/2 Sun keyboard + */ + + { 0, 0, 0x40, 0, 0, 0, 125}, /* Left Meta (Win, Apple, Amiga) */ + { 0, 0, 0x48, 0, 0, 0, 126}, /* Right Meta (Win, Apple, Amiga) */ + { 0, 0, 0x39, 0, 0, 0, 127}, /* Compose (Application) */ + +/* + * PrintScreen + */ + + { 0, 0xfc, 0x57, 0x16, 0x46, 0, 99}, /* PrintScreen SysRq */ + +/* + * Right Ctrl + */ + + { 0, 0x94, 0x58, 0, 0xe4, 0x7d, 97}, /* Right Ctrl */ + +/* + * The European 102nd key + */ + + { 0, 0x61, 0x13, 0, 0x64, 0, 86}, /* the 102nd key */ + +/* + * Sun function keys + */ + + { 0, 0, 0x0a, 0x01, 0x78, 0, 128}, /* Stop */ + { 0, 0, 0x0b, 0x03, 0x79, 0, 129}, /* Again */ + { 0, 0, 0x0c, 0x19, 0, 0, 130}, /* Props */ + { 0, 0, 0x10, 0x1a, 0x7a, 0, 131}, /* Undo */ + { 0, 0, 0x13, 0x31, 0, 0, 132}, /* Front */ + { 0, 0, 0x18, 0x33, 0x7c, 0, 133}, /* Copy */ + { 0, 0, 0x20, 0x48, 0, 0, 134}, /* Open */ + { 0, 0, 0x28, 0x49, 0x7d, 0, 135}, /* Paste */ + { 0, 0, 0x30, 0x5f, 0x7e, 0, 136}, /* Find */ + { 0, 0, 0x38, 0x61, 0x7b, 0, 137}, /* Cut */ + { 0, 0, 0x09, 0x76, 0x75, 0, 138}, /* Help */ + + +/* + * Line Feed found on Sun Type 4 keyboard + */ + + { 0, 0, 0, 0x6f, 0, 0, 101}, /* Line Feed */ + +/* + * AT Enhanced keyboard in XT mode + */ + + {0x57, 0, 0, 0, 0, 0, 87}, /* F11 */ + {0x58, 0, 0, 0, 0, 0, 88}, /* F12 */ + +/* + * PP-06 keyboard extension keys + */ + + {0x65, 0, 0, 0, 0, 0, 87}, /* F11 */ + {0x66, 0, 0, 0, 0, 0, 88}, /* F12 */ + {0x6b, 0, 0, 0, 0, 0, 110}, /* Insert */ + {0x6c, 0, 0, 0, 0, 0, 111}, /* Delete */ + {0x6d, 0, 0, 0, 0, 0, 103}, /* Up */ + {0x6e, 0, 0, 0, 0, 0, 108}, /* Down */ + {0x6f, 0, 0, 0, 0, 0, 105}, /* Left */ + {0x70, 0, 0, 0, 0, 0, 106}, /* Right */ + +/* + * F13-F24, for USB and Focus 9000 + */ + + { 0, 0x60, 0, 0, 0x68, 0, 85}, /* F13 (PF1) */ + { 0, 0x51, 0, 0, 0x69, 0, 89}, /* F14 (PF2) */ + { 0, 0x62, 0, 0, 0x6a, 0, 90}, /* F15 (PF3) */ + { 0, 0x63, 0, 0, 0x6b, 0, 91}, /* F16 (PF4) */ + { 0, 0x64, 0, 0, 0x6c, 0, 92}, /* F17 (PF5) */ + { 0, 0x65, 0, 0, 0x6d, 0, 93}, /* F18 (PF6) */ + { 0, 0x67, 0, 0, 0x6e, 0, 94}, /* F19 (PF7) */ + { 0, 0x68, 0, 0, 0x6f, 0, 95}, /* F20 (PF8) */ + { 0, 0x53, 0, 0, 0x70, 0, 120}, /* F21 (PF9) */ + { 0, 0x6d, 0, 0, 0x71, 0, 121}, /* F22 (PF10) */ + { 0, 0x50, 0, 0, 0x72, 0, 122}, /* F23 (PF11) */ + { 0, 0x6f, 0, 0, 0x73, 0, 123}, /* F24 (PF12) */ + +/* + * F13-F17 for DEC LK450 + */ + + { 0, 0x84, 0, 0, 0, 0, 85}, /* F13 */ + { 0, 0x8c, 0, 0, 0, 0, 89}, /* F14 */ + { 0, 0x83, 0, 0, 0, 0, 90}, /* F15 */ + { 0, 0x8b, 0, 0, 0, 0, 91}, /* F16 */ + { 0, 0x82, 0, 0, 0, 0, 92}, /* F17 */ + +/* + * A1-A4 for RC930 + */ + + { 0, 0x0f, 0, 0, 0, 0, 85}, /* A1 */ + { 0, 0x17, 0, 0, 0, 0, 89}, /* A2 */ + { 0, 0x1f, 0, 0, 0, 0, 90}, /* A3 */ + { 0, 0x27, 0, 0, 0, 0, 91}, /* A4 */ + +/* + * Unlabeled keys on the NCD Sun PS/2 keyboard + */ + + { 0, 0, 0x7f, 0, 0, 0, 85}, /* U1 */ + { 0, 0, 0x80, 0, 0, 0, 89}, /* U2 */ + { 0, 0, 0x81, 0, 0, 0, 90}, /* U3 */ + { 0, 0, 0x82, 0, 0, 0, 91}, /* U4 */ + { 0, 0, 0x83, 0, 0, 0, 92}, /* U5 */ + +/* + * Macro key on BTC and other keyboards + */ + + { 0, 0xef, 0, 0, 0, 0, 112}, /* BTC Macro key */ + +/* + * Logitech key on Logitech NewTouch + */ + + { 0, 0xa8, 0x8e, 0, 0, 0, 112}, /* Logitech key */ + +/* + * Omni key on NorthGate and Lueck keyboards + */ + + { 0, 0xf3, 0, 0, 0, 0, 112}, /* NorthGate / Lueck Omni */ + +/* + * Sound (NCD Sun PS/2 + Sun Type 5 keyboard) + */ + + { 0, 0, 0x50, 0x2d, 0x7f, 0, 113}, /* Mute */ + { 0, 0, 0x51, 0x02, 0x81, 0, 114}, /* Volume Down */ + { 0, 0, 0x53, 0x04, 0x80, 0, 115}, /* Volume Up */ + +/* + * Sound (BTC Ez multimedia keyboard) + */ + + { 0, 0xcb, 0x9c, 0, 0, 0, 113}, /* Mute */ + { 0, 0xc2, 0x9d, 0, 0, 0, 114}, /* Volume Down */ + { 0, 0x9c, 0x95, 0, 0, 0, 115}, /* Volume Up */ + +/* + * BTC Ez Function keys + */ + + { 0, 0xbb, 0x94, 0, 0, 0, 165}, /* Previous song */ + { 0, 0xab, 0x99, 0, 0, 0, 164}, /* Play/Pause */ + { 0, 0xc3, 0x98, 0, 0, 0, 166}, /* Stop */ + { 0, 0xb4, 0x93, 0, 0, 0, 163}, /* Next song */ + { 0, 0xba, 0x97, 0, 0, 0, 161}, /* Eject */ + { 0, 0xb3, 0x9a, 0, 0, 0, 160}, /* Close */ + { 0, 0xb1, 0x9e, 0, 0, 0, 167}, /* Record */ + { 0, 0xc4, 0x9f, 0, 0, 0, 168}, /* Rewind */ + { 0, 0xb2, 0x91, 0, 0, 0, 139}, /* Menu */ + { 0, 0x9b, 0xa3, 0, 0, 0, 140}, /* Calc */ + { 0, 0xad, 0xa2, 0, 0, 0, 147}, /* X-fer */ + { 0, 0xa1, 0x92, 0, 0, 0, 150}, /* WWW */ + { 0, 0xa3, 0x9b, 0, 0, 0, 154}, /* Cycle Windows */ + { 0, 0xa4, 0x96, 0, 0, 0, 152}, /* Coffee */ + { 0, 0xcd, 0xa0, 0, 0, 0, 148}, /* Prog 1 */ + { 0, 0x95, 0xa1, 0, 0, 0, 149}, /* Prog 2 */ + +/* + * NCD Sun PS/2 Setup key + */ + + { 0, 0, 0x5d, 0, 0, 0, 141}, /* Setup */ + +/* + * The power key (AP PFT keyboard) + */ + + { 0, 0xb7, 0, 0x30, 0x66, 0x7f, 116}, /* Power */ + +/* + * The power management keys (AP PFT keyboard) + */ + + { 0, 0xbf, 0, 0, 0, 0, 142}, /* Sleep */ + { 0, 0xde, 0, 0, 0, 0, 143}, /* WakeUp */ + +/* + * Turbo-Xwing function keys. + */ + + { 0, 0xe2, 0, 0, 0, 0, 116}, /* WWW / Power */ + { 0, 0xb3, 0, 0, 0, 0, 176}, /* Sleep */ + { 0, 0xe4, 0, 0, 0, 0, 143}, /* Joystick / Wake */ + { 0, 0xd7, 0, 0, 0, 0, 140}, /* Calc */ + { 0, 0x8c, 0, 0, 0, 0, 101}, /* Line Feed */ + { 0, 0x86, 0, 0, 0, 0, 137}, /* Cut */ + { 0, 0xe7, 0, 0, 0, 0, 133}, /* Copy */ + { 0, 0xb4, 0, 0, 0, 0, 135}, /* Paste */ + { 0, 0xcf, 0, 0, 0, 0, 138}, /* Help */ + { 0, 0x8d, 0, 0, 0, 0, 144}, /* File */ + { 0, 0xab, 0, 0, 0, 0, 145}, /* Send File */ + { 0, 0xc0, 0, 0, 0, 0, 146}, /* Delete File */ + { 0, 0xa6, 0, 0, 0, 0, 151}, /* MS DOS */ + { 0, 0xd6, 0, 0, 0, 0, 153}, /* Direction */ + { 0, 0xa9, 0, 0, 0, 0, 166}, /* Stop */ + { 0, 0x95, 0, 0, 0, 0, 165}, /* Prev Song */ + { 0, 0xbb, 0, 0, 0, 0, 113}, /* Mute */ + { 0, 0xa5, 0, 0, 0, 0, 163}, /* Next Song */ + { 0, 0x96, 0, 0, 0, 0, 164}, /* Play / Pause */ + { 0, 0x82, 0, 0, 0, 0, 162}, /* Eject / Close */ + { 0, 0x84, 0, 0, 0, 0, 115}, /* Volume Up */ + { 0, 0x83, 0, 0, 0, 0, 114}, /* Volume Down */ + +/* + * KeyPad equal, found on Sun Type 4 and Mac keyboards + */ + + { 0, 0, 0, 0x2d, 0x67, 0x51, 117}, /* KP = */ + +/* + * KeyPad plusminus, found on DEC LK450 + */ + + { 0, 0xf9, 0, 0, 0, 0, 118}, /* DEC LK450 KP +- */ + +/* + * Japan alphabet switch key + */ + + { 0, 0x68, 0, 0, 0x87, 0, 124}, /* The Jpn key - clashes with Focus PF8 */ + { 0, 0, 0, 0, 0, 0, 0}}; + diff --git a/adb2usb/adb2uart/exsc/test.c b/adb2usb/adb2uart/exsc/test.c new file mode 100644 index 0000000..eb5572e --- /dev/null +++ b/adb2usb/adb2uart/exsc/test.c @@ -0,0 +1,10 @@ +#include + +#include "scancodes.h" + +int main() { + int x; + for (x=0; x<128; x++) { + printf("\t\t{%i, %i},\n", scancodes[x].adb, scancodes[x].usb); + } +} \ No newline at end of file diff --git a/adb2usb/adb2uart/main.c b/adb2usb/adb2uart/main.c new file mode 100644 index 0000000..0e5df63 --- /dev/null +++ b/adb2usb/adb2uart/main.c @@ -0,0 +1,121 @@ +/* +ADB to USB-converter, for a non-extended keyboard and a mouse +Copyright (C) 2010 Jeroen Domburg + +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 . +*/ +#define F_CPU 12000000 +#include +#include +#include +#include +#include +#include +#include "adb.h" + +#include "scanadb2usb.h" + + +#define UDR0 UDR +#define UCSR0A UCSRA +#define UCSR0B UCSRB +#define UCSR0C UCSRC +#define UBRR0L UBRRL +#define UBRR0H UBRRH + + +void sendchar(char c) { + while(!(UCSR0A&(1<<5))) ; + UDR0=c; +} + +//Main routine +int main(void) { + unsigned char data[8]; + unsigned char keys[4]={0,0,0,0}; + unsigned char modFlags=0; + int ret; + int x; +// stdoutInit(39); //1228800MHz -> 19200 baud + UCSR0B=0x18; + UBRR0L=39; + UBRR0H=0; +// sei(); +// printf_P(PSTR("PWRON\n")); + PORTD&=~(1<0) { + char n; + sendchar('M'); + sendchar((data[0]&0x80)?0:1); + n=data[1]&0x7f; if (data[1]&0x40) n+=128; + sendchar(n); + n=data[0]&0x7f; if (data[0]&0x40) n+=128; + sendchar(n); +// printf("Mouse: %i %i, but=%i\n", data[0]&0x7f, data[1]&0x7f, (data[0]&0x80)?0:1); +// printf("Mouse: %x %x %x %x\n", data[0], data[1], data[2], data[3]); + } + ret=adbCommand((2<<4)|C_TALK|REG_0, data, 2); + if (ret>0) { + int x=0; + char mask=0; + unsigned char usbkey; + unsigned int key=data[0]&0x7F; + char press=data[0]&0x80; + if (key==0x7F) key=(data[1]&0x7f)+0x80; +// printf("Keyboard: key %3x %s.\n", key, press?"released":"pressed"); + while(pgm_read_byte(&scanadb2usb[x].usb)!=0) { + if (pgm_read_byte(&scanadb2usb[x].adb)==key) usbkey=pgm_read_byte(&scanadb2usb[x].usb); + x++; + } + x=0; + + //Check meta keys + mask=0; + if (key==0x36) mask=0x01; + if (key==0x38) mask=0x02; + if (key==0x37) mask=0x04; + if (key==0x7d) mask=0x10; + if (key==0x7b) mask=0x20; + + if (!mask) { + if (!press) { + while (x!=4 && keys[x]!=0) x++; + if (x!=4) keys[x]=usbkey; + } else { + for (x=0; x<4; x++) { + if (keys[x]==usbkey) keys[x]=0; + } + } + } else { + if (!press) { + modFlags|=mask; + } else { + modFlags&=~mask; + } + } + sendchar('K'); + sendchar(modFlags); + sendchar(keys[0]); + sendchar(keys[1]); + sendchar(keys[2]); + sendchar(keys[3]); + } + _delay_ms(9); + } +} diff --git a/adb2usb/adb2uart/notes.txt b/adb2usb/adb2uart/notes.txt new file mode 100644 index 0000000..73ab8a1 --- /dev/null +++ b/adb2usb/adb2uart/notes.txt @@ -0,0 +1,2 @@ +http://developer.apple.com/legacy/mac/library/technotes/hw/hw_01.html +http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011984 diff --git a/adb2usb/adb2uart/scanadb2usb.h b/adb2usb/adb2uart/scanadb2usb.h new file mode 100644 index 0000000..31b5478 --- /dev/null +++ b/adb2usb/adb2uart/scanadb2usb.h @@ -0,0 +1,110 @@ +struct scanadb2usb_t { + unsigned char adb; + unsigned char usb; +}; +//ADB to USB scancode table, generated (partially) by the tool in the +//exsc-dir +struct scanadb2usb_t scanadb2usb[] PROGMEM = { + {53, 41}, + {18, 30}, + {19, 31}, + {20, 32}, + {21, 33}, + {23, 34}, + {22, 35}, + {26, 36}, + {28, 37}, + {25, 38}, + {29, 39}, + {27, 45}, + {24, 46}, + {51, 42}, + {48, 43}, + {12, 20}, + {13, 26}, + {14, 8}, + {15, 21}, + {17, 23}, + {16, 28}, + {32, 24}, + {34, 12}, + {31, 18}, + {35, 19}, + {33, 47}, + {30, 48}, + {36, 40}, +// {54, 224}, + {0, 4}, + {1, 22}, + {2, 7}, + {3, 9}, + {5, 10}, + {4, 11}, + {38, 13}, + {40, 14}, + {37, 15}, + {41, 51}, + {39, 52}, + {50, 53}, +// {56, 225}, + {42, 49}, + {6, 29}, + {7, 27}, + {8, 6}, + {9, 25}, + {11, 5}, + {45, 17}, + {46, 16}, + {43, 54}, + {47, 55}, + {44, 56}, +// {123, 229}, + {67, 85}, + {55, 226}, + {49, 44}, + {57, 57}, + {122, 58}, + {120, 59}, + {99, 60}, + {118, 61}, + {96, 62}, + {97, 63}, + {98, 64}, + {100, 65}, + {101, 66}, + {109, 67}, + {71, 83}, + {107, 71}, + {89, 95}, + {91, 96}, + {92, 97}, + {78, 86}, + {86, 92}, + {87, 93}, + {88, 94}, + {69, 87}, + {83, 89}, + {84, 90}, + {85, 91}, + {82, 98}, + {65, 99}, + {103, 68}, + {111, 69}, + {76, 88}, + {75, 84}, +// {124, 230}, + {117, 76}, + {113, 72}, + {115, 74}, + {62, 82}, + {116, 75}, + {59, 80}, + {60, 79}, + {119, 77}, + {61, 81}, + {121, 78}, + {114, 73}, +// {125, 228}, + {255, 116}, //power key + {0,0} +}; diff --git a/adb2usb/uart2usb/Makefile b/adb2usb/uart2usb/Makefile new file mode 100644 index 0000000..7c6959b --- /dev/null +++ b/adb2usb/uart2usb/Makefile @@ -0,0 +1,171 @@ +# Name: Makefile +# Project: hid-mouse example +# Author: Christian Starkjohann +# Creation Date: 2008-04-07 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + +DEVICE = attiny2313 +F_CPU = 12000000 # in Hz +# see below for fuse values for particular devices +FUSE_L = 0xce +FUSE_H = 0xdf +AVRDUDE = avrdude -c usbasp -p $(DEVICE) -P bla # edit this line for your programmer + +#Shitload of C-flags to cram all of this into the 2K AVR :X +CFLAGS = -Ivusb/usbdrv -I. -DDEBUG_LEVEL=0 \ + -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \ + -ffunction-sections -fdata-sections -ffreestanding -Wl,--gc-sections \ + -Wl,--relax -fno-tree-scev-cprop -fno-split-wide-types +# --param inline-call-cost=2 -finline-limit=3 -fno-inline-small-functions +OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o + +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) + +############################################################################## +# Fuse values for particular devices +############################################################################## +# If your device is not listed here, go to +# http://palmavr.sourceforge.net/cgi-bin/fc.cgi +# and choose options for external crystal clock and no clock divider +# +################################## ATMega8 ################################## +# ATMega8 FUSE_L (Fuse low byte): +# 0x9f = 1 0 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ BODEN (BrownOut Detector enabled) +# +-------------------- BODLEVEL (2.7V) +# ATMega8 FUSE_H (Fuse high byte): +# 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) +# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 +# | | | | | +-------- BOOTSZ1 +# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) +# | | | +-------------- CKOPT (full output swing) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ WDTON (WDT not always on) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATMega48/88/168 ############################## +# ATMega*8 FUSE_L (Fuse low byte): +# 0xdf = 1 1 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ CKOUT (if 0: Clock output enabled) +# +-------------------- CKDIV8 (if 0: divide by 8) +# ATMega*8 FUSE_H (Fuse high byte): +# 0xde = 1 1 0 1 1 1 1 0 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V) +# | | | | + --------- EESAVE (preserve EEPROM over chip erase) +# | | | +-------------- WDTON (if 0: watchdog always on) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATTiny25/45/85 ############################### +# ATMega*5 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATMega*5 FUSE_H (Fuse high byte): +# 0xdd = 1 1 0 1 1 1 0 1 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (disable external reset -> enabled) +# +################################ ATTiny2313 ################################# +# ATTiny2313 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATTiny2313 FUSE_H (Fuse high byte): +# 0xdb = 1 1 0 1 1 0 1 1 +# ^ ^ ^ ^ \-+-/ ^ +# | | | | | +---- RSTDISBL (disable external reset -> enabled) +# | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# +-------------------- DWEN (debug wire enable) + +first: flash + +# symbolic targets: +help: + @echo "This Makefile has no default rule. Use one of the following:" + @echo "make hex ....... to build main.hex" + @echo "make program ... to flash fuses and firmware" + @echo "make fuse ...... to flash the fuses" + @echo "make flash ..... to flash the firmware (use this on metaboard)" + @echo "make clean ..... to delete objects and hex file" + +hex: main.hex + +program: flash fuse + +# rule for programming fuse bits: +fuse: + @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \ + { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; } + $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m + +# rule for uploading firmware: +flash: main.hex + $(AVRDUDE) -U flash:w:main.hex:i + +# rule for deleting dependent files (those which can be built by Make): +clean: + rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s + +# Generic rule for compiling C files: +.c.o: + $(COMPILE) -c $< -o $@ + +# Generic rule for assembling Assembler source files: +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +# Generic rule for compiling C to assembler, used for debugging only. +.c.s: + $(COMPILE) -S $< -o $@ + +# file targets: + +# Since we don't want to ship the driver multipe times, we copy it into this project: +usbdrv: + cp -r vusb//usbdrv . + +main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it + $(COMPILE) -o main.elf $(OBJECTS) + +main.hex: main.elf + rm -f main.hex main.eep.hex + avr-objcopy -j .text -j .data -O ihex main.elf main.hex + avr-size main.hex + +# debugging targets: + +disasm: main.elf + avr-objdump -d main.elf + +cpp: + $(COMPILE) -E main.c diff --git a/adb2usb/uart2usb/main.c b/adb2usb/uart2usb/main.c new file mode 100644 index 0000000..b95e2ba --- /dev/null +++ b/adb2usb/uart2usb/main.c @@ -0,0 +1,222 @@ +/* +ADB to USB-converter, for a non-extended keyboard and a mouse +Copyright (C) 2010 Jeroen Domburg + +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 . +*/ +#include +#include +#include /* for sei() */ +#include /* for _delay_ms() */ + +#include /* required by usbdrv.h */ +#include "usbdrv.h" +//#include "usbdrv/usbdrv.c" +#include "oddebug.h" /* This is also an example for using debug macros */ + + +/* ------------------------------------------------------------------------- */ +/* ----------------------------- USB interface ----------------------------- */ +/* ------------------------------------------------------------------------- */ + +char usbHidReportDescriptor[] PROGMEM = { + /* partial keyboard */ + 0x05, 0x01, /* Usage Page (Generic Desktop), */ + 0x09, 0x06, /* Usage (Keyboard), */ + 0xA1, 0x01, /* Collection (Application), */ + 0x85, 0x01, /* Report Id (1) */ + 0x05, 0x07, // USAGE_PAGE (Keyboard) + 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) + 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) + + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x08, // REPORT_COUNT (8) + 0x81, 0x02, // INPUT (Data,Var,Abs) + + 0x05, 0x07, /* Usage Page (Key Codes), */ + 0x95, 0x04, /* Report Count (4), */ + 0x75, 0x08, /* Report Size (8), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x25, 0x75, /* Logical Maximum(117), */ + 0x19, 0x00, /* Usage Minimum (0), */ + 0x29, 0x75, /* Usage Maximum (117), */ + 0x81, 0x00, /* Input (Data, Array), ;Key arrays (4 bytes) */ + 0xC0, /* End Collection */ + + /* mouse */ + 0x05, 0x01, /* Usage Page (Generic Desktop), */ + 0x09, 0x02, /* Usage (Mouse), */ + 0xA1, 0x01, /* Collection (Application), */ + 0x09, 0x01, /* Usage (Pointer), */ + 0xA1, 0x00, /* Collection (Physical), */ + 0x05, 0x09, /* Usage Page (Buttons), */ + 0x19, 0x01, /* Usage Minimum (01), */ + 0x29, 0x03, /* Usage Maximun (03), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x85, 0x02, /* Report Id (2) */ + 0x95, 0x03, /* Report Count (3), */ + 0x75, 0x01, /* Report Size (1), */ + 0x81, 0x02, /* Input (Data, Variable, Absolute), ;3 button bits */ + 0x95, 0x01, /* Report Count (1), */ + 0x75, 0x05, /* Report Size (5), */ + 0x81, 0x01, /* Input (Constant), ;5 bit padding */ + 0x05, 0x01, /* Usage Page (Generic Desktop), */ + 0x09, 0x30, /* Usage (X), */ + 0x09, 0x31, /* Usage (Y), */ + 0x15, 0x81, /* Logical Minimum (-127), */ + 0x25, 0x7F, /* Logical Maximum (127), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x06, /* Input (Data, Variable, Relative), ;2 position bytes (X & Y) */ + 0xC0, /* End Collection, */ + 0xC0, /* End Collection */ +}; + +typedef struct { + char id; + char meta; + char b[4]; +}keybReport_t; + +typedef struct{ + char id; + uchar buttonMask; + char dx; + char dy; +}mouseReport_t; + +static keybReport_t keybReportBuffer={1, 0, {0, 0, 0, 0}}; +static mouseReport_t mouseReportBuffer={2, 0, 0, 0}; +static uchar idleRate; /* repeat rate for keyboards, never used for mice */ +static char doSend; + +#define SEND_MOUSE 1 +#define SEND_KEYB 2 + + +//Parses a byte from the ADB receiving microcontroller. +//Includes a state machne to convert the individual bytes into a +//HID report we can send. +static void parseByte(unsigned char b) { + static unsigned char buff[8]; + static int toGet=0; //Bytes left in this hid report + static int p=0; //Buffer index + if (toGet==0) { + if (b=='M') { + toGet=4; + } else if (b=='K') { + toGet=6; + } + } + if (toGet>0) { + buff[p++]=b; + toGet--; + if (toGet==0) { //Got all bytes we need? + if (buff[0]=='M') { + mouseReportBuffer.buttonMask=buff[1]; + mouseReportBuffer.dx+=buff[2]; + mouseReportBuffer.dy+=buff[3]; + doSend|=SEND_MOUSE; + } else if (buff[0]=='K') { + keybReportBuffer.meta=buff[1]; + keybReportBuffer.b[0]=buff[2]; + keybReportBuffer.b[1]=buff[3]; + keybReportBuffer.b[2]=buff[4]; + keybReportBuffer.b[3]=buff[5]; + doSend|=SEND_KEYB; + } + p=0; + } + } +} + + +usbMsgLen_t usbFunctionSetup(uchar data[8]) { + usbRequest_t *rq = (void *)data; + /* The following requests are never used. But since they are required by + * the specification, we implement them in this example. + */ + if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */ + if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */ + if (rq->wValue.bytes[1]==1) { + usbMsgPtr = (void *)&mouseReportBuffer; + return sizeof(mouseReportBuffer); + } else if (rq->wValue.bytes[1]==2) { + usbMsgPtr = (void *)&mouseReportBuffer; + return sizeof(mouseReportBuffer); + } + } else if(rq->bRequest == USBRQ_HID_GET_IDLE){ + usbMsgPtr = &idleRate; + return 1; + } else if(rq->bRequest == USBRQ_HID_SET_IDLE){ + idleRate = rq->wValue.bytes[1]; + } + }else{ + /* no vendor specific requests implemented */ + } + return 0; /* default for not implemented requests: return no data back to host */ +} + +/* ------------------------------------------------------------------------- */ + +int __attribute__((noreturn)) main(void) { + uchar i; + wdt_enable(WDTO_1S); + /* Even if you don't use the watchdog, turn it off here. On newer devices, + * the status of the watchdog (on/off, period) is PRESERVED OVER RESET! + */ + /* RESET status: all port bits are inputs without pull-up. + * That's the way we need D+ and D-. Therefore we don't need any + * additional hardware initialization. + */ + DDRD=0; + UCSRB=0x18; + UBRRL=39; + UBRRH=0; + odDebugInit(); + usbInit(); + usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ + i = 0; + while(--i){ // fake USB disconnect for > 250 ms + wdt_reset(); + _delay_ms(1); + } + + usbDeviceConnect(); + sei(); + for(;;){ /* main event loop */ + wdt_reset(); + usbPoll(); + if(usbInterruptIsReady()){ + if (doSend&SEND_MOUSE) { + /* called after every poll of the interrupt endpoint */ + usbSetInterrupt((void *)&mouseReportBuffer, sizeof(mouseReportBuffer)); + mouseReportBuffer.dx=0; + mouseReportBuffer.dy=0; + mouseReportBuffer.buttonMask=0; + doSend&=~SEND_MOUSE; + } else if (doSend&SEND_KEYB) { + usbSetInterrupt((void *)&keybReportBuffer, sizeof(keybReportBuffer)); + keybReportBuffer.b[0]=0; + doSend&=~SEND_KEYB; + } + } + if (UCSRA&(1<<7)) parseByte(UDR); + } +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/usbconfig.h b/adb2usb/uart2usb/usbconfig.h new file mode 100644 index 0000000..4a57987 --- /dev/null +++ b/adb2usb/uart2usb/usbconfig.h @@ -0,0 +1,373 @@ +/* Name: usbconfig.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2005-04-01 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ + */ + +#ifndef __usbconfig_h_included__ +#define __usbconfig_h_included__ + +/* +General Description: +This file is an example configuration (with inline documentation) for the USB +driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is +also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may +wire the lines to any other port, as long as D+ is also wired to INT0 (or any +other hardware interrupt, as long as it is the highest level interrupt, see +section at the end of this file). +*/ + +/* ---------------------------- Hardware Config ---------------------------- */ + +#define USB_CFG_IOPORTNAME D +/* This is the port where the USB bus is connected. When you configure it to + * "B", the registers PORTB, PINB and DDRB will be used. + */ +#define USB_CFG_DMINUS_BIT 4 +/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. + * This may be any bit in the port. + */ +#define USB_CFG_DPLUS_BIT 2 +/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. + * This may be any bit in the port. Please note that D+ must also be connected + * to interrupt pin INT0! [You can also use other interrupts, see section + * "Optional MCU Description" below, or you can connect D- to the interrupt, as + * it is required if you use the USB_COUNT_SOF feature. If you use D- for the + * interrupt, the USB interrupt will also be triggered at Start-Of-Frame + * markers every millisecond.] + */ +#define USB_CFG_CLOCK_KHZ (F_CPU/1000) +/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, + * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code + * require no crystal, they tolerate +/- 1% deviation from the nominal + * frequency. All other rates require a precision of 2000 ppm and thus a + * crystal! + * Since F_CPU should be defined to your actual clock rate anyway, you should + * not need to modify this setting. + */ +#define USB_CFG_CHECK_CRC 0 +/* Define this to 1 if you want that the driver checks integrity of incoming + * data packets (CRC checks). CRC checks cost quite a bit of code size and are + * currently only available for 18 MHz crystal clock. You must choose + * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. + */ + +/* ----------------------- Optional Hardware Config ------------------------ */ + +#define USB_CFG_PULLUP_IOPORTNAME D +/* If you connect the 1.5k pullup resistor from D- to a port pin instead of + * V+, you can connect and disconnect the device from firmware by calling + * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). + * This constant defines the port on which the pullup resistor is connected. + */ +#define USB_CFG_PULLUP_BIT 3 +/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined + * above) where the 1.5k pullup resistor is connected. See description + * above for details. + */ + +/* --------------------------- Functional Range ---------------------------- */ + +#define USB_CFG_HAVE_INTRIN_ENDPOINT 1 +/* Define this to 1 if you want to compile a version with two endpoints: The + * default control endpoint 0 and an interrupt-in endpoint (any other endpoint + * number). + */ +#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 +/* Define this to 1 if you want to compile a version with three endpoints: The + * default control endpoint 0, an interrupt-in endpoint 3 (or the number + * configured below) and a catch-all default interrupt-in endpoint as above. + * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. + */ +#define USB_CFG_EP3_NUMBER 3 +/* If the so-called endpoint 3 is used, it can now be configured to any other + * endpoint number (except 0) with this macro. Default if undefined is 3. + */ +/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ +/* The above macro defines the startup condition for data toggling on the + * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. + * Since the token is toggled BEFORE sending any data, the first packet is + * sent with the oposite value of this configuration! + */ +#define USB_CFG_IMPLEMENT_HALT 0 +/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature + * for endpoint 1 (interrupt endpoint). Although you may not need this feature, + * it is required by the standard. We have made it a config option because it + * bloats the code considerably. + */ +#define USB_CFG_SUPPRESS_INTR_CODE 0 +/* Define this to 1 if you want to declare interrupt-in endpoints, but don't + * want to send any data over them. If this macro is defined to 1, functions + * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if + * you need the interrupt-in endpoints in order to comply to an interface + * (e.g. HID), but never want to send any data. This option saves a couple + * of bytes in flash memory and the transmit buffers in RAM. + */ +#define USB_CFG_INTR_POLL_INTERVAL 10 +/* If you compile a version with endpoint 1 (interrupt-in), this is the poll + * interval. The value is in milliseconds and must not be less than 10 ms for + * low speed devices. + */ +#define USB_CFG_IS_SELF_POWERED 0 +/* Define this to 1 if the device has its own power supply. Set it to 0 if the + * device is powered from the USB bus. + */ +#define USB_CFG_MAX_BUS_POWER 100 +/* Set this variable to the maximum USB bus power consumption of your device. + * The value is in milliamperes. [It will be divided by two since USB + * communicates power requirements in units of 2 mA.] + */ +#define USB_CFG_IMPLEMENT_FN_WRITE 0 +/* Set this to 1 if you want usbFunctionWrite() to be called for control-out + * transfers. Set it to 0 if you don't need it and want to save a couple of + * bytes. + */ +#define USB_CFG_IMPLEMENT_FN_READ 0 +/* Set this to 1 if you need to send control replies which are generated + * "on the fly" when usbFunctionRead() is called. If you only want to send + * data from a static buffer, set it to 0 and return the data from + * usbFunctionSetup(). This saves a couple of bytes. + */ +#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 +/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. + * You must implement the function usbFunctionWriteOut() which receives all + * interrupt/bulk data sent to any endpoint other than 0. The endpoint number + * can be found in 'usbRxToken'. + */ +#define USB_CFG_HAVE_FLOWCONTROL 0 +/* Define this to 1 if you want flowcontrol over USB data. See the definition + * of the macros usbDisableAllRequests() and usbEnableAllRequests() in + * usbdrv.h. + */ +#define USB_CFG_DRIVER_FLASH_PAGE 0 +/* If the device has more than 64 kBytes of flash, define this to the 64 k page + * where the driver's constants (descriptors) are located. Or in other words: + * Define this to 1 for boot loaders on the ATMega128. + */ +#define USB_CFG_LONG_TRANSFERS 0 +/* Define this to 1 if you want to send/receive blocks of more than 254 bytes + * in a single control-in or control-out transfer. Note that the capability + * for long transfers increases the driver size. + */ +/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ +/* This macro is a hook if you want to do unconventional things. If it is + * defined, it's inserted at the beginning of received message processing. + * If you eat the received message and don't want default processing to + * proceed, do a return after doing your things. One possible application + * (besides debugging) is to flash a status LED on each packet. + */ +/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ +/* This macro is a hook if you need to know when an USB RESET occurs. It has + * one parameter which distinguishes between the start of RESET state and its + * end. + */ +/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ +/* This macro (if defined) is executed when a USB SET_ADDRESS request was + * received. + */ +#define USB_COUNT_SOF 0 +/* define this macro to 1 if you need the global variable "usbSofCount" which + * counts SOF packets. This feature requires that the hardware interrupt is + * connected to D- instead of D+. + */ +/* #ifdef __ASSEMBLER__ + * macro myAssemblerMacro + * in YL, TCNT0 + * sts timer0Snapshot, YL + * endm + * #endif + * #define USB_SOF_HOOK myAssemblerMacro + * This macro (if defined) is executed in the assembler module when a + * Start Of Frame condition is detected. It is recommended to define it to + * the name of an assembler macro which is defined here as well so that more + * than one assembler instruction can be used. The macro may use the register + * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages + * immediately after an SOF pulse may be lost and must be retried by the host. + * What can you do with this hook? Since the SOF signal occurs exactly every + * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in + * designs running on the internal RC oscillator. + * Please note that Start Of Frame detection works only if D- is wired to the + * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! + */ +#define USB_CFG_CHECK_DATA_TOGGLING 0 +/* define this macro to 1 if you want to filter out duplicate data packets + * sent by the host. Duplicates occur only as a consequence of communication + * errors, when the host does not receive an ACK. Please note that you need to + * implement the filtering yourself in usbFunctionWriteOut() and + * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable + * for each control- and out-endpoint to check for duplicate packets. + */ +#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 +/* define this macro to 1 if you want the function usbMeasureFrameLength() + * compiled in. This function can be used to calibrate the AVR's RC oscillator. + */ +#define USB_USE_FAST_CRC 0 +/* The assembler module has two implementations for the CRC algorithm. One is + * faster, the other is smaller. This CRC routine is only used for transmitted + * messages where timing is not critical. The faster routine needs 31 cycles + * per byte while the smaller one needs 61 to 69 cycles. The faster routine + * may be worth the 32 bytes bigger code size if you transmit lots of data and + * run the AVR close to its limit. + */ + +/* -------------------------- Device Description --------------------------- */ + +#define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ +/* USB vendor ID for the device, low byte first. If you have registered your + * own Vendor ID, define it here. Otherwise you may use one of obdev's free + * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_ID 0xe8, 0x03 /* VOTI's lab use PID */ +/* This is the ID of the product, low byte first. It is interpreted in the + * scope of the vendor ID. If you have registered your own VID with usb.org + * or if you have licensed a PID from somebody else, define it here. Otherwise + * you may use one of obdev's free shared VID/PID pairs. See the file + * USB-IDs-for-free.txt for details! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +/* Version number of the device: Minor number first, then major number. + */ +#define USB_CFG_VENDOR_NAME 's', 'p', 'r', 'i', 't', 'e', 's', 'm', 'o', 'd', 's', '.', 'c', 'o', 'm' +#define USB_CFG_VENDOR_NAME_LEN 15 +/* These two values define the vendor name returned by the USB device. The name + * must be given as a list of characters under single quotes. The characters + * are interpreted as Unicode (UTF-16) entities. + * If you don't want a vendor name string, undefine these macros. + * ALWAYS define a vendor name containing your Internet domain name if you use + * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for + * details. + */ +#define USB_CFG_DEVICE_NAME 'A', 'D', 'B', '2', 'U', 'S', 'B' +#define USB_CFG_DEVICE_NAME_LEN 7 +/* Same as above for the device name. If you don't want a device name, undefine + * the macros. See the file USB-IDs-for-free.txt before you assign a name if + * you use a shared VID/PID. + */ +/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ +/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ +/* Same as above for the serial number. If you don't want a serial number, + * undefine the macros. + * It may be useful to provide the serial number through other means than at + * compile time. See the section about descriptor properties below for how + * to fine tune control over USB descriptors such as the string descriptor + * for the serial number. + */ +#define USB_CFG_DEVICE_CLASS 0 +#define USB_CFG_DEVICE_SUBCLASS 0 +/* See USB specification if you want to conform to an existing device class. + * Class 0xff is "vendor specific". + */ +#define USB_CFG_INTERFACE_CLASS 3 +#define USB_CFG_INTERFACE_SUBCLASS 0 +#define USB_CFG_INTERFACE_PROTOCOL 0 +/* See USB specification if you want to conform to an existing device class or + * protocol. The following classes must be set at interface level: + * HID class is 3, no subclass and protocol required (but may be useful!) + * CDC class is 2, use subclass 2 and protocol 1 for ACM + */ +#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 93 +/* Define this to the length of the HID report descriptor, if you implement + * an HID device. Otherwise don't define it or define it to 0. + * If you use this define, you must add a PROGMEM character array named + * "usbHidReportDescriptor" to your code which contains the report descriptor. + * Don't forget to keep the array and this define in sync! + */ + +//#define USB_PUBLIC static +/* Use the define above if you #include usbdrv.c instead of linking against it. + * This technique saves a couple of bytes in flash memory. + */ + +/* ------------------- Fine Control over USB Descriptors ------------------- */ +/* If you don't want to use the driver's default USB descriptors, you can + * provide our own. These can be provided as (1) fixed length static data in + * flash memory, (2) fixed length static data in RAM or (3) dynamically at + * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more + * information about this function. + * Descriptor handling is configured through the descriptor's properties. If + * no properties are defined or if they are 0, the default descriptor is used. + * Possible properties are: + * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched + * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is + * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if + * you want RAM pointers. + * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found + * in static memory is in RAM, not in flash memory. + * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), + * the driver must know the descriptor's length. The descriptor itself is + * found at the address of a well known identifier (see below). + * List of static descriptor names (must be declared PROGMEM if in flash): + * char usbDescriptorDevice[]; + * char usbDescriptorConfiguration[]; + * char usbDescriptorHidReport[]; + * char usbDescriptorString0[]; + * int usbDescriptorStringVendor[]; + * int usbDescriptorStringDevice[]; + * int usbDescriptorStringSerialNumber[]; + * Other descriptors can't be provided statically, they must be provided + * dynamically at runtime. + * + * Descriptor properties are or-ed or added together, e.g.: + * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) + * + * The following descriptors are defined: + * USB_CFG_DESCR_PROPS_DEVICE + * USB_CFG_DESCR_PROPS_CONFIGURATION + * USB_CFG_DESCR_PROPS_STRINGS + * USB_CFG_DESCR_PROPS_STRING_0 + * USB_CFG_DESCR_PROPS_STRING_VENDOR + * USB_CFG_DESCR_PROPS_STRING_PRODUCT + * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER + * USB_CFG_DESCR_PROPS_HID + * USB_CFG_DESCR_PROPS_HID_REPORT + * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) + * + * Note about string descriptors: String descriptors are not just strings, they + * are Unicode strings prefixed with a 2 byte header. Example: + * int serialNumberDescriptor[] = { + * USB_STRING_DESCRIPTOR_HEADER(6), + * 'S', 'e', 'r', 'i', 'a', 'l' + * }; + */ + +#define USB_CFG_DESCR_PROPS_DEVICE 0 +#define USB_CFG_DESCR_PROPS_CONFIGURATION 0 +#define USB_CFG_DESCR_PROPS_STRINGS 0 +#define USB_CFG_DESCR_PROPS_STRING_0 0 +#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 +#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 +#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 +#define USB_CFG_DESCR_PROPS_HID 0 +#define USB_CFG_DESCR_PROPS_HID_REPORT 0 +#define USB_CFG_DESCR_PROPS_UNKNOWN 0 + +/* ----------------------- Optional MCU Description ------------------------ */ + +/* The following configurations have working defaults in usbdrv.h. You + * usually don't need to set them explicitly. Only if you want to run + * the driver on a device which is not yet supported or with a compiler + * which is not fully supported (such as IAR C) or if you use a differnt + * interrupt than INT0, you may have to define some of these. + */ +/* #define USB_INTR_CFG MCUCR */ +/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ +/* #define USB_INTR_CFG_CLR 0 */ +/* #define USB_INTR_ENABLE GIMSK */ +/* #define USB_INTR_ENABLE_BIT INT0 */ +/* #define USB_INTR_PENDING GIFR */ +/* #define USB_INTR_PENDING_BIT INTF0 */ +/* #define USB_INTR_VECTOR INT0_vect */ + +#endif /* __usbconfig_h_included__ */ diff --git a/adb2usb/uart2usb/usbdrv/Changelog.txt b/adb2usb/uart2usb/usbdrv/Changelog.txt new file mode 100644 index 0000000..5c6354a --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/Changelog.txt @@ -0,0 +1,308 @@ +This file documents changes in the firmware-only USB driver for atmel's AVR +microcontrollers. New entries are always appended to the end of the file. +Scroll down to the bottom to see the most recent changes. + +2005-04-01: + - Implemented endpoint 1 as interrupt-in endpoint. + - Moved all configuration options to usbconfig.h which is not part of the + driver. + - Changed interface for usbVendorSetup(). + - Fixed compatibility with ATMega8 device. + - Various minor optimizations. + +2005-04-11: + - Changed interface to application: Use usbFunctionSetup(), usbFunctionRead() + and usbFunctionWrite() now. Added configuration options to choose which + of these functions to compile in. + - Assembler module delivers receive data non-inverted now. + - Made register and bit names compatible with more AVR devices. + +2005-05-03: + - Allow address of usbRxBuf on any memory page as long as the buffer does + not cross 256 byte page boundaries. + - Better device compatibility: works with Mega88 now. + - Code optimization in debugging module. + - Documentation updates. + +2006-01-02: + - Added (free) default Vendor- and Product-IDs bought from voti.nl. + - Added USBID-License.txt file which defines the rules for using the free + shared VID/PID pair. + - Added Readme.txt to the usbdrv directory which clarifies administrative + issues. + +2006-01-25: + - Added "configured state" to become more standards compliant. + - Added "HALT" state for interrupt endpoint. + - Driver passes the "USB Command Verifier" test from usb.org now. + - Made "serial number" a configuration option. + - Minor optimizations, we now recommend compiler option "-Os" for best + results. + - Added a version number to usbdrv.h + +2006-02-03: + - New configuration variable USB_BUFFER_SECTION for the memory section where + the USB rx buffer will go. This defaults to ".bss" if not defined. Since + this buffer MUST NOT cross 256 byte pages (not even touch a page at the + end), the user may want to pass a linker option similar to + "-Wl,--section-start=.mybuffer=0x800060". + - Provide structure for usbRequest_t. + - New defines for USB constants. + - Prepared for HID implementations. + - Increased data size limit for interrupt transfers to 8 bytes. + - New macro usbInterruptIsReady() to query interrupt buffer state. + +2006-02-18: + - Ensure that the data token which is sent as an ack to an OUT transfer is + always zero sized. This fixes a bug where the host reports an error after + sending an out transfer to the device, although all data arrived at the + device. + - Updated docs in usbdrv.h to reflect changed API in usbFunctionWrite(). + +* Release 2006-02-20 + + - Give a compiler warning when compiling with debugging turned on. + - Added Oleg Semyonov's changes for IAR-cc compatibility. + - Added new (optional) functions usbDeviceConnect() and usbDeviceDisconnect() + (also thanks to Oleg!). + - Rearranged tests in usbPoll() to save a couple of instructions in the most + likely case that no actions are pending. + - We need a delay between the SET ADDRESS request until the new address + becomes active. This delay was handled in usbPoll() until now. Since the + spec says that the delay must not exceed 2ms, previous versions required + aggressive polling during the enumeration phase. We have now moved the + handling of the delay into the interrupt routine. + - We must not reply with NAK to a SETUP transaction. We can only achieve this + by making sure that the rx buffer is empty when SETUP tokens are expected. + We therefore don't pass zero sized data packets from the status phase of + a transfer to usbPoll(). This change MAY cause troubles if you rely on + receiving a less than 8 bytes long packet in usbFunctionWrite() to + identify the end of a transfer. usbFunctionWrite() will NEVER be called + with a zero length. + +* Release 2006-03-14 + + - Improved IAR C support: tiny memory model, more devices + - Added template usbconfig.h file under the name usbconfig-prototype.h + +* Release 2006-03-26 + + - Added provision for one more interrupt-in endpoint (endpoint 3). + - Added provision for one interrupt-out endpoint (endpoint 1). + - Added flowcontrol macros for USB. + - Added provision for custom configuration descriptor. + - Allow ANY two port bits for D+ and D-. + - Merged (optional) receive endpoint number into global usbRxToken variable. + - Use USB_CFG_IOPORTNAME instead of USB_CFG_IOPORT. We now construct the + variable name from the single port letter instead of computing the address + of related ports from the output-port address. + +* Release 2006-06-26 + + - Updated documentation in usbdrv.h and usbconfig-prototype.h to reflect the + new features. + - Removed "#warning" directives because IAR does not understand them. Use + unused static variables instead to generate a warning. + - Do not include when compiling with IAR. + - Introduced USB_CFG_DESCR_PROPS_* in usbconfig.h to configure how each + USB descriptor should be handled. It is now possible to provide descriptor + data in Flash, RAM or dynamically at runtime. + - STALL is now a status in usbTxLen* instead of a message. We can now conform + to the spec and leave the stall status pending until it is cleared. + - Made usbTxPacketCnt1 and usbTxPacketCnt3 public. This allows the + application code to reset data toggling on interrupt pipes. + +* Release 2006-07-18 + + - Added an #if !defined __ASSEMBLER__ to the warning in usbdrv.h. This fixes + an assembler error. + - usbDeviceDisconnect() takes pull-up resistor to high impedance now. + +* Release 2007-02-01 + + - Merged in some code size improvements from usbtiny (thanks to Dick + Streefland for these optimizations!) + - Special alignment requirement for usbRxBuf not required any more. Thanks + again to Dick Streefland for this hint! + - Reverted to "#warning" instead of unused static variables -- new versions + of IAR CC should handle this directive. + - Changed Open Source license to GNU GPL v2 in order to make linking against + other free libraries easier. We no longer require publication of the + circuit diagrams, but we STRONGLY encourage it. If you improve the driver + itself, PLEASE grant us a royalty free license to your changes for our + commercial license. + +* Release 2007-03-29 + + - New configuration option "USB_PUBLIC" in usbconfig.h. + - Set USB version number to 1.10 instead of 1.01. + - Code used USB_CFG_DESCR_PROPS_STRING_DEVICE and + USB_CFG_DESCR_PROPS_STRING_PRODUCT inconsistently. Changed all occurrences + to USB_CFG_DESCR_PROPS_STRING_PRODUCT. + - New assembler module for 16.5 MHz RC oscillator clock with PLL in receiver + code. + - New assembler module for 16 MHz crystal. + - usbdrvasm.S contains common code only, clock-specific parts have been moved + to usbdrvasm12.S, usbdrvasm16.S and usbdrvasm165.S respectively. + +* Release 2007-06-25 + + - 16 MHz module: Do SE0 check in stuffed bits as well. + +* Release 2007-07-07 + + - Define hi8(x) for IAR compiler to limit result to 8 bits. This is necessary + for negative values. + - Added 15 MHz module contributed by V. Bosch. + - Interrupt vector name can now be configured. This is useful if somebody + wants to use a different hardware interrupt than INT0. + +* Release 2007-08-07 + + - Moved handleIn3 routine in usbdrvasm16.S so that relative jump range is + not exceeded. + - More config options: USB_RX_USER_HOOK(), USB_INITIAL_DATATOKEN, + USB_COUNT_SOF + - USB_INTR_PENDING can now be a memory address, not just I/O + +* Release 2007-09-19 + + - Split out common parts of assembler modules into separate include file + - Made endpoint numbers configurable so that given interface definitions + can be matched. See USB_CFG_EP3_NUMBER in usbconfig-prototype.h. + - Store endpoint number for interrupt/bulk-out so that usbFunctionWriteOut() + can handle any number of endpoints. + - Define usbDeviceConnect() and usbDeviceDisconnect() even if no + USB_CFG_PULLUP_IOPORTNAME is defined. Directly set D+ and D- to 0 in this + case. + +* Release 2007-12-01 + + - Optimize usbDeviceConnect() and usbDeviceDisconnect() for less code size + when USB_CFG_PULLUP_IOPORTNAME is not defined. + +* Release 2007-12-13 + + - Renamed all include-only assembler modules from *.S to *.inc so that + people don't add them to their project sources. + - Distribute leap bits in tx loop more evenly for 16 MHz module. + - Use "macro" and "endm" instead of ".macro" and ".endm" for IAR + - Avoid compiler warnings for constant expr range by casting some values in + USB descriptors. + +* Release 2008-01-21 + + - Fixed bug in 15 and 16 MHz module where the new address set with + SET_ADDRESS was already accepted at the next NAK or ACK we send, not at + the next data packet we send. This caused problems when the host polled + too fast. Thanks to Alexander Neumann for his help and patience debugging + this issue! + +* Release 2008-02-05 + + - Fixed bug in 16.5 MHz module where a register was used in the interrupt + handler before it was pushed. This bug was introduced with version + 2007-09-19 when common parts were moved to a separate file. + - Optimized CRC routine (thanks to Reimar Doeffinger). + +* Release 2008-02-16 + + - Removed outdated IAR compatibility stuff (code sections). + - Added hook macros for USB_RESET_HOOK() and USB_SET_ADDRESS_HOOK(). + - Added optional routine usbMeasureFrameLength() for calibration of the + internal RC oscillator. + +* Release 2008-02-28 + + - USB_INITIAL_DATATOKEN defaults to USBPID_DATA1 now, which means that we + start with sending USBPID_DATA0. + - Changed defaults in usbconfig-prototype.h + - Added free USB VID/PID pair for MIDI class devices + - Restructured AVR-USB as separate package, not part of PowerSwitch any more. + +* Release 2008-04-18 + + - Restructured usbdrv.c so that it is easier to read and understand. + - Better code optimization with gcc 4. + - If a second interrupt in endpoint is enabled, also add it to config + descriptor. + - Added config option for long transfers (above 254 bytes), see + USB_CFG_LONG_TRANSFERS in usbconfig.h. + - Added 20 MHz module contributed by Jeroen Benschop. + +* Release 2008-05-13 + + - Fixed bug in libs-host/hiddata.c function usbhidGetReport(): length + was not incremented, pointer to length was incremented instead. + - Added code to command line tool(s) which claims an interface. This code + is disabled by default, but may be necessary on newer Linux kernels. + - Added usbconfig.h option "USB_CFG_CHECK_DATA_TOGGLING". + - New header "usbportability.h" prepares ports to other development + environments. + - Long transfers (above 254 bytes) did not work when usbFunctionRead() was + used to supply the data. Fixed this bug. [Thanks to Alexander Neumann!] + - In hiddata.c (example code for sending/receiving data over HID), use + USB_RECIP_DEVICE instead of USB_RECIP_INTERFACE for control transfers so + that we need not claim the interface. + - in usbPoll() loop 20 times polling for RESET state instead of 10 times. + This accounts for the higher clock rates we now support. + - Added a module for 12.8 MHz RC oscillator with PLL in receiver loop. + - Added hook to SOF code so that oscillator can be tuned to USB frame clock. + - Added timeout to waitForJ loop. Helps preventing unexpected hangs. + - Added example code for oscillator tuning to libs-device (thanks to + Henrik Haftmann for the idea to this routine). + - Implemented option USB_CFG_SUPPRESS_INTR_CODE. + +* Release 2008-10-22 + + - Fixed libs-device/osctune.h: OSCCAL is memory address on ATMega88 and + similar, not offset of 0x20 needs to be added. + - Allow distribution under GPLv3 for those who have to link against other + code distributed under GPLv3. + +* Release 2008-11-26 + + - Removed libusb-win32 dependency for hid-data example in Makefile.windows. + It was never required and confused many people. + - Added extern uchar usbRxToken to usbdrv.h. + - Integrated a module with CRC checks at 18 MHz by Lukas Schrittwieser. + +* Release 2009-03-23 + + - Hid-mouse example used settings from hid-data example, fixed that. + - Renamed project to V-USB due to a trademark issue with Atmel(r). + - Changed CommercialLicense.txt and USBID-License.txt to make the + background of USB ID registration clearer. + +* Release 2009-04-15 + + - Changed CommercialLicense.txt to reflect the new range of PIDs from + Jason Kotzin. + - Removed USBID-License.txt in favor of USB-IDs-for-free.txt and + USB-ID-FAQ.txt + - Fixed a bug in the 12.8 MHz module: End Of Packet decection was made in + the center between bit 0 and 1 of each byte. This is where the data lines + are expected to change and the sampled data may therefore be nonsense. + We therefore check EOP ONLY if bits 0 AND 1 have both been read as 0 on D-. + - Fixed a bitstuffing problem in the 16 MHz module: If bit 6 was stuffed, + the unstuffing code in the receiver routine was 1 cycle too long. If + multiple bytes had the unstuffing in bit 6, the error summed up until the + receiver was out of sync. + - Included option for faster CRC routine. + Thanks to Slawomir Fras (BoskiDialer) for this code! + - Updated bits in Configuration Descriptor's bmAttributes according to + USB 1.1 (in particular bit 7, it is a must-be-set bit now). + +* Release 2009-08-22 + + - Moved first DBG1() after odDebugInit() in all examples. + - Use vector INT0_vect instead of SIG_INTERRUPT0 if defined. This makes + V-USB compatible with the new "p" suffix devices (e.g. ATMega328p). + - USB_CFG_CLOCK_KHZ setting is now required in usbconfig.h (no default any + more). + - New option USB_CFG_DRIVER_FLASH_PAGE allows boot loaders on devices with + more than 64 kB flash. + - Built-in configuration descriptor allows custom definition for second + endpoint now. + +* Release 2010-07-15 diff --git a/adb2usb/uart2usb/usbdrv/CommercialLicense.txt b/adb2usb/uart2usb/usbdrv/CommercialLicense.txt new file mode 100644 index 0000000..11d07d9 --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/CommercialLicense.txt @@ -0,0 +1,166 @@ +V-USB Driver Software License Agreement +Version 2009-08-03 + +THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN +ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING +THE AMOUNT ACCORDING TO SECTION 4 ("PAYMENT") TO OBJECTIVE DEVELOPMENT. + + +1 DEFINITIONS + +1.1 "OBJECTIVE DEVELOPMENT" shall mean OBJECTIVE DEVELOPMENT Software GmbH, +Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA. + +1.2 "You" shall mean the Licensee. + +1.3 "V-USB" shall mean all files included in the package distributed under +the name "vusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/vusb/) +unless otherwise noted. This includes the firmware-only USB device +implementation for Atmel AVR microcontrollers, some simple device examples +and host side software examples and libraries. + + +2 LICENSE GRANTS + +2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source +code of V-USB. + +2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the +non-exclusive right to use, copy and distribute V-USB with your hardware +product(s), restricted by the limitations in section 3 below. + +2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify +the source code and your copy of V-USB according to your needs. + +2.4 USB IDs. OBJECTIVE DEVELOPMENT furnishes you with one or two USB +Product ID(s), sent to you in e-mail. These Product IDs are reserved +exclusively for you. OBJECTIVE DEVELOPMENT has obtained USB Product ID +ranges under the Vendor ID 5824 from Wouter van Ooijen (Van Ooijen +Technische Informatica, www.voti.nl) and under the Vendor ID 8352 from +Jason Kotzin (Clay Logic, www.claylogic.com). Both owners of the Vendor IDs +have obtained these IDs from the USB Implementers Forum, Inc. +(www.usb.org). OBJECTIVE DEVELOPMENT disclaims all liability which might +arise from the assignment of USB IDs. + +2.5 USB Certification. Although not part of this agreement, we want to make +it clear that you cannot become USB certified when you use V-USB or a USB +Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't +meet the electrical specifications required by the USB specification and +the USB Implementers Forum certifies only members who bought a Vendor ID of +their own. + + +3 LICENSE RESTRICTIONS + +3.1 Number of Units. Only one of the following three definitions is +applicable. Which one is determined by the amount you pay to OBJECTIVE +DEVELOPMENT, see section 4 ("Payment") below. + +Hobby License: You may use V-USB according to section 2 above in no more +than 5 hardware units. These units must not be sold for profit. + +Entry Level License: You may use V-USB according to section 2 above in no +more than 150 hardware units. + +Professional License: You may use V-USB according to section 2 above in +any number of hardware units, except for large scale production ("unlimited +fair use"). Quantities below 10,000 units are not considered large scale +production. If your reach quantities which are obviously large scale +production, you must pay a license fee of 0.10 EUR per unit for all units +above 10,000. + +3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber +any copy of V-USB, or any of the rights granted herein. + +3.3 Transfer. You may not transfer your rights under this Agreement to +another party without OBJECTIVE DEVELOPMENT's prior written consent. If +such consent is obtained, you may permanently transfer this License to +another party. The recipient of such transfer must agree to all terms and +conditions of this Agreement. + +3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not +expressly granted. + +3.5 Non-Exclusive Rights. Your license rights under this Agreement are +non-exclusive. + +3.6 Third Party Rights. This Agreement cannot grant you rights controlled +by third parties. In particular, you are not allowed to use the USB logo or +other trademarks owned by the USB Implementers Forum, Inc. without their +consent. Since such consent depends on USB certification, it should be +noted that V-USB will not pass certification because it does not +implement checksum verification and the microcontroller ports do not meet +the electrical specifications. + + +4 PAYMENT + +The payment amount depends on the variation of this agreement (according to +section 3.1) into which you want to enter. Concrete prices are listed on +OBJECTIVE DEVELOPMENT's web site, usually at +http://www.obdev.at/vusb/license.html. You agree to pay the amount listed +there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor +or reseller. + + +5 COPYRIGHT AND OWNERSHIP + +V-USB is protected by copyright laws and international copyright +treaties, as well as other intellectual property laws and treaties. V-USB +is licensed, not sold. + + +6 TERM AND TERMINATION + +6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE +DEVELOPMENT may terminate this Agreement and revoke the granted license and +USB-IDs if you fail to comply with any of its terms and conditions. + +6.2 Survival of Terms. All provisions regarding secrecy, confidentiality +and limitation of liability shall survive termination of this agreement. + + +7 DISCLAIMER OF WARRANTY AND LIABILITY + +LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE +DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND +NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE +TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL +RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO +STATE/JURISDICTION. + +LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, +IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY +SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER +(INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, +BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY +LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE +PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE +DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY +CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS +AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB. + + +8 MISCELLANEOUS TERMS + +8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing +purposes that you entered into this agreement. + +8.2 Entire Agreement. This document represents the entire agreement between +OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by +an authorized representative of both, OBJECTIVE DEVELOPMENT and you. + +8.3 Severability. In case a provision of these terms and conditions should +be or become partly or entirely invalid, ineffective, or not executable, +the validity of all other provisions shall not be affected. + +8.4 Applicable Law. This agreement is governed by the laws of the Republic +of Austria. + +8.5 Responsible Courts. The responsible courts in Vienna/Austria will have +exclusive jurisdiction regarding all disputes in connection with this +agreement. + diff --git a/adb2usb/uart2usb/usbdrv/License.txt b/adb2usb/uart2usb/usbdrv/License.txt new file mode 100644 index 0000000..4460cfb --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/License.txt @@ -0,0 +1,361 @@ +OBJECTIVE DEVELOPMENT GmbH's V-USB driver software is distributed under the +terms and conditions of the GNU GPL version 2 or the GNU GPL version 3. It is +your choice whether you apply the terms of version 2 or version 3. The full +text of GPLv2 is included below. In addition to the requirements in the GPL, +we STRONGLY ENCOURAGE you to do the following: + +(1) Publish your entire project on a web site and drop us a note with the URL. +Use the form at http://www.obdev.at/vusb/feedback.html for your submission. + +(2) Adhere to minimum publication standards. Please include AT LEAST: + - a circuit diagram in PDF, PNG or GIF format + - full source code for the host software + - a Readme.txt file in ASCII format which describes the purpose of the + project and what can be found in which directories and which files + - a reference to http://www.obdev.at/vusb/ + +(3) If you improve the driver firmware itself, please give us a free license +to your modifications for our commercial license offerings. + + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License. diff --git a/adb2usb/uart2usb/usbdrv/Readme.txt b/adb2usb/uart2usb/usbdrv/Readme.txt new file mode 100644 index 0000000..970dc66 --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/Readme.txt @@ -0,0 +1,172 @@ +This is the Readme file to Objective Development's firmware-only USB driver +for Atmel AVR microcontrollers. For more information please visit +http://www.obdev.at/vusb/ + +This directory contains the USB firmware only. Copy it as-is to your own +project and add all .c and .S files to your project (these files are marked +with an asterisk in the list below). Then copy usbconfig-prototype.h as +usbconfig.h to your project and edit it according to your configuration. + + +TECHNICAL DOCUMENTATION +======================= +The technical documentation (API) for the firmware driver is contained in the +file "usbdrv.h". Please read all of it carefully! Configuration options are +documented in "usbconfig-prototype.h". + +The driver consists of the following files: + Readme.txt ............. The file you are currently reading. + Changelog.txt .......... Release notes for all versions of the driver. + usbdrv.h ............... Driver interface definitions and technical docs. +* usbdrv.c ............... High level language part of the driver. Link this + module to your code! +* usbdrvasm.S ............ Assembler part of the driver. This module is mostly + a stub and includes one of the usbdrvasm*.S files + depending on processor clock. Link this module to + your code! + usbdrvasm*.inc ......... Assembler routines for particular clock frequencies. + Included by usbdrvasm.S, don't link it directly! + asmcommon.inc .......... Common assembler routines. Included by + usbdrvasm*.inc, don't link it directly! + usbconfig-prototype.h .. Prototype for your own usbdrv.h file. +* oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is + defined to a value greater than 0. Link this module + to your code! + oddebug.h .............. Interface definitions of the debug module. + usbportability.h ....... Header with compiler-dependent stuff. + usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this + module instead of usbdrvasm.S when you assembler + with IAR's tools. + License.txt ............ Open Source license for this driver. + CommercialLicense.txt .. Optional commercial license for this driver. + USB-ID-FAQ.txt ......... General infos about USB Product- and Vendor-IDs. + USB-IDs-for-free.txt ... List and terms of use for free shared PIDs. + +(*) ... These files should be linked to your project. + + +CPU CORE CLOCK FREQUENCY +======================== +We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz, +16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The +actual clock rate must be configured in usbconfig.h. + +12 MHz Clock +This is the traditional clock rate of V-USB because it's the lowest clock +rate where the timing constraints of the USB spec can be met. + +15 MHz Clock +Similar to 12 MHz, but some NOPs inserted. On the other hand, the higher clock +rate allows for some loops which make the resulting code size somewhat smaller +than the 12 MHz version. + +16 MHz Clock +This clock rate has been added for users of the Arduino board and other +ready-made boards which come with a fixed 16 MHz crystal. It's also an option +if you need the slightly higher clock rate for performance reasons. Since +16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code +is somewhat tricky and has to insert a leap cycle every third byte. + +12.8 MHz and 16.5 MHz Clock +The assembler modules for these clock rates differ from the other modules +because they have been built for an RC oscillator with only 1% precision. The +receiver code inserts leap cycles to compensate for clock deviations. 1% is +also the precision which can be achieved by calibrating the internal RC +oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL +oscillator can reach 16.5 MHz with the RC oscillator. This includes the very +popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost +all AVRs can reach 12.8 MHz, although this is outside the specified range. + +See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for +code which calibrates the RC oscillator based on the USB frame clock. + +18 MHz Clock +This module is closer to the USB specification because it performs an on the +fly CRC check for incoming packets. Packets with invalid checksum are +discarded as required by the spec. If you also implement checks for data +PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING +in usbconfig.h for more info), this ensures data integrity. Due to the CRC +tables and alignment requirements, this code is bigger than modules for other +clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1 +and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h. + +20 MHz Clock +This module is for people who won't do it with less than the maximum. Since +20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code +uses similar tricks as the 16 MHz module to insert leap cycles. + + +USB IDENTIFIERS +=============== +Every USB device needs a vendor- and a product-identifier (VID and PID). VIDs +are obtained from usb.org for a price of 1,500 USD. Once you have a VID, you +can assign PIDs at will. + +Since an entry level cost of 1,500 USD is too high for most small companies +and hobbyists, we provide some VID/PID pairs for free. See the file +USB-IDs-for-free.txt for details. + +Objective Development also has some license offerings which include product +IDs. See http://www.obdev.at/vusb/ for details. + + +DEVELOPMENT SYSTEM +================== +This driver has been developed and optimized for the GNU compiler version 3 +and 4. We recommend that you use the GNU compiler suite because it is freely +available. V-USB has also been ported to the IAR compiler and assembler. It +has been tested with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the +"small" and "tiny" memory model. Not every release is tested with IAR CC and +the driver may therefore fail to compile with IAR. Please note that gcc is +more efficient for usbdrv.c because this module has been deliberately +optimized for gcc. + +Gcc version 3 produces smaller code than version 4 due to new optimizing +capabilities which don't always improve things on 8 bit CPUs. The code size +generated by gcc 4 can be reduced with the compiler options +-fno-move-loop-invariants, -fno-tree-scev-cprop and +-fno-inline-small-functions in addition to -Os. On devices with more than +8k of flash memory, we also recommend the linker option --relax (written as +-Wl,--relax for gcc) to convert absolute calls into relative where possible. + +For more information about optimizing options see: + + http://www.tty1.net/blog/2008-04-29-avr-gcc-optimisations_en.html + +These optimizations are good for gcc 4.x. Version 3.x of gcc does not support +most of these options and produces good code anyway. + + +USING V-USB FOR FREE +==================== +The AVR firmware driver is published under the GNU General Public License +Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is +your choice whether you apply the terms of version 2 or version 3. + +If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the +following things IN ADDITION to the obligations from the GPL: + +(1) Publish your entire project on a web site and drop us a note with the URL. +Use the form at http://www.obdev.at/vusb/feedback.html for your submission. +If you don't have a web site, you can publish the project in obdev's +documentation wiki at +http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects. + +(2) Adhere to minimum publication standards. Please include AT LEAST: + - a circuit diagram in PDF, PNG or GIF format + - full source code for the host software + - a Readme.txt file in ASCII format which describes the purpose of the + project and what can be found in which directories and which files + - a reference to http://www.obdev.at/vusb/ + +(3) If you improve the driver firmware itself, please give us a free license +to your modifications for our commercial license offerings. + + +COMMERCIAL LICENSES FOR V-USB +============================= +If you don't want to publish your source code under the terms of the GPL, +you can simply pay money for V-USB. As an additional benefit you get +USB PIDs for free, reserved exclusively to you. See the file +"CommercialLicense.txt" for details. + diff --git a/adb2usb/uart2usb/usbdrv/USB-ID-FAQ.txt b/adb2usb/uart2usb/usbdrv/USB-ID-FAQ.txt new file mode 100644 index 0000000..d1de8fb --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/USB-ID-FAQ.txt @@ -0,0 +1,149 @@ +Version 2009-08-22 + +========================== +WHY DO WE NEED THESE IDs? +========================== + +USB is more than a low level protocol for data transport. It also defines a +common set of requests which must be understood by all devices. And as part +of these common requests, the specification defines data structures, the +USB Descriptors, which are used to describe the properties of the device. + +From the perspective of an operating system, it is therefore possible to find +out basic properties of a device (such as e.g. the manufacturer and the name +of the device) without a device-specific driver. This is essential because +the operating system can choose a driver to load based on this information +(Plug-And-Play). + +Among the most important properties in the Device Descriptor are the USB +Vendor- and Product-ID. Both are 16 bit integers. The most simple form of +driver matching is based on these IDs. The driver announces the Vendor- and +Product-IDs of the devices it can handle and the operating system loads the +appropriate driver when the device is connected. + +It is obvious that this technique only works if the pair Vendor- plus +Product-ID is unique: Only devices which require the same driver can have the +same pair of IDs. + + +===================================================== +HOW DOES THE USB STANDARD ENSURE THAT IDs ARE UNIQUE? +===================================================== + +Since it is so important that USB IDs are unique, the USB Implementers Forum, +Inc. (usb.org) needs a way to enforce this legally. It is not forbidden by +law to build a device and assign it any random numbers as IDs. Usb.org +therefore needs an agreement to regulate the use of USB IDs. The agreement +binds only parties who agreed to it, of course. Everybody else is free to use +any numbers for their IDs. + +So how can usb.org ensure that every manufacturer of USB devices enters into +an agreement with them? They do it via trademark licensing. Usb.org has +registered the trademark "USB", all associated logos and related terms. If +you want to put an USB logo on your product or claim that it is USB +compliant, you must license these trademarks from usb.org. And this is where +you enter into an agreement. See the "USB-IF Trademark License Agreement and +Usage Guidelines for the USB-IF Logo" at +http://www.usb.org/developers/logo_license/. + +Licensing the USB trademarks requires that you buy a USB Vendor-ID from +usb.org (one-time fee of ca. 2,000 USD), that you become a member of usb.org +(yearly fee of ca. 4,000 USD) and that you meet all the technical +specifications from the USB spec. + +This means that most hobbyists and small companies will never be able to +become USB compliant, just because membership is so expensive. And you can't +be compliant with a driver based on V-USB anyway, because the AVR's port pins +don't meet the electrical specifications for USB. So, in principle, all +hobbyists and small companies are free to choose any random numbers for their +IDs. They have nothing to lose... + +There is one exception worth noting, though: If you use a sub-component which +implements USB, the vendor of the sub-components may guarantee USB +compliance. This might apply to some or all of FTDI's solutions. + + +======================================================================= +WHY SHOULD YOU OBTAIN USB IDs EVEN IF YOU DON'T LICENSE USB TRADEMARKS? +======================================================================= + +You have learned in the previous section that you are free to choose any +numbers for your IDs anyway. So why not do exactly this? There is still the +technical issue. If you choose IDs which are already in use by somebody else, +operating systems will load the wrong drivers and your device won't work. +Even if you choose IDs which are not currently in use, they may be in use in +the next version of the operating system or even after an automatic update. + +So what you need is a pair of Vendor- and Product-IDs for which you have the +guarantee that no USB compliant product uses them. This implies that no +operating system will ever ship with drivers responsible for these IDs. + + +============================================== +HOW DOES OBJECTIVE DEVELOPMENT HANDLE USB IDs? +============================================== + +Objective Development gives away pairs of USB-IDs with their V-USB licenses. +In order to ensure that these IDs are unique, Objective Development has an +agreement with the company/person who has bought the USB Vendor-ID from +usb.org. This agreement ensures that a range of USB Product-IDs is reserved +for assignment by Objective Development and that the owner of the Vendor-ID +won't give it to anybody else. + +This means that you have to trust three parties to ensure uniqueness of +your IDs: + + - Objective Development, that they don't give the same PID to more than + one person. + - The owner of the Vendor-ID that they don't assign PIDs from the range + assigned to Objective Development to anybody else. + - Usb.org that they don't assign the same Vendor-ID a second time. + + +================================== +WHO IS THE OWNER OF THE VENDOR-ID? +================================== + +Objective Development has obtained ranges of USB Product-IDs under two +Vendor-IDs: Under Vendor-ID 5824 from Wouter van Ooijen (Van Ooijen +Technische Informatica, www.voti.nl) and under Vendor-ID 8352 from Jason +Kotzin (Clay Logic, www.claylogic.com). Both VID owners have received their +Vendor-ID directly from usb.org. + + +========================================================================= +CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE? +========================================================================= + +The short answer is: Yes. All you get is a guarantee that the IDs are never +assigned to anybody else. What more do you need? + + +============================ +WHAT ABOUT SHARED ID PAIRS? +============================ + +Objective Development has reserved some PID/VID pairs for shared use. You +have no guarantee of uniqueness for them, except that no USB compliant device +uses them. In order to avoid technical problems, we must ensure that all +devices with the same pair of IDs use the same driver on kernel level. For +details, see the file USB-IDs-for-free.txt. + + +====================================================== +I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL? +====================================================== + +A 16 bit integer number cannot be protected by copyright laws. It is not +sufficiently complex. And since none of the parties involved entered into the +USB-IF Trademark License Agreement, we are not bound by this agreement. So +there is no reason why it should be illegal to sub-license USB-IDs. + + +============================================= +WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES? +============================================= + +Objective Development disclaims all liabilities which might arise from the +assignment of IDs. If you guarantee product features to your customers +without proper disclaimer, YOU are liable for that. diff --git a/adb2usb/uart2usb/usbdrv/USB-IDs-for-free.txt b/adb2usb/uart2usb/usbdrv/USB-IDs-for-free.txt new file mode 100644 index 0000000..2f4d59a --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/USB-IDs-for-free.txt @@ -0,0 +1,148 @@ +Version 2009-08-22 + +=========================== +FREE USB-IDs FOR SHARED USE +=========================== + +Objective Development has reserved a set of USB Product-IDs for use according +to the guidelines outlined below. For more information about the concept of +USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees +that the IDs listed below are not used by any USB compliant devices. + + +==================== +MECHANISM OF SHARING +==================== + +From a technical point of view, two different devices can share the same USB +Vendor- and Product-ID if they require the same driver on operating system +level. We make use of this fact by assigning separate IDs for various device +classes. On application layer, devices must be distinguished by their textual +name or serial number. We offer separate sets of IDs for discrimination by +textual name and for serial number. + +Examples for shared use of USB IDs are included with V-USB in the "examples" +subdirectory. + + +====================================== +IDs FOR DISCRIMINATION BY TEXTUAL NAME +====================================== + +If you use one of the IDs listed below, your device and host-side software +must conform to these rules: + +(1) The USB device MUST provide a textual representation of the manufacturer +and product identification. The manufacturer identification MUST be available +at least in USB language 0x0409 (English/US). + +(2) The textual manufacturer identification MUST contain either an Internet +domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail +address under your control (e.g. "myname@gmx.net"). You can embed the domain +name or e-mail address in any string you like, e.g. "Objective Development +http://www.obdev.at/vusb/". + +(3) You are responsible for retaining ownership of the domain or e-mail +address for as long as any of your products are in use. + +(4) You may choose any string for the textual product identification, as long +as this string is unique within the scope of your textual manufacturer +identification. + +(5) Application side device look-up MUST be based on the textual manufacturer +and product identification in addition to VID/PID matching. The driver +matching MUST be a comparison of the entire strings, NOT a sub-string match. + +(6) For devices which implement a particular USB device class (e.g. HID), the +operating system's default class driver MUST be used. If an operating system +driver for Vendor Class devices is needed, this driver must be libusb or +libusb-win32 (see http://libusb.org/ and +http://libusb-win32.sourceforge.net/). + +Table if IDs for discrimination by textual name: + +PID dec (hex) | VID dec (hex) | Description of use +==============+===============+============================================ +1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb +--------------+---------------+-------------------------------------------- +1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are + | | NOT mice, keyboards or joysticks) +--------------+---------------+-------------------------------------------- +1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems) +--------------+---------------+-------------------------------------------- +1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices +--------------+---------------+-------------------------------------------- + +Note that Windows caches the textual product- and vendor-description for +mice, keyboards and joysticks. Name-bsed discrimination is therefore not +recommended for these device classes. + + +======================================= +IDs FOR DISCRIMINATION BY SERIAL NUMBER +======================================= + +If you use one of the IDs listed below, your device and host-side software +must conform to these rules: + +(1) The USB device MUST provide a textual representation of the serial +number. The serial number string MUST be available at least in USB language +0x0409 (English/US). + +(2) The serial number MUST start with either an Internet domain name (e.g. +"mycompany.com") registered and owned by you, or an e-mail address under your +control (e.g. "myname@gmx.net"), both terminated with a colon (":") character. +You MAY append any string you like for further discrimination of your devices. + +(3) You are responsible for retaining ownership of the domain or e-mail +address for as long as any of your products are in use. + +(5) Application side device look-up MUST be based on the serial number string +in addition to VID/PID matching. The matching must start at the first +character of the serial number string and include the colon character +terminating your domain or e-mail address. It MAY stop anywhere after that. + +(6) For devices which implement a particular USB device class (e.g. HID), the +operating system's default class driver MUST be used. If an operating system +driver for Vendor Class devices is needed, this driver must be libusb or +libusb-win32 (see http://libusb.org/ and +http://libusb-win32.sourceforge.net/). + +Table if IDs for discrimination by serial number string: + +PID dec (hex) | VID dec (hex) | Description of use +===============+===============+=========================================== +10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb +---------------+---------------+------------------------------------------- +10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are + | | NOT mice, keyboards or joysticks) +---------------+---------------+------------------------------------------- +10202 (0x27da) | 5824 (0x16c0) | For USB Mice +---------------+---------------+------------------------------------------- +10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards +---------------+---------------+------------------------------------------- +10204 (0x27db) | 5824 (0x16c0) | For USB Joysticks +---------------+---------------+------------------------------------------- +10205 (0x27dc) | 5824 (0x16c0) | For CDC-ACM class devices (modems) +---------------+---------------+------------------------------------------- +10206 (0x27dd) | 5824 (0x16c0) | For MIDI class devices +---------------+---------------+------------------------------------------- + + +================= +ORIGIN OF USB-IDs +================= + +OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed +here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition. +Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc. +(see www.usb.org). The VID is registered for the company name "Van Ooijen +Technische Informatica". + + +========== +DISCLAIMER +========== + +OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any +problems which are caused by the shared use of these VID/PID pairs. diff --git a/adb2usb/uart2usb/usbdrv/asmcommon.inc b/adb2usb/uart2usb/usbdrv/asmcommon.inc new file mode 100644 index 0000000..07d692b --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/asmcommon.inc @@ -0,0 +1,188 @@ +/* Name: asmcommon.inc + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2007-11-05 + * Tabsize: 4 + * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Revision: $Id$ + */ + +/* Do not link this file! Link usbdrvasm.S instead, which includes the + * appropriate implementation! + */ + +/* +General Description: +This file contains assembler code which is shared among the USB driver +implementations for different CPU cocks. Since the code must be inserted +in the middle of the module, it's split out into this file and #included. + +Jump destinations called from outside: + sofError: Called when no start sequence was found. + se0: Called when a package has been successfully received. + overflow: Called when receive buffer overflows. + doReturn: Called after sending data. + +Outside jump destinations used by this module: + waitForJ: Called to receive an already arriving packet. + sendAckAndReti: + sendNakAndReti: + sendCntAndReti: + usbSendAndReti: + +The following macros must be defined before this file is included: + .macro POP_STANDARD + .endm + .macro POP_RETI + .endm +*/ + +#define token x1 + +overflow: + ldi x2, 1< 0 + +#warning "Never compile production devices with debugging enabled" + +static void uartPutc(char c) +{ + while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ + ODDBG_UDR = c; +} + +static uchar hexAscii(uchar h) +{ + h &= 0xf; + if(h >= 10) + h += 'a' - (uchar)10 - '0'; + h += '0'; + return h; +} + +static void printHex(uchar c) +{ + uartPutc(hexAscii(c >> 4)); + uartPutc(hexAscii(c)); +} + +void odDebug(uchar prefix, uchar *data, uchar len) +{ + printHex(prefix); + uartPutc(':'); + while(len--){ + uartPutc(' '); + printHex(*data++); + } + uartPutc('\r'); + uartPutc('\n'); +} + +#endif diff --git a/adb2usb/uart2usb/usbdrv/oddebug.h b/adb2usb/uart2usb/usbdrv/oddebug.h new file mode 100644 index 0000000..d61309d --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/oddebug.h @@ -0,0 +1,123 @@ +/* Name: oddebug.h + * Project: AVR library + * Author: Christian Starkjohann + * Creation Date: 2005-01-16 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: oddebug.h 692 2008-11-07 15:07:40Z cs $ + */ + +#ifndef __oddebug_h_included__ +#define __oddebug_h_included__ + +/* +General Description: +This module implements a function for debug logs on the serial line of the +AVR microcontroller. Debugging can be configured with the define +'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging +calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is +2, DBG1 and DBG2 logs will be printed. + +A debug log consists of a label ('prefix') to indicate which debug log created +the output and a memory block to dump in hex ('data' and 'len'). +*/ + + +#ifndef F_CPU +# define F_CPU 12000000 /* 12 MHz */ +#endif + +/* make sure we have the UART defines: */ +#include "usbportability.h" + +#ifndef uchar +# define uchar unsigned char +#endif + +#if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */ +# warning "Debugging disabled because device has no UART" +# undef DEBUG_LEVEL +#endif + +#ifndef DEBUG_LEVEL +# define DEBUG_LEVEL 0 +#endif + +/* ------------------------------------------------------------------------- */ + +#if DEBUG_LEVEL > 0 +# define DBG1(prefix, data, len) odDebug(prefix, data, len) +#else +# define DBG1(prefix, data, len) +#endif + +#if DEBUG_LEVEL > 1 +# define DBG2(prefix, data, len) odDebug(prefix, data, len) +#else +# define DBG2(prefix, data, len) +#endif + +/* ------------------------------------------------------------------------- */ + +#if DEBUG_LEVEL > 0 +extern void odDebug(uchar prefix, uchar *data, uchar len); + +/* Try to find our control registers; ATMEL likes to rename these */ + +#if defined UBRR +# define ODDBG_UBRR UBRR +#elif defined UBRRL +# define ODDBG_UBRR UBRRL +#elif defined UBRR0 +# define ODDBG_UBRR UBRR0 +#elif defined UBRR0L +# define ODDBG_UBRR UBRR0L +#endif + +#if defined UCR +# define ODDBG_UCR UCR +#elif defined UCSRB +# define ODDBG_UCR UCSRB +#elif defined UCSR0B +# define ODDBG_UCR UCSR0B +#endif + +#if defined TXEN +# define ODDBG_TXEN TXEN +#else +# define ODDBG_TXEN TXEN0 +#endif + +#if defined USR +# define ODDBG_USR USR +#elif defined UCSRA +# define ODDBG_USR UCSRA +#elif defined UCSR0A +# define ODDBG_USR UCSR0A +#endif + +#if defined UDRE +# define ODDBG_UDRE UDRE +#else +# define ODDBG_UDRE UDRE0 +#endif + +#if defined UDR +# define ODDBG_UDR UDR +#elif defined UDR0 +# define ODDBG_UDR UDR0 +#endif + +static inline void odDebugInit(void) +{ + ODDBG_UCR |= (1<len & 0x10){ /* packet buffer was empty */ + txStatus->buffer[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* toggle token */ + }else{ + txStatus->len = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */ + } + p = txStatus->buffer + 1; + i = len; + do{ /* if len == 0, we still copy 1 byte, but that's no problem */ + *p++ = *data++; + }while(--i > 0); /* loop control at the end is 2 bytes shorter than at beginning */ + usbCrc16Append(&txStatus->buffer[1], len); + txStatus->len = len + 4; /* len must be given including sync byte */ + DBG2(0x21 + (((int)txStatus >> 3) & 3), txStatus->buffer, len + 3); +} + +USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len) +{ + usbGenericSetInterrupt(data, len, &usbTxStatus1); +} +#endif + +#if USB_CFG_HAVE_INTRIN_ENDPOINT3 +USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len) +{ + usbGenericSetInterrupt(data, len, &usbTxStatus3); +} +#endif +#endif /* USB_CFG_SUPPRESS_INTR_CODE */ + +/* ------------------ utilities for code following below ------------------- */ + +/* Use defines for the switch statement so that we can choose between an + * if()else if() and a switch/case based implementation. switch() is more + * efficient for a LARGE set of sequential choices, if() is better in all other + * cases. + */ +#if USB_CFG_USE_SWITCH_STATEMENT +# define SWITCH_START(cmd) switch(cmd){{ +# define SWITCH_CASE(value) }break; case (value):{ +# define SWITCH_CASE2(v1,v2) }break; case (v1): case(v2):{ +# define SWITCH_CASE3(v1,v2,v3) }break; case (v1): case(v2): case(v3):{ +# define SWITCH_DEFAULT }break; default:{ +# define SWITCH_END }} +#else +# define SWITCH_START(cmd) {uchar _cmd = cmd; if(0){ +# define SWITCH_CASE(value) }else if(_cmd == (value)){ +# define SWITCH_CASE2(v1,v2) }else if(_cmd == (v1) || _cmd == (v2)){ +# define SWITCH_CASE3(v1,v2,v3) }else if(_cmd == (v1) || _cmd == (v2) || (_cmd == v3)){ +# define SWITCH_DEFAULT }else{ +# define SWITCH_END }} +#endif + +#ifndef USB_RX_USER_HOOK +#define USB_RX_USER_HOOK(data, len) +#endif +#ifndef USB_SET_ADDRESS_HOOK +#define USB_SET_ADDRESS_HOOK() +#endif + +/* ------------------------------------------------------------------------- */ + +/* We use if() instead of #if in the macro below because #if can't be used + * in macros and the compiler optimizes constant conditions anyway. + * This may cause problems with undefined symbols if compiled without + * optimizing! + */ +#define GET_DESCRIPTOR(cfgProp, staticName) \ + if(cfgProp){ \ + if((cfgProp) & USB_PROP_IS_RAM) \ + flags = 0; \ + if((cfgProp) & USB_PROP_IS_DYNAMIC){ \ + len = usbFunctionDescriptor(rq); \ + }else{ \ + len = USB_PROP_LENGTH(cfgProp); \ + usbMsgPtr = (uchar *)(staticName); \ + } \ + } + +/* usbDriverDescriptor() is similar to usbFunctionDescriptor(), but used + * internally for all types of descriptors. + */ +static inline usbMsgLen_t usbDriverDescriptor(usbRequest_t *rq) +{ +usbMsgLen_t len = 0; +uchar flags = USB_FLG_MSGPTR_IS_ROM; + + SWITCH_START(rq->wValue.bytes[1]) + SWITCH_CASE(USBDESCR_DEVICE) /* 1 */ + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_DEVICE, usbDescriptorDevice) + SWITCH_CASE(USBDESCR_CONFIG) /* 2 */ + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_CONFIGURATION, usbDescriptorConfiguration) + SWITCH_CASE(USBDESCR_STRING) /* 3 */ +#if USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC + if(USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_RAM) + flags = 0; + len = usbFunctionDescriptor(rq); +#else /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ + SWITCH_START(rq->wValue.bytes[0]) + SWITCH_CASE(0) + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_0, usbDescriptorString0) + SWITCH_CASE(1) + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor) + SWITCH_CASE(2) + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_PRODUCT, usbDescriptorStringDevice) + SWITCH_CASE(3) + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, usbDescriptorStringSerialNumber) + SWITCH_DEFAULT + if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){ + len = usbFunctionDescriptor(rq); + } + SWITCH_END +#endif /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ +#if USB_CFG_DESCR_PROPS_HID_REPORT /* only support HID descriptors if enabled */ + SWITCH_CASE(USBDESCR_HID) /* 0x21 */ + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID, usbDescriptorConfiguration + 18) + SWITCH_CASE(USBDESCR_HID_REPORT)/* 0x22 */ + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID_REPORT, usbDescriptorHidReport) +#endif + SWITCH_DEFAULT + if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){ + len = usbFunctionDescriptor(rq); + } + SWITCH_END + usbMsgFlags = flags; + return len; +} + +/* ------------------------------------------------------------------------- */ + +/* usbDriverSetup() is similar to usbFunctionSetup(), but it's used for + * standard requests instead of class and custom requests. + */ +static inline usbMsgLen_t usbDriverSetup(usbRequest_t *rq) +{ +uchar len = 0, *dataPtr = usbTxBuf + 9; /* there are 2 bytes free space at the end of the buffer */ +uchar value = rq->wValue.bytes[0]; +#if USB_CFG_IMPLEMENT_HALT +uchar index = rq->wIndex.bytes[0]; +#endif + + dataPtr[0] = 0; /* default reply common to USBRQ_GET_STATUS and USBRQ_GET_INTERFACE */ + SWITCH_START(rq->bRequest) + SWITCH_CASE(USBRQ_GET_STATUS) /* 0 */ + uchar recipient = rq->bmRequestType & USBRQ_RCPT_MASK; /* assign arith ops to variables to enforce byte size */ + if(USB_CFG_IS_SELF_POWERED && recipient == USBRQ_RCPT_DEVICE) + dataPtr[0] = USB_CFG_IS_SELF_POWERED; +#if USB_CFG_IMPLEMENT_HALT + if(recipient == USBRQ_RCPT_ENDPOINT && index == 0x81) /* request status for endpoint 1 */ + dataPtr[0] = usbTxLen1 == USBPID_STALL; +#endif + dataPtr[1] = 0; + len = 2; +#if USB_CFG_IMPLEMENT_HALT + SWITCH_CASE2(USBRQ_CLEAR_FEATURE, USBRQ_SET_FEATURE) /* 1, 3 */ + if(value == 0 && index == 0x81){ /* feature 0 == HALT for endpoint == 1 */ + usbTxLen1 = rq->bRequest == USBRQ_CLEAR_FEATURE ? USBPID_NAK : USBPID_STALL; + usbResetDataToggling(); + } +#endif + SWITCH_CASE(USBRQ_SET_ADDRESS) /* 5 */ + usbNewDeviceAddr = value; + USB_SET_ADDRESS_HOOK(); + SWITCH_CASE(USBRQ_GET_DESCRIPTOR) /* 6 */ + len = usbDriverDescriptor(rq); + goto skipMsgPtrAssignment; + SWITCH_CASE(USBRQ_GET_CONFIGURATION) /* 8 */ + dataPtr = &usbConfiguration; /* send current configuration value */ + len = 1; + SWITCH_CASE(USBRQ_SET_CONFIGURATION) /* 9 */ + usbConfiguration = value; + usbResetStall(); + SWITCH_CASE(USBRQ_GET_INTERFACE) /* 10 */ + len = 1; +#if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE + SWITCH_CASE(USBRQ_SET_INTERFACE) /* 11 */ + usbResetDataToggling(); + usbResetStall(); +#endif + SWITCH_DEFAULT /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */ + /* Should we add an optional hook here? */ + SWITCH_END + usbMsgPtr = dataPtr; +skipMsgPtrAssignment: + return len; +} + +/* ------------------------------------------------------------------------- */ + +/* usbProcessRx() is called for every message received by the interrupt + * routine. It distinguishes between SETUP and DATA packets and processes + * them accordingly. + */ +static inline void usbProcessRx(uchar *data, uchar len) +{ +usbRequest_t *rq = (void *)data; + +/* usbRxToken can be: + * 0x2d 00101101 (USBPID_SETUP for setup data) + * 0xe1 11100001 (USBPID_OUT: data phase of setup transfer) + * 0...0x0f for OUT on endpoint X + */ + DBG2(0x10 + (usbRxToken & 0xf), data, len + 2); /* SETUP=1d, SETUP-DATA=11, OUTx=1x */ + USB_RX_USER_HOOK(data, len) +#if USB_CFG_IMPLEMENT_FN_WRITEOUT + if(usbRxToken < 0x10){ /* OUT to endpoint != 0: endpoint number in usbRxToken */ + usbFunctionWriteOut(data, len); + return; + } +#endif + if(usbRxToken == (uchar)USBPID_SETUP){ + if(len != 8) /* Setup size must be always 8 bytes. Ignore otherwise. */ + return; + usbMsgLen_t replyLen; + usbTxBuf[0] = USBPID_DATA0; /* initialize data toggling */ + usbTxLen = USBPID_NAK; /* abort pending transmit */ + usbMsgFlags = 0; + uchar type = rq->bmRequestType & USBRQ_TYPE_MASK; + if(type != USBRQ_TYPE_STANDARD){ /* standard requests are handled by driver */ + replyLen = usbFunctionSetup(data); + }else{ + replyLen = usbDriverSetup(rq); + } +#if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE + if(replyLen == USB_NO_MSG){ /* use user-supplied read/write function */ + /* do some conditioning on replyLen, but on IN transfers only */ + if((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE){ + if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */ + replyLen = rq->wLength.bytes[0]; + }else{ + replyLen = rq->wLength.word; + } + } + usbMsgFlags = USB_FLG_USE_USER_RW; + }else /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the maximum transfer len. */ +#endif + if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */ + if(!rq->wLength.bytes[1] && replyLen > rq->wLength.bytes[0]) /* limit length to max */ + replyLen = rq->wLength.bytes[0]; + }else{ + if(replyLen > rq->wLength.word) /* limit length to max */ + replyLen = rq->wLength.word; + } + usbMsgLen = replyLen; + }else{ /* usbRxToken must be USBPID_OUT, which means data phase of setup (control-out) */ +#if USB_CFG_IMPLEMENT_FN_WRITE + if(usbMsgFlags & USB_FLG_USE_USER_RW){ + uchar rval = usbFunctionWrite(data, len); + if(rval == 0xff){ /* an error occurred */ + usbTxLen = USBPID_STALL; + }else if(rval != 0){ /* This was the final package */ + usbMsgLen = 0; /* answer with a zero-sized data packet */ + } + } +#endif + } +} + +/* ------------------------------------------------------------------------- */ + +/* This function is similar to usbFunctionRead(), but it's also called for + * data handled automatically by the driver (e.g. descriptor reads). + */ +static uchar usbDeviceRead(uchar *data, uchar len) +{ + if(len > 0){ /* don't bother app with 0 sized reads */ +#if USB_CFG_IMPLEMENT_FN_READ + if(usbMsgFlags & USB_FLG_USE_USER_RW){ + len = usbFunctionRead(data, len); + }else +#endif + { + uchar i = len, *r = usbMsgPtr; + if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */ + do{ + uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */ + *data++ = c; + r++; + }while(--i); + }else{ /* RAM data */ + do{ + *data++ = *r++; + }while(--i); + } + usbMsgPtr = r; + } + } + return len; +} + +/* ------------------------------------------------------------------------- */ + +/* usbBuildTxBlock() is called when we have data to transmit and the + * interrupt routine's transmit buffer is empty. + */ +static inline void usbBuildTxBlock(void) +{ +usbMsgLen_t wantLen; +uchar len; + + wantLen = usbMsgLen; + if(wantLen > 8) + wantLen = 8; + usbMsgLen -= wantLen; + usbTxBuf[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* DATA toggling */ + len = usbDeviceRead(usbTxBuf + 1, wantLen); + if(len <= 8){ /* valid data packet */ + usbCrc16Append(&usbTxBuf[1], len); + len += 4; /* length including sync byte */ + if(len < 12) /* a partial package identifies end of message */ + usbMsgLen = USB_NO_MSG; + }else{ + len = USBPID_STALL; /* stall the endpoint */ + usbMsgLen = USB_NO_MSG; + } + usbTxLen = len; + DBG2(0x20, usbTxBuf, len-1); +} + +/* ------------------------------------------------------------------------- */ + +static inline void usbHandleResetHook(uchar notResetState) +{ +#ifdef USB_RESET_HOOK +static uchar wasReset; +uchar isReset = !notResetState; + + if(wasReset != isReset){ + USB_RESET_HOOK(isReset); + wasReset = isReset; + } +#endif +} + +/* ------------------------------------------------------------------------- */ + +USB_PUBLIC void usbPoll(void) +{ +schar len; +uchar i; + + len = usbRxLen - 3; + if(len >= 0){ +/* We could check CRC16 here -- but ACK has already been sent anyway. If you + * need data integrity checks with this driver, check the CRC in your app + * code and report errors back to the host. Since the ACK was already sent, + * retries must be handled on application level. + * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3); + */ + usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len); +#if USB_CFG_HAVE_FLOWCONTROL + if(usbRxLen > 0) /* only mark as available if not inactivated */ + usbRxLen = 0; +#else + usbRxLen = 0; /* mark rx buffer as available */ +#endif + } + if(usbTxLen & 0x10){ /* transmit system idle */ + if(usbMsgLen != USB_NO_MSG){ /* transmit data pending? */ + usbBuildTxBlock(); + } + } + for(i = 20; i > 0; i--){ + uchar usbLineStatus = USBIN & USBMASK; + if(usbLineStatus != 0) /* SE0 has ended */ + goto isNotReset; + } + /* RESET condition, called multiple times during reset */ + usbNewDeviceAddr = 0; + usbDeviceAddr = 0; + usbResetStall(); + DBG1(0xff, 0, 0); +isNotReset: + usbHandleResetHook(i); +} + +/* ------------------------------------------------------------------------- */ + +USB_PUBLIC void usbInit(void) +{ +#if USB_INTR_CFG_SET != 0 + USB_INTR_CFG |= USB_INTR_CFG_SET; +#endif +#if USB_INTR_CFG_CLR != 0 + USB_INTR_CFG &= ~(USB_INTR_CFG_CLR); +#endif + USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT); + usbResetDataToggling(); +#if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE + usbTxLen1 = USBPID_NAK; +#if USB_CFG_HAVE_INTRIN_ENDPOINT3 + usbTxLen3 = USBPID_NAK; +#endif +#endif +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/usbdrv/usbdrv.h b/adb2usb/uart2usb/usbdrv/usbdrv.h new file mode 100644 index 0000000..3a78f30 --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/usbdrv.h @@ -0,0 +1,735 @@ +/* Name: usbdrv.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2004-12-29 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbdrv.h 793 2010-07-15 15:58:11Z cs $ + */ + +#ifndef __usbdrv_h_included__ +#define __usbdrv_h_included__ +#include "usbconfig.h" +#include "usbportability.h" + +/* +Hardware Prerequisites: +======================= +USB lines D+ and D- MUST be wired to the same I/O port. We recommend that D+ +triggers the interrupt (best achieved by using INT0 for D+), but it is also +possible to trigger the interrupt from D-. If D- is used, interrupts are also +triggered by SOF packets. D- requires a pull-up of 1.5k to +3.5V (and the +device must be powered at 3.5V) to identify as low-speed USB device. A +pull-down or pull-up of 1M SHOULD be connected from D+ to +3.5V to prevent +interference when no USB master is connected. If you use Zener diodes to limit +the voltage on D+ and D-, you MUST use a pull-down resistor, not a pull-up. +We use D+ as interrupt source and not D- because it does not trigger on +keep-alive and RESET states. If you want to count keep-alive events with +USB_COUNT_SOF, you MUST use D- as an interrupt source. + +As a compile time option, the 1.5k pull-up resistor on D- can be made +switchable to allow the device to disconnect at will. See the definition of +usbDeviceConnect() and usbDeviceDisconnect() further down in this file. + +Please adapt the values in usbconfig.h according to your hardware! + +The device MUST be clocked at exactly 12 MHz, 15 MHz, 16 MHz or 20 MHz +or at 12.8 MHz resp. 16.5 MHz +/- 1%. See usbconfig-prototype.h for details. + + +Limitations: +============ +Robustness with respect to communication errors: +The driver assumes error-free communication. It DOES check for errors in +the PID, but does NOT check bit stuffing errors, SE0 in middle of a byte, +token CRC (5 bit) and data CRC (16 bit). CRC checks can not be performed due +to timing constraints: We must start sending a reply within 7 bit times. +Bit stuffing and misplaced SE0 would have to be checked in real-time, but CPU +performance does not permit that. The driver does not check Data0/Data1 +toggling, but application software can implement the check. + +Input characteristics: +Since no differential receiver circuit is used, electrical interference +robustness may suffer. The driver samples only one of the data lines with +an ordinary I/O pin's input characteristics. However, since this is only a +low speed USB implementation and the specification allows for 8 times the +bit rate over the same hardware, we should be on the safe side. Even the spec +requires detection of asymmetric states at high bit rate for SE0 detection. + +Number of endpoints: +The driver supports the following endpoints: + +- Endpoint 0, the default control endpoint. +- Any number of interrupt- or bulk-out endpoints. The data is sent to + usbFunctionWriteOut() and USB_CFG_IMPLEMENT_FN_WRITEOUT must be defined + to 1 to activate this feature. The endpoint number can be found in the + global variable 'usbRxToken'. +- One default interrupt- or bulk-in endpoint. This endpoint is used for + interrupt- or bulk-in transfers which are not handled by any other endpoint. + You must define USB_CFG_HAVE_INTRIN_ENDPOINT in order to activate this + feature and call usbSetInterrupt() to send interrupt/bulk data. +- One additional interrupt- or bulk-in endpoint. This was endpoint 3 in + previous versions of this driver but can now be configured to any endpoint + number. You must define USB_CFG_HAVE_INTRIN_ENDPOINT3 in order to activate + this feature and call usbSetInterrupt3() to send interrupt/bulk data. The + endpoint number can be set with USB_CFG_EP3_NUMBER. + +Please note that the USB standard forbids bulk endpoints for low speed devices! +Most operating systems allow them anyway, but the AVR will spend 90% of the CPU +time in the USB interrupt polling for bulk data. + +Maximum data payload: +Data payload of control in and out transfers may be up to 254 bytes. In order +to accept payload data of out transfers, you need to implement +'usbFunctionWrite()'. + +USB Suspend Mode supply current: +The USB standard limits power consumption to 500uA when the bus is in suspend +mode. This is not a problem for self-powered devices since they don't need +bus power anyway. Bus-powered devices can achieve this only by putting the +CPU in sleep mode. The driver does not implement suspend handling by itself. +However, the application may implement activity monitoring and wakeup from +sleep. The host sends regular SE0 states on the bus to keep it active. These +SE0 states can be detected by using D- as the interrupt source. Define +USB_COUNT_SOF to 1 and use the global variable usbSofCount to check for bus +activity. + +Operation without an USB master: +The driver behaves neutral without connection to an USB master if D- reads +as 1. To avoid spurious interrupts, we recommend a high impedance (e.g. 1M) +pull-down or pull-up resistor on D+ (interrupt). If Zener diodes are used, +use a pull-down. If D- becomes statically 0, the driver may block in the +interrupt routine. + +Interrupt latency: +The application must ensure that the USB interrupt is not disabled for more +than 25 cycles (this is for 12 MHz, faster clocks allow longer latency). +This implies that all interrupt routines must either have the "ISR_NOBLOCK" +attribute set (see "avr/interrupt.h") or be written in assembler with "sei" +as the first instruction. + +Maximum interrupt duration / CPU cycle consumption: +The driver handles all USB communication during the interrupt service +routine. The routine will not return before an entire USB message is received +and the reply is sent. This may be up to ca. 1200 cycles @ 12 MHz (= 100us) if +the host conforms to the standard. The driver will consume CPU cycles for all +USB messages, even if they address another (low-speed) device on the same bus. + +*/ + +/* ------------------------------------------------------------------------- */ +/* --------------------------- Module Interface ---------------------------- */ +/* ------------------------------------------------------------------------- */ + +#define USBDRV_VERSION 20100715 +/* This define uniquely identifies a driver version. It is a decimal number + * constructed from the driver's release date in the form YYYYMMDD. If the + * driver's behavior or interface changes, you can use this constant to + * distinguish versions. If it is not defined, the driver's release date is + * older than 2006-01-25. + */ + + +#ifndef USB_PUBLIC +#define USB_PUBLIC +#endif +/* USB_PUBLIC is used as declaration attribute for all functions exported by + * the USB driver. The default is no attribute (see above). You may define it + * to static either in usbconfig.h or from the command line if you include + * usbdrv.c instead of linking against it. Including the C module of the driver + * directly in your code saves a couple of bytes in flash memory. + */ + +#ifndef __ASSEMBLER__ +#ifndef uchar +#define uchar unsigned char +#endif +#ifndef schar +#define schar signed char +#endif +/* shortcuts for well defined 8 bit integer types */ + +#if USB_CFG_LONG_TRANSFERS /* if more than 254 bytes transfer size required */ +# define usbMsgLen_t unsigned +#else +# define usbMsgLen_t uchar +#endif +/* usbMsgLen_t is the data type used for transfer lengths. By default, it is + * defined to uchar, allowing a maximum of 254 bytes (255 is reserved for + * USB_NO_MSG below). If the usbconfig.h defines USB_CFG_LONG_TRANSFERS to 1, + * a 16 bit data type is used, allowing up to 16384 bytes (the rest is used + * for flags in the descriptor configuration). + */ +#define USB_NO_MSG ((usbMsgLen_t)-1) /* constant meaning "no message" */ + +struct usbRequest; /* forward declaration */ + +USB_PUBLIC void usbInit(void); +/* This function must be called before interrupts are enabled and the main + * loop is entered. We exepct that the PORT and DDR bits for D+ and D- have + * not been changed from their default status (which is 0). If you have changed + * them, set both back to 0 (configure them as input with no internal pull-up). + */ +USB_PUBLIC void usbPoll(void); +/* This function must be called at regular intervals from the main loop. + * Maximum delay between calls is somewhat less than 50ms (USB timeout for + * accepting a Setup message). Otherwise the device will not be recognized. + * Please note that debug outputs through the UART take ~ 0.5ms per byte + * at 19200 bps. + */ +extern uchar *usbMsgPtr; +/* This variable may be used to pass transmit data to the driver from the + * implementation of usbFunctionWrite(). It is also used internally by the + * driver for standard control requests. + */ +USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8]); +/* This function is called when the driver receives a SETUP transaction from + * the host which is not answered by the driver itself (in practice: class and + * vendor requests). All control transfers start with a SETUP transaction where + * the host communicates the parameters of the following (optional) data + * transfer. The SETUP data is available in the 'data' parameter which can + * (and should) be casted to 'usbRequest_t *' for a more user-friendly access + * to parameters. + * + * If the SETUP indicates a control-in transfer, you should provide the + * requested data to the driver. There are two ways to transfer this data: + * (1) Set the global pointer 'usbMsgPtr' to the base of the static RAM data + * block and return the length of the data in 'usbFunctionSetup()'. The driver + * will handle the rest. Or (2) return USB_NO_MSG in 'usbFunctionSetup()'. The + * driver will then call 'usbFunctionRead()' when data is needed. See the + * documentation for usbFunctionRead() for details. + * + * If the SETUP indicates a control-out transfer, the only way to receive the + * data from the host is through the 'usbFunctionWrite()' call. If you + * implement this function, you must return USB_NO_MSG in 'usbFunctionSetup()' + * to indicate that 'usbFunctionWrite()' should be used. See the documentation + * of this function for more information. If you just want to ignore the data + * sent by the host, return 0 in 'usbFunctionSetup()'. + * + * Note that calls to the functions usbFunctionRead() and usbFunctionWrite() + * are only done if enabled by the configuration in usbconfig.h. + */ +USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq); +/* You need to implement this function ONLY if you provide USB descriptors at + * runtime (which is an expert feature). It is very similar to + * usbFunctionSetup() above, but it is called only to request USB descriptor + * data. See the documentation of usbFunctionSetup() above for more info. + */ +#if USB_CFG_HAVE_INTRIN_ENDPOINT +USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len); +/* This function sets the message which will be sent during the next interrupt + * IN transfer. The message is copied to an internal buffer and must not exceed + * a length of 8 bytes. The message may be 0 bytes long just to indicate the + * interrupt status to the host. + * If you need to transfer more bytes, use a control read after the interrupt. + */ +#define usbInterruptIsReady() (usbTxLen1 & 0x10) +/* This macro indicates whether the last interrupt message has already been + * sent. If you set a new interrupt message before the old was sent, the + * message already buffered will be lost. + */ +#if USB_CFG_HAVE_INTRIN_ENDPOINT3 +USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len); +#define usbInterruptIsReady3() (usbTxLen3 & 0x10) +/* Same as above for endpoint 3 */ +#endif +#endif /* USB_CFG_HAVE_INTRIN_ENDPOINT */ +#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* simplified interface for backward compatibility */ +#define usbHidReportDescriptor usbDescriptorHidReport +/* should be declared as: PROGMEM char usbHidReportDescriptor[]; */ +/* If you implement an HID device, you need to provide a report descriptor. + * The HID report descriptor syntax is a bit complex. If you understand how + * report descriptors are constructed, we recommend that you use the HID + * Descriptor Tool from usb.org, see http://www.usb.org/developers/hidpage/. + * Otherwise you should probably start with a working example. + */ +#endif /* USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH */ +#if USB_CFG_IMPLEMENT_FN_WRITE +USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len); +/* This function is called by the driver to provide a control transfer's + * payload data (control-out). It is called in chunks of up to 8 bytes. The + * total count provided in the current control transfer can be obtained from + * the 'length' property in the setup data. If an error occurred during + * processing, return 0xff (== -1). The driver will answer the entire transfer + * with a STALL token in this case. If you have received the entire payload + * successfully, return 1. If you expect more data, return 0. If you don't + * know whether the host will send more data (you should know, the total is + * provided in the usbFunctionSetup() call!), return 1. + * NOTE: If you return 0xff for STALL, 'usbFunctionWrite()' may still be called + * for the remaining data. You must continue to return 0xff for STALL in these + * calls. + * In order to get usbFunctionWrite() called, define USB_CFG_IMPLEMENT_FN_WRITE + * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. + */ +#endif /* USB_CFG_IMPLEMENT_FN_WRITE */ +#if USB_CFG_IMPLEMENT_FN_READ +USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len); +/* This function is called by the driver to ask the application for a control + * transfer's payload data (control-in). It is called in chunks of up to 8 + * bytes each. You should copy the data to the location given by 'data' and + * return the actual number of bytes copied. If you return less than requested, + * the control-in transfer is terminated. If you return 0xff, the driver aborts + * the transfer with a STALL token. + * In order to get usbFunctionRead() called, define USB_CFG_IMPLEMENT_FN_READ + * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. + */ +#endif /* USB_CFG_IMPLEMENT_FN_READ */ + +extern uchar usbRxToken; /* may be used in usbFunctionWriteOut() below */ +#if USB_CFG_IMPLEMENT_FN_WRITEOUT +USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len); +/* This function is called by the driver when data is received on an interrupt- + * or bulk-out endpoint. The endpoint number can be found in the global + * variable usbRxToken. You must define USB_CFG_IMPLEMENT_FN_WRITEOUT to 1 in + * usbconfig.h to get this function called. + */ +#endif /* USB_CFG_IMPLEMENT_FN_WRITEOUT */ +#ifdef USB_CFG_PULLUP_IOPORTNAME +#define usbDeviceConnect() ((USB_PULLUP_DDR |= (1<device, 1=device->host + * t ..... type: 0=standard, 1=class, 2=vendor, 3=reserved + * r ..... recipient: 0=device, 1=interface, 2=endpoint, 3=other + */ + +/* USB setup recipient values */ +#define USBRQ_RCPT_MASK 0x1f +#define USBRQ_RCPT_DEVICE 0 +#define USBRQ_RCPT_INTERFACE 1 +#define USBRQ_RCPT_ENDPOINT 2 + +/* USB request type values */ +#define USBRQ_TYPE_MASK 0x60 +#define USBRQ_TYPE_STANDARD (0<<5) +#define USBRQ_TYPE_CLASS (1<<5) +#define USBRQ_TYPE_VENDOR (2<<5) + +/* USB direction values: */ +#define USBRQ_DIR_MASK 0x80 +#define USBRQ_DIR_HOST_TO_DEVICE (0<<7) +#define USBRQ_DIR_DEVICE_TO_HOST (1<<7) + +/* USB Standard Requests */ +#define USBRQ_GET_STATUS 0 +#define USBRQ_CLEAR_FEATURE 1 +#define USBRQ_SET_FEATURE 3 +#define USBRQ_SET_ADDRESS 5 +#define USBRQ_GET_DESCRIPTOR 6 +#define USBRQ_SET_DESCRIPTOR 7 +#define USBRQ_GET_CONFIGURATION 8 +#define USBRQ_SET_CONFIGURATION 9 +#define USBRQ_GET_INTERFACE 10 +#define USBRQ_SET_INTERFACE 11 +#define USBRQ_SYNCH_FRAME 12 + +/* USB descriptor constants */ +#define USBDESCR_DEVICE 1 +#define USBDESCR_CONFIG 2 +#define USBDESCR_STRING 3 +#define USBDESCR_INTERFACE 4 +#define USBDESCR_ENDPOINT 5 +#define USBDESCR_HID 0x21 +#define USBDESCR_HID_REPORT 0x22 +#define USBDESCR_HID_PHYS 0x23 + +//#define USBATTR_BUSPOWER 0x80 // USB 1.1 does not define this value any more +#define USBATTR_SELFPOWER 0x40 +#define USBATTR_REMOTEWAKE 0x20 + +/* USB HID Requests */ +#define USBRQ_HID_GET_REPORT 0x01 +#define USBRQ_HID_GET_IDLE 0x02 +#define USBRQ_HID_GET_PROTOCOL 0x03 +#define USBRQ_HID_SET_REPORT 0x09 +#define USBRQ_HID_SET_IDLE 0x0a +#define USBRQ_HID_SET_PROTOCOL 0x0b + +/* ------------------------------------------------------------------------- */ + +#endif /* __usbdrv_h_included__ */ diff --git a/adb2usb/uart2usb/usbdrv/usbdrvasm.S b/adb2usb/uart2usb/usbdrv/usbdrvasm.S new file mode 100644 index 0000000..45fcf18 --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/usbdrvasm.S @@ -0,0 +1,393 @@ +/* Name: usbdrvasm.S + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2007-06-13 + * Tabsize: 4 + * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Revision: $Id: usbdrvasm.S 785 2010-05-30 17:57:07Z cs $ + */ + +/* +General Description: +This module is the assembler part of the USB driver. This file contains +general code (preprocessor acrobatics and CRC computation) and then includes +the file appropriate for the given clock rate. +*/ + +#define __SFR_OFFSET 0 /* used by avr-libc's register definitions */ +#include "usbportability.h" +#include "usbdrv.h" /* for common defs */ + +/* register names */ +#define x1 r16 +#define x2 r17 +#define shift r18 +#define cnt r19 +#define x3 r20 +#define x4 r21 +#define x5 r22 +#define bitcnt x5 +#define phase x4 +#define leap x4 + +/* Some assembler dependent definitions and declarations: */ + +#ifdef __IAR_SYSTEMS_ASM__ + extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset + extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen + extern usbTxBuf, usbTxStatus1, usbTxStatus3 +# if USB_COUNT_SOF + extern usbSofCount +# endif + public usbCrc16 + public usbCrc16Append + + COMMON INTVEC +# ifndef USB_INTR_VECTOR + ORG INT0_vect +# else /* USB_INTR_VECTOR */ + ORG USB_INTR_VECTOR +# undef USB_INTR_VECTOR +# endif /* USB_INTR_VECTOR */ +# define USB_INTR_VECTOR usbInterruptHandler + rjmp USB_INTR_VECTOR + RSEG CODE + +#else /* __IAR_SYSTEMS_ASM__ */ + +# ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */ +# ifdef INT0_vect +# define USB_INTR_VECTOR INT0_vect // this is the "new" define for the vector +# else +# define USB_INTR_VECTOR SIG_INTERRUPT0 // this is the "old" vector +# endif +# endif + .text + .global USB_INTR_VECTOR + .type USB_INTR_VECTOR, @function + .global usbCrc16 + .global usbCrc16Append +#endif /* __IAR_SYSTEMS_ASM__ */ + + +#if USB_INTR_PENDING < 0x40 /* This is an I/O address, use in and out */ +# define USB_LOAD_PENDING(reg) in reg, USB_INTR_PENDING +# define USB_STORE_PENDING(reg) out USB_INTR_PENDING, reg +#else /* It's a memory address, use lds and sts */ +# define USB_LOAD_PENDING(reg) lds reg, USB_INTR_PENDING +# define USB_STORE_PENDING(reg) sts USB_INTR_PENDING, reg +#endif + +#define usbTxLen1 usbTxStatus1 +#define usbTxBuf1 (usbTxStatus1 + 1) +#define usbTxLen3 usbTxStatus3 +#define usbTxBuf3 (usbTxStatus3 + 1) + + +;---------------------------------------------------------------------------- +; Utility functions +;---------------------------------------------------------------------------- + +#ifdef __IAR_SYSTEMS_ASM__ +/* Register assignments for usbCrc16 on IAR cc */ +/* Calling conventions on IAR: + * First parameter passed in r16/r17, second in r18/r19 and so on. + * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) + * Result is passed in r16/r17 + * In case of the "tiny" memory model, pointers are only 8 bit with no + * padding. We therefore pass argument 1 as "16 bit unsigned". + */ +RTMODEL "__rt_version", "3" +/* The line above will generate an error if cc calling conventions change. + * The value "3" above is valid for IAR 4.10B/W32 + */ +# define argLen r18 /* argument 2 */ +# define argPtrL r16 /* argument 1 */ +# define argPtrH r17 /* argument 1 */ + +# define resCrcL r16 /* result */ +# define resCrcH r17 /* result */ + +# define ptrL ZL +# define ptrH ZH +# define ptr Z +# define byte r22 +# define bitCnt r19 +# define polyL r20 +# define polyH r21 +# define scratch r23 + +#else /* __IAR_SYSTEMS_ASM__ */ +/* Register assignments for usbCrc16 on gcc */ +/* Calling conventions on gcc: + * First parameter passed in r24/r25, second in r22/23 and so on. + * Callee must preserve r1-r17, r28/r29 + * Result is passed in r24/r25 + */ +# define argLen r22 /* argument 2 */ +# define argPtrL r24 /* argument 1 */ +# define argPtrH r25 /* argument 1 */ + +# define resCrcL r24 /* result */ +# define resCrcH r25 /* result */ + +# define ptrL XL +# define ptrH XH +# define ptr x +# define byte r18 +# define bitCnt r19 +# define polyL r20 +# define polyH r21 +# define scratch r23 + +#endif + +#if USB_USE_FAST_CRC + +; This implementation is faster, but has bigger code size +; Thanks to Slawomir Fras (BoskiDialer) for this code! +; It implements the following C pseudo-code: +; unsigned table(unsigned char x) +; { +; unsigned value; +; +; value = (unsigned)x << 6; +; value ^= (unsigned)x << 7; +; if(parity(x)) +; value ^= 0xc001; +; return value; +; } +; unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen) +; { +; unsigned crc = 0xffff; +; +; while(argLen--) +; crc = table(lo8(crc) ^ *argPtr++) ^ hi8(crc); +; return ~crc; +; } + +; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen); +; argPtr r24+25 / r16+r17 +; argLen r22 / r18 +; temp variables: +; byte r18 / r22 +; scratch r23 +; resCrc r24+r25 / r16+r17 +; ptr X / Z +usbCrc16: + mov ptrL, argPtrL + mov ptrH, argPtrH + ldi resCrcL, 0xFF + ldi resCrcH, 0xFF + rjmp usbCrc16LoopTest +usbCrc16ByteLoop: + ld byte, ptr+ + eor resCrcL, byte ; resCrcL is now 'x' in table() + mov byte, resCrcL ; compute parity of 'x' + swap byte + eor byte, resCrcL + mov scratch, byte + lsr byte + lsr byte + eor byte, scratch + inc byte + lsr byte + andi byte, 1 ; byte is now parity(x) + mov scratch, resCrcL + mov resCrcL, resCrcH + eor resCrcL, byte ; low byte of if(parity(x)) value ^= 0xc001; + neg byte + andi byte, 0xc0 + mov resCrcH, byte ; high byte of if(parity(x)) value ^= 0xc001; + clr byte + lsr scratch + ror byte + eor resCrcH, scratch + eor resCrcL, byte + lsr scratch + ror byte + eor resCrcH, scratch + eor resCrcL, byte +usbCrc16LoopTest: + subi argLen, 1 + brsh usbCrc16ByteLoop + com resCrcL + com resCrcH + ret + +#else /* USB_USE_FAST_CRC */ + +; This implementation is slower, but has less code size +; +; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen); +; argPtr r24+25 / r16+r17 +; argLen r22 / r18 +; temp variables: +; byte r18 / r22 +; bitCnt r19 +; poly r20+r21 +; scratch r23 +; resCrc r24+r25 / r16+r17 +; ptr X / Z +usbCrc16: + mov ptrL, argPtrL + mov ptrH, argPtrH + ldi resCrcL, 0 + ldi resCrcH, 0 + ldi polyL, lo8(0xa001) + ldi polyH, hi8(0xa001) + com argLen ; argLen = -argLen - 1: modified loop to ensure that carry is set + ldi bitCnt, 0 ; loop counter with starnd condition = end condition + rjmp usbCrcLoopEntry +usbCrcByteLoop: + ld byte, ptr+ + eor resCrcL, byte +usbCrcBitLoop: + ror resCrcH ; carry is always set here (see brcs jumps to here) + ror resCrcL + brcs usbCrcNoXor + eor resCrcL, polyL + eor resCrcH, polyH +usbCrcNoXor: + subi bitCnt, 224 ; (8 * 224) % 256 = 0; this loop iterates 8 times + brcs usbCrcBitLoop +usbCrcLoopEntry: + subi argLen, -1 + brcs usbCrcByteLoop +usbCrcReady: + ret +; Thanks to Reimar Doeffinger for optimizing this CRC routine! + +#endif /* USB_USE_FAST_CRC */ + +; extern unsigned usbCrc16Append(unsigned char *data, unsigned char len); +usbCrc16Append: + rcall usbCrc16 + st ptr+, resCrcL + st ptr+, resCrcH + ret + +#undef argLen +#undef argPtrL +#undef argPtrH +#undef resCrcL +#undef resCrcH +#undef ptrL +#undef ptrH +#undef ptr +#undef byte +#undef bitCnt +#undef polyL +#undef polyH +#undef scratch + + +#if USB_CFG_HAVE_MEASURE_FRAME_LENGTH +#ifdef __IAR_SYSTEMS_ASM__ +/* Register assignments for usbMeasureFrameLength on IAR cc */ +/* Calling conventions on IAR: + * First parameter passed in r16/r17, second in r18/r19 and so on. + * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) + * Result is passed in r16/r17 + * In case of the "tiny" memory model, pointers are only 8 bit with no + * padding. We therefore pass argument 1 as "16 bit unsigned". + */ +# define resL r16 +# define resH r17 +# define cnt16L r30 +# define cnt16H r31 +# define cntH r18 + +#else /* __IAR_SYSTEMS_ASM__ */ +/* Register assignments for usbMeasureFrameLength on gcc */ +/* Calling conventions on gcc: + * First parameter passed in r24/r25, second in r22/23 and so on. + * Callee must preserve r1-r17, r28/r29 + * Result is passed in r24/r25 + */ +# define resL r24 +# define resH r25 +# define cnt16L r24 +# define cnt16H r25 +# define cntH r26 +#endif +# define cnt16 cnt16L + +; extern unsigned usbMeasurePacketLength(void); +; returns time between two idle strobes in multiples of 7 CPU clocks +.global usbMeasureFrameLength +usbMeasureFrameLength: + ldi cntH, 6 ; wait ~ 10 ms for D- == 0 + clr cnt16L + clr cnt16H +usbMFTime16: + dec cntH + breq usbMFTimeout +usbMFWaitStrobe: ; first wait for D- == 0 (idle strobe) + sbiw cnt16, 1 ;[0] [6] + breq usbMFTime16 ;[2] + sbic USBIN, USBMINUS ;[3] + rjmp usbMFWaitStrobe ;[4] +usbMFWaitIdle: ; then wait until idle again + sbis USBIN, USBMINUS ;1 wait for D- == 1 + rjmp usbMFWaitIdle ;2 + ldi cnt16L, 1 ;1 represents cycles so far + clr cnt16H ;1 +usbMFWaitLoop: + in cntH, USBIN ;[0] [7] + adiw cnt16, 1 ;[1] + breq usbMFTimeout ;[3] + andi cntH, USBMASK ;[4] + brne usbMFWaitLoop ;[5] +usbMFTimeout: +#if resL != cnt16L + mov resL, cnt16L + mov resH, cnt16H +#endif + ret + +#undef resL +#undef resH +#undef cnt16 +#undef cnt16L +#undef cnt16H +#undef cntH + +#endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ + +;---------------------------------------------------------------------------- +; Now include the clock rate specific code +;---------------------------------------------------------------------------- + +#ifndef USB_CFG_CLOCK_KHZ +# ifdef F_CPU +# define USB_CFG_CLOCK_KHZ (F_CPU/1000) +# else +# error "USB_CFG_CLOCK_KHZ not defined in usbconfig.h and no F_CPU set!" +# endif +#endif + +#if USB_CFG_CHECK_CRC /* separate dispatcher for CRC type modules */ +# if USB_CFG_CLOCK_KHZ == 18000 +# include "usbdrvasm18-crc.inc" +# else +# error "USB_CFG_CLOCK_KHZ is not one of the supported crc-rates!" +# endif +#else /* USB_CFG_CHECK_CRC */ +# if USB_CFG_CLOCK_KHZ == 12000 +# include "usbdrvasm12.inc" +# elif USB_CFG_CLOCK_KHZ == 12800 +# include "usbdrvasm128.inc" +# elif USB_CFG_CLOCK_KHZ == 15000 +# include "usbdrvasm15.inc" +# elif USB_CFG_CLOCK_KHZ == 16000 +# include "usbdrvasm16.inc" +# elif USB_CFG_CLOCK_KHZ == 16500 +# include "usbdrvasm165.inc" +# elif USB_CFG_CLOCK_KHZ == 20000 +# include "usbdrvasm20.inc" +# else +# error "USB_CFG_CLOCK_KHZ is not one of the supported non-crc-rates!" +# endif +#endif /* USB_CFG_CHECK_CRC */ diff --git a/adb2usb/uart2usb/usbdrv/usbdrvasm.asm b/adb2usb/uart2usb/usbdrv/usbdrvasm.asm new file mode 100644 index 0000000..9cc4e4d --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/usbdrvasm.asm @@ -0,0 +1,21 @@ +/* Name: usbdrvasm.asm + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2006-03-01 + * Tabsize: 4 + * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id$ + */ + +/* +General Description: +The IAR compiler/assembler system prefers assembler files with file extension +".asm". We simply provide this file as an alias for usbdrvasm.S. + +Thanks to Oleg Semyonov for his help with the IAR tools port! +*/ + +#include "usbdrvasm.S" + +end diff --git a/adb2usb/uart2usb/usbdrv/usbdrvasm12.inc b/adb2usb/uart2usb/usbdrv/usbdrvasm12.inc new file mode 100644 index 0000000..c116758 --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/usbdrvasm12.inc @@ -0,0 +1,393 @@ +/* Name: usbdrvasm12.inc + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2004-12-29 + * Tabsize: 4 + * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbdrvasm12.inc 740 2009-04-13 18:23:31Z cs $ + */ + +/* Do not link this file! Link usbdrvasm.S instead, which includes the + * appropriate implementation! + */ + +/* +General Description: +This file is the 12 MHz version of the asssembler part of the USB driver. It +requires a 12 MHz crystal (not a ceramic resonator and not a calibrated RC +oscillator). + +See usbdrv.h for a description of the entire driver. + +Since almost all of this code is timing critical, don't change unless you +really know what you are doing! Many parts require not only a maximum number +of CPU cycles, but even an exact number of cycles! + + +Timing constraints according to spec (in bit times): +timing subject min max CPUcycles +--------------------------------------------------------------------------- +EOP of OUT/SETUP to sync pattern of DATA0 (both rx) 2 16 16-128 +EOP of IN to sync pattern of DATA0 (rx, then tx) 2 7.5 16-60 +DATAx (rx) to ACK/NAK/STALL (tx) 2 7.5 16-60 +*/ + +;Software-receiver engine. Strict timing! Don't change unless you can preserve timing! +;interrupt response time: 4 cycles + insn running = 7 max if interrupts always enabled +;max allowable interrupt latency: 34 cycles -> max 25 cycles interrupt disable +;max stack usage: [ret(2), YL, SREG, YH, shift, x1, x2, x3, cnt, x4] = 11 bytes +;Numbers in brackets are maximum cycles since SOF. +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG [sofError], YH, shift, x1, x2, x3, cnt + push YL ;2 [35] push only what is necessary to sync with edge ASAP + in YL, SREG ;1 [37] + push YL ;2 [39] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of 1/4 bit which meets the spec. + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: +;{3, 5} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling] +;we have 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push YH ;2 [2] + lds YL, usbInputBufOffset;2 [4] + clr YH ;1 [5] + subi YL, lo8(-(usbRxBuf));1 [6] + sbci YH, hi8(-(usbRxBuf));1 [7] + + sbis USBIN, USBMINUS ;1 [8] we want two bits K [sample 1 cycle too early] + rjmp haveTwoBitsK ;2 [10] + pop YH ;2 [11] undo the push from before + rjmp waitForK ;2 [13] this was not the end of sync, retry +haveTwoBitsK: +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- + push shift ;2 [16] + push x1 ;2 [12] + push x2 ;2 [14] + + in x1, USBIN ;1 [17] <-- sample bit 0 + ldi shift, 0xff ;1 [18] + bst x1, USBMINUS ;1 [19] + bld shift, 0 ;1 [20] + push x3 ;2 [22] + push cnt ;2 [24] + + in x2, USBIN ;1 [25] <-- sample bit 1 + ser x3 ;1 [26] [inserted init instruction] + eor x1, x2 ;1 [27] + bst x1, USBMINUS ;1 [28] + bld shift, 1 ;1 [29] + ldi cnt, USB_BUFSIZE;1 [30] [inserted init instruction] + rjmp rxbit2 ;2 [32] + +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- + +unstuff0: ;1 (branch taken) + andi x3, ~0x01 ;1 [15] + mov x1, x2 ;1 [16] x2 contains last sampled (stuffed) bit + in x2, USBIN ;1 [17] <-- sample bit 1 again + ori shift, 0x01 ;1 [18] + rjmp didUnstuff0 ;2 [20] + +unstuff1: ;1 (branch taken) + mov x2, x1 ;1 [21] x1 contains last sampled (stuffed) bit + andi x3, ~0x02 ;1 [22] + ori shift, 0x02 ;1 [23] + nop ;1 [24] + in x1, USBIN ;1 [25] <-- sample bit 2 again + rjmp didUnstuff1 ;2 [27] + +unstuff2: ;1 (branch taken) + andi x3, ~0x04 ;1 [29] + ori shift, 0x04 ;1 [30] + mov x1, x2 ;1 [31] x2 contains last sampled (stuffed) bit + nop ;1 [32] + in x2, USBIN ;1 [33] <-- sample bit 3 + rjmp didUnstuff2 ;2 [35] + +unstuff3: ;1 (branch taken) + in x2, USBIN ;1 [34] <-- sample stuffed bit 3 [one cycle too late] + andi x3, ~0x08 ;1 [35] + ori shift, 0x08 ;1 [36] + rjmp didUnstuff3 ;2 [38] + +unstuff4: ;1 (branch taken) + andi x3, ~0x10 ;1 [40] + in x1, USBIN ;1 [41] <-- sample stuffed bit 4 + ori shift, 0x10 ;1 [42] + rjmp didUnstuff4 ;2 [44] + +unstuff5: ;1 (branch taken) + andi x3, ~0x20 ;1 [48] + in x2, USBIN ;1 [49] <-- sample stuffed bit 5 + ori shift, 0x20 ;1 [50] + rjmp didUnstuff5 ;2 [52] + +unstuff6: ;1 (branch taken) + andi x3, ~0x40 ;1 [56] + in x1, USBIN ;1 [57] <-- sample stuffed bit 6 + ori shift, 0x40 ;1 [58] + rjmp didUnstuff6 ;2 [60] + +; extra jobs done during bit interval: +; bit 0: store, clear [SE0 is unreliable here due to bit dribbling in hubs] +; bit 1: se0 check +; bit 2: overflow check +; bit 3: recovery from delay [bit 0 tasks took too long] +; bit 4: none +; bit 5: none +; bit 6: none +; bit 7: jump, eor +rxLoop: + eor x3, shift ;1 [0] reconstruct: x3 is 0 at bit locations we changed, 1 at others + in x1, USBIN ;1 [1] <-- sample bit 0 + st y+, x3 ;2 [3] store data + ser x3 ;1 [4] + nop ;1 [5] + eor x2, x1 ;1 [6] + bst x2, USBMINUS;1 [7] + bld shift, 0 ;1 [8] + in x2, USBIN ;1 [9] <-- sample bit 1 (or possibly bit 0 stuffed) + andi x2, USBMASK ;1 [10] + breq se0 ;1 [11] SE0 check for bit 1 + andi shift, 0xf9 ;1 [12] +didUnstuff0: + breq unstuff0 ;1 [13] + eor x1, x2 ;1 [14] + bst x1, USBMINUS;1 [15] + bld shift, 1 ;1 [16] +rxbit2: + in x1, USBIN ;1 [17] <-- sample bit 2 (or possibly bit 1 stuffed) + andi shift, 0xf3 ;1 [18] + breq unstuff1 ;1 [19] do remaining work for bit 1 +didUnstuff1: + subi cnt, 1 ;1 [20] + brcs overflow ;1 [21] loop control + eor x2, x1 ;1 [22] + bst x2, USBMINUS;1 [23] + bld shift, 2 ;1 [24] + in x2, USBIN ;1 [25] <-- sample bit 3 (or possibly bit 2 stuffed) + andi shift, 0xe7 ;1 [26] + breq unstuff2 ;1 [27] +didUnstuff2: + eor x1, x2 ;1 [28] + bst x1, USBMINUS;1 [29] + bld shift, 3 ;1 [30] +didUnstuff3: + andi shift, 0xcf ;1 [31] + breq unstuff3 ;1 [32] + in x1, USBIN ;1 [33] <-- sample bit 4 + eor x2, x1 ;1 [34] + bst x2, USBMINUS;1 [35] + bld shift, 4 ;1 [36] +didUnstuff4: + andi shift, 0x9f ;1 [37] + breq unstuff4 ;1 [38] + nop2 ;2 [40] + in x2, USBIN ;1 [41] <-- sample bit 5 + eor x1, x2 ;1 [42] + bst x1, USBMINUS;1 [43] + bld shift, 5 ;1 [44] +didUnstuff5: + andi shift, 0x3f ;1 [45] + breq unstuff5 ;1 [46] + nop2 ;2 [48] + in x1, USBIN ;1 [49] <-- sample bit 6 + eor x2, x1 ;1 [50] + bst x2, USBMINUS;1 [51] + bld shift, 6 ;1 [52] +didUnstuff6: + cpi shift, 0x02 ;1 [53] + brlo unstuff6 ;1 [54] + nop2 ;2 [56] + in x2, USBIN ;1 [57] <-- sample bit 7 + eor x1, x2 ;1 [58] + bst x1, USBMINUS;1 [59] + bld shift, 7 ;1 [60] +didUnstuff7: + cpi shift, 0x04 ;1 [61] + brsh rxLoop ;2 [63] loop control +unstuff7: + andi x3, ~0x80 ;1 [63] + ori shift, 0x80 ;1 [64] + in x2, USBIN ;1 [65] <-- sample stuffed bit 7 + nop ;1 [66] + rjmp didUnstuff7 ;2 [68] + +macro POP_STANDARD ; 12 cycles + pop cnt + pop x3 + pop x2 + pop x1 + pop shift + pop YH + endm +macro POP_RETI ; 5 cycles + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + +;---------------------------------------------------------------------------- +; Transmitting data +;---------------------------------------------------------------------------- + +txByteLoop: +txBitloop: +stuffN1Delay: ; [03] + ror shift ;[-5] [11] [59] + brcc doExorN1 ;[-4] [60] + subi x4, 1 ;[-3] + brne commonN1 ;[-2] + lsl shift ;[-1] compensate ror after rjmp stuffDelay + nop ;[00] stuffing consists of just waiting 8 cycles + rjmp stuffN1Delay ;[01] after ror, C bit is reliably clear + +sendNakAndReti: ;0 [-19] 19 cycles until SOP + ldi x3, USBPID_NAK ;1 [-18] + rjmp usbSendX3 ;2 [-16] +sendAckAndReti: ;0 [-19] 19 cycles until SOP + ldi x3, USBPID_ACK ;1 [-18] + rjmp usbSendX3 ;2 [-16] +sendCntAndReti: ;0 [-17] 17 cycles until SOP + mov x3, cnt ;1 [-16] +usbSendX3: ;0 [-16] + ldi YL, 20 ;1 [-15] 'x3' is R20 + ldi YH, 0 ;1 [-14] + ldi cnt, 2 ;1 [-13] +; rjmp usbSendAndReti fallthrough + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) or USBOUT = 0x01 +; K = (D+ = 1), (D- = 0) or USBOUT = 0x02 +; Spec allows 7.5 bit times from EOP to SOP for replies (= 60 cycles) + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte +;uses: x1...x2, x4, shift, cnt, Y [x1 = mirror USBOUT, x2 = USBMASK, x4 = bitstuff cnt] +;Numbers in brackets are time since first bit of sync pattern is sent (start of instruction) +usbSendAndReti: + in x2, USBDDR ;[-12] 12 cycles until SOP + ori x2, USBMASK ;[-11] + sbi USBOUT, USBMINUS ;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) + out USBDDR, x2 ;[-8] <--- acquire bus + in x1, USBOUT ;[-7] port mirror for tx loop + ldi shift, 0x40 ;[-6] sync byte is first byte sent (we enter loop after ror) + ldi x2, USBMASK ;[-5] + push x4 ;[-4] +doExorN1: + eor x1, x2 ;[-2] [06] [62] + ldi x4, 6 ;[-1] [07] [63] +commonN1: +stuffN2Delay: + out USBOUT, x1 ;[00] [08] [64] <--- set bit + ror shift ;[01] + brcc doExorN2 ;[02] + subi x4, 1 ;[03] + brne commonN2 ;[04] + lsl shift ;[05] compensate ror after rjmp stuffDelay + rjmp stuffN2Delay ;[06] after ror, C bit is reliably clear +doExorN2: + eor x1, x2 ;[04] [12] + ldi x4, 6 ;[05] [13] +commonN2: + nop ;[06] [14] + subi cnt, 171 ;[07] [15] trick: (3 * 171) & 0xff = 1 + out USBOUT, x1 ;[08] [16] <--- set bit + brcs txBitloop ;[09] [25] [41] + +stuff6Delay: + ror shift ;[42] [50] + brcc doExor6 ;[43] + subi x4, 1 ;[44] + brne common6 ;[45] + lsl shift ;[46] compensate ror after rjmp stuffDelay + nop ;[47] stuffing consists of just waiting 8 cycles + rjmp stuff6Delay ;[48] after ror, C bit is reliably clear +doExor6: + eor x1, x2 ;[45] [53] + ldi x4, 6 ;[46] +common6: +stuff7Delay: + ror shift ;[47] [55] + out USBOUT, x1 ;[48] <--- set bit + brcc doExor7 ;[49] + subi x4, 1 ;[50] + brne common7 ;[51] + lsl shift ;[52] compensate ror after rjmp stuffDelay + rjmp stuff7Delay ;[53] after ror, C bit is reliably clear +doExor7: + eor x1, x2 ;[51] [59] + ldi x4, 6 ;[52] +common7: + ld shift, y+ ;[53] + tst cnt ;[55] + out USBOUT, x1 ;[56] <--- set bit + brne txByteLoop ;[57] + +;make SE0: + cbr x1, USBMASK ;[58] prepare SE0 [spec says EOP may be 15 to 18 cycles] + lds x2, usbNewDeviceAddr;[59] + lsl x2 ;[61] we compare with left shifted address + subi YL, 2 + 20 ;[62] Only assign address on data packets, not ACK/NAK in x3 + sbci YH, 0 ;[63] + out USBOUT, x1 ;[00] <-- out SE0 -- from now 2 bits = 16 cycles until bus idle +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + breq skipAddrAssign ;[01] + sts usbDeviceAddr, x2 ; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< 12.5625 MHz +max frequency: 69.286 cycles for 8 bit -> 12.99 MHz +nominal frequency: 12.77 MHz ( = sqrt(min * max)) + +sampling positions: (next even number in range [+/- 0.5]) +cycle index range: 0 ... 66 +bits: +.5, 8.875, 17.25, 25.625, 34, 42.375, 50.75, 59.125 +[0/1], [9], [17], [25/+26], [34], [+42/43], [51], [59] + +bit number: 0 1 2 3 4 5 6 7 +spare cycles 1 2 1 2 1 1 1 0 + +operations to perform: duration cycle + ---------------- + eor fix, shift 1 -> 00 + andi phase, USBMASK 1 -> 08 + breq se0 1 -> 16 (moved to 11) + st y+, data 2 -> 24, 25 + mov data, fix 1 -> 33 + ser data 1 -> 41 + subi cnt, 1 1 -> 49 + brcs overflow 1 -> 50 + +layout of samples and operations: +[##] = sample bit +<##> = sample phase +*##* = operation + +0: *00* [01] 02 03 04 <05> 06 07 +1: *08* [09] 10 11 12 <13> 14 15 *16* +2: [17] 18 19 20 <21> 22 23 +3: *24* *25* [26] 27 28 29 <30> 31 32 +4: *33* [34] 35 36 37 <38> 39 40 +5: *41* [42] 43 44 45 <46> 47 48 +6: *49* *50* [51] 52 53 54 <55> 56 57 58 +7: [59] 60 61 62 <63> 64 65 66 +*****************************************************************************/ + +/* we prefer positive expressions (do if condition) instead of negative + * (skip if condition), therefore use defines for skip instructions: + */ +#define ifioclr sbis +#define ifioset sbic +#define ifrclr sbrs +#define ifrset sbrc + +/* The registers "fix" and "data" swap their meaning during the loop. Use + * defines to keep their name constant. + */ +#define fix x2 +#define data x1 +#undef phase /* phase has a default definition to x4 */ +#define phase x3 + + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG [sofError], YH, shift, x1, x2, x3, cnt, r0 + push YL ;2 push only what is necessary to sync with edge ASAP + in YL, SREG ;1 + push YL ;2 +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of 1/4 bit which meets the spec. + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS ;[0] + rjmp foundK ;[1] +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError + +foundK: +;{3, 5} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling] +;we have 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push YH ;[2] + lds YL, usbInputBufOffset;[4] + clr YH ;[6] + subi YL, lo8(-(usbRxBuf));[7] + sbci YH, hi8(-(usbRxBuf));[8] + + sbis USBIN, USBMINUS ;[9] we want two bits K [we want to sample at 8 + 4 - 1.5 = 10.5] + rjmp haveTwoBitsK ;[10] + pop YH ;[11] undo the push from before + rjmp waitForK ;[13] this was not the end of sync, retry +haveTwoBitsK: +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +#define fix x2 +#define data x1 + + push shift ;[12] + push x1 ;[14] + push x2 ;[16] + ldi shift, 0x80 ;[18] prevent bit-unstuffing but init low bits to 0 + ifioset USBIN, USBMINUS ;[19] [01] <--- bit 0 [10.5 + 8 = 18.5] + ori shift, 1<<0 ;[02] + push x3 ;[03] + push cnt ;[05] + push r0 ;[07] + ifioset USBIN, USBMINUS ;[09] <--- bit 1 + ori shift, 1<<1 ;[10] + ser fix ;[11] + ldi cnt, USB_BUFSIZE ;[12] + mov data, shift ;[13] + lsl shift ;[14] + nop2 ;[15] + ifioset USBIN, USBMINUS ;[17] <--- bit 2 + ori data, 3<<2 ;[18] store in bit 2 AND bit 3 + eor shift, data ;[19] do nrzi decoding + andi data, 1<<3 ;[20] + in phase, USBIN ;[21] <- phase + brne jumpToEntryAfterSet ;[22] if USBMINS at bit 3 was 1 + nop ;[23] + rjmp entryAfterClr ;[24] +jumpToEntryAfterSet: + rjmp entryAfterSet ;[24] + +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- +#undef fix +#define fix x1 +#undef data +#define data x2 + +bit7IsSet: + ifrclr phase, USBMINUS ;[62] check phase only if D- changed + lpm ;[63] + in phase, USBIN ;[64] <- phase (one cycle too late) + ori shift, 1 << 7 ;[65] + nop ;[66] +;;;;rjmp bit0AfterSet ; -> [00] == [67] moved block up to save jump +bit0AfterSet: + eor fix, shift ;[00] +#undef fix +#define fix x2 +#undef data +#define data x1 /* we now have result in data, fix is reset to 0xff */ + ifioclr USBIN, USBMINUS ;[01] <--- sample 0 + rjmp bit0IsClr ;[02] + andi shift, ~(7 << 0) ;[03] + breq unstuff0s ;[04] + in phase, USBIN ;[05] <- phase + rjmp bit1AfterSet ;[06] +unstuff0s: + in phase, USBIN ;[06] <- phase (one cycle too late) + andi fix, ~(1 << 0) ;[07] + ifioclr USBIN, USBMINUS ;[00] + ifioset USBIN, USBPLUS ;[01] + rjmp bit0IsClr ;[02] executed if first expr false or second true +se0AndStore: ; executed only if both bits 0 + st y+, x1 ;[15/17] cycles after start of byte + rjmp se0 ;[17/19] + +bit0IsClr: + ifrset phase, USBMINUS ;[04] check phase only if D- changed + lpm ;[05] + in phase, USBIN ;[06] <- phase (one cycle too late) + ori shift, 1 << 0 ;[07] +bit1AfterClr: + andi phase, USBMASK ;[08] + ifioset USBIN, USBMINUS ;[09] <--- sample 1 + rjmp bit1IsSet ;[10] + breq se0AndStore ;[11] if D- was 0 in bits 0 AND 1 and D+ was 0 in between, we have SE0 + andi shift, ~(7 << 1) ;[12] + in phase, USBIN ;[13] <- phase + breq unstuff1c ;[14] + rjmp bit2AfterClr ;[15] +unstuff1c: + andi fix, ~(1 << 1) ;[16] + nop2 ;[08] + nop2 ;[10] +bit1IsSet: + ifrclr phase, USBMINUS ;[12] check phase only if D- changed + lpm ;[13] + in phase, USBIN ;[14] <- phase (one cycle too late) + ori shift, 1 << 1 ;[15] + nop ;[16] +bit2AfterSet: + ifioclr USBIN, USBMINUS ;[17] <--- sample 2 + rjmp bit2IsClr ;[18] + andi shift, ~(7 << 2) ;[19] + breq unstuff2s ;[20] + in phase, USBIN ;[21] <- phase + rjmp bit3AfterSet ;[22] +unstuff2s: + in phase, USBIN ;[22] <- phase (one cycle too late) + andi fix, ~(1 << 2) ;[23] + nop2 ;[16] + nop2 ;[18] +bit2IsClr: + ifrset phase, USBMINUS ;[20] check phase only if D- changed + lpm ;[21] + in phase, USBIN ;[22] <- phase (one cycle too late) + ori shift, 1 << 2 ;[23] +bit3AfterClr: + st y+, data ;[24] +entryAfterClr: + ifioset USBIN, USBMINUS ;[26] <--- sample 3 + rjmp bit3IsSet ;[27] + andi shift, ~(7 << 3) ;[28] + breq unstuff3c ;[29] + in phase, USBIN ;[30] <- phase + rjmp bit4AfterClr ;[31] +unstuff3c: + in phase, USBIN ;[31] <- phase (one cycle too late) + andi fix, ~(1 << 3) ;[32] + nop2 ;[25] + nop2 ;[27] +bit3IsSet: + ifrclr phase, USBMINUS ;[29] check phase only if D- changed + lpm ;[30] + in phase, USBIN ;[31] <- phase (one cycle too late) + ori shift, 1 << 3 ;[32] +bit4AfterSet: + mov data, fix ;[33] undo this move by swapping defines +#undef fix +#define fix x1 +#undef data +#define data x2 + ifioclr USBIN, USBMINUS ;[34] <--- sample 4 + rjmp bit4IsClr ;[35] + andi shift, ~(7 << 4) ;[36] + breq unstuff4s ;[37] + in phase, USBIN ;[38] <- phase + rjmp bit5AfterSet ;[39] +unstuff4s: + in phase, USBIN ;[39] <- phase (one cycle too late) + andi fix, ~(1 << 4) ;[40] + nop2 ;[33] + nop2 ;[35] +bit4IsClr: + ifrset phase, USBMINUS ;[37] check phase only if D- changed + lpm ;[38] + in phase, USBIN ;[39] <- phase (one cycle too late) + ori shift, 1 << 4 ;[40] +bit5AfterClr: + ser data ;[41] + ifioset USBIN, USBMINUS ;[42] <--- sample 5 + rjmp bit5IsSet ;[43] + andi shift, ~(7 << 5) ;[44] + breq unstuff5c ;[45] + in phase, USBIN ;[46] <- phase + rjmp bit6AfterClr ;[47] +unstuff5c: + in phase, USBIN ;[47] <- phase (one cycle too late) + andi fix, ~(1 << 5) ;[48] + nop2 ;[41] + nop2 ;[43] +bit5IsSet: + ifrclr phase, USBMINUS ;[45] check phase only if D- changed + lpm ;[46] + in phase, USBIN ;[47] <- phase (one cycle too late) + ori shift, 1 << 5 ;[48] +bit6AfterSet: + subi cnt, 1 ;[49] + brcs jumpToOverflow ;[50] + ifioclr USBIN, USBMINUS ;[51] <--- sample 6 + rjmp bit6IsClr ;[52] + andi shift, ~(3 << 6) ;[53] + cpi shift, 2 ;[54] + in phase, USBIN ;[55] <- phase + brlt unstuff6s ;[56] + rjmp bit7AfterSet ;[57] + +jumpToOverflow: + rjmp overflow + +unstuff6s: + andi fix, ~(1 << 6) ;[50] + lpm ;[51] +bit6IsClr: + ifrset phase, USBMINUS ;[54] check phase only if D- changed + lpm ;[55] + in phase, USBIN ;[56] <- phase (one cycle too late) + ori shift, 1 << 6 ;[57] + nop ;[58] +bit7AfterClr: + ifioset USBIN, USBMINUS ;[59] <--- sample 7 + rjmp bit7IsSet ;[60] + andi shift, ~(1 << 7) ;[61] + cpi shift, 4 ;[62] + in phase, USBIN ;[63] <- phase + brlt unstuff7c ;[64] + rjmp bit0AfterClr ;[65] -> [00] == [67] +unstuff7c: + andi fix, ~(1 << 7) ;[58] + nop ;[59] + rjmp bit7IsSet ;[60] + +bit7IsClr: + ifrset phase, USBMINUS ;[62] check phase only if D- changed + lpm ;[63] + in phase, USBIN ;[64] <- phase (one cycle too late) + ori shift, 1 << 7 ;[65] + nop ;[66] +;;;;rjmp bit0AfterClr ; -> [00] == [67] moved block up to save jump +bit0AfterClr: + eor fix, shift ;[00] +#undef fix +#define fix x2 +#undef data +#define data x1 /* we now have result in data, fix is reset to 0xff */ + ifioset USBIN, USBMINUS ;[01] <--- sample 0 + rjmp bit0IsSet ;[02] + andi shift, ~(7 << 0) ;[03] + breq unstuff0c ;[04] + in phase, USBIN ;[05] <- phase + rjmp bit1AfterClr ;[06] +unstuff0c: + in phase, USBIN ;[06] <- phase (one cycle too late) + andi fix, ~(1 << 0) ;[07] + ifioclr USBIN, USBMINUS ;[00] + ifioset USBIN, USBPLUS ;[01] + rjmp bit0IsSet ;[02] executed if first expr false or second true + rjmp se0AndStore ;[03] executed only if both bits 0 +bit0IsSet: + ifrclr phase, USBMINUS ;[04] check phase only if D- changed + lpm ;[05] + in phase, USBIN ;[06] <- phase (one cycle too late) + ori shift, 1 << 0 ;[07] +bit1AfterSet: + andi shift, ~(7 << 1) ;[08] compensated by "ori shift, 1<<1" if bit1IsClr + ifioclr USBIN, USBMINUS ;[09] <--- sample 1 + rjmp bit1IsClr ;[10] + breq unstuff1s ;[11] + nop2 ;[12] do not check for SE0 if bit 0 was 1 + in phase, USBIN ;[14] <- phase (one cycle too late) + rjmp bit2AfterSet ;[15] +unstuff1s: + in phase, USBIN ;[13] <- phase + andi fix, ~(1 << 1) ;[14] + lpm ;[07] + nop2 ;[10] +bit1IsClr: + ifrset phase, USBMINUS ;[12] check phase only if D- changed + lpm ;[13] + in phase, USBIN ;[14] <- phase (one cycle too late) + ori shift, 1 << 1 ;[15] + nop ;[16] +bit2AfterClr: + ifioset USBIN, USBMINUS ;[17] <--- sample 2 + rjmp bit2IsSet ;[18] + andi shift, ~(7 << 2) ;[19] + breq unstuff2c ;[20] + in phase, USBIN ;[21] <- phase + rjmp bit3AfterClr ;[22] +unstuff2c: + in phase, USBIN ;[22] <- phase (one cycle too late) + andi fix, ~(1 << 2) ;[23] + nop2 ;[16] + nop2 ;[18] +bit2IsSet: + ifrclr phase, USBMINUS ;[20] check phase only if D- changed + lpm ;[21] + in phase, USBIN ;[22] <- phase (one cycle too late) + ori shift, 1 << 2 ;[23] +bit3AfterSet: + st y+, data ;[24] +entryAfterSet: + ifioclr USBIN, USBMINUS ;[26] <--- sample 3 + rjmp bit3IsClr ;[27] + andi shift, ~(7 << 3) ;[28] + breq unstuff3s ;[29] + in phase, USBIN ;[30] <- phase + rjmp bit4AfterSet ;[31] +unstuff3s: + in phase, USBIN ;[31] <- phase (one cycle too late) + andi fix, ~(1 << 3) ;[32] + nop2 ;[25] + nop2 ;[27] +bit3IsClr: + ifrset phase, USBMINUS ;[29] check phase only if D- changed + lpm ;[30] + in phase, USBIN ;[31] <- phase (one cycle too late) + ori shift, 1 << 3 ;[32] +bit4AfterClr: + mov data, fix ;[33] undo this move by swapping defines +#undef fix +#define fix x1 +#undef data +#define data x2 + ifioset USBIN, USBMINUS ;[34] <--- sample 4 + rjmp bit4IsSet ;[35] + andi shift, ~(7 << 4) ;[36] + breq unstuff4c ;[37] + in phase, USBIN ;[38] <- phase + rjmp bit5AfterClr ;[39] +unstuff4c: + in phase, USBIN ;[39] <- phase (one cycle too late) + andi fix, ~(1 << 4) ;[40] + nop2 ;[33] + nop2 ;[35] +bit4IsSet: + ifrclr phase, USBMINUS ;[37] check phase only if D- changed + lpm ;[38] + in phase, USBIN ;[39] <- phase (one cycle too late) + ori shift, 1 << 4 ;[40] +bit5AfterSet: + ser data ;[41] + ifioclr USBIN, USBMINUS ;[42] <--- sample 5 + rjmp bit5IsClr ;[43] + andi shift, ~(7 << 5) ;[44] + breq unstuff5s ;[45] + in phase, USBIN ;[46] <- phase + rjmp bit6AfterSet ;[47] +unstuff5s: + in phase, USBIN ;[47] <- phase (one cycle too late) + andi fix, ~(1 << 5) ;[48] + nop2 ;[41] + nop2 ;[43] +bit5IsClr: + ifrset phase, USBMINUS ;[45] check phase only if D- changed + lpm ;[46] + in phase, USBIN ;[47] <- phase (one cycle too late) + ori shift, 1 << 5 ;[48] +bit6AfterClr: + subi cnt, 1 ;[49] + brcs overflow ;[50] + ifioset USBIN, USBMINUS ;[51] <--- sample 6 + rjmp bit6IsSet ;[52] + andi shift, ~(3 << 6) ;[53] + cpi shift, 2 ;[54] + in phase, USBIN ;[55] <- phase + brlt unstuff6c ;[56] + rjmp bit7AfterClr ;[57] +unstuff6c: + andi fix, ~(1 << 6) ;[50] + lpm ;[51] +bit6IsSet: + ifrclr phase, USBMINUS ;[54] check phase only if D- changed + lpm ;[55] + in phase, USBIN ;[56] <- phase (one cycle too late) + ori shift, 1 << 6 ;[57] +bit7AfterSet: + ifioclr USBIN, USBMINUS ;[59] <--- sample 7 + rjmp bit7IsClr ;[60] + andi shift, ~(1 << 7) ;[61] + cpi shift, 4 ;[62] + in phase, USBIN ;[63] <- phase + brlt unstuff7s ;[64] + rjmp bit0AfterSet ;[65] -> [00] == [67] +unstuff7s: + andi fix, ~(1 << 7) ;[58] + nop ;[59] + rjmp bit7IsClr ;[60] + +macro POP_STANDARD ; 14 cycles + pop r0 + pop cnt + pop x3 + pop x2 + pop x1 + pop shift + pop YH + endm +macro POP_RETI ; 5 cycles + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + +;---------------------------------------------------------------------------- +; Transmitting data +;---------------------------------------------------------------------------- + +txByteLoop: +txBitloop: +stuffN1Delay: ; [03] + ror shift ;[-5] [11] [63] + brcc doExorN1 ;[-4] [64] + subi x3, 1 ;[-3] + brne commonN1 ;[-2] + lsl shift ;[-1] compensate ror after rjmp stuffDelay + nop ;[00] stuffing consists of just waiting 8 cycles + rjmp stuffN1Delay ;[01] after ror, C bit is reliably clear + +sendNakAndReti: + ldi cnt, USBPID_NAK ;[-19] + rjmp sendCntAndReti ;[-18] +sendAckAndReti: + ldi cnt, USBPID_ACK ;[-17] +sendCntAndReti: + mov r0, cnt ;[-16] + ldi YL, 0 ;[-15] R0 address is 0 + ldi YH, 0 ;[-14] + ldi cnt, 2 ;[-13] +; rjmp usbSendAndReti fallthrough + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) or USBOUT = 0x01 +; K = (D+ = 1), (D- = 0) or USBOUT = 0x02 +; Spec allows 7.5 bit times from EOP to SOP for replies (= 60 cycles) + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte +;uses: x1...x3, shift, cnt, Y [x1 = mirror USBOUT, x2 = USBMASK, x3 = bitstuff cnt] +;Numbers in brackets are time since first bit of sync pattern is sent (start of instruction) +usbSendAndReti: + in x2, USBDDR ;[-10] 10 cycles until SOP + ori x2, USBMASK ;[-9] + sbi USBOUT, USBMINUS ;[-8] prepare idle state; D+ and D- must have been 0 (no pullups) + out USBDDR, x2 ;[-6] <--- acquire bus + in x1, USBOUT ;[-5] port mirror for tx loop + ldi shift, 0x40 ;[-4] sync byte is first byte sent (we enter loop after ror) + ldi x2, USBMASK ;[-3] +doExorN1: + eor x1, x2 ;[-2] [06] [62] + ldi x3, 6 ;[-1] [07] [63] +commonN1: +stuffN2Delay: + out USBOUT, x1 ;[00] [08] [64] <--- set bit + ror shift ;[01] + brcc doExorN2 ;[02] + subi x3, 1 ;[03] + brne commonN2 ;[04] + lsl shift ;[05] compensate ror after rjmp stuffDelay + rjmp stuffN2Delay ;[06] after ror, C bit is reliably clear +doExorN2: + eor x1, x2 ;[04] [12] + ldi x3, 6 ;[05] [13] +commonN2: + nop2 ;[06] [14] + subi cnt, 171 ;[08] [16] trick: (3 * 171) & 0xff = 1 + out USBOUT, x1 ;[09] [17] <--- set bit + brcs txBitloop ;[10] [27] [44] + +stuff6Delay: + ror shift ;[45] [53] + brcc doExor6 ;[46] + subi x3, 1 ;[47] + brne common6 ;[48] + lsl shift ;[49] compensate ror after rjmp stuffDelay + nop ;[50] stuffing consists of just waiting 8 cycles + rjmp stuff6Delay ;[51] after ror, C bit is reliably clear +doExor6: + eor x1, x2 ;[48] [56] + ldi x3, 6 ;[49] +common6: +stuff7Delay: + ror shift ;[50] [58] + out USBOUT, x1 ;[51] <--- set bit + brcc doExor7 ;[52] + subi x3, 1 ;[53] + brne common7 ;[54] + lsl shift ;[55] compensate ror after rjmp stuffDelay + rjmp stuff7Delay ;[56] after ror, C bit is reliably clear +doExor7: + eor x1, x2 ;[54] [62] + ldi x3, 6 ;[55] +common7: + ld shift, y+ ;[56] + nop ;[58] + tst cnt ;[59] + out USBOUT, x1 ;[60] [00]<--- set bit + brne txByteLoop ;[61] [01] +;make SE0: + cbr x1, USBMASK ;[02] prepare SE0 [spec says EOP may be 15 to 18 cycles] + lds x2, usbNewDeviceAddr;[03] + lsl x2 ;[05] we compare with left shifted address + subi YL, 2 + 0 ;[06] Only assign address on data packets, not ACK/NAK in r0 + sbci YH, 0 ;[07] + out USBOUT, x1 ;[00] <-- out SE0 -- from now 2 bits = 16 cycles until bus idle +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + breq skipAddrAssign ;[01] + sts usbDeviceAddr, x2 ; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< 0) + echo "$s\n"; + } +} + +function printBit($isAfterSet, $bitNum) +{ + ob_start(); + if($isAfterSet){ +?> + ifioclr USBIN, USBMINUS ;[00] <--- sample + rjmp bit#IsClr ;[01] + andi shift, ~(7 << #) ;[02] + breq unstuff#s ;[03] + in phase, USBIN ;[04] <- phase + rjmp bit@AfterSet ;[05] +unstuff#s: + in phase, USBIN ;[05] <- phase (one cycle too late) + andi fix, ~(1 << #) ;[06] + nop2 ;[-1] + nop2 ;[01] +bit#IsClr: + ifrset phase, USBMINUS ;[03] check phase only if D- changed + lpm ;[04] + in phase, USBIN ;[05] <- phase (one cycle too late) + ori shift, 1 << # ;[06] + + ifioset USBIN, USBMINUS ;[00] <--- sample + rjmp bit#IsSet ;[01] + andi shift, ~(7 << #) ;[02] + breq unstuff#c ;[03] + in phase, USBIN ;[04] <- phase + rjmp bit@AfterClr ;[05] +unstuff#c: + in phase, USBIN ;[05] <- phase (one cycle too late) + andi fix, ~(1 << #) ;[06] + nop2 ;[-1] + nop2 ;[01] +bit#IsSet: + ifrclr phase, USBMINUS ;[03] check phase only if D- changed + lpm ;[04] + in phase, USBIN ;[05] <- phase (one cycle too late) + ori shift, 1 << # ;[06] + +*****************************************************************************/ diff --git a/adb2usb/uart2usb/usbdrv/usbdrvasm15.inc b/adb2usb/uart2usb/usbdrv/usbdrvasm15.inc new file mode 100644 index 0000000..401b7f8 --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/usbdrvasm15.inc @@ -0,0 +1,423 @@ +/* Name: usbdrvasm15.inc + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: contributed by V. Bosch + * Creation Date: 2007-08-06 + * Tabsize: 4 + * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Revision: $Id: usbdrvasm15.inc 740 2009-04-13 18:23:31Z cs $ + */ + +/* Do not link this file! Link usbdrvasm.S instead, which includes the + * appropriate implementation! + */ + +/* +General Description: +This file is the 15 MHz version of the asssembler part of the USB driver. It +requires a 15 MHz crystal (not a ceramic resonator and not a calibrated RC +oscillator). + +See usbdrv.h for a description of the entire driver. + +Since almost all of this code is timing critical, don't change unless you +really know what you are doing! Many parts require not only a maximum number +of CPU cycles, but even an exact number of cycles! +*/ + +;max stack usage: [ret(2), YL, SREG, YH, bitcnt, shift, x1, x2, x3, x4, cnt] = 12 bytes +;nominal frequency: 15 MHz -> 10.0 cycles per bit, 80.0 cycles per byte +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts + +;---------------------------------------------------------------------------- +; order of registers pushed: +; YL, SREG [sofError] YH, shift, x1, x2, x3, bitcnt, cnt, x4 +;---------------------------------------------------------------------------- +USB_INTR_VECTOR: + push YL ;2 push only what is necessary to sync with edge ASAP + in YL, SREG ;1 + push YL ;2 +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +; +; sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +; sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +;------------------------------------------------------------------------------- +; The following code results in a sampling window of < 1/4 bit +; which meets the spec. +;------------------------------------------------------------------------------- +waitForK: ;- + sbis USBIN, USBMINUS ;1 [00] <-- sample + rjmp foundK ;2 [01] + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +;------------------------------------------------------------------------------ +; {3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for +; center sampling] +; we have 1 bit time for setup purposes, then sample again. +; Numbers in brackets are cycles from center of first sync (double K) +; bit after the instruction +;------------------------------------------------------------------------------ +foundK: ;- [02] + lds YL, usbInputBufOffset;2 [03+04] tx loop + push YH ;2 [05+06] + clr YH ;1 [07] + subi YL, lo8(-(usbRxBuf)) ;1 [08] [rx loop init] + sbci YH, hi8(-(usbRxBuf)) ;1 [09] [rx loop init] + push shift ;2 [10+11] + ser shift ;1 [12] + sbis USBIN, USBMINUS ;1 [-1] [13] <--sample:we want two bits K (sample 1 cycle too early) + rjmp haveTwoBitsK ;2 [00] [14] + pop shift ;2 [15+16] undo the push from before + pop YH ;2 [17+18] undo the push from before + rjmp waitForK ;2 [19+20] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 20 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: ;- [01] + push x1 ;2 [02+03] + push x2 ;2 [04+05] + push x3 ;2 [06+07] + push bitcnt ;2 [08+09] + in x1, USBIN ;1 [00] [10] <-- sample bit 0 + bst x1, USBMINUS ;1 [01] + bld shift, 0 ;1 [02] + push cnt ;2 [03+04] + ldi cnt, USB_BUFSIZE ;1 [05] + push x4 ;2 [06+07] tx loop + rjmp rxLoop ;2 [08] +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- +unstuff0: ;- [07] (branch taken) + andi x3, ~0x01 ;1 [08] + mov x1, x2 ;1 [09] x2 contains last sampled (stuffed) bit + in x2, USBIN ;1 [00] [10] <-- sample bit 1 again + andi x2, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 1 + ori shift, 0x01 ;1 [03] 0b00000001 + nop ;1 [04] + rjmp didUnstuff0 ;2 [05] +;----------------------------------------------------- +unstuff1: ;- [05] (branch taken) + mov x2, x1 ;1 [06] x1 contains last sampled (stuffed) bit + andi x3, ~0x02 ;1 [07] + ori shift, 0x02 ;1 [08] 0b00000010 + nop ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample bit 2 again + andi x1, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 2 + rjmp didUnstuff1 ;2 [03] +;----------------------------------------------------- +unstuff2: ;- [05] (branch taken) + andi x3, ~0x04 ;1 [06] + ori shift, 0x04 ;1 [07] 0b00000100 + mov x1, x2 ;1 [08] x2 contains last sampled (stuffed) bit + nop ;1 [09] + in x2, USBIN ;1 [00] [10] <-- sample bit 3 + andi x2, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 3 + rjmp didUnstuff2 ;2 [03] +;----------------------------------------------------- +unstuff3: ;- [00] [10] (branch taken) + in x2, USBIN ;1 [01] [11] <-- sample stuffed bit 3 one cycle too late + andi x2, USBMASK ;1 [02] + breq se0Hop ;1 [03] SE0 check for stuffed bit 3 + andi x3, ~0x08 ;1 [04] + ori shift, 0x08 ;1 [05] 0b00001000 + rjmp didUnstuff3 ;2 [06] +;---------------------------------------------------------------------------- +; extra jobs done during bit interval: +; +; bit 0: store, clear [SE0 is unreliable here due to bit dribbling in hubs], +; overflow check, jump to the head of rxLoop +; bit 1: SE0 check +; bit 2: SE0 check, recovery from delay [bit 0 tasks took too long] +; bit 3: SE0 check, recovery from delay [bit 0 tasks took too long] +; bit 4: SE0 check, none +; bit 5: SE0 check, none +; bit 6: SE0 check, none +; bit 7: SE0 check, reconstruct: x3 is 0 at bit locations we changed, 1 at others +;---------------------------------------------------------------------------- +rxLoop: ;- [09] + in x2, USBIN ;1 [00] [10] <-- sample bit 1 (or possibly bit 0 stuffed) + andi x2, USBMASK ;1 [01] + brne SkipSe0Hop ;1 [02] +se0Hop: ;- [02] + rjmp se0 ;2 [03] SE0 check for bit 1 +SkipSe0Hop: ;- [03] + ser x3 ;1 [04] + andi shift, 0xf9 ;1 [05] 0b11111001 + breq unstuff0 ;1 [06] +didUnstuff0: ;- [06] + eor x1, x2 ;1 [07] + bst x1, USBMINUS ;1 [08] + bld shift, 1 ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample bit 2 (or possibly bit 1 stuffed) + andi x1, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 2 + andi shift, 0xf3 ;1 [03] 0b11110011 + breq unstuff1 ;1 [04] do remaining work for bit 1 +didUnstuff1: ;- [04] + eor x2, x1 ;1 [05] + bst x2, USBMINUS ;1 [06] + bld shift, 2 ;1 [07] + nop2 ;2 [08+09] + in x2, USBIN ;1 [00] [10] <-- sample bit 3 (or possibly bit 2 stuffed) + andi x2, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 3 + andi shift, 0xe7 ;1 [03] 0b11100111 + breq unstuff2 ;1 [04] +didUnstuff2: ;- [04] + eor x1, x2 ;1 [05] + bst x1, USBMINUS ;1 [06] + bld shift, 3 ;1 [07] +didUnstuff3: ;- [07] + andi shift, 0xcf ;1 [08] 0b11001111 + breq unstuff3 ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample bit 4 + andi x1, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 4 + eor x2, x1 ;1 [03] + bst x2, USBMINUS ;1 [04] + bld shift, 4 ;1 [05] +didUnstuff4: ;- [05] + andi shift, 0x9f ;1 [06] 0b10011111 + breq unstuff4 ;1 [07] + nop2 ;2 [08+09] + in x2, USBIN ;1 [00] [10] <-- sample bit 5 + andi x2, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for bit 5 + eor x1, x2 ;1 [03] + bst x1, USBMINUS ;1 [04] + bld shift, 5 ;1 [05] +didUnstuff5: ;- [05] + andi shift, 0x3f ;1 [06] 0b00111111 + breq unstuff5 ;1 [07] + nop2 ;2 [08+09] + in x1, USBIN ;1 [00] [10] <-- sample bit 6 + andi x1, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for bit 6 + eor x2, x1 ;1 [03] + bst x2, USBMINUS ;1 [04] + bld shift, 6 ;1 [05] +didUnstuff6: ;- [05] + cpi shift, 0x02 ;1 [06] 0b00000010 + brlo unstuff6 ;1 [07] + nop2 ;2 [08+09] + in x2, USBIN ;1 [00] [10] <-- sample bit 7 + andi x2, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for bit 7 + eor x1, x2 ;1 [03] + bst x1, USBMINUS ;1 [04] + bld shift, 7 ;1 [05] +didUnstuff7: ;- [05] + cpi shift, 0x04 ;1 [06] 0b00000100 + brlo unstuff7 ;1 [07] + eor x3, shift ;1 [08] reconstruct: x3 is 0 at bit locations we changed, 1 at others + nop ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample bit 0 + st y+, x3 ;2 [01+02] store data + eor x2, x1 ;1 [03] + bst x2, USBMINUS ;1 [04] + bld shift, 0 ;1 [05] + subi cnt, 1 ;1 [06] + brcs overflow ;1 [07] + rjmp rxLoop ;2 [08] +;----------------------------------------------------- +unstuff4: ;- [08] + andi x3, ~0x10 ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample stuffed bit 4 + andi x1, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for stuffed bit 4 + ori shift, 0x10 ;1 [03] + rjmp didUnstuff4 ;2 [04] +;----------------------------------------------------- +unstuff5: ;- [08] + ori shift, 0x20 ;1 [09] + in x2, USBIN ;1 [00] [10] <-- sample stuffed bit 5 + andi x2, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for stuffed bit 5 + andi x3, ~0x20 ;1 [03] + rjmp didUnstuff5 ;2 [04] +;----------------------------------------------------- +unstuff6: ;- [08] + andi x3, ~0x40 ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample stuffed bit 6 + andi x1, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for stuffed bit 6 + ori shift, 0x40 ;1 [03] + rjmp didUnstuff6 ;2 [04] +;----------------------------------------------------- +unstuff7: ;- [08] + andi x3, ~0x80 ;1 [09] + in x2, USBIN ;1 [00] [10] <-- sample stuffed bit 7 + andi x2, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for stuffed bit 7 + ori shift, 0x80 ;1 [03] + rjmp didUnstuff7 ;2 [04] + +macro POP_STANDARD ; 16 cycles + pop x4 + pop cnt + pop bitcnt + pop x3 + pop x2 + pop x1 + pop shift + pop YH + endm +macro POP_RETI ; 5 cycles + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + +;--------------------------------------------------------------------------- +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) +; K = (D+ = 1), (D- = 0) +; Spec allows 7.5 bit times from EOP to SOP for replies +;--------------------------------------------------------------------------- +bitstuffN: ;- [04] + eor x1, x4 ;1 [05] + clr x2 ;1 [06] + nop ;1 [07] + rjmp didStuffN ;1 [08] +;--------------------------------------------------------------------------- +bitstuff6: ;- [04] + eor x1, x4 ;1 [05] + clr x2 ;1 [06] + rjmp didStuff6 ;1 [07] +;--------------------------------------------------------------------------- +bitstuff7: ;- [02] + eor x1, x4 ;1 [03] + clr x2 ;1 [06] + nop ;1 [05] + rjmp didStuff7 ;1 [06] +;--------------------------------------------------------------------------- +sendNakAndReti: ;- [-19] + ldi x3, USBPID_NAK ;1 [-18] + rjmp sendX3AndReti ;1 [-17] +;--------------------------------------------------------------------------- +sendAckAndReti: ;- [-17] + ldi cnt, USBPID_ACK ;1 [-16] +sendCntAndReti: ;- [-16] + mov x3, cnt ;1 [-15] +sendX3AndReti: ;- [-15] + ldi YL, 20 ;1 [-14] x3==r20 address is 20 + ldi YH, 0 ;1 [-13] + ldi cnt, 2 ;1 [-12] +; rjmp usbSendAndReti fallthrough +;--------------------------------------------------------------------------- +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] +;uses: x1...x4, btcnt, shift, cnt, Y +;Numbers in brackets are time since first bit of sync pattern is sent +;We need not to match the transfer rate exactly because the spec demands +;only 1.5% precision anyway. +usbSendAndReti: ;- [-13] 13 cycles until SOP + in x2, USBDDR ;1 [-12] + ori x2, USBMASK ;1 [-11] + sbi USBOUT, USBMINUS ;2 [-09-10] prepare idle state; D+ and D- must have been 0 (no pullups) + in x1, USBOUT ;1 [-08] port mirror for tx loop + out USBDDR, x2 ;1 [-07] <- acquire bus + ; need not init x2 (bitstuff history) because sync starts with 0 + ldi x4, USBMASK ;1 [-06] exor mask + ldi shift, 0x80 ;1 [-05] sync byte is first byte sent + ldi bitcnt, 6 ;1 [-04] +txBitLoop: ;- [-04] [06] + sbrs shift, 0 ;1 [-03] [07] + eor x1, x4 ;1 [-02] [08] + ror shift ;1 [-01] [09] +didStuffN: ;- [09] + out USBOUT, x1 ;1 [00] [10] <-- out N + ror x2 ;1 [01] + cpi x2, 0xfc ;1 [02] + brcc bitstuffN ;1 [03] + dec bitcnt ;1 [04] + brne txBitLoop ;1 [05] + sbrs shift, 0 ;1 [06] + eor x1, x4 ;1 [07] + ror shift ;1 [08] +didStuff6: ;- [08] + nop ;1 [09] + out USBOUT, x1 ;1 [00] [10] <-- out 6 + ror x2 ;1 [01] + cpi x2, 0xfc ;1 [02] + brcc bitstuff6 ;1 [03] + sbrs shift, 0 ;1 [04] + eor x1, x4 ;1 [05] + ror shift ;1 [06] + ror x2 ;1 [07] +didStuff7: ;- [07] + ldi bitcnt, 6 ;1 [08] + cpi x2, 0xfc ;1 [09] + out USBOUT, x1 ;1 [00] [10] <-- out 7 + brcc bitstuff7 ;1 [01] + ld shift, y+ ;2 [02+03] + dec cnt ;1 [04] + brne txBitLoop ;1 [05] +makeSE0: + cbr x1, USBMASK ;1 [06] prepare SE0 [spec says EOP may be 19 to 23 cycles] + lds x2, usbNewDeviceAddr;2 [07+08] + lsl x2 ;1 [09] we compare with left shifted address +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + out USBOUT, x1 ;1 [00] [10] <-- out SE0-- from now 2 bits==20 cycl. until bus idle + subi YL, 20 + 2 ;1 [01] Only assign address on data packets, not ACK/NAK in x3 + sbci YH, 0 ;1 [02] + breq skipAddrAssign ;1 [03] + sts usbDeviceAddr, x2 ;2 [04+05] if not skipped: SE0 is one cycle longer +;---------------------------------------------------------------------------- +;end of usbDeviceAddress transfer +skipAddrAssign: ;- [03/04] + ldi x2, 1< 10.6666666 cycles per bit, 85.333333333 cycles per byte +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG YH, [sofError], bitcnt, shift, x1, x2, x3, x4, cnt + push YL ;[-25] push only what is necessary to sync with edge ASAP + in YL, SREG ;[-23] + push YL ;[-22] + push YH ;[-20] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of < 1/4 bit which meets the spec. + sbis USBIN, USBMINUS ;[-15] + rjmp foundK ;[-14] + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: ;[-12] +;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling] +;we have 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push bitcnt ;[-12] +; [---] ;[-11] + lds YL, usbInputBufOffset;[-10] +; [---] ;[-9] + clr YH ;[-8] + subi YL, lo8(-(usbRxBuf));[-7] [rx loop init] + sbci YH, hi8(-(usbRxBuf));[-6] [rx loop init] + push shift ;[-5] +; [---] ;[-4] + ldi bitcnt, 0x55 ;[-3] [rx loop init] + sbis USBIN, USBMINUS ;[-2] we want two bits K (sample 2 cycles too early) + rjmp haveTwoBitsK ;[-1] + pop shift ;[0] undo the push from before + pop bitcnt ;[2] undo the push from before + rjmp waitForK ;[4] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 21 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: + push x1 ;[1] + push x2 ;[3] + push x3 ;[5] + ldi shift, 0 ;[7] + ldi x3, 1<<4 ;[8] [rx loop init] first sample is inverse bit, compensate that + push x4 ;[9] == leap + + in x1, USBIN ;[11] <-- sample bit 0 + andi x1, USBMASK ;[12] + bst x1, USBMINUS ;[13] + bld shift, 7 ;[14] + push cnt ;[15] + ldi leap, 0 ;[17] [rx loop init] + ldi cnt, USB_BUFSIZE;[18] [rx loop init] + rjmp rxbit1 ;[19] arrives at [21] + +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- + +; duration of unstuffing code should be 10.66666667 cycles. We adjust "leap" +; accordingly to approximate this value in the long run. + +unstuff6: + andi x2, USBMASK ;[03] + ori x3, 1<<6 ;[04] will not be shifted any more + andi shift, ~0x80;[05] + mov x1, x2 ;[06] sampled bit 7 is actually re-sampled bit 6 + subi leap, -1 ;[07] total duration = 11 bits -> subtract 1/3 + rjmp didUnstuff6 ;[08] + +unstuff7: + ori x3, 1<<7 ;[09] will not be shifted any more + in x2, USBIN ;[00] [10] re-sample bit 7 + andi x2, USBMASK ;[01] + andi shift, ~0x80;[02] + subi leap, 2 ;[03] total duration = 10 bits -> add 1/3 + rjmp didUnstuff7 ;[04] + +unstuffEven: + ori x3, 1<<6 ;[09] will be shifted right 6 times for bit 0 + in x1, USBIN ;[00] [10] + andi shift, ~0x80;[01] + andi x1, USBMASK ;[02] + breq se0 ;[03] + subi leap, -1 ;[04] total duration = 11 bits -> subtract 1/3 + nop2 ;[05] + rjmp didUnstuffE ;[06] + +unstuffOdd: + ori x3, 1<<5 ;[09] will be shifted right 4 times for bit 1 + in x2, USBIN ;[00] [10] + andi shift, ~0x80;[01] + andi x2, USBMASK ;[02] + breq se0 ;[03] + subi leap, -1 ;[04] total duration = 11 bits -> subtract 1/3 + nop2 ;[05] + rjmp didUnstuffO ;[06] + +rxByteLoop: + andi x1, USBMASK ;[03] + eor x2, x1 ;[04] + subi leap, 1 ;[05] + brpl skipLeap ;[06] + subi leap, -3 ;1 one leap cycle every 3rd byte -> 85 + 1/3 cycles per byte + nop ;1 +skipLeap: + subi x2, 1 ;[08] + ror shift ;[09] +didUnstuff6: + cpi shift, 0xfc ;[10] + in x2, USBIN ;[00] [11] <-- sample bit 7 + brcc unstuff6 ;[01] + andi x2, USBMASK ;[02] + eor x1, x2 ;[03] + subi x1, 1 ;[04] + ror shift ;[05] +didUnstuff7: + cpi shift, 0xfc ;[06] + brcc unstuff7 ;[07] + eor x3, shift ;[08] reconstruct: x3 is 1 at bit locations we changed, 0 at others + st y+, x3 ;[09] store data +rxBitLoop: + in x1, USBIN ;[00] [11] <-- sample bit 0/2/4 + andi x1, USBMASK ;[01] + eor x2, x1 ;[02] + andi x3, 0x3f ;[03] topmost two bits reserved for 6 and 7 + subi x2, 1 ;[04] + ror shift ;[05] + cpi shift, 0xfc ;[06] + brcc unstuffEven ;[07] +didUnstuffE: + lsr x3 ;[08] + lsr x3 ;[09] +rxbit1: + in x2, USBIN ;[00] [10] <-- sample bit 1/3/5 + andi x2, USBMASK ;[01] + breq se0 ;[02] + eor x1, x2 ;[03] + subi x1, 1 ;[04] + ror shift ;[05] + cpi shift, 0xfc ;[06] + brcc unstuffOdd ;[07] +didUnstuffO: + subi bitcnt, 0xab;[08] == addi 0x55, 0x55 = 0x100/3 + brcs rxBitLoop ;[09] + + subi cnt, 1 ;[10] + in x1, USBIN ;[00] [11] <-- sample bit 6 + brcc rxByteLoop ;[01] + rjmp overflow + +macro POP_STANDARD ; 14 cycles + pop cnt + pop x4 + pop x3 + pop x2 + pop x1 + pop shift + pop bitcnt + endm +macro POP_RETI ; 7 cycles + pop YH + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) +; K = (D+ = 1), (D- = 0) +; Spec allows 7.5 bit times from EOP to SOP for replies + +bitstuffN: + eor x1, x4 ;[5] + ldi x2, 0 ;[6] + nop2 ;[7] + nop ;[9] + out USBOUT, x1 ;[10] <-- out + rjmp didStuffN ;[0] + +bitstuff6: + eor x1, x4 ;[5] + ldi x2, 0 ;[6] Carry is zero due to brcc + rol shift ;[7] compensate for ror shift at branch destination + rjmp didStuff6 ;[8] + +bitstuff7: + ldi x2, 0 ;[2] Carry is zero due to brcc + rjmp didStuff7 ;[3] + + +sendNakAndReti: + ldi x3, USBPID_NAK ;[-18] + rjmp sendX3AndReti ;[-17] +sendAckAndReti: + ldi cnt, USBPID_ACK ;[-17] +sendCntAndReti: + mov x3, cnt ;[-16] +sendX3AndReti: + ldi YL, 20 ;[-15] x3==r20 address is 20 + ldi YH, 0 ;[-14] + ldi cnt, 2 ;[-13] +; rjmp usbSendAndReti fallthrough + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] +;uses: x1...x4, btcnt, shift, cnt, Y +;Numbers in brackets are time since first bit of sync pattern is sent +;We don't match the transfer rate exactly (don't insert leap cycles every third +;byte) because the spec demands only 1.5% precision anyway. +usbSendAndReti: ; 12 cycles until SOP + in x2, USBDDR ;[-12] + ori x2, USBMASK ;[-11] + sbi USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) + in x1, USBOUT ;[-8] port mirror for tx loop + out USBDDR, x2 ;[-7] <- acquire bus +; need not init x2 (bitstuff history) because sync starts with 0 + ldi x4, USBMASK ;[-6] exor mask + ldi shift, 0x80 ;[-5] sync byte is first byte sent +txByteLoop: + ldi bitcnt, 0x35 ;[-4] [6] binary 0011 0101 +txBitLoop: + sbrs shift, 0 ;[-3] [7] + eor x1, x4 ;[-2] [8] + out USBOUT, x1 ;[-1] [9] <-- out N + ror shift ;[0] [10] + ror x2 ;[1] +didStuffN: + cpi x2, 0xfc ;[2] + brcc bitstuffN ;[3] + lsr bitcnt ;[4] + brcc txBitLoop ;[5] + brne txBitLoop ;[6] + + sbrs shift, 0 ;[7] + eor x1, x4 ;[8] +didStuff6: + out USBOUT, x1 ;[-1] [9] <-- out 6 + ror shift ;[0] [10] + ror x2 ;[1] + cpi x2, 0xfc ;[2] + brcc bitstuff6 ;[3] + ror shift ;[4] +didStuff7: + ror x2 ;[5] + sbrs x2, 7 ;[6] + eor x1, x4 ;[7] + nop ;[8] + cpi x2, 0xfc ;[9] + out USBOUT, x1 ;[-1][10] <-- out 7 + brcc bitstuff7 ;[0] [11] + ld shift, y+ ;[1] + dec cnt ;[3] + brne txByteLoop ;[4] +;make SE0: + cbr x1, USBMASK ;[5] prepare SE0 [spec says EOP may be 21 to 25 cycles] + lds x2, usbNewDeviceAddr;[6] + lsl x2 ;[8] we compare with left shifted address + subi YL, 20 + 2 ;[9] Only assign address on data packets, not ACK/NAK in x3 + sbci YH, 0 ;[10] + out USBOUT, x1 ;[11] <-- out SE0 -- from now 2 bits = 22 cycles until bus idle +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + breq skipAddrAssign ;[0] + sts usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< max 52 cycles interrupt disable +;max stack usage: [ret(2), r0, SREG, YL, YH, shift, x1, x2, x3, x4, cnt] = 12 bytes +;nominal frequency: 16.5 MHz -> 11 cycles per bit +; 16.3125 MHz < F_CPU < 16.6875 MHz (+/- 1.1%) +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts + + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG [sofError], r0, YH, shift, x1, x2, x3, x4, cnt + push YL ;[-23] push only what is necessary to sync with edge ASAP + in YL, SREG ;[-21] + push YL ;[-20] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of < 1/4 bit which meets the spec. + sbis USBIN, USBMINUS ;[-15] + rjmp foundK ;[-14] + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: ;[-12] +;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling] +;we have 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push r0 ;[-12] +; [---] ;[-11] + push YH ;[-10] +; [---] ;[-9] + lds YL, usbInputBufOffset;[-8] +; [---] ;[-7] + clr YH ;[-6] + subi YL, lo8(-(usbRxBuf));[-5] [rx loop init] + sbci YH, hi8(-(usbRxBuf));[-4] [rx loop init] + mov r0, x2 ;[-3] [rx loop init] + sbis USBIN, USBMINUS ;[-2] we want two bits K (sample 2 cycles too early) + rjmp haveTwoBitsK ;[-1] + pop YH ;[0] undo the pushes from before + pop r0 ;[2] + rjmp waitForK ;[4] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 22 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: ;[1] + push shift ;[1] + push x1 ;[3] + push x2 ;[5] + push x3 ;[7] + ldi shift, 0xff ;[9] [rx loop init] + ori x3, 0xff ;[10] [rx loop init] == ser x3, clear zero flag + + in x1, USBIN ;[11] <-- sample bit 0 + bst x1, USBMINUS ;[12] + bld shift, 0 ;[13] + push x4 ;[14] == phase +; [---] ;[15] + push cnt ;[16] +; [---] ;[17] + ldi phase, 0 ;[18] [rx loop init] + ldi cnt, USB_BUFSIZE;[19] [rx loop init] + rjmp rxbit1 ;[20] +; [---] ;[21] + +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- +/* +byte oriented operations done during loop: +bit 0: store data +bit 1: SE0 check +bit 2: overflow check +bit 3: catch up +bit 4: rjmp to achieve conditional jump range +bit 5: PLL +bit 6: catch up +bit 7: jump, fixup bitstuff +; 87 [+ 2] cycles +------------------------------------------------------------------ +*/ +continueWithBit5: + in x2, USBIN ;[055] <-- bit 5 + eor r0, x2 ;[056] + or phase, r0 ;[057] + sbrc phase, USBMINUS ;[058] + lpm ;[059] optional nop3; modifies r0 + in phase, USBIN ;[060] <-- phase + eor x1, x2 ;[061] + bst x1, USBMINUS ;[062] + bld shift, 5 ;[063] + andi shift, 0x3f ;[064] + in x1, USBIN ;[065] <-- bit 6 + breq unstuff5 ;[066] *** unstuff escape + eor phase, x1 ;[067] + eor x2, x1 ;[068] + bst x2, USBMINUS ;[069] + bld shift, 6 ;[070] +didUnstuff6: ;[ ] + in r0, USBIN ;[071] <-- phase + cpi shift, 0x02 ;[072] + brlo unstuff6 ;[073] *** unstuff escape +didUnstuff5: ;[ ] + nop2 ;[074] +; [---] ;[075] + in x2, USBIN ;[076] <-- bit 7 + eor x1, x2 ;[077] + bst x1, USBMINUS ;[078] + bld shift, 7 ;[079] +didUnstuff7: ;[ ] + eor r0, x2 ;[080] + or phase, r0 ;[081] + in r0, USBIN ;[082] <-- phase + cpi shift, 0x04 ;[083] + brsh rxLoop ;[084] +; [---] ;[085] +unstuff7: ;[ ] + andi x3, ~0x80 ;[085] + ori shift, 0x80 ;[086] + in x2, USBIN ;[087] <-- sample stuffed bit 7 + nop ;[088] + rjmp didUnstuff7 ;[089] +; [---] ;[090] + ;[080] + +unstuff5: ;[067] + eor phase, x1 ;[068] + andi x3, ~0x20 ;[069] + ori shift, 0x20 ;[070] + in r0, USBIN ;[071] <-- phase + mov x2, x1 ;[072] + nop ;[073] + nop2 ;[074] +; [---] ;[075] + in x1, USBIN ;[076] <-- bit 6 + eor r0, x1 ;[077] + or phase, r0 ;[078] + eor x2, x1 ;[079] + bst x2, USBMINUS ;[080] + bld shift, 6 ;[081] no need to check bitstuffing, we just had one + in r0, USBIN ;[082] <-- phase + rjmp didUnstuff5 ;[083] +; [---] ;[084] + ;[074] + +unstuff6: ;[074] + andi x3, ~0x40 ;[075] + in x1, USBIN ;[076] <-- bit 6 again + ori shift, 0x40 ;[077] + nop2 ;[078] +; [---] ;[079] + rjmp didUnstuff6 ;[080] +; [---] ;[081] + ;[071] + +unstuff0: ;[013] + eor r0, x2 ;[014] + or phase, r0 ;[015] + andi x2, USBMASK ;[016] check for SE0 + in r0, USBIN ;[017] <-- phase + breq didUnstuff0 ;[018] direct jump to se0 would be too long + andi x3, ~0x01 ;[019] + ori shift, 0x01 ;[020] + mov x1, x2 ;[021] mov existing sample + in x2, USBIN ;[022] <-- bit 1 again + rjmp didUnstuff0 ;[023] +; [---] ;[024] + ;[014] + +unstuff1: ;[024] + eor r0, x1 ;[025] + or phase, r0 ;[026] + andi x3, ~0x02 ;[027] + in r0, USBIN ;[028] <-- phase + ori shift, 0x02 ;[029] + mov x2, x1 ;[030] + rjmp didUnstuff1 ;[031] +; [---] ;[032] + ;[022] + +unstuff2: ;[035] + eor r0, x2 ;[036] + or phase, r0 ;[037] + andi x3, ~0x04 ;[038] + in r0, USBIN ;[039] <-- phase + ori shift, 0x04 ;[040] + mov x1, x2 ;[041] + rjmp didUnstuff2 ;[042] +; [---] ;[043] + ;[033] + +unstuff3: ;[043] + in x2, USBIN ;[044] <-- bit 3 again + eor r0, x2 ;[045] + or phase, r0 ;[046] + andi x3, ~0x08 ;[047] + ori shift, 0x08 ;[048] + nop ;[049] + in r0, USBIN ;[050] <-- phase + rjmp didUnstuff3 ;[051] +; [---] ;[052] + ;[042] + +unstuff4: ;[053] + andi x3, ~0x10 ;[054] + in x1, USBIN ;[055] <-- bit 4 again + ori shift, 0x10 ;[056] + rjmp didUnstuff4 ;[057] +; [---] ;[058] + ;[048] + +rxLoop: ;[085] + eor x3, shift ;[086] reconstruct: x3 is 0 at bit locations we changed, 1 at others + in x1, USBIN ;[000] <-- bit 0 + st y+, x3 ;[001] +; [---] ;[002] + eor r0, x1 ;[003] + or phase, r0 ;[004] + eor x2, x1 ;[005] + in r0, USBIN ;[006] <-- phase + ser x3 ;[007] + bst x2, USBMINUS ;[008] + bld shift, 0 ;[009] + andi shift, 0xf9 ;[010] +rxbit1: ;[ ] + in x2, USBIN ;[011] <-- bit 1 + breq unstuff0 ;[012] *** unstuff escape + andi x2, USBMASK ;[013] SE0 check for bit 1 +didUnstuff0: ;[ ] Z only set if we detected SE0 in bitstuff + breq se0 ;[014] + eor r0, x2 ;[015] + or phase, r0 ;[016] + in r0, USBIN ;[017] <-- phase + eor x1, x2 ;[018] + bst x1, USBMINUS ;[019] + bld shift, 1 ;[020] + andi shift, 0xf3 ;[021] +didUnstuff1: ;[ ] + in x1, USBIN ;[022] <-- bit 2 + breq unstuff1 ;[023] *** unstuff escape + eor r0, x1 ;[024] + or phase, r0 ;[025] + subi cnt, 1 ;[026] overflow check + brcs overflow ;[027] + in r0, USBIN ;[028] <-- phase + eor x2, x1 ;[029] + bst x2, USBMINUS ;[030] + bld shift, 2 ;[031] + andi shift, 0xe7 ;[032] +didUnstuff2: ;[ ] + in x2, USBIN ;[033] <-- bit 3 + breq unstuff2 ;[034] *** unstuff escape + eor r0, x2 ;[035] + or phase, r0 ;[036] + eor x1, x2 ;[037] + bst x1, USBMINUS ;[038] + in r0, USBIN ;[039] <-- phase + bld shift, 3 ;[040] + andi shift, 0xcf ;[041] +didUnstuff3: ;[ ] + breq unstuff3 ;[042] *** unstuff escape + nop ;[043] + in x1, USBIN ;[044] <-- bit 4 + eor x2, x1 ;[045] + bst x2, USBMINUS ;[046] + bld shift, 4 ;[047] +didUnstuff4: ;[ ] + eor r0, x1 ;[048] + or phase, r0 ;[049] + in r0, USBIN ;[050] <-- phase + andi shift, 0x9f ;[051] + breq unstuff4 ;[052] *** unstuff escape + rjmp continueWithBit5;[053] +; [---] ;[054] + +macro POP_STANDARD ; 16 cycles + pop cnt + pop x4 + pop x3 + pop x2 + pop x1 + pop shift + pop YH + pop r0 + endm +macro POP_RETI ; 5 cycles + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) +; K = (D+ = 1), (D- = 0) +; Spec allows 7.5 bit times from EOP to SOP for replies + +bitstuff7: + eor x1, x4 ;[4] + ldi x2, 0 ;[5] + nop2 ;[6] C is zero (brcc) + rjmp didStuff7 ;[8] + +bitstuffN: + eor x1, x4 ;[5] + ldi x2, 0 ;[6] + lpm ;[7] 3 cycle NOP, modifies r0 + out USBOUT, x1 ;[10] <-- out + rjmp didStuffN ;[0] + +#define bitStatus x3 + +sendNakAndReti: + ldi cnt, USBPID_NAK ;[-19] + rjmp sendCntAndReti ;[-18] +sendAckAndReti: + ldi cnt, USBPID_ACK ;[-17] +sendCntAndReti: + mov r0, cnt ;[-16] + ldi YL, 0 ;[-15] R0 address is 0 + ldi YH, 0 ;[-14] + ldi cnt, 2 ;[-13] +; rjmp usbSendAndReti fallthrough + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] +;uses: x1...x4, shift, cnt, Y +;Numbers in brackets are time since first bit of sync pattern is sent +usbSendAndReti: ; 12 cycles until SOP + in x2, USBDDR ;[-12] + ori x2, USBMASK ;[-11] + sbi USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) + in x1, USBOUT ;[-8] port mirror for tx loop + out USBDDR, x2 ;[-7] <- acquire bus +; need not init x2 (bitstuff history) because sync starts with 0 + ldi x4, USBMASK ;[-6] exor mask + ldi shift, 0x80 ;[-5] sync byte is first byte sent + ldi bitStatus, 0xff ;[-4] init bit loop counter, works for up to 12 bytes +byteloop: +bitloop: + sbrs shift, 0 ;[8] [-3] + eor x1, x4 ;[9] [-2] + out USBOUT, x1 ;[10] [-1] <-- out + ror shift ;[0] + ror x2 ;[1] +didStuffN: + cpi x2, 0xfc ;[2] + brcc bitstuffN ;[3] + nop ;[4] + subi bitStatus, 37 ;[5] 256 / 7 ~=~ 37 + brcc bitloop ;[6] when we leave the loop, bitStatus has almost the initial value + sbrs shift, 0 ;[7] + eor x1, x4 ;[8] + ror shift ;[9] +didStuff7: + out USBOUT, x1 ;[10] <-- out + ror x2 ;[0] + cpi x2, 0xfc ;[1] + brcc bitstuff7 ;[2] + ld shift, y+ ;[3] + dec cnt ;[5] + brne byteloop ;[6] +;make SE0: + cbr x1, USBMASK ;[7] prepare SE0 [spec says EOP may be 21 to 25 cycles] + lds x2, usbNewDeviceAddr;[8] + lsl x2 ;[10] we compare with left shifted address + out USBOUT, x1 ;[11] <-- out SE0 -- from now 2 bits = 22 cycles until bus idle +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + subi YL, 2 ;[0] Only assign address on data packets, not ACK/NAK in r0 + sbci YH, 0 ;[1] + breq skipAddrAssign ;[2] + sts usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< 12 cycles per bit +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts +;register use in receive loop to receive the data bytes: +; shift assembles the byte currently being received +; x1 holds the D+ and D- line state +; x2 holds the previous line state +; cnt holds the number of bytes left in the receive buffer +; x3 holds the higher crc byte (see algorithm below) +; x4 is used as temporary register for the crc algorithm +; x5 is used for unstuffing: when unstuffing the last received bit is inverted in shift (to prevent further +; unstuffing calls. In the same time the corresponding bit in x5 is cleared to mark the bit as beening iverted +; zl lower crc value and crc table index +; zh used for crc table accesses + +;-------------------------------------------------------------------------------------------------------------- +; CRC mods: +; table driven crc checker, Z points to table in prog space +; ZL is the lower crc byte, x3 is the higher crc byte +; x4 is used as temp register to store different results +; the initialization of the crc register is not 0xFFFF but 0xFE54. This is because during the receipt of the +; first data byte an virtual zero data byte is added to the crc register, this results in the correct initial +; value of 0xFFFF at beginning of the second data byte before the first data byte is added to the crc. +; The magic number 0xFE54 results form the crc table: At tabH[0x54] = 0xFF = crcH (required) and +; tabL[0x54] = 0x01 -> crcL = 0x01 xor 0xFE = 0xFF +; bitcnt is renamed to x5 and is used for unstuffing purposes, the unstuffing works like in the 12MHz version +;-------------------------------------------------------------------------------------------------------------- +; CRC algorithm: +; The crc register is formed by x3 (higher byte) and ZL (lower byte). The algorithm uses a 'reversed' form +; i.e. that it takes the least significant bit first and shifts to the right. So in fact the highest order +; bit seen from the polynomial devision point of view is the lsb of ZL. (If this sounds strange to you i +; propose a research on CRC :-) ) +; Each data byte received is xored to ZL, the lower crc byte. This byte now builds the crc +; table index. Next the new high byte is loaded from the table and stored in x4 until we have space in x3 +; (its destination). +; Afterwards the lower table is loaded from the table and stored in ZL (the old index is overwritten as +; we don't need it anymore. In fact this is a right shift by 8 bits.) Now the old crc high value is xored +; to ZL, this is the second shift of the old crc value. Now x4 (the temp reg) is moved to x3 and the crc +; calculation is done. +; Prior to the first byte the two CRC register have to be initialized to 0xFFFF (as defined in usb spec) +; however the crc engine also runs during the receipt of the first byte, therefore x3 and zl are initialized +; to a magic number which results in a crc value of 0xFFFF after the first complete byte. +; +; This algorithm is split into the extra cycles of the different bits: +; bit7: XOR the received byte to ZL +; bit5: load the new high byte to x4 +; bit6: load the lower xor byte from the table, xor zl and x3, store result in zl (=the new crc low value) +; move x4 (the new high byte) to x3, the crc value is ready +; + + +macro POP_STANDARD ; 18 cycles + pop ZH + pop ZL + pop cnt + pop x5 + pop x3 + pop x2 + pop x1 + pop shift + pop x4 + endm +macro POP_RETI ; 7 cycles + pop YH + pop YL + out SREG, YL + pop YL + endm + +macro CRC_CLEANUP_AND_CHECK + ; the last byte has already been xored with the lower crc byte, we have to do the table lookup and xor + ; x3 is the higher crc byte, zl the lower one + ldi ZH, hi8(usbCrcTableHigh);[+1] get the new high byte from the table + lpm x2, Z ;[+2][+3][+4] + ldi ZH, hi8(usbCrcTableLow);[+5] get the new low xor byte from the table + lpm ZL, Z ;[+6][+7][+8] + eor ZL, x3 ;[+7] xor the old high byte with the value from the table, x2:ZL now holds the crc value + cpi ZL, 0x01 ;[+8] if the crc is ok we have a fixed remainder value of 0xb001 in x2:ZL (see usb spec) + brne ignorePacket ;[+9] detected a crc fault -> paket is ignored and retransmitted by the host + cpi x2, 0xb0 ;[+10] + brne ignorePacket ;[+11] detected a crc fault -> paket is ignored and retransmitted by the host + endm + + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG, YH, [sofError], x4, shift, x1, x2, x3, x5, cnt, ZL, ZH + push YL ;[-28] push only what is necessary to sync with edge ASAP + in YL, SREG ;[-26] + push YL ;[-25] + push YH ;[-23] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of < 1/4 bit which meets the spec. + sbis USBIN, USBMINUS ;[-17] + rjmp foundK ;[-16] + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: ;[-15] +;{3, 5} after falling D- edge, average delay: 4 cycles +;bit0 should be at 30 (2.5 bits) for center sampling. Currently at 4 so 26 cylces till bit 0 sample +;use 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push x4 ;[-14] +; [---] ;[-13] + lds YL, usbInputBufOffset;[-12] used to toggle the two usb receive buffers +; [---] ;[-11] + clr YH ;[-10] + subi YL, lo8(-(usbRxBuf));[-9] [rx loop init] + sbci YH, hi8(-(usbRxBuf));[-8] [rx loop init] + push shift ;[-7] +; [---] ;[-6] + ldi shift, 0x80 ;[-5] the last bit is the end of byte marker for the pid receiver loop + clc ;[-4] the carry has to be clear for receipt of pid bit 0 + sbis USBIN, USBMINUS ;[-3] we want two bits K (sample 3 cycles too early) + rjmp haveTwoBitsK ;[-2] + pop shift ;[-1] undo the push from before + pop x4 ;[1] + rjmp waitForK ;[3] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 24 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: + push x1 ;[0] + push x2 ;[2] + push x3 ;[4] crc high byte + ldi x2, 1< jump back and store the byte + ori shift, 0x01 ;[11] invert the last received bit to prevent furhter unstuffing + in x2, USBIN ;[0] we have some free cycles so we could check for bit stuffing errors + andi x5, 0xFE ;[1] mark this bit as inverted (will be corrected before storing shift) + eor x1, x2 ;[2] x1 and x2 have to be different because the stuff bit is always a zero + andi x1, USBMASK ;[3] mask the interesting bits + breq stuffErr ;[4] if the stuff bit is a 1-bit something went wrong + mov x1, x2 ;[5] the next bit expects the last state to be in x1 + rjmp didunstuff0 ;[6] + ;[7] jump delay of rjmp didunstuffX + +unstuff1: ;[11] this is the jump delay of breq unstuffX + in x1, USBIN ;[0] we have some free cycles so we could check for bit stuffing errors + ori shift, 0x02 ;[1] invert the last received bit to prevent furhter unstuffing + andi x5, 0xFD ;[2] mark this bit as inverted (will be corrected before storing shift) + eor x2, x1 ;[3] x1 and x2 have to be different because the stuff bit is always a zero + andi x2, USBMASK ;[4] mask the interesting bits + breq stuffErr ;[5] if the stuff bit is a 1-bit something went wrong + mov x2, x1 ;[6] the next bit expects the last state to be in x2 + nop2 ;[7] + ;[8] + rjmp didunstuff1 ;[9] + ;[10] jump delay of rjmp didunstuffX + +unstuff2: ;[9] this is the jump delay of breq unstuffX + ori shift, 0x04 ;[10] invert the last received bit to prevent furhter unstuffing + andi x5, 0xFB ;[11] mark this bit as inverted (will be corrected before storing shift) + in x2, USBIN ;[0] we have some free cycles so we could check for bit stuffing errors + eor x1, x2 ;[1] x1 and x2 have to be different because the stuff bit is always a zero + andi x1, USBMASK ;[2] mask the interesting bits + breq stuffErr ;[3] if the stuff bit is a 1-bit something went wrong + mov x1, x2 ;[4] the next bit expects the last state to be in x1 + nop2 ;[5] + ;[6] + rjmp didunstuff2 ;[7] + ;[8] jump delay of rjmp didunstuffX + +unstuff3: ;[9] this is the jump delay of breq unstuffX + ori shift, 0x08 ;[10] invert the last received bit to prevent furhter unstuffing + andi x5, 0xF7 ;[11] mark this bit as inverted (will be corrected before storing shift) + in x1, USBIN ;[0] we have some free cycles so we could check for bit stuffing errors + eor x2, x1 ;[1] x1 and x2 have to be different because the stuff bit is always a zero + andi x2, USBMASK ;[2] mask the interesting bits + breq stuffErr ;[3] if the stuff bit is a 1-bit something went wrong + mov x2, x1 ;[4] the next bit expects the last state to be in x2 + nop2 ;[5] + ;[6] + rjmp didunstuff3 ;[7] + ;[8] jump delay of rjmp didunstuffX + + + +; the include has to be here due to branch distance restirctions +#define __USE_CRC__ +#include "asmcommon.inc" + + + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) +; K = (D+ = 1), (D- = 0) +; Spec allows 7.5 bit times from EOP to SOP for replies +; 7.5 bit times is 90 cycles. ...there is plenty of time + + +sendNakAndReti: + ldi x3, USBPID_NAK ;[-18] + rjmp sendX3AndReti ;[-17] +sendAckAndReti: + ldi cnt, USBPID_ACK ;[-17] +sendCntAndReti: + mov x3, cnt ;[-16] +sendX3AndReti: + ldi YL, 20 ;[-15] x3==r20 address is 20 + ldi YH, 0 ;[-14] + ldi cnt, 2 ;[-13] +; rjmp usbSendAndReti fallthrough + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] +;uses: x1...x4, btcnt, shift, cnt, Y +;Numbers in brackets are time since first bit of sync pattern is sent + +usbSendAndReti: ; 12 cycles until SOP + in x2, USBDDR ;[-12] + ori x2, USBMASK ;[-11] + sbi USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) + in x1, USBOUT ;[-8] port mirror for tx loop + out USBDDR, x2 ;[-6] <- acquire bus + ldi x2, 0 ;[-6] init x2 (bitstuff history) because sync starts with 0 + ldi x4, USBMASK ;[-5] exor mask + ldi shift, 0x80 ;[-4] sync byte is first byte sent +txByteLoop: + ldi bitcnt, 0x40 ;[-3]=[9] binary 01000000 +txBitLoop: ; the loop sends the first 7 bits of the byte + sbrs shift, 0 ;[-2]=[10] if we have to send a 1 don't change the line state + eor x1, x4 ;[-1]=[11] + out USBOUT, x1 ;[0] + ror shift ;[1] + ror x2 ;[2] transfers the last sent bit to the stuffing history +didStuffN: + nop ;[3] + nop ;[4] + cpi x2, 0xfc ;[5] if we sent six consecutive ones + brcc bitstuffN ;[6] + lsr bitcnt ;[7] + brne txBitLoop ;[8] restart the loop while the 1 is still in the bitcount + +; transmit bit 7 + sbrs shift, 0 ;[9] + eor x1, x4 ;[10] +didStuff7: + ror shift ;[11] + out USBOUT, x1 ;[0] transfer bit 7 to the pins + ror x2 ;[1] move the bit into the stuffing history + cpi x2, 0xfc ;[2] + brcc bitstuff7 ;[3] + ld shift, y+ ;[4] get next byte to transmit + dec cnt ;[5] decrement byte counter + brne txByteLoop ;[7] if we have more bytes start next one + ;[8] branch delay + +;make SE0: + cbr x1, USBMASK ;[8] prepare SE0 [spec says EOP may be 25 to 30 cycles] + lds x2, usbNewDeviceAddr;[9] + lsl x2 ;[11] we compare with left shifted address + out USBOUT, x1 ;[0] <-- out SE0 -- from now 2 bits = 24 cycles until bus idle + subi YL, 20 + 2 ;[1] Only assign address on data packets, not ACK/NAK in x3 + sbci YH, 0 ;[2] +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + breq skipAddrAssign ;[3] + sts usbDeviceAddr, x2 ; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< +int main (int argc, char **argv) +{ + int i, j; + for (i=0; i<512; i++){ + unsigned short crc = i & 0xff; + for(j=0; j<8; j++) crc = (crc >> 1) ^ ((crc & 1) ? 0xa001 : 0); + if((i & 7) == 0) printf("\n.byte "); + printf("0x%02x, ", (i > 0xff ? (crc >> 8) : crc) & 0xff); + if(i == 255) printf("\n"); + } + return 0; +} + +// Use the following algorithm to compute CRC values: +ushort computeCrc(uchar *msg, uchar msgLen) +{ + uchar i; + ushort crc = 0xffff; + for(i = 0; i < msgLen; i++) + crc = usbCrcTable16[lo8(crc) ^ msg[i]] ^ hi8(crc); + return crc; +} +*/ + +.balign 256 +usbCrcTableLow: +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 + +; .balign 256 +usbCrcTableHigh: +.byte 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2 +.byte 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04 +.byte 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E +.byte 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8 +.byte 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A +.byte 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC +.byte 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6 +.byte 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10 +.byte 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32 +.byte 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4 +.byte 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE +.byte 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38 +.byte 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA +.byte 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C +.byte 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26 +.byte 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0 +.byte 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62 +.byte 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4 +.byte 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE +.byte 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68 +.byte 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA +.byte 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C +.byte 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76 +.byte 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0 +.byte 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92 +.byte 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54 +.byte 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E +.byte 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98 +.byte 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A +.byte 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C +.byte 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86 +.byte 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 + diff --git a/adb2usb/uart2usb/usbdrv/usbdrvasm20.inc b/adb2usb/uart2usb/usbdrv/usbdrvasm20.inc new file mode 100644 index 0000000..303abaf --- /dev/null +++ b/adb2usb/uart2usb/usbdrv/usbdrvasm20.inc @@ -0,0 +1,360 @@ +/* Name: usbdrvasm20.inc + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Jeroen Benschop + * Based on usbdrvasm16.inc from Christian Starkjohann + * Creation Date: 2008-03-05 + * Tabsize: 4 + * Copyright: (c) 2008 by Jeroen Benschop and OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Revision: $Id: usbdrvasm20.inc 740 2009-04-13 18:23:31Z cs $ + */ + +/* Do not link this file! Link usbdrvasm.S instead, which includes the + * appropriate implementation! + */ + +/* +General Description: +This file is the 20 MHz version of the asssembler part of the USB driver. It +requires a 20 MHz crystal (not a ceramic resonator and not a calibrated RC +oscillator). + +See usbdrv.h for a description of the entire driver. + +Since almost all of this code is timing critical, don't change unless you +really know what you are doing! Many parts require not only a maximum number +of CPU cycles, but even an exact number of cycles! +*/ + +#define leap2 x3 +#ifdef __IAR_SYSTEMS_ASM__ +#define nextInst $+2 +#else +#define nextInst .+0 +#endif + +;max stack usage: [ret(2), YL, SREG, YH, bitcnt, shift, x1, x2, x3, x4, cnt] = 12 bytes +;nominal frequency: 20 MHz -> 13.333333 cycles per bit, 106.666667 cycles per byte +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts +;register use in receive loop: +; shift assembles the byte currently being received +; x1 holds the D+ and D- line state +; x2 holds the previous line state +; x4 (leap) is used to add a leap cycle once every three bytes received +; X3 (leap2) is used to add a leap cycle once every three stuff bits received +; bitcnt is used to determine when a stuff bit is due +; cnt holds the number of bytes left in the receive buffer + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG YH, [sofError], bitcnt, shift, x1, x2, x3, x4, cnt + push YL ;[-28] push only what is necessary to sync with edge ASAP + in YL, SREG ;[-26] + push YL ;[-25] + push YH ;[-23] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of < 1/4 bit which meets the spec. + sbis USBIN, USBMINUS ;[-19] + rjmp foundK ;[-18] + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: ;[-16] +;{3, 5} after falling D- edge, average delay: 4 cycles +;bit0 should be at 34 for center sampling. Currently at 4 so 30 cylces till bit 0 sample +;use 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push bitcnt ;[-16] +; [---] ;[-15] + lds YL, usbInputBufOffset;[-14] +; [---] ;[-13] + clr YH ;[-12] + subi YL, lo8(-(usbRxBuf));[-11] [rx loop init] + sbci YH, hi8(-(usbRxBuf));[-10] [rx loop init] + push shift ;[-9] +; [---] ;[-8] + ldi shift,0x40 ;[-7] set msb to "1" so processing bit7 can be detected + nop2 ;[-6] +; [---] ;[-5] + ldi bitcnt, 5 ;[-4] [rx loop init] + sbis USBIN, USBMINUS ;[-3] we want two bits K (sample 3 cycles too early) + rjmp haveTwoBitsK ;[-2] + pop shift ;[-1] undo the push from before + pop bitcnt ;[1] + rjmp waitForK ;[3] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 27 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: + push x1 ;[0] + push x2 ;[2] + push x3 ;[4] (leap2) + ldi leap2, 0x55 ;[6] add leap cycle on 2nd,5th,8th,... stuff bit + push x4 ;[7] == leap + ldi leap, 0x55 ;[9] skip leap cycle on 2nd,5th,8th,... byte received + push cnt ;[10] + ldi cnt, USB_BUFSIZE ;[12] [rx loop init] + ldi x2, 1< +#ifndef __IAR_SYSTEMS_ASM__ +# include +#endif + +#define __attribute__(arg) /* not supported on IAR */ + +#ifdef __IAR_SYSTEMS_ASM__ +# define __ASSEMBLER__ /* IAR does not define standard macro for asm */ +#endif + +#ifdef __HAS_ELPM__ +# define PROGMEM __farflash +#else +# define PROGMEM __flash +#endif + +#define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) + +/* The following definitions are not needed by the driver, but may be of some + * help if you port a gcc based project to IAR. + */ +#define cli() __disable_interrupt() +#define sei() __enable_interrupt() +#define wdt_reset() __watchdog_reset() +#define _BV(x) (1 << (x)) + +/* assembler compatibility macros */ +#define nop2 rjmp $+2 /* jump to next instruction */ +#define XL r26 +#define XH r27 +#define YL r28 +#define YH r29 +#define ZL r30 +#define ZH r31 +#define lo8(x) LOW(x) +#define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */ + +/* Depending on the device you use, you may get problems with the way usbdrv.h + * handles the differences between devices. Since IAR does not use #defines + * for MCU registers, we can't check for the existence of a particular + * register with an #ifdef. If the autodetection mechanism fails, include + * definitions for the required USB_INTR_* macros in your usbconfig.h. See + * usbconfig-prototype.h and usbdrv.h for details. + */ + +/* ------------------------------------------------------------------------- */ +#elif __CODEVISIONAVR__ /* check for CodeVision AVR */ +/* ------------------------------------------------------------------------- */ +/* This port is not working (yet) */ + +/* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */ + +#include +#include + +#define __attribute__(arg) /* not supported on IAR */ + +#define PROGMEM __flash +#define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) + +#ifndef __ASSEMBLER__ +static inline void cli(void) +{ + #asm("cli"); +} +static inline void sei(void) +{ + #asm("sei"); +} +#endif +#define _delay_ms(t) delay_ms(t) +#define _BV(x) (1 << (x)) +#define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */ + +#define macro .macro +#define endm .endmacro +#define nop2 rjmp .+0 /* jump to next instruction */ + +/* ------------------------------------------------------------------------- */ +#else /* default development environment is avr-gcc/avr-libc */ +/* ------------------------------------------------------------------------- */ + +#include +#ifdef __ASSEMBLER__ +# define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */ +#else +# include +#endif + +#if USB_CFG_DRIVER_FLASH_PAGE +# define USB_READ_FLASH(addr) pgm_read_byte_far(((long)USB_CFG_DRIVER_FLASH_PAGE << 16) | (long)(addr)) +#else +# define USB_READ_FLASH(addr) pgm_read_byte(addr) +#endif + +#define macro .macro +#define endm .endm +#define nop2 rjmp .+0 /* jump to next instruction */ + +#endif /* development environment */ + +/* for conveniecne, ensure that PRG_RDB exists */ +#ifndef PRG_RDB +# define PRG_RDB(addr) USB_READ_FLASH(addr) +#endif +#endif /* __usbportability_h_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb b/adb2usb/uart2usb/vusb new file mode 120000 index 0000000..8bfa54c --- /dev/null +++ b/adb2usb/uart2usb/vusb @@ -0,0 +1 @@ +vusb-20100715 \ No newline at end of file diff --git a/adb2usb/uart2usb/vusb-20100715/Changelog.txt b/adb2usb/uart2usb/vusb-20100715/Changelog.txt new file mode 100644 index 0000000..5c6354a --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/Changelog.txt @@ -0,0 +1,308 @@ +This file documents changes in the firmware-only USB driver for atmel's AVR +microcontrollers. New entries are always appended to the end of the file. +Scroll down to the bottom to see the most recent changes. + +2005-04-01: + - Implemented endpoint 1 as interrupt-in endpoint. + - Moved all configuration options to usbconfig.h which is not part of the + driver. + - Changed interface for usbVendorSetup(). + - Fixed compatibility with ATMega8 device. + - Various minor optimizations. + +2005-04-11: + - Changed interface to application: Use usbFunctionSetup(), usbFunctionRead() + and usbFunctionWrite() now. Added configuration options to choose which + of these functions to compile in. + - Assembler module delivers receive data non-inverted now. + - Made register and bit names compatible with more AVR devices. + +2005-05-03: + - Allow address of usbRxBuf on any memory page as long as the buffer does + not cross 256 byte page boundaries. + - Better device compatibility: works with Mega88 now. + - Code optimization in debugging module. + - Documentation updates. + +2006-01-02: + - Added (free) default Vendor- and Product-IDs bought from voti.nl. + - Added USBID-License.txt file which defines the rules for using the free + shared VID/PID pair. + - Added Readme.txt to the usbdrv directory which clarifies administrative + issues. + +2006-01-25: + - Added "configured state" to become more standards compliant. + - Added "HALT" state for interrupt endpoint. + - Driver passes the "USB Command Verifier" test from usb.org now. + - Made "serial number" a configuration option. + - Minor optimizations, we now recommend compiler option "-Os" for best + results. + - Added a version number to usbdrv.h + +2006-02-03: + - New configuration variable USB_BUFFER_SECTION for the memory section where + the USB rx buffer will go. This defaults to ".bss" if not defined. Since + this buffer MUST NOT cross 256 byte pages (not even touch a page at the + end), the user may want to pass a linker option similar to + "-Wl,--section-start=.mybuffer=0x800060". + - Provide structure for usbRequest_t. + - New defines for USB constants. + - Prepared for HID implementations. + - Increased data size limit for interrupt transfers to 8 bytes. + - New macro usbInterruptIsReady() to query interrupt buffer state. + +2006-02-18: + - Ensure that the data token which is sent as an ack to an OUT transfer is + always zero sized. This fixes a bug where the host reports an error after + sending an out transfer to the device, although all data arrived at the + device. + - Updated docs in usbdrv.h to reflect changed API in usbFunctionWrite(). + +* Release 2006-02-20 + + - Give a compiler warning when compiling with debugging turned on. + - Added Oleg Semyonov's changes for IAR-cc compatibility. + - Added new (optional) functions usbDeviceConnect() and usbDeviceDisconnect() + (also thanks to Oleg!). + - Rearranged tests in usbPoll() to save a couple of instructions in the most + likely case that no actions are pending. + - We need a delay between the SET ADDRESS request until the new address + becomes active. This delay was handled in usbPoll() until now. Since the + spec says that the delay must not exceed 2ms, previous versions required + aggressive polling during the enumeration phase. We have now moved the + handling of the delay into the interrupt routine. + - We must not reply with NAK to a SETUP transaction. We can only achieve this + by making sure that the rx buffer is empty when SETUP tokens are expected. + We therefore don't pass zero sized data packets from the status phase of + a transfer to usbPoll(). This change MAY cause troubles if you rely on + receiving a less than 8 bytes long packet in usbFunctionWrite() to + identify the end of a transfer. usbFunctionWrite() will NEVER be called + with a zero length. + +* Release 2006-03-14 + + - Improved IAR C support: tiny memory model, more devices + - Added template usbconfig.h file under the name usbconfig-prototype.h + +* Release 2006-03-26 + + - Added provision for one more interrupt-in endpoint (endpoint 3). + - Added provision for one interrupt-out endpoint (endpoint 1). + - Added flowcontrol macros for USB. + - Added provision for custom configuration descriptor. + - Allow ANY two port bits for D+ and D-. + - Merged (optional) receive endpoint number into global usbRxToken variable. + - Use USB_CFG_IOPORTNAME instead of USB_CFG_IOPORT. We now construct the + variable name from the single port letter instead of computing the address + of related ports from the output-port address. + +* Release 2006-06-26 + + - Updated documentation in usbdrv.h and usbconfig-prototype.h to reflect the + new features. + - Removed "#warning" directives because IAR does not understand them. Use + unused static variables instead to generate a warning. + - Do not include when compiling with IAR. + - Introduced USB_CFG_DESCR_PROPS_* in usbconfig.h to configure how each + USB descriptor should be handled. It is now possible to provide descriptor + data in Flash, RAM or dynamically at runtime. + - STALL is now a status in usbTxLen* instead of a message. We can now conform + to the spec and leave the stall status pending until it is cleared. + - Made usbTxPacketCnt1 and usbTxPacketCnt3 public. This allows the + application code to reset data toggling on interrupt pipes. + +* Release 2006-07-18 + + - Added an #if !defined __ASSEMBLER__ to the warning in usbdrv.h. This fixes + an assembler error. + - usbDeviceDisconnect() takes pull-up resistor to high impedance now. + +* Release 2007-02-01 + + - Merged in some code size improvements from usbtiny (thanks to Dick + Streefland for these optimizations!) + - Special alignment requirement for usbRxBuf not required any more. Thanks + again to Dick Streefland for this hint! + - Reverted to "#warning" instead of unused static variables -- new versions + of IAR CC should handle this directive. + - Changed Open Source license to GNU GPL v2 in order to make linking against + other free libraries easier. We no longer require publication of the + circuit diagrams, but we STRONGLY encourage it. If you improve the driver + itself, PLEASE grant us a royalty free license to your changes for our + commercial license. + +* Release 2007-03-29 + + - New configuration option "USB_PUBLIC" in usbconfig.h. + - Set USB version number to 1.10 instead of 1.01. + - Code used USB_CFG_DESCR_PROPS_STRING_DEVICE and + USB_CFG_DESCR_PROPS_STRING_PRODUCT inconsistently. Changed all occurrences + to USB_CFG_DESCR_PROPS_STRING_PRODUCT. + - New assembler module for 16.5 MHz RC oscillator clock with PLL in receiver + code. + - New assembler module for 16 MHz crystal. + - usbdrvasm.S contains common code only, clock-specific parts have been moved + to usbdrvasm12.S, usbdrvasm16.S and usbdrvasm165.S respectively. + +* Release 2007-06-25 + + - 16 MHz module: Do SE0 check in stuffed bits as well. + +* Release 2007-07-07 + + - Define hi8(x) for IAR compiler to limit result to 8 bits. This is necessary + for negative values. + - Added 15 MHz module contributed by V. Bosch. + - Interrupt vector name can now be configured. This is useful if somebody + wants to use a different hardware interrupt than INT0. + +* Release 2007-08-07 + + - Moved handleIn3 routine in usbdrvasm16.S so that relative jump range is + not exceeded. + - More config options: USB_RX_USER_HOOK(), USB_INITIAL_DATATOKEN, + USB_COUNT_SOF + - USB_INTR_PENDING can now be a memory address, not just I/O + +* Release 2007-09-19 + + - Split out common parts of assembler modules into separate include file + - Made endpoint numbers configurable so that given interface definitions + can be matched. See USB_CFG_EP3_NUMBER in usbconfig-prototype.h. + - Store endpoint number for interrupt/bulk-out so that usbFunctionWriteOut() + can handle any number of endpoints. + - Define usbDeviceConnect() and usbDeviceDisconnect() even if no + USB_CFG_PULLUP_IOPORTNAME is defined. Directly set D+ and D- to 0 in this + case. + +* Release 2007-12-01 + + - Optimize usbDeviceConnect() and usbDeviceDisconnect() for less code size + when USB_CFG_PULLUP_IOPORTNAME is not defined. + +* Release 2007-12-13 + + - Renamed all include-only assembler modules from *.S to *.inc so that + people don't add them to their project sources. + - Distribute leap bits in tx loop more evenly for 16 MHz module. + - Use "macro" and "endm" instead of ".macro" and ".endm" for IAR + - Avoid compiler warnings for constant expr range by casting some values in + USB descriptors. + +* Release 2008-01-21 + + - Fixed bug in 15 and 16 MHz module where the new address set with + SET_ADDRESS was already accepted at the next NAK or ACK we send, not at + the next data packet we send. This caused problems when the host polled + too fast. Thanks to Alexander Neumann for his help and patience debugging + this issue! + +* Release 2008-02-05 + + - Fixed bug in 16.5 MHz module where a register was used in the interrupt + handler before it was pushed. This bug was introduced with version + 2007-09-19 when common parts were moved to a separate file. + - Optimized CRC routine (thanks to Reimar Doeffinger). + +* Release 2008-02-16 + + - Removed outdated IAR compatibility stuff (code sections). + - Added hook macros for USB_RESET_HOOK() and USB_SET_ADDRESS_HOOK(). + - Added optional routine usbMeasureFrameLength() for calibration of the + internal RC oscillator. + +* Release 2008-02-28 + + - USB_INITIAL_DATATOKEN defaults to USBPID_DATA1 now, which means that we + start with sending USBPID_DATA0. + - Changed defaults in usbconfig-prototype.h + - Added free USB VID/PID pair for MIDI class devices + - Restructured AVR-USB as separate package, not part of PowerSwitch any more. + +* Release 2008-04-18 + + - Restructured usbdrv.c so that it is easier to read and understand. + - Better code optimization with gcc 4. + - If a second interrupt in endpoint is enabled, also add it to config + descriptor. + - Added config option for long transfers (above 254 bytes), see + USB_CFG_LONG_TRANSFERS in usbconfig.h. + - Added 20 MHz module contributed by Jeroen Benschop. + +* Release 2008-05-13 + + - Fixed bug in libs-host/hiddata.c function usbhidGetReport(): length + was not incremented, pointer to length was incremented instead. + - Added code to command line tool(s) which claims an interface. This code + is disabled by default, but may be necessary on newer Linux kernels. + - Added usbconfig.h option "USB_CFG_CHECK_DATA_TOGGLING". + - New header "usbportability.h" prepares ports to other development + environments. + - Long transfers (above 254 bytes) did not work when usbFunctionRead() was + used to supply the data. Fixed this bug. [Thanks to Alexander Neumann!] + - In hiddata.c (example code for sending/receiving data over HID), use + USB_RECIP_DEVICE instead of USB_RECIP_INTERFACE for control transfers so + that we need not claim the interface. + - in usbPoll() loop 20 times polling for RESET state instead of 10 times. + This accounts for the higher clock rates we now support. + - Added a module for 12.8 MHz RC oscillator with PLL in receiver loop. + - Added hook to SOF code so that oscillator can be tuned to USB frame clock. + - Added timeout to waitForJ loop. Helps preventing unexpected hangs. + - Added example code for oscillator tuning to libs-device (thanks to + Henrik Haftmann for the idea to this routine). + - Implemented option USB_CFG_SUPPRESS_INTR_CODE. + +* Release 2008-10-22 + + - Fixed libs-device/osctune.h: OSCCAL is memory address on ATMega88 and + similar, not offset of 0x20 needs to be added. + - Allow distribution under GPLv3 for those who have to link against other + code distributed under GPLv3. + +* Release 2008-11-26 + + - Removed libusb-win32 dependency for hid-data example in Makefile.windows. + It was never required and confused many people. + - Added extern uchar usbRxToken to usbdrv.h. + - Integrated a module with CRC checks at 18 MHz by Lukas Schrittwieser. + +* Release 2009-03-23 + + - Hid-mouse example used settings from hid-data example, fixed that. + - Renamed project to V-USB due to a trademark issue with Atmel(r). + - Changed CommercialLicense.txt and USBID-License.txt to make the + background of USB ID registration clearer. + +* Release 2009-04-15 + + - Changed CommercialLicense.txt to reflect the new range of PIDs from + Jason Kotzin. + - Removed USBID-License.txt in favor of USB-IDs-for-free.txt and + USB-ID-FAQ.txt + - Fixed a bug in the 12.8 MHz module: End Of Packet decection was made in + the center between bit 0 and 1 of each byte. This is where the data lines + are expected to change and the sampled data may therefore be nonsense. + We therefore check EOP ONLY if bits 0 AND 1 have both been read as 0 on D-. + - Fixed a bitstuffing problem in the 16 MHz module: If bit 6 was stuffed, + the unstuffing code in the receiver routine was 1 cycle too long. If + multiple bytes had the unstuffing in bit 6, the error summed up until the + receiver was out of sync. + - Included option for faster CRC routine. + Thanks to Slawomir Fras (BoskiDialer) for this code! + - Updated bits in Configuration Descriptor's bmAttributes according to + USB 1.1 (in particular bit 7, it is a must-be-set bit now). + +* Release 2009-08-22 + + - Moved first DBG1() after odDebugInit() in all examples. + - Use vector INT0_vect instead of SIG_INTERRUPT0 if defined. This makes + V-USB compatible with the new "p" suffix devices (e.g. ATMega328p). + - USB_CFG_CLOCK_KHZ setting is now required in usbconfig.h (no default any + more). + - New option USB_CFG_DRIVER_FLASH_PAGE allows boot loaders on devices with + more than 64 kB flash. + - Built-in configuration descriptor allows custom definition for second + endpoint now. + +* Release 2010-07-15 diff --git a/adb2usb/uart2usb/vusb-20100715/CommercialLicense.txt b/adb2usb/uart2usb/vusb-20100715/CommercialLicense.txt new file mode 100644 index 0000000..11d07d9 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/CommercialLicense.txt @@ -0,0 +1,166 @@ +V-USB Driver Software License Agreement +Version 2009-08-03 + +THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN +ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING +THE AMOUNT ACCORDING TO SECTION 4 ("PAYMENT") TO OBJECTIVE DEVELOPMENT. + + +1 DEFINITIONS + +1.1 "OBJECTIVE DEVELOPMENT" shall mean OBJECTIVE DEVELOPMENT Software GmbH, +Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA. + +1.2 "You" shall mean the Licensee. + +1.3 "V-USB" shall mean all files included in the package distributed under +the name "vusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/vusb/) +unless otherwise noted. This includes the firmware-only USB device +implementation for Atmel AVR microcontrollers, some simple device examples +and host side software examples and libraries. + + +2 LICENSE GRANTS + +2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source +code of V-USB. + +2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the +non-exclusive right to use, copy and distribute V-USB with your hardware +product(s), restricted by the limitations in section 3 below. + +2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify +the source code and your copy of V-USB according to your needs. + +2.4 USB IDs. OBJECTIVE DEVELOPMENT furnishes you with one or two USB +Product ID(s), sent to you in e-mail. These Product IDs are reserved +exclusively for you. OBJECTIVE DEVELOPMENT has obtained USB Product ID +ranges under the Vendor ID 5824 from Wouter van Ooijen (Van Ooijen +Technische Informatica, www.voti.nl) and under the Vendor ID 8352 from +Jason Kotzin (Clay Logic, www.claylogic.com). Both owners of the Vendor IDs +have obtained these IDs from the USB Implementers Forum, Inc. +(www.usb.org). OBJECTIVE DEVELOPMENT disclaims all liability which might +arise from the assignment of USB IDs. + +2.5 USB Certification. Although not part of this agreement, we want to make +it clear that you cannot become USB certified when you use V-USB or a USB +Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't +meet the electrical specifications required by the USB specification and +the USB Implementers Forum certifies only members who bought a Vendor ID of +their own. + + +3 LICENSE RESTRICTIONS + +3.1 Number of Units. Only one of the following three definitions is +applicable. Which one is determined by the amount you pay to OBJECTIVE +DEVELOPMENT, see section 4 ("Payment") below. + +Hobby License: You may use V-USB according to section 2 above in no more +than 5 hardware units. These units must not be sold for profit. + +Entry Level License: You may use V-USB according to section 2 above in no +more than 150 hardware units. + +Professional License: You may use V-USB according to section 2 above in +any number of hardware units, except for large scale production ("unlimited +fair use"). Quantities below 10,000 units are not considered large scale +production. If your reach quantities which are obviously large scale +production, you must pay a license fee of 0.10 EUR per unit for all units +above 10,000. + +3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber +any copy of V-USB, or any of the rights granted herein. + +3.3 Transfer. You may not transfer your rights under this Agreement to +another party without OBJECTIVE DEVELOPMENT's prior written consent. If +such consent is obtained, you may permanently transfer this License to +another party. The recipient of such transfer must agree to all terms and +conditions of this Agreement. + +3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not +expressly granted. + +3.5 Non-Exclusive Rights. Your license rights under this Agreement are +non-exclusive. + +3.6 Third Party Rights. This Agreement cannot grant you rights controlled +by third parties. In particular, you are not allowed to use the USB logo or +other trademarks owned by the USB Implementers Forum, Inc. without their +consent. Since such consent depends on USB certification, it should be +noted that V-USB will not pass certification because it does not +implement checksum verification and the microcontroller ports do not meet +the electrical specifications. + + +4 PAYMENT + +The payment amount depends on the variation of this agreement (according to +section 3.1) into which you want to enter. Concrete prices are listed on +OBJECTIVE DEVELOPMENT's web site, usually at +http://www.obdev.at/vusb/license.html. You agree to pay the amount listed +there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor +or reseller. + + +5 COPYRIGHT AND OWNERSHIP + +V-USB is protected by copyright laws and international copyright +treaties, as well as other intellectual property laws and treaties. V-USB +is licensed, not sold. + + +6 TERM AND TERMINATION + +6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE +DEVELOPMENT may terminate this Agreement and revoke the granted license and +USB-IDs if you fail to comply with any of its terms and conditions. + +6.2 Survival of Terms. All provisions regarding secrecy, confidentiality +and limitation of liability shall survive termination of this agreement. + + +7 DISCLAIMER OF WARRANTY AND LIABILITY + +LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE +DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND +NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE +TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL +RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO +STATE/JURISDICTION. + +LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, +IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY +SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER +(INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, +BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY +LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE +PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE +DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY +CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS +AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB. + + +8 MISCELLANEOUS TERMS + +8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing +purposes that you entered into this agreement. + +8.2 Entire Agreement. This document represents the entire agreement between +OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by +an authorized representative of both, OBJECTIVE DEVELOPMENT and you. + +8.3 Severability. In case a provision of these terms and conditions should +be or become partly or entirely invalid, ineffective, or not executable, +the validity of all other provisions shall not be affected. + +8.4 Applicable Law. This agreement is governed by the laws of the Republic +of Austria. + +8.5 Responsible Courts. The responsible courts in Vienna/Austria will have +exclusive jurisdiction regarding all disputes in connection with this +agreement. + diff --git a/adb2usb/uart2usb/vusb-20100715/License.txt b/adb2usb/uart2usb/vusb-20100715/License.txt new file mode 100644 index 0000000..4460cfb --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/License.txt @@ -0,0 +1,361 @@ +OBJECTIVE DEVELOPMENT GmbH's V-USB driver software is distributed under the +terms and conditions of the GNU GPL version 2 or the GNU GPL version 3. It is +your choice whether you apply the terms of version 2 or version 3. The full +text of GPLv2 is included below. In addition to the requirements in the GPL, +we STRONGLY ENCOURAGE you to do the following: + +(1) Publish your entire project on a web site and drop us a note with the URL. +Use the form at http://www.obdev.at/vusb/feedback.html for your submission. + +(2) Adhere to minimum publication standards. Please include AT LEAST: + - a circuit diagram in PDF, PNG or GIF format + - full source code for the host software + - a Readme.txt file in ASCII format which describes the purpose of the + project and what can be found in which directories and which files + - a reference to http://www.obdev.at/vusb/ + +(3) If you improve the driver firmware itself, please give us a free license +to your modifications for our commercial license offerings. + + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License. diff --git a/adb2usb/uart2usb/vusb-20100715/Readme.txt b/adb2usb/uart2usb/vusb-20100715/Readme.txt new file mode 100644 index 0000000..84d27f9 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/Readme.txt @@ -0,0 +1,83 @@ +This is the Readme file for V-USB and related code. V-USB is Objective +Development's firmware-only USB driver for Atmel's(r) AVR(r) microcontrollers. +For more information please visit http://www.obdev.at/vusb/. + +To avoid name confusion: This project was formerly known as AVR-USB. Due to +a trademark issue, it was renamed to V-USB in April 2009. + + +WHAT IS INCLUDED IN THIS PACKAGE? +================================= +This package consists of the device side USB driver firmware, library code +for device and host and fully working examples for device and host: + + Readme.txt .............. The file you are currently reading. + usbdrv .................. V-USB firmware, to be included in your project. + examples ................ Example code for device and host side. + libs-device ............. Useful code snippets for the device firmware. + libs-host ............... Useful code snippets for host-side drivers. + circuits ................ Example circuits using this driver. + Changelog.txt ........... Documentation of changes between versions. + License.txt ............. Free Open Source license for this package (GPL). + CommercialLicense.txt ... Alternative commercial license for this package. + USB-ID-FAQ.txt .......... General infos about USB Product- and Vendor-IDs. + USB-IDs-for-free.txt .... List and terms of use for free shared PIDs. + +Each subdirectory contains a separate Readme file which explains its +contents. We recommend that you also read the Readme.txt file in the +usbdrv subdirectory. + + +PREREQUISITES +============= +The AVR code of V-USB is written in C and assembler. You need either +avr-gcc or IAR CC to compile the project. We recommend avr-gcc because it +is free and easily available. Gcc version 3 generates slightly more +efficient code than version 4 for V-USB. Not every release is tested with +the IAR compiler. Previous versions have been tested with IAR 4.10B/W32 and +4.12A/W32 on an ATmega8 with the "small" and "tiny" memory model. + +Ready made avr-gcc tool chains are available for most operating systems: + * Windows: WinAVR http://winavr.sourceforge.net/ + * Mac: CrossPack for AVR Development http://www.obdev.at/crosspack/ + * Linux and other Unixes: Most free Unixes have optional packages for AVR + development. If not, follow the instructions at + http://www.nongnu.org/avr-libc/user-manual/install_tools.html + +Our host side examples are compiled with gcc on all platforms. Gcc is the +default C compiler on Mac, Linux and many other Unixes. On windows, we +recommend MinGW (http://www.mingw.org/). Use the automated MinGW installer +for least troubles. You also need MSYS from the same site to work with +standard Makefiles. + +Most examples also depend on libusb. Libusb is available from +http://libusb.sourceforge.net/ for Unix and +http://libusb-win32.sourceforge.net/ for Windows. + + +TECHNICAL DOCUMENTATION +======================= +The API reference of the driver firmware can be found in usbdrv/usbdrv.h. +Documentation for host and device library files are in the respective header +files. For more information, see our documentation wiki at +http://www.obdev.at/goto.php?t=vusb-wiki. + +See the file usbdrv/Readme.txt for more info about the driver itself. + + +LICENSE +======= +V-USB and related code is distributed under the terms of the GNU General +Public License (GPL) version 2 (see License.txt for details) and the GNU +General Public License (GPL) version 3. It is your choice whether you apply +the terms of version 2 or version 3. In addition to the terms of the GPL, we +strongly encourage you to publish your entire project and mail OBJECTIVE +DEVELOPMENT a link to your publication. + +Alternatively, we offer a commercial license without the restrictions of the +GPL. See CommercialLicense.txt for details. + + +---------------------------------------------------------------------------- +(c) 2010 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/USB-ID-FAQ.txt b/adb2usb/uart2usb/vusb-20100715/USB-ID-FAQ.txt new file mode 100644 index 0000000..d1de8fb --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/USB-ID-FAQ.txt @@ -0,0 +1,149 @@ +Version 2009-08-22 + +========================== +WHY DO WE NEED THESE IDs? +========================== + +USB is more than a low level protocol for data transport. It also defines a +common set of requests which must be understood by all devices. And as part +of these common requests, the specification defines data structures, the +USB Descriptors, which are used to describe the properties of the device. + +From the perspective of an operating system, it is therefore possible to find +out basic properties of a device (such as e.g. the manufacturer and the name +of the device) without a device-specific driver. This is essential because +the operating system can choose a driver to load based on this information +(Plug-And-Play). + +Among the most important properties in the Device Descriptor are the USB +Vendor- and Product-ID. Both are 16 bit integers. The most simple form of +driver matching is based on these IDs. The driver announces the Vendor- and +Product-IDs of the devices it can handle and the operating system loads the +appropriate driver when the device is connected. + +It is obvious that this technique only works if the pair Vendor- plus +Product-ID is unique: Only devices which require the same driver can have the +same pair of IDs. + + +===================================================== +HOW DOES THE USB STANDARD ENSURE THAT IDs ARE UNIQUE? +===================================================== + +Since it is so important that USB IDs are unique, the USB Implementers Forum, +Inc. (usb.org) needs a way to enforce this legally. It is not forbidden by +law to build a device and assign it any random numbers as IDs. Usb.org +therefore needs an agreement to regulate the use of USB IDs. The agreement +binds only parties who agreed to it, of course. Everybody else is free to use +any numbers for their IDs. + +So how can usb.org ensure that every manufacturer of USB devices enters into +an agreement with them? They do it via trademark licensing. Usb.org has +registered the trademark "USB", all associated logos and related terms. If +you want to put an USB logo on your product or claim that it is USB +compliant, you must license these trademarks from usb.org. And this is where +you enter into an agreement. See the "USB-IF Trademark License Agreement and +Usage Guidelines for the USB-IF Logo" at +http://www.usb.org/developers/logo_license/. + +Licensing the USB trademarks requires that you buy a USB Vendor-ID from +usb.org (one-time fee of ca. 2,000 USD), that you become a member of usb.org +(yearly fee of ca. 4,000 USD) and that you meet all the technical +specifications from the USB spec. + +This means that most hobbyists and small companies will never be able to +become USB compliant, just because membership is so expensive. And you can't +be compliant with a driver based on V-USB anyway, because the AVR's port pins +don't meet the electrical specifications for USB. So, in principle, all +hobbyists and small companies are free to choose any random numbers for their +IDs. They have nothing to lose... + +There is one exception worth noting, though: If you use a sub-component which +implements USB, the vendor of the sub-components may guarantee USB +compliance. This might apply to some or all of FTDI's solutions. + + +======================================================================= +WHY SHOULD YOU OBTAIN USB IDs EVEN IF YOU DON'T LICENSE USB TRADEMARKS? +======================================================================= + +You have learned in the previous section that you are free to choose any +numbers for your IDs anyway. So why not do exactly this? There is still the +technical issue. If you choose IDs which are already in use by somebody else, +operating systems will load the wrong drivers and your device won't work. +Even if you choose IDs which are not currently in use, they may be in use in +the next version of the operating system or even after an automatic update. + +So what you need is a pair of Vendor- and Product-IDs for which you have the +guarantee that no USB compliant product uses them. This implies that no +operating system will ever ship with drivers responsible for these IDs. + + +============================================== +HOW DOES OBJECTIVE DEVELOPMENT HANDLE USB IDs? +============================================== + +Objective Development gives away pairs of USB-IDs with their V-USB licenses. +In order to ensure that these IDs are unique, Objective Development has an +agreement with the company/person who has bought the USB Vendor-ID from +usb.org. This agreement ensures that a range of USB Product-IDs is reserved +for assignment by Objective Development and that the owner of the Vendor-ID +won't give it to anybody else. + +This means that you have to trust three parties to ensure uniqueness of +your IDs: + + - Objective Development, that they don't give the same PID to more than + one person. + - The owner of the Vendor-ID that they don't assign PIDs from the range + assigned to Objective Development to anybody else. + - Usb.org that they don't assign the same Vendor-ID a second time. + + +================================== +WHO IS THE OWNER OF THE VENDOR-ID? +================================== + +Objective Development has obtained ranges of USB Product-IDs under two +Vendor-IDs: Under Vendor-ID 5824 from Wouter van Ooijen (Van Ooijen +Technische Informatica, www.voti.nl) and under Vendor-ID 8352 from Jason +Kotzin (Clay Logic, www.claylogic.com). Both VID owners have received their +Vendor-ID directly from usb.org. + + +========================================================================= +CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE? +========================================================================= + +The short answer is: Yes. All you get is a guarantee that the IDs are never +assigned to anybody else. What more do you need? + + +============================ +WHAT ABOUT SHARED ID PAIRS? +============================ + +Objective Development has reserved some PID/VID pairs for shared use. You +have no guarantee of uniqueness for them, except that no USB compliant device +uses them. In order to avoid technical problems, we must ensure that all +devices with the same pair of IDs use the same driver on kernel level. For +details, see the file USB-IDs-for-free.txt. + + +====================================================== +I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL? +====================================================== + +A 16 bit integer number cannot be protected by copyright laws. It is not +sufficiently complex. And since none of the parties involved entered into the +USB-IF Trademark License Agreement, we are not bound by this agreement. So +there is no reason why it should be illegal to sub-license USB-IDs. + + +============================================= +WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES? +============================================= + +Objective Development disclaims all liabilities which might arise from the +assignment of IDs. If you guarantee product features to your customers +without proper disclaimer, YOU are liable for that. diff --git a/adb2usb/uart2usb/vusb-20100715/USB-IDs-for-free.txt b/adb2usb/uart2usb/vusb-20100715/USB-IDs-for-free.txt new file mode 100644 index 0000000..2f4d59a --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/USB-IDs-for-free.txt @@ -0,0 +1,148 @@ +Version 2009-08-22 + +=========================== +FREE USB-IDs FOR SHARED USE +=========================== + +Objective Development has reserved a set of USB Product-IDs for use according +to the guidelines outlined below. For more information about the concept of +USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees +that the IDs listed below are not used by any USB compliant devices. + + +==================== +MECHANISM OF SHARING +==================== + +From a technical point of view, two different devices can share the same USB +Vendor- and Product-ID if they require the same driver on operating system +level. We make use of this fact by assigning separate IDs for various device +classes. On application layer, devices must be distinguished by their textual +name or serial number. We offer separate sets of IDs for discrimination by +textual name and for serial number. + +Examples for shared use of USB IDs are included with V-USB in the "examples" +subdirectory. + + +====================================== +IDs FOR DISCRIMINATION BY TEXTUAL NAME +====================================== + +If you use one of the IDs listed below, your device and host-side software +must conform to these rules: + +(1) The USB device MUST provide a textual representation of the manufacturer +and product identification. The manufacturer identification MUST be available +at least in USB language 0x0409 (English/US). + +(2) The textual manufacturer identification MUST contain either an Internet +domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail +address under your control (e.g. "myname@gmx.net"). You can embed the domain +name or e-mail address in any string you like, e.g. "Objective Development +http://www.obdev.at/vusb/". + +(3) You are responsible for retaining ownership of the domain or e-mail +address for as long as any of your products are in use. + +(4) You may choose any string for the textual product identification, as long +as this string is unique within the scope of your textual manufacturer +identification. + +(5) Application side device look-up MUST be based on the textual manufacturer +and product identification in addition to VID/PID matching. The driver +matching MUST be a comparison of the entire strings, NOT a sub-string match. + +(6) For devices which implement a particular USB device class (e.g. HID), the +operating system's default class driver MUST be used. If an operating system +driver for Vendor Class devices is needed, this driver must be libusb or +libusb-win32 (see http://libusb.org/ and +http://libusb-win32.sourceforge.net/). + +Table if IDs for discrimination by textual name: + +PID dec (hex) | VID dec (hex) | Description of use +==============+===============+============================================ +1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb +--------------+---------------+-------------------------------------------- +1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are + | | NOT mice, keyboards or joysticks) +--------------+---------------+-------------------------------------------- +1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems) +--------------+---------------+-------------------------------------------- +1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices +--------------+---------------+-------------------------------------------- + +Note that Windows caches the textual product- and vendor-description for +mice, keyboards and joysticks. Name-bsed discrimination is therefore not +recommended for these device classes. + + +======================================= +IDs FOR DISCRIMINATION BY SERIAL NUMBER +======================================= + +If you use one of the IDs listed below, your device and host-side software +must conform to these rules: + +(1) The USB device MUST provide a textual representation of the serial +number. The serial number string MUST be available at least in USB language +0x0409 (English/US). + +(2) The serial number MUST start with either an Internet domain name (e.g. +"mycompany.com") registered and owned by you, or an e-mail address under your +control (e.g. "myname@gmx.net"), both terminated with a colon (":") character. +You MAY append any string you like for further discrimination of your devices. + +(3) You are responsible for retaining ownership of the domain or e-mail +address for as long as any of your products are in use. + +(5) Application side device look-up MUST be based on the serial number string +in addition to VID/PID matching. The matching must start at the first +character of the serial number string and include the colon character +terminating your domain or e-mail address. It MAY stop anywhere after that. + +(6) For devices which implement a particular USB device class (e.g. HID), the +operating system's default class driver MUST be used. If an operating system +driver for Vendor Class devices is needed, this driver must be libusb or +libusb-win32 (see http://libusb.org/ and +http://libusb-win32.sourceforge.net/). + +Table if IDs for discrimination by serial number string: + +PID dec (hex) | VID dec (hex) | Description of use +===============+===============+=========================================== +10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb +---------------+---------------+------------------------------------------- +10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are + | | NOT mice, keyboards or joysticks) +---------------+---------------+------------------------------------------- +10202 (0x27da) | 5824 (0x16c0) | For USB Mice +---------------+---------------+------------------------------------------- +10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards +---------------+---------------+------------------------------------------- +10204 (0x27db) | 5824 (0x16c0) | For USB Joysticks +---------------+---------------+------------------------------------------- +10205 (0x27dc) | 5824 (0x16c0) | For CDC-ACM class devices (modems) +---------------+---------------+------------------------------------------- +10206 (0x27dd) | 5824 (0x16c0) | For MIDI class devices +---------------+---------------+------------------------------------------- + + +================= +ORIGIN OF USB-IDs +================= + +OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed +here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition. +Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc. +(see www.usb.org). The VID is registered for the company name "Van Ooijen +Technische Informatica". + + +========== +DISCLAIMER +========== + +OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any +problems which are caused by the shared use of these VID/PID pairs. diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/Readme.txt b/adb2usb/uart2usb/vusb-20100715/circuits/Readme.txt new file mode 100644 index 0000000..1aa5218 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/circuits/Readme.txt @@ -0,0 +1,79 @@ +This is the Readme file for the V-USB example circuits directory. + + +CIRCUITS IN THIS DIRECTORY +========================== +Since USB requires 3.3 V levels on D+ and D- but delivers a power supply of +ca. 5 V, some kind of level conversion must be performed. There are several +ways to implement this level conversion, see the example circuits below. + +with-vreg.png and with-vreg.sch (EAGLE schematics): + This circuit uses a low drop voltage regulator to reduce the USB supply to + 3.3 V. You MUST use a low drop regulator because standard regulators such + as the LM317 require at least ca. 2 V drop. The advantage of this approach + is that it comes closest to the voltage levels required by the USB + specification and that the circuit is powered from a regulated supply. If + no USB cable is used (connector directly soldered on PCB), you can even + omit the 68 Ohm series resistors. The disadvantage is that you may want to + use other chips in your design which require 5 V. Please check that the AVR + used in your design allows the chosen clock rate at 3.3 V. + +with-zener.png and with-zener.sch (EAGLE schematics): + This circuit enforces lower voltage levels on D+ and D- with zener diodes. + The zener diodes MUST be low power / low current types to ensure that the + 1k5 pull-up resistor on D- generates a voltage of well above 2.5 V (but + below 3.6 V). The advantage of this circuit is its simplicity and that the + circuit can be powered at 5 V (usually precise enough if the cable drop is + neglected). The disadvantage is that some zener diodes have a lower voltage + than 3 V when powered through 1k5 and the choice of components becomes + relevant. In addition to that, the power consumption during USB data + transfer is increased because the current is only limited by the 68 Ohm + series resistor. The zeners may even distort the signal waveforms due to + their capacity. + +with-series-diodes.png and with-series-diodes.sch (EAGLE schematics): + This is a simplified low-cost version of the voltage regulator approach. + Instead of using a voltage regulator, we reduce the voltage by the forward + voltage of two silicon diodes (roughly 1.4 V). This gives ca. 3.6 V which + is practically inside the allowed range. The big disadvantage is that the + supply is not regulated -- it even depends strongly on the power + consumption. This cannot be tolerated for analog circuits. + +tiny45-rc.png and tiny45-rc.sch (EAGLE schematics): + This is mostly an example for connecting an 8 pin device using the internal + RC oscillator for system clock. This example uses series diodes to limit + the supply, but you may choose any other method. Please note that you must + choose a clock rate of 12.8 or 16.5 MHz because only the receiver modules + for these frequencies have a PLL to allow higher clock rate tolerances. + + +GENERAL DESIGN NOTES +==================== +All examples have D+ on hardware interrupt INT0 because this is the highest +priority interrupt on AVRs. You may use other hardware interrupts (and +configure the options at the end of usbconfig.h accordingly) if you make sure +that no higher priority interrupt is used. + +If you use USB_SOF_HOOK or USB_COUNT_SOF in usbconfig.h, you must wire D- to +the interrupt instead. This way the interrupt is triggered on USB Start Of +Frame pulses as well. + +Most examples have a 1M pull-down resistor at D+. This pull-up ensures that +in self-powered designs no interrupts occur while USB is not connected. You +may omit this resistor in bus-powered designs. Older examples had a pull-up +resistor instead. This is not compatible with the zener diode approach to +level conversion: 1M pull-up in conjunction with a 3.6 V zener diode give an +invalid logic level. + +All examples with ATMega8/88/168 have D+ at port D bit 2 (because this is +hardware interrupt 0) and D- on port D bit 4 because it is also a clock input +for timer/counter 0. This way the firmware can easily check for activity on +D- (USB frame pulses) by checking the counter value in regular intervals. If +no activity is found, the firmware should (according to the USB +specification) put the system into a low power suspend mode. + + + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/tiny45-rc.png b/adb2usb/uart2usb/vusb-20100715/circuits/tiny45-rc.png new file mode 100644 index 0000000..ac97657 Binary files /dev/null and b/adb2usb/uart2usb/vusb-20100715/circuits/tiny45-rc.png differ diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/tiny45-rc.sch b/adb2usb/uart2usb/vusb-20100715/circuits/tiny45-rc.sch new file mode 100644 index 0000000..349f1ad Binary files /dev/null and b/adb2usb/uart2usb/vusb-20100715/circuits/tiny45-rc.sch differ diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/with-series-diodes.png b/adb2usb/uart2usb/vusb-20100715/circuits/with-series-diodes.png new file mode 100644 index 0000000..1cc8d63 Binary files /dev/null and b/adb2usb/uart2usb/vusb-20100715/circuits/with-series-diodes.png differ diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/with-series-diodes.sch b/adb2usb/uart2usb/vusb-20100715/circuits/with-series-diodes.sch new file mode 100644 index 0000000..d84d99e Binary files /dev/null and b/adb2usb/uart2usb/vusb-20100715/circuits/with-series-diodes.sch differ diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/with-vreg.png b/adb2usb/uart2usb/vusb-20100715/circuits/with-vreg.png new file mode 100644 index 0000000..eca7932 Binary files /dev/null and b/adb2usb/uart2usb/vusb-20100715/circuits/with-vreg.png differ diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/with-vreg.sch b/adb2usb/uart2usb/vusb-20100715/circuits/with-vreg.sch new file mode 100644 index 0000000..1f1797b Binary files /dev/null and b/adb2usb/uart2usb/vusb-20100715/circuits/with-vreg.sch differ diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/with-zener.png b/adb2usb/uart2usb/vusb-20100715/circuits/with-zener.png new file mode 100644 index 0000000..598441f Binary files /dev/null and b/adb2usb/uart2usb/vusb-20100715/circuits/with-zener.png differ diff --git a/adb2usb/uart2usb/vusb-20100715/circuits/with-zener.sch b/adb2usb/uart2usb/vusb-20100715/circuits/with-zener.sch new file mode 100644 index 0000000..624177a Binary files /dev/null and b/adb2usb/uart2usb/vusb-20100715/circuits/with-zener.sch differ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/Readme.txt b/adb2usb/uart2usb/vusb-20100715/examples/Readme.txt new file mode 100644 index 0000000..82b10fe --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/Readme.txt @@ -0,0 +1,102 @@ +This is the Readme file for the directory "examples" of V-USB, a firmware- +only USB driver for AVR microcontrollers. + +WHAT IS IN THIS DIRECTORY? +========================== +This directory contains examples which are mostly for educational purposes. +Examples can be device firmware only, host software only or both. Here is +a summary: + +custom-class + A custom class device with host software based on libusb. It demonstrates + the straight forward way of sending small amounts of data to a device and + receiving data from the device. It does NOT demonstrate how to send large + amounts of data to the device or how to receive data generated on the fly + by the device (how to use usbFunctionWrite() and usbFunctionRead()). See + the hid-data example for how usbFunctionWrite() and usbFunctionRead() are + used. + +hid-custom-rq + This example implements the same functionality as the custom-class example + above, but declares the device as HID. This prevents the "give me a driver + CD" dialog on Windows. The device can still be controlled with libusb as in + the previous example (on Windows, the filter version of libusb-win32 must + be installed). In addition to the features presented in custom-class, this + example demonstrates how a HID class device is defined. + +hid-mouse + This example implements a mouse device. No host driver is required since + today's operating systems have drivers for USB mice built-in. It + demonstrates how a real-world HID class device is implemented and how + interrupt-in endpoints are used. + +hid-data + This example demonstrates how the HID class can be misused to transfer + arbitrary data over HID feature reports. This technique is of great value + on Windows because no driver DLLs are needed (the hid-custom-rq example + still requires the libusb-win32 DLL, although it may be in the program's + directory). The host side application requires no installation, it can + even be started directly from a CD. This example also demonstrates how + to transfer data using usbFunctionWrite() and usbFunctionRead(). + +usbtool + This is a general purpose development and debugging tool for USB devices. + You can use it during development of your device to test various requests + without special test programs. But it is also an example how all the + libusb API functions are used. + +More information about each example can be found in the Readme file in the +respective directory. + +Hardware dependencies of AVR code has been kept at a minimum. All examples +should work on any AVR chip which has enough resources to run the driver. +Makefile and usbconfig.h have been configured for the metaboard hardware (see +http://www.obdev.at/goto.php?t=metaboard for details). Edit the target +device, fuse values, clock rate and programmer in Makefile and the I/O pins +dedicated to USB in usbconfig.h. + + +WHAT IS NOT DEMONSTRATED IN THESE EXAMPLES? +=========================================== +These examples show only the most basic functionality. More elaborate +examples and real world applications showing more features of the driver are +available at http://www.obdev.at/vusb/projects.html. Most of these +features are described in our documentation wiki at +http://www.obdev.at/goto.php?t=vusb-wiki. + +To mention just a few: + +Using RC oscillator for system clock + The 12.8 MHz and 16.5 MHz modules of V-USB have been designed to cope + with clock rate deviations up to 1%. This allows an RC oscillator to be + used. Since the AVR's RC oscillator has a factory precision of only 10%, + it must be calibrated to an external reference. The EasyLogger example + shows how this can be done. + +Dynamically generated descriptors + Sometimes you want to implement different typtes of USB device depending + on a jumper or other condition. V-USB has a very flexible interface for + providing USB descriptors. See AVR-Doper for how to provide descriptors + at runtime. + +Virtual COM port + Some people prefer a virtual serial interface to communicate with their + device. We strongly discourage this method because it does things + forbidden by the USB specification. If you still want to go this route, + see AVR-CDC. + +Implementing suspend mode + V-USB does not implement suspend mode. This means that the device does + not reduce power consumption when the host goes into sleep mode. Device + firmware is free to implement suspend mode, though. See USB2LPT for an + example. + +The projects mentioned above can best be found on + + http://www.obdev.at/vusb/prjall.html + +where all projects are listed. + +---------------------------------------------------------------------------- +(c) 2009 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/Readme.txt b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/Readme.txt new file mode 100644 index 0000000..815518e --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/Readme.txt @@ -0,0 +1,64 @@ +This is the Readme file for the custom-class example. In this example, we +show how an LED can be controlled via USB. + + +WHAT IS DEMONSTRATED? +===================== +This example shows how small amounts of data (several bytes) can be +transferred between the device and the host. In addition to a very basic +USB device, it demonstrates how to build a host side driver application +using libusb or libusb-win32. It does NOT show how usbFunctionWrite() and +usbFunctionRead() are used. See the hid-data example if you want to learn +about these functions. + + +PREREQUISITES +============= +Target hardware: You need an AVR based circuit based on one of the examples +(see the "circuits" directory at the top level of this package), e.g. the +metaboard (http://www.obdev.at/goto.php?t=metaboard). + +AVR development environment: You need the gcc tool chain for the AVR, see +the Prerequisites section in the top level Readme file for how to obtain it. + +Host development environment: A C compiler and libusb. See the top level +Readme file, section Prerequisites for more information. + + +BUILDING THE FIRMWARE +===================== +Change to the "firmware" directory and modify Makefile according to your +architecture (CPU clock, target device, fuse values) and ISP programmer. Then +edit usbconfig.h according to your pin assignments for D+ and D-. The default +settings are for the metaboard hardware. You should have wired an LED with a +current limiting resistor of ca. 270 Ohm to a free I/O pin. Change the +defines in main.c to match the port and bit number. + +Type "make hex" to build main.hex, then "make flash" to upload the firmware +to the device. Don't forget to run "make fuse" once to program the fuses. If +you use a prototyping board with boot loader, follow the instructions of the +boot loader instead. + +Please note that the first "make hex" copies the driver from the top level +into the firmware directory. If you use a different build system than our +Makefile, you must copy the driver by hand. + + +BUILDING THE HOST SOFTWARE +========================== +Since the host software is based on libusb or libusb-win32, make sure that +this library is installed. On Unix, ensure that libusb-config is in your +search PATH. On Windows, edit Makefile.windows and set the library path +appropriately. Then type "make" on Unix or "make -f Makefile.windows" on +Windows to build the command line tool. + + +USING THE COMMAND LINE TOOL +=========================== +The command line tool has three valid arguments: "status" to query the +current LED status, "on" to turn on the LED and "off" to turn it off. + + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/Makefile b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/Makefile new file mode 100644 index 0000000..aaa948a --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/Makefile @@ -0,0 +1,48 @@ +# Name: Makefile +# Project: custom-class example +# Author: Christian Starkjohann +# Creation Date: 2008-04-06 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + + +# Concigure the following definitions according to your system. +# This Makefile has been tested on Mac OS X, Linux and Windows. + +# Use the following 3 lines on Unix (uncomment the framework on Mac OS X): +USBFLAGS = `libusb-config --cflags` +USBLIBS = `libusb-config --libs` +EXE_SUFFIX = + +# Use the following 3 lines on Windows and comment out the 3 above. You may +# have to change the include paths to where you installed libusb-win32 +#USBFLAGS = -I/usr/local/include +#USBLIBS = -L/usr/local/lib -lusb +#EXE_SUFFIX = .exe + +NAME = set-led + +OBJECTS = opendevice.o $(NAME).o + +CC = gcc +CFLAGS = $(CPPFLAGS) $(USBFLAGS) -O -g -Wall +LIBS = $(USBLIBS) + +PROGRAM = $(NAME)$(EXE_SUFFIX) + + +all: $(PROGRAM) + +.c.o: + $(CC) $(CFLAGS) -c $< + +$(PROGRAM): $(OBJECTS) + $(CC) -o $(PROGRAM) $(OBJECTS) $(LIBS) + +strip: $(PROGRAM) + strip $(PROGRAM) + +clean: + rm -f *.o $(PROGRAM) diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/Makefile.windows b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/Makefile.windows new file mode 100644 index 0000000..a8239ad --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/Makefile.windows @@ -0,0 +1,18 @@ +# Name: Makefile.windows +# Project: custom-class example +# Author: Christian Starkjohann +# Creation Date: 2008-04-06 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id$ + +# You may use this file with +# make -f Makefile.windows +# on Windows with MinGW instead of editing the main Makefile. + +include Makefile + +USBFLAGS = -I/usr/local/mingw/include +USBLIBS = -L/usr/local/mingw/lib -lusb +EXE_SUFFIX = .exe diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/opendevice.c b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/opendevice.c new file mode 100644 index 0000000..137f50c --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/opendevice.c @@ -0,0 +1,203 @@ +/* Name: opendevice.c + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.c 740 2009-04-13 18:23:31Z cs $ + */ + +/* +General Description: +The functions in this module can be used to find and open a device based on +libusb or libusb-win32. +*/ + +#include +#include "opendevice.h" + +/* ------------------------------------------------------------------------- */ + +#define MATCH_SUCCESS 1 +#define MATCH_FAILED 0 +#define MATCH_ABORT -1 + +/* private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or MATCH_ABORT. */ +static int _shellStyleMatch(char *text, char *p) +{ +int last, matched, reverse; + + for(; *p; text++, p++){ + if(*text == 0 && *p != '*') + return MATCH_ABORT; + switch(*p){ + case '\\': + /* Literal match with following character. */ + p++; + /* FALLTHROUGH */ + default: + if(*text != *p) + return MATCH_FAILED; + continue; + case '?': + /* Match anything. */ + continue; + case '*': + while(*++p == '*') + /* Consecutive stars act just like one. */ + continue; + if(*p == 0) + /* Trailing star matches everything. */ + return MATCH_SUCCESS; + while(*text) + if((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED) + return matched; + return MATCH_ABORT; + case '[': + reverse = p[1] == '^'; + if(reverse) /* Inverted character class. */ + p++; + matched = MATCH_FAILED; + if(p[1] == ']' || p[1] == '-') + if(*++p == *text) + matched = MATCH_SUCCESS; + for(last = *p; *++p && *p != ']'; last = *p) + if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p) + matched = MATCH_SUCCESS; + if(matched == reverse) + return MATCH_FAILED; + continue; + } + } + return *text == 0; +} + +/* public interface for shell style matching: returns 0 if fails, 1 if matches */ +static int shellStyleMatch(char *text, char *pattern) +{ + if(pattern == NULL) /* NULL pattern is synonymous to "*" */ + return 1; + return _shellStyleMatch(text, pattern) == MATCH_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) +{ +char buffer[256]; +int rval, i; + + if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ + return rval; + if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) + return rval; + if(buffer[1] != USB_DT_STRING){ + *buf = 0; + return 0; + } + if((unsigned char)buffer[0] < rval) + rval = (unsigned char)buffer[0]; + rval /= 2; + /* lossy conversion to ISO Latin1: */ + for(i=1;i buflen) /* destination buffer overflow */ + break; + buf[i-1] = buffer[2 * i]; + if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ + buf[i-1] = '?'; + } + buf[i-1] = 0; + return i-1; +} + +/* ------------------------------------------------------------------------- */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp) +{ +struct usb_bus *bus; +struct usb_device *dev; +usb_dev_handle *handle = NULL; +int errorCode = USBOPEN_ERR_NOTFOUND; + + usb_find_busses(); + usb_find_devices(); + for(bus = usb_get_busses(); bus; bus = bus->next){ + for(dev = bus->devices; dev; dev = dev->next){ /* iterate over all devices on all busses */ + if((vendorID == 0 || dev->descriptor.idVendor == vendorID) + && (productID == 0 || dev->descriptor.idProduct == productID)){ + char vendor[256], product[256], serial[256]; + int len; + handle = usb_open(dev); /* we need to open the device in order to query strings */ + if(!handle){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot open VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + continue; + } + /* now check whether the names match: */ + len = vendor[0] = 0; + if(dev->descriptor.iManufacturer > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, vendor, sizeof(vendor)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen device from vendor ->%s<-\n", vendor); */ + if(shellStyleMatch(vendor, vendorNamePattern)){ + len = product[0] = 0; + if(dev->descriptor.iProduct > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iProduct, product, sizeof(product)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen product ->%s<-\n", product); */ + if(shellStyleMatch(product, productNamePattern)){ + len = serial[0] = 0; + if(dev->descriptor.iSerialNumber > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, serial, sizeof(serial)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + } + if(shellStyleMatch(serial, serialNamePattern)){ + if(printMatchingDevicesFp != NULL){ + if(serial[0] == 0){ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product); + }else{ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product, serial); + } + }else{ + break; + } + } + } + } + } + } + usb_close(handle); + handle = NULL; + } + } + if(handle) /* we have found a deice */ + break; + } + if(handle != NULL){ + errorCode = 0; + *device = handle; + } + if(printMatchingDevicesFp != NULL) /* never return an error for listing only */ + errorCode = 0; + return errorCode; +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/opendevice.h b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/opendevice.h new file mode 100644 index 0000000..79c12f6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/opendevice.h @@ -0,0 +1,77 @@ +/* Name: opendevice.h + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.h 755 2009-08-03 17:01:21Z cs $ + */ + +/* +General Description: +This module offers additional functionality for host side drivers based on +libusb or libusb-win32. It includes a function to find and open a device +based on numeric IDs and textual description. It also includes a function to +obtain textual descriptions from a device. + +To use this functionality, simply copy opendevice.c and opendevice.h into your +project and add them to your Makefile. You may modify and redistribute these +files according to the GNU General Public License (GPL) version 2 or 3. +*/ + +#ifndef __OPENDEVICE_H_INCLUDED__ +#define __OPENDEVICE_H_INCLUDED__ + +#include /* this is libusb, see http://libusb.sourceforge.net/ */ +#include + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen); +/* This function gets a string descriptor from the device. 'index' is the + * string descriptor index. The string is returned in ISO Latin 1 encoding in + * 'buf' and it is terminated with a 0-character. The buffer size must be + * passed in 'buflen' to prevent buffer overflows. A libusb device handle + * must be given in 'dev'. + * Returns: The length of the string (excluding the terminating 0) or + * a negative number in case of an error. If there was an error, use + * usb_strerror() to obtain the error message. + */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp); +/* This function iterates over all devices on all USB busses and searches for + * a device. Matching is done first by means of Vendor- and Product-ID (passed + * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard). + * When a device matches by its IDs, matching by names is performed. Name + * matching can be done on textual vendor name ('vendorNamePattern'), product + * name ('productNamePattern') and serial number ('serialNamePattern'). A + * device matches only if all non-null pattern match. If you don't care about + * a string, pass NULL for the pattern. Patterns are Unix shell style pattern: + * '*' stands for 0 or more characters, '?' for one single character, a list + * of characters in square brackets for a single character from the list + * (dashes are allowed to specify a range) and if the lis of characters begins + * with a caret ('^'), it matches one character which is NOT in the list. + * Other parameters to the function: If 'warningsFp' is not NULL, warning + * messages are printed to this file descriptor with fprintf(). If + * 'printMatchingDevicesFp' is not NULL, no device is opened but matching + * devices are printed to the given file descriptor with fprintf(). + * If a device is opened, the resulting USB handle is stored in '*device'. A + * pointer to a "usb_dev_handle *" type variable must be passed here. + * Returns: 0 on success, an error code (see defines below) on failure. + */ + +/* usbOpenDevice() error codes: */ +#define USBOPEN_SUCCESS 0 /* no error */ +#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ +#define USBOPEN_ERR_IO 2 /* I/O error */ +#define USBOPEN_ERR_NOTFOUND 3 /* device not found */ + + +/* Obdev's free USB IDs, see USB-IDs-for-free.txt for details */ + +#define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */ +#define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */ +#define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */ +#define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */ +#define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */ + +#endif /* __OPENDEVICE_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/set-led.c b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/set-led.c new file mode 100644 index 0000000..3f167dc --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/commandline/set-led.c @@ -0,0 +1,135 @@ +/* Name: set-led.c + * Project: custom-class, a basic USB example + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: set-led.c 692 2008-11-07 15:07:40Z cs $ + */ + +/* +General Description: +This is the host-side driver for the custom-class example device. It searches +the USB for the LEDControl device and sends the requests understood by this +device. +This program must be linked with libusb on Unix and libusb-win32 on Windows. +See http://libusb.sourceforge.net/ or http://libusb-win32.sourceforge.net/ +respectively. +*/ + +#include +#include +#include +#include /* this is libusb */ +#include "opendevice.h" /* common code moved to separate module */ + +#include "../firmware/requests.h" /* custom request numbers */ +#include "../firmware/usbconfig.h" /* device's VID/PID and names */ + +static void usage(char *name) +{ + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s on ....... turn on LED\n", name); + fprintf(stderr, " %s off ...... turn off LED\n", name); + fprintf(stderr, " %s status ... ask current status of LED\n", name); +#if ENABLE_TEST + fprintf(stderr, " %s test ..... run driver reliability test\n", name); +#endif /* ENABLE_TEST */ +} + +int main(int argc, char **argv) +{ +usb_dev_handle *handle = NULL; +const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID}; +char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0}; +char buffer[4]; +int cnt, vid, pid, isOn; + + usb_init(); + if(argc < 2){ /* we need at least one argument */ + usage(argv[0]); + exit(1); + } + /* compute VID/PID from usbconfig.h so that there is a central source of information */ + vid = rawVid[1] * 256 + rawVid[0]; + pid = rawPid[1] * 256 + rawPid[0]; + /* The following function is in opendevice.c: */ + if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){ + fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid); + exit(1); + } + /* Since we use only control endpoint 0, we don't need to choose a + * configuration and interface. Reading device descriptor and setting a + * configuration and interface is done through endpoint 0 after all. + * However, newer versions of Linux require that we claim an interface + * even for endpoint 0. Enable the following code if your operating system + * needs it: */ +#if 0 + int retries = 1, usbConfiguration = 1, usbInterface = 0; + if(usb_set_configuration(handle, usbConfiguration) && showWarnings){ + fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror()); + } + /* now try to claim the interface and detach the kernel HID driver on + * Linux and other operating systems which support the call. */ + while((len = usb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){ +#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP + if(usb_detach_kernel_driver_np(handle, 0) < 0 && showWarnings){ + fprintf(stderr, "Warning: could not detach kernel driver: %s\n", usb_strerror()); + } +#endif + } +#endif + + if(strcasecmp(argv[1], "status") == 0){ + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_STATUS, 0, 0, buffer, sizeof(buffer), 5000); + if(cnt < 1){ + if(cnt < 0){ + fprintf(stderr, "USB error: %s\n", usb_strerror()); + }else{ + fprintf(stderr, "only %d bytes received.\n", cnt); + } + }else{ + printf("LED is %s\n", buffer[0] ? "on" : "off"); + } + }else if((isOn = (strcasecmp(argv[1], "on") == 0)) || strcasecmp(argv[1], "off") == 0){ + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, isOn, 0, buffer, 0, 5000); + if(cnt < 0){ + fprintf(stderr, "USB error: %s\n", usb_strerror()); + } +#if ENABLE_TEST + }else if(strcasecmp(argv[1], "test") == 0){ + int i; + srandomdev(); + for(i = 0; i < 50000; i++){ + int value = random() & 0xffff, index = random() & 0xffff; + int rxValue, rxIndex; + if((i+1) % 100 == 0){ + fprintf(stderr, "\r%05d", i+1); + fflush(stderr); + } + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_ECHO, value, index, buffer, sizeof(buffer), 5000); + if(cnt < 0){ + fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror()); + break; + }else if(cnt != 4){ + fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of 4\n", i, cnt); + break; + } + rxValue = ((int)buffer[0] & 0xff) | (((int)buffer[1] & 0xff) << 8); + rxIndex = ((int)buffer[2] & 0xff) | (((int)buffer[3] & 0xff) << 8); + if(rxValue != value || rxIndex != index){ + fprintf(stderr, "\ndata error in iteration %d:\n", i); + fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, value); + fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, index); + } + } + fprintf(stderr, "\nTest completed.\n"); +#endif /* ENABLE_TEST */ + }else{ + usage(argv[0]); + exit(1); + } + usb_close(handle); + return 0; +} diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/Makefile b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/Makefile new file mode 100644 index 0000000..e909fc6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/Makefile @@ -0,0 +1,164 @@ +# Name: Makefile +# Project: custom-class example +# Author: Christian Starkjohann +# Creation Date: 2008-04-07 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + +DEVICE = atmega168 +F_CPU = 16000000 # in Hz +FUSE_L = # see below for fuse values for particular devices +FUSE_H = +AVRDUDE = avrdude -c usbasp -p $(DEVICE) # edit this line for your programmer + +CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 +OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o + +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) + +############################################################################## +# Fuse values for particular devices +############################################################################## +# If your device is not listed here, go to +# http://palmavr.sourceforge.net/cgi-bin/fc.cgi +# and choose options for external crystal clock and no clock divider +# +################################## ATMega8 ################################## +# ATMega8 FUSE_L (Fuse low byte): +# 0x9f = 1 0 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ BODEN (BrownOut Detector enabled) +# +-------------------- BODLEVEL (2.7V) +# ATMega8 FUSE_H (Fuse high byte): +# 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) +# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 +# | | | | | +-------- BOOTSZ1 +# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) +# | | | +-------------- CKOPT (full output swing) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ WDTON (WDT not always on) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATMega48/88/168 ############################## +# ATMega*8 FUSE_L (Fuse low byte): +# 0xdf = 1 1 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ CKOUT (if 0: Clock output enabled) +# +-------------------- CKDIV8 (if 0: divide by 8) +# ATMega*8 FUSE_H (Fuse high byte): +# 0xde = 1 1 0 1 1 1 1 0 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V) +# | | | | + --------- EESAVE (preserve EEPROM over chip erase) +# | | | +-------------- WDTON (if 0: watchdog always on) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATTiny25/45/85 ############################### +# ATMega*5 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATMega*5 FUSE_H (Fuse high byte): +# 0xdd = 1 1 0 1 1 1 0 1 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (disable external reset -> enabled) +# +################################ ATTiny2313 ################################# +# ATTiny2313 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATTiny2313 FUSE_H (Fuse high byte): +# 0xdb = 1 1 0 1 1 0 1 1 +# ^ ^ ^ ^ \-+-/ ^ +# | | | | | +---- RSTDISBL (disable external reset -> enabled) +# | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# +-------------------- DWEN (debug wire enable) + + +# symbolic targets: +help: + @echo "This Makefile has no default rule. Use one of the following:" + @echo "make hex ....... to build main.hex" + @echo "make program ... to flash fuses and firmware" + @echo "make fuse ...... to flash the fuses" + @echo "make flash ..... to flash the firmware (use this on metaboard)" + @echo "make clean ..... to delete objects and hex file" + +hex: main.hex + +program: flash fuse + +# rule for programming fuse bits: +fuse: + @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \ + { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; } + $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m + +# rule for uploading firmware: +flash: main.hex + $(AVRDUDE) -U flash:w:main.hex:i + +# rule for deleting dependent files (those which can be built by Make): +clean: + rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s + +# Generic rule for compiling C files: +.c.o: + $(COMPILE) -c $< -o $@ + +# Generic rule for assembling Assembler source files: +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +# Generic rule for compiling C to assembler, used for debugging only. +.c.s: + $(COMPILE) -S $< -o $@ + +# file targets: + +# Since we don't want to ship the driver multipe times, we copy it into this project: +usbdrv: + cp -r ../../../usbdrv . + +main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it + $(COMPILE) -o main.elf $(OBJECTS) + +main.hex: main.elf + rm -f main.hex main.eep.hex + avr-objcopy -j .text -j .data -O ihex main.elf main.hex + avr-size main.hex + +# debugging targets: + +disasm: main.elf + avr-objdump -d main.elf + +cpp: + $(COMPILE) -E main.c diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/main.c b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/main.c new file mode 100644 index 0000000..231b1ce --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/main.c @@ -0,0 +1,97 @@ +/* Name: main.c + * Project: custom-class, a basic USB example + * Author: Christian Starkjohann + * Creation Date: 2008-04-09 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ + */ + +/* +This example should run on most AVRs with only little changes. No special +hardware resources except INT0 are used. You may have to change usbconfig.h for +different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or +at least be connected to INT0 as well. +We assume that an LED is connected to port B bit 0. If you connect it to a +different port or bit, change the macros below: +*/ +#define LED_PORT_DDR DDRB +#define LED_PORT_OUTPUT PORTB +#define LED_BIT 0 + +#include +#include +#include /* for sei() */ +#include /* for _delay_ms() */ + +#include /* required by usbdrv.h */ +#include "usbdrv.h" +#include "oddebug.h" /* This is also an example for using debug macros */ +#include "requests.h" /* The custom request numbers we use */ + +/* ------------------------------------------------------------------------- */ +/* ----------------------------- USB interface ----------------------------- */ +/* ------------------------------------------------------------------------- */ + +usbMsgLen_t usbFunctionSetup(uchar data[8]) +{ +usbRequest_t *rq = (void *)data; +static uchar dataBuffer[4]; /* buffer must stay valid when usbFunctionSetup returns */ + + if(rq->bRequest == CUSTOM_RQ_ECHO){ /* echo -- used for reliability tests */ + dataBuffer[0] = rq->wValue.bytes[0]; + dataBuffer[1] = rq->wValue.bytes[1]; + dataBuffer[2] = rq->wIndex.bytes[0]; + dataBuffer[3] = rq->wIndex.bytes[1]; + usbMsgPtr = dataBuffer; /* tell the driver which data to return */ + return 4; + }else if(rq->bRequest == CUSTOM_RQ_SET_STATUS){ + if(rq->wValue.bytes[0] & 1){ /* set LED */ + LED_PORT_OUTPUT |= _BV(LED_BIT); + }else{ /* clear LED */ + LED_PORT_OUTPUT &= ~_BV(LED_BIT); + } + }else if(rq->bRequest == CUSTOM_RQ_GET_STATUS){ + dataBuffer[0] = ((LED_PORT_OUTPUT & _BV(LED_BIT)) != 0); + usbMsgPtr = dataBuffer; /* tell the driver which data to return */ + return 1; /* tell the driver to send 1 byte */ + } + return 0; /* default for not implemented requests: return no data back to host */ +} + +/* ------------------------------------------------------------------------- */ + +int __attribute__((noreturn)) main(void) +{ +uchar i; + + wdt_enable(WDTO_1S); + /* Even if you don't use the watchdog, turn it off here. On newer devices, + * the status of the watchdog (on/off, period) is PRESERVED OVER RESET! + */ + /* RESET status: all port bits are inputs without pull-up. + * That's the way we need D+ and D-. Therefore we don't need any + * additional hardware initialization. + */ + odDebugInit(); + DBG1(0x00, 0, 0); /* debug output: main starts */ + usbInit(); + usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ + i = 0; + while(--i){ /* fake USB disconnect for > 250 ms */ + wdt_reset(); + _delay_ms(1); + } + usbDeviceConnect(); + LED_PORT_DDR |= _BV(LED_BIT); /* make the LED bit an output */ + sei(); + DBG1(0x01, 0, 0); /* debug output: main loop starts */ + for(;;){ /* main event loop */ + DBG1(0x02, 0, 0); /* debug output: main loop iterates */ + wdt_reset(); + usbPoll(); + } +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/requests.h b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/requests.h new file mode 100644 index 0000000..b4ecb14 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/requests.h @@ -0,0 +1,36 @@ +/* Name: requests.h + * Project: custom-class, a basic USB example + * Author: Christian Starkjohann + * Creation Date: 2008-04-09 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: requests.h 692 2008-11-07 15:07:40Z cs $ + */ + +/* This header is shared between the firmware and the host software. It + * defines the USB request numbers (and optionally data types) used to + * communicate between the host and the device. + */ + +#ifndef __REQUESTS_H_INCLUDED__ +#define __REQUESTS_H_INCLUDED__ + +#define CUSTOM_RQ_ECHO 0 +/* Request that the device sends back wValue and wIndex. This is used with + * random data to test the reliability of the communication. + */ +#define CUSTOM_RQ_SET_STATUS 1 +/* Set the LED status. Control-OUT. + * The requested status is passed in the "wValue" field of the control + * transfer. No OUT data is sent. Bit 0 of the low byte of wValue controls + * the LED. + */ + +#define CUSTOM_RQ_GET_STATUS 2 +/* Get the current LED status. Control-IN. + * This control transfer involves a 1 byte data phase where the device sends + * the current status to the host. The status is in bit 0 of the byte. + */ + +#endif /* __REQUESTS_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/usbconfig.h b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/usbconfig.h new file mode 100644 index 0000000..4b7ea54 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/custom-class/firmware/usbconfig.h @@ -0,0 +1,373 @@ +/* Name: usbconfig.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2005-04-01 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ + */ + +#ifndef __usbconfig_h_included__ +#define __usbconfig_h_included__ + +/* +General Description: +This file is an example configuration (with inline documentation) for the USB +driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is +also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may +wire the lines to any other port, as long as D+ is also wired to INT0 (or any +other hardware interrupt, as long as it is the highest level interrupt, see +section at the end of this file). +*/ + +/* ---------------------------- Hardware Config ---------------------------- */ + +#define USB_CFG_IOPORTNAME D +/* This is the port where the USB bus is connected. When you configure it to + * "B", the registers PORTB, PINB and DDRB will be used. + */ +#define USB_CFG_DMINUS_BIT 4 +/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. + * This may be any bit in the port. + */ +#define USB_CFG_DPLUS_BIT 2 +/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. + * This may be any bit in the port. Please note that D+ must also be connected + * to interrupt pin INT0! [You can also use other interrupts, see section + * "Optional MCU Description" below, or you can connect D- to the interrupt, as + * it is required if you use the USB_COUNT_SOF feature. If you use D- for the + * interrupt, the USB interrupt will also be triggered at Start-Of-Frame + * markers every millisecond.] + */ +#define USB_CFG_CLOCK_KHZ (F_CPU/1000) +/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, + * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code + * require no crystal, they tolerate +/- 1% deviation from the nominal + * frequency. All other rates require a precision of 2000 ppm and thus a + * crystal! + * Since F_CPU should be defined to your actual clock rate anyway, you should + * not need to modify this setting. + */ +#define USB_CFG_CHECK_CRC 0 +/* Define this to 1 if you want that the driver checks integrity of incoming + * data packets (CRC checks). CRC checks cost quite a bit of code size and are + * currently only available for 18 MHz crystal clock. You must choose + * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. + */ + +/* ----------------------- Optional Hardware Config ------------------------ */ + +/* #define USB_CFG_PULLUP_IOPORTNAME D */ +/* If you connect the 1.5k pullup resistor from D- to a port pin instead of + * V+, you can connect and disconnect the device from firmware by calling + * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). + * This constant defines the port on which the pullup resistor is connected. + */ +/* #define USB_CFG_PULLUP_BIT 4 */ +/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined + * above) where the 1.5k pullup resistor is connected. See description + * above for details. + */ + +/* --------------------------- Functional Range ---------------------------- */ + +#define USB_CFG_HAVE_INTRIN_ENDPOINT 0 +/* Define this to 1 if you want to compile a version with two endpoints: The + * default control endpoint 0 and an interrupt-in endpoint (any other endpoint + * number). + */ +#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 +/* Define this to 1 if you want to compile a version with three endpoints: The + * default control endpoint 0, an interrupt-in endpoint 3 (or the number + * configured below) and a catch-all default interrupt-in endpoint as above. + * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. + */ +#define USB_CFG_EP3_NUMBER 3 +/* If the so-called endpoint 3 is used, it can now be configured to any other + * endpoint number (except 0) with this macro. Default if undefined is 3. + */ +/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ +/* The above macro defines the startup condition for data toggling on the + * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. + * Since the token is toggled BEFORE sending any data, the first packet is + * sent with the oposite value of this configuration! + */ +#define USB_CFG_IMPLEMENT_HALT 0 +/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature + * for endpoint 1 (interrupt endpoint). Although you may not need this feature, + * it is required by the standard. We have made it a config option because it + * bloats the code considerably. + */ +#define USB_CFG_SUPPRESS_INTR_CODE 0 +/* Define this to 1 if you want to declare interrupt-in endpoints, but don't + * want to send any data over them. If this macro is defined to 1, functions + * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if + * you need the interrupt-in endpoints in order to comply to an interface + * (e.g. HID), but never want to send any data. This option saves a couple + * of bytes in flash memory and the transmit buffers in RAM. + */ +#define USB_CFG_INTR_POLL_INTERVAL 10 +/* If you compile a version with endpoint 1 (interrupt-in), this is the poll + * interval. The value is in milliseconds and must not be less than 10 ms for + * low speed devices. + */ +#define USB_CFG_IS_SELF_POWERED 0 +/* Define this to 1 if the device has its own power supply. Set it to 0 if the + * device is powered from the USB bus. + */ +#define USB_CFG_MAX_BUS_POWER 40 +/* Set this variable to the maximum USB bus power consumption of your device. + * The value is in milliamperes. [It will be divided by two since USB + * communicates power requirements in units of 2 mA.] + */ +#define USB_CFG_IMPLEMENT_FN_WRITE 0 +/* Set this to 1 if you want usbFunctionWrite() to be called for control-out + * transfers. Set it to 0 if you don't need it and want to save a couple of + * bytes. + */ +#define USB_CFG_IMPLEMENT_FN_READ 0 +/* Set this to 1 if you need to send control replies which are generated + * "on the fly" when usbFunctionRead() is called. If you only want to send + * data from a static buffer, set it to 0 and return the data from + * usbFunctionSetup(). This saves a couple of bytes. + */ +#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 +/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. + * You must implement the function usbFunctionWriteOut() which receives all + * interrupt/bulk data sent to any endpoint other than 0. The endpoint number + * can be found in 'usbRxToken'. + */ +#define USB_CFG_HAVE_FLOWCONTROL 0 +/* Define this to 1 if you want flowcontrol over USB data. See the definition + * of the macros usbDisableAllRequests() and usbEnableAllRequests() in + * usbdrv.h. + */ +#define USB_CFG_DRIVER_FLASH_PAGE 0 +/* If the device has more than 64 kBytes of flash, define this to the 64 k page + * where the driver's constants (descriptors) are located. Or in other words: + * Define this to 1 for boot loaders on the ATMega128. + */ +#define USB_CFG_LONG_TRANSFERS 0 +/* Define this to 1 if you want to send/receive blocks of more than 254 bytes + * in a single control-in or control-out transfer. Note that the capability + * for long transfers increases the driver size. + */ +/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ +/* This macro is a hook if you want to do unconventional things. If it is + * defined, it's inserted at the beginning of received message processing. + * If you eat the received message and don't want default processing to + * proceed, do a return after doing your things. One possible application + * (besides debugging) is to flash a status LED on each packet. + */ +/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ +/* This macro is a hook if you need to know when an USB RESET occurs. It has + * one parameter which distinguishes between the start of RESET state and its + * end. + */ +/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ +/* This macro (if defined) is executed when a USB SET_ADDRESS request was + * received. + */ +#define USB_COUNT_SOF 0 +/* define this macro to 1 if you need the global variable "usbSofCount" which + * counts SOF packets. This feature requires that the hardware interrupt is + * connected to D- instead of D+. + */ +/* #ifdef __ASSEMBLER__ + * macro myAssemblerMacro + * in YL, TCNT0 + * sts timer0Snapshot, YL + * endm + * #endif + * #define USB_SOF_HOOK myAssemblerMacro + * This macro (if defined) is executed in the assembler module when a + * Start Of Frame condition is detected. It is recommended to define it to + * the name of an assembler macro which is defined here as well so that more + * than one assembler instruction can be used. The macro may use the register + * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages + * immediately after an SOF pulse may be lost and must be retried by the host. + * What can you do with this hook? Since the SOF signal occurs exactly every + * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in + * designs running on the internal RC oscillator. + * Please note that Start Of Frame detection works only if D- is wired to the + * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! + */ +#define USB_CFG_CHECK_DATA_TOGGLING 0 +/* define this macro to 1 if you want to filter out duplicate data packets + * sent by the host. Duplicates occur only as a consequence of communication + * errors, when the host does not receive an ACK. Please note that you need to + * implement the filtering yourself in usbFunctionWriteOut() and + * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable + * for each control- and out-endpoint to check for duplicate packets. + */ +#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 +/* define this macro to 1 if you want the function usbMeasureFrameLength() + * compiled in. This function can be used to calibrate the AVR's RC oscillator. + */ +#define USB_USE_FAST_CRC 0 +/* The assembler module has two implementations for the CRC algorithm. One is + * faster, the other is smaller. This CRC routine is only used for transmitted + * messages where timing is not critical. The faster routine needs 31 cycles + * per byte while the smaller one needs 61 to 69 cycles. The faster routine + * may be worth the 32 bytes bigger code size if you transmit lots of data and + * run the AVR close to its limit. + */ + +/* -------------------------- Device Description --------------------------- */ + +#define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ +/* USB vendor ID for the device, low byte first. If you have registered your + * own Vendor ID, define it here. Otherwise you may use one of obdev's free + * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_ID 0xdc, 0x05 /* = 0x05dc = 1500 */ +/* This is the ID of the product, low byte first. It is interpreted in the + * scope of the vendor ID. If you have registered your own VID with usb.org + * or if you have licensed a PID from somebody else, define it here. Otherwise + * you may use one of obdev's free shared VID/PID pairs. See the file + * USB-IDs-for-free.txt for details! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +/* Version number of the device: Minor number first, then major number. + */ +#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' +#define USB_CFG_VENDOR_NAME_LEN 8 +/* These two values define the vendor name returned by the USB device. The name + * must be given as a list of characters under single quotes. The characters + * are interpreted as Unicode (UTF-16) entities. + * If you don't want a vendor name string, undefine these macros. + * ALWAYS define a vendor name containing your Internet domain name if you use + * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for + * details. + */ +#define USB_CFG_DEVICE_NAME 'L', 'E', 'D', 'C', 'o', 'n', 't', 'r', 'o', 'l' +#define USB_CFG_DEVICE_NAME_LEN 10 +/* Same as above for the device name. If you don't want a device name, undefine + * the macros. See the file USB-IDs-for-free.txt before you assign a name if + * you use a shared VID/PID. + */ +/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ +/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ +/* Same as above for the serial number. If you don't want a serial number, + * undefine the macros. + * It may be useful to provide the serial number through other means than at + * compile time. See the section about descriptor properties below for how + * to fine tune control over USB descriptors such as the string descriptor + * for the serial number. + */ +#define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */ +#define USB_CFG_DEVICE_SUBCLASS 0 +/* See USB specification if you want to conform to an existing device class. + * Class 0xff is "vendor specific". + */ +#define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */ +#define USB_CFG_INTERFACE_SUBCLASS 0 +#define USB_CFG_INTERFACE_PROTOCOL 0 +/* See USB specification if you want to conform to an existing device class or + * protocol. The following classes must be set at interface level: + * HID class is 3, no subclass and protocol required (but may be useful!) + * CDC class is 2, use subclass 2 and protocol 1 for ACM + */ +/* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */ +/* Define this to the length of the HID report descriptor, if you implement + * an HID device. Otherwise don't define it or define it to 0. + * If you use this define, you must add a PROGMEM character array named + * "usbHidReportDescriptor" to your code which contains the report descriptor. + * Don't forget to keep the array and this define in sync! + */ + +/* #define USB_PUBLIC static */ +/* Use the define above if you #include usbdrv.c instead of linking against it. + * This technique saves a couple of bytes in flash memory. + */ + +/* ------------------- Fine Control over USB Descriptors ------------------- */ +/* If you don't want to use the driver's default USB descriptors, you can + * provide our own. These can be provided as (1) fixed length static data in + * flash memory, (2) fixed length static data in RAM or (3) dynamically at + * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more + * information about this function. + * Descriptor handling is configured through the descriptor's properties. If + * no properties are defined or if they are 0, the default descriptor is used. + * Possible properties are: + * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched + * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is + * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if + * you want RAM pointers. + * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found + * in static memory is in RAM, not in flash memory. + * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), + * the driver must know the descriptor's length. The descriptor itself is + * found at the address of a well known identifier (see below). + * List of static descriptor names (must be declared PROGMEM if in flash): + * char usbDescriptorDevice[]; + * char usbDescriptorConfiguration[]; + * char usbDescriptorHidReport[]; + * char usbDescriptorString0[]; + * int usbDescriptorStringVendor[]; + * int usbDescriptorStringDevice[]; + * int usbDescriptorStringSerialNumber[]; + * Other descriptors can't be provided statically, they must be provided + * dynamically at runtime. + * + * Descriptor properties are or-ed or added together, e.g.: + * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) + * + * The following descriptors are defined: + * USB_CFG_DESCR_PROPS_DEVICE + * USB_CFG_DESCR_PROPS_CONFIGURATION + * USB_CFG_DESCR_PROPS_STRINGS + * USB_CFG_DESCR_PROPS_STRING_0 + * USB_CFG_DESCR_PROPS_STRING_VENDOR + * USB_CFG_DESCR_PROPS_STRING_PRODUCT + * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER + * USB_CFG_DESCR_PROPS_HID + * USB_CFG_DESCR_PROPS_HID_REPORT + * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) + * + * Note about string descriptors: String descriptors are not just strings, they + * are Unicode strings prefixed with a 2 byte header. Example: + * int serialNumberDescriptor[] = { + * USB_STRING_DESCRIPTOR_HEADER(6), + * 'S', 'e', 'r', 'i', 'a', 'l' + * }; + */ + +#define USB_CFG_DESCR_PROPS_DEVICE 0 +#define USB_CFG_DESCR_PROPS_CONFIGURATION 0 +#define USB_CFG_DESCR_PROPS_STRINGS 0 +#define USB_CFG_DESCR_PROPS_STRING_0 0 +#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 +#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 +#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 +#define USB_CFG_DESCR_PROPS_HID 0 +#define USB_CFG_DESCR_PROPS_HID_REPORT 0 +#define USB_CFG_DESCR_PROPS_UNKNOWN 0 + +/* ----------------------- Optional MCU Description ------------------------ */ + +/* The following configurations have working defaults in usbdrv.h. You + * usually don't need to set them explicitly. Only if you want to run + * the driver on a device which is not yet supported or with a compiler + * which is not fully supported (such as IAR C) or if you use a differnt + * interrupt than INT0, you may have to define some of these. + */ +/* #define USB_INTR_CFG MCUCR */ +/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ +/* #define USB_INTR_CFG_CLR 0 */ +/* #define USB_INTR_ENABLE GIMSK */ +/* #define USB_INTR_ENABLE_BIT INT0 */ +/* #define USB_INTR_PENDING GIFR */ +/* #define USB_INTR_PENDING_BIT INTF0 */ +/* #define USB_INTR_VECTOR INT0_vect */ + +#endif /* __usbconfig_h_included__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/Readme.txt b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/Readme.txt new file mode 100644 index 0000000..6a2ab3b --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/Readme.txt @@ -0,0 +1,28 @@ +This is the Readme file for the hid-custom-rq example. This is basically the +same as the custom-class example, except that the device conforms to the USB +HID class. + + +WHAT IS DEMONSTRATED? +===================== +This example demonstrates how custom requests can be sent to devices which +are otherwise HID compliant. This mechanism can be used to prevent the +"driver CD" dialog on Windows and still control the device with libusb-win32. +It can also be used to extend the functionality of the USB class, e.g. by +setting parameters. + +Please note that you should install the filter version of libusb-win32 to +take full advantage or this mode. The device driver version only has access +to devices which have been registered for it with a *.inf file. The filter +version has access to all devices. + + +MORE INFORMATION +================ +For information about how to build this example and how to use the command +line tool see the Readme file in the custom-class example. + + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/Makefile b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/Makefile new file mode 100644 index 0000000..5894ca8 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/Makefile @@ -0,0 +1,48 @@ +# Name: Makefile +# Project: hid-custom-rq example +# Author: Christian Starkjohann +# Creation Date: 2008-04-06 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + + +# Concigure the following definitions according to your system. +# This Makefile has been tested on Mac OS X, Linux and Windows. + +# Use the following 3 lines on Unix (uncomment the framework on Mac OS X): +USBFLAGS = `libusb-config --cflags` +USBLIBS = `libusb-config --libs` +EXE_SUFFIX = + +# Use the following 3 lines on Windows and comment out the 3 above. You may +# have to change the include paths to where you installed libusb-win32 +#USBFLAGS = -I/usr/local/include +#USBLIBS = -L/usr/local/lib -lusb +#EXE_SUFFIX = .exe + +NAME = set-led + +OBJECTS = opendevice.o $(NAME).o + +CC = gcc +CFLAGS = $(CPPFLAGS) $(USBFLAGS) -O -g -Wall +LIBS = $(USBLIBS) + +PROGRAM = $(NAME)$(EXE_SUFFIX) + + +all: $(PROGRAM) + +.c.o: + $(CC) $(CFLAGS) -c $< + +$(PROGRAM): $(OBJECTS) + $(CC) -o $(PROGRAM) $(OBJECTS) $(LIBS) + +strip: $(PROGRAM) + strip $(PROGRAM) + +clean: + rm -f *.o $(PROGRAM) diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/Makefile.windows b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/Makefile.windows new file mode 100644 index 0000000..4ea1df6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/Makefile.windows @@ -0,0 +1,18 @@ +# Name: Makefile.windows +# Project: hid-custom-rq example +# Author: Christian Starkjohann +# Creation Date: 2008-04-06 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id$ + +# You may use this file with +# make -f Makefile.windows +# on Windows with MinGW instead of editing the main Makefile. + +include Makefile + +USBFLAGS = -I/usr/local/mingw/include +USBLIBS = -L/usr/local/mingw/lib -lusb +EXE_SUFFIX = .exe diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/opendevice.c b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/opendevice.c new file mode 100644 index 0000000..137f50c --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/opendevice.c @@ -0,0 +1,203 @@ +/* Name: opendevice.c + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.c 740 2009-04-13 18:23:31Z cs $ + */ + +/* +General Description: +The functions in this module can be used to find and open a device based on +libusb or libusb-win32. +*/ + +#include +#include "opendevice.h" + +/* ------------------------------------------------------------------------- */ + +#define MATCH_SUCCESS 1 +#define MATCH_FAILED 0 +#define MATCH_ABORT -1 + +/* private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or MATCH_ABORT. */ +static int _shellStyleMatch(char *text, char *p) +{ +int last, matched, reverse; + + for(; *p; text++, p++){ + if(*text == 0 && *p != '*') + return MATCH_ABORT; + switch(*p){ + case '\\': + /* Literal match with following character. */ + p++; + /* FALLTHROUGH */ + default: + if(*text != *p) + return MATCH_FAILED; + continue; + case '?': + /* Match anything. */ + continue; + case '*': + while(*++p == '*') + /* Consecutive stars act just like one. */ + continue; + if(*p == 0) + /* Trailing star matches everything. */ + return MATCH_SUCCESS; + while(*text) + if((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED) + return matched; + return MATCH_ABORT; + case '[': + reverse = p[1] == '^'; + if(reverse) /* Inverted character class. */ + p++; + matched = MATCH_FAILED; + if(p[1] == ']' || p[1] == '-') + if(*++p == *text) + matched = MATCH_SUCCESS; + for(last = *p; *++p && *p != ']'; last = *p) + if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p) + matched = MATCH_SUCCESS; + if(matched == reverse) + return MATCH_FAILED; + continue; + } + } + return *text == 0; +} + +/* public interface for shell style matching: returns 0 if fails, 1 if matches */ +static int shellStyleMatch(char *text, char *pattern) +{ + if(pattern == NULL) /* NULL pattern is synonymous to "*" */ + return 1; + return _shellStyleMatch(text, pattern) == MATCH_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) +{ +char buffer[256]; +int rval, i; + + if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ + return rval; + if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) + return rval; + if(buffer[1] != USB_DT_STRING){ + *buf = 0; + return 0; + } + if((unsigned char)buffer[0] < rval) + rval = (unsigned char)buffer[0]; + rval /= 2; + /* lossy conversion to ISO Latin1: */ + for(i=1;i buflen) /* destination buffer overflow */ + break; + buf[i-1] = buffer[2 * i]; + if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ + buf[i-1] = '?'; + } + buf[i-1] = 0; + return i-1; +} + +/* ------------------------------------------------------------------------- */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp) +{ +struct usb_bus *bus; +struct usb_device *dev; +usb_dev_handle *handle = NULL; +int errorCode = USBOPEN_ERR_NOTFOUND; + + usb_find_busses(); + usb_find_devices(); + for(bus = usb_get_busses(); bus; bus = bus->next){ + for(dev = bus->devices; dev; dev = dev->next){ /* iterate over all devices on all busses */ + if((vendorID == 0 || dev->descriptor.idVendor == vendorID) + && (productID == 0 || dev->descriptor.idProduct == productID)){ + char vendor[256], product[256], serial[256]; + int len; + handle = usb_open(dev); /* we need to open the device in order to query strings */ + if(!handle){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot open VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + continue; + } + /* now check whether the names match: */ + len = vendor[0] = 0; + if(dev->descriptor.iManufacturer > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, vendor, sizeof(vendor)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen device from vendor ->%s<-\n", vendor); */ + if(shellStyleMatch(vendor, vendorNamePattern)){ + len = product[0] = 0; + if(dev->descriptor.iProduct > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iProduct, product, sizeof(product)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen product ->%s<-\n", product); */ + if(shellStyleMatch(product, productNamePattern)){ + len = serial[0] = 0; + if(dev->descriptor.iSerialNumber > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, serial, sizeof(serial)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + } + if(shellStyleMatch(serial, serialNamePattern)){ + if(printMatchingDevicesFp != NULL){ + if(serial[0] == 0){ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product); + }else{ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product, serial); + } + }else{ + break; + } + } + } + } + } + } + usb_close(handle); + handle = NULL; + } + } + if(handle) /* we have found a deice */ + break; + } + if(handle != NULL){ + errorCode = 0; + *device = handle; + } + if(printMatchingDevicesFp != NULL) /* never return an error for listing only */ + errorCode = 0; + return errorCode; +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/opendevice.h b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/opendevice.h new file mode 100644 index 0000000..79c12f6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/opendevice.h @@ -0,0 +1,77 @@ +/* Name: opendevice.h + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.h 755 2009-08-03 17:01:21Z cs $ + */ + +/* +General Description: +This module offers additional functionality for host side drivers based on +libusb or libusb-win32. It includes a function to find and open a device +based on numeric IDs and textual description. It also includes a function to +obtain textual descriptions from a device. + +To use this functionality, simply copy opendevice.c and opendevice.h into your +project and add them to your Makefile. You may modify and redistribute these +files according to the GNU General Public License (GPL) version 2 or 3. +*/ + +#ifndef __OPENDEVICE_H_INCLUDED__ +#define __OPENDEVICE_H_INCLUDED__ + +#include /* this is libusb, see http://libusb.sourceforge.net/ */ +#include + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen); +/* This function gets a string descriptor from the device. 'index' is the + * string descriptor index. The string is returned in ISO Latin 1 encoding in + * 'buf' and it is terminated with a 0-character. The buffer size must be + * passed in 'buflen' to prevent buffer overflows. A libusb device handle + * must be given in 'dev'. + * Returns: The length of the string (excluding the terminating 0) or + * a negative number in case of an error. If there was an error, use + * usb_strerror() to obtain the error message. + */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp); +/* This function iterates over all devices on all USB busses and searches for + * a device. Matching is done first by means of Vendor- and Product-ID (passed + * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard). + * When a device matches by its IDs, matching by names is performed. Name + * matching can be done on textual vendor name ('vendorNamePattern'), product + * name ('productNamePattern') and serial number ('serialNamePattern'). A + * device matches only if all non-null pattern match. If you don't care about + * a string, pass NULL for the pattern. Patterns are Unix shell style pattern: + * '*' stands for 0 or more characters, '?' for one single character, a list + * of characters in square brackets for a single character from the list + * (dashes are allowed to specify a range) and if the lis of characters begins + * with a caret ('^'), it matches one character which is NOT in the list. + * Other parameters to the function: If 'warningsFp' is not NULL, warning + * messages are printed to this file descriptor with fprintf(). If + * 'printMatchingDevicesFp' is not NULL, no device is opened but matching + * devices are printed to the given file descriptor with fprintf(). + * If a device is opened, the resulting USB handle is stored in '*device'. A + * pointer to a "usb_dev_handle *" type variable must be passed here. + * Returns: 0 on success, an error code (see defines below) on failure. + */ + +/* usbOpenDevice() error codes: */ +#define USBOPEN_SUCCESS 0 /* no error */ +#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ +#define USBOPEN_ERR_IO 2 /* I/O error */ +#define USBOPEN_ERR_NOTFOUND 3 /* device not found */ + + +/* Obdev's free USB IDs, see USB-IDs-for-free.txt for details */ + +#define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */ +#define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */ +#define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */ +#define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */ +#define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */ + +#endif /* __OPENDEVICE_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/set-led.c b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/set-led.c new file mode 100644 index 0000000..52b2a3b --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/commandline/set-led.c @@ -0,0 +1,135 @@ +/* Name: set-led.c + * Project: hid-custom-rq example + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: set-led.c 692 2008-11-07 15:07:40Z cs $ + */ + +/* +General Description: +This is the host-side driver for the custom-class example device. It searches +the USB for the LEDControl device and sends the requests understood by this +device. +This program must be linked with libusb on Unix and libusb-win32 on Windows. +See http://libusb.sourceforge.net/ or http://libusb-win32.sourceforge.net/ +respectively. +*/ + +#include +#include +#include +#include /* this is libusb */ +#include "opendevice.h" /* common code moved to separate module */ + +#include "../firmware/requests.h" /* custom request numbers */ +#include "../firmware/usbconfig.h" /* device's VID/PID and names */ + +static void usage(char *name) +{ + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s on ....... turn on LED\n", name); + fprintf(stderr, " %s off ...... turn off LED\n", name); + fprintf(stderr, " %s status ... ask current status of LED\n", name); +#if ENABLE_TEST + fprintf(stderr, " %s test ..... run driver reliability test\n", name); +#endif /* ENABLE_TEST */ +} + +int main(int argc, char **argv) +{ +usb_dev_handle *handle = NULL; +const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID}; +char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0}; +char buffer[4]; +int cnt, vid, pid, isOn; + + usb_init(); + if(argc < 2){ /* we need at least one argument */ + usage(argv[0]); + exit(1); + } + /* compute VID/PID from usbconfig.h so that there is a central source of information */ + vid = rawVid[1] * 256 + rawVid[0]; + pid = rawPid[1] * 256 + rawPid[0]; + /* The following function is in opendevice.c: */ + if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){ + fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid); + exit(1); + } + /* Since we use only control endpoint 0, we don't need to choose a + * configuration and interface. Reading device descriptor and setting a + * configuration and interface is done through endpoint 0 after all. + * However, newer versions of Linux require that we claim an interface + * even for endpoint 0. Enable the following code if your operating system + * needs it: */ +#if 0 + int retries = 1, usbConfiguration = 1, usbInterface = 0; + if(usb_set_configuration(handle, usbConfiguration) && showWarnings){ + fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror()); + } + /* now try to claim the interface and detach the kernel HID driver on + * Linux and other operating systems which support the call. */ + while((len = usb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){ +#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP + if(usb_detach_kernel_driver_np(handle, 0) < 0 && showWarnings){ + fprintf(stderr, "Warning: could not detach kernel driver: %s\n", usb_strerror()); + } +#endif + } +#endif + + if(strcasecmp(argv[1], "status") == 0){ + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_STATUS, 0, 0, buffer, sizeof(buffer), 5000); + if(cnt < 1){ + if(cnt < 0){ + fprintf(stderr, "USB error: %s\n", usb_strerror()); + }else{ + fprintf(stderr, "only %d bytes received.\n", cnt); + } + }else{ + printf("LED is %s\n", buffer[0] ? "on" : "off"); + } + }else if((isOn = (strcasecmp(argv[1], "on") == 0)) || strcasecmp(argv[1], "off") == 0){ + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, isOn, 0, buffer, 0, 5000); + if(cnt < 0){ + fprintf(stderr, "USB error: %s\n", usb_strerror()); + } +#if ENABLE_TEST + }else if(strcasecmp(argv[1], "test") == 0){ + int i; + srandomdev(); + for(i = 0; i < 50000; i++){ + int value = random() & 0xffff, index = random() & 0xffff; + int rxValue, rxIndex; + if((i+1) % 100 == 0){ + fprintf(stderr, "\r%05d", i+1); + fflush(stderr); + } + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_ECHO, value, index, buffer, sizeof(buffer), 5000); + if(cnt < 0){ + fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror()); + break; + }else if(cnt != 4){ + fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of 4\n", i, cnt); + break; + } + rxValue = ((int)buffer[0] & 0xff) | (((int)buffer[1] & 0xff) << 8); + rxIndex = ((int)buffer[2] & 0xff) | (((int)buffer[3] & 0xff) << 8); + if(rxValue != value || rxIndex != index){ + fprintf(stderr, "\ndata error in iteration %d:\n", i); + fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, value); + fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, index); + } + } + fprintf(stderr, "\nTest completed.\n"); +#endif /* ENABLE_TEST */ + }else{ + usage(argv[0]); + exit(1); + } + usb_close(handle); + return 0; +} diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/Makefile b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/Makefile new file mode 100644 index 0000000..f2372db --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/Makefile @@ -0,0 +1,164 @@ +# Name: Makefile +# Project: hid-custom-rq example +# Author: Christian Starkjohann +# Creation Date: 2008-04-07 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + +DEVICE = atmega168 +F_CPU = 16000000 # in Hz +FUSE_L = # see below for fuse values for particular devices +FUSE_H = +AVRDUDE = avrdude -c usbasp -p $(DEVICE) # edit this line for your programmer + +CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 +OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o + +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) + +############################################################################## +# Fuse values for particular devices +############################################################################## +# If your device is not listed here, go to +# http://palmavr.sourceforge.net/cgi-bin/fc.cgi +# and choose options for external crystal clock and no clock divider +# +################################## ATMega8 ################################## +# ATMega8 FUSE_L (Fuse low byte): +# 0x9f = 1 0 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ BODEN (BrownOut Detector enabled) +# +-------------------- BODLEVEL (2.7V) +# ATMega8 FUSE_H (Fuse high byte): +# 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) +# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 +# | | | | | +-------- BOOTSZ1 +# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) +# | | | +-------------- CKOPT (full output swing) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ WDTON (WDT not always on) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATMega48/88/168 ############################## +# ATMega*8 FUSE_L (Fuse low byte): +# 0xdf = 1 1 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ CKOUT (if 0: Clock output enabled) +# +-------------------- CKDIV8 (if 0: divide by 8) +# ATMega*8 FUSE_H (Fuse high byte): +# 0xde = 1 1 0 1 1 1 1 0 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V) +# | | | | + --------- EESAVE (preserve EEPROM over chip erase) +# | | | +-------------- WDTON (if 0: watchdog always on) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATTiny25/45/85 ############################### +# ATMega*5 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATMega*5 FUSE_H (Fuse high byte): +# 0xdd = 1 1 0 1 1 1 0 1 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (disable external reset -> enabled) +# +################################ ATTiny2313 ################################# +# ATTiny2313 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATTiny2313 FUSE_H (Fuse high byte): +# 0xdb = 1 1 0 1 1 0 1 1 +# ^ ^ ^ ^ \-+-/ ^ +# | | | | | +---- RSTDISBL (disable external reset -> enabled) +# | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# +-------------------- DWEN (debug wire enable) + + +# symbolic targets: +help: + @echo "This Makefile has no default rule. Use one of the following:" + @echo "make hex ....... to build main.hex" + @echo "make program ... to flash fuses and firmware" + @echo "make fuse ...... to flash the fuses" + @echo "make flash ..... to flash the firmware (use this on metaboard)" + @echo "make clean ..... to delete objects and hex file" + +hex: main.hex + +program: flash fuse + +# rule for programming fuse bits: +fuse: + @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \ + { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; } + $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m + +# rule for uploading firmware: +flash: main.hex + $(AVRDUDE) -U flash:w:main.hex:i + +# rule for deleting dependent files (those which can be built by Make): +clean: + rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s + +# Generic rule for compiling C files: +.c.o: + $(COMPILE) -c $< -o $@ + +# Generic rule for assembling Assembler source files: +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +# Generic rule for compiling C to assembler, used for debugging only. +.c.s: + $(COMPILE) -S $< -o $@ + +# file targets: + +# Since we don't want to ship the driver multipe times, we copy it into this project: +usbdrv: + cp -r ../../../usbdrv . + +main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it + $(COMPILE) -o main.elf $(OBJECTS) + +main.hex: main.elf + rm -f main.hex main.eep.hex + avr-objcopy -j .text -j .data -O ihex main.elf main.hex + avr-size main.hex + +# debugging targets: + +disasm: main.elf + avr-objdump -d main.elf + +cpp: + $(COMPILE) -E main.c diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/main.c b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/main.c new file mode 100644 index 0000000..9681a29 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/main.c @@ -0,0 +1,120 @@ +/* Name: main.c + * Project: hid-custom-rq example + * Author: Christian Starkjohann + * Creation Date: 2008-04-07 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ + */ + +/* +This example should run on most AVRs with only little changes. No special +hardware resources except INT0 are used. You may have to change usbconfig.h for +different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or +at least be connected to INT0 as well. +We assume that an LED is connected to port B bit 0. If you connect it to a +different port or bit, change the macros below: +*/ +#define LED_PORT_DDR DDRB +#define LED_PORT_OUTPUT PORTB +#define LED_BIT 0 + +#include +#include +#include /* for sei() */ +#include /* for _delay_ms() */ + +#include /* required by usbdrv.h */ +#include "usbdrv.h" +#include "oddebug.h" /* This is also an example for using debug macros */ +#include "requests.h" /* The custom request numbers we use */ + +/* ------------------------------------------------------------------------- */ +/* ----------------------------- USB interface ----------------------------- */ +/* ------------------------------------------------------------------------- */ + +PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */ + 0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop) + 0x09, 0x01, // USAGE (Vendor Usage 1) + 0xa1, 0x01, // COLLECTION (Application) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) + 0x09, 0x00, // USAGE (Undefined) + 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf) + 0xc0 // END_COLLECTION +}; +/* The descriptor above is a dummy only, it silences the drivers. The report + * it describes consists of one byte of undefined data. + * We don't transfer our data through HID reports, we use custom requests + * instead. + */ + +/* ------------------------------------------------------------------------- */ + +usbMsgLen_t usbFunctionSetup(uchar data[8]) +{ +usbRequest_t *rq = (void *)data; + + if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR){ + DBG1(0x50, &rq->bRequest, 1); /* debug output: print our request */ + if(rq->bRequest == CUSTOM_RQ_SET_STATUS){ + if(rq->wValue.bytes[0] & 1){ /* set LED */ + LED_PORT_OUTPUT |= _BV(LED_BIT); + }else{ /* clear LED */ + LED_PORT_OUTPUT &= ~_BV(LED_BIT); + } + }else if(rq->bRequest == CUSTOM_RQ_GET_STATUS){ + static uchar dataBuffer[1]; /* buffer must stay valid when usbFunctionSetup returns */ + dataBuffer[0] = ((LED_PORT_OUTPUT & _BV(LED_BIT)) != 0); + usbMsgPtr = dataBuffer; /* tell the driver which data to return */ + return 1; /* tell the driver to send 1 byte */ + } + }else{ + /* calss requests USBRQ_HID_GET_REPORT and USBRQ_HID_SET_REPORT are + * not implemented since we never call them. The operating system + * won't call them either because our descriptor defines no meaning. + */ + } + return 0; /* default for not implemented requests: return no data back to host */ +} + +/* ------------------------------------------------------------------------- */ + +int __attribute__((noreturn)) main(void) +{ +uchar i; + + wdt_enable(WDTO_1S); + /* Even if you don't use the watchdog, turn it off here. On newer devices, + * the status of the watchdog (on/off, period) is PRESERVED OVER RESET! + */ + /* RESET status: all port bits are inputs without pull-up. + * That's the way we need D+ and D-. Therefore we don't need any + * additional hardware initialization. + */ + odDebugInit(); + DBG1(0x00, 0, 0); /* debug output: main starts */ + usbInit(); + usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ + i = 0; + while(--i){ /* fake USB disconnect for > 250 ms */ + wdt_reset(); + _delay_ms(1); + } + usbDeviceConnect(); + LED_PORT_DDR |= _BV(LED_BIT); /* make the LED bit an output */ + sei(); + DBG1(0x01, 0, 0); /* debug output: main loop starts */ + for(;;){ /* main event loop */ +#if 0 /* this is a bit too aggressive for a debug output */ + DBG2(0x02, 0, 0); /* debug output: main loop iterates */ +#endif + wdt_reset(); + usbPoll(); + } +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/requests.h b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/requests.h new file mode 100644 index 0000000..79282b6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/requests.h @@ -0,0 +1,32 @@ +/* Name: requests.h + * Project: custom-class, a basic USB example + * Author: Christian Starkjohann + * Creation Date: 2008-04-09 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: requests.h 692 2008-11-07 15:07:40Z cs $ + */ + +/* This header is shared between the firmware and the host software. It + * defines the USB request numbers (and optionally data types) used to + * communicate between the host and the device. + */ + +#ifndef __REQUESTS_H_INCLUDED__ +#define __REQUESTS_H_INCLUDED__ + +#define CUSTOM_RQ_SET_STATUS 1 +/* Set the LED status. Control-OUT. + * The requested status is passed in the "wValue" field of the control + * transfer. No OUT data is sent. Bit 0 of the low byte of wValue controls + * the LED. + */ + +#define CUSTOM_RQ_GET_STATUS 2 +/* Get the current LED status. Control-IN. + * This control transfer involves a 1 byte data phase where the device sends + * the current status to the host. The status is in bit 0 of the byte. + */ + +#endif /* __REQUESTS_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/usbconfig.h b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/usbconfig.h new file mode 100644 index 0000000..e34583f --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-custom-rq/firmware/usbconfig.h @@ -0,0 +1,373 @@ +/* Name: usbconfig.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2005-04-01 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ + */ + +#ifndef __usbconfig_h_included__ +#define __usbconfig_h_included__ + +/* +General Description: +This file is an example configuration (with inline documentation) for the USB +driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is +also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may +wire the lines to any other port, as long as D+ is also wired to INT0 (or any +other hardware interrupt, as long as it is the highest level interrupt, see +section at the end of this file). +*/ + +/* ---------------------------- Hardware Config ---------------------------- */ + +#define USB_CFG_IOPORTNAME D +/* This is the port where the USB bus is connected. When you configure it to + * "B", the registers PORTB, PINB and DDRB will be used. + */ +#define USB_CFG_DMINUS_BIT 4 +/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. + * This may be any bit in the port. + */ +#define USB_CFG_DPLUS_BIT 2 +/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. + * This may be any bit in the port. Please note that D+ must also be connected + * to interrupt pin INT0! [You can also use other interrupts, see section + * "Optional MCU Description" below, or you can connect D- to the interrupt, as + * it is required if you use the USB_COUNT_SOF feature. If you use D- for the + * interrupt, the USB interrupt will also be triggered at Start-Of-Frame + * markers every millisecond.] + */ +#define USB_CFG_CLOCK_KHZ (F_CPU/1000) +/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, + * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code + * require no crystal, they tolerate +/- 1% deviation from the nominal + * frequency. All other rates require a precision of 2000 ppm and thus a + * crystal! + * Since F_CPU should be defined to your actual clock rate anyway, you should + * not need to modify this setting. + */ +#define USB_CFG_CHECK_CRC 0 +/* Define this to 1 if you want that the driver checks integrity of incoming + * data packets (CRC checks). CRC checks cost quite a bit of code size and are + * currently only available for 18 MHz crystal clock. You must choose + * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. + */ + +/* ----------------------- Optional Hardware Config ------------------------ */ + +/* #define USB_CFG_PULLUP_IOPORTNAME D */ +/* If you connect the 1.5k pullup resistor from D- to a port pin instead of + * V+, you can connect and disconnect the device from firmware by calling + * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). + * This constant defines the port on which the pullup resistor is connected. + */ +/* #define USB_CFG_PULLUP_BIT 4 */ +/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined + * above) where the 1.5k pullup resistor is connected. See description + * above for details. + */ + +/* --------------------------- Functional Range ---------------------------- */ + +#define USB_CFG_HAVE_INTRIN_ENDPOINT 1 +/* Define this to 1 if you want to compile a version with two endpoints: The + * default control endpoint 0 and an interrupt-in endpoint (any other endpoint + * number). + */ +#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 +/* Define this to 1 if you want to compile a version with three endpoints: The + * default control endpoint 0, an interrupt-in endpoint 3 (or the number + * configured below) and a catch-all default interrupt-in endpoint as above. + * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. + */ +#define USB_CFG_EP3_NUMBER 3 +/* If the so-called endpoint 3 is used, it can now be configured to any other + * endpoint number (except 0) with this macro. Default if undefined is 3. + */ +/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ +/* The above macro defines the startup condition for data toggling on the + * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. + * Since the token is toggled BEFORE sending any data, the first packet is + * sent with the oposite value of this configuration! + */ +#define USB_CFG_IMPLEMENT_HALT 0 +/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature + * for endpoint 1 (interrupt endpoint). Although you may not need this feature, + * it is required by the standard. We have made it a config option because it + * bloats the code considerably. + */ +#define USB_CFG_SUPPRESS_INTR_CODE 0 +/* Define this to 1 if you want to declare interrupt-in endpoints, but don't + * want to send any data over them. If this macro is defined to 1, functions + * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if + * you need the interrupt-in endpoints in order to comply to an interface + * (e.g. HID), but never want to send any data. This option saves a couple + * of bytes in flash memory and the transmit buffers in RAM. + */ +#define USB_CFG_INTR_POLL_INTERVAL 100 +/* If you compile a version with endpoint 1 (interrupt-in), this is the poll + * interval. The value is in milliseconds and must not be less than 10 ms for + * low speed devices. + */ +#define USB_CFG_IS_SELF_POWERED 0 +/* Define this to 1 if the device has its own power supply. Set it to 0 if the + * device is powered from the USB bus. + */ +#define USB_CFG_MAX_BUS_POWER 40 +/* Set this variable to the maximum USB bus power consumption of your device. + * The value is in milliamperes. [It will be divided by two since USB + * communicates power requirements in units of 2 mA.] + */ +#define USB_CFG_IMPLEMENT_FN_WRITE 0 +/* Set this to 1 if you want usbFunctionWrite() to be called for control-out + * transfers. Set it to 0 if you don't need it and want to save a couple of + * bytes. + */ +#define USB_CFG_IMPLEMENT_FN_READ 0 +/* Set this to 1 if you need to send control replies which are generated + * "on the fly" when usbFunctionRead() is called. If you only want to send + * data from a static buffer, set it to 0 and return the data from + * usbFunctionSetup(). This saves a couple of bytes. + */ +#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 +/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. + * You must implement the function usbFunctionWriteOut() which receives all + * interrupt/bulk data sent to any endpoint other than 0. The endpoint number + * can be found in 'usbRxToken'. + */ +#define USB_CFG_HAVE_FLOWCONTROL 0 +/* Define this to 1 if you want flowcontrol over USB data. See the definition + * of the macros usbDisableAllRequests() and usbEnableAllRequests() in + * usbdrv.h. + */ +#define USB_CFG_DRIVER_FLASH_PAGE 0 +/* If the device has more than 64 kBytes of flash, define this to the 64 k page + * where the driver's constants (descriptors) are located. Or in other words: + * Define this to 1 for boot loaders on the ATMega128. + */ +#define USB_CFG_LONG_TRANSFERS 0 +/* Define this to 1 if you want to send/receive blocks of more than 254 bytes + * in a single control-in or control-out transfer. Note that the capability + * for long transfers increases the driver size. + */ +/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ +/* This macro is a hook if you want to do unconventional things. If it is + * defined, it's inserted at the beginning of received message processing. + * If you eat the received message and don't want default processing to + * proceed, do a return after doing your things. One possible application + * (besides debugging) is to flash a status LED on each packet. + */ +/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ +/* This macro is a hook if you need to know when an USB RESET occurs. It has + * one parameter which distinguishes between the start of RESET state and its + * end. + */ +/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ +/* This macro (if defined) is executed when a USB SET_ADDRESS request was + * received. + */ +#define USB_COUNT_SOF 0 +/* define this macro to 1 if you need the global variable "usbSofCount" which + * counts SOF packets. This feature requires that the hardware interrupt is + * connected to D- instead of D+. + */ +/* #ifdef __ASSEMBLER__ + * macro myAssemblerMacro + * in YL, TCNT0 + * sts timer0Snapshot, YL + * endm + * #endif + * #define USB_SOF_HOOK myAssemblerMacro + * This macro (if defined) is executed in the assembler module when a + * Start Of Frame condition is detected. It is recommended to define it to + * the name of an assembler macro which is defined here as well so that more + * than one assembler instruction can be used. The macro may use the register + * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages + * immediately after an SOF pulse may be lost and must be retried by the host. + * What can you do with this hook? Since the SOF signal occurs exactly every + * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in + * designs running on the internal RC oscillator. + * Please note that Start Of Frame detection works only if D- is wired to the + * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! + */ +#define USB_CFG_CHECK_DATA_TOGGLING 0 +/* define this macro to 1 if you want to filter out duplicate data packets + * sent by the host. Duplicates occur only as a consequence of communication + * errors, when the host does not receive an ACK. Please note that you need to + * implement the filtering yourself in usbFunctionWriteOut() and + * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable + * for each control- and out-endpoint to check for duplicate packets. + */ +#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 +/* define this macro to 1 if you want the function usbMeasureFrameLength() + * compiled in. This function can be used to calibrate the AVR's RC oscillator. + */ +#define USB_USE_FAST_CRC 0 +/* The assembler module has two implementations for the CRC algorithm. One is + * faster, the other is smaller. This CRC routine is only used for transmitted + * messages where timing is not critical. The faster routine needs 31 cycles + * per byte while the smaller one needs 61 to 69 cycles. The faster routine + * may be worth the 32 bytes bigger code size if you transmit lots of data and + * run the AVR close to its limit. + */ + +/* -------------------------- Device Description --------------------------- */ + +#define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ +/* USB vendor ID for the device, low byte first. If you have registered your + * own Vendor ID, define it here. Otherwise you may use one of obdev's free + * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_ID 0xdf, 0x05 /* obdev's shared PID for HIDs */ +/* This is the ID of the product, low byte first. It is interpreted in the + * scope of the vendor ID. If you have registered your own VID with usb.org + * or if you have licensed a PID from somebody else, define it here. Otherwise + * you may use one of obdev's free shared VID/PID pairs. See the file + * USB-IDs-for-free.txt for details! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +/* Version number of the device: Minor number first, then major number. + */ +#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' +#define USB_CFG_VENDOR_NAME_LEN 8 +/* These two values define the vendor name returned by the USB device. The name + * must be given as a list of characters under single quotes. The characters + * are interpreted as Unicode (UTF-16) entities. + * If you don't want a vendor name string, undefine these macros. + * ALWAYS define a vendor name containing your Internet domain name if you use + * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for + * details. + */ +#define USB_CFG_DEVICE_NAME 'L', 'E', 'D', 'C', 't', 'l', 'H', 'I', 'D' +#define USB_CFG_DEVICE_NAME_LEN 9 +/* Same as above for the device name. If you don't want a device name, undefine + * the macros. See the file USB-IDs-for-free.txt before you assign a name if + * you use a shared VID/PID. + */ +/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ +/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ +/* Same as above for the serial number. If you don't want a serial number, + * undefine the macros. + * It may be useful to provide the serial number through other means than at + * compile time. See the section about descriptor properties below for how + * to fine tune control over USB descriptors such as the string descriptor + * for the serial number. + */ +#define USB_CFG_DEVICE_CLASS 0 +#define USB_CFG_DEVICE_SUBCLASS 0 +/* See USB specification if you want to conform to an existing device class. + * Class 0xff is "vendor specific". + */ +#define USB_CFG_INTERFACE_CLASS 3 +#define USB_CFG_INTERFACE_SUBCLASS 0 +#define USB_CFG_INTERFACE_PROTOCOL 0 +/* See USB specification if you want to conform to an existing device class or + * protocol. The following classes must be set at interface level: + * HID class is 3, no subclass and protocol required (but may be useful!) + * CDC class is 2, use subclass 2 and protocol 1 for ACM + */ +#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 22 +/* Define this to the length of the HID report descriptor, if you implement + * an HID device. Otherwise don't define it or define it to 0. + * If you use this define, you must add a PROGMEM character array named + * "usbHidReportDescriptor" to your code which contains the report descriptor. + * Don't forget to keep the array and this define in sync! + */ + +/* #define USB_PUBLIC static */ +/* Use the define above if you #include usbdrv.c instead of linking against it. + * This technique saves a couple of bytes in flash memory. + */ + +/* ------------------- Fine Control over USB Descriptors ------------------- */ +/* If you don't want to use the driver's default USB descriptors, you can + * provide our own. These can be provided as (1) fixed length static data in + * flash memory, (2) fixed length static data in RAM or (3) dynamically at + * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more + * information about this function. + * Descriptor handling is configured through the descriptor's properties. If + * no properties are defined or if they are 0, the default descriptor is used. + * Possible properties are: + * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched + * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is + * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if + * you want RAM pointers. + * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found + * in static memory is in RAM, not in flash memory. + * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), + * the driver must know the descriptor's length. The descriptor itself is + * found at the address of a well known identifier (see below). + * List of static descriptor names (must be declared PROGMEM if in flash): + * char usbDescriptorDevice[]; + * char usbDescriptorConfiguration[]; + * char usbDescriptorHidReport[]; + * char usbDescriptorString0[]; + * int usbDescriptorStringVendor[]; + * int usbDescriptorStringDevice[]; + * int usbDescriptorStringSerialNumber[]; + * Other descriptors can't be provided statically, they must be provided + * dynamically at runtime. + * + * Descriptor properties are or-ed or added together, e.g.: + * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) + * + * The following descriptors are defined: + * USB_CFG_DESCR_PROPS_DEVICE + * USB_CFG_DESCR_PROPS_CONFIGURATION + * USB_CFG_DESCR_PROPS_STRINGS + * USB_CFG_DESCR_PROPS_STRING_0 + * USB_CFG_DESCR_PROPS_STRING_VENDOR + * USB_CFG_DESCR_PROPS_STRING_PRODUCT + * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER + * USB_CFG_DESCR_PROPS_HID + * USB_CFG_DESCR_PROPS_HID_REPORT + * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) + * + * Note about string descriptors: String descriptors are not just strings, they + * are Unicode strings prefixed with a 2 byte header. Example: + * int serialNumberDescriptor[] = { + * USB_STRING_DESCRIPTOR_HEADER(6), + * 'S', 'e', 'r', 'i', 'a', 'l' + * }; + */ + +#define USB_CFG_DESCR_PROPS_DEVICE 0 +#define USB_CFG_DESCR_PROPS_CONFIGURATION 0 +#define USB_CFG_DESCR_PROPS_STRINGS 0 +#define USB_CFG_DESCR_PROPS_STRING_0 0 +#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 +#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 +#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 +#define USB_CFG_DESCR_PROPS_HID 0 +#define USB_CFG_DESCR_PROPS_HID_REPORT 0 +#define USB_CFG_DESCR_PROPS_UNKNOWN 0 + +/* ----------------------- Optional MCU Description ------------------------ */ + +/* The following configurations have working defaults in usbdrv.h. You + * usually don't need to set them explicitly. Only if you want to run + * the driver on a device which is not yet supported or with a compiler + * which is not fully supported (such as IAR C) or if you use a differnt + * interrupt than INT0, you may have to define some of these. + */ +/* #define USB_INTR_CFG MCUCR */ +/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ +/* #define USB_INTR_CFG_CLR 0 */ +/* #define USB_INTR_ENABLE GIMSK */ +/* #define USB_INTR_ENABLE_BIT INT0 */ +/* #define USB_INTR_PENDING GIFR */ +/* #define USB_INTR_PENDING_BIT INTF0 */ +/* #define USB_INTR_VECTOR INT0_vect */ + +#endif /* __usbconfig_h_included__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/Readme.txt b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/Readme.txt new file mode 100644 index 0000000..cb17baa --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/Readme.txt @@ -0,0 +1,75 @@ +This is the Readme file for the hid-data example. In this example, we show +how blocks of data can be exchanged with the device using only functionality +compliant to the HID class. Since class drivers for HID are included with +Windows, you don't need to install drivers on Windows. + + +WHAT IS DEMONSTRATED? +===================== +This example demonstrates how the HID class can be misused to transfer fixed +size blocks of data (up to the driver's transfer size limit) over HID feature +reports. This technique is of great value on Windows because no driver DLLs +are needed (the hid-custom-rq example still requires the libusb-win32 DLL, +although it may be in the program's directory). The host side application +requires no installation, it can even be started directly from a CD. This +example also demonstrates how to transfer data using usbFunctionWrite() and +usbFunctionRead(). + + +PREREQUISITES +============= +Target hardware: You need an AVR based circuit based on one of the examples +(see the "circuits" directory at the top level of this package), e.g. the +metaboard (http://www.obdev.at/goto.php?t=metaboard). + +AVR development environment: You need the gcc tool chain for the AVR, see +the Prerequisites section in the top level Readme file for how to obtain it. + +Host development environment: A C compiler and libusb on Unix. On Windows +you need the Driver Development Kit (DDK) Instead of libusb. MinGW ships +with a free version of the DDK. + + +BUILDING THE FIRMWARE +===================== +Change to the "firmware" directory and modify Makefile according to your +architecture (CPU clock, target device, fuse values) and ISP programmer. Then +edit usbconfig.h according to your pin assignments for D+ and D-. The default +settings are for the metaboard hardware. + +Type "make hex" to build main.hex, then "make flash" to upload the firmware +to the device. Don't forget to run "make fuse" once to program the fuses. If +you use a prototyping board with boot loader, follow the instructions of the +boot loader instead. + +Please note that the first "make hex" copies the driver from the top level +into the firmware directory. If you use a different build system than our +Makefile, you must copy the driver by hand. + + +BUILDING THE HOST SOFTWARE +========================== +Make sure that you have libusb (on Unix) or the DDK (on Windows) installed. +We recommend MinGW on Windows since it includes a free version of the DDK. +Then change to directory "commandline" and run "make" on Unix or +"make -f Makefile.windows" on Windows. + + +USING THE COMMAND LINE TOOL +=========================== +The device implements a data store of 128 bytes in EEPROM. You can send a +block of 128 bytes to the device or read the block using the command line +tool. + +To send a block to the device, use e.g. + + hidtool write 0x01,0x02,0x03,0x04,... + +and to receive the block, use + + hidtool read + + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/Makefile b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/Makefile new file mode 100644 index 0000000..dabfa42 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/Makefile @@ -0,0 +1,42 @@ +# Name: Makefile +# Project: hid-data example +# Author: Christian Starkjohann +# Creation Date: 2008-04-11 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + +# Please read the definitions below and edit them as appropriate for your +# system: + +# Use the following 3 lines on Unix and Mac OS X: +USBFLAGS= `libusb-config --cflags` +USBLIBS= `libusb-config --libs` +EXE_SUFFIX= + +# Use the following 3 lines on Windows and comment out the 3 above: +#USBFLAGS= +#USBLIBS= -lhid -lusb -lsetupapi +#EXE_SUFFIX= .exe + +CC= gcc +CFLAGS= -O -Wall $(USBFLAGS) +LIBS= $(USBLIBS) + +OBJ= hidtool.o hiddata.o +PROGRAM= hidtool$(EXE_SUFFIX) + +all: $(PROGRAM) + +$(PROGRAM): $(OBJ) + $(CC) -o $(PROGRAM) $(OBJ) $(LIBS) + +strip: $(PROGRAM) + strip $(PROGRAM) + +clean: + rm -f $(OBJ) $(PROGRAM) + +.c.o: + $(CC) $(ARCH_COMPILE) $(CFLAGS) -c $*.c -o $*.o diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/Makefile.windows b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/Makefile.windows new file mode 100644 index 0000000..a66dffc --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/Makefile.windows @@ -0,0 +1,18 @@ +# Name: Makefile.windows +# Project: hid-data example +# Author: Christian Starkjohann +# Creation Date: 2008-04-11 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id$ + +# You may use this file with +# make -f Makefile.windows +# on Windows with MinGW instead of editing the main Makefile. + +include Makefile + +USBFLAGS= +USBLIBS= -lhid -lsetupapi +EXE_SUFFIX= .exe diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hiddata.c b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hiddata.c new file mode 100644 index 0000000..93795e4 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hiddata.c @@ -0,0 +1,324 @@ +/* Name: hiddata.c + * Author: Christian Starkjohann + * Creation Date: 2008-04-11 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: hiddata.c 743 2009-04-15 15:00:49Z cs $ + */ + +#include +#include "hiddata.h" + +/* ######################################################################## */ +#if defined(WIN32) /* ##################################################### */ +/* ######################################################################## */ + +#include +#include +#include "hidsdi.h" +#include + +#ifdef DEBUG +#define DEBUG_PRINT(arg) printf arg +#else +#define DEBUG_PRINT(arg) +#endif + +/* ------------------------------------------------------------------------ */ + +static void convertUniToAscii(char *buffer) +{ +unsigned short *uni = (void *)buffer; +char *ascii = buffer; + + while(*uni != 0){ + if(*uni >= 256){ + *ascii++ = '?'; + }else{ + *ascii++ = *uni++; + } + } + *ascii++ = 0; +} + +int usbhidOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int usesReportIDs) +{ +GUID hidGuid; /* GUID for HID driver */ +HDEVINFO deviceInfoList; +SP_DEVICE_INTERFACE_DATA deviceInfo; +SP_DEVICE_INTERFACE_DETAIL_DATA *deviceDetails = NULL; +DWORD size; +int i, openFlag = 0; /* may be FILE_FLAG_OVERLAPPED */ +int errorCode = USBOPEN_ERR_NOTFOUND; +HANDLE handle = INVALID_HANDLE_VALUE; +HIDD_ATTRIBUTES deviceAttributes; + + HidD_GetHidGuid(&hidGuid); + deviceInfoList = SetupDiGetClassDevs(&hidGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); + deviceInfo.cbSize = sizeof(deviceInfo); + for(i=0;;i++){ + if(handle != INVALID_HANDLE_VALUE){ + CloseHandle(handle); + handle = INVALID_HANDLE_VALUE; + } + if(!SetupDiEnumDeviceInterfaces(deviceInfoList, 0, &hidGuid, i, &deviceInfo)) + break; /* no more entries */ + /* first do a dummy call just to determine the actual size required */ + SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, NULL, 0, &size, NULL); + if(deviceDetails != NULL) + free(deviceDetails); + deviceDetails = malloc(size); + deviceDetails->cbSize = sizeof(*deviceDetails); + /* this call is for real: */ + SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, deviceDetails, size, &size, NULL); + DEBUG_PRINT(("checking HID path \"%s\"\n", deviceDetails->DevicePath)); +#if 0 + /* If we want to access a mouse our keyboard, we can only use feature + * requests as the device is locked by Windows. It must be opened + * with ACCESS_TYPE_NONE. + */ + handle = CreateFile(deviceDetails->DevicePath, ACCESS_TYPE_NONE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); +#endif + /* attempt opening for R/W -- we don't care about devices which can't be accessed */ + handle = CreateFile(deviceDetails->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); + if(handle == INVALID_HANDLE_VALUE){ + DEBUG_PRINT(("opening failed: %d\n", (int)GetLastError())); + /* errorCode = USBOPEN_ERR_ACCESS; opening will always fail for mouse -- ignore */ + continue; + } + deviceAttributes.Size = sizeof(deviceAttributes); + HidD_GetAttributes(handle, &deviceAttributes); + DEBUG_PRINT(("device attributes: vid=%d pid=%d\n", deviceAttributes.VendorID, deviceAttributes.ProductID)); + if(deviceAttributes.VendorID != vendor || deviceAttributes.ProductID != product) + continue; /* ignore this device */ + errorCode = USBOPEN_ERR_NOTFOUND; + if(vendorName != NULL && productName != NULL){ + char buffer[512]; + if(!HidD_GetManufacturerString(handle, buffer, sizeof(buffer))){ + DEBUG_PRINT(("error obtaining vendor name\n")); + errorCode = USBOPEN_ERR_IO; + continue; + } + convertUniToAscii(buffer); + DEBUG_PRINT(("vendorName = \"%s\"\n", buffer)); + if(strcmp(vendorName, buffer) != 0) + continue; + if(!HidD_GetProductString(handle, buffer, sizeof(buffer))){ + DEBUG_PRINT(("error obtaining product name\n")); + errorCode = USBOPEN_ERR_IO; + continue; + } + convertUniToAscii(buffer); + DEBUG_PRINT(("productName = \"%s\"\n", buffer)); + if(strcmp(productName, buffer) != 0) + continue; + } + break; /* we have found the device we are looking for! */ + } + SetupDiDestroyDeviceInfoList(deviceInfoList); + if(deviceDetails != NULL) + free(deviceDetails); + if(handle != INVALID_HANDLE_VALUE){ + *device = (usbDevice_t *)handle; + errorCode = 0; + } + return errorCode; +} + +/* ------------------------------------------------------------------------ */ + +void usbhidCloseDevice(usbDevice_t *device) +{ + CloseHandle((HANDLE)device); +} + +/* ------------------------------------------------------------------------ */ + +int usbhidSetReport(usbDevice_t *device, char *buffer, int len) +{ +BOOLEAN rval; + + rval = HidD_SetFeature((HANDLE)device, buffer, len); + return rval == 0 ? USBOPEN_ERR_IO : 0; +} + +/* ------------------------------------------------------------------------ */ + +int usbhidGetReport(usbDevice_t *device, int reportNumber, char *buffer, int *len) +{ +BOOLEAN rval = 0; + + buffer[0] = reportNumber; + rval = HidD_GetFeature((HANDLE)device, buffer, *len); + return rval == 0 ? USBOPEN_ERR_IO : 0; +} + +/* ------------------------------------------------------------------------ */ + +/* ######################################################################## */ +#else /* defined WIN32 #################################################### */ +/* ######################################################################## */ + +#include +#include + +#define usbDevice usb_dev_handle /* use libusb's device structure */ + +/* ------------------------------------------------------------------------- */ + +#define USBRQ_HID_GET_REPORT 0x01 +#define USBRQ_HID_SET_REPORT 0x09 + +#define USB_HID_REPORT_TYPE_FEATURE 3 + + +static int usesReportIDs; + +/* ------------------------------------------------------------------------- */ + +static int usbhidGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) +{ +char buffer[256]; +int rval, i; + + if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ + return rval; + if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) + return rval; + if(buffer[1] != USB_DT_STRING){ + *buf = 0; + return 0; + } + if((unsigned char)buffer[0] < rval) + rval = (unsigned char)buffer[0]; + rval /= 2; + /* lossy conversion to ISO Latin1: */ + for(i=1;i buflen) /* destination buffer overflow */ + break; + buf[i-1] = buffer[2 * i]; + if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ + buf[i-1] = '?'; + } + buf[i-1] = 0; + return i-1; +} + +int usbhidOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int _usesReportIDs) +{ +struct usb_bus *bus; +struct usb_device *dev; +usb_dev_handle *handle = NULL; +int errorCode = USBOPEN_ERR_NOTFOUND; +static int didUsbInit = 0; + + if(!didUsbInit){ + usb_init(); + didUsbInit = 1; + } + usb_find_busses(); + usb_find_devices(); + for(bus=usb_get_busses(); bus; bus=bus->next){ + for(dev=bus->devices; dev; dev=dev->next){ + if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product){ + char string[256]; + int len; + handle = usb_open(dev); /* we need to open the device in order to query strings */ + if(!handle){ + errorCode = USBOPEN_ERR_ACCESS; + fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror()); + continue; + } + if(vendorName == NULL && productName == NULL){ /* name does not matter */ + break; + } + /* now check whether the names match: */ + len = usbhidGetStringAscii(handle, dev->descriptor.iManufacturer, string, sizeof(string)); + if(len < 0){ + errorCode = USBOPEN_ERR_IO; + fprintf(stderr, "Warning: cannot query manufacturer for device: %s\n", usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* fprintf(stderr, "seen device from vendor ->%s<-\n", string); */ + if(strcmp(string, vendorName) == 0){ + len = usbhidGetStringAscii(handle, dev->descriptor.iProduct, string, sizeof(string)); + if(len < 0){ + errorCode = USBOPEN_ERR_IO; + fprintf(stderr, "Warning: cannot query product for device: %s\n", usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* fprintf(stderr, "seen product ->%s<-\n", string); */ + if(strcmp(string, productName) == 0) + break; + } + } + } + usb_close(handle); + handle = NULL; + } + } + if(handle) + break; + } + if(handle != NULL){ + errorCode = 0; + *device = (void *)handle; + usesReportIDs = _usesReportIDs; + } + return errorCode; +} + +/* ------------------------------------------------------------------------- */ + +void usbhidCloseDevice(usbDevice_t *device) +{ + if(device != NULL) + usb_close((void *)device); +} + +/* ------------------------------------------------------------------------- */ + +int usbhidSetReport(usbDevice_t *device, char *buffer, int len) +{ +int bytesSent; + + if(!usesReportIDs){ + buffer++; /* skip dummy report ID */ + len--; + } + bytesSent = usb_control_msg((void *)device, USB_TYPE_CLASS | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USBRQ_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8 | (buffer[0] & 0xff), 0, buffer, len, 5000); + if(bytesSent != len){ + if(bytesSent < 0) + fprintf(stderr, "Error sending message: %s\n", usb_strerror()); + return USBOPEN_ERR_IO; + } + return 0; +} + +/* ------------------------------------------------------------------------- */ + +int usbhidGetReport(usbDevice_t *device, int reportNumber, char *buffer, int *len) +{ +int bytesReceived, maxLen = *len; + + if(!usesReportIDs){ + buffer++; /* make room for dummy report ID */ + maxLen--; + } + bytesReceived = usb_control_msg((void *)device, USB_TYPE_CLASS | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8 | reportNumber, 0, buffer, maxLen, 5000); + if(bytesReceived < 0){ + fprintf(stderr, "Error sending message: %s\n", usb_strerror()); + return USBOPEN_ERR_IO; + } + *len = bytesReceived; + if(!usesReportIDs){ + buffer[-1] = reportNumber; /* add dummy report ID */ + (*len)++; + } + return 0; +} + +/* ######################################################################## */ +#endif /* defined WIN32 ################################################### */ +/* ######################################################################## */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hiddata.h b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hiddata.h new file mode 100644 index 0000000..fce0743 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hiddata.h @@ -0,0 +1,71 @@ +/* Name: hiddata.h + * Author: Christian Starkjohann + * Creation Date: 2008-04-11 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: hiddata.h 692 2008-11-07 15:07:40Z cs $ + */ + +#ifndef __HIDDATA_H_INCLUDED__ +#define __HIDDATA_H_INCLUDED__ + +/* +General Description: +This module implements an abstraction layer for data transfer over HID feature +requests. The implementation uses native Windows functions on Windows so that +no driver installation is required and libusb on Unix. You must link the +appropriate libraries in either case: "-lhid -lusb -lsetupapi" on Windows and +`libusb-config --libs` on Unix. +*/ + +/* ------------------------------------------------------------------------ */ + +#define USBOPEN_SUCCESS 0 /* no error */ +#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ +#define USBOPEN_ERR_IO 2 /* I/O error */ +#define USBOPEN_ERR_NOTFOUND 3 /* device not found */ + +/* ------------------------------------------------------------------------ */ + +typedef struct usbDevice usbDevice_t; +/* Opaque data type representing the USB device. This can be a Windows handle + * or a libusb handle, depending on the backend implementation. + */ + +/* ------------------------------------------------------------------------ */ + +int usbhidOpenDevice(usbDevice_t **device, int vendorID, char *vendorName, int productID, char *productName, int usesReportIDs); +/* This function opens a USB device. 'vendorID' and 'productID' are the numeric + * Vendor-ID and Product-ID of the device we want to open. If 'vendorName' and + * 'productName' are both not NULL, only devices with matching manufacturer- + * and product name strings are accepted. If the device uses report IDs, + * 'usesReportIDs' must be set to a non-zero value. + * Returns: If a matching device has been found, USBOPEN_SUCCESS is returned + * and '*device' is set to an opaque pointer representing the device. The + * device must be closed with usbhidCloseDevice(). If the device has not been + * found or opening failed, an error code is returned. + */ +void usbhidCloseDevice(usbDevice_t *device); +/* Every device opened with usbhidOpenDevice() must be closed with this function. + */ +int usbhidSetReport(usbDevice_t *device, char *buffer, int len); +/* This function sends a feature report to the device. The report ID must be + * in the first byte of buffer and the length 'len' of the report is specified + * including this report ID. If no report IDs are used, buffer[0] must be set + * to 0 (dummy report ID). + * Returns: 0 on success, an error code otherwise. + */ +int usbhidGetReport(usbDevice_t *device, int reportID, char *buffer, int *len); +/* This function obtains a feature report from the device. The requested + * report-ID is passed in 'reportID'. The caller must pass a buffer of the size + * of the expected report in 'buffer' and initialize the variable pointed to by + * 'len' to the total size of this buffer. Upon successful return, the report + * (prefixed with the report-ID) is in 'buffer' and the actual length of the + * report is returned in '*len'. + * Returns: 0 on success, an error code otherwise. + */ + +/* ------------------------------------------------------------------------ */ + +#endif /* __HIDDATA_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hidsdi.h b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hidsdi.h new file mode 100644 index 0000000..a549ab1 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hidsdi.h @@ -0,0 +1,49 @@ +/* Name: hidsdi.h + * Author: Christian Starkjohann + * Creation Date: 2006-02-02 + * Tabsize: 4 + * Copyright: (c) 2006-2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: hidsdi.h 692 2008-11-07 15:07:40Z cs $ + */ + +/* +General Description +This file is a replacement for hidsdi.h from the Windows DDK. It defines some +of the types and function prototypes of this header for our project. If you +have the Windows DDK version of this file or a version shipped with MinGW, use +that instead. +*/ + +#ifndef _HIDSDI_H +#define _HIDSDI_H + +#include + +#include +#include + +typedef struct{ + ULONG Size; + USHORT VendorID; + USHORT ProductID; + USHORT VersionNumber; +}HIDD_ATTRIBUTES; + +void __stdcall HidD_GetHidGuid(OUT LPGUID hidGuid); + +BOOLEAN __stdcall HidD_GetAttributes(IN HANDLE device, OUT HIDD_ATTRIBUTES *attributes); + +BOOLEAN __stdcall HidD_GetManufacturerString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); +BOOLEAN __stdcall HidD_GetProductString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); +BOOLEAN __stdcall HidD_GetSerialNumberString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); + +BOOLEAN __stdcall HidD_GetFeature(IN HANDLE device, OUT void *reportBuffer, IN ULONG bufferLen); +BOOLEAN __stdcall HidD_SetFeature(IN HANDLE device, IN void *reportBuffer, IN ULONG bufferLen); + +BOOLEAN __stdcall HidD_GetNumInputBuffers(IN HANDLE device, OUT ULONG *numBuffers); +BOOLEAN __stdcall HidD_SetNumInputBuffers(IN HANDLE device, OUT ULONG numBuffers); + +#include + +#endif diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hidtool.c b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hidtool.c new file mode 100644 index 0000000..9b581cd --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/commandline/hidtool.c @@ -0,0 +1,127 @@ +/* Name: hidtool.c + * Project: hid-data example + * Author: Christian Starkjohann + * Creation Date: 2008-04-11 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: hidtool.c 723 2009-03-16 19:04:32Z cs $ + */ + +#include +#include +#include +#include "hiddata.h" +#include "../firmware/usbconfig.h" /* for device VID, PID, vendor name and product name */ + +/* ------------------------------------------------------------------------- */ + +static char *usbErrorMessage(int errCode) +{ +static char buffer[80]; + + switch(errCode){ + case USBOPEN_ERR_ACCESS: return "Access to device denied"; + case USBOPEN_ERR_NOTFOUND: return "The specified device was not found"; + case USBOPEN_ERR_IO: return "Communication error with device"; + default: + sprintf(buffer, "Unknown USB error %d", errCode); + return buffer; + } + return NULL; /* not reached */ +} + +static usbDevice_t *openDevice(void) +{ +usbDevice_t *dev = NULL; +unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID}; +char vendorName[] = {USB_CFG_VENDOR_NAME, 0}, productName[] = {USB_CFG_DEVICE_NAME, 0}; +int vid = rawVid[0] + 256 * rawVid[1]; +int pid = rawPid[0] + 256 * rawPid[1]; +int err; + + if((err = usbhidOpenDevice(&dev, vid, vendorName, pid, productName, 0)) != 0){ + fprintf(stderr, "error finding %s: %s\n", productName, usbErrorMessage(err)); + return NULL; + } + return dev; +} + +/* ------------------------------------------------------------------------- */ + +static void hexdump(char *buffer, int len) +{ +int i; +FILE *fp = stdout; + + for(i = 0; i < len; i++){ + if(i != 0){ + if(i % 16 == 0){ + fprintf(fp, "\n"); + }else{ + fprintf(fp, " "); + } + } + fprintf(fp, "0x%02x", buffer[i] & 0xff); + } + if(i != 0) + fprintf(fp, "\n"); +} + +static int hexread(char *buffer, char *string, int buflen) +{ +char *s; +int pos = 0; + + while((s = strtok(string, ", ")) != NULL && pos < buflen){ + string = NULL; + buffer[pos++] = (char)strtol(s, NULL, 0); + } + return pos; +} + +/* ------------------------------------------------------------------------- */ + +static void usage(char *myName) +{ + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s read\n", myName); + fprintf(stderr, " %s write \n", myName); +} + +int main(int argc, char **argv) +{ +usbDevice_t *dev; +char buffer[129]; /* room for dummy report ID */ +int err; + + if(argc < 2){ + usage(argv[0]); + exit(1); + } + if((dev = openDevice()) == NULL) + exit(1); + if(strcasecmp(argv[1], "read") == 0){ + int len = sizeof(buffer); + if((err = usbhidGetReport(dev, 0, buffer, &len)) != 0){ + fprintf(stderr, "error reading data: %s\n", usbErrorMessage(err)); + }else{ + hexdump(buffer + 1, sizeof(buffer) - 1); + } + }else if(strcasecmp(argv[1], "write") == 0){ + int i, pos; + memset(buffer, 0, sizeof(buffer)); + for(pos = 1, i = 2; i < argc && pos < sizeof(buffer); i++){ + pos += hexread(buffer + pos, argv[i], sizeof(buffer) - pos); + } + if((err = usbhidSetReport(dev, buffer, sizeof(buffer))) != 0) /* add a dummy report ID */ + fprintf(stderr, "error writing data: %s\n", usbErrorMessage(err)); + }else{ + usage(argv[0]); + exit(1); + } + usbhidCloseDevice(dev); + return 0; +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/Makefile b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/Makefile new file mode 100644 index 0000000..5876ab0 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/Makefile @@ -0,0 +1,164 @@ +# Name: Makefile +# Project: hid-data example +# Author: Christian Starkjohann +# Creation Date: 2008-04-07 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + +DEVICE = atmega168 +F_CPU = 16000000 # in Hz +FUSE_L = # see below for fuse values for particular devices +FUSE_H = +AVRDUDE = avrdude -c usbasp -p $(DEVICE) # edit this line for your programmer + +CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 +OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o + +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) + +############################################################################## +# Fuse values for particular devices +############################################################################## +# If your device is not listed here, go to +# http://palmavr.sourceforge.net/cgi-bin/fc.cgi +# and choose options for external crystal clock and no clock divider +# +################################## ATMega8 ################################## +# ATMega8 FUSE_L (Fuse low byte): +# 0x9f = 1 0 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ BODEN (BrownOut Detector enabled) +# +-------------------- BODLEVEL (2.7V) +# ATMega8 FUSE_H (Fuse high byte): +# 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) +# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 +# | | | | | +-------- BOOTSZ1 +# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) +# | | | +-------------- CKOPT (full output swing) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ WDTON (WDT not always on) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATMega48/88/168 ############################## +# ATMega*8 FUSE_L (Fuse low byte): +# 0xdf = 1 1 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ CKOUT (if 0: Clock output enabled) +# +-------------------- CKDIV8 (if 0: divide by 8) +# ATMega*8 FUSE_H (Fuse high byte): +# 0xde = 1 1 0 1 1 1 1 0 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V) +# | | | | + --------- EESAVE (preserve EEPROM over chip erase) +# | | | +-------------- WDTON (if 0: watchdog always on) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATTiny25/45/85 ############################### +# ATMega*5 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATMega*5 FUSE_H (Fuse high byte): +# 0xdd = 1 1 0 1 1 1 0 1 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (disable external reset -> enabled) +# +################################ ATTiny2313 ################################# +# ATTiny2313 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATTiny2313 FUSE_H (Fuse high byte): +# 0xdb = 1 1 0 1 1 0 1 1 +# ^ ^ ^ ^ \-+-/ ^ +# | | | | | +---- RSTDISBL (disable external reset -> enabled) +# | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# +-------------------- DWEN (debug wire enable) + + +# symbolic targets: +help: + @echo "This Makefile has no default rule. Use one of the following:" + @echo "make hex ....... to build main.hex" + @echo "make program ... to flash fuses and firmware" + @echo "make fuse ...... to flash the fuses" + @echo "make flash ..... to flash the firmware (use this on metaboard)" + @echo "make clean ..... to delete objects and hex file" + +hex: main.hex + +program: flash fuse + +# rule for programming fuse bits: +fuse: + @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \ + { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; } + $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m + +# rule for uploading firmware: +flash: main.hex + $(AVRDUDE) -U flash:w:main.hex:i + +# rule for deleting dependent files (those which can be built by Make): +clean: + rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s + +# Generic rule for compiling C files: +.c.o: + $(COMPILE) -c $< -o $@ + +# Generic rule for assembling Assembler source files: +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +# Generic rule for compiling C to assembler, used for debugging only. +.c.s: + $(COMPILE) -S $< -o $@ + +# file targets: + +# Since we don't want to ship the driver multipe times, we copy it into this project: +usbdrv: + cp -r ../../../usbdrv . + +main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it + $(COMPILE) -o main.elf $(OBJECTS) + +main.hex: main.elf + rm -f main.hex main.eep.hex + avr-objcopy -j .text -j .data -O ihex main.elf main.hex + avr-size main.hex + +# debugging targets: + +disasm: main.elf + avr-objdump -d main.elf + +cpp: + $(COMPILE) -E main.c diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/main.c b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/main.c new file mode 100644 index 0000000..aa4bf1d --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/main.c @@ -0,0 +1,141 @@ +/* Name: main.c + * Project: hid-data, example how to use HID for data transfer + * Author: Christian Starkjohann + * Creation Date: 2008-04-11 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: main.c 777 2010-01-15 18:34:48Z cs $ + */ + +/* +This example should run on most AVRs with only little changes. No special +hardware resources except INT0 are used. You may have to change usbconfig.h for +different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or +at least be connected to INT0 as well. +*/ + +#include +#include +#include /* for sei() */ +#include /* for _delay_ms() */ +#include + +#include /* required by usbdrv.h */ +#include "usbdrv.h" +#include "oddebug.h" /* This is also an example for using debug macros */ + +/* ------------------------------------------------------------------------- */ +/* ----------------------------- USB interface ----------------------------- */ +/* ------------------------------------------------------------------------- */ + +PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */ + 0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop) + 0x09, 0x01, // USAGE (Vendor Usage 1) + 0xa1, 0x01, // COLLECTION (Application) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x80, // REPORT_COUNT (128) + 0x09, 0x00, // USAGE (Undefined) + 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf) + 0xc0 // END_COLLECTION +}; +/* Since we define only one feature report, we don't use report-IDs (which + * would be the first byte of the report). The entire report consists of 128 + * opaque data bytes. + */ + +/* The following variables store the status of the current data transfer */ +static uchar currentAddress; +static uchar bytesRemaining; + +/* ------------------------------------------------------------------------- */ + +/* usbFunctionRead() is called when the host requests a chunk of data from + * the device. For more information see the documentation in usbdrv/usbdrv.h. + */ +uchar usbFunctionRead(uchar *data, uchar len) +{ + if(len > bytesRemaining) + len = bytesRemaining; + eeprom_read_block(data, (uchar *)0 + currentAddress, len); + currentAddress += len; + bytesRemaining -= len; + return len; +} + +/* usbFunctionWrite() is called when the host sends a chunk of data to the + * device. For more information see the documentation in usbdrv/usbdrv.h. + */ +uchar usbFunctionWrite(uchar *data, uchar len) +{ + if(bytesRemaining == 0) + return 1; /* end of transfer */ + if(len > bytesRemaining) + len = bytesRemaining; + eeprom_write_block(data, (uchar *)0 + currentAddress, len); + currentAddress += len; + bytesRemaining -= len; + return bytesRemaining == 0; /* return 1 if this was the last chunk */ +} + +/* ------------------------------------------------------------------------- */ + +usbMsgLen_t usbFunctionSetup(uchar data[8]) +{ +usbRequest_t *rq = (void *)data; + + if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* HID class request */ + if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */ + /* since we have only one report type, we can ignore the report-ID */ + bytesRemaining = 128; + currentAddress = 0; + return USB_NO_MSG; /* use usbFunctionRead() to obtain data */ + }else if(rq->bRequest == USBRQ_HID_SET_REPORT){ + /* since we have only one report type, we can ignore the report-ID */ + bytesRemaining = 128; + currentAddress = 0; + return USB_NO_MSG; /* use usbFunctionWrite() to receive data from host */ + } + }else{ + /* ignore vendor type requests, we don't use any */ + } + return 0; +} + +/* ------------------------------------------------------------------------- */ + +int main(void) +{ +uchar i; + + wdt_enable(WDTO_1S); + /* Even if you don't use the watchdog, turn it off here. On newer devices, + * the status of the watchdog (on/off, period) is PRESERVED OVER RESET! + */ + /* RESET status: all port bits are inputs without pull-up. + * That's the way we need D+ and D-. Therefore we don't need any + * additional hardware initialization. + */ + odDebugInit(); + DBG1(0x00, 0, 0); /* debug output: main starts */ + usbInit(); + usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ + i = 0; + while(--i){ /* fake USB disconnect for > 250 ms */ + wdt_reset(); + _delay_ms(1); + } + usbDeviceConnect(); + sei(); + DBG1(0x01, 0, 0); /* debug output: main loop starts */ + for(;;){ /* main event loop */ + DBG1(0x02, 0, 0); /* debug output: main loop iterates */ + wdt_reset(); + usbPoll(); + } + return 0; +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/usbconfig.h b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/usbconfig.h new file mode 100644 index 0000000..4831281 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-data/firmware/usbconfig.h @@ -0,0 +1,373 @@ +/* Name: usbconfig.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2005-04-01 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ + */ + +#ifndef __usbconfig_h_included__ +#define __usbconfig_h_included__ + +/* +General Description: +This file is an example configuration (with inline documentation) for the USB +driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is +also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may +wire the lines to any other port, as long as D+ is also wired to INT0 (or any +other hardware interrupt, as long as it is the highest level interrupt, see +section at the end of this file). +*/ + +/* ---------------------------- Hardware Config ---------------------------- */ + +#define USB_CFG_IOPORTNAME D +/* This is the port where the USB bus is connected. When you configure it to + * "B", the registers PORTB, PINB and DDRB will be used. + */ +#define USB_CFG_DMINUS_BIT 4 +/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. + * This may be any bit in the port. + */ +#define USB_CFG_DPLUS_BIT 2 +/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. + * This may be any bit in the port. Please note that D+ must also be connected + * to interrupt pin INT0! [You can also use other interrupts, see section + * "Optional MCU Description" below, or you can connect D- to the interrupt, as + * it is required if you use the USB_COUNT_SOF feature. If you use D- for the + * interrupt, the USB interrupt will also be triggered at Start-Of-Frame + * markers every millisecond.] + */ +#define USB_CFG_CLOCK_KHZ (F_CPU/1000) +/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, + * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code + * require no crystal, they tolerate +/- 1% deviation from the nominal + * frequency. All other rates require a precision of 2000 ppm and thus a + * crystal! + * Since F_CPU should be defined to your actual clock rate anyway, you should + * not need to modify this setting. + */ +#define USB_CFG_CHECK_CRC 0 +/* Define this to 1 if you want that the driver checks integrity of incoming + * data packets (CRC checks). CRC checks cost quite a bit of code size and are + * currently only available for 18 MHz crystal clock. You must choose + * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. + */ + +/* ----------------------- Optional Hardware Config ------------------------ */ + +/* #define USB_CFG_PULLUP_IOPORTNAME D */ +/* If you connect the 1.5k pullup resistor from D- to a port pin instead of + * V+, you can connect and disconnect the device from firmware by calling + * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). + * This constant defines the port on which the pullup resistor is connected. + */ +/* #define USB_CFG_PULLUP_BIT 4 */ +/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined + * above) where the 1.5k pullup resistor is connected. See description + * above for details. + */ + +/* --------------------------- Functional Range ---------------------------- */ + +#define USB_CFG_HAVE_INTRIN_ENDPOINT 1 +/* Define this to 1 if you want to compile a version with two endpoints: The + * default control endpoint 0 and an interrupt-in endpoint (any other endpoint + * number). + */ +#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 +/* Define this to 1 if you want to compile a version with three endpoints: The + * default control endpoint 0, an interrupt-in endpoint 3 (or the number + * configured below) and a catch-all default interrupt-in endpoint as above. + * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. + */ +#define USB_CFG_EP3_NUMBER 3 +/* If the so-called endpoint 3 is used, it can now be configured to any other + * endpoint number (except 0) with this macro. Default if undefined is 3. + */ +/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ +/* The above macro defines the startup condition for data toggling on the + * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. + * Since the token is toggled BEFORE sending any data, the first packet is + * sent with the oposite value of this configuration! + */ +#define USB_CFG_IMPLEMENT_HALT 0 +/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature + * for endpoint 1 (interrupt endpoint). Although you may not need this feature, + * it is required by the standard. We have made it a config option because it + * bloats the code considerably. + */ +#define USB_CFG_SUPPRESS_INTR_CODE 0 +/* Define this to 1 if you want to declare interrupt-in endpoints, but don't + * want to send any data over them. If this macro is defined to 1, functions + * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if + * you need the interrupt-in endpoints in order to comply to an interface + * (e.g. HID), but never want to send any data. This option saves a couple + * of bytes in flash memory and the transmit buffers in RAM. + */ +#define USB_CFG_INTR_POLL_INTERVAL 100 +/* If you compile a version with endpoint 1 (interrupt-in), this is the poll + * interval. The value is in milliseconds and must not be less than 10 ms for + * low speed devices. + */ +#define USB_CFG_IS_SELF_POWERED 0 +/* Define this to 1 if the device has its own power supply. Set it to 0 if the + * device is powered from the USB bus. + */ +#define USB_CFG_MAX_BUS_POWER 20 +/* Set this variable to the maximum USB bus power consumption of your device. + * The value is in milliamperes. [It will be divided by two since USB + * communicates power requirements in units of 2 mA.] + */ +#define USB_CFG_IMPLEMENT_FN_WRITE 1 +/* Set this to 1 if you want usbFunctionWrite() to be called for control-out + * transfers. Set it to 0 if you don't need it and want to save a couple of + * bytes. + */ +#define USB_CFG_IMPLEMENT_FN_READ 1 +/* Set this to 1 if you need to send control replies which are generated + * "on the fly" when usbFunctionRead() is called. If you only want to send + * data from a static buffer, set it to 0 and return the data from + * usbFunctionSetup(). This saves a couple of bytes. + */ +#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 +/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. + * You must implement the function usbFunctionWriteOut() which receives all + * interrupt/bulk data sent to any endpoint other than 0. The endpoint number + * can be found in 'usbRxToken'. + */ +#define USB_CFG_HAVE_FLOWCONTROL 0 +/* Define this to 1 if you want flowcontrol over USB data. See the definition + * of the macros usbDisableAllRequests() and usbEnableAllRequests() in + * usbdrv.h. + */ +#define USB_CFG_DRIVER_FLASH_PAGE 0 +/* If the device has more than 64 kBytes of flash, define this to the 64 k page + * where the driver's constants (descriptors) are located. Or in other words: + * Define this to 1 for boot loaders on the ATMega128. + */ +#define USB_CFG_LONG_TRANSFERS 0 +/* Define this to 1 if you want to send/receive blocks of more than 254 bytes + * in a single control-in or control-out transfer. Note that the capability + * for long transfers increases the driver size. + */ +/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ +/* This macro is a hook if you want to do unconventional things. If it is + * defined, it's inserted at the beginning of received message processing. + * If you eat the received message and don't want default processing to + * proceed, do a return after doing your things. One possible application + * (besides debugging) is to flash a status LED on each packet. + */ +/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ +/* This macro is a hook if you need to know when an USB RESET occurs. It has + * one parameter which distinguishes between the start of RESET state and its + * end. + */ +/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ +/* This macro (if defined) is executed when a USB SET_ADDRESS request was + * received. + */ +#define USB_COUNT_SOF 0 +/* define this macro to 1 if you need the global variable "usbSofCount" which + * counts SOF packets. This feature requires that the hardware interrupt is + * connected to D- instead of D+. + */ +/* #ifdef __ASSEMBLER__ + * macro myAssemblerMacro + * in YL, TCNT0 + * sts timer0Snapshot, YL + * endm + * #endif + * #define USB_SOF_HOOK myAssemblerMacro + * This macro (if defined) is executed in the assembler module when a + * Start Of Frame condition is detected. It is recommended to define it to + * the name of an assembler macro which is defined here as well so that more + * than one assembler instruction can be used. The macro may use the register + * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages + * immediately after an SOF pulse may be lost and must be retried by the host. + * What can you do with this hook? Since the SOF signal occurs exactly every + * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in + * designs running on the internal RC oscillator. + * Please note that Start Of Frame detection works only if D- is wired to the + * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! + */ +#define USB_CFG_CHECK_DATA_TOGGLING 0 +/* define this macro to 1 if you want to filter out duplicate data packets + * sent by the host. Duplicates occur only as a consequence of communication + * errors, when the host does not receive an ACK. Please note that you need to + * implement the filtering yourself in usbFunctionWriteOut() and + * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable + * for each control- and out-endpoint to check for duplicate packets. + */ +#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 +/* define this macro to 1 if you want the function usbMeasureFrameLength() + * compiled in. This function can be used to calibrate the AVR's RC oscillator. + */ +#define USB_USE_FAST_CRC 0 +/* The assembler module has two implementations for the CRC algorithm. One is + * faster, the other is smaller. This CRC routine is only used for transmitted + * messages where timing is not critical. The faster routine needs 31 cycles + * per byte while the smaller one needs 61 to 69 cycles. The faster routine + * may be worth the 32 bytes bigger code size if you transmit lots of data and + * run the AVR close to its limit. + */ + +/* -------------------------- Device Description --------------------------- */ + +#define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ +/* USB vendor ID for the device, low byte first. If you have registered your + * own Vendor ID, define it here. Otherwise you may use one of obdev's free + * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_ID 0xdf, 0x05 /* obdev's shared PID for HIDs */ +/* This is the ID of the product, low byte first. It is interpreted in the + * scope of the vendor ID. If you have registered your own VID with usb.org + * or if you have licensed a PID from somebody else, define it here. Otherwise + * you may use one of obdev's free shared VID/PID pairs. See the file + * USB-IDs-for-free.txt for details! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +/* Version number of the device: Minor number first, then major number. + */ +#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' +#define USB_CFG_VENDOR_NAME_LEN 8 +/* These two values define the vendor name returned by the USB device. The name + * must be given as a list of characters under single quotes. The characters + * are interpreted as Unicode (UTF-16) entities. + * If you don't want a vendor name string, undefine these macros. + * ALWAYS define a vendor name containing your Internet domain name if you use + * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for + * details. + */ +#define USB_CFG_DEVICE_NAME 'D', 'a', 't', 'a', 'S', 't', 'o', 'r', 'e' +#define USB_CFG_DEVICE_NAME_LEN 9 +/* Same as above for the device name. If you don't want a device name, undefine + * the macros. See the file USB-IDs-for-free.txt before you assign a name if + * you use a shared VID/PID. + */ +/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ +/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ +/* Same as above for the serial number. If you don't want a serial number, + * undefine the macros. + * It may be useful to provide the serial number through other means than at + * compile time. See the section about descriptor properties below for how + * to fine tune control over USB descriptors such as the string descriptor + * for the serial number. + */ +#define USB_CFG_DEVICE_CLASS 0 +#define USB_CFG_DEVICE_SUBCLASS 0 +/* See USB specification if you want to conform to an existing device class. + * Class 0xff is "vendor specific". + */ +#define USB_CFG_INTERFACE_CLASS 3 +#define USB_CFG_INTERFACE_SUBCLASS 0 +#define USB_CFG_INTERFACE_PROTOCOL 0 +/* See USB specification if you want to conform to an existing device class or + * protocol. The following classes must be set at interface level: + * HID class is 3, no subclass and protocol required (but may be useful!) + * CDC class is 2, use subclass 2 and protocol 1 for ACM + */ +#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 22 +/* Define this to the length of the HID report descriptor, if you implement + * an HID device. Otherwise don't define it or define it to 0. + * If you use this define, you must add a PROGMEM character array named + * "usbHidReportDescriptor" to your code which contains the report descriptor. + * Don't forget to keep the array and this define in sync! + */ + +/* #define USB_PUBLIC static */ +/* Use the define above if you #include usbdrv.c instead of linking against it. + * This technique saves a couple of bytes in flash memory. + */ + +/* ------------------- Fine Control over USB Descriptors ------------------- */ +/* If you don't want to use the driver's default USB descriptors, you can + * provide our own. These can be provided as (1) fixed length static data in + * flash memory, (2) fixed length static data in RAM or (3) dynamically at + * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more + * information about this function. + * Descriptor handling is configured through the descriptor's properties. If + * no properties are defined or if they are 0, the default descriptor is used. + * Possible properties are: + * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched + * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is + * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if + * you want RAM pointers. + * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found + * in static memory is in RAM, not in flash memory. + * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), + * the driver must know the descriptor's length. The descriptor itself is + * found at the address of a well known identifier (see below). + * List of static descriptor names (must be declared PROGMEM if in flash): + * char usbDescriptorDevice[]; + * char usbDescriptorConfiguration[]; + * char usbDescriptorHidReport[]; + * char usbDescriptorString0[]; + * int usbDescriptorStringVendor[]; + * int usbDescriptorStringDevice[]; + * int usbDescriptorStringSerialNumber[]; + * Other descriptors can't be provided statically, they must be provided + * dynamically at runtime. + * + * Descriptor properties are or-ed or added together, e.g.: + * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) + * + * The following descriptors are defined: + * USB_CFG_DESCR_PROPS_DEVICE + * USB_CFG_DESCR_PROPS_CONFIGURATION + * USB_CFG_DESCR_PROPS_STRINGS + * USB_CFG_DESCR_PROPS_STRING_0 + * USB_CFG_DESCR_PROPS_STRING_VENDOR + * USB_CFG_DESCR_PROPS_STRING_PRODUCT + * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER + * USB_CFG_DESCR_PROPS_HID + * USB_CFG_DESCR_PROPS_HID_REPORT + * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) + * + * Note about string descriptors: String descriptors are not just strings, they + * are Unicode strings prefixed with a 2 byte header. Example: + * int serialNumberDescriptor[] = { + * USB_STRING_DESCRIPTOR_HEADER(6), + * 'S', 'e', 'r', 'i', 'a', 'l' + * }; + */ + +#define USB_CFG_DESCR_PROPS_DEVICE 0 +#define USB_CFG_DESCR_PROPS_CONFIGURATION 0 +#define USB_CFG_DESCR_PROPS_STRINGS 0 +#define USB_CFG_DESCR_PROPS_STRING_0 0 +#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 +#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 +#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 +#define USB_CFG_DESCR_PROPS_HID 0 +#define USB_CFG_DESCR_PROPS_HID_REPORT 0 +#define USB_CFG_DESCR_PROPS_UNKNOWN 0 + +/* ----------------------- Optional MCU Description ------------------------ */ + +/* The following configurations have working defaults in usbdrv.h. You + * usually don't need to set them explicitly. Only if you want to run + * the driver on a device which is not yet supported or with a compiler + * which is not fully supported (such as IAR C) or if you use a differnt + * interrupt than INT0, you may have to define some of these. + */ +/* #define USB_INTR_CFG MCUCR */ +/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ +/* #define USB_INTR_CFG_CLR 0 */ +/* #define USB_INTR_ENABLE GIMSK */ +/* #define USB_INTR_ENABLE_BIT INT0 */ +/* #define USB_INTR_PENDING GIFR */ +/* #define USB_INTR_PENDING_BIT INTF0 */ +/* #define USB_INTR_VECTOR INT0_vect */ + +#endif /* __usbconfig_h_included__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/Readme.txt b/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/Readme.txt new file mode 100644 index 0000000..e0c8142 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/Readme.txt @@ -0,0 +1,48 @@ +This is the Readme file for hid-mouse, an example of a USB mouse device. In +order to have as little dependencies on hardware and architecture as +possible, mouse movements are computed internally so that the mouse pointer +moves in a circle. + + +WHAT IS DEMONSTRATED? +===================== +This example demonstrates how HID class devices are implemented. The example +is kept as simple as possible, except the report descriptor which is taken +from a real-world mouse. + +It does NOT include a host side driver because all modern operating systems +include one. It does NOT implement USBRQ_HID_SET_REPORT and report-IDs. See +the "hid-data" example for this topic. It does NOT implement any special +features such as suspend mode etc. + + +PREREQUISITES +============= +Target hardware: You need an AVR based circuit based on one of the examples +(see the "circuits" directory at the top level of this package), e.g. the +metaboard (http://www.obdev.at/goto.php?t=metaboard). + +AVR development environment: You need the gcc tool chain for the AVR, see +the Prerequisites section in the top level Readme file for how to obtain it. + + +BUILDING THE FIRMWARE +===================== +Change to the "firmware" directory and modify Makefile according to your +architecture (CPU clock, target device, fuse values) and ISP programmer. Then +edit usbconfig.h according to your pin assignments for D+ and D-. The default +settings are for the metaboard hardware. + +Type "make hex" to build main.hex, then "make flash" to upload the firmware +to the device. Don't forget to run "make fuse" once to program the fuses. If +you use a prototyping board with boot loader, follow the instructions of the +boot loader instead. + +Please note that the first "make hex" copies the driver from the top level +into the firmware directory. If you use a different build system than our +Makefile, you must copy the driver by hand. + + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/Makefile b/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/Makefile new file mode 100644 index 0000000..22b1227 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/Makefile @@ -0,0 +1,164 @@ +# Name: Makefile +# Project: hid-mouse example +# Author: Christian Starkjohann +# Creation Date: 2008-04-07 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + +DEVICE = atmega168 +F_CPU = 16000000 # in Hz +FUSE_L = # see below for fuse values for particular devices +FUSE_H = +AVRDUDE = avrdude -c usbasp -p $(DEVICE) # edit this line for your programmer + +CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 +OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o + +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) + +############################################################################## +# Fuse values for particular devices +############################################################################## +# If your device is not listed here, go to +# http://palmavr.sourceforge.net/cgi-bin/fc.cgi +# and choose options for external crystal clock and no clock divider +# +################################## ATMega8 ################################## +# ATMega8 FUSE_L (Fuse low byte): +# 0x9f = 1 0 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ BODEN (BrownOut Detector enabled) +# +-------------------- BODLEVEL (2.7V) +# ATMega8 FUSE_H (Fuse high byte): +# 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) +# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 +# | | | | | +-------- BOOTSZ1 +# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) +# | | | +-------------- CKOPT (full output swing) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ WDTON (WDT not always on) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATMega48/88/168 ############################## +# ATMega*8 FUSE_L (Fuse low byte): +# 0xdf = 1 1 0 1 1 1 1 1 +# ^ ^ \ / \--+--/ +# | | | +------- CKSEL 3..0 (external >8M crystal) +# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) +# | +------------------ CKOUT (if 0: Clock output enabled) +# +-------------------- CKDIV8 (if 0: divide by 8) +# ATMega*8 FUSE_H (Fuse high byte): +# 0xde = 1 1 0 1 1 1 1 0 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V) +# | | | | + --------- EESAVE (preserve EEPROM over chip erase) +# | | | +-------------- WDTON (if 0: watchdog always on) +# | | +---------------- SPIEN (allow serial programming) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (reset pin is enabled) +# +############################## ATTiny25/45/85 ############################### +# ATMega*5 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATMega*5 FUSE_H (Fuse high byte): +# 0xdd = 1 1 0 1 1 1 0 1 +# ^ ^ ^ ^ ^ \-+-/ +# | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ DWEN (debug wire enable) +# +-------------------- RSTDISBL (disable external reset -> enabled) +# +################################ ATTiny2313 ################################# +# ATTiny2313 FUSE_L (Fuse low byte): +# 0xef = 1 1 1 0 1 1 1 1 +# ^ ^ \+/ \--+--/ +# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) +# | | +--------------- SUT 1..0 (BOD enabled, fast rising power) +# | +------------------ CKOUT (clock output on CKOUT pin -> disabled) +# +-------------------- CKDIV8 (divide clock by 8 -> don't divide) +# ATTiny2313 FUSE_H (Fuse high byte): +# 0xdb = 1 1 0 1 1 0 1 1 +# ^ ^ ^ ^ \-+-/ ^ +# | | | | | +---- RSTDISBL (disable external reset -> enabled) +# | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V) +# | | | +-------------- WDTON (watchdog timer always on -> disable) +# | | +---------------- SPIEN (enable serial programming -> enabled) +# | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved) +# +-------------------- DWEN (debug wire enable) + + +# symbolic targets: +help: + @echo "This Makefile has no default rule. Use one of the following:" + @echo "make hex ....... to build main.hex" + @echo "make program ... to flash fuses and firmware" + @echo "make fuse ...... to flash the fuses" + @echo "make flash ..... to flash the firmware (use this on metaboard)" + @echo "make clean ..... to delete objects and hex file" + +hex: main.hex + +program: flash fuse + +# rule for programming fuse bits: +fuse: + @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \ + { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; } + $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m + +# rule for uploading firmware: +flash: main.hex + $(AVRDUDE) -U flash:w:main.hex:i + +# rule for deleting dependent files (those which can be built by Make): +clean: + rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s + +# Generic rule for compiling C files: +.c.o: + $(COMPILE) -c $< -o $@ + +# Generic rule for assembling Assembler source files: +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +# Generic rule for compiling C to assembler, used for debugging only. +.c.s: + $(COMPILE) -S $< -o $@ + +# file targets: + +# Since we don't want to ship the driver multipe times, we copy it into this project: +usbdrv: + cp -r ../../../usbdrv . + +main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it + $(COMPILE) -o main.elf $(OBJECTS) + +main.hex: main.elf + rm -f main.hex main.eep.hex + avr-objcopy -j .text -j .data -O ihex main.elf main.hex + avr-size main.hex + +# debugging targets: + +disasm: main.elf + avr-objdump -d main.elf + +cpp: + $(COMPILE) -E main.c diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/main.c b/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/main.c new file mode 100644 index 0000000..747f643 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/main.c @@ -0,0 +1,164 @@ +/* Name: main.c + * Project: hid-mouse, a very simple HID example + * Author: Christian Starkjohann + * Creation Date: 2008-04-07 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ + */ + +/* +This example should run on most AVRs with only little changes. No special +hardware resources except INT0 are used. You may have to change usbconfig.h for +different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or +at least be connected to INT0 as well. + +We use VID/PID 0x046D/0xC00E which is taken from a Logitech mouse. Don't +publish any hardware using these IDs! This is for demonstration only! +*/ + +#include +#include +#include /* for sei() */ +#include /* for _delay_ms() */ + +#include /* required by usbdrv.h */ +#include "usbdrv.h" +#include "oddebug.h" /* This is also an example for using debug macros */ + +/* ------------------------------------------------------------------------- */ +/* ----------------------------- USB interface ----------------------------- */ +/* ------------------------------------------------------------------------- */ + +PROGMEM char usbHidReportDescriptor[52] = { /* USB report descriptor, size must match usbconfig.h */ + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + 0x09, 0x01, // USAGE (Pointer) + 0xA1, 0x00, // COLLECTION (Physical) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM + 0x29, 0x03, // USAGE_MAXIMUM + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x03, // REPORT_COUNT (3) + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x95, 0x01, // REPORT_COUNT (1) + 0x75, 0x05, // REPORT_SIZE (5) + 0x81, 0x03, // INPUT (Const,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7F, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x03, // REPORT_COUNT (3) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xC0, // END_COLLECTION + 0xC0, // END COLLECTION +}; +/* This is the same report descriptor as seen in a Logitech mouse. The data + * described by this descriptor consists of 4 bytes: + * . . . . . B2 B1 B0 .... one byte with mouse button states + * X7 X6 X5 X4 X3 X2 X1 X0 .... 8 bit signed relative coordinate x + * Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 .... 8 bit signed relative coordinate y + * W7 W6 W5 W4 W3 W2 W1 W0 .... 8 bit signed relative coordinate wheel + */ +typedef struct{ + uchar buttonMask; + char dx; + char dy; + char dWheel; +}report_t; + +static report_t reportBuffer; +static int sinus = 7 << 6, cosinus = 0; +static uchar idleRate; /* repeat rate for keyboards, never used for mice */ + + +/* The following function advances sin/cos by a fixed angle + * and stores the difference to the previous coordinates in the report + * descriptor. + * The algorithm is the simulation of a second order differential equation. + */ +static void advanceCircleByFixedAngle(void) +{ +char d; + +#define DIVIDE_BY_64(val) (val + (val > 0 ? 32 : -32)) >> 6 /* rounding divide */ + reportBuffer.dx = d = DIVIDE_BY_64(cosinus); + sinus += d; + reportBuffer.dy = d = DIVIDE_BY_64(sinus); + cosinus -= d; +} + +/* ------------------------------------------------------------------------- */ + +usbMsgLen_t usbFunctionSetup(uchar data[8]) +{ +usbRequest_t *rq = (void *)data; + + /* The following requests are never used. But since they are required by + * the specification, we implement them in this example. + */ + if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */ + DBG1(0x50, &rq->bRequest, 1); /* debug output: print our request */ + if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */ + /* we only have one report type, so don't look at wValue */ + usbMsgPtr = (void *)&reportBuffer; + return sizeof(reportBuffer); + }else if(rq->bRequest == USBRQ_HID_GET_IDLE){ + usbMsgPtr = &idleRate; + return 1; + }else if(rq->bRequest == USBRQ_HID_SET_IDLE){ + idleRate = rq->wValue.bytes[1]; + } + }else{ + /* no vendor specific requests implemented */ + } + return 0; /* default for not implemented requests: return no data back to host */ +} + +/* ------------------------------------------------------------------------- */ + +int __attribute__((noreturn)) main(void) +{ +uchar i; + + wdt_enable(WDTO_1S); + /* Even if you don't use the watchdog, turn it off here. On newer devices, + * the status of the watchdog (on/off, period) is PRESERVED OVER RESET! + */ + /* RESET status: all port bits are inputs without pull-up. + * That's the way we need D+ and D-. Therefore we don't need any + * additional hardware initialization. + */ + odDebugInit(); + DBG1(0x00, 0, 0); /* debug output: main starts */ + usbInit(); + usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ + i = 0; + while(--i){ /* fake USB disconnect for > 250 ms */ + wdt_reset(); + _delay_ms(1); + } + usbDeviceConnect(); + sei(); + DBG1(0x01, 0, 0); /* debug output: main loop starts */ + for(;;){ /* main event loop */ + DBG1(0x02, 0, 0); /* debug output: main loop iterates */ + wdt_reset(); + usbPoll(); + if(usbInterruptIsReady()){ + /* called after every poll of the interrupt endpoint */ + advanceCircleByFixedAngle(); + DBG1(0x03, 0, 0); /* debug output: interrupt report prepared */ + usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer)); + } + } +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/usbconfig.h b/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/usbconfig.h new file mode 100644 index 0000000..c16a146 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/hid-mouse/firmware/usbconfig.h @@ -0,0 +1,373 @@ +/* Name: usbconfig.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2005-04-01 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ + */ + +#ifndef __usbconfig_h_included__ +#define __usbconfig_h_included__ + +/* +General Description: +This file is an example configuration (with inline documentation) for the USB +driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is +also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may +wire the lines to any other port, as long as D+ is also wired to INT0 (or any +other hardware interrupt, as long as it is the highest level interrupt, see +section at the end of this file). +*/ + +/* ---------------------------- Hardware Config ---------------------------- */ + +#define USB_CFG_IOPORTNAME D +/* This is the port where the USB bus is connected. When you configure it to + * "B", the registers PORTB, PINB and DDRB will be used. + */ +#define USB_CFG_DMINUS_BIT 4 +/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. + * This may be any bit in the port. + */ +#define USB_CFG_DPLUS_BIT 2 +/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. + * This may be any bit in the port. Please note that D+ must also be connected + * to interrupt pin INT0! [You can also use other interrupts, see section + * "Optional MCU Description" below, or you can connect D- to the interrupt, as + * it is required if you use the USB_COUNT_SOF feature. If you use D- for the + * interrupt, the USB interrupt will also be triggered at Start-Of-Frame + * markers every millisecond.] + */ +#define USB_CFG_CLOCK_KHZ (F_CPU/1000) +/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, + * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code + * require no crystal, they tolerate +/- 1% deviation from the nominal + * frequency. All other rates require a precision of 2000 ppm and thus a + * crystal! + * Since F_CPU should be defined to your actual clock rate anyway, you should + * not need to modify this setting. + */ +#define USB_CFG_CHECK_CRC 0 +/* Define this to 1 if you want that the driver checks integrity of incoming + * data packets (CRC checks). CRC checks cost quite a bit of code size and are + * currently only available for 18 MHz crystal clock. You must choose + * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. + */ + +/* ----------------------- Optional Hardware Config ------------------------ */ + +/* #define USB_CFG_PULLUP_IOPORTNAME D */ +/* If you connect the 1.5k pullup resistor from D- to a port pin instead of + * V+, you can connect and disconnect the device from firmware by calling + * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). + * This constant defines the port on which the pullup resistor is connected. + */ +/* #define USB_CFG_PULLUP_BIT 4 */ +/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined + * above) where the 1.5k pullup resistor is connected. See description + * above for details. + */ + +/* --------------------------- Functional Range ---------------------------- */ + +#define USB_CFG_HAVE_INTRIN_ENDPOINT 1 +/* Define this to 1 if you want to compile a version with two endpoints: The + * default control endpoint 0 and an interrupt-in endpoint (any other endpoint + * number). + */ +#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 +/* Define this to 1 if you want to compile a version with three endpoints: The + * default control endpoint 0, an interrupt-in endpoint 3 (or the number + * configured below) and a catch-all default interrupt-in endpoint as above. + * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. + */ +#define USB_CFG_EP3_NUMBER 3 +/* If the so-called endpoint 3 is used, it can now be configured to any other + * endpoint number (except 0) with this macro. Default if undefined is 3. + */ +/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ +/* The above macro defines the startup condition for data toggling on the + * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. + * Since the token is toggled BEFORE sending any data, the first packet is + * sent with the oposite value of this configuration! + */ +#define USB_CFG_IMPLEMENT_HALT 0 +/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature + * for endpoint 1 (interrupt endpoint). Although you may not need this feature, + * it is required by the standard. We have made it a config option because it + * bloats the code considerably. + */ +#define USB_CFG_SUPPRESS_INTR_CODE 0 +/* Define this to 1 if you want to declare interrupt-in endpoints, but don't + * want to send any data over them. If this macro is defined to 1, functions + * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if + * you need the interrupt-in endpoints in order to comply to an interface + * (e.g. HID), but never want to send any data. This option saves a couple + * of bytes in flash memory and the transmit buffers in RAM. + */ +#define USB_CFG_INTR_POLL_INTERVAL 100 +/* If you compile a version with endpoint 1 (interrupt-in), this is the poll + * interval. The value is in milliseconds and must not be less than 10 ms for + * low speed devices. + */ +#define USB_CFG_IS_SELF_POWERED 0 +/* Define this to 1 if the device has its own power supply. Set it to 0 if the + * device is powered from the USB bus. + */ +#define USB_CFG_MAX_BUS_POWER 20 +/* Set this variable to the maximum USB bus power consumption of your device. + * The value is in milliamperes. [It will be divided by two since USB + * communicates power requirements in units of 2 mA.] + */ +#define USB_CFG_IMPLEMENT_FN_WRITE 0 +/* Set this to 1 if you want usbFunctionWrite() to be called for control-out + * transfers. Set it to 0 if you don't need it and want to save a couple of + * bytes. + */ +#define USB_CFG_IMPLEMENT_FN_READ 0 +/* Set this to 1 if you need to send control replies which are generated + * "on the fly" when usbFunctionRead() is called. If you only want to send + * data from a static buffer, set it to 0 and return the data from + * usbFunctionSetup(). This saves a couple of bytes. + */ +#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 +/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. + * You must implement the function usbFunctionWriteOut() which receives all + * interrupt/bulk data sent to any endpoint other than 0. The endpoint number + * can be found in 'usbRxToken'. + */ +#define USB_CFG_HAVE_FLOWCONTROL 0 +/* Define this to 1 if you want flowcontrol over USB data. See the definition + * of the macros usbDisableAllRequests() and usbEnableAllRequests() in + * usbdrv.h. + */ +#define USB_CFG_DRIVER_FLASH_PAGE 0 +/* If the device has more than 64 kBytes of flash, define this to the 64 k page + * where the driver's constants (descriptors) are located. Or in other words: + * Define this to 1 for boot loaders on the ATMega128. + */ +#define USB_CFG_LONG_TRANSFERS 0 +/* Define this to 1 if you want to send/receive blocks of more than 254 bytes + * in a single control-in or control-out transfer. Note that the capability + * for long transfers increases the driver size. + */ +/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ +/* This macro is a hook if you want to do unconventional things. If it is + * defined, it's inserted at the beginning of received message processing. + * If you eat the received message and don't want default processing to + * proceed, do a return after doing your things. One possible application + * (besides debugging) is to flash a status LED on each packet. + */ +/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ +/* This macro is a hook if you need to know when an USB RESET occurs. It has + * one parameter which distinguishes between the start of RESET state and its + * end. + */ +/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ +/* This macro (if defined) is executed when a USB SET_ADDRESS request was + * received. + */ +#define USB_COUNT_SOF 0 +/* define this macro to 1 if you need the global variable "usbSofCount" which + * counts SOF packets. This feature requires that the hardware interrupt is + * connected to D- instead of D+. + */ +/* #ifdef __ASSEMBLER__ + * macro myAssemblerMacro + * in YL, TCNT0 + * sts timer0Snapshot, YL + * endm + * #endif + * #define USB_SOF_HOOK myAssemblerMacro + * This macro (if defined) is executed in the assembler module when a + * Start Of Frame condition is detected. It is recommended to define it to + * the name of an assembler macro which is defined here as well so that more + * than one assembler instruction can be used. The macro may use the register + * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages + * immediately after an SOF pulse may be lost and must be retried by the host. + * What can you do with this hook? Since the SOF signal occurs exactly every + * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in + * designs running on the internal RC oscillator. + * Please note that Start Of Frame detection works only if D- is wired to the + * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! + */ +#define USB_CFG_CHECK_DATA_TOGGLING 0 +/* define this macro to 1 if you want to filter out duplicate data packets + * sent by the host. Duplicates occur only as a consequence of communication + * errors, when the host does not receive an ACK. Please note that you need to + * implement the filtering yourself in usbFunctionWriteOut() and + * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable + * for each control- and out-endpoint to check for duplicate packets. + */ +#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 +/* define this macro to 1 if you want the function usbMeasureFrameLength() + * compiled in. This function can be used to calibrate the AVR's RC oscillator. + */ +#define USB_USE_FAST_CRC 0 +/* The assembler module has two implementations for the CRC algorithm. One is + * faster, the other is smaller. This CRC routine is only used for transmitted + * messages where timing is not critical. The faster routine needs 31 cycles + * per byte while the smaller one needs 61 to 69 cycles. The faster routine + * may be worth the 32 bytes bigger code size if you transmit lots of data and + * run the AVR close to its limit. + */ + +/* -------------------------- Device Description --------------------------- */ + +#define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ +/* USB vendor ID for the device, low byte first. If you have registered your + * own Vendor ID, define it here. Otherwise you may use one of obdev's free + * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_ID 0xe8, 0x03 /* VOTI's lab use PID */ +/* This is the ID of the product, low byte first. It is interpreted in the + * scope of the vendor ID. If you have registered your own VID with usb.org + * or if you have licensed a PID from somebody else, define it here. Otherwise + * you may use one of obdev's free shared VID/PID pairs. See the file + * USB-IDs-for-free.txt for details! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +/* Version number of the device: Minor number first, then major number. + */ +#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' +#define USB_CFG_VENDOR_NAME_LEN 8 +/* These two values define the vendor name returned by the USB device. The name + * must be given as a list of characters under single quotes. The characters + * are interpreted as Unicode (UTF-16) entities. + * If you don't want a vendor name string, undefine these macros. + * ALWAYS define a vendor name containing your Internet domain name if you use + * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for + * details. + */ +#define USB_CFG_DEVICE_NAME 'M', 'o', 'u', 's', 'e' +#define USB_CFG_DEVICE_NAME_LEN 5 +/* Same as above for the device name. If you don't want a device name, undefine + * the macros. See the file USB-IDs-for-free.txt before you assign a name if + * you use a shared VID/PID. + */ +/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ +/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ +/* Same as above for the serial number. If you don't want a serial number, + * undefine the macros. + * It may be useful to provide the serial number through other means than at + * compile time. See the section about descriptor properties below for how + * to fine tune control over USB descriptors such as the string descriptor + * for the serial number. + */ +#define USB_CFG_DEVICE_CLASS 0 +#define USB_CFG_DEVICE_SUBCLASS 0 +/* See USB specification if you want to conform to an existing device class. + * Class 0xff is "vendor specific". + */ +#define USB_CFG_INTERFACE_CLASS 3 +#define USB_CFG_INTERFACE_SUBCLASS 0 +#define USB_CFG_INTERFACE_PROTOCOL 0 +/* See USB specification if you want to conform to an existing device class or + * protocol. The following classes must be set at interface level: + * HID class is 3, no subclass and protocol required (but may be useful!) + * CDC class is 2, use subclass 2 and protocol 1 for ACM + */ +#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 52 +/* Define this to the length of the HID report descriptor, if you implement + * an HID device. Otherwise don't define it or define it to 0. + * If you use this define, you must add a PROGMEM character array named + * "usbHidReportDescriptor" to your code which contains the report descriptor. + * Don't forget to keep the array and this define in sync! + */ + +/* #define USB_PUBLIC static */ +/* Use the define above if you #include usbdrv.c instead of linking against it. + * This technique saves a couple of bytes in flash memory. + */ + +/* ------------------- Fine Control over USB Descriptors ------------------- */ +/* If you don't want to use the driver's default USB descriptors, you can + * provide our own. These can be provided as (1) fixed length static data in + * flash memory, (2) fixed length static data in RAM or (3) dynamically at + * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more + * information about this function. + * Descriptor handling is configured through the descriptor's properties. If + * no properties are defined or if they are 0, the default descriptor is used. + * Possible properties are: + * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched + * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is + * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if + * you want RAM pointers. + * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found + * in static memory is in RAM, not in flash memory. + * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), + * the driver must know the descriptor's length. The descriptor itself is + * found at the address of a well known identifier (see below). + * List of static descriptor names (must be declared PROGMEM if in flash): + * char usbDescriptorDevice[]; + * char usbDescriptorConfiguration[]; + * char usbDescriptorHidReport[]; + * char usbDescriptorString0[]; + * int usbDescriptorStringVendor[]; + * int usbDescriptorStringDevice[]; + * int usbDescriptorStringSerialNumber[]; + * Other descriptors can't be provided statically, they must be provided + * dynamically at runtime. + * + * Descriptor properties are or-ed or added together, e.g.: + * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) + * + * The following descriptors are defined: + * USB_CFG_DESCR_PROPS_DEVICE + * USB_CFG_DESCR_PROPS_CONFIGURATION + * USB_CFG_DESCR_PROPS_STRINGS + * USB_CFG_DESCR_PROPS_STRING_0 + * USB_CFG_DESCR_PROPS_STRING_VENDOR + * USB_CFG_DESCR_PROPS_STRING_PRODUCT + * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER + * USB_CFG_DESCR_PROPS_HID + * USB_CFG_DESCR_PROPS_HID_REPORT + * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) + * + * Note about string descriptors: String descriptors are not just strings, they + * are Unicode strings prefixed with a 2 byte header. Example: + * int serialNumberDescriptor[] = { + * USB_STRING_DESCRIPTOR_HEADER(6), + * 'S', 'e', 'r', 'i', 'a', 'l' + * }; + */ + +#define USB_CFG_DESCR_PROPS_DEVICE 0 +#define USB_CFG_DESCR_PROPS_CONFIGURATION 0 +#define USB_CFG_DESCR_PROPS_STRINGS 0 +#define USB_CFG_DESCR_PROPS_STRING_0 0 +#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 +#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 +#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 +#define USB_CFG_DESCR_PROPS_HID 0 +#define USB_CFG_DESCR_PROPS_HID_REPORT 0 +#define USB_CFG_DESCR_PROPS_UNKNOWN 0 + +/* ----------------------- Optional MCU Description ------------------------ */ + +/* The following configurations have working defaults in usbdrv.h. You + * usually don't need to set them explicitly. Only if you want to run + * the driver on a device which is not yet supported or with a compiler + * which is not fully supported (such as IAR C) or if you use a differnt + * interrupt than INT0, you may have to define some of these. + */ +/* #define USB_INTR_CFG MCUCR */ +/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ +/* #define USB_INTR_CFG_CLR 0 */ +/* #define USB_INTR_ENABLE GIMSK */ +/* #define USB_INTR_ENABLE_BIT INT0 */ +/* #define USB_INTR_PENDING GIFR */ +/* #define USB_INTR_PENDING_BIT INTF0 */ +/* #define USB_INTR_VECTOR INT0_vect */ + +#endif /* __usbconfig_h_included__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Makefile b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Makefile new file mode 100644 index 0000000..d41aba6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Makefile @@ -0,0 +1,48 @@ +# Name: Makefile +# Project: usbtool +# Author: Christian Starkjohann +# Creation Date: 2008-04-06 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 692 2008-11-07 15:07:40Z cs $ + + +# Concigure the following definitions according to your system. +# This Makefile has been tested on Mac OS X, Linux and Windows. + +# Use the following 3 lines on Unix (uncomment the framework on Mac OS X): +USBFLAGS = `libusb-config --cflags` +USBLIBS = `libusb-config --libs` +EXE_SUFFIX = + +# Use the following 3 lines on Windows and comment out the 3 above. You may +# have to change the include paths to where you installed libusb-win32 +#USBFLAGS = -I/usr/local/include +#USBLIBS = -L/usr/local/lib -lusb +#EXE_SUFFIX = .exe + +NAME = usbtool + +OBJECTS = opendevice.o $(NAME).o + +CC = gcc +CFLAGS = $(CPPFLAGS) $(USBFLAGS) -O -g -Wall +LIBS = $(USBLIBS) + +PROGRAM = $(NAME)$(EXE_SUFFIX) + + +all: $(PROGRAM) + +.c.o: + $(CC) $(CFLAGS) -c $< + +$(PROGRAM): $(OBJECTS) + $(CC) -o $(PROGRAM) $(OBJECTS) $(LIBS) + +strip: $(PROGRAM) + strip $(PROGRAM) + +clean: + rm -f *.o $(PROGRAM) diff --git a/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Makefile.windows b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Makefile.windows new file mode 100644 index 0000000..fa910fc --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Makefile.windows @@ -0,0 +1,18 @@ +# Name: Makefile.windows +# Project: usbtool +# Author: Christian Starkjohann +# Creation Date: 2008-04-06 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id$ + +# You may use this file with +# make -f Makefile.windows +# on Windows with MinGW instead of editing the main Makefile. + +include Makefile + +USBFLAGS = -I/usr/local/mingw/include +USBLIBS = -L/usr/local/mingw/lib -lusb +EXE_SUFFIX = .exe diff --git a/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Readme.txt b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Readme.txt new file mode 100644 index 0000000..33f527c --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/Readme.txt @@ -0,0 +1,209 @@ +This is the Readme file for usbtool, a general purpose command line utility +which can send USB requests to arbitrary devices. Usbtool is based on libusb. + + +WHAT IS USBTOOL GOOD FOR? +========================= +When you implement a communication protocol like USB, you must usually write +two programs: one on each end of the communication. For USB, this means that +you must write a firmware for the device and driver software for the host. + +Usbtool can save you the work of writing the host software, at least during +firmware development and testing. Usbtool can send control-in and -out +requests to arbitrary devices and send and receive data on interrupt- and +bulk-endpoints. + +Usbtool is not only a useful developer tool, it's also an example for using +libusb for communication with the device. + + +SYNOPSIS +======== + usbtool [options] + + +COMMANDS +======== + list + This command prints a list of devices found on all available USB busses. + Options -v, -V, -p and -P can be used to filter the list. + + control in|out + Sends a control-in or control-out request to the device. The request + parameters are: + type ........ Type of request, can be "standard", "class", "vendor" or + "reserved". The type determines which software module in + the device is responsible for answering the request: + Standard requests are answered by the driver, class + requests by the class implementation (e.g. HID, CDC) and + vendor requests by custom code. + recipient ... Recipient of the request in the device. Can be "device", + "interface", "endpoint" or "other". For standard and + class requests, the specification defines a recipient for + each request. For vendor requests, choose whatever your + code expects. + request ..... 8 bit numeric value identifying the request. + value ....... 16 bit numeric value passed to the device. + index ....... another 16 bit numeric value passed to the device. + Use options -v, -V, -p and -P to single out a particular device. Use + options -d or -D to to send data in an OUT request. Use options -n, -O + and -b to determine what to do with data received in an IN request. + + interrupt in|out + Sends or receives data on an interrupt-out resp. -in endpoint. + Use options -v, -V, -p and -P to single out a particular device. Use + options -d or -D to to send data to an OUT endpoint. Use options -n, -O + and -b to determine what to do with data received from an IN endpoint. + Use option -e to set the endpoint number, -c to choose a configuration + -i to claim a particular interface. + + bulk in|out + Same as "interrupt in" and "interrupt out", but for bulk endpoints. + + +OPTIONS +======= +Most options have already been mentioned at the commands which use them. +here is a complete list: + + -h or -? + Prints a short help. + + -v + Numeric vendor ID, can be "*" to allow any VID. Take only devices with + matching vendor ID into account. + + -p + Numeric product ID, can be "*" to allow any PID. Take only devices with + matching product ID into account. + + -V + Shell style matching pattern for vendor name. Take only devices into + account which have a vendor name that matches this pattern. + + -P + Shell style matching pattern for product name. Take only devices into + account which have a product name that matches this pattern. + + -S + Shell style matching pattern for serial number. Take only devices into + account which have a serial number that matches this pattern. + + -d + Data bytes to send to the device, comma separated list of numeric values. + E.g.: "1,2,3,4,5". + + -D + Binary data sent to the device should be taken from this file. + + -O + Write received data bytes to the given file. Format is either hex or + binary, depending on the -b flag. By default, received data is printed + to standard output. + + -b + Request binary output format for files and standard output. Default is + a hexadecimal listing. + + -n + Numeric value: Maximum number of bytes to receive. This value is passed + directly to the libusb API functions. + + -e + Numeric value: Endpoint number for interrupt and bulk commands. + + -t + Numeric value: Timeout in milliseconds for the request. This value is + passed directly to the libusb API functions. + + -c + Numeric value: Interrupt and bulk endpoints can usually only be used if + a configuration and an interface has been chosen. Use -c and -i to + specify configuration and interface values. + + -i + Numeric value: Interrupt and bulk endpoints can usually only be used if + a configuration and an interface has been chosen. Use -c and -i to + specify configuration and interface values. + + -w + Usbtool may be too verbose with warnings for some applications. Use this + option to suppress USB warnings. + + +NUMERIC VALUES +============== +All numeric values can be given in hexadecimal, decimal or octal. Hex values +are identified by their 0x or 0X prefix, octal values by a leading "0" (the +digit zero) and decimal values because they start with a non-zero digit. An +optional sign character is allowed. The special value "*" is translated to +zero and stands for "any value" in some contexts. + + +SHELL STYLE MATCHING PATTERNS +============================= +Some options take shell style matching patterns as an argument. This refers +to Unix shells and their file wildcard operations: + + "*" (asterisk character) matches any number (0 to infinite) of any + characters. + + "?" matches exactly one arbitrary character. + + A list of characters in square brackets (e.g. "[abc]") matches any of the + characters in the list. If a dash ("-") is in the list, it must be the + first or the last character. If a caret ("^") is in the list, it must + not be the first character. A closing square bracket ("]") must be the + first character in the list. A range of characters can be specified in + the way "[a-z]". This matches all characters with numeric representation + (usually ASCII) starting with "a" and ending with "z". The entire + construct matches only one character. + + A list of characters in square brackets starting with a caret ("^"), e.g. + ("[^abc]") matches any character NOT in the list. The other rules are as + above. + + "\" (backslash) followed by any character matches that following + character. This can be used to escape "*", "?", "[" and "\". + + +BUILDING USBTOOL +================ +Usbtool uses libusb on Unix and libusb-win32 on Windows. These libraries can +be obtained from http://libusb.sourceforge.net/ and +http://libusb-win32.sourceforge.net/ respectively. On Unix, a simple "make" +should compile the sources (although you may have to edit Makefile to +include or remove additional libraries). On Windows, we recommend that you +use MinGW and MSYS. See the top level Readme file for details. Edit +Makefile.windows according to your library installation paths and build with +"make -f Makefile.windows". + + +EXAMPLES +======== +To list all devices connected to your computer, do + + usbtool -w list + +To check whether our selection options single out the desired device, use eg. + + usbtool -w -P LEDControl list + +This command shows all LEDControl devices connected or prints nothing if +none is found. LEDControl is the device from the "custom-class" example. + +You can also send commands to the LEDControl device using usbtool. From +the file requests.h in custom-class/firmware, we know that the set-status +request has numeric value 1 and the get-status request is 2. See this file +for details of the protocol used. We can therefore query the status with + + usbtool -w -P LEDControl control in vendor device 2 0 0 + +This command prints 0x00 if the LED is off or 0x01 if it is on. To turn the +LED on, use + + usbtool -w -P LEDControl control out vendor device 1 1 0 + +and to turn it off, use + + usbtool -w -P LEDControl control out vendor device 1 0 0 + + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/usbtool/opendevice.c b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/opendevice.c new file mode 100644 index 0000000..137f50c --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/opendevice.c @@ -0,0 +1,203 @@ +/* Name: opendevice.c + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.c 740 2009-04-13 18:23:31Z cs $ + */ + +/* +General Description: +The functions in this module can be used to find and open a device based on +libusb or libusb-win32. +*/ + +#include +#include "opendevice.h" + +/* ------------------------------------------------------------------------- */ + +#define MATCH_SUCCESS 1 +#define MATCH_FAILED 0 +#define MATCH_ABORT -1 + +/* private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or MATCH_ABORT. */ +static int _shellStyleMatch(char *text, char *p) +{ +int last, matched, reverse; + + for(; *p; text++, p++){ + if(*text == 0 && *p != '*') + return MATCH_ABORT; + switch(*p){ + case '\\': + /* Literal match with following character. */ + p++; + /* FALLTHROUGH */ + default: + if(*text != *p) + return MATCH_FAILED; + continue; + case '?': + /* Match anything. */ + continue; + case '*': + while(*++p == '*') + /* Consecutive stars act just like one. */ + continue; + if(*p == 0) + /* Trailing star matches everything. */ + return MATCH_SUCCESS; + while(*text) + if((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED) + return matched; + return MATCH_ABORT; + case '[': + reverse = p[1] == '^'; + if(reverse) /* Inverted character class. */ + p++; + matched = MATCH_FAILED; + if(p[1] == ']' || p[1] == '-') + if(*++p == *text) + matched = MATCH_SUCCESS; + for(last = *p; *++p && *p != ']'; last = *p) + if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p) + matched = MATCH_SUCCESS; + if(matched == reverse) + return MATCH_FAILED; + continue; + } + } + return *text == 0; +} + +/* public interface for shell style matching: returns 0 if fails, 1 if matches */ +static int shellStyleMatch(char *text, char *pattern) +{ + if(pattern == NULL) /* NULL pattern is synonymous to "*" */ + return 1; + return _shellStyleMatch(text, pattern) == MATCH_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) +{ +char buffer[256]; +int rval, i; + + if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ + return rval; + if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) + return rval; + if(buffer[1] != USB_DT_STRING){ + *buf = 0; + return 0; + } + if((unsigned char)buffer[0] < rval) + rval = (unsigned char)buffer[0]; + rval /= 2; + /* lossy conversion to ISO Latin1: */ + for(i=1;i buflen) /* destination buffer overflow */ + break; + buf[i-1] = buffer[2 * i]; + if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ + buf[i-1] = '?'; + } + buf[i-1] = 0; + return i-1; +} + +/* ------------------------------------------------------------------------- */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp) +{ +struct usb_bus *bus; +struct usb_device *dev; +usb_dev_handle *handle = NULL; +int errorCode = USBOPEN_ERR_NOTFOUND; + + usb_find_busses(); + usb_find_devices(); + for(bus = usb_get_busses(); bus; bus = bus->next){ + for(dev = bus->devices; dev; dev = dev->next){ /* iterate over all devices on all busses */ + if((vendorID == 0 || dev->descriptor.idVendor == vendorID) + && (productID == 0 || dev->descriptor.idProduct == productID)){ + char vendor[256], product[256], serial[256]; + int len; + handle = usb_open(dev); /* we need to open the device in order to query strings */ + if(!handle){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot open VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + continue; + } + /* now check whether the names match: */ + len = vendor[0] = 0; + if(dev->descriptor.iManufacturer > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, vendor, sizeof(vendor)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen device from vendor ->%s<-\n", vendor); */ + if(shellStyleMatch(vendor, vendorNamePattern)){ + len = product[0] = 0; + if(dev->descriptor.iProduct > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iProduct, product, sizeof(product)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen product ->%s<-\n", product); */ + if(shellStyleMatch(product, productNamePattern)){ + len = serial[0] = 0; + if(dev->descriptor.iSerialNumber > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, serial, sizeof(serial)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + } + if(shellStyleMatch(serial, serialNamePattern)){ + if(printMatchingDevicesFp != NULL){ + if(serial[0] == 0){ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product); + }else{ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product, serial); + } + }else{ + break; + } + } + } + } + } + } + usb_close(handle); + handle = NULL; + } + } + if(handle) /* we have found a deice */ + break; + } + if(handle != NULL){ + errorCode = 0; + *device = handle; + } + if(printMatchingDevicesFp != NULL) /* never return an error for listing only */ + errorCode = 0; + return errorCode; +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/usbtool/opendevice.h b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/opendevice.h new file mode 100644 index 0000000..79c12f6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/opendevice.h @@ -0,0 +1,77 @@ +/* Name: opendevice.h + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.h 755 2009-08-03 17:01:21Z cs $ + */ + +/* +General Description: +This module offers additional functionality for host side drivers based on +libusb or libusb-win32. It includes a function to find and open a device +based on numeric IDs and textual description. It also includes a function to +obtain textual descriptions from a device. + +To use this functionality, simply copy opendevice.c and opendevice.h into your +project and add them to your Makefile. You may modify and redistribute these +files according to the GNU General Public License (GPL) version 2 or 3. +*/ + +#ifndef __OPENDEVICE_H_INCLUDED__ +#define __OPENDEVICE_H_INCLUDED__ + +#include /* this is libusb, see http://libusb.sourceforge.net/ */ +#include + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen); +/* This function gets a string descriptor from the device. 'index' is the + * string descriptor index. The string is returned in ISO Latin 1 encoding in + * 'buf' and it is terminated with a 0-character. The buffer size must be + * passed in 'buflen' to prevent buffer overflows. A libusb device handle + * must be given in 'dev'. + * Returns: The length of the string (excluding the terminating 0) or + * a negative number in case of an error. If there was an error, use + * usb_strerror() to obtain the error message. + */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp); +/* This function iterates over all devices on all USB busses and searches for + * a device. Matching is done first by means of Vendor- and Product-ID (passed + * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard). + * When a device matches by its IDs, matching by names is performed. Name + * matching can be done on textual vendor name ('vendorNamePattern'), product + * name ('productNamePattern') and serial number ('serialNamePattern'). A + * device matches only if all non-null pattern match. If you don't care about + * a string, pass NULL for the pattern. Patterns are Unix shell style pattern: + * '*' stands for 0 or more characters, '?' for one single character, a list + * of characters in square brackets for a single character from the list + * (dashes are allowed to specify a range) and if the lis of characters begins + * with a caret ('^'), it matches one character which is NOT in the list. + * Other parameters to the function: If 'warningsFp' is not NULL, warning + * messages are printed to this file descriptor with fprintf(). If + * 'printMatchingDevicesFp' is not NULL, no device is opened but matching + * devices are printed to the given file descriptor with fprintf(). + * If a device is opened, the resulting USB handle is stored in '*device'. A + * pointer to a "usb_dev_handle *" type variable must be passed here. + * Returns: 0 on success, an error code (see defines below) on failure. + */ + +/* usbOpenDevice() error codes: */ +#define USBOPEN_SUCCESS 0 /* no error */ +#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ +#define USBOPEN_ERR_IO 2 /* I/O error */ +#define USBOPEN_ERR_NOTFOUND 3 /* device not found */ + + +/* Obdev's free USB IDs, see USB-IDs-for-free.txt for details */ + +#define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */ +#define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */ +#define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */ +#define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */ +#define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */ + +#endif /* __OPENDEVICE_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/examples/usbtool/usbtool.c b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/usbtool.c new file mode 100644 index 0000000..dc7e4eb --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/examples/usbtool/usbtool.c @@ -0,0 +1,356 @@ +/* Name: usbtool.c + * Project: V-USB examples, host side + * Author: Christian Starkjohann + * Creation Date: 2008-04-06 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbtool.c 740 2009-04-13 18:23:31Z cs $ + */ + +/* +General Description: +This command line tool can perform various USB requests at arbitrary +USB devices. It is intended as universal host side tool for experimentation +and debugging purposes. It must be linked with libusb, a library for accessing +the USB bus from Linux, FreeBSD, Mac OS X and other Unix operating systems. +Libusb can be obtained from http://libusb.sourceforge.net/. +On Windows use libusb-win32 from http://libusb-win32.sourceforge.net/. +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include /* this is libusb, see http://libusb.sourceforge.net/ */ +#include "opendevice.h" /* common code moved to separate module */ + +#define DEFAULT_USB_VID 0 /* any */ +#define DEFAULT_USB_PID 0 /* any */ + +static void usage(char *name) +{ + fprintf(stderr, "usage: %s [options] \n", name); + fprintf(stderr, + "Options are:\n" + " -h or -? (print this help and exit)\n" + " -v (defaults to 0x%x, can be '*' for any VID)\n" + " -p (defaults to 0x%x, can be '*' for any PID)\n" + " -V (shell style matching, defaults to '*')\n" + " -P (shell style matching, defaults to '*')\n" + " -S (shell style matching, defaults to '*')\n" + " -d (data byte for request, comma separated list)\n" + " -D (binary data for request taken from file)\n" + " -O (write received data bytes to file)\n" + " -b (binary output format, default is hex)\n" + " -n (maximum number of bytes to receive)\n" + " -e (specify endpoint for some commands)\n" + " -t (specify USB timeout in milliseconds)\n" + " -c (device configuration to choose)\n" + " -i (configuration interface to claim)\n" + " -w (suppress USB warnings, default is verbose)\n" + "\n" + "Commands are:\n" + " list (list all matching devices by name)\n" + " control in|out (send control request)\n" + " interrupt in|out (send or receive interrupt data)\n" + " bulk in|out (send or receive bulk data)\n" + "For valid enum values for and pass \"x\" for the value.\n" + "Objective Development's free VID/PID pairs are:\n" + " 5824/1500 for vendor class devices\n" + " 5824/1503 for HID class devices excluding mice and keyboards\n" + " 5824/1505 for CDC-ACM class devices\n" + " 5824/1508 for MIDI class devices\n" + , DEFAULT_USB_VID, DEFAULT_USB_PID + ); + + +} + +static int vendorID = DEFAULT_USB_VID; +static int productID = DEFAULT_USB_PID; +static char *vendorNamePattern = "*"; +static char *productNamePattern = "*"; +static char *serialPattern = "*"; +static char *sendBytes = NULL; +static int sendByteCount; +static char *outputFile = NULL; +static int endpoint = 0; +static int outputFormatIsBinary = 0; +static int showWarnings = 1; +static int usbTimeout = 5000; +static int usbCount = 128; +static int usbConfiguration = 1; +static int usbInterface = 0; + +static int usbDirection, usbType, usbRecipient, usbRequest, usbValue, usbIndex; /* arguments of control transfer */ + +/* ------------------------------------------------------------------------- */ + +/* ASCII to integer (number parsing) which allows hex (0x prefix), + * octal (0 prefix) and decimal (1-9 prefix) input. + */ +static int myAtoi(char *text) +{ +long l; +char *endPtr; + + if(strcmp(text, "*") == 0) + return 0; + l = strtol(text, &endPtr, 0); + if(endPtr == text){ + fprintf(stderr, "warning: can't parse numeric parameter ->%s<-, defaults to 0.\n", text); + l = 0; + }else if(*endPtr != 0){ + fprintf(stderr, "warning: numeric parameter ->%s<- only partially parsed.\n", text); + } + return l; +} + +static int parseEnum(char *text, ...) +{ +va_list vlist; +char *entries[64]; +int i, numEntries; + + va_start(vlist, text); + for(i = 0; i < 64; i++){ + entries[i] = va_arg(vlist, char *); + if(entries[i] == NULL) + break; + } + numEntries = i; + va_end(vlist); + for(i = 0; i < numEntries; i++){ + if(strcasecmp(text, entries[i]) == 0) + return i; + } + if(isdigit(*text)){ + return myAtoi(text); + } + fprintf(stderr, "Enum value \"%s\" not allowed. Allowed values are:\n", text); + for(i = 0; i < numEntries; i++){ + fprintf(stderr, " %s\n", entries[i]); + } + exit(1); +} + +/* ------------------------------------------------------------------------- */ + +#define ACTION_LIST 0 +#define ACTION_CONTROL 1 +#define ACTION_INTERRUPT 2 +#define ACTION_BULK 3 + +int main(int argc, char **argv) +{ +usb_dev_handle *handle = NULL; +int opt, len, action, argcnt; +char *myName = argv[0], *s, *rxBuffer = NULL; +FILE *fp; + + while((opt = getopt(argc, argv, "?hv:p:V:P:S:d:D:O:e:n:tbw")) != -1){ + switch(opt){ + case 'h': + case '?': /* -h or -? (print this help and exit) */ + usage(myName); + exit(1); + case 'v': /* -v (defaults to 0x%x, can be '*' for any VID) */ + vendorID = myAtoi(optarg); + break; + case 'p': /* -p (defaults to 0x%x, can be '*' for any PID) */ + productID = myAtoi(optarg); + break; + case 'V': /* -V (shell style matching, defaults to '*') */ + vendorNamePattern = optarg; + break; + case 'P': /* -P (shell style matching, defaults to '*') */ + productNamePattern = optarg; + break; + case 'S': /* -S (shell style matching, defaults to '*') */ + serialPattern = optarg; + break; + case 'd': /* -d (data bytes for requests given on command line) */ + while((s = strtok(optarg, ", ")) != NULL){ + optarg = NULL; + if(sendBytes != NULL){ + sendBytes = realloc(sendBytes, sendByteCount + 1); + }else{ + sendBytes = malloc(sendByteCount + 1); + } + sendBytes[sendByteCount++] = myAtoi(s); + } + break; + case 'D': /* -D (data bytes for request taken from file) */ + if((fp = fopen(optarg, "rb")) == NULL){ + fprintf(stderr, "error opening %s: %s\n", optarg, strerror(errno)); + exit(1); + } + fseek(fp, 0, SEEK_END); + len = ftell(fp); + fseek(fp, 0, SEEK_SET); + if(sendBytes != NULL){ + sendBytes = realloc(sendBytes, sendByteCount + len); + }else{ + sendBytes = malloc(sendByteCount + len); + } + fread(sendBytes + sendByteCount, 1, len, fp); /* would need error checking */ + sendByteCount += len; + fclose(fp); + break; + case 'O': /* -O (write received data bytes to file) */ + outputFile = optarg; + break; + case 'e': /* -e (specify endpoint for some commands) */ + endpoint = myAtoi(optarg); + break; + case 't': /* -t (specify USB timeout in milliseconds) */ + usbTimeout = myAtoi(optarg); + break; + case 'b': /* -b (binary output format, default is hex) */ + outputFormatIsBinary = 1; + break; + case 'n': /* -n (maximum number of bytes to receive) */ + usbCount = myAtoi(optarg); + break; + case 'c': /* -c (device configuration to choose) */ + usbConfiguration = myAtoi(optarg); + break; + case 'i': /* -i (configuration interface to claim) */ + usbInterface = myAtoi(optarg); + break; + case 'w': /* -w (suppress USB warnings, default is verbose) */ + showWarnings = 0; + break; + default: + fprintf(stderr, "Option -%c unknown\n", opt); + exit(1); + } + } + argc -= optind; + argv += optind; + if(argc < 1){ + usage(myName); + exit(1); + } + argcnt = 2; + if(strcasecmp(argv[0], "list") == 0){ + action = ACTION_LIST; + argcnt = 1; + }else if(strcasecmp(argv[0], "control") == 0){ + action = ACTION_CONTROL; + argcnt = 7; + }else if(strcasecmp(argv[0], "interrupt") == 0){ + action = ACTION_INTERRUPT; + }else if(strcasecmp(argv[0], "bulk") == 0){ + action = ACTION_BULK; + }else{ + fprintf(stderr, "command %s not known\n", argv[0]); + usage(myName); + exit(1); + } + if(argc < argcnt){ + fprintf(stderr, "Not enough arguments.\n"); + usage(myName); + exit(1); + } + if(argc > argcnt){ + fprintf(stderr, "Warning: only %d arguments expected, rest ignored.\n", argcnt); + } + usb_init(); + if(usbOpenDevice(&handle, vendorID, vendorNamePattern, productID, productNamePattern, serialPattern, action == ACTION_LIST ? stdout : NULL, showWarnings ? stderr : NULL) != 0){ + fprintf(stderr, "Could not find USB device with VID=0x%x PID=0x%x Vname=%s Pname=%s Serial=%s\n", vendorID, productID, vendorNamePattern, productNamePattern, serialPattern); + exit(1); + } + if(action == ACTION_LIST) + exit(0); /* we've done what we were asked to do already */ + usbDirection = parseEnum(argv[1], "out", "in", NULL); + if(usbDirection){ /* IN transfer */ + rxBuffer = malloc(usbCount); + } + if(action == ACTION_CONTROL){ + int requestType; + usbType = parseEnum(argv[2], "standard", "class", "vendor", "reserved", NULL); + usbRecipient = parseEnum(argv[3], "device", "interface", "endpoint", "other", NULL); + usbRequest = myAtoi(argv[4]); + usbValue = myAtoi(argv[5]); + usbIndex = myAtoi(argv[6]); + requestType = ((usbDirection & 1) << 7) | ((usbType & 3) << 5) | (usbRecipient & 0x1f); + if(usbDirection){ /* IN transfer */ + len = usb_control_msg(handle, requestType, usbRequest, usbValue, usbIndex, rxBuffer, usbCount, usbTimeout); + }else{ /* OUT transfer */ + len = usb_control_msg(handle, requestType, usbRequest, usbValue, usbIndex, sendBytes, sendByteCount, usbTimeout); + } + }else{ /* must be ACTION_INTERRUPT or ACTION_BULK */ + int retries = 1; + if(usb_set_configuration(handle, usbConfiguration) && showWarnings){ + fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror()); + } + /* now try to claim the interface and detach the kernel HID driver on + * linux and other operating systems which support the call. + */ + while((len = usb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){ +#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP + if(usb_detach_kernel_driver_np(handle, 0) < 0 && showWarnings){ + fprintf(stderr, "Warning: could not detach kernel driver: %s\n", usb_strerror()); + } +#endif + } + if(len != 0 && showWarnings) + fprintf(stderr, "Warning: could not claim interface: %s\n", usb_strerror()); + if(action == ACTION_INTERRUPT){ + if(usbDirection){ /* IN transfer */ + len = usb_interrupt_read(handle, endpoint, rxBuffer, usbCount, usbTimeout); + }else{ + len = usb_interrupt_write(handle, endpoint, sendBytes, sendByteCount, usbTimeout); + } + }else{ + if(usbDirection){ /* IN transfer */ + len = usb_bulk_read(handle, endpoint, rxBuffer, usbCount, usbTimeout); + }else{ + len = usb_bulk_write(handle, endpoint, sendBytes, sendByteCount, usbTimeout); + } + } + } + if(len < 0){ + fprintf(stderr, "USB error: %s\n", usb_strerror()); + exit(1); + } + if(usbDirection == 0) /* OUT */ + printf("%d bytes sent.\n", len); + if(rxBuffer != NULL){ + FILE *fp = stdout; + if(outputFile != NULL){ + fp = fopen(outputFile, outputFormatIsBinary ? "wb" : "w"); + if(fp == NULL){ + fprintf(stderr, "Error writing \"%s\": %s\n", outputFile, strerror(errno)); + exit(1); + } + } + if(outputFormatIsBinary){ + fwrite(rxBuffer, 1, len, fp); + }else{ + int i; + for(i = 0; i < len; i++){ + if(i != 0){ + if(i % 16 == 0){ + fprintf(fp, "\n"); + }else{ + fprintf(fp, " "); + } + } + fprintf(fp, "0x%02x", rxBuffer[i] & 0xff); + } + if(i != 0) + fprintf(fp, "\n"); + } + } + usb_close(handle); + if(rxBuffer != NULL) + free(rxBuffer); + return 0; +} diff --git a/adb2usb/uart2usb/vusb-20100715/libs-device/Readme.txt b/adb2usb/uart2usb/vusb-20100715/libs-device/Readme.txt new file mode 100644 index 0000000..76518dc --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-device/Readme.txt @@ -0,0 +1,22 @@ +This is the Readme file for the libs-device directory. This directory contains +code snippets which may be useful for USB device firmware. + + +WHAT IS INCLUDED IN THIS DIRECTORY? +=================================== + +osccal.c and osccal.h + This module contains a function which calibrates the AVR's built-in RC + oscillator based on the USB frame clock. See osccal.h for a documentation + of the API. + +osctune.h + This header file contains a code snippet for usbconfig.h. With this code, + you can keep the AVR's internal RC oscillator in sync with the USB frame + clock. This is a continuous synchronization, not a single calibration at + USB reset as with osccal.c above. Please note that this code works only + if D- is wired to the interrupt, not D+. + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/libs-device/osccal.c b/adb2usb/uart2usb/vusb-20100715/libs-device/osccal.c new file mode 100644 index 0000000..939d5c3 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-device/osccal.c @@ -0,0 +1,63 @@ +/* Name: osccal.c + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: osccal.c 762 2009-08-12 17:10:30Z cs $ + */ + +#include + +#ifndef uchar +#define uchar unsigned char +#endif + +/* ------------------------------------------------------------------------- */ +/* ------------------------ Oscillator Calibration ------------------------- */ +/* ------------------------------------------------------------------------- */ + +/* Calibrate the RC oscillator. Our timing reference is the Start Of Frame + * signal (a single SE0 bit) repeating every millisecond immediately after + * a USB RESET. We first do a binary search for the OSCCAL value and then + * optimize this value with a neighboorhod search. + */ +void calibrateOscillator(void) +{ +uchar step = 128; +uchar trialValue = 0, optimumValue; +int x, optimumDev, targetValue = (unsigned)(1499 * (double)F_CPU / 10.5e6 + 0.5); + + /* do a binary search: */ + do{ + OSCCAL = trialValue + step; + x = usbMeasureFrameLength(); /* proportional to current real frequency */ + if(x < targetValue) /* frequency still too low */ + trialValue += step; + step >>= 1; + }while(step > 0); + /* We have a precision of +/- 1 for optimum OSCCAL here */ + /* now do a neighborhood search for optimum value */ + optimumValue = trialValue; + optimumDev = x; /* this is certainly far away from optimum */ + for(OSCCAL = trialValue - 1; OSCCAL <= trialValue + 1; OSCCAL++){ + x = usbMeasureFrameLength() - targetValue; + if(x < 0) + x = -x; + if(x < optimumDev){ + optimumDev = x; + optimumValue = OSCCAL; + } + } + OSCCAL = optimumValue; +} +/* +Note: This calibration algorithm may try OSCCAL values of up to 192 even if +the optimum value is far below 192. It may therefore exceed the allowed clock +frequency of the CPU in low voltage designs! +You may replace this search algorithm with any other algorithm you like if +you have additional constraints such as a maximum CPU clock. +For version 5.x RC oscillators (those with a split range of 2x128 steps, e.g. +ATTiny25, ATTiny45, ATTiny85), it may be useful to search for the optimum in +both regions. +*/ diff --git a/adb2usb/uart2usb/vusb-20100715/libs-device/osccal.h b/adb2usb/uart2usb/vusb-20100715/libs-device/osccal.h new file mode 100644 index 0000000..777dfb2 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-device/osccal.h @@ -0,0 +1,63 @@ +/* Name: osccal.h + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: osccal.h 762 2009-08-12 17:10:30Z cs $ + */ + +/* +General Description: +This module contains a function which calibrates the AVR's internal RC +oscillator so that the CPU runs at F_CPU (F_CPU is a macro which must be +defined when the module is compiled, best passed in the compiler command +line). The time reference is the USB frame clock of 1 kHz available +immediately after a USB RESET condition. Timing is done by counting CPU +cycles, so all interrupts must be disabled while the calibration runs. For +low level timing measurements, usbMeasureFrameLength() is called. This +function must be enabled in usbconfig.h by defining +USB_CFG_HAVE_MEASURE_FRAME_LENGTH to 1. It is recommended to call +calibrateOscillator() from the reset hook in usbconfig.h: + +#ifndef __ASSEMBLER__ +#include // for sei() +extern void calibrateOscillator(void); +#endif +#define USB_RESET_HOOK(resetStarts) if(!resetStarts){cli(); calibrateOscillator(); sei();} + +This routine is an alternative to the continuous synchronization described +in osctune.h. + +Algorithm used: +calibrateOscillator() first does a binary search in the OSCCAL register for +the best matching oscillator frequency. Then it does a next neighbor search +to find the value with the lowest clock rate deviation. It is guaranteed to +find the best match among neighboring values, but for version 5 oscillators +(which have a discontinuous relationship between OSCCAL and frequency) a +better match might be available in another OSCCAL region. + +Limitations: +This calibration algorithm may try OSCCAL values of up to 192 even if the +optimum value is far below 192. It may therefore exceed the allowed clock +frequency of the CPU in low voltage designs! +Precision depends on the OSCCAL vs. frequency dependency of the oscillator. +Typical precision for an ATMega168 (derived from the OSCCAL vs. F_RC diagram +in the data sheet) should be in the range of 0.4%. Only the 12.8 MHz and +16.5 MHz versions of V-USB (with built-in receiver PLL) can tolerate this +deviation! All other frequency modules require at least 0.2% precision. +*/ + +#ifndef __OSCCAL_H_INCLUDED__ +#define __OSCCAL_H_INCLUDED__ + +void calibrateOscillator(void); +/* This function calibrates the RC oscillator so that the CPU runs at F_CPU. + * It MUST be called immediately after the end of a USB RESET condition! + * Disable all interrupts during the call! + * It is recommended that you store the resulting value in EEPROM so that a + * good guess value is available after the next reset. + */ + + +#endif /* __OSCCAL_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/libs-device/osctune.h b/adb2usb/uart2usb/vusb-20100715/libs-device/osctune.h new file mode 100644 index 0000000..c751648 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-device/osctune.h @@ -0,0 +1,88 @@ +/* Name: osctune.h + * Author: Christian Starkjohann + * Creation Date: 2008-10-18 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: osctune.h 692 2008-11-07 15:07:40Z cs $ + */ + +/* +General Description: +This file is declared as C-header file although it is mostly documentation +how the RC oscillator can be kept in sync to the USB frame rate. The code +shown here must be added to usbconfig.h or this header file is included from +there. This code works only if D- is wired to the interrupt, not D+!!! + +This is an alternative to the osccal routine in osccal.c. It has the advantage +that the synchronization is done continuously and that it has more compact +code size. The disadvantages are slow synchronization (it may take a while +until the driver works), that messages immediately after the SOF pulse may be +lost (and need to be retried by the host) and that the interrupt is on D- +contrary to most examples. + +You may want to store a good calibration value in EEPROM for the next startup. +You know that the calibration value is good when the first USB message is +received. Do not store the value on every received message because the EEPROM +has a limited endurance. + +Notes: +(*) You must declare the global character variable "lastTimer0Value" in your +main code. + +(*) Timer 0 must be free running (not written by your code) and the prescaling +must be consistent with the TIMER0_PRESCALING define. + +(*) Good values for Timer 0 prescaling depend on how precise the clock must +be tuned and how far away from the default clock rate the target clock is. +For precise tuning, choose a low prescaler factor, for a broad range of tuning +choose a high one. A prescaler factor of 64 is good for the entire OSCCAL +range and allows a precision of better than +/-1%. A prescaler factor of 8 +allows tuning to slightly more than +/-6% of the default frequency and is +more precise than one step of OSCCAL. It is therefore not suitable to tune an +8 MHz oscillator to 12.5 MHz. + +Thanks to Henrik Haftmann for the idea to this routine! +*/ + +#define TIMER0_PRESCALING 64 /* must match the configuration for TIMER0 in main */ +#define TOLERATED_DEVIATION_PPT 5 /* max clock deviation before we tune in 1/10 % */ +/* derived constants: */ +#define EXPECTED_TIMER0_INCREMENT ((F_CPU / (1000 * TIMER0_PRESCALING)) & 0xff) +#define TOLERATED_DEVIATION (TOLERATED_DEVIATION_PPT * F_CPU / (1000000 * TIMER0_PRESCALING)) + +#ifdef __ASSEMBLER__ +macro tuneOsccal + push YH ;[0] + in YL, TCNT0 ;[2] + lds YH, lastTimer0Value ;[3] + sts lastTimer0Value, YL ;[5] + sub YL, YH ;[7] time passed since last frame + subi YL, EXPECTED_TIMER0_INCREMENT ;[8] +#if OSCCAL > 0x3f /* outside I/O addressable range */ + lds YH, OSCCAL ;[6] +#else + in YH, OSCCAL ;[6] assembler modle uses __SFR_OFFSET == 0 +#endif + cpi YL, TOLERATED_DEVIATION + 1 ;[10] + brmi notTooHigh ;[11] + subi YH, 1 ;[12] clock rate was too high +; brcs tuningOverflow ; optionally check for overflow + rjmp osctuneDone ;[13] +notTooHigh: + cpi YL, -TOLERATED_DEVIATION ;[13] + brpl osctuneDone ;[14] not too low + inc YH ;[15] clock rate was too low +; breq tuningOverflow ; optionally check for overflow +osctuneDone: +#if OSCCAL > 0x3f /* outside I/O addressable range */ + sts OSCCAL, YH ;[12-13] store tuned value +#else + out OSCCAL, YH ;[12-13] store tuned value +#endif +tuningOverflow: + pop YH ;[17] + endm ;[19] max number of cycles +#endif + +#define USB_SOF_HOOK tuneOsccal diff --git a/adb2usb/uart2usb/vusb-20100715/libs-host/Readme.txt b/adb2usb/uart2usb/vusb-20100715/libs-host/Readme.txt new file mode 100644 index 0000000..5117d18 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-host/Readme.txt @@ -0,0 +1,26 @@ +This is the Readme file for the libs-host directory. This directory contains +code snippets which may be useful for host side USB software. + + +WHAT IS INCLUDED IN THIS DIRECTORY? +=================================== + +opendevice.c and opendevice.h + This module contains a function to find and open a device given its + numeric IDs (VID, PID), names (vendor name and product name) and serial + number. It is based on libusb/libusb-win32 and returns a libusb device + handle. See opendevice.h for an API documentation. + +hiddata.c and hiddata.h + This module contains functions for data transfer over HID feature reports. + It is based on libusb on Unix and native Windows functions on Windows. No + driver DLL is needed on Windows. See hiddata.h for an API documentation. + +hidsdi.h + This DDK header file is missing in the free MinGW version of the Windows + DDK. Use this version if you get an "include file not found" error. + + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/libs-host/hiddata.c b/adb2usb/uart2usb/vusb-20100715/libs-host/hiddata.c new file mode 100644 index 0000000..93795e4 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-host/hiddata.c @@ -0,0 +1,324 @@ +/* Name: hiddata.c + * Author: Christian Starkjohann + * Creation Date: 2008-04-11 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: hiddata.c 743 2009-04-15 15:00:49Z cs $ + */ + +#include +#include "hiddata.h" + +/* ######################################################################## */ +#if defined(WIN32) /* ##################################################### */ +/* ######################################################################## */ + +#include +#include +#include "hidsdi.h" +#include + +#ifdef DEBUG +#define DEBUG_PRINT(arg) printf arg +#else +#define DEBUG_PRINT(arg) +#endif + +/* ------------------------------------------------------------------------ */ + +static void convertUniToAscii(char *buffer) +{ +unsigned short *uni = (void *)buffer; +char *ascii = buffer; + + while(*uni != 0){ + if(*uni >= 256){ + *ascii++ = '?'; + }else{ + *ascii++ = *uni++; + } + } + *ascii++ = 0; +} + +int usbhidOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int usesReportIDs) +{ +GUID hidGuid; /* GUID for HID driver */ +HDEVINFO deviceInfoList; +SP_DEVICE_INTERFACE_DATA deviceInfo; +SP_DEVICE_INTERFACE_DETAIL_DATA *deviceDetails = NULL; +DWORD size; +int i, openFlag = 0; /* may be FILE_FLAG_OVERLAPPED */ +int errorCode = USBOPEN_ERR_NOTFOUND; +HANDLE handle = INVALID_HANDLE_VALUE; +HIDD_ATTRIBUTES deviceAttributes; + + HidD_GetHidGuid(&hidGuid); + deviceInfoList = SetupDiGetClassDevs(&hidGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); + deviceInfo.cbSize = sizeof(deviceInfo); + for(i=0;;i++){ + if(handle != INVALID_HANDLE_VALUE){ + CloseHandle(handle); + handle = INVALID_HANDLE_VALUE; + } + if(!SetupDiEnumDeviceInterfaces(deviceInfoList, 0, &hidGuid, i, &deviceInfo)) + break; /* no more entries */ + /* first do a dummy call just to determine the actual size required */ + SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, NULL, 0, &size, NULL); + if(deviceDetails != NULL) + free(deviceDetails); + deviceDetails = malloc(size); + deviceDetails->cbSize = sizeof(*deviceDetails); + /* this call is for real: */ + SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, deviceDetails, size, &size, NULL); + DEBUG_PRINT(("checking HID path \"%s\"\n", deviceDetails->DevicePath)); +#if 0 + /* If we want to access a mouse our keyboard, we can only use feature + * requests as the device is locked by Windows. It must be opened + * with ACCESS_TYPE_NONE. + */ + handle = CreateFile(deviceDetails->DevicePath, ACCESS_TYPE_NONE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); +#endif + /* attempt opening for R/W -- we don't care about devices which can't be accessed */ + handle = CreateFile(deviceDetails->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); + if(handle == INVALID_HANDLE_VALUE){ + DEBUG_PRINT(("opening failed: %d\n", (int)GetLastError())); + /* errorCode = USBOPEN_ERR_ACCESS; opening will always fail for mouse -- ignore */ + continue; + } + deviceAttributes.Size = sizeof(deviceAttributes); + HidD_GetAttributes(handle, &deviceAttributes); + DEBUG_PRINT(("device attributes: vid=%d pid=%d\n", deviceAttributes.VendorID, deviceAttributes.ProductID)); + if(deviceAttributes.VendorID != vendor || deviceAttributes.ProductID != product) + continue; /* ignore this device */ + errorCode = USBOPEN_ERR_NOTFOUND; + if(vendorName != NULL && productName != NULL){ + char buffer[512]; + if(!HidD_GetManufacturerString(handle, buffer, sizeof(buffer))){ + DEBUG_PRINT(("error obtaining vendor name\n")); + errorCode = USBOPEN_ERR_IO; + continue; + } + convertUniToAscii(buffer); + DEBUG_PRINT(("vendorName = \"%s\"\n", buffer)); + if(strcmp(vendorName, buffer) != 0) + continue; + if(!HidD_GetProductString(handle, buffer, sizeof(buffer))){ + DEBUG_PRINT(("error obtaining product name\n")); + errorCode = USBOPEN_ERR_IO; + continue; + } + convertUniToAscii(buffer); + DEBUG_PRINT(("productName = \"%s\"\n", buffer)); + if(strcmp(productName, buffer) != 0) + continue; + } + break; /* we have found the device we are looking for! */ + } + SetupDiDestroyDeviceInfoList(deviceInfoList); + if(deviceDetails != NULL) + free(deviceDetails); + if(handle != INVALID_HANDLE_VALUE){ + *device = (usbDevice_t *)handle; + errorCode = 0; + } + return errorCode; +} + +/* ------------------------------------------------------------------------ */ + +void usbhidCloseDevice(usbDevice_t *device) +{ + CloseHandle((HANDLE)device); +} + +/* ------------------------------------------------------------------------ */ + +int usbhidSetReport(usbDevice_t *device, char *buffer, int len) +{ +BOOLEAN rval; + + rval = HidD_SetFeature((HANDLE)device, buffer, len); + return rval == 0 ? USBOPEN_ERR_IO : 0; +} + +/* ------------------------------------------------------------------------ */ + +int usbhidGetReport(usbDevice_t *device, int reportNumber, char *buffer, int *len) +{ +BOOLEAN rval = 0; + + buffer[0] = reportNumber; + rval = HidD_GetFeature((HANDLE)device, buffer, *len); + return rval == 0 ? USBOPEN_ERR_IO : 0; +} + +/* ------------------------------------------------------------------------ */ + +/* ######################################################################## */ +#else /* defined WIN32 #################################################### */ +/* ######################################################################## */ + +#include +#include + +#define usbDevice usb_dev_handle /* use libusb's device structure */ + +/* ------------------------------------------------------------------------- */ + +#define USBRQ_HID_GET_REPORT 0x01 +#define USBRQ_HID_SET_REPORT 0x09 + +#define USB_HID_REPORT_TYPE_FEATURE 3 + + +static int usesReportIDs; + +/* ------------------------------------------------------------------------- */ + +static int usbhidGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) +{ +char buffer[256]; +int rval, i; + + if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ + return rval; + if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) + return rval; + if(buffer[1] != USB_DT_STRING){ + *buf = 0; + return 0; + } + if((unsigned char)buffer[0] < rval) + rval = (unsigned char)buffer[0]; + rval /= 2; + /* lossy conversion to ISO Latin1: */ + for(i=1;i buflen) /* destination buffer overflow */ + break; + buf[i-1] = buffer[2 * i]; + if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ + buf[i-1] = '?'; + } + buf[i-1] = 0; + return i-1; +} + +int usbhidOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int _usesReportIDs) +{ +struct usb_bus *bus; +struct usb_device *dev; +usb_dev_handle *handle = NULL; +int errorCode = USBOPEN_ERR_NOTFOUND; +static int didUsbInit = 0; + + if(!didUsbInit){ + usb_init(); + didUsbInit = 1; + } + usb_find_busses(); + usb_find_devices(); + for(bus=usb_get_busses(); bus; bus=bus->next){ + for(dev=bus->devices; dev; dev=dev->next){ + if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product){ + char string[256]; + int len; + handle = usb_open(dev); /* we need to open the device in order to query strings */ + if(!handle){ + errorCode = USBOPEN_ERR_ACCESS; + fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror()); + continue; + } + if(vendorName == NULL && productName == NULL){ /* name does not matter */ + break; + } + /* now check whether the names match: */ + len = usbhidGetStringAscii(handle, dev->descriptor.iManufacturer, string, sizeof(string)); + if(len < 0){ + errorCode = USBOPEN_ERR_IO; + fprintf(stderr, "Warning: cannot query manufacturer for device: %s\n", usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* fprintf(stderr, "seen device from vendor ->%s<-\n", string); */ + if(strcmp(string, vendorName) == 0){ + len = usbhidGetStringAscii(handle, dev->descriptor.iProduct, string, sizeof(string)); + if(len < 0){ + errorCode = USBOPEN_ERR_IO; + fprintf(stderr, "Warning: cannot query product for device: %s\n", usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* fprintf(stderr, "seen product ->%s<-\n", string); */ + if(strcmp(string, productName) == 0) + break; + } + } + } + usb_close(handle); + handle = NULL; + } + } + if(handle) + break; + } + if(handle != NULL){ + errorCode = 0; + *device = (void *)handle; + usesReportIDs = _usesReportIDs; + } + return errorCode; +} + +/* ------------------------------------------------------------------------- */ + +void usbhidCloseDevice(usbDevice_t *device) +{ + if(device != NULL) + usb_close((void *)device); +} + +/* ------------------------------------------------------------------------- */ + +int usbhidSetReport(usbDevice_t *device, char *buffer, int len) +{ +int bytesSent; + + if(!usesReportIDs){ + buffer++; /* skip dummy report ID */ + len--; + } + bytesSent = usb_control_msg((void *)device, USB_TYPE_CLASS | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USBRQ_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8 | (buffer[0] & 0xff), 0, buffer, len, 5000); + if(bytesSent != len){ + if(bytesSent < 0) + fprintf(stderr, "Error sending message: %s\n", usb_strerror()); + return USBOPEN_ERR_IO; + } + return 0; +} + +/* ------------------------------------------------------------------------- */ + +int usbhidGetReport(usbDevice_t *device, int reportNumber, char *buffer, int *len) +{ +int bytesReceived, maxLen = *len; + + if(!usesReportIDs){ + buffer++; /* make room for dummy report ID */ + maxLen--; + } + bytesReceived = usb_control_msg((void *)device, USB_TYPE_CLASS | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8 | reportNumber, 0, buffer, maxLen, 5000); + if(bytesReceived < 0){ + fprintf(stderr, "Error sending message: %s\n", usb_strerror()); + return USBOPEN_ERR_IO; + } + *len = bytesReceived; + if(!usesReportIDs){ + buffer[-1] = reportNumber; /* add dummy report ID */ + (*len)++; + } + return 0; +} + +/* ######################################################################## */ +#endif /* defined WIN32 ################################################### */ +/* ######################################################################## */ diff --git a/adb2usb/uart2usb/vusb-20100715/libs-host/hiddata.h b/adb2usb/uart2usb/vusb-20100715/libs-host/hiddata.h new file mode 100644 index 0000000..fce0743 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-host/hiddata.h @@ -0,0 +1,71 @@ +/* Name: hiddata.h + * Author: Christian Starkjohann + * Creation Date: 2008-04-11 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: hiddata.h 692 2008-11-07 15:07:40Z cs $ + */ + +#ifndef __HIDDATA_H_INCLUDED__ +#define __HIDDATA_H_INCLUDED__ + +/* +General Description: +This module implements an abstraction layer for data transfer over HID feature +requests. The implementation uses native Windows functions on Windows so that +no driver installation is required and libusb on Unix. You must link the +appropriate libraries in either case: "-lhid -lusb -lsetupapi" on Windows and +`libusb-config --libs` on Unix. +*/ + +/* ------------------------------------------------------------------------ */ + +#define USBOPEN_SUCCESS 0 /* no error */ +#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ +#define USBOPEN_ERR_IO 2 /* I/O error */ +#define USBOPEN_ERR_NOTFOUND 3 /* device not found */ + +/* ------------------------------------------------------------------------ */ + +typedef struct usbDevice usbDevice_t; +/* Opaque data type representing the USB device. This can be a Windows handle + * or a libusb handle, depending on the backend implementation. + */ + +/* ------------------------------------------------------------------------ */ + +int usbhidOpenDevice(usbDevice_t **device, int vendorID, char *vendorName, int productID, char *productName, int usesReportIDs); +/* This function opens a USB device. 'vendorID' and 'productID' are the numeric + * Vendor-ID and Product-ID of the device we want to open. If 'vendorName' and + * 'productName' are both not NULL, only devices with matching manufacturer- + * and product name strings are accepted. If the device uses report IDs, + * 'usesReportIDs' must be set to a non-zero value. + * Returns: If a matching device has been found, USBOPEN_SUCCESS is returned + * and '*device' is set to an opaque pointer representing the device. The + * device must be closed with usbhidCloseDevice(). If the device has not been + * found or opening failed, an error code is returned. + */ +void usbhidCloseDevice(usbDevice_t *device); +/* Every device opened with usbhidOpenDevice() must be closed with this function. + */ +int usbhidSetReport(usbDevice_t *device, char *buffer, int len); +/* This function sends a feature report to the device. The report ID must be + * in the first byte of buffer and the length 'len' of the report is specified + * including this report ID. If no report IDs are used, buffer[0] must be set + * to 0 (dummy report ID). + * Returns: 0 on success, an error code otherwise. + */ +int usbhidGetReport(usbDevice_t *device, int reportID, char *buffer, int *len); +/* This function obtains a feature report from the device. The requested + * report-ID is passed in 'reportID'. The caller must pass a buffer of the size + * of the expected report in 'buffer' and initialize the variable pointed to by + * 'len' to the total size of this buffer. Upon successful return, the report + * (prefixed with the report-ID) is in 'buffer' and the actual length of the + * report is returned in '*len'. + * Returns: 0 on success, an error code otherwise. + */ + +/* ------------------------------------------------------------------------ */ + +#endif /* __HIDDATA_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/libs-host/hidsdi.h b/adb2usb/uart2usb/vusb-20100715/libs-host/hidsdi.h new file mode 100644 index 0000000..a549ab1 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-host/hidsdi.h @@ -0,0 +1,49 @@ +/* Name: hidsdi.h + * Author: Christian Starkjohann + * Creation Date: 2006-02-02 + * Tabsize: 4 + * Copyright: (c) 2006-2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: hidsdi.h 692 2008-11-07 15:07:40Z cs $ + */ + +/* +General Description +This file is a replacement for hidsdi.h from the Windows DDK. It defines some +of the types and function prototypes of this header for our project. If you +have the Windows DDK version of this file or a version shipped with MinGW, use +that instead. +*/ + +#ifndef _HIDSDI_H +#define _HIDSDI_H + +#include + +#include +#include + +typedef struct{ + ULONG Size; + USHORT VendorID; + USHORT ProductID; + USHORT VersionNumber; +}HIDD_ATTRIBUTES; + +void __stdcall HidD_GetHidGuid(OUT LPGUID hidGuid); + +BOOLEAN __stdcall HidD_GetAttributes(IN HANDLE device, OUT HIDD_ATTRIBUTES *attributes); + +BOOLEAN __stdcall HidD_GetManufacturerString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); +BOOLEAN __stdcall HidD_GetProductString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); +BOOLEAN __stdcall HidD_GetSerialNumberString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); + +BOOLEAN __stdcall HidD_GetFeature(IN HANDLE device, OUT void *reportBuffer, IN ULONG bufferLen); +BOOLEAN __stdcall HidD_SetFeature(IN HANDLE device, IN void *reportBuffer, IN ULONG bufferLen); + +BOOLEAN __stdcall HidD_GetNumInputBuffers(IN HANDLE device, OUT ULONG *numBuffers); +BOOLEAN __stdcall HidD_SetNumInputBuffers(IN HANDLE device, OUT ULONG numBuffers); + +#include + +#endif diff --git a/adb2usb/uart2usb/vusb-20100715/libs-host/opendevice.c b/adb2usb/uart2usb/vusb-20100715/libs-host/opendevice.c new file mode 100644 index 0000000..137f50c --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-host/opendevice.c @@ -0,0 +1,203 @@ +/* Name: opendevice.c + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.c 740 2009-04-13 18:23:31Z cs $ + */ + +/* +General Description: +The functions in this module can be used to find and open a device based on +libusb or libusb-win32. +*/ + +#include +#include "opendevice.h" + +/* ------------------------------------------------------------------------- */ + +#define MATCH_SUCCESS 1 +#define MATCH_FAILED 0 +#define MATCH_ABORT -1 + +/* private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or MATCH_ABORT. */ +static int _shellStyleMatch(char *text, char *p) +{ +int last, matched, reverse; + + for(; *p; text++, p++){ + if(*text == 0 && *p != '*') + return MATCH_ABORT; + switch(*p){ + case '\\': + /* Literal match with following character. */ + p++; + /* FALLTHROUGH */ + default: + if(*text != *p) + return MATCH_FAILED; + continue; + case '?': + /* Match anything. */ + continue; + case '*': + while(*++p == '*') + /* Consecutive stars act just like one. */ + continue; + if(*p == 0) + /* Trailing star matches everything. */ + return MATCH_SUCCESS; + while(*text) + if((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED) + return matched; + return MATCH_ABORT; + case '[': + reverse = p[1] == '^'; + if(reverse) /* Inverted character class. */ + p++; + matched = MATCH_FAILED; + if(p[1] == ']' || p[1] == '-') + if(*++p == *text) + matched = MATCH_SUCCESS; + for(last = *p; *++p && *p != ']'; last = *p) + if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p) + matched = MATCH_SUCCESS; + if(matched == reverse) + return MATCH_FAILED; + continue; + } + } + return *text == 0; +} + +/* public interface for shell style matching: returns 0 if fails, 1 if matches */ +static int shellStyleMatch(char *text, char *pattern) +{ + if(pattern == NULL) /* NULL pattern is synonymous to "*" */ + return 1; + return _shellStyleMatch(text, pattern) == MATCH_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) +{ +char buffer[256]; +int rval, i; + + if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ + return rval; + if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) + return rval; + if(buffer[1] != USB_DT_STRING){ + *buf = 0; + return 0; + } + if((unsigned char)buffer[0] < rval) + rval = (unsigned char)buffer[0]; + rval /= 2; + /* lossy conversion to ISO Latin1: */ + for(i=1;i buflen) /* destination buffer overflow */ + break; + buf[i-1] = buffer[2 * i]; + if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ + buf[i-1] = '?'; + } + buf[i-1] = 0; + return i-1; +} + +/* ------------------------------------------------------------------------- */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp) +{ +struct usb_bus *bus; +struct usb_device *dev; +usb_dev_handle *handle = NULL; +int errorCode = USBOPEN_ERR_NOTFOUND; + + usb_find_busses(); + usb_find_devices(); + for(bus = usb_get_busses(); bus; bus = bus->next){ + for(dev = bus->devices; dev; dev = dev->next){ /* iterate over all devices on all busses */ + if((vendorID == 0 || dev->descriptor.idVendor == vendorID) + && (productID == 0 || dev->descriptor.idProduct == productID)){ + char vendor[256], product[256], serial[256]; + int len; + handle = usb_open(dev); /* we need to open the device in order to query strings */ + if(!handle){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot open VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + continue; + } + /* now check whether the names match: */ + len = vendor[0] = 0; + if(dev->descriptor.iManufacturer > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, vendor, sizeof(vendor)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen device from vendor ->%s<-\n", vendor); */ + if(shellStyleMatch(vendor, vendorNamePattern)){ + len = product[0] = 0; + if(dev->descriptor.iProduct > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iProduct, product, sizeof(product)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + }else{ + errorCode = USBOPEN_ERR_NOTFOUND; + /* printf("seen product ->%s<-\n", product); */ + if(shellStyleMatch(product, productNamePattern)){ + len = serial[0] = 0; + if(dev->descriptor.iSerialNumber > 0){ + len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, serial, sizeof(serial)); + } + if(len < 0){ + errorCode = USBOPEN_ERR_ACCESS; + if(warningsFp != NULL) + fprintf(warningsFp, "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); + } + if(shellStyleMatch(serial, serialNamePattern)){ + if(printMatchingDevicesFp != NULL){ + if(serial[0] == 0){ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product); + }else{ + fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product, serial); + } + }else{ + break; + } + } + } + } + } + } + usb_close(handle); + handle = NULL; + } + } + if(handle) /* we have found a deice */ + break; + } + if(handle != NULL){ + errorCode = 0; + *device = handle; + } + if(printMatchingDevicesFp != NULL) /* never return an error for listing only */ + errorCode = 0; + return errorCode; +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/libs-host/opendevice.h b/adb2usb/uart2usb/vusb-20100715/libs-host/opendevice.h new file mode 100644 index 0000000..79c12f6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/libs-host/opendevice.h @@ -0,0 +1,77 @@ +/* Name: opendevice.h + * Project: V-USB host-side library + * Author: Christian Starkjohann + * Creation Date: 2008-04-10 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: opendevice.h 755 2009-08-03 17:01:21Z cs $ + */ + +/* +General Description: +This module offers additional functionality for host side drivers based on +libusb or libusb-win32. It includes a function to find and open a device +based on numeric IDs and textual description. It also includes a function to +obtain textual descriptions from a device. + +To use this functionality, simply copy opendevice.c and opendevice.h into your +project and add them to your Makefile. You may modify and redistribute these +files according to the GNU General Public License (GPL) version 2 or 3. +*/ + +#ifndef __OPENDEVICE_H_INCLUDED__ +#define __OPENDEVICE_H_INCLUDED__ + +#include /* this is libusb, see http://libusb.sourceforge.net/ */ +#include + +int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen); +/* This function gets a string descriptor from the device. 'index' is the + * string descriptor index. The string is returned in ISO Latin 1 encoding in + * 'buf' and it is terminated with a 0-character. The buffer size must be + * passed in 'buflen' to prevent buffer overflows. A libusb device handle + * must be given in 'dev'. + * Returns: The length of the string (excluding the terminating 0) or + * a negative number in case of an error. If there was an error, use + * usb_strerror() to obtain the error message. + */ + +int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp); +/* This function iterates over all devices on all USB busses and searches for + * a device. Matching is done first by means of Vendor- and Product-ID (passed + * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard). + * When a device matches by its IDs, matching by names is performed. Name + * matching can be done on textual vendor name ('vendorNamePattern'), product + * name ('productNamePattern') and serial number ('serialNamePattern'). A + * device matches only if all non-null pattern match. If you don't care about + * a string, pass NULL for the pattern. Patterns are Unix shell style pattern: + * '*' stands for 0 or more characters, '?' for one single character, a list + * of characters in square brackets for a single character from the list + * (dashes are allowed to specify a range) and if the lis of characters begins + * with a caret ('^'), it matches one character which is NOT in the list. + * Other parameters to the function: If 'warningsFp' is not NULL, warning + * messages are printed to this file descriptor with fprintf(). If + * 'printMatchingDevicesFp' is not NULL, no device is opened but matching + * devices are printed to the given file descriptor with fprintf(). + * If a device is opened, the resulting USB handle is stored in '*device'. A + * pointer to a "usb_dev_handle *" type variable must be passed here. + * Returns: 0 on success, an error code (see defines below) on failure. + */ + +/* usbOpenDevice() error codes: */ +#define USBOPEN_SUCCESS 0 /* no error */ +#define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ +#define USBOPEN_ERR_IO 2 /* I/O error */ +#define USBOPEN_ERR_NOTFOUND 3 /* device not found */ + + +/* Obdev's free USB IDs, see USB-IDs-for-free.txt for details */ + +#define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */ +#define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */ +#define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */ +#define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */ +#define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */ + +#endif /* __OPENDEVICE_H_INCLUDED__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/tests/Makefile b/adb2usb/uart2usb/vusb-20100715/tests/Makefile new file mode 100644 index 0000000..74b2518 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/Makefile @@ -0,0 +1,127 @@ +# Name: Makefile +# Project: custom-class example +# Author: Christian Starkjohann +# Creation Date: 2008-04-07 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id: Makefile 719 2009-03-16 18:51:56Z cs $ + +DEVICE = attiny2313 +F_CPU = 16000000 # in Hz +DEFINES = + +CFLAGS = $(DEFINES) -Iusbdrv -I. -DDEBUG_LEVEL=0 +OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o + +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) + +SIZES_TMP = /tmp/sizetmp.txt + +# symbolic targets: +help: + @echo "This Makefile has no default rule. Use one of the following:" + @echo "make clean ..... to delete objects and hex file" + @echo "make sizes ..... compute code and RAM sizes for various options" + @echo "make test ...... test with all features whether everything compiles" + +sizes sizes.txt: + rm -f $(SIZES_TMP) sizes.txt + $(MAKE) null.elf + avr-size null.elf | tail -1 | awk '{print "null", $$1+$$2, $$3+$$2}' >$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf + avr-size main.elf | tail -1 | awk '{print "Minimum_with_16_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf F_CPU=12000000 + avr-size main.elf | tail -1 | awk '{print "Minimum_with_12_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf F_CPU=12800000 + avr-size main.elf | tail -1 | awk '{print "Minimum_with_12_8_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf F_CPU=15000000 + avr-size main.elf | tail -1 | awk '{print "Minimum_with_15_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf F_CPU=16500000 + avr-size main.elf | tail -1 | awk '{print "Minimum_with_16_5_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf F_CPU=18000000 + avr-size main.elf | tail -1 | awk '{print "Minimum_with_18_MHz+CRC", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf F_CPU=20000000 + avr-size main.elf | tail -1 | awk '{print "Minimum_with_20_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf DEFINES=-DUSB_CFG_IMPLEMENT_FN_WRITE=1 + avr-size main.elf | tail -1 | awk '{print "With_usbFunctionWrite", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf DEFINES=-DUSB_CFG_IMPLEMENT_FN_READ=1 + avr-size main.elf | tail -1 | awk '{print "With_usbFunctionRead", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_IMPLEMENT_FN_READ=1 -DUSB_CFG_IMPLEMENT_FN_WRITE=1" + avr-size main.elf | tail -1 | awk '{print "With_usbFunctionRead_and_Write", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_IMPLEMENT_FN_WRITEOUT=1" + avr-size main.elf | tail -1 | awk '{print "With_usbFunctionWriteOut", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_HAVE_INTRIN_ENDPOINT=1" + avr-size main.elf | tail -1 | awk '{print "With_Interrupt_In_Endpoint_1", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_IMPLEMENT_HALT=1 -DUSB_CFG_HAVE_INTRIN_ENDPOINT=1" + avr-size main.elf | tail -1 | awk '{print "With_Interrupt_In_Endpoint_1_and_Halt", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_HAVE_INTRIN_ENDPOINT3=1" + avr-size main.elf | tail -1 | awk '{print "With_Interrupt_In_Endpoint_1_and_3", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSE_DYNAMIC_DESCRIPTOR=1" + avr-size main.elf | tail -1 | awk '{print "With_Dynamic_Descriptor", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_LONG_TRANSFERS=1" + avr-size main.elf | tail -1 | awk '{print "With_Long_Transfers", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP) + cat $(SIZES_TMP) | awk 'BEGIN{printf("%39s %5s %5s %5s %5s\n"), "Variation", "Flash", "RAM", "+F", "+RAM"}\ + /^null/{nullRom=$$2; nullRam=$$3; next} \ + {rom=$$2-nullRom; ram=$$3-nullRam; if(!refRom){refRom=rom; refRam=ram} \ + printf("%39s %5d %5d %+5d %+5d\n", $$1, rom, ram, rom-refRom, ram-refRam)}' | tee sizes.txt + rm $(SIZES_TMP) + +test: + for freq in 12000000 12800000 15000000 16000000 16500000 18000000 20000000; do \ + for opt in USB_COUNT_SOF USB_CFG_HAVE_INTRIN_ENDPOINT USB_CFG_HAVE_INTRIN_ENDPOINT3 USB_CFG_HAVE_MEASURE_FRAME_LENGTH USB_CFG_LONG_TRANSFERS; do \ + $(MAKE) clean; $(MAKE) main.elf F_CPU=$$freq "DEFINES=-D$$opt=1" || exit 1; \ + $(MAKE) clean; $(MAKE) main.elf F_CPU=$$freq "DEFINES=-D$$opt=1 -DDUSB_CFG_IMPLEMENT_FN_WRITEOUT=1" || exit 1; \ + done \ + done + +# The following rule is used to check the compiler +devices: #exclude devices without RAM for stack and atmega603 for gcc 3 + excludes="at90s1200 attiny11 attiny12 attiny15 attiny28"; \ + for gccVersion in 3 4; do \ + avr-gcc-select $$gccVersion; \ + for device in `echo | avr-gcc -xc -mmcu=x - 2>&1 | egrep '^ *at[a-zA-Z0-9_-]+$$'`; do \ + if echo "$$excludes" | grep "$$device" >/dev/null; then continue; fi; \ + if [ "$$gccVersion" = 3 -a "$$device" = atmega603 ]; then continue; fi; \ + $(MAKE) clean; $(MAKE) null.elf DEVICE=$$device || exit 1; \ + done \ + done + $(MAKE) clean + avr-gcc-select 3 + @echo "+++ Device test succeeded!" + +# rule for deleting dependent files (those which can be built by Make): +clean: + rm -f *.hex *.lst *.map *.elf *.o + rm -rf usbdrv + +# Generic rule for compiling C files: +.c.o: + $(COMPILE) -c $< -o $@ + +# Generic rule for assembling Assembler source files: +.S.o: + $(COMPILE) -x assembler-with-cpp -c $< -o $@ +# "-x assembler-with-cpp" should not be necessary since this is the default +# file type for the .S (with capital S) extension. However, upper case +# characters are not always preserved on Windows. To ensure WinAVR +# compatibility define the file type manually. + +# Generic rule for compiling C to assembler, used for debugging only. +.c.s: + $(COMPILE) -S $< -o $@ + +# file targets: + +# Since we don't want to ship the driver multipe times, we copy it into this project: +usbdrv: + cp -r ../usbdrv . + +main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it + $(COMPILE) -o main.elf $(OBJECTS) + +main_i.elf: usbdrv main.o usbdrv/usbdrvasm.o # usbdrv dependency only needed because we copy it + $(COMPILE) -o main_i.elf main.o usbdrv/usbdrvasm.o + +null.elf: null.o + $(COMPILE) -o null.elf null.o diff --git a/adb2usb/uart2usb/vusb-20100715/tests/Readme.txt b/adb2usb/uart2usb/vusb-20100715/tests/Readme.txt new file mode 100644 index 0000000..3f0d36d --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/Readme.txt @@ -0,0 +1,13 @@ +This is the Readme file for the directory "tests" of V-USB, a firmware-only +USB driver for AVR microcontrollers. + +WHAT IS IN THIS DIRECTORY? +========================== +This directory is for driver development only. It contains tests to check +whether all branches of #ifdef code compile as they should and whether the +code size of the driver increased. + + +---------------------------------------------------------------------------- +(c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. +http://www.obdev.at/ diff --git a/adb2usb/uart2usb/vusb-20100715/tests/compare-sizes.awk b/adb2usb/uart2usb/vusb-20100715/tests/compare-sizes.awk new file mode 100755 index 0000000..8135729 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/compare-sizes.awk @@ -0,0 +1,45 @@ +#!/usr/bin/awk -f +# Name: compare-sizes.awk +# Project: v-usb +# Author: Christian Starkjohann +# Creation Date: 2008-04-29 +# Tabsize: 4 +# Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH +# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +# This Revision: $Id$ + +BEGIN{ + opt = 0; + if(ARGC != 3){ + printf("usage: compare-sizes.awk file1 file2\n"); + printf(" computes size differences between two size lists\n"); + exit 1; + } + file1 = ARGV[1]; + file2 = ARGV[2]; +} + +{ + if(($2 + 0) != 0){ + if(!hadOption[$1]){ + hadOption[$1] = 1; + options[opt++] = $1; + } + flash[FILENAME, $1] = $2; + ram[FILENAME, $1] = $3; + } +} + +END{ + if(opt > 0){ + printf ("%39s %6s %5s\n", "Variation", "+Flash", "+RAM"); + } + for(i = 0; i < opt; i++){ + option = options[i]; + if(!flash[file2, option] || !flash[file1, option]){ + printf("%39s %6s %5s\n", option, "n/a", "n/a"); + }else{ + printf("%39s %+6d %+5d\n", option, flash[file2, option] - flash[file1, option], ram[file2, option] - ram[file1, option]); + } + } +} diff --git a/adb2usb/uart2usb/vusb-20100715/tests/main.c b/adb2usb/uart2usb/vusb-20100715/tests/main.c new file mode 100644 index 0000000..55f881c --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/main.c @@ -0,0 +1,159 @@ +/* Name: main.c + * Project: Testing driver features + * Author: Christian Starkjohann + * Creation Date: 2008-04-29 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: main.c 773 2010-01-15 18:30:36Z cs $ + */ + +/* +This module is a do-nothing test code linking against (or including) the USB +driver. It is used to determine the code size for various options and to +check whether the code compiles with all options. +*/ +#include +#include /* for sei() */ +#include /* required by usbdrv.h */ +#include /* for _delay_ms() */ +#include "usbdrv.h" +#if USE_INCLUDE +#include "usbdrv.c" +#endif + +/* ------------------------------------------------------------------------- */ +/* ----------------------------- USB interface ----------------------------- */ +/* ------------------------------------------------------------------------- */ + +#if USB_CFG_IMPLEMENT_FN_WRITE +uchar usbFunctionWrite(uchar *data, uchar len) +{ + return 1; +} +#endif + +#if USB_CFG_IMPLEMENT_FN_READ +uchar usbFunctionRead(uchar *data, uchar len) +{ + return len; +} +#endif + +#if USB_CFG_IMPLEMENT_FN_WRITEOUT +void usbFunctionWriteOut(uchar *data, uchar len) +{ +} +#endif + +#if USE_DYNAMIC_DESCRIPTOR + +static PROGMEM char myDescriptorDevice[] = { /* USB device descriptor */ + 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */ + USBDESCR_DEVICE, /* descriptor type */ + 0x10, 0x01, /* USB version supported */ + USB_CFG_DEVICE_CLASS, + USB_CFG_DEVICE_SUBCLASS, + 0, /* protocol */ + 8, /* max packet size */ + /* the following two casts affect the first byte of the constant only, but + * that's sufficient to avoid a warning with the default values. + */ + (char)USB_CFG_VENDOR_ID,/* 2 bytes */ + (char)USB_CFG_DEVICE_ID,/* 2 bytes */ + USB_CFG_DEVICE_VERSION, /* 2 bytes */ + USB_CFG_DESCR_PROPS_STRING_VENDOR != 0 ? 1 : 0, /* manufacturer string index */ + USB_CFG_DESCR_PROPS_STRING_PRODUCT != 0 ? 2 : 0, /* product string index */ + USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER != 0 ? 3 : 0, /* serial number string index */ + 1, /* number of configurations */ +}; + +static PROGMEM char myDescriptorConfiguration[] = { /* USB configuration descriptor */ + 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ + USBDESCR_CONFIG, /* descriptor type */ + 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + (USB_CFG_DESCR_PROPS_HID & 0xff), 0, + /* total length of data returned (including inlined descriptors) */ + 1, /* number of interfaces in this configuration */ + 1, /* index of this configuration */ + 0, /* configuration name string index */ +#if USB_CFG_IS_SELF_POWERED + USBATTR_SELFPOWER, /* attributes */ +#else + 0, /* attributes */ +#endif + USB_CFG_MAX_BUS_POWER/2, /* max USB current in 2mA units */ +/* interface descriptor follows inline: */ + 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ + USBDESCR_INTERFACE, /* descriptor type */ + 0, /* index of this interface */ + 0, /* alternate setting for this interface */ + USB_CFG_HAVE_INTRIN_ENDPOINT, /* endpoints excl 0: number of endpoint descriptors to follow */ + USB_CFG_INTERFACE_CLASS, + USB_CFG_INTERFACE_SUBCLASS, + USB_CFG_INTERFACE_PROTOCOL, + 0, /* string index for interface */ +#if (USB_CFG_DESCR_PROPS_HID & 0xff) /* HID descriptor */ + 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ + USBDESCR_HID, /* descriptor type: HID */ + 0x01, 0x01, /* BCD representation of HID version */ + 0x00, /* target country code */ + 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ + 0x22, /* descriptor type: report */ + USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, 0, /* total length of report descriptor */ +#endif +#if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */ + 7, /* sizeof(usbDescrEndpoint) */ + USBDESCR_ENDPOINT, /* descriptor type = endpoint */ + (char)0x81, /* IN endpoint number 1 */ + 0x03, /* attrib: Interrupt endpoint */ + 8, 0, /* maximum packet size */ + USB_CFG_INTR_POLL_INTERVAL, /* in ms */ +#endif +}; + +USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(usbRequest_t *rq) +{ +uchar *p = 0, len = 0; + + if(rq->wValue.bytes[1] == USBDESCR_DEVICE){ + p = (uchar *)myDescriptorDevice; + len = sizeof(myDescriptorDevice); + }else{ /* must be configuration descriptor */ + p = (uchar *)(myDescriptorConfiguration); + len = sizeof(myDescriptorConfiguration); + } + usbMsgPtr = p; + return len; +} +#endif + +USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8]) +{ +usbRequest_t *rq = (void *)data; + + if(rq->bRequest == 0) /* request using usbFunctionRead()/usbFunctionWrite() */ + return 0xff; + return 0; /* default for not implemented requests: return no data back to host */ +} + +/* ------------------------------------------------------------------------- */ + +int main(void) +{ +uchar i; + + usbInit(); + usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ + i = 0; + while(--i){ /* fake USB disconnect for > 250 ms */ + _delay_ms(1); + } + usbDeviceConnect(); + sei(); + for(;;){ /* main event loop */ + usbPoll(); + } + return 0; +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/tests/null.c b/adb2usb/uart2usb/vusb-20100715/tests/null.c new file mode 100644 index 0000000..dc6848d --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/null.c @@ -0,0 +1,26 @@ +/* Name: null.c + * Project: Testing driver features + * Author: Christian Starkjohann + * Creation Date: 2008-04-29 + * Tabsize: 4 + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: null.c 692 2008-11-07 15:07:40Z cs $ + */ + +/* +This is a NULL main() function to find out the code size required by libusb's +startup code, interrupt vectors etc. +*/ +#include + + +/* ------------------------------------------------------------------------- */ + +int main(void) +{ + for(;;); + return 0; +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080418-gcc3.4.6.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080418-gcc3.4.6.txt new file mode 100644 index 0000000..2257e89 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080418-gcc3.4.6.txt @@ -0,0 +1,13 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1154 45 +0 +0 + Minimum_with_12_MHz 1274 45 +120 +0 + Minimum_with_15_MHz 1260 45 +106 +0 + Minimum_with_16_5_MHz 1276 45 +122 +0 + With_usbFunctionWrite 1214 45 +60 +0 + With_usbFunctionRead 1200 45 +46 +0 + With_usbFunctionRead_and_Write 1246 45 +92 +0 + With_usbFunctionWriteOut 1178 45 +24 +0 + With_Interrupt_In_Endpoint_1 1284 58 +130 +13 + With_Interrupt_In_Endpoint_1_and_Halt 1372 58 +218 +13 + With_Interrupt_In_Endpoint_1_and_3 1386 69 +232 +24 + With_Dynamic_Descriptor 1186 45 +32 +0 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080418-gcc4.2.2.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080418-gcc4.2.2.txt new file mode 100644 index 0000000..f776893 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080418-gcc4.2.2.txt @@ -0,0 +1,13 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1208 45 +0 +0 + Minimum_with_12_MHz 1328 45 +120 +0 + Minimum_with_15_MHz 1314 45 +106 +0 + Minimum_with_16_5_MHz 1330 45 +122 +0 + With_usbFunctionWrite 1268 45 +60 +0 + With_usbFunctionRead 1264 45 +56 +0 + With_usbFunctionRead_and_Write 1314 45 +106 +0 + With_usbFunctionWriteOut 1218 45 +10 +0 + With_Interrupt_In_Endpoint_1 1340 58 +132 +13 + With_Interrupt_In_Endpoint_1_and_Halt 1414 58 +206 +13 + With_Interrupt_In_Endpoint_1_and_3 1426 69 +218 +24 + With_Dynamic_Descriptor 1238 45 +30 +0 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080513-gcc3.4.6.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080513-gcc3.4.6.txt new file mode 100644 index 0000000..d292bfb --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080513-gcc3.4.6.txt @@ -0,0 +1,15 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1154 45 +0 +0 + Minimum_with_12_MHz 1274 45 +120 +0 + Minimum_with_15_MHz 1260 45 +106 +0 + Minimum_with_16_5_MHz 1276 45 +122 +0 + Minimum_with_20_MHz 1136 45 -18 +0 + With_usbFunctionWrite 1214 45 +60 +0 + With_usbFunctionRead 1192 45 +38 +0 + With_usbFunctionRead_and_Write 1234 45 +80 +0 + With_usbFunctionWriteOut 1178 45 +24 +0 + With_Interrupt_In_Endpoint_1 1280 57 +126 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1370 57 +216 +12 + With_Interrupt_In_Endpoint_1_and_3 1346 69 +192 +24 + With_Dynamic_Descriptor 1182 45 +28 +0 + With_Long_Transfers 1200 47 +46 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080513-gcc4.3.0.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080513-gcc4.3.0.txt new file mode 100644 index 0000000..e3218b4 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20080513-gcc4.3.0.txt @@ -0,0 +1,15 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1192 45 +0 +0 + Minimum_with_12_MHz 1312 45 +120 +0 + Minimum_with_15_MHz 1298 45 +106 +0 + Minimum_with_16_5_MHz 1314 45 +122 +0 + Minimum_with_20_MHz 1174 45 -18 +0 + With_usbFunctionWrite 1246 45 +54 +0 + With_usbFunctionRead 1242 45 +50 +0 + With_usbFunctionRead_and_Write 1280 45 +88 +0 + With_usbFunctionWriteOut 1208 45 +16 +0 + With_Interrupt_In_Endpoint_1 1320 57 +128 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1410 57 +218 +12 + With_Interrupt_In_Endpoint_1_and_3 1428 69 +236 +24 + With_Dynamic_Descriptor 1212 45 +20 +0 + With_Long_Transfers 1270 47 +78 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081022-gcc3.4.6.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081022-gcc3.4.6.txt new file mode 100644 index 0000000..0dfafa7 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081022-gcc3.4.6.txt @@ -0,0 +1,16 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1152 45 +0 +0 + Minimum_with_12_MHz 1202 45 +50 +0 + Minimum_with_12_8_MHz 1522 45 +370 +0 + Minimum_with_15_MHz 1258 45 +106 +0 + Minimum_with_16_5_MHz 1274 45 +122 +0 + Minimum_with_20_MHz 1134 45 -18 +0 + With_usbFunctionWrite 1212 45 +60 +0 + With_usbFunctionRead 1190 45 +38 +0 + With_usbFunctionRead_and_Write 1232 45 +80 +0 + With_usbFunctionWriteOut 1176 45 +24 +0 + With_Interrupt_In_Endpoint_1 1278 57 +126 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12 + With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24 + With_Dynamic_Descriptor 1180 45 +28 +0 + With_Long_Transfers 1198 47 +46 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081022-gcc4.3.0.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081022-gcc4.3.0.txt new file mode 100644 index 0000000..42e2ba9 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081022-gcc4.3.0.txt @@ -0,0 +1,16 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1194 45 +0 +0 + Minimum_with_12_MHz 1244 45 +50 +0 + Minimum_with_12_8_MHz 1564 45 +370 +0 + Minimum_with_15_MHz 1300 45 +106 +0 + Minimum_with_16_5_MHz 1316 45 +122 +0 + Minimum_with_20_MHz 1176 45 -18 +0 + With_usbFunctionWrite 1248 45 +54 +0 + With_usbFunctionRead 1244 45 +50 +0 + With_usbFunctionRead_and_Write 1282 45 +88 +0 + With_usbFunctionWriteOut 1210 45 +16 +0 + With_Interrupt_In_Endpoint_1 1322 57 +128 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1412 57 +218 +12 + With_Interrupt_In_Endpoint_1_and_3 1430 69 +236 +24 + With_Dynamic_Descriptor 1214 45 +20 +0 + With_Long_Transfers 1272 47 +78 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081126-gcc3.4.6.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081126-gcc3.4.6.txt new file mode 100644 index 0000000..0dfafa7 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081126-gcc3.4.6.txt @@ -0,0 +1,16 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1152 45 +0 +0 + Minimum_with_12_MHz 1202 45 +50 +0 + Minimum_with_12_8_MHz 1522 45 +370 +0 + Minimum_with_15_MHz 1258 45 +106 +0 + Minimum_with_16_5_MHz 1274 45 +122 +0 + Minimum_with_20_MHz 1134 45 -18 +0 + With_usbFunctionWrite 1212 45 +60 +0 + With_usbFunctionRead 1190 45 +38 +0 + With_usbFunctionRead_and_Write 1232 45 +80 +0 + With_usbFunctionWriteOut 1176 45 +24 +0 + With_Interrupt_In_Endpoint_1 1278 57 +126 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12 + With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24 + With_Dynamic_Descriptor 1180 45 +28 +0 + With_Long_Transfers 1198 47 +46 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081126-gcc4.3.0.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081126-gcc4.3.0.txt new file mode 100644 index 0000000..42e2ba9 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20081126-gcc4.3.0.txt @@ -0,0 +1,16 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1194 45 +0 +0 + Minimum_with_12_MHz 1244 45 +50 +0 + Minimum_with_12_8_MHz 1564 45 +370 +0 + Minimum_with_15_MHz 1300 45 +106 +0 + Minimum_with_16_5_MHz 1316 45 +122 +0 + Minimum_with_20_MHz 1176 45 -18 +0 + With_usbFunctionWrite 1248 45 +54 +0 + With_usbFunctionRead 1244 45 +50 +0 + With_usbFunctionRead_and_Write 1282 45 +88 +0 + With_usbFunctionWriteOut 1210 45 +16 +0 + With_Interrupt_In_Endpoint_1 1322 57 +128 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1412 57 +218 +12 + With_Interrupt_In_Endpoint_1_and_3 1430 69 +236 +24 + With_Dynamic_Descriptor 1214 45 +20 +0 + With_Long_Transfers 1272 47 +78 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090323-gcc3.4.6.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090323-gcc3.4.6.txt new file mode 100644 index 0000000..18e72a6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090323-gcc3.4.6.txt @@ -0,0 +1,17 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1152 45 +0 +0 + Minimum_with_12_MHz 1202 45 +50 +0 + Minimum_with_12_8_MHz 1522 45 +370 +0 + Minimum_with_15_MHz 1258 45 +106 +0 + Minimum_with_16_5_MHz 1274 45 +122 +0 + Minimum_with_18_MHz+CRC 2268 45 +1116 +0 + Minimum_with_20_MHz 1134 45 -18 +0 + With_usbFunctionWrite 1212 45 +60 +0 + With_usbFunctionRead 1190 45 +38 +0 + With_usbFunctionRead_and_Write 1232 45 +80 +0 + With_usbFunctionWriteOut 1176 45 +24 +0 + With_Interrupt_In_Endpoint_1 1278 57 +126 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12 + With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24 + With_Dynamic_Descriptor 1180 45 +28 +0 + With_Long_Transfers 1198 47 +46 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090323-gcc4.3.2.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090323-gcc4.3.2.txt new file mode 100644 index 0000000..9b4f4ee --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090323-gcc4.3.2.txt @@ -0,0 +1,17 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1224 45 +0 +0 + Minimum_with_12_MHz 1274 45 +50 +0 + Minimum_with_12_8_MHz 1594 45 +370 +0 + Minimum_with_15_MHz 1330 45 +106 +0 + Minimum_with_16_5_MHz 1346 45 +122 +0 + Minimum_with_18_MHz+CRC 2298 45 +1074 +0 + Minimum_with_20_MHz 1206 45 -18 +0 + With_usbFunctionWrite 1284 45 +60 +0 + With_usbFunctionRead 1280 45 +56 +0 + With_usbFunctionRead_and_Write 1318 45 +94 +0 + With_usbFunctionWriteOut 1246 45 +22 +0 + With_Interrupt_In_Endpoint_1 1358 57 +134 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1448 57 +224 +12 + With_Interrupt_In_Endpoint_1_and_3 1466 69 +242 +24 + With_Dynamic_Descriptor 1250 45 +26 +0 + With_Long_Transfers 1302 47 +78 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090415-gcc3.4.6.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090415-gcc3.4.6.txt new file mode 100644 index 0000000..18e72a6 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090415-gcc3.4.6.txt @@ -0,0 +1,17 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1152 45 +0 +0 + Minimum_with_12_MHz 1202 45 +50 +0 + Minimum_with_12_8_MHz 1522 45 +370 +0 + Minimum_with_15_MHz 1258 45 +106 +0 + Minimum_with_16_5_MHz 1274 45 +122 +0 + Minimum_with_18_MHz+CRC 2268 45 +1116 +0 + Minimum_with_20_MHz 1134 45 -18 +0 + With_usbFunctionWrite 1212 45 +60 +0 + With_usbFunctionRead 1190 45 +38 +0 + With_usbFunctionRead_and_Write 1232 45 +80 +0 + With_usbFunctionWriteOut 1176 45 +24 +0 + With_Interrupt_In_Endpoint_1 1278 57 +126 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12 + With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24 + With_Dynamic_Descriptor 1180 45 +28 +0 + With_Long_Transfers 1198 47 +46 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090415-gcc4.3.2.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090415-gcc4.3.2.txt new file mode 100644 index 0000000..9b4f4ee --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20090415-gcc4.3.2.txt @@ -0,0 +1,17 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1224 45 +0 +0 + Minimum_with_12_MHz 1274 45 +50 +0 + Minimum_with_12_8_MHz 1594 45 +370 +0 + Minimum_with_15_MHz 1330 45 +106 +0 + Minimum_with_16_5_MHz 1346 45 +122 +0 + Minimum_with_18_MHz+CRC 2298 45 +1074 +0 + Minimum_with_20_MHz 1206 45 -18 +0 + With_usbFunctionWrite 1284 45 +60 +0 + With_usbFunctionRead 1280 45 +56 +0 + With_usbFunctionRead_and_Write 1318 45 +94 +0 + With_usbFunctionWriteOut 1246 45 +22 +0 + With_Interrupt_In_Endpoint_1 1358 57 +134 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1448 57 +224 +12 + With_Interrupt_In_Endpoint_1_and_3 1466 69 +242 +24 + With_Dynamic_Descriptor 1250 45 +26 +0 + With_Long_Transfers 1302 47 +78 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20100715-gcc3.4.6.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20100715-gcc3.4.6.txt new file mode 100644 index 0000000..a7550ee --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20100715-gcc3.4.6.txt @@ -0,0 +1,17 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1152 45 +0 +0 + Minimum_with_12_MHz 1202 45 +50 +0 + Minimum_with_12_8_MHz 1518 45 +366 +0 + Minimum_with_15_MHz 1258 45 +106 +0 + Minimum_with_16_5_MHz 1274 45 +122 +0 + Minimum_with_18_MHz+CRC 2268 45 +1116 +0 + Minimum_with_20_MHz 1134 45 -18 +0 + With_usbFunctionWrite 1212 45 +60 +0 + With_usbFunctionRead 1190 45 +38 +0 + With_usbFunctionRead_and_Write 1232 45 +80 +0 + With_usbFunctionWriteOut 1176 45 +24 +0 + With_Interrupt_In_Endpoint_1 1278 57 +126 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12 + With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24 + With_Dynamic_Descriptor 1180 45 +28 +0 + With_Long_Transfers 1198 47 +46 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20100715-gcc4.3.3.txt b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20100715-gcc4.3.3.txt new file mode 100644 index 0000000..ce162f3 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/sizes-reference/sizes-20100715-gcc4.3.3.txt @@ -0,0 +1,17 @@ + Variation Flash RAM +F +RAM + Minimum_with_16_MHz 1226 45 +0 +0 + Minimum_with_12_MHz 1276 45 +50 +0 + Minimum_with_12_8_MHz 1592 45 +366 +0 + Minimum_with_15_MHz 1332 45 +106 +0 + Minimum_with_16_5_MHz 1348 45 +122 +0 + Minimum_with_18_MHz+CRC 2298 45 +1072 +0 + Minimum_with_20_MHz 1208 45 -18 +0 + With_usbFunctionWrite 1286 45 +60 +0 + With_usbFunctionRead 1282 45 +56 +0 + With_usbFunctionRead_and_Write 1320 45 +94 +0 + With_usbFunctionWriteOut 1248 45 +22 +0 + With_Interrupt_In_Endpoint_1 1360 57 +134 +12 + With_Interrupt_In_Endpoint_1_and_Halt 1450 57 +224 +12 + With_Interrupt_In_Endpoint_1_and_3 1418 69 +192 +24 + With_Dynamic_Descriptor 1252 45 +26 +0 + With_Long_Transfers 1304 47 +78 +2 diff --git a/adb2usb/uart2usb/vusb-20100715/tests/usbconfig.h b/adb2usb/uart2usb/vusb-20100715/tests/usbconfig.h new file mode 100644 index 0000000..8281c2e --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/tests/usbconfig.h @@ -0,0 +1,288 @@ +/* Name: usbconfig.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2005-04-01 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbconfig.h 774 2010-01-15 18:33:11Z cs $ + */ + +#ifndef __usbconfig_h_included__ +#define __usbconfig_h_included__ + +/* +General Description: +This is the config file for tests. It is not updated to the latest set of +features. Don't use it as a prototype, use usbconfig-prototype.h instead! +*/ + +/* ---------------------------- Hardware Config ---------------------------- */ + +#define USB_CFG_IOPORTNAME D +#define USB_CFG_DMINUS_BIT 4 +#define USB_CFG_DPLUS_BIT 2 +#define USB_CFG_CLOCK_KHZ (F_CPU/1000) +#define USB_CFG_CHECK_CRC (USB_CFG_CLOCK_KHZ == 18000) + + +/* ----------------------- Optional Hardware Config ------------------------ */ + +/* #define USB_CFG_PULLUP_IOPORTNAME D */ +/* If you connect the 1.5k pullup resistor from D- to a port pin instead of + * V+, you can connect and disconnect the device from firmware by calling + * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). + * This constant defines the port on which the pullup resistor is connected. + */ +/* #define USB_CFG_PULLUP_BIT 4 */ +/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined + * above) where the 1.5k pullup resistor is connected. See description + * above for details. + */ + +/* --------------------------- Functional Range ---------------------------- */ + +#ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3 +#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 +#endif +/* Define this to 1 if you want to compile a version with three endpoints: The + * default control endpoint 0, an interrupt-in endpoint 3 (or the number + * configured below) and a catch-all default interrupt-in endpoint as above. + * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. + */ +#ifndef USB_CFG_HAVE_INTRIN_ENDPOINT +#define USB_CFG_HAVE_INTRIN_ENDPOINT USB_CFG_HAVE_INTRIN_ENDPOINT3 +#endif +/* Define this to 1 if you want to compile a version with two endpoints: The + * default control endpoint 0 and an interrupt-in endpoint (any other endpoint + * number). + */ +#define USB_CFG_EP3_NUMBER 3 +/* If the so-called endpoint 3 is used, it can now be configured to any other + * endpoint number (except 0) with this macro. Default if undefined is 3. + */ +/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ +/* The above macro defines the startup condition for data toggling on the + * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. + * Since the token is toggled BEFORE sending any data, the first packet is + * sent with the oposite value of this configuration! + */ +//#define USB_CFG_IMPLEMENT_HALT 0 +/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature + * for endpoint 1 (interrupt endpoint). Although you may not need this feature, + * it is required by the standard. We have made it a config option because it + * bloats the code considerably. + */ +#define USB_CFG_INTR_POLL_INTERVAL 10 +/* If you compile a version with endpoint 1 (interrupt-in), this is the poll + * interval. The value is in milliseconds and must not be less than 10 ms for + * low speed devices. + */ +#define USB_CFG_IS_SELF_POWERED 0 +/* Define this to 1 if the device has its own power supply. Set it to 0 if the + * device is powered from the USB bus. + */ +#define USB_CFG_MAX_BUS_POWER 40 +/* Set this variable to the maximum USB bus power consumption of your device. + * The value is in milliamperes. [It will be divided by two since USB + * communicates power requirements in units of 2 mA.] + */ +//#define USB_CFG_IMPLEMENT_FN_WRITE 0 +/* Set this to 1 if you want usbFunctionWrite() to be called for control-out + * transfers. Set it to 0 if you don't need it and want to save a couple of + * bytes. + */ +//#define USB_CFG_IMPLEMENT_FN_READ 0 +/* Set this to 1 if you need to send control replies which are generated + * "on the fly" when usbFunctionRead() is called. If you only want to send + * data from a static buffer, set it to 0 and return the data from + * usbFunctionSetup(). This saves a couple of bytes. + */ +//#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 +/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. + * You must implement the function usbFunctionWriteOut() which receives all + * interrupt/bulk data sent to any endpoint other than 0. The endpoint number + * can be found in 'usbRxToken'. + */ +#define USB_CFG_HAVE_FLOWCONTROL 0 +/* Define this to 1 if you want flowcontrol over USB data. See the definition + * of the macros usbDisableAllRequests() and usbEnableAllRequests() in + * usbdrv.h. + */ +//#define USB_CFG_LONG_TRANSFERS 0 +/* Define this to 1 if you want to send/receive blocks of more than 254 bytes + * in a single control-in or control-out transfer. Note that the capability + * for long transfers increases the driver size. + */ +/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ +/* This macro is a hook if you want to do unconventional things. If it is + * defined, it's inserted at the beginning of received message processing. + * If you eat the received message and don't want default processing to + * proceed, do a return after doing your things. One possible application + * (besides debugging) is to flash a status LED on each packet. + */ +/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ +/* This macro is a hook if you need to know when an USB RESET occurs. It has + * one parameter which distinguishes between the start of RESET state and its + * end. + */ +/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ +/* This macro (if defined) is executed when a USB SET_ADDRESS request was + * received. + */ +//#define USB_COUNT_SOF 0 +/* define this macro to 1 if you need the global variable "usbSofCount" which + * counts SOF packets. This feature requires that the hardware interrupt is + * connected to D- instead of D+. + */ +//#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 +/* define this macro to 1 if you want the function usbMeasureFrameLength() + * compiled in. This function can be used to calibrate the AVR's RC oscillator. + */ + +/* -------------------------- Device Description --------------------------- */ + +#define USB_CFG_VENDOR_ID 0xc0, 0x16 +/* USB vendor ID for the device, low byte first. If you have registered your + * own Vendor ID, define it here. Otherwise you use one of obdev's free shared + * VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! + */ +#define USB_CFG_DEVICE_ID 0x08, 0x3e /* 1000 dec, "free for lab use" */ +/* This is the ID of the product, low byte first. It is interpreted in the + * scope of the vendor ID. If you have registered your own VID with usb.org + * or if you have licensed a PID from somebody else, define it here. Otherwise + * you use obdev's free shared VID/PID pair. Be sure to read the rules in + * USB-IDs-for-free.txt! + */ +#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +/* Version number of the device: Minor number first, then major number. + */ +#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' +#define USB_CFG_VENDOR_NAME_LEN 8 +/* These two values define the vendor name returned by the USB device. The name + * must be given as a list of characters under single quotes. The characters + * are interpreted as Unicode (UTF-16) entities. + * If you don't want a vendor name string, undefine these macros. + * ALWAYS define a vendor name containing your Internet domain name if you use + * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for + * details. + */ +#define USB_CFG_DEVICE_NAME 'T', 'e', 's', 't' +#define USB_CFG_DEVICE_NAME_LEN 4 +/* Same as above for the device name. If you don't want a device name, undefine + * the macros. See the file USB-IDs-for-free.txt before you assign a name if + * you use a shared VID/PID. + */ +/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ +/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ +/* Same as above for the serial number. If you don't want a serial number, + * undefine the macros. + * It may be useful to provide the serial number through other means than at + * compile time. See the section about descriptor properties below for how + * to fine tune control over USB descriptors such as the string descriptor + * for the serial number. + */ +#define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */ +#define USB_CFG_DEVICE_SUBCLASS 0 +/* See USB specification if you want to conform to an existing device class. + * Class 0xff is "vendor specific". + */ +#define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */ +#define USB_CFG_INTERFACE_SUBCLASS 0 +#define USB_CFG_INTERFACE_PROTOCOL 0 +/* See USB specification if you want to conform to an existing device class or + * protocol. The following classes must be set at interface level: + * HID class is 3, no subclass and protocol required (but may be useful!) + * CDC class is 2, use subclass 2 and protocol 1 for ACM + */ +/* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */ +/* Define this to the length of the HID report descriptor, if you implement + * an HID device. Otherwise don't define it or define it to 0. + * If you use this define, you must add a PROGMEM character array named + * "usbHidReportDescriptor" to your code which contains the report descriptor. + * Don't forget to keep the array and this define in sync! + */ + +/* #define USB_PUBLIC static */ +/* Use the define above if you #include usbdrv.c instead of linking against it. + * This technique saves a couple of bytes in flash memory. + */ + +/* ------------------- Fine Control over USB Descriptors ------------------- */ +/* If you don't want to use the driver's default USB descriptors, you can + * provide our own. These can be provided as (1) fixed length static data in + * flash memory, (2) fixed length static data in RAM or (3) dynamically at + * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more + * information about this function. + * Descriptor handling is configured through the descriptor's properties. If + * no properties are defined or if they are 0, the default descriptor is used. + * Possible properties are: + * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched + * at runtime via usbFunctionDescriptor(). + * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found + * in static memory is in RAM, not in flash memory. + * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), + * the driver must know the descriptor's length. The descriptor itself is + * found at the address of a well known identifier (see below). + * List of static descriptor names (must be declared PROGMEM if in flash): + * char usbDescriptorDevice[]; + * char usbDescriptorConfiguration[]; + * char usbDescriptorHidReport[]; + * char usbDescriptorString0[]; + * int usbDescriptorStringVendor[]; + * int usbDescriptorStringDevice[]; + * int usbDescriptorStringSerialNumber[]; + * Other descriptors can't be provided statically, they must be provided + * dynamically at runtime. + * + * Descriptor properties are or-ed or added together, e.g.: + * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) + * + * The following descriptors are defined: + * USB_CFG_DESCR_PROPS_DEVICE + * USB_CFG_DESCR_PROPS_CONFIGURATION + * USB_CFG_DESCR_PROPS_STRINGS + * USB_CFG_DESCR_PROPS_STRING_0 + * USB_CFG_DESCR_PROPS_STRING_VENDOR + * USB_CFG_DESCR_PROPS_STRING_PRODUCT + * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER + * USB_CFG_DESCR_PROPS_HID + * USB_CFG_DESCR_PROPS_HID_REPORT + * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) + * + */ + +#if USE_DYNAMIC_DESCRIPTOR +#define USB_CFG_DESCR_PROPS_DEVICE USB_PROP_IS_DYNAMIC +#define USB_CFG_DESCR_PROPS_CONFIGURATION USB_PROP_IS_DYNAMIC +#else +#define USB_CFG_DESCR_PROPS_DEVICE 0 +#define USB_CFG_DESCR_PROPS_CONFIGURATION 0 +#endif +#define USB_CFG_DESCR_PROPS_STRINGS 0 +#define USB_CFG_DESCR_PROPS_STRING_0 0 +#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 +#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 +#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 +#define USB_CFG_DESCR_PROPS_HID 0 +#define USB_CFG_DESCR_PROPS_HID_REPORT 0 +#define USB_CFG_DESCR_PROPS_UNKNOWN 0 + +/* ----------------------- Optional MCU Description ------------------------ */ + +/* The following configurations have working defaults in usbdrv.h. You + * usually don't need to set them explicitly. Only if you want to run + * the driver on a device which is not yet supported or with a compiler + * which is not fully supported (such as IAR C) or if you use a differnt + * interrupt than INT0, you may have to define some of these. + */ +/* #define USB_INTR_CFG MCUCR */ +/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ +/* #define USB_INTR_CFG_CLR 0 */ +/* #define USB_INTR_ENABLE GIMSK */ +/* #define USB_INTR_ENABLE_BIT INT0 */ +/* #define USB_INTR_PENDING GIFR */ +/* #define USB_INTR_PENDING_BIT INTF0 */ +/* #define USB_INTR_VECTOR INT0_vect */ + +#endif /* __usbconfig_h_included__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/Changelog.txt b/adb2usb/uart2usb/vusb-20100715/usbdrv/Changelog.txt new file mode 100644 index 0000000..5c6354a --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/Changelog.txt @@ -0,0 +1,308 @@ +This file documents changes in the firmware-only USB driver for atmel's AVR +microcontrollers. New entries are always appended to the end of the file. +Scroll down to the bottom to see the most recent changes. + +2005-04-01: + - Implemented endpoint 1 as interrupt-in endpoint. + - Moved all configuration options to usbconfig.h which is not part of the + driver. + - Changed interface for usbVendorSetup(). + - Fixed compatibility with ATMega8 device. + - Various minor optimizations. + +2005-04-11: + - Changed interface to application: Use usbFunctionSetup(), usbFunctionRead() + and usbFunctionWrite() now. Added configuration options to choose which + of these functions to compile in. + - Assembler module delivers receive data non-inverted now. + - Made register and bit names compatible with more AVR devices. + +2005-05-03: + - Allow address of usbRxBuf on any memory page as long as the buffer does + not cross 256 byte page boundaries. + - Better device compatibility: works with Mega88 now. + - Code optimization in debugging module. + - Documentation updates. + +2006-01-02: + - Added (free) default Vendor- and Product-IDs bought from voti.nl. + - Added USBID-License.txt file which defines the rules for using the free + shared VID/PID pair. + - Added Readme.txt to the usbdrv directory which clarifies administrative + issues. + +2006-01-25: + - Added "configured state" to become more standards compliant. + - Added "HALT" state for interrupt endpoint. + - Driver passes the "USB Command Verifier" test from usb.org now. + - Made "serial number" a configuration option. + - Minor optimizations, we now recommend compiler option "-Os" for best + results. + - Added a version number to usbdrv.h + +2006-02-03: + - New configuration variable USB_BUFFER_SECTION for the memory section where + the USB rx buffer will go. This defaults to ".bss" if not defined. Since + this buffer MUST NOT cross 256 byte pages (not even touch a page at the + end), the user may want to pass a linker option similar to + "-Wl,--section-start=.mybuffer=0x800060". + - Provide structure for usbRequest_t. + - New defines for USB constants. + - Prepared for HID implementations. + - Increased data size limit for interrupt transfers to 8 bytes. + - New macro usbInterruptIsReady() to query interrupt buffer state. + +2006-02-18: + - Ensure that the data token which is sent as an ack to an OUT transfer is + always zero sized. This fixes a bug where the host reports an error after + sending an out transfer to the device, although all data arrived at the + device. + - Updated docs in usbdrv.h to reflect changed API in usbFunctionWrite(). + +* Release 2006-02-20 + + - Give a compiler warning when compiling with debugging turned on. + - Added Oleg Semyonov's changes for IAR-cc compatibility. + - Added new (optional) functions usbDeviceConnect() and usbDeviceDisconnect() + (also thanks to Oleg!). + - Rearranged tests in usbPoll() to save a couple of instructions in the most + likely case that no actions are pending. + - We need a delay between the SET ADDRESS request until the new address + becomes active. This delay was handled in usbPoll() until now. Since the + spec says that the delay must not exceed 2ms, previous versions required + aggressive polling during the enumeration phase. We have now moved the + handling of the delay into the interrupt routine. + - We must not reply with NAK to a SETUP transaction. We can only achieve this + by making sure that the rx buffer is empty when SETUP tokens are expected. + We therefore don't pass zero sized data packets from the status phase of + a transfer to usbPoll(). This change MAY cause troubles if you rely on + receiving a less than 8 bytes long packet in usbFunctionWrite() to + identify the end of a transfer. usbFunctionWrite() will NEVER be called + with a zero length. + +* Release 2006-03-14 + + - Improved IAR C support: tiny memory model, more devices + - Added template usbconfig.h file under the name usbconfig-prototype.h + +* Release 2006-03-26 + + - Added provision for one more interrupt-in endpoint (endpoint 3). + - Added provision for one interrupt-out endpoint (endpoint 1). + - Added flowcontrol macros for USB. + - Added provision for custom configuration descriptor. + - Allow ANY two port bits for D+ and D-. + - Merged (optional) receive endpoint number into global usbRxToken variable. + - Use USB_CFG_IOPORTNAME instead of USB_CFG_IOPORT. We now construct the + variable name from the single port letter instead of computing the address + of related ports from the output-port address. + +* Release 2006-06-26 + + - Updated documentation in usbdrv.h and usbconfig-prototype.h to reflect the + new features. + - Removed "#warning" directives because IAR does not understand them. Use + unused static variables instead to generate a warning. + - Do not include when compiling with IAR. + - Introduced USB_CFG_DESCR_PROPS_* in usbconfig.h to configure how each + USB descriptor should be handled. It is now possible to provide descriptor + data in Flash, RAM or dynamically at runtime. + - STALL is now a status in usbTxLen* instead of a message. We can now conform + to the spec and leave the stall status pending until it is cleared. + - Made usbTxPacketCnt1 and usbTxPacketCnt3 public. This allows the + application code to reset data toggling on interrupt pipes. + +* Release 2006-07-18 + + - Added an #if !defined __ASSEMBLER__ to the warning in usbdrv.h. This fixes + an assembler error. + - usbDeviceDisconnect() takes pull-up resistor to high impedance now. + +* Release 2007-02-01 + + - Merged in some code size improvements from usbtiny (thanks to Dick + Streefland for these optimizations!) + - Special alignment requirement for usbRxBuf not required any more. Thanks + again to Dick Streefland for this hint! + - Reverted to "#warning" instead of unused static variables -- new versions + of IAR CC should handle this directive. + - Changed Open Source license to GNU GPL v2 in order to make linking against + other free libraries easier. We no longer require publication of the + circuit diagrams, but we STRONGLY encourage it. If you improve the driver + itself, PLEASE grant us a royalty free license to your changes for our + commercial license. + +* Release 2007-03-29 + + - New configuration option "USB_PUBLIC" in usbconfig.h. + - Set USB version number to 1.10 instead of 1.01. + - Code used USB_CFG_DESCR_PROPS_STRING_DEVICE and + USB_CFG_DESCR_PROPS_STRING_PRODUCT inconsistently. Changed all occurrences + to USB_CFG_DESCR_PROPS_STRING_PRODUCT. + - New assembler module for 16.5 MHz RC oscillator clock with PLL in receiver + code. + - New assembler module for 16 MHz crystal. + - usbdrvasm.S contains common code only, clock-specific parts have been moved + to usbdrvasm12.S, usbdrvasm16.S and usbdrvasm165.S respectively. + +* Release 2007-06-25 + + - 16 MHz module: Do SE0 check in stuffed bits as well. + +* Release 2007-07-07 + + - Define hi8(x) for IAR compiler to limit result to 8 bits. This is necessary + for negative values. + - Added 15 MHz module contributed by V. Bosch. + - Interrupt vector name can now be configured. This is useful if somebody + wants to use a different hardware interrupt than INT0. + +* Release 2007-08-07 + + - Moved handleIn3 routine in usbdrvasm16.S so that relative jump range is + not exceeded. + - More config options: USB_RX_USER_HOOK(), USB_INITIAL_DATATOKEN, + USB_COUNT_SOF + - USB_INTR_PENDING can now be a memory address, not just I/O + +* Release 2007-09-19 + + - Split out common parts of assembler modules into separate include file + - Made endpoint numbers configurable so that given interface definitions + can be matched. See USB_CFG_EP3_NUMBER in usbconfig-prototype.h. + - Store endpoint number for interrupt/bulk-out so that usbFunctionWriteOut() + can handle any number of endpoints. + - Define usbDeviceConnect() and usbDeviceDisconnect() even if no + USB_CFG_PULLUP_IOPORTNAME is defined. Directly set D+ and D- to 0 in this + case. + +* Release 2007-12-01 + + - Optimize usbDeviceConnect() and usbDeviceDisconnect() for less code size + when USB_CFG_PULLUP_IOPORTNAME is not defined. + +* Release 2007-12-13 + + - Renamed all include-only assembler modules from *.S to *.inc so that + people don't add them to their project sources. + - Distribute leap bits in tx loop more evenly for 16 MHz module. + - Use "macro" and "endm" instead of ".macro" and ".endm" for IAR + - Avoid compiler warnings for constant expr range by casting some values in + USB descriptors. + +* Release 2008-01-21 + + - Fixed bug in 15 and 16 MHz module where the new address set with + SET_ADDRESS was already accepted at the next NAK or ACK we send, not at + the next data packet we send. This caused problems when the host polled + too fast. Thanks to Alexander Neumann for his help and patience debugging + this issue! + +* Release 2008-02-05 + + - Fixed bug in 16.5 MHz module where a register was used in the interrupt + handler before it was pushed. This bug was introduced with version + 2007-09-19 when common parts were moved to a separate file. + - Optimized CRC routine (thanks to Reimar Doeffinger). + +* Release 2008-02-16 + + - Removed outdated IAR compatibility stuff (code sections). + - Added hook macros for USB_RESET_HOOK() and USB_SET_ADDRESS_HOOK(). + - Added optional routine usbMeasureFrameLength() for calibration of the + internal RC oscillator. + +* Release 2008-02-28 + + - USB_INITIAL_DATATOKEN defaults to USBPID_DATA1 now, which means that we + start with sending USBPID_DATA0. + - Changed defaults in usbconfig-prototype.h + - Added free USB VID/PID pair for MIDI class devices + - Restructured AVR-USB as separate package, not part of PowerSwitch any more. + +* Release 2008-04-18 + + - Restructured usbdrv.c so that it is easier to read and understand. + - Better code optimization with gcc 4. + - If a second interrupt in endpoint is enabled, also add it to config + descriptor. + - Added config option for long transfers (above 254 bytes), see + USB_CFG_LONG_TRANSFERS in usbconfig.h. + - Added 20 MHz module contributed by Jeroen Benschop. + +* Release 2008-05-13 + + - Fixed bug in libs-host/hiddata.c function usbhidGetReport(): length + was not incremented, pointer to length was incremented instead. + - Added code to command line tool(s) which claims an interface. This code + is disabled by default, but may be necessary on newer Linux kernels. + - Added usbconfig.h option "USB_CFG_CHECK_DATA_TOGGLING". + - New header "usbportability.h" prepares ports to other development + environments. + - Long transfers (above 254 bytes) did not work when usbFunctionRead() was + used to supply the data. Fixed this bug. [Thanks to Alexander Neumann!] + - In hiddata.c (example code for sending/receiving data over HID), use + USB_RECIP_DEVICE instead of USB_RECIP_INTERFACE for control transfers so + that we need not claim the interface. + - in usbPoll() loop 20 times polling for RESET state instead of 10 times. + This accounts for the higher clock rates we now support. + - Added a module for 12.8 MHz RC oscillator with PLL in receiver loop. + - Added hook to SOF code so that oscillator can be tuned to USB frame clock. + - Added timeout to waitForJ loop. Helps preventing unexpected hangs. + - Added example code for oscillator tuning to libs-device (thanks to + Henrik Haftmann for the idea to this routine). + - Implemented option USB_CFG_SUPPRESS_INTR_CODE. + +* Release 2008-10-22 + + - Fixed libs-device/osctune.h: OSCCAL is memory address on ATMega88 and + similar, not offset of 0x20 needs to be added. + - Allow distribution under GPLv3 for those who have to link against other + code distributed under GPLv3. + +* Release 2008-11-26 + + - Removed libusb-win32 dependency for hid-data example in Makefile.windows. + It was never required and confused many people. + - Added extern uchar usbRxToken to usbdrv.h. + - Integrated a module with CRC checks at 18 MHz by Lukas Schrittwieser. + +* Release 2009-03-23 + + - Hid-mouse example used settings from hid-data example, fixed that. + - Renamed project to V-USB due to a trademark issue with Atmel(r). + - Changed CommercialLicense.txt and USBID-License.txt to make the + background of USB ID registration clearer. + +* Release 2009-04-15 + + - Changed CommercialLicense.txt to reflect the new range of PIDs from + Jason Kotzin. + - Removed USBID-License.txt in favor of USB-IDs-for-free.txt and + USB-ID-FAQ.txt + - Fixed a bug in the 12.8 MHz module: End Of Packet decection was made in + the center between bit 0 and 1 of each byte. This is where the data lines + are expected to change and the sampled data may therefore be nonsense. + We therefore check EOP ONLY if bits 0 AND 1 have both been read as 0 on D-. + - Fixed a bitstuffing problem in the 16 MHz module: If bit 6 was stuffed, + the unstuffing code in the receiver routine was 1 cycle too long. If + multiple bytes had the unstuffing in bit 6, the error summed up until the + receiver was out of sync. + - Included option for faster CRC routine. + Thanks to Slawomir Fras (BoskiDialer) for this code! + - Updated bits in Configuration Descriptor's bmAttributes according to + USB 1.1 (in particular bit 7, it is a must-be-set bit now). + +* Release 2009-08-22 + + - Moved first DBG1() after odDebugInit() in all examples. + - Use vector INT0_vect instead of SIG_INTERRUPT0 if defined. This makes + V-USB compatible with the new "p" suffix devices (e.g. ATMega328p). + - USB_CFG_CLOCK_KHZ setting is now required in usbconfig.h (no default any + more). + - New option USB_CFG_DRIVER_FLASH_PAGE allows boot loaders on devices with + more than 64 kB flash. + - Built-in configuration descriptor allows custom definition for second + endpoint now. + +* Release 2010-07-15 diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/CommercialLicense.txt b/adb2usb/uart2usb/vusb-20100715/usbdrv/CommercialLicense.txt new file mode 100644 index 0000000..11d07d9 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/CommercialLicense.txt @@ -0,0 +1,166 @@ +V-USB Driver Software License Agreement +Version 2009-08-03 + +THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN +ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING +THE AMOUNT ACCORDING TO SECTION 4 ("PAYMENT") TO OBJECTIVE DEVELOPMENT. + + +1 DEFINITIONS + +1.1 "OBJECTIVE DEVELOPMENT" shall mean OBJECTIVE DEVELOPMENT Software GmbH, +Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA. + +1.2 "You" shall mean the Licensee. + +1.3 "V-USB" shall mean all files included in the package distributed under +the name "vusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/vusb/) +unless otherwise noted. This includes the firmware-only USB device +implementation for Atmel AVR microcontrollers, some simple device examples +and host side software examples and libraries. + + +2 LICENSE GRANTS + +2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source +code of V-USB. + +2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the +non-exclusive right to use, copy and distribute V-USB with your hardware +product(s), restricted by the limitations in section 3 below. + +2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify +the source code and your copy of V-USB according to your needs. + +2.4 USB IDs. OBJECTIVE DEVELOPMENT furnishes you with one or two USB +Product ID(s), sent to you in e-mail. These Product IDs are reserved +exclusively for you. OBJECTIVE DEVELOPMENT has obtained USB Product ID +ranges under the Vendor ID 5824 from Wouter van Ooijen (Van Ooijen +Technische Informatica, www.voti.nl) and under the Vendor ID 8352 from +Jason Kotzin (Clay Logic, www.claylogic.com). Both owners of the Vendor IDs +have obtained these IDs from the USB Implementers Forum, Inc. +(www.usb.org). OBJECTIVE DEVELOPMENT disclaims all liability which might +arise from the assignment of USB IDs. + +2.5 USB Certification. Although not part of this agreement, we want to make +it clear that you cannot become USB certified when you use V-USB or a USB +Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't +meet the electrical specifications required by the USB specification and +the USB Implementers Forum certifies only members who bought a Vendor ID of +their own. + + +3 LICENSE RESTRICTIONS + +3.1 Number of Units. Only one of the following three definitions is +applicable. Which one is determined by the amount you pay to OBJECTIVE +DEVELOPMENT, see section 4 ("Payment") below. + +Hobby License: You may use V-USB according to section 2 above in no more +than 5 hardware units. These units must not be sold for profit. + +Entry Level License: You may use V-USB according to section 2 above in no +more than 150 hardware units. + +Professional License: You may use V-USB according to section 2 above in +any number of hardware units, except for large scale production ("unlimited +fair use"). Quantities below 10,000 units are not considered large scale +production. If your reach quantities which are obviously large scale +production, you must pay a license fee of 0.10 EUR per unit for all units +above 10,000. + +3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber +any copy of V-USB, or any of the rights granted herein. + +3.3 Transfer. You may not transfer your rights under this Agreement to +another party without OBJECTIVE DEVELOPMENT's prior written consent. If +such consent is obtained, you may permanently transfer this License to +another party. The recipient of such transfer must agree to all terms and +conditions of this Agreement. + +3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not +expressly granted. + +3.5 Non-Exclusive Rights. Your license rights under this Agreement are +non-exclusive. + +3.6 Third Party Rights. This Agreement cannot grant you rights controlled +by third parties. In particular, you are not allowed to use the USB logo or +other trademarks owned by the USB Implementers Forum, Inc. without their +consent. Since such consent depends on USB certification, it should be +noted that V-USB will not pass certification because it does not +implement checksum verification and the microcontroller ports do not meet +the electrical specifications. + + +4 PAYMENT + +The payment amount depends on the variation of this agreement (according to +section 3.1) into which you want to enter. Concrete prices are listed on +OBJECTIVE DEVELOPMENT's web site, usually at +http://www.obdev.at/vusb/license.html. You agree to pay the amount listed +there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor +or reseller. + + +5 COPYRIGHT AND OWNERSHIP + +V-USB is protected by copyright laws and international copyright +treaties, as well as other intellectual property laws and treaties. V-USB +is licensed, not sold. + + +6 TERM AND TERMINATION + +6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE +DEVELOPMENT may terminate this Agreement and revoke the granted license and +USB-IDs if you fail to comply with any of its terms and conditions. + +6.2 Survival of Terms. All provisions regarding secrecy, confidentiality +and limitation of liability shall survive termination of this agreement. + + +7 DISCLAIMER OF WARRANTY AND LIABILITY + +LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE +DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND +NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE +TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL +RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO +STATE/JURISDICTION. + +LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, +IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY +SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER +(INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, +BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY +LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE +PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE +DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY +CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS +AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB. + + +8 MISCELLANEOUS TERMS + +8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing +purposes that you entered into this agreement. + +8.2 Entire Agreement. This document represents the entire agreement between +OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by +an authorized representative of both, OBJECTIVE DEVELOPMENT and you. + +8.3 Severability. In case a provision of these terms and conditions should +be or become partly or entirely invalid, ineffective, or not executable, +the validity of all other provisions shall not be affected. + +8.4 Applicable Law. This agreement is governed by the laws of the Republic +of Austria. + +8.5 Responsible Courts. The responsible courts in Vienna/Austria will have +exclusive jurisdiction regarding all disputes in connection with this +agreement. + diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/License.txt b/adb2usb/uart2usb/vusb-20100715/usbdrv/License.txt new file mode 100644 index 0000000..4460cfb --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/License.txt @@ -0,0 +1,361 @@ +OBJECTIVE DEVELOPMENT GmbH's V-USB driver software is distributed under the +terms and conditions of the GNU GPL version 2 or the GNU GPL version 3. It is +your choice whether you apply the terms of version 2 or version 3. The full +text of GPLv2 is included below. In addition to the requirements in the GPL, +we STRONGLY ENCOURAGE you to do the following: + +(1) Publish your entire project on a web site and drop us a note with the URL. +Use the form at http://www.obdev.at/vusb/feedback.html for your submission. + +(2) Adhere to minimum publication standards. Please include AT LEAST: + - a circuit diagram in PDF, PNG or GIF format + - full source code for the host software + - a Readme.txt file in ASCII format which describes the purpose of the + project and what can be found in which directories and which files + - a reference to http://www.obdev.at/vusb/ + +(3) If you improve the driver firmware itself, please give us a free license +to your modifications for our commercial license offerings. + + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License. diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/Readme.txt b/adb2usb/uart2usb/vusb-20100715/usbdrv/Readme.txt new file mode 100644 index 0000000..970dc66 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/Readme.txt @@ -0,0 +1,172 @@ +This is the Readme file to Objective Development's firmware-only USB driver +for Atmel AVR microcontrollers. For more information please visit +http://www.obdev.at/vusb/ + +This directory contains the USB firmware only. Copy it as-is to your own +project and add all .c and .S files to your project (these files are marked +with an asterisk in the list below). Then copy usbconfig-prototype.h as +usbconfig.h to your project and edit it according to your configuration. + + +TECHNICAL DOCUMENTATION +======================= +The technical documentation (API) for the firmware driver is contained in the +file "usbdrv.h". Please read all of it carefully! Configuration options are +documented in "usbconfig-prototype.h". + +The driver consists of the following files: + Readme.txt ............. The file you are currently reading. + Changelog.txt .......... Release notes for all versions of the driver. + usbdrv.h ............... Driver interface definitions and technical docs. +* usbdrv.c ............... High level language part of the driver. Link this + module to your code! +* usbdrvasm.S ............ Assembler part of the driver. This module is mostly + a stub and includes one of the usbdrvasm*.S files + depending on processor clock. Link this module to + your code! + usbdrvasm*.inc ......... Assembler routines for particular clock frequencies. + Included by usbdrvasm.S, don't link it directly! + asmcommon.inc .......... Common assembler routines. Included by + usbdrvasm*.inc, don't link it directly! + usbconfig-prototype.h .. Prototype for your own usbdrv.h file. +* oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is + defined to a value greater than 0. Link this module + to your code! + oddebug.h .............. Interface definitions of the debug module. + usbportability.h ....... Header with compiler-dependent stuff. + usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this + module instead of usbdrvasm.S when you assembler + with IAR's tools. + License.txt ............ Open Source license for this driver. + CommercialLicense.txt .. Optional commercial license for this driver. + USB-ID-FAQ.txt ......... General infos about USB Product- and Vendor-IDs. + USB-IDs-for-free.txt ... List and terms of use for free shared PIDs. + +(*) ... These files should be linked to your project. + + +CPU CORE CLOCK FREQUENCY +======================== +We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz, +16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The +actual clock rate must be configured in usbconfig.h. + +12 MHz Clock +This is the traditional clock rate of V-USB because it's the lowest clock +rate where the timing constraints of the USB spec can be met. + +15 MHz Clock +Similar to 12 MHz, but some NOPs inserted. On the other hand, the higher clock +rate allows for some loops which make the resulting code size somewhat smaller +than the 12 MHz version. + +16 MHz Clock +This clock rate has been added for users of the Arduino board and other +ready-made boards which come with a fixed 16 MHz crystal. It's also an option +if you need the slightly higher clock rate for performance reasons. Since +16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code +is somewhat tricky and has to insert a leap cycle every third byte. + +12.8 MHz and 16.5 MHz Clock +The assembler modules for these clock rates differ from the other modules +because they have been built for an RC oscillator with only 1% precision. The +receiver code inserts leap cycles to compensate for clock deviations. 1% is +also the precision which can be achieved by calibrating the internal RC +oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL +oscillator can reach 16.5 MHz with the RC oscillator. This includes the very +popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost +all AVRs can reach 12.8 MHz, although this is outside the specified range. + +See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for +code which calibrates the RC oscillator based on the USB frame clock. + +18 MHz Clock +This module is closer to the USB specification because it performs an on the +fly CRC check for incoming packets. Packets with invalid checksum are +discarded as required by the spec. If you also implement checks for data +PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING +in usbconfig.h for more info), this ensures data integrity. Due to the CRC +tables and alignment requirements, this code is bigger than modules for other +clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1 +and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h. + +20 MHz Clock +This module is for people who won't do it with less than the maximum. Since +20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code +uses similar tricks as the 16 MHz module to insert leap cycles. + + +USB IDENTIFIERS +=============== +Every USB device needs a vendor- and a product-identifier (VID and PID). VIDs +are obtained from usb.org for a price of 1,500 USD. Once you have a VID, you +can assign PIDs at will. + +Since an entry level cost of 1,500 USD is too high for most small companies +and hobbyists, we provide some VID/PID pairs for free. See the file +USB-IDs-for-free.txt for details. + +Objective Development also has some license offerings which include product +IDs. See http://www.obdev.at/vusb/ for details. + + +DEVELOPMENT SYSTEM +================== +This driver has been developed and optimized for the GNU compiler version 3 +and 4. We recommend that you use the GNU compiler suite because it is freely +available. V-USB has also been ported to the IAR compiler and assembler. It +has been tested with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the +"small" and "tiny" memory model. Not every release is tested with IAR CC and +the driver may therefore fail to compile with IAR. Please note that gcc is +more efficient for usbdrv.c because this module has been deliberately +optimized for gcc. + +Gcc version 3 produces smaller code than version 4 due to new optimizing +capabilities which don't always improve things on 8 bit CPUs. The code size +generated by gcc 4 can be reduced with the compiler options +-fno-move-loop-invariants, -fno-tree-scev-cprop and +-fno-inline-small-functions in addition to -Os. On devices with more than +8k of flash memory, we also recommend the linker option --relax (written as +-Wl,--relax for gcc) to convert absolute calls into relative where possible. + +For more information about optimizing options see: + + http://www.tty1.net/blog/2008-04-29-avr-gcc-optimisations_en.html + +These optimizations are good for gcc 4.x. Version 3.x of gcc does not support +most of these options and produces good code anyway. + + +USING V-USB FOR FREE +==================== +The AVR firmware driver is published under the GNU General Public License +Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is +your choice whether you apply the terms of version 2 or version 3. + +If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the +following things IN ADDITION to the obligations from the GPL: + +(1) Publish your entire project on a web site and drop us a note with the URL. +Use the form at http://www.obdev.at/vusb/feedback.html for your submission. +If you don't have a web site, you can publish the project in obdev's +documentation wiki at +http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects. + +(2) Adhere to minimum publication standards. Please include AT LEAST: + - a circuit diagram in PDF, PNG or GIF format + - full source code for the host software + - a Readme.txt file in ASCII format which describes the purpose of the + project and what can be found in which directories and which files + - a reference to http://www.obdev.at/vusb/ + +(3) If you improve the driver firmware itself, please give us a free license +to your modifications for our commercial license offerings. + + +COMMERCIAL LICENSES FOR V-USB +============================= +If you don't want to publish your source code under the terms of the GPL, +you can simply pay money for V-USB. As an additional benefit you get +USB PIDs for free, reserved exclusively to you. See the file +"CommercialLicense.txt" for details. + diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/USB-ID-FAQ.txt b/adb2usb/uart2usb/vusb-20100715/usbdrv/USB-ID-FAQ.txt new file mode 100644 index 0000000..d1de8fb --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/USB-ID-FAQ.txt @@ -0,0 +1,149 @@ +Version 2009-08-22 + +========================== +WHY DO WE NEED THESE IDs? +========================== + +USB is more than a low level protocol for data transport. It also defines a +common set of requests which must be understood by all devices. And as part +of these common requests, the specification defines data structures, the +USB Descriptors, which are used to describe the properties of the device. + +From the perspective of an operating system, it is therefore possible to find +out basic properties of a device (such as e.g. the manufacturer and the name +of the device) without a device-specific driver. This is essential because +the operating system can choose a driver to load based on this information +(Plug-And-Play). + +Among the most important properties in the Device Descriptor are the USB +Vendor- and Product-ID. Both are 16 bit integers. The most simple form of +driver matching is based on these IDs. The driver announces the Vendor- and +Product-IDs of the devices it can handle and the operating system loads the +appropriate driver when the device is connected. + +It is obvious that this technique only works if the pair Vendor- plus +Product-ID is unique: Only devices which require the same driver can have the +same pair of IDs. + + +===================================================== +HOW DOES THE USB STANDARD ENSURE THAT IDs ARE UNIQUE? +===================================================== + +Since it is so important that USB IDs are unique, the USB Implementers Forum, +Inc. (usb.org) needs a way to enforce this legally. It is not forbidden by +law to build a device and assign it any random numbers as IDs. Usb.org +therefore needs an agreement to regulate the use of USB IDs. The agreement +binds only parties who agreed to it, of course. Everybody else is free to use +any numbers for their IDs. + +So how can usb.org ensure that every manufacturer of USB devices enters into +an agreement with them? They do it via trademark licensing. Usb.org has +registered the trademark "USB", all associated logos and related terms. If +you want to put an USB logo on your product or claim that it is USB +compliant, you must license these trademarks from usb.org. And this is where +you enter into an agreement. See the "USB-IF Trademark License Agreement and +Usage Guidelines for the USB-IF Logo" at +http://www.usb.org/developers/logo_license/. + +Licensing the USB trademarks requires that you buy a USB Vendor-ID from +usb.org (one-time fee of ca. 2,000 USD), that you become a member of usb.org +(yearly fee of ca. 4,000 USD) and that you meet all the technical +specifications from the USB spec. + +This means that most hobbyists and small companies will never be able to +become USB compliant, just because membership is so expensive. And you can't +be compliant with a driver based on V-USB anyway, because the AVR's port pins +don't meet the electrical specifications for USB. So, in principle, all +hobbyists and small companies are free to choose any random numbers for their +IDs. They have nothing to lose... + +There is one exception worth noting, though: If you use a sub-component which +implements USB, the vendor of the sub-components may guarantee USB +compliance. This might apply to some or all of FTDI's solutions. + + +======================================================================= +WHY SHOULD YOU OBTAIN USB IDs EVEN IF YOU DON'T LICENSE USB TRADEMARKS? +======================================================================= + +You have learned in the previous section that you are free to choose any +numbers for your IDs anyway. So why not do exactly this? There is still the +technical issue. If you choose IDs which are already in use by somebody else, +operating systems will load the wrong drivers and your device won't work. +Even if you choose IDs which are not currently in use, they may be in use in +the next version of the operating system or even after an automatic update. + +So what you need is a pair of Vendor- and Product-IDs for which you have the +guarantee that no USB compliant product uses them. This implies that no +operating system will ever ship with drivers responsible for these IDs. + + +============================================== +HOW DOES OBJECTIVE DEVELOPMENT HANDLE USB IDs? +============================================== + +Objective Development gives away pairs of USB-IDs with their V-USB licenses. +In order to ensure that these IDs are unique, Objective Development has an +agreement with the company/person who has bought the USB Vendor-ID from +usb.org. This agreement ensures that a range of USB Product-IDs is reserved +for assignment by Objective Development and that the owner of the Vendor-ID +won't give it to anybody else. + +This means that you have to trust three parties to ensure uniqueness of +your IDs: + + - Objective Development, that they don't give the same PID to more than + one person. + - The owner of the Vendor-ID that they don't assign PIDs from the range + assigned to Objective Development to anybody else. + - Usb.org that they don't assign the same Vendor-ID a second time. + + +================================== +WHO IS THE OWNER OF THE VENDOR-ID? +================================== + +Objective Development has obtained ranges of USB Product-IDs under two +Vendor-IDs: Under Vendor-ID 5824 from Wouter van Ooijen (Van Ooijen +Technische Informatica, www.voti.nl) and under Vendor-ID 8352 from Jason +Kotzin (Clay Logic, www.claylogic.com). Both VID owners have received their +Vendor-ID directly from usb.org. + + +========================================================================= +CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE? +========================================================================= + +The short answer is: Yes. All you get is a guarantee that the IDs are never +assigned to anybody else. What more do you need? + + +============================ +WHAT ABOUT SHARED ID PAIRS? +============================ + +Objective Development has reserved some PID/VID pairs for shared use. You +have no guarantee of uniqueness for them, except that no USB compliant device +uses them. In order to avoid technical problems, we must ensure that all +devices with the same pair of IDs use the same driver on kernel level. For +details, see the file USB-IDs-for-free.txt. + + +====================================================== +I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL? +====================================================== + +A 16 bit integer number cannot be protected by copyright laws. It is not +sufficiently complex. And since none of the parties involved entered into the +USB-IF Trademark License Agreement, we are not bound by this agreement. So +there is no reason why it should be illegal to sub-license USB-IDs. + + +============================================= +WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES? +============================================= + +Objective Development disclaims all liabilities which might arise from the +assignment of IDs. If you guarantee product features to your customers +without proper disclaimer, YOU are liable for that. diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/USB-IDs-for-free.txt b/adb2usb/uart2usb/vusb-20100715/usbdrv/USB-IDs-for-free.txt new file mode 100644 index 0000000..2f4d59a --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/USB-IDs-for-free.txt @@ -0,0 +1,148 @@ +Version 2009-08-22 + +=========================== +FREE USB-IDs FOR SHARED USE +=========================== + +Objective Development has reserved a set of USB Product-IDs for use according +to the guidelines outlined below. For more information about the concept of +USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees +that the IDs listed below are not used by any USB compliant devices. + + +==================== +MECHANISM OF SHARING +==================== + +From a technical point of view, two different devices can share the same USB +Vendor- and Product-ID if they require the same driver on operating system +level. We make use of this fact by assigning separate IDs for various device +classes. On application layer, devices must be distinguished by their textual +name or serial number. We offer separate sets of IDs for discrimination by +textual name and for serial number. + +Examples for shared use of USB IDs are included with V-USB in the "examples" +subdirectory. + + +====================================== +IDs FOR DISCRIMINATION BY TEXTUAL NAME +====================================== + +If you use one of the IDs listed below, your device and host-side software +must conform to these rules: + +(1) The USB device MUST provide a textual representation of the manufacturer +and product identification. The manufacturer identification MUST be available +at least in USB language 0x0409 (English/US). + +(2) The textual manufacturer identification MUST contain either an Internet +domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail +address under your control (e.g. "myname@gmx.net"). You can embed the domain +name or e-mail address in any string you like, e.g. "Objective Development +http://www.obdev.at/vusb/". + +(3) You are responsible for retaining ownership of the domain or e-mail +address for as long as any of your products are in use. + +(4) You may choose any string for the textual product identification, as long +as this string is unique within the scope of your textual manufacturer +identification. + +(5) Application side device look-up MUST be based on the textual manufacturer +and product identification in addition to VID/PID matching. The driver +matching MUST be a comparison of the entire strings, NOT a sub-string match. + +(6) For devices which implement a particular USB device class (e.g. HID), the +operating system's default class driver MUST be used. If an operating system +driver for Vendor Class devices is needed, this driver must be libusb or +libusb-win32 (see http://libusb.org/ and +http://libusb-win32.sourceforge.net/). + +Table if IDs for discrimination by textual name: + +PID dec (hex) | VID dec (hex) | Description of use +==============+===============+============================================ +1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb +--------------+---------------+-------------------------------------------- +1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are + | | NOT mice, keyboards or joysticks) +--------------+---------------+-------------------------------------------- +1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems) +--------------+---------------+-------------------------------------------- +1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices +--------------+---------------+-------------------------------------------- + +Note that Windows caches the textual product- and vendor-description for +mice, keyboards and joysticks. Name-bsed discrimination is therefore not +recommended for these device classes. + + +======================================= +IDs FOR DISCRIMINATION BY SERIAL NUMBER +======================================= + +If you use one of the IDs listed below, your device and host-side software +must conform to these rules: + +(1) The USB device MUST provide a textual representation of the serial +number. The serial number string MUST be available at least in USB language +0x0409 (English/US). + +(2) The serial number MUST start with either an Internet domain name (e.g. +"mycompany.com") registered and owned by you, or an e-mail address under your +control (e.g. "myname@gmx.net"), both terminated with a colon (":") character. +You MAY append any string you like for further discrimination of your devices. + +(3) You are responsible for retaining ownership of the domain or e-mail +address for as long as any of your products are in use. + +(5) Application side device look-up MUST be based on the serial number string +in addition to VID/PID matching. The matching must start at the first +character of the serial number string and include the colon character +terminating your domain or e-mail address. It MAY stop anywhere after that. + +(6) For devices which implement a particular USB device class (e.g. HID), the +operating system's default class driver MUST be used. If an operating system +driver for Vendor Class devices is needed, this driver must be libusb or +libusb-win32 (see http://libusb.org/ and +http://libusb-win32.sourceforge.net/). + +Table if IDs for discrimination by serial number string: + +PID dec (hex) | VID dec (hex) | Description of use +===============+===============+=========================================== +10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb +---------------+---------------+------------------------------------------- +10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are + | | NOT mice, keyboards or joysticks) +---------------+---------------+------------------------------------------- +10202 (0x27da) | 5824 (0x16c0) | For USB Mice +---------------+---------------+------------------------------------------- +10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards +---------------+---------------+------------------------------------------- +10204 (0x27db) | 5824 (0x16c0) | For USB Joysticks +---------------+---------------+------------------------------------------- +10205 (0x27dc) | 5824 (0x16c0) | For CDC-ACM class devices (modems) +---------------+---------------+------------------------------------------- +10206 (0x27dd) | 5824 (0x16c0) | For MIDI class devices +---------------+---------------+------------------------------------------- + + +================= +ORIGIN OF USB-IDs +================= + +OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed +here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition. +Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc. +(see www.usb.org). The VID is registered for the company name "Van Ooijen +Technische Informatica". + + +========== +DISCLAIMER +========== + +OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any +problems which are caused by the shared use of these VID/PID pairs. diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/asmcommon.inc b/adb2usb/uart2usb/vusb-20100715/usbdrv/asmcommon.inc new file mode 100644 index 0000000..07d692b --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/asmcommon.inc @@ -0,0 +1,188 @@ +/* Name: asmcommon.inc + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2007-11-05 + * Tabsize: 4 + * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Revision: $Id$ + */ + +/* Do not link this file! Link usbdrvasm.S instead, which includes the + * appropriate implementation! + */ + +/* +General Description: +This file contains assembler code which is shared among the USB driver +implementations for different CPU cocks. Since the code must be inserted +in the middle of the module, it's split out into this file and #included. + +Jump destinations called from outside: + sofError: Called when no start sequence was found. + se0: Called when a package has been successfully received. + overflow: Called when receive buffer overflows. + doReturn: Called after sending data. + +Outside jump destinations used by this module: + waitForJ: Called to receive an already arriving packet. + sendAckAndReti: + sendNakAndReti: + sendCntAndReti: + usbSendAndReti: + +The following macros must be defined before this file is included: + .macro POP_STANDARD + .endm + .macro POP_RETI + .endm +*/ + +#define token x1 + +overflow: + ldi x2, 1< 0 + +#warning "Never compile production devices with debugging enabled" + +static void uartPutc(char c) +{ + while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ + ODDBG_UDR = c; +} + +static uchar hexAscii(uchar h) +{ + h &= 0xf; + if(h >= 10) + h += 'a' - (uchar)10 - '0'; + h += '0'; + return h; +} + +static void printHex(uchar c) +{ + uartPutc(hexAscii(c >> 4)); + uartPutc(hexAscii(c)); +} + +void odDebug(uchar prefix, uchar *data, uchar len) +{ + printHex(prefix); + uartPutc(':'); + while(len--){ + uartPutc(' '); + printHex(*data++); + } + uartPutc('\r'); + uartPutc('\n'); +} + +#endif diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/oddebug.h b/adb2usb/uart2usb/vusb-20100715/usbdrv/oddebug.h new file mode 100644 index 0000000..d61309d --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/oddebug.h @@ -0,0 +1,123 @@ +/* Name: oddebug.h + * Project: AVR library + * Author: Christian Starkjohann + * Creation Date: 2005-01-16 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: oddebug.h 692 2008-11-07 15:07:40Z cs $ + */ + +#ifndef __oddebug_h_included__ +#define __oddebug_h_included__ + +/* +General Description: +This module implements a function for debug logs on the serial line of the +AVR microcontroller. Debugging can be configured with the define +'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging +calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is +2, DBG1 and DBG2 logs will be printed. + +A debug log consists of a label ('prefix') to indicate which debug log created +the output and a memory block to dump in hex ('data' and 'len'). +*/ + + +#ifndef F_CPU +# define F_CPU 12000000 /* 12 MHz */ +#endif + +/* make sure we have the UART defines: */ +#include "usbportability.h" + +#ifndef uchar +# define uchar unsigned char +#endif + +#if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */ +# warning "Debugging disabled because device has no UART" +# undef DEBUG_LEVEL +#endif + +#ifndef DEBUG_LEVEL +# define DEBUG_LEVEL 0 +#endif + +/* ------------------------------------------------------------------------- */ + +#if DEBUG_LEVEL > 0 +# define DBG1(prefix, data, len) odDebug(prefix, data, len) +#else +# define DBG1(prefix, data, len) +#endif + +#if DEBUG_LEVEL > 1 +# define DBG2(prefix, data, len) odDebug(prefix, data, len) +#else +# define DBG2(prefix, data, len) +#endif + +/* ------------------------------------------------------------------------- */ + +#if DEBUG_LEVEL > 0 +extern void odDebug(uchar prefix, uchar *data, uchar len); + +/* Try to find our control registers; ATMEL likes to rename these */ + +#if defined UBRR +# define ODDBG_UBRR UBRR +#elif defined UBRRL +# define ODDBG_UBRR UBRRL +#elif defined UBRR0 +# define ODDBG_UBRR UBRR0 +#elif defined UBRR0L +# define ODDBG_UBRR UBRR0L +#endif + +#if defined UCR +# define ODDBG_UCR UCR +#elif defined UCSRB +# define ODDBG_UCR UCSRB +#elif defined UCSR0B +# define ODDBG_UCR UCSR0B +#endif + +#if defined TXEN +# define ODDBG_TXEN TXEN +#else +# define ODDBG_TXEN TXEN0 +#endif + +#if defined USR +# define ODDBG_USR USR +#elif defined UCSRA +# define ODDBG_USR UCSRA +#elif defined UCSR0A +# define ODDBG_USR UCSR0A +#endif + +#if defined UDRE +# define ODDBG_UDRE UDRE +#else +# define ODDBG_UDRE UDRE0 +#endif + +#if defined UDR +# define ODDBG_UDR UDR +#elif defined UDR0 +# define ODDBG_UDR UDR0 +#endif + +static inline void odDebugInit(void) +{ + ODDBG_UCR |= (1<len & 0x10){ /* packet buffer was empty */ + txStatus->buffer[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* toggle token */ + }else{ + txStatus->len = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */ + } + p = txStatus->buffer + 1; + i = len; + do{ /* if len == 0, we still copy 1 byte, but that's no problem */ + *p++ = *data++; + }while(--i > 0); /* loop control at the end is 2 bytes shorter than at beginning */ + usbCrc16Append(&txStatus->buffer[1], len); + txStatus->len = len + 4; /* len must be given including sync byte */ + DBG2(0x21 + (((int)txStatus >> 3) & 3), txStatus->buffer, len + 3); +} + +USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len) +{ + usbGenericSetInterrupt(data, len, &usbTxStatus1); +} +#endif + +#if USB_CFG_HAVE_INTRIN_ENDPOINT3 +USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len) +{ + usbGenericSetInterrupt(data, len, &usbTxStatus3); +} +#endif +#endif /* USB_CFG_SUPPRESS_INTR_CODE */ + +/* ------------------ utilities for code following below ------------------- */ + +/* Use defines for the switch statement so that we can choose between an + * if()else if() and a switch/case based implementation. switch() is more + * efficient for a LARGE set of sequential choices, if() is better in all other + * cases. + */ +#if USB_CFG_USE_SWITCH_STATEMENT +# define SWITCH_START(cmd) switch(cmd){{ +# define SWITCH_CASE(value) }break; case (value):{ +# define SWITCH_CASE2(v1,v2) }break; case (v1): case(v2):{ +# define SWITCH_CASE3(v1,v2,v3) }break; case (v1): case(v2): case(v3):{ +# define SWITCH_DEFAULT }break; default:{ +# define SWITCH_END }} +#else +# define SWITCH_START(cmd) {uchar _cmd = cmd; if(0){ +# define SWITCH_CASE(value) }else if(_cmd == (value)){ +# define SWITCH_CASE2(v1,v2) }else if(_cmd == (v1) || _cmd == (v2)){ +# define SWITCH_CASE3(v1,v2,v3) }else if(_cmd == (v1) || _cmd == (v2) || (_cmd == v3)){ +# define SWITCH_DEFAULT }else{ +# define SWITCH_END }} +#endif + +#ifndef USB_RX_USER_HOOK +#define USB_RX_USER_HOOK(data, len) +#endif +#ifndef USB_SET_ADDRESS_HOOK +#define USB_SET_ADDRESS_HOOK() +#endif + +/* ------------------------------------------------------------------------- */ + +/* We use if() instead of #if in the macro below because #if can't be used + * in macros and the compiler optimizes constant conditions anyway. + * This may cause problems with undefined symbols if compiled without + * optimizing! + */ +#define GET_DESCRIPTOR(cfgProp, staticName) \ + if(cfgProp){ \ + if((cfgProp) & USB_PROP_IS_RAM) \ + flags = 0; \ + if((cfgProp) & USB_PROP_IS_DYNAMIC){ \ + len = usbFunctionDescriptor(rq); \ + }else{ \ + len = USB_PROP_LENGTH(cfgProp); \ + usbMsgPtr = (uchar *)(staticName); \ + } \ + } + +/* usbDriverDescriptor() is similar to usbFunctionDescriptor(), but used + * internally for all types of descriptors. + */ +static inline usbMsgLen_t usbDriverDescriptor(usbRequest_t *rq) +{ +usbMsgLen_t len = 0; +uchar flags = USB_FLG_MSGPTR_IS_ROM; + + SWITCH_START(rq->wValue.bytes[1]) + SWITCH_CASE(USBDESCR_DEVICE) /* 1 */ + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_DEVICE, usbDescriptorDevice) + SWITCH_CASE(USBDESCR_CONFIG) /* 2 */ + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_CONFIGURATION, usbDescriptorConfiguration) + SWITCH_CASE(USBDESCR_STRING) /* 3 */ +#if USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC + if(USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_RAM) + flags = 0; + len = usbFunctionDescriptor(rq); +#else /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ + SWITCH_START(rq->wValue.bytes[0]) + SWITCH_CASE(0) + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_0, usbDescriptorString0) + SWITCH_CASE(1) + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor) + SWITCH_CASE(2) + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_PRODUCT, usbDescriptorStringDevice) + SWITCH_CASE(3) + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, usbDescriptorStringSerialNumber) + SWITCH_DEFAULT + if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){ + len = usbFunctionDescriptor(rq); + } + SWITCH_END +#endif /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ +#if USB_CFG_DESCR_PROPS_HID_REPORT /* only support HID descriptors if enabled */ + SWITCH_CASE(USBDESCR_HID) /* 0x21 */ + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID, usbDescriptorConfiguration + 18) + SWITCH_CASE(USBDESCR_HID_REPORT)/* 0x22 */ + GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID_REPORT, usbDescriptorHidReport) +#endif + SWITCH_DEFAULT + if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){ + len = usbFunctionDescriptor(rq); + } + SWITCH_END + usbMsgFlags = flags; + return len; +} + +/* ------------------------------------------------------------------------- */ + +/* usbDriverSetup() is similar to usbFunctionSetup(), but it's used for + * standard requests instead of class and custom requests. + */ +static inline usbMsgLen_t usbDriverSetup(usbRequest_t *rq) +{ +uchar len = 0, *dataPtr = usbTxBuf + 9; /* there are 2 bytes free space at the end of the buffer */ +uchar value = rq->wValue.bytes[0]; +#if USB_CFG_IMPLEMENT_HALT +uchar index = rq->wIndex.bytes[0]; +#endif + + dataPtr[0] = 0; /* default reply common to USBRQ_GET_STATUS and USBRQ_GET_INTERFACE */ + SWITCH_START(rq->bRequest) + SWITCH_CASE(USBRQ_GET_STATUS) /* 0 */ + uchar recipient = rq->bmRequestType & USBRQ_RCPT_MASK; /* assign arith ops to variables to enforce byte size */ + if(USB_CFG_IS_SELF_POWERED && recipient == USBRQ_RCPT_DEVICE) + dataPtr[0] = USB_CFG_IS_SELF_POWERED; +#if USB_CFG_IMPLEMENT_HALT + if(recipient == USBRQ_RCPT_ENDPOINT && index == 0x81) /* request status for endpoint 1 */ + dataPtr[0] = usbTxLen1 == USBPID_STALL; +#endif + dataPtr[1] = 0; + len = 2; +#if USB_CFG_IMPLEMENT_HALT + SWITCH_CASE2(USBRQ_CLEAR_FEATURE, USBRQ_SET_FEATURE) /* 1, 3 */ + if(value == 0 && index == 0x81){ /* feature 0 == HALT for endpoint == 1 */ + usbTxLen1 = rq->bRequest == USBRQ_CLEAR_FEATURE ? USBPID_NAK : USBPID_STALL; + usbResetDataToggling(); + } +#endif + SWITCH_CASE(USBRQ_SET_ADDRESS) /* 5 */ + usbNewDeviceAddr = value; + USB_SET_ADDRESS_HOOK(); + SWITCH_CASE(USBRQ_GET_DESCRIPTOR) /* 6 */ + len = usbDriverDescriptor(rq); + goto skipMsgPtrAssignment; + SWITCH_CASE(USBRQ_GET_CONFIGURATION) /* 8 */ + dataPtr = &usbConfiguration; /* send current configuration value */ + len = 1; + SWITCH_CASE(USBRQ_SET_CONFIGURATION) /* 9 */ + usbConfiguration = value; + usbResetStall(); + SWITCH_CASE(USBRQ_GET_INTERFACE) /* 10 */ + len = 1; +#if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE + SWITCH_CASE(USBRQ_SET_INTERFACE) /* 11 */ + usbResetDataToggling(); + usbResetStall(); +#endif + SWITCH_DEFAULT /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */ + /* Should we add an optional hook here? */ + SWITCH_END + usbMsgPtr = dataPtr; +skipMsgPtrAssignment: + return len; +} + +/* ------------------------------------------------------------------------- */ + +/* usbProcessRx() is called for every message received by the interrupt + * routine. It distinguishes between SETUP and DATA packets and processes + * them accordingly. + */ +static inline void usbProcessRx(uchar *data, uchar len) +{ +usbRequest_t *rq = (void *)data; + +/* usbRxToken can be: + * 0x2d 00101101 (USBPID_SETUP for setup data) + * 0xe1 11100001 (USBPID_OUT: data phase of setup transfer) + * 0...0x0f for OUT on endpoint X + */ + DBG2(0x10 + (usbRxToken & 0xf), data, len + 2); /* SETUP=1d, SETUP-DATA=11, OUTx=1x */ + USB_RX_USER_HOOK(data, len) +#if USB_CFG_IMPLEMENT_FN_WRITEOUT + if(usbRxToken < 0x10){ /* OUT to endpoint != 0: endpoint number in usbRxToken */ + usbFunctionWriteOut(data, len); + return; + } +#endif + if(usbRxToken == (uchar)USBPID_SETUP){ + if(len != 8) /* Setup size must be always 8 bytes. Ignore otherwise. */ + return; + usbMsgLen_t replyLen; + usbTxBuf[0] = USBPID_DATA0; /* initialize data toggling */ + usbTxLen = USBPID_NAK; /* abort pending transmit */ + usbMsgFlags = 0; + uchar type = rq->bmRequestType & USBRQ_TYPE_MASK; + if(type != USBRQ_TYPE_STANDARD){ /* standard requests are handled by driver */ + replyLen = usbFunctionSetup(data); + }else{ + replyLen = usbDriverSetup(rq); + } +#if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE + if(replyLen == USB_NO_MSG){ /* use user-supplied read/write function */ + /* do some conditioning on replyLen, but on IN transfers only */ + if((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE){ + if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */ + replyLen = rq->wLength.bytes[0]; + }else{ + replyLen = rq->wLength.word; + } + } + usbMsgFlags = USB_FLG_USE_USER_RW; + }else /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the maximum transfer len. */ +#endif + if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */ + if(!rq->wLength.bytes[1] && replyLen > rq->wLength.bytes[0]) /* limit length to max */ + replyLen = rq->wLength.bytes[0]; + }else{ + if(replyLen > rq->wLength.word) /* limit length to max */ + replyLen = rq->wLength.word; + } + usbMsgLen = replyLen; + }else{ /* usbRxToken must be USBPID_OUT, which means data phase of setup (control-out) */ +#if USB_CFG_IMPLEMENT_FN_WRITE + if(usbMsgFlags & USB_FLG_USE_USER_RW){ + uchar rval = usbFunctionWrite(data, len); + if(rval == 0xff){ /* an error occurred */ + usbTxLen = USBPID_STALL; + }else if(rval != 0){ /* This was the final package */ + usbMsgLen = 0; /* answer with a zero-sized data packet */ + } + } +#endif + } +} + +/* ------------------------------------------------------------------------- */ + +/* This function is similar to usbFunctionRead(), but it's also called for + * data handled automatically by the driver (e.g. descriptor reads). + */ +static uchar usbDeviceRead(uchar *data, uchar len) +{ + if(len > 0){ /* don't bother app with 0 sized reads */ +#if USB_CFG_IMPLEMENT_FN_READ + if(usbMsgFlags & USB_FLG_USE_USER_RW){ + len = usbFunctionRead(data, len); + }else +#endif + { + uchar i = len, *r = usbMsgPtr; + if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */ + do{ + uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */ + *data++ = c; + r++; + }while(--i); + }else{ /* RAM data */ + do{ + *data++ = *r++; + }while(--i); + } + usbMsgPtr = r; + } + } + return len; +} + +/* ------------------------------------------------------------------------- */ + +/* usbBuildTxBlock() is called when we have data to transmit and the + * interrupt routine's transmit buffer is empty. + */ +static inline void usbBuildTxBlock(void) +{ +usbMsgLen_t wantLen; +uchar len; + + wantLen = usbMsgLen; + if(wantLen > 8) + wantLen = 8; + usbMsgLen -= wantLen; + usbTxBuf[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* DATA toggling */ + len = usbDeviceRead(usbTxBuf + 1, wantLen); + if(len <= 8){ /* valid data packet */ + usbCrc16Append(&usbTxBuf[1], len); + len += 4; /* length including sync byte */ + if(len < 12) /* a partial package identifies end of message */ + usbMsgLen = USB_NO_MSG; + }else{ + len = USBPID_STALL; /* stall the endpoint */ + usbMsgLen = USB_NO_MSG; + } + usbTxLen = len; + DBG2(0x20, usbTxBuf, len-1); +} + +/* ------------------------------------------------------------------------- */ + +static inline void usbHandleResetHook(uchar notResetState) +{ +#ifdef USB_RESET_HOOK +static uchar wasReset; +uchar isReset = !notResetState; + + if(wasReset != isReset){ + USB_RESET_HOOK(isReset); + wasReset = isReset; + } +#endif +} + +/* ------------------------------------------------------------------------- */ + +USB_PUBLIC void usbPoll(void) +{ +schar len; +uchar i; + + len = usbRxLen - 3; + if(len >= 0){ +/* We could check CRC16 here -- but ACK has already been sent anyway. If you + * need data integrity checks with this driver, check the CRC in your app + * code and report errors back to the host. Since the ACK was already sent, + * retries must be handled on application level. + * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3); + */ + usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len); +#if USB_CFG_HAVE_FLOWCONTROL + if(usbRxLen > 0) /* only mark as available if not inactivated */ + usbRxLen = 0; +#else + usbRxLen = 0; /* mark rx buffer as available */ +#endif + } + if(usbTxLen & 0x10){ /* transmit system idle */ + if(usbMsgLen != USB_NO_MSG){ /* transmit data pending? */ + usbBuildTxBlock(); + } + } + for(i = 20; i > 0; i--){ + uchar usbLineStatus = USBIN & USBMASK; + if(usbLineStatus != 0) /* SE0 has ended */ + goto isNotReset; + } + /* RESET condition, called multiple times during reset */ + usbNewDeviceAddr = 0; + usbDeviceAddr = 0; + usbResetStall(); + DBG1(0xff, 0, 0); +isNotReset: + usbHandleResetHook(i); +} + +/* ------------------------------------------------------------------------- */ + +USB_PUBLIC void usbInit(void) +{ +#if USB_INTR_CFG_SET != 0 + USB_INTR_CFG |= USB_INTR_CFG_SET; +#endif +#if USB_INTR_CFG_CLR != 0 + USB_INTR_CFG &= ~(USB_INTR_CFG_CLR); +#endif + USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT); + usbResetDataToggling(); +#if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE + usbTxLen1 = USBPID_NAK; +#if USB_CFG_HAVE_INTRIN_ENDPOINT3 + usbTxLen3 = USBPID_NAK; +#endif +#endif +} + +/* ------------------------------------------------------------------------- */ diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrv.h b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrv.h new file mode 100644 index 0000000..3a78f30 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrv.h @@ -0,0 +1,735 @@ +/* Name: usbdrv.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2004-12-29 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbdrv.h 793 2010-07-15 15:58:11Z cs $ + */ + +#ifndef __usbdrv_h_included__ +#define __usbdrv_h_included__ +#include "usbconfig.h" +#include "usbportability.h" + +/* +Hardware Prerequisites: +======================= +USB lines D+ and D- MUST be wired to the same I/O port. We recommend that D+ +triggers the interrupt (best achieved by using INT0 for D+), but it is also +possible to trigger the interrupt from D-. If D- is used, interrupts are also +triggered by SOF packets. D- requires a pull-up of 1.5k to +3.5V (and the +device must be powered at 3.5V) to identify as low-speed USB device. A +pull-down or pull-up of 1M SHOULD be connected from D+ to +3.5V to prevent +interference when no USB master is connected. If you use Zener diodes to limit +the voltage on D+ and D-, you MUST use a pull-down resistor, not a pull-up. +We use D+ as interrupt source and not D- because it does not trigger on +keep-alive and RESET states. If you want to count keep-alive events with +USB_COUNT_SOF, you MUST use D- as an interrupt source. + +As a compile time option, the 1.5k pull-up resistor on D- can be made +switchable to allow the device to disconnect at will. See the definition of +usbDeviceConnect() and usbDeviceDisconnect() further down in this file. + +Please adapt the values in usbconfig.h according to your hardware! + +The device MUST be clocked at exactly 12 MHz, 15 MHz, 16 MHz or 20 MHz +or at 12.8 MHz resp. 16.5 MHz +/- 1%. See usbconfig-prototype.h for details. + + +Limitations: +============ +Robustness with respect to communication errors: +The driver assumes error-free communication. It DOES check for errors in +the PID, but does NOT check bit stuffing errors, SE0 in middle of a byte, +token CRC (5 bit) and data CRC (16 bit). CRC checks can not be performed due +to timing constraints: We must start sending a reply within 7 bit times. +Bit stuffing and misplaced SE0 would have to be checked in real-time, but CPU +performance does not permit that. The driver does not check Data0/Data1 +toggling, but application software can implement the check. + +Input characteristics: +Since no differential receiver circuit is used, electrical interference +robustness may suffer. The driver samples only one of the data lines with +an ordinary I/O pin's input characteristics. However, since this is only a +low speed USB implementation and the specification allows for 8 times the +bit rate over the same hardware, we should be on the safe side. Even the spec +requires detection of asymmetric states at high bit rate for SE0 detection. + +Number of endpoints: +The driver supports the following endpoints: + +- Endpoint 0, the default control endpoint. +- Any number of interrupt- or bulk-out endpoints. The data is sent to + usbFunctionWriteOut() and USB_CFG_IMPLEMENT_FN_WRITEOUT must be defined + to 1 to activate this feature. The endpoint number can be found in the + global variable 'usbRxToken'. +- One default interrupt- or bulk-in endpoint. This endpoint is used for + interrupt- or bulk-in transfers which are not handled by any other endpoint. + You must define USB_CFG_HAVE_INTRIN_ENDPOINT in order to activate this + feature and call usbSetInterrupt() to send interrupt/bulk data. +- One additional interrupt- or bulk-in endpoint. This was endpoint 3 in + previous versions of this driver but can now be configured to any endpoint + number. You must define USB_CFG_HAVE_INTRIN_ENDPOINT3 in order to activate + this feature and call usbSetInterrupt3() to send interrupt/bulk data. The + endpoint number can be set with USB_CFG_EP3_NUMBER. + +Please note that the USB standard forbids bulk endpoints for low speed devices! +Most operating systems allow them anyway, but the AVR will spend 90% of the CPU +time in the USB interrupt polling for bulk data. + +Maximum data payload: +Data payload of control in and out transfers may be up to 254 bytes. In order +to accept payload data of out transfers, you need to implement +'usbFunctionWrite()'. + +USB Suspend Mode supply current: +The USB standard limits power consumption to 500uA when the bus is in suspend +mode. This is not a problem for self-powered devices since they don't need +bus power anyway. Bus-powered devices can achieve this only by putting the +CPU in sleep mode. The driver does not implement suspend handling by itself. +However, the application may implement activity monitoring and wakeup from +sleep. The host sends regular SE0 states on the bus to keep it active. These +SE0 states can be detected by using D- as the interrupt source. Define +USB_COUNT_SOF to 1 and use the global variable usbSofCount to check for bus +activity. + +Operation without an USB master: +The driver behaves neutral without connection to an USB master if D- reads +as 1. To avoid spurious interrupts, we recommend a high impedance (e.g. 1M) +pull-down or pull-up resistor on D+ (interrupt). If Zener diodes are used, +use a pull-down. If D- becomes statically 0, the driver may block in the +interrupt routine. + +Interrupt latency: +The application must ensure that the USB interrupt is not disabled for more +than 25 cycles (this is for 12 MHz, faster clocks allow longer latency). +This implies that all interrupt routines must either have the "ISR_NOBLOCK" +attribute set (see "avr/interrupt.h") or be written in assembler with "sei" +as the first instruction. + +Maximum interrupt duration / CPU cycle consumption: +The driver handles all USB communication during the interrupt service +routine. The routine will not return before an entire USB message is received +and the reply is sent. This may be up to ca. 1200 cycles @ 12 MHz (= 100us) if +the host conforms to the standard. The driver will consume CPU cycles for all +USB messages, even if they address another (low-speed) device on the same bus. + +*/ + +/* ------------------------------------------------------------------------- */ +/* --------------------------- Module Interface ---------------------------- */ +/* ------------------------------------------------------------------------- */ + +#define USBDRV_VERSION 20100715 +/* This define uniquely identifies a driver version. It is a decimal number + * constructed from the driver's release date in the form YYYYMMDD. If the + * driver's behavior or interface changes, you can use this constant to + * distinguish versions. If it is not defined, the driver's release date is + * older than 2006-01-25. + */ + + +#ifndef USB_PUBLIC +#define USB_PUBLIC +#endif +/* USB_PUBLIC is used as declaration attribute for all functions exported by + * the USB driver. The default is no attribute (see above). You may define it + * to static either in usbconfig.h or from the command line if you include + * usbdrv.c instead of linking against it. Including the C module of the driver + * directly in your code saves a couple of bytes in flash memory. + */ + +#ifndef __ASSEMBLER__ +#ifndef uchar +#define uchar unsigned char +#endif +#ifndef schar +#define schar signed char +#endif +/* shortcuts for well defined 8 bit integer types */ + +#if USB_CFG_LONG_TRANSFERS /* if more than 254 bytes transfer size required */ +# define usbMsgLen_t unsigned +#else +# define usbMsgLen_t uchar +#endif +/* usbMsgLen_t is the data type used for transfer lengths. By default, it is + * defined to uchar, allowing a maximum of 254 bytes (255 is reserved for + * USB_NO_MSG below). If the usbconfig.h defines USB_CFG_LONG_TRANSFERS to 1, + * a 16 bit data type is used, allowing up to 16384 bytes (the rest is used + * for flags in the descriptor configuration). + */ +#define USB_NO_MSG ((usbMsgLen_t)-1) /* constant meaning "no message" */ + +struct usbRequest; /* forward declaration */ + +USB_PUBLIC void usbInit(void); +/* This function must be called before interrupts are enabled and the main + * loop is entered. We exepct that the PORT and DDR bits for D+ and D- have + * not been changed from their default status (which is 0). If you have changed + * them, set both back to 0 (configure them as input with no internal pull-up). + */ +USB_PUBLIC void usbPoll(void); +/* This function must be called at regular intervals from the main loop. + * Maximum delay between calls is somewhat less than 50ms (USB timeout for + * accepting a Setup message). Otherwise the device will not be recognized. + * Please note that debug outputs through the UART take ~ 0.5ms per byte + * at 19200 bps. + */ +extern uchar *usbMsgPtr; +/* This variable may be used to pass transmit data to the driver from the + * implementation of usbFunctionWrite(). It is also used internally by the + * driver for standard control requests. + */ +USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8]); +/* This function is called when the driver receives a SETUP transaction from + * the host which is not answered by the driver itself (in practice: class and + * vendor requests). All control transfers start with a SETUP transaction where + * the host communicates the parameters of the following (optional) data + * transfer. The SETUP data is available in the 'data' parameter which can + * (and should) be casted to 'usbRequest_t *' for a more user-friendly access + * to parameters. + * + * If the SETUP indicates a control-in transfer, you should provide the + * requested data to the driver. There are two ways to transfer this data: + * (1) Set the global pointer 'usbMsgPtr' to the base of the static RAM data + * block and return the length of the data in 'usbFunctionSetup()'. The driver + * will handle the rest. Or (2) return USB_NO_MSG in 'usbFunctionSetup()'. The + * driver will then call 'usbFunctionRead()' when data is needed. See the + * documentation for usbFunctionRead() for details. + * + * If the SETUP indicates a control-out transfer, the only way to receive the + * data from the host is through the 'usbFunctionWrite()' call. If you + * implement this function, you must return USB_NO_MSG in 'usbFunctionSetup()' + * to indicate that 'usbFunctionWrite()' should be used. See the documentation + * of this function for more information. If you just want to ignore the data + * sent by the host, return 0 in 'usbFunctionSetup()'. + * + * Note that calls to the functions usbFunctionRead() and usbFunctionWrite() + * are only done if enabled by the configuration in usbconfig.h. + */ +USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq); +/* You need to implement this function ONLY if you provide USB descriptors at + * runtime (which is an expert feature). It is very similar to + * usbFunctionSetup() above, but it is called only to request USB descriptor + * data. See the documentation of usbFunctionSetup() above for more info. + */ +#if USB_CFG_HAVE_INTRIN_ENDPOINT +USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len); +/* This function sets the message which will be sent during the next interrupt + * IN transfer. The message is copied to an internal buffer and must not exceed + * a length of 8 bytes. The message may be 0 bytes long just to indicate the + * interrupt status to the host. + * If you need to transfer more bytes, use a control read after the interrupt. + */ +#define usbInterruptIsReady() (usbTxLen1 & 0x10) +/* This macro indicates whether the last interrupt message has already been + * sent. If you set a new interrupt message before the old was sent, the + * message already buffered will be lost. + */ +#if USB_CFG_HAVE_INTRIN_ENDPOINT3 +USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len); +#define usbInterruptIsReady3() (usbTxLen3 & 0x10) +/* Same as above for endpoint 3 */ +#endif +#endif /* USB_CFG_HAVE_INTRIN_ENDPOINT */ +#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* simplified interface for backward compatibility */ +#define usbHidReportDescriptor usbDescriptorHidReport +/* should be declared as: PROGMEM char usbHidReportDescriptor[]; */ +/* If you implement an HID device, you need to provide a report descriptor. + * The HID report descriptor syntax is a bit complex. If you understand how + * report descriptors are constructed, we recommend that you use the HID + * Descriptor Tool from usb.org, see http://www.usb.org/developers/hidpage/. + * Otherwise you should probably start with a working example. + */ +#endif /* USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH */ +#if USB_CFG_IMPLEMENT_FN_WRITE +USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len); +/* This function is called by the driver to provide a control transfer's + * payload data (control-out). It is called in chunks of up to 8 bytes. The + * total count provided in the current control transfer can be obtained from + * the 'length' property in the setup data. If an error occurred during + * processing, return 0xff (== -1). The driver will answer the entire transfer + * with a STALL token in this case. If you have received the entire payload + * successfully, return 1. If you expect more data, return 0. If you don't + * know whether the host will send more data (you should know, the total is + * provided in the usbFunctionSetup() call!), return 1. + * NOTE: If you return 0xff for STALL, 'usbFunctionWrite()' may still be called + * for the remaining data. You must continue to return 0xff for STALL in these + * calls. + * In order to get usbFunctionWrite() called, define USB_CFG_IMPLEMENT_FN_WRITE + * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. + */ +#endif /* USB_CFG_IMPLEMENT_FN_WRITE */ +#if USB_CFG_IMPLEMENT_FN_READ +USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len); +/* This function is called by the driver to ask the application for a control + * transfer's payload data (control-in). It is called in chunks of up to 8 + * bytes each. You should copy the data to the location given by 'data' and + * return the actual number of bytes copied. If you return less than requested, + * the control-in transfer is terminated. If you return 0xff, the driver aborts + * the transfer with a STALL token. + * In order to get usbFunctionRead() called, define USB_CFG_IMPLEMENT_FN_READ + * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. + */ +#endif /* USB_CFG_IMPLEMENT_FN_READ */ + +extern uchar usbRxToken; /* may be used in usbFunctionWriteOut() below */ +#if USB_CFG_IMPLEMENT_FN_WRITEOUT +USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len); +/* This function is called by the driver when data is received on an interrupt- + * or bulk-out endpoint. The endpoint number can be found in the global + * variable usbRxToken. You must define USB_CFG_IMPLEMENT_FN_WRITEOUT to 1 in + * usbconfig.h to get this function called. + */ +#endif /* USB_CFG_IMPLEMENT_FN_WRITEOUT */ +#ifdef USB_CFG_PULLUP_IOPORTNAME +#define usbDeviceConnect() ((USB_PULLUP_DDR |= (1<device, 1=device->host + * t ..... type: 0=standard, 1=class, 2=vendor, 3=reserved + * r ..... recipient: 0=device, 1=interface, 2=endpoint, 3=other + */ + +/* USB setup recipient values */ +#define USBRQ_RCPT_MASK 0x1f +#define USBRQ_RCPT_DEVICE 0 +#define USBRQ_RCPT_INTERFACE 1 +#define USBRQ_RCPT_ENDPOINT 2 + +/* USB request type values */ +#define USBRQ_TYPE_MASK 0x60 +#define USBRQ_TYPE_STANDARD (0<<5) +#define USBRQ_TYPE_CLASS (1<<5) +#define USBRQ_TYPE_VENDOR (2<<5) + +/* USB direction values: */ +#define USBRQ_DIR_MASK 0x80 +#define USBRQ_DIR_HOST_TO_DEVICE (0<<7) +#define USBRQ_DIR_DEVICE_TO_HOST (1<<7) + +/* USB Standard Requests */ +#define USBRQ_GET_STATUS 0 +#define USBRQ_CLEAR_FEATURE 1 +#define USBRQ_SET_FEATURE 3 +#define USBRQ_SET_ADDRESS 5 +#define USBRQ_GET_DESCRIPTOR 6 +#define USBRQ_SET_DESCRIPTOR 7 +#define USBRQ_GET_CONFIGURATION 8 +#define USBRQ_SET_CONFIGURATION 9 +#define USBRQ_GET_INTERFACE 10 +#define USBRQ_SET_INTERFACE 11 +#define USBRQ_SYNCH_FRAME 12 + +/* USB descriptor constants */ +#define USBDESCR_DEVICE 1 +#define USBDESCR_CONFIG 2 +#define USBDESCR_STRING 3 +#define USBDESCR_INTERFACE 4 +#define USBDESCR_ENDPOINT 5 +#define USBDESCR_HID 0x21 +#define USBDESCR_HID_REPORT 0x22 +#define USBDESCR_HID_PHYS 0x23 + +//#define USBATTR_BUSPOWER 0x80 // USB 1.1 does not define this value any more +#define USBATTR_SELFPOWER 0x40 +#define USBATTR_REMOTEWAKE 0x20 + +/* USB HID Requests */ +#define USBRQ_HID_GET_REPORT 0x01 +#define USBRQ_HID_GET_IDLE 0x02 +#define USBRQ_HID_GET_PROTOCOL 0x03 +#define USBRQ_HID_SET_REPORT 0x09 +#define USBRQ_HID_SET_IDLE 0x0a +#define USBRQ_HID_SET_PROTOCOL 0x0b + +/* ------------------------------------------------------------------------- */ + +#endif /* __usbdrv_h_included__ */ diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm.S b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm.S new file mode 100644 index 0000000..45fcf18 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm.S @@ -0,0 +1,393 @@ +/* Name: usbdrvasm.S + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2007-06-13 + * Tabsize: 4 + * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Revision: $Id: usbdrvasm.S 785 2010-05-30 17:57:07Z cs $ + */ + +/* +General Description: +This module is the assembler part of the USB driver. This file contains +general code (preprocessor acrobatics and CRC computation) and then includes +the file appropriate for the given clock rate. +*/ + +#define __SFR_OFFSET 0 /* used by avr-libc's register definitions */ +#include "usbportability.h" +#include "usbdrv.h" /* for common defs */ + +/* register names */ +#define x1 r16 +#define x2 r17 +#define shift r18 +#define cnt r19 +#define x3 r20 +#define x4 r21 +#define x5 r22 +#define bitcnt x5 +#define phase x4 +#define leap x4 + +/* Some assembler dependent definitions and declarations: */ + +#ifdef __IAR_SYSTEMS_ASM__ + extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset + extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen + extern usbTxBuf, usbTxStatus1, usbTxStatus3 +# if USB_COUNT_SOF + extern usbSofCount +# endif + public usbCrc16 + public usbCrc16Append + + COMMON INTVEC +# ifndef USB_INTR_VECTOR + ORG INT0_vect +# else /* USB_INTR_VECTOR */ + ORG USB_INTR_VECTOR +# undef USB_INTR_VECTOR +# endif /* USB_INTR_VECTOR */ +# define USB_INTR_VECTOR usbInterruptHandler + rjmp USB_INTR_VECTOR + RSEG CODE + +#else /* __IAR_SYSTEMS_ASM__ */ + +# ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */ +# ifdef INT0_vect +# define USB_INTR_VECTOR INT0_vect // this is the "new" define for the vector +# else +# define USB_INTR_VECTOR SIG_INTERRUPT0 // this is the "old" vector +# endif +# endif + .text + .global USB_INTR_VECTOR + .type USB_INTR_VECTOR, @function + .global usbCrc16 + .global usbCrc16Append +#endif /* __IAR_SYSTEMS_ASM__ */ + + +#if USB_INTR_PENDING < 0x40 /* This is an I/O address, use in and out */ +# define USB_LOAD_PENDING(reg) in reg, USB_INTR_PENDING +# define USB_STORE_PENDING(reg) out USB_INTR_PENDING, reg +#else /* It's a memory address, use lds and sts */ +# define USB_LOAD_PENDING(reg) lds reg, USB_INTR_PENDING +# define USB_STORE_PENDING(reg) sts USB_INTR_PENDING, reg +#endif + +#define usbTxLen1 usbTxStatus1 +#define usbTxBuf1 (usbTxStatus1 + 1) +#define usbTxLen3 usbTxStatus3 +#define usbTxBuf3 (usbTxStatus3 + 1) + + +;---------------------------------------------------------------------------- +; Utility functions +;---------------------------------------------------------------------------- + +#ifdef __IAR_SYSTEMS_ASM__ +/* Register assignments for usbCrc16 on IAR cc */ +/* Calling conventions on IAR: + * First parameter passed in r16/r17, second in r18/r19 and so on. + * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) + * Result is passed in r16/r17 + * In case of the "tiny" memory model, pointers are only 8 bit with no + * padding. We therefore pass argument 1 as "16 bit unsigned". + */ +RTMODEL "__rt_version", "3" +/* The line above will generate an error if cc calling conventions change. + * The value "3" above is valid for IAR 4.10B/W32 + */ +# define argLen r18 /* argument 2 */ +# define argPtrL r16 /* argument 1 */ +# define argPtrH r17 /* argument 1 */ + +# define resCrcL r16 /* result */ +# define resCrcH r17 /* result */ + +# define ptrL ZL +# define ptrH ZH +# define ptr Z +# define byte r22 +# define bitCnt r19 +# define polyL r20 +# define polyH r21 +# define scratch r23 + +#else /* __IAR_SYSTEMS_ASM__ */ +/* Register assignments for usbCrc16 on gcc */ +/* Calling conventions on gcc: + * First parameter passed in r24/r25, second in r22/23 and so on. + * Callee must preserve r1-r17, r28/r29 + * Result is passed in r24/r25 + */ +# define argLen r22 /* argument 2 */ +# define argPtrL r24 /* argument 1 */ +# define argPtrH r25 /* argument 1 */ + +# define resCrcL r24 /* result */ +# define resCrcH r25 /* result */ + +# define ptrL XL +# define ptrH XH +# define ptr x +# define byte r18 +# define bitCnt r19 +# define polyL r20 +# define polyH r21 +# define scratch r23 + +#endif + +#if USB_USE_FAST_CRC + +; This implementation is faster, but has bigger code size +; Thanks to Slawomir Fras (BoskiDialer) for this code! +; It implements the following C pseudo-code: +; unsigned table(unsigned char x) +; { +; unsigned value; +; +; value = (unsigned)x << 6; +; value ^= (unsigned)x << 7; +; if(parity(x)) +; value ^= 0xc001; +; return value; +; } +; unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen) +; { +; unsigned crc = 0xffff; +; +; while(argLen--) +; crc = table(lo8(crc) ^ *argPtr++) ^ hi8(crc); +; return ~crc; +; } + +; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen); +; argPtr r24+25 / r16+r17 +; argLen r22 / r18 +; temp variables: +; byte r18 / r22 +; scratch r23 +; resCrc r24+r25 / r16+r17 +; ptr X / Z +usbCrc16: + mov ptrL, argPtrL + mov ptrH, argPtrH + ldi resCrcL, 0xFF + ldi resCrcH, 0xFF + rjmp usbCrc16LoopTest +usbCrc16ByteLoop: + ld byte, ptr+ + eor resCrcL, byte ; resCrcL is now 'x' in table() + mov byte, resCrcL ; compute parity of 'x' + swap byte + eor byte, resCrcL + mov scratch, byte + lsr byte + lsr byte + eor byte, scratch + inc byte + lsr byte + andi byte, 1 ; byte is now parity(x) + mov scratch, resCrcL + mov resCrcL, resCrcH + eor resCrcL, byte ; low byte of if(parity(x)) value ^= 0xc001; + neg byte + andi byte, 0xc0 + mov resCrcH, byte ; high byte of if(parity(x)) value ^= 0xc001; + clr byte + lsr scratch + ror byte + eor resCrcH, scratch + eor resCrcL, byte + lsr scratch + ror byte + eor resCrcH, scratch + eor resCrcL, byte +usbCrc16LoopTest: + subi argLen, 1 + brsh usbCrc16ByteLoop + com resCrcL + com resCrcH + ret + +#else /* USB_USE_FAST_CRC */ + +; This implementation is slower, but has less code size +; +; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen); +; argPtr r24+25 / r16+r17 +; argLen r22 / r18 +; temp variables: +; byte r18 / r22 +; bitCnt r19 +; poly r20+r21 +; scratch r23 +; resCrc r24+r25 / r16+r17 +; ptr X / Z +usbCrc16: + mov ptrL, argPtrL + mov ptrH, argPtrH + ldi resCrcL, 0 + ldi resCrcH, 0 + ldi polyL, lo8(0xa001) + ldi polyH, hi8(0xa001) + com argLen ; argLen = -argLen - 1: modified loop to ensure that carry is set + ldi bitCnt, 0 ; loop counter with starnd condition = end condition + rjmp usbCrcLoopEntry +usbCrcByteLoop: + ld byte, ptr+ + eor resCrcL, byte +usbCrcBitLoop: + ror resCrcH ; carry is always set here (see brcs jumps to here) + ror resCrcL + brcs usbCrcNoXor + eor resCrcL, polyL + eor resCrcH, polyH +usbCrcNoXor: + subi bitCnt, 224 ; (8 * 224) % 256 = 0; this loop iterates 8 times + brcs usbCrcBitLoop +usbCrcLoopEntry: + subi argLen, -1 + brcs usbCrcByteLoop +usbCrcReady: + ret +; Thanks to Reimar Doeffinger for optimizing this CRC routine! + +#endif /* USB_USE_FAST_CRC */ + +; extern unsigned usbCrc16Append(unsigned char *data, unsigned char len); +usbCrc16Append: + rcall usbCrc16 + st ptr+, resCrcL + st ptr+, resCrcH + ret + +#undef argLen +#undef argPtrL +#undef argPtrH +#undef resCrcL +#undef resCrcH +#undef ptrL +#undef ptrH +#undef ptr +#undef byte +#undef bitCnt +#undef polyL +#undef polyH +#undef scratch + + +#if USB_CFG_HAVE_MEASURE_FRAME_LENGTH +#ifdef __IAR_SYSTEMS_ASM__ +/* Register assignments for usbMeasureFrameLength on IAR cc */ +/* Calling conventions on IAR: + * First parameter passed in r16/r17, second in r18/r19 and so on. + * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) + * Result is passed in r16/r17 + * In case of the "tiny" memory model, pointers are only 8 bit with no + * padding. We therefore pass argument 1 as "16 bit unsigned". + */ +# define resL r16 +# define resH r17 +# define cnt16L r30 +# define cnt16H r31 +# define cntH r18 + +#else /* __IAR_SYSTEMS_ASM__ */ +/* Register assignments for usbMeasureFrameLength on gcc */ +/* Calling conventions on gcc: + * First parameter passed in r24/r25, second in r22/23 and so on. + * Callee must preserve r1-r17, r28/r29 + * Result is passed in r24/r25 + */ +# define resL r24 +# define resH r25 +# define cnt16L r24 +# define cnt16H r25 +# define cntH r26 +#endif +# define cnt16 cnt16L + +; extern unsigned usbMeasurePacketLength(void); +; returns time between two idle strobes in multiples of 7 CPU clocks +.global usbMeasureFrameLength +usbMeasureFrameLength: + ldi cntH, 6 ; wait ~ 10 ms for D- == 0 + clr cnt16L + clr cnt16H +usbMFTime16: + dec cntH + breq usbMFTimeout +usbMFWaitStrobe: ; first wait for D- == 0 (idle strobe) + sbiw cnt16, 1 ;[0] [6] + breq usbMFTime16 ;[2] + sbic USBIN, USBMINUS ;[3] + rjmp usbMFWaitStrobe ;[4] +usbMFWaitIdle: ; then wait until idle again + sbis USBIN, USBMINUS ;1 wait for D- == 1 + rjmp usbMFWaitIdle ;2 + ldi cnt16L, 1 ;1 represents cycles so far + clr cnt16H ;1 +usbMFWaitLoop: + in cntH, USBIN ;[0] [7] + adiw cnt16, 1 ;[1] + breq usbMFTimeout ;[3] + andi cntH, USBMASK ;[4] + brne usbMFWaitLoop ;[5] +usbMFTimeout: +#if resL != cnt16L + mov resL, cnt16L + mov resH, cnt16H +#endif + ret + +#undef resL +#undef resH +#undef cnt16 +#undef cnt16L +#undef cnt16H +#undef cntH + +#endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ + +;---------------------------------------------------------------------------- +; Now include the clock rate specific code +;---------------------------------------------------------------------------- + +#ifndef USB_CFG_CLOCK_KHZ +# ifdef F_CPU +# define USB_CFG_CLOCK_KHZ (F_CPU/1000) +# else +# error "USB_CFG_CLOCK_KHZ not defined in usbconfig.h and no F_CPU set!" +# endif +#endif + +#if USB_CFG_CHECK_CRC /* separate dispatcher for CRC type modules */ +# if USB_CFG_CLOCK_KHZ == 18000 +# include "usbdrvasm18-crc.inc" +# else +# error "USB_CFG_CLOCK_KHZ is not one of the supported crc-rates!" +# endif +#else /* USB_CFG_CHECK_CRC */ +# if USB_CFG_CLOCK_KHZ == 12000 +# include "usbdrvasm12.inc" +# elif USB_CFG_CLOCK_KHZ == 12800 +# include "usbdrvasm128.inc" +# elif USB_CFG_CLOCK_KHZ == 15000 +# include "usbdrvasm15.inc" +# elif USB_CFG_CLOCK_KHZ == 16000 +# include "usbdrvasm16.inc" +# elif USB_CFG_CLOCK_KHZ == 16500 +# include "usbdrvasm165.inc" +# elif USB_CFG_CLOCK_KHZ == 20000 +# include "usbdrvasm20.inc" +# else +# error "USB_CFG_CLOCK_KHZ is not one of the supported non-crc-rates!" +# endif +#endif /* USB_CFG_CHECK_CRC */ diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm.asm b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm.asm new file mode 100644 index 0000000..9cc4e4d --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm.asm @@ -0,0 +1,21 @@ +/* Name: usbdrvasm.asm + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2006-03-01 + * Tabsize: 4 + * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id$ + */ + +/* +General Description: +The IAR compiler/assembler system prefers assembler files with file extension +".asm". We simply provide this file as an alias for usbdrvasm.S. + +Thanks to Oleg Semyonov for his help with the IAR tools port! +*/ + +#include "usbdrvasm.S" + +end diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm12.inc b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm12.inc new file mode 100644 index 0000000..c116758 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm12.inc @@ -0,0 +1,393 @@ +/* Name: usbdrvasm12.inc + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2004-12-29 + * Tabsize: 4 + * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbdrvasm12.inc 740 2009-04-13 18:23:31Z cs $ + */ + +/* Do not link this file! Link usbdrvasm.S instead, which includes the + * appropriate implementation! + */ + +/* +General Description: +This file is the 12 MHz version of the asssembler part of the USB driver. It +requires a 12 MHz crystal (not a ceramic resonator and not a calibrated RC +oscillator). + +See usbdrv.h for a description of the entire driver. + +Since almost all of this code is timing critical, don't change unless you +really know what you are doing! Many parts require not only a maximum number +of CPU cycles, but even an exact number of cycles! + + +Timing constraints according to spec (in bit times): +timing subject min max CPUcycles +--------------------------------------------------------------------------- +EOP of OUT/SETUP to sync pattern of DATA0 (both rx) 2 16 16-128 +EOP of IN to sync pattern of DATA0 (rx, then tx) 2 7.5 16-60 +DATAx (rx) to ACK/NAK/STALL (tx) 2 7.5 16-60 +*/ + +;Software-receiver engine. Strict timing! Don't change unless you can preserve timing! +;interrupt response time: 4 cycles + insn running = 7 max if interrupts always enabled +;max allowable interrupt latency: 34 cycles -> max 25 cycles interrupt disable +;max stack usage: [ret(2), YL, SREG, YH, shift, x1, x2, x3, cnt, x4] = 11 bytes +;Numbers in brackets are maximum cycles since SOF. +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG [sofError], YH, shift, x1, x2, x3, cnt + push YL ;2 [35] push only what is necessary to sync with edge ASAP + in YL, SREG ;1 [37] + push YL ;2 [39] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of 1/4 bit which meets the spec. + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: +;{3, 5} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling] +;we have 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push YH ;2 [2] + lds YL, usbInputBufOffset;2 [4] + clr YH ;1 [5] + subi YL, lo8(-(usbRxBuf));1 [6] + sbci YH, hi8(-(usbRxBuf));1 [7] + + sbis USBIN, USBMINUS ;1 [8] we want two bits K [sample 1 cycle too early] + rjmp haveTwoBitsK ;2 [10] + pop YH ;2 [11] undo the push from before + rjmp waitForK ;2 [13] this was not the end of sync, retry +haveTwoBitsK: +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- + push shift ;2 [16] + push x1 ;2 [12] + push x2 ;2 [14] + + in x1, USBIN ;1 [17] <-- sample bit 0 + ldi shift, 0xff ;1 [18] + bst x1, USBMINUS ;1 [19] + bld shift, 0 ;1 [20] + push x3 ;2 [22] + push cnt ;2 [24] + + in x2, USBIN ;1 [25] <-- sample bit 1 + ser x3 ;1 [26] [inserted init instruction] + eor x1, x2 ;1 [27] + bst x1, USBMINUS ;1 [28] + bld shift, 1 ;1 [29] + ldi cnt, USB_BUFSIZE;1 [30] [inserted init instruction] + rjmp rxbit2 ;2 [32] + +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- + +unstuff0: ;1 (branch taken) + andi x3, ~0x01 ;1 [15] + mov x1, x2 ;1 [16] x2 contains last sampled (stuffed) bit + in x2, USBIN ;1 [17] <-- sample bit 1 again + ori shift, 0x01 ;1 [18] + rjmp didUnstuff0 ;2 [20] + +unstuff1: ;1 (branch taken) + mov x2, x1 ;1 [21] x1 contains last sampled (stuffed) bit + andi x3, ~0x02 ;1 [22] + ori shift, 0x02 ;1 [23] + nop ;1 [24] + in x1, USBIN ;1 [25] <-- sample bit 2 again + rjmp didUnstuff1 ;2 [27] + +unstuff2: ;1 (branch taken) + andi x3, ~0x04 ;1 [29] + ori shift, 0x04 ;1 [30] + mov x1, x2 ;1 [31] x2 contains last sampled (stuffed) bit + nop ;1 [32] + in x2, USBIN ;1 [33] <-- sample bit 3 + rjmp didUnstuff2 ;2 [35] + +unstuff3: ;1 (branch taken) + in x2, USBIN ;1 [34] <-- sample stuffed bit 3 [one cycle too late] + andi x3, ~0x08 ;1 [35] + ori shift, 0x08 ;1 [36] + rjmp didUnstuff3 ;2 [38] + +unstuff4: ;1 (branch taken) + andi x3, ~0x10 ;1 [40] + in x1, USBIN ;1 [41] <-- sample stuffed bit 4 + ori shift, 0x10 ;1 [42] + rjmp didUnstuff4 ;2 [44] + +unstuff5: ;1 (branch taken) + andi x3, ~0x20 ;1 [48] + in x2, USBIN ;1 [49] <-- sample stuffed bit 5 + ori shift, 0x20 ;1 [50] + rjmp didUnstuff5 ;2 [52] + +unstuff6: ;1 (branch taken) + andi x3, ~0x40 ;1 [56] + in x1, USBIN ;1 [57] <-- sample stuffed bit 6 + ori shift, 0x40 ;1 [58] + rjmp didUnstuff6 ;2 [60] + +; extra jobs done during bit interval: +; bit 0: store, clear [SE0 is unreliable here due to bit dribbling in hubs] +; bit 1: se0 check +; bit 2: overflow check +; bit 3: recovery from delay [bit 0 tasks took too long] +; bit 4: none +; bit 5: none +; bit 6: none +; bit 7: jump, eor +rxLoop: + eor x3, shift ;1 [0] reconstruct: x3 is 0 at bit locations we changed, 1 at others + in x1, USBIN ;1 [1] <-- sample bit 0 + st y+, x3 ;2 [3] store data + ser x3 ;1 [4] + nop ;1 [5] + eor x2, x1 ;1 [6] + bst x2, USBMINUS;1 [7] + bld shift, 0 ;1 [8] + in x2, USBIN ;1 [9] <-- sample bit 1 (or possibly bit 0 stuffed) + andi x2, USBMASK ;1 [10] + breq se0 ;1 [11] SE0 check for bit 1 + andi shift, 0xf9 ;1 [12] +didUnstuff0: + breq unstuff0 ;1 [13] + eor x1, x2 ;1 [14] + bst x1, USBMINUS;1 [15] + bld shift, 1 ;1 [16] +rxbit2: + in x1, USBIN ;1 [17] <-- sample bit 2 (or possibly bit 1 stuffed) + andi shift, 0xf3 ;1 [18] + breq unstuff1 ;1 [19] do remaining work for bit 1 +didUnstuff1: + subi cnt, 1 ;1 [20] + brcs overflow ;1 [21] loop control + eor x2, x1 ;1 [22] + bst x2, USBMINUS;1 [23] + bld shift, 2 ;1 [24] + in x2, USBIN ;1 [25] <-- sample bit 3 (or possibly bit 2 stuffed) + andi shift, 0xe7 ;1 [26] + breq unstuff2 ;1 [27] +didUnstuff2: + eor x1, x2 ;1 [28] + bst x1, USBMINUS;1 [29] + bld shift, 3 ;1 [30] +didUnstuff3: + andi shift, 0xcf ;1 [31] + breq unstuff3 ;1 [32] + in x1, USBIN ;1 [33] <-- sample bit 4 + eor x2, x1 ;1 [34] + bst x2, USBMINUS;1 [35] + bld shift, 4 ;1 [36] +didUnstuff4: + andi shift, 0x9f ;1 [37] + breq unstuff4 ;1 [38] + nop2 ;2 [40] + in x2, USBIN ;1 [41] <-- sample bit 5 + eor x1, x2 ;1 [42] + bst x1, USBMINUS;1 [43] + bld shift, 5 ;1 [44] +didUnstuff5: + andi shift, 0x3f ;1 [45] + breq unstuff5 ;1 [46] + nop2 ;2 [48] + in x1, USBIN ;1 [49] <-- sample bit 6 + eor x2, x1 ;1 [50] + bst x2, USBMINUS;1 [51] + bld shift, 6 ;1 [52] +didUnstuff6: + cpi shift, 0x02 ;1 [53] + brlo unstuff6 ;1 [54] + nop2 ;2 [56] + in x2, USBIN ;1 [57] <-- sample bit 7 + eor x1, x2 ;1 [58] + bst x1, USBMINUS;1 [59] + bld shift, 7 ;1 [60] +didUnstuff7: + cpi shift, 0x04 ;1 [61] + brsh rxLoop ;2 [63] loop control +unstuff7: + andi x3, ~0x80 ;1 [63] + ori shift, 0x80 ;1 [64] + in x2, USBIN ;1 [65] <-- sample stuffed bit 7 + nop ;1 [66] + rjmp didUnstuff7 ;2 [68] + +macro POP_STANDARD ; 12 cycles + pop cnt + pop x3 + pop x2 + pop x1 + pop shift + pop YH + endm +macro POP_RETI ; 5 cycles + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + +;---------------------------------------------------------------------------- +; Transmitting data +;---------------------------------------------------------------------------- + +txByteLoop: +txBitloop: +stuffN1Delay: ; [03] + ror shift ;[-5] [11] [59] + brcc doExorN1 ;[-4] [60] + subi x4, 1 ;[-3] + brne commonN1 ;[-2] + lsl shift ;[-1] compensate ror after rjmp stuffDelay + nop ;[00] stuffing consists of just waiting 8 cycles + rjmp stuffN1Delay ;[01] after ror, C bit is reliably clear + +sendNakAndReti: ;0 [-19] 19 cycles until SOP + ldi x3, USBPID_NAK ;1 [-18] + rjmp usbSendX3 ;2 [-16] +sendAckAndReti: ;0 [-19] 19 cycles until SOP + ldi x3, USBPID_ACK ;1 [-18] + rjmp usbSendX3 ;2 [-16] +sendCntAndReti: ;0 [-17] 17 cycles until SOP + mov x3, cnt ;1 [-16] +usbSendX3: ;0 [-16] + ldi YL, 20 ;1 [-15] 'x3' is R20 + ldi YH, 0 ;1 [-14] + ldi cnt, 2 ;1 [-13] +; rjmp usbSendAndReti fallthrough + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) or USBOUT = 0x01 +; K = (D+ = 1), (D- = 0) or USBOUT = 0x02 +; Spec allows 7.5 bit times from EOP to SOP for replies (= 60 cycles) + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte +;uses: x1...x2, x4, shift, cnt, Y [x1 = mirror USBOUT, x2 = USBMASK, x4 = bitstuff cnt] +;Numbers in brackets are time since first bit of sync pattern is sent (start of instruction) +usbSendAndReti: + in x2, USBDDR ;[-12] 12 cycles until SOP + ori x2, USBMASK ;[-11] + sbi USBOUT, USBMINUS ;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) + out USBDDR, x2 ;[-8] <--- acquire bus + in x1, USBOUT ;[-7] port mirror for tx loop + ldi shift, 0x40 ;[-6] sync byte is first byte sent (we enter loop after ror) + ldi x2, USBMASK ;[-5] + push x4 ;[-4] +doExorN1: + eor x1, x2 ;[-2] [06] [62] + ldi x4, 6 ;[-1] [07] [63] +commonN1: +stuffN2Delay: + out USBOUT, x1 ;[00] [08] [64] <--- set bit + ror shift ;[01] + brcc doExorN2 ;[02] + subi x4, 1 ;[03] + brne commonN2 ;[04] + lsl shift ;[05] compensate ror after rjmp stuffDelay + rjmp stuffN2Delay ;[06] after ror, C bit is reliably clear +doExorN2: + eor x1, x2 ;[04] [12] + ldi x4, 6 ;[05] [13] +commonN2: + nop ;[06] [14] + subi cnt, 171 ;[07] [15] trick: (3 * 171) & 0xff = 1 + out USBOUT, x1 ;[08] [16] <--- set bit + brcs txBitloop ;[09] [25] [41] + +stuff6Delay: + ror shift ;[42] [50] + brcc doExor6 ;[43] + subi x4, 1 ;[44] + brne common6 ;[45] + lsl shift ;[46] compensate ror after rjmp stuffDelay + nop ;[47] stuffing consists of just waiting 8 cycles + rjmp stuff6Delay ;[48] after ror, C bit is reliably clear +doExor6: + eor x1, x2 ;[45] [53] + ldi x4, 6 ;[46] +common6: +stuff7Delay: + ror shift ;[47] [55] + out USBOUT, x1 ;[48] <--- set bit + brcc doExor7 ;[49] + subi x4, 1 ;[50] + brne common7 ;[51] + lsl shift ;[52] compensate ror after rjmp stuffDelay + rjmp stuff7Delay ;[53] after ror, C bit is reliably clear +doExor7: + eor x1, x2 ;[51] [59] + ldi x4, 6 ;[52] +common7: + ld shift, y+ ;[53] + tst cnt ;[55] + out USBOUT, x1 ;[56] <--- set bit + brne txByteLoop ;[57] + +;make SE0: + cbr x1, USBMASK ;[58] prepare SE0 [spec says EOP may be 15 to 18 cycles] + lds x2, usbNewDeviceAddr;[59] + lsl x2 ;[61] we compare with left shifted address + subi YL, 2 + 20 ;[62] Only assign address on data packets, not ACK/NAK in x3 + sbci YH, 0 ;[63] + out USBOUT, x1 ;[00] <-- out SE0 -- from now 2 bits = 16 cycles until bus idle +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + breq skipAddrAssign ;[01] + sts usbDeviceAddr, x2 ; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< 12.5625 MHz +max frequency: 69.286 cycles for 8 bit -> 12.99 MHz +nominal frequency: 12.77 MHz ( = sqrt(min * max)) + +sampling positions: (next even number in range [+/- 0.5]) +cycle index range: 0 ... 66 +bits: +.5, 8.875, 17.25, 25.625, 34, 42.375, 50.75, 59.125 +[0/1], [9], [17], [25/+26], [34], [+42/43], [51], [59] + +bit number: 0 1 2 3 4 5 6 7 +spare cycles 1 2 1 2 1 1 1 0 + +operations to perform: duration cycle + ---------------- + eor fix, shift 1 -> 00 + andi phase, USBMASK 1 -> 08 + breq se0 1 -> 16 (moved to 11) + st y+, data 2 -> 24, 25 + mov data, fix 1 -> 33 + ser data 1 -> 41 + subi cnt, 1 1 -> 49 + brcs overflow 1 -> 50 + +layout of samples and operations: +[##] = sample bit +<##> = sample phase +*##* = operation + +0: *00* [01] 02 03 04 <05> 06 07 +1: *08* [09] 10 11 12 <13> 14 15 *16* +2: [17] 18 19 20 <21> 22 23 +3: *24* *25* [26] 27 28 29 <30> 31 32 +4: *33* [34] 35 36 37 <38> 39 40 +5: *41* [42] 43 44 45 <46> 47 48 +6: *49* *50* [51] 52 53 54 <55> 56 57 58 +7: [59] 60 61 62 <63> 64 65 66 +*****************************************************************************/ + +/* we prefer positive expressions (do if condition) instead of negative + * (skip if condition), therefore use defines for skip instructions: + */ +#define ifioclr sbis +#define ifioset sbic +#define ifrclr sbrs +#define ifrset sbrc + +/* The registers "fix" and "data" swap their meaning during the loop. Use + * defines to keep their name constant. + */ +#define fix x2 +#define data x1 +#undef phase /* phase has a default definition to x4 */ +#define phase x3 + + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG [sofError], YH, shift, x1, x2, x3, cnt, r0 + push YL ;2 push only what is necessary to sync with edge ASAP + in YL, SREG ;1 + push YL ;2 +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of 1/4 bit which meets the spec. + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS ;[0] + rjmp foundK ;[1] +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError + +foundK: +;{3, 5} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling] +;we have 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push YH ;[2] + lds YL, usbInputBufOffset;[4] + clr YH ;[6] + subi YL, lo8(-(usbRxBuf));[7] + sbci YH, hi8(-(usbRxBuf));[8] + + sbis USBIN, USBMINUS ;[9] we want two bits K [we want to sample at 8 + 4 - 1.5 = 10.5] + rjmp haveTwoBitsK ;[10] + pop YH ;[11] undo the push from before + rjmp waitForK ;[13] this was not the end of sync, retry +haveTwoBitsK: +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +#define fix x2 +#define data x1 + + push shift ;[12] + push x1 ;[14] + push x2 ;[16] + ldi shift, 0x80 ;[18] prevent bit-unstuffing but init low bits to 0 + ifioset USBIN, USBMINUS ;[19] [01] <--- bit 0 [10.5 + 8 = 18.5] + ori shift, 1<<0 ;[02] + push x3 ;[03] + push cnt ;[05] + push r0 ;[07] + ifioset USBIN, USBMINUS ;[09] <--- bit 1 + ori shift, 1<<1 ;[10] + ser fix ;[11] + ldi cnt, USB_BUFSIZE ;[12] + mov data, shift ;[13] + lsl shift ;[14] + nop2 ;[15] + ifioset USBIN, USBMINUS ;[17] <--- bit 2 + ori data, 3<<2 ;[18] store in bit 2 AND bit 3 + eor shift, data ;[19] do nrzi decoding + andi data, 1<<3 ;[20] + in phase, USBIN ;[21] <- phase + brne jumpToEntryAfterSet ;[22] if USBMINS at bit 3 was 1 + nop ;[23] + rjmp entryAfterClr ;[24] +jumpToEntryAfterSet: + rjmp entryAfterSet ;[24] + +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- +#undef fix +#define fix x1 +#undef data +#define data x2 + +bit7IsSet: + ifrclr phase, USBMINUS ;[62] check phase only if D- changed + lpm ;[63] + in phase, USBIN ;[64] <- phase (one cycle too late) + ori shift, 1 << 7 ;[65] + nop ;[66] +;;;;rjmp bit0AfterSet ; -> [00] == [67] moved block up to save jump +bit0AfterSet: + eor fix, shift ;[00] +#undef fix +#define fix x2 +#undef data +#define data x1 /* we now have result in data, fix is reset to 0xff */ + ifioclr USBIN, USBMINUS ;[01] <--- sample 0 + rjmp bit0IsClr ;[02] + andi shift, ~(7 << 0) ;[03] + breq unstuff0s ;[04] + in phase, USBIN ;[05] <- phase + rjmp bit1AfterSet ;[06] +unstuff0s: + in phase, USBIN ;[06] <- phase (one cycle too late) + andi fix, ~(1 << 0) ;[07] + ifioclr USBIN, USBMINUS ;[00] + ifioset USBIN, USBPLUS ;[01] + rjmp bit0IsClr ;[02] executed if first expr false or second true +se0AndStore: ; executed only if both bits 0 + st y+, x1 ;[15/17] cycles after start of byte + rjmp se0 ;[17/19] + +bit0IsClr: + ifrset phase, USBMINUS ;[04] check phase only if D- changed + lpm ;[05] + in phase, USBIN ;[06] <- phase (one cycle too late) + ori shift, 1 << 0 ;[07] +bit1AfterClr: + andi phase, USBMASK ;[08] + ifioset USBIN, USBMINUS ;[09] <--- sample 1 + rjmp bit1IsSet ;[10] + breq se0AndStore ;[11] if D- was 0 in bits 0 AND 1 and D+ was 0 in between, we have SE0 + andi shift, ~(7 << 1) ;[12] + in phase, USBIN ;[13] <- phase + breq unstuff1c ;[14] + rjmp bit2AfterClr ;[15] +unstuff1c: + andi fix, ~(1 << 1) ;[16] + nop2 ;[08] + nop2 ;[10] +bit1IsSet: + ifrclr phase, USBMINUS ;[12] check phase only if D- changed + lpm ;[13] + in phase, USBIN ;[14] <- phase (one cycle too late) + ori shift, 1 << 1 ;[15] + nop ;[16] +bit2AfterSet: + ifioclr USBIN, USBMINUS ;[17] <--- sample 2 + rjmp bit2IsClr ;[18] + andi shift, ~(7 << 2) ;[19] + breq unstuff2s ;[20] + in phase, USBIN ;[21] <- phase + rjmp bit3AfterSet ;[22] +unstuff2s: + in phase, USBIN ;[22] <- phase (one cycle too late) + andi fix, ~(1 << 2) ;[23] + nop2 ;[16] + nop2 ;[18] +bit2IsClr: + ifrset phase, USBMINUS ;[20] check phase only if D- changed + lpm ;[21] + in phase, USBIN ;[22] <- phase (one cycle too late) + ori shift, 1 << 2 ;[23] +bit3AfterClr: + st y+, data ;[24] +entryAfterClr: + ifioset USBIN, USBMINUS ;[26] <--- sample 3 + rjmp bit3IsSet ;[27] + andi shift, ~(7 << 3) ;[28] + breq unstuff3c ;[29] + in phase, USBIN ;[30] <- phase + rjmp bit4AfterClr ;[31] +unstuff3c: + in phase, USBIN ;[31] <- phase (one cycle too late) + andi fix, ~(1 << 3) ;[32] + nop2 ;[25] + nop2 ;[27] +bit3IsSet: + ifrclr phase, USBMINUS ;[29] check phase only if D- changed + lpm ;[30] + in phase, USBIN ;[31] <- phase (one cycle too late) + ori shift, 1 << 3 ;[32] +bit4AfterSet: + mov data, fix ;[33] undo this move by swapping defines +#undef fix +#define fix x1 +#undef data +#define data x2 + ifioclr USBIN, USBMINUS ;[34] <--- sample 4 + rjmp bit4IsClr ;[35] + andi shift, ~(7 << 4) ;[36] + breq unstuff4s ;[37] + in phase, USBIN ;[38] <- phase + rjmp bit5AfterSet ;[39] +unstuff4s: + in phase, USBIN ;[39] <- phase (one cycle too late) + andi fix, ~(1 << 4) ;[40] + nop2 ;[33] + nop2 ;[35] +bit4IsClr: + ifrset phase, USBMINUS ;[37] check phase only if D- changed + lpm ;[38] + in phase, USBIN ;[39] <- phase (one cycle too late) + ori shift, 1 << 4 ;[40] +bit5AfterClr: + ser data ;[41] + ifioset USBIN, USBMINUS ;[42] <--- sample 5 + rjmp bit5IsSet ;[43] + andi shift, ~(7 << 5) ;[44] + breq unstuff5c ;[45] + in phase, USBIN ;[46] <- phase + rjmp bit6AfterClr ;[47] +unstuff5c: + in phase, USBIN ;[47] <- phase (one cycle too late) + andi fix, ~(1 << 5) ;[48] + nop2 ;[41] + nop2 ;[43] +bit5IsSet: + ifrclr phase, USBMINUS ;[45] check phase only if D- changed + lpm ;[46] + in phase, USBIN ;[47] <- phase (one cycle too late) + ori shift, 1 << 5 ;[48] +bit6AfterSet: + subi cnt, 1 ;[49] + brcs jumpToOverflow ;[50] + ifioclr USBIN, USBMINUS ;[51] <--- sample 6 + rjmp bit6IsClr ;[52] + andi shift, ~(3 << 6) ;[53] + cpi shift, 2 ;[54] + in phase, USBIN ;[55] <- phase + brlt unstuff6s ;[56] + rjmp bit7AfterSet ;[57] + +jumpToOverflow: + rjmp overflow + +unstuff6s: + andi fix, ~(1 << 6) ;[50] + lpm ;[51] +bit6IsClr: + ifrset phase, USBMINUS ;[54] check phase only if D- changed + lpm ;[55] + in phase, USBIN ;[56] <- phase (one cycle too late) + ori shift, 1 << 6 ;[57] + nop ;[58] +bit7AfterClr: + ifioset USBIN, USBMINUS ;[59] <--- sample 7 + rjmp bit7IsSet ;[60] + andi shift, ~(1 << 7) ;[61] + cpi shift, 4 ;[62] + in phase, USBIN ;[63] <- phase + brlt unstuff7c ;[64] + rjmp bit0AfterClr ;[65] -> [00] == [67] +unstuff7c: + andi fix, ~(1 << 7) ;[58] + nop ;[59] + rjmp bit7IsSet ;[60] + +bit7IsClr: + ifrset phase, USBMINUS ;[62] check phase only if D- changed + lpm ;[63] + in phase, USBIN ;[64] <- phase (one cycle too late) + ori shift, 1 << 7 ;[65] + nop ;[66] +;;;;rjmp bit0AfterClr ; -> [00] == [67] moved block up to save jump +bit0AfterClr: + eor fix, shift ;[00] +#undef fix +#define fix x2 +#undef data +#define data x1 /* we now have result in data, fix is reset to 0xff */ + ifioset USBIN, USBMINUS ;[01] <--- sample 0 + rjmp bit0IsSet ;[02] + andi shift, ~(7 << 0) ;[03] + breq unstuff0c ;[04] + in phase, USBIN ;[05] <- phase + rjmp bit1AfterClr ;[06] +unstuff0c: + in phase, USBIN ;[06] <- phase (one cycle too late) + andi fix, ~(1 << 0) ;[07] + ifioclr USBIN, USBMINUS ;[00] + ifioset USBIN, USBPLUS ;[01] + rjmp bit0IsSet ;[02] executed if first expr false or second true + rjmp se0AndStore ;[03] executed only if both bits 0 +bit0IsSet: + ifrclr phase, USBMINUS ;[04] check phase only if D- changed + lpm ;[05] + in phase, USBIN ;[06] <- phase (one cycle too late) + ori shift, 1 << 0 ;[07] +bit1AfterSet: + andi shift, ~(7 << 1) ;[08] compensated by "ori shift, 1<<1" if bit1IsClr + ifioclr USBIN, USBMINUS ;[09] <--- sample 1 + rjmp bit1IsClr ;[10] + breq unstuff1s ;[11] + nop2 ;[12] do not check for SE0 if bit 0 was 1 + in phase, USBIN ;[14] <- phase (one cycle too late) + rjmp bit2AfterSet ;[15] +unstuff1s: + in phase, USBIN ;[13] <- phase + andi fix, ~(1 << 1) ;[14] + lpm ;[07] + nop2 ;[10] +bit1IsClr: + ifrset phase, USBMINUS ;[12] check phase only if D- changed + lpm ;[13] + in phase, USBIN ;[14] <- phase (one cycle too late) + ori shift, 1 << 1 ;[15] + nop ;[16] +bit2AfterClr: + ifioset USBIN, USBMINUS ;[17] <--- sample 2 + rjmp bit2IsSet ;[18] + andi shift, ~(7 << 2) ;[19] + breq unstuff2c ;[20] + in phase, USBIN ;[21] <- phase + rjmp bit3AfterClr ;[22] +unstuff2c: + in phase, USBIN ;[22] <- phase (one cycle too late) + andi fix, ~(1 << 2) ;[23] + nop2 ;[16] + nop2 ;[18] +bit2IsSet: + ifrclr phase, USBMINUS ;[20] check phase only if D- changed + lpm ;[21] + in phase, USBIN ;[22] <- phase (one cycle too late) + ori shift, 1 << 2 ;[23] +bit3AfterSet: + st y+, data ;[24] +entryAfterSet: + ifioclr USBIN, USBMINUS ;[26] <--- sample 3 + rjmp bit3IsClr ;[27] + andi shift, ~(7 << 3) ;[28] + breq unstuff3s ;[29] + in phase, USBIN ;[30] <- phase + rjmp bit4AfterSet ;[31] +unstuff3s: + in phase, USBIN ;[31] <- phase (one cycle too late) + andi fix, ~(1 << 3) ;[32] + nop2 ;[25] + nop2 ;[27] +bit3IsClr: + ifrset phase, USBMINUS ;[29] check phase only if D- changed + lpm ;[30] + in phase, USBIN ;[31] <- phase (one cycle too late) + ori shift, 1 << 3 ;[32] +bit4AfterClr: + mov data, fix ;[33] undo this move by swapping defines +#undef fix +#define fix x1 +#undef data +#define data x2 + ifioset USBIN, USBMINUS ;[34] <--- sample 4 + rjmp bit4IsSet ;[35] + andi shift, ~(7 << 4) ;[36] + breq unstuff4c ;[37] + in phase, USBIN ;[38] <- phase + rjmp bit5AfterClr ;[39] +unstuff4c: + in phase, USBIN ;[39] <- phase (one cycle too late) + andi fix, ~(1 << 4) ;[40] + nop2 ;[33] + nop2 ;[35] +bit4IsSet: + ifrclr phase, USBMINUS ;[37] check phase only if D- changed + lpm ;[38] + in phase, USBIN ;[39] <- phase (one cycle too late) + ori shift, 1 << 4 ;[40] +bit5AfterSet: + ser data ;[41] + ifioclr USBIN, USBMINUS ;[42] <--- sample 5 + rjmp bit5IsClr ;[43] + andi shift, ~(7 << 5) ;[44] + breq unstuff5s ;[45] + in phase, USBIN ;[46] <- phase + rjmp bit6AfterSet ;[47] +unstuff5s: + in phase, USBIN ;[47] <- phase (one cycle too late) + andi fix, ~(1 << 5) ;[48] + nop2 ;[41] + nop2 ;[43] +bit5IsClr: + ifrset phase, USBMINUS ;[45] check phase only if D- changed + lpm ;[46] + in phase, USBIN ;[47] <- phase (one cycle too late) + ori shift, 1 << 5 ;[48] +bit6AfterClr: + subi cnt, 1 ;[49] + brcs overflow ;[50] + ifioset USBIN, USBMINUS ;[51] <--- sample 6 + rjmp bit6IsSet ;[52] + andi shift, ~(3 << 6) ;[53] + cpi shift, 2 ;[54] + in phase, USBIN ;[55] <- phase + brlt unstuff6c ;[56] + rjmp bit7AfterClr ;[57] +unstuff6c: + andi fix, ~(1 << 6) ;[50] + lpm ;[51] +bit6IsSet: + ifrclr phase, USBMINUS ;[54] check phase only if D- changed + lpm ;[55] + in phase, USBIN ;[56] <- phase (one cycle too late) + ori shift, 1 << 6 ;[57] +bit7AfterSet: + ifioclr USBIN, USBMINUS ;[59] <--- sample 7 + rjmp bit7IsClr ;[60] + andi shift, ~(1 << 7) ;[61] + cpi shift, 4 ;[62] + in phase, USBIN ;[63] <- phase + brlt unstuff7s ;[64] + rjmp bit0AfterSet ;[65] -> [00] == [67] +unstuff7s: + andi fix, ~(1 << 7) ;[58] + nop ;[59] + rjmp bit7IsClr ;[60] + +macro POP_STANDARD ; 14 cycles + pop r0 + pop cnt + pop x3 + pop x2 + pop x1 + pop shift + pop YH + endm +macro POP_RETI ; 5 cycles + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + +;---------------------------------------------------------------------------- +; Transmitting data +;---------------------------------------------------------------------------- + +txByteLoop: +txBitloop: +stuffN1Delay: ; [03] + ror shift ;[-5] [11] [63] + brcc doExorN1 ;[-4] [64] + subi x3, 1 ;[-3] + brne commonN1 ;[-2] + lsl shift ;[-1] compensate ror after rjmp stuffDelay + nop ;[00] stuffing consists of just waiting 8 cycles + rjmp stuffN1Delay ;[01] after ror, C bit is reliably clear + +sendNakAndReti: + ldi cnt, USBPID_NAK ;[-19] + rjmp sendCntAndReti ;[-18] +sendAckAndReti: + ldi cnt, USBPID_ACK ;[-17] +sendCntAndReti: + mov r0, cnt ;[-16] + ldi YL, 0 ;[-15] R0 address is 0 + ldi YH, 0 ;[-14] + ldi cnt, 2 ;[-13] +; rjmp usbSendAndReti fallthrough + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) or USBOUT = 0x01 +; K = (D+ = 1), (D- = 0) or USBOUT = 0x02 +; Spec allows 7.5 bit times from EOP to SOP for replies (= 60 cycles) + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte +;uses: x1...x3, shift, cnt, Y [x1 = mirror USBOUT, x2 = USBMASK, x3 = bitstuff cnt] +;Numbers in brackets are time since first bit of sync pattern is sent (start of instruction) +usbSendAndReti: + in x2, USBDDR ;[-10] 10 cycles until SOP + ori x2, USBMASK ;[-9] + sbi USBOUT, USBMINUS ;[-8] prepare idle state; D+ and D- must have been 0 (no pullups) + out USBDDR, x2 ;[-6] <--- acquire bus + in x1, USBOUT ;[-5] port mirror for tx loop + ldi shift, 0x40 ;[-4] sync byte is first byte sent (we enter loop after ror) + ldi x2, USBMASK ;[-3] +doExorN1: + eor x1, x2 ;[-2] [06] [62] + ldi x3, 6 ;[-1] [07] [63] +commonN1: +stuffN2Delay: + out USBOUT, x1 ;[00] [08] [64] <--- set bit + ror shift ;[01] + brcc doExorN2 ;[02] + subi x3, 1 ;[03] + brne commonN2 ;[04] + lsl shift ;[05] compensate ror after rjmp stuffDelay + rjmp stuffN2Delay ;[06] after ror, C bit is reliably clear +doExorN2: + eor x1, x2 ;[04] [12] + ldi x3, 6 ;[05] [13] +commonN2: + nop2 ;[06] [14] + subi cnt, 171 ;[08] [16] trick: (3 * 171) & 0xff = 1 + out USBOUT, x1 ;[09] [17] <--- set bit + brcs txBitloop ;[10] [27] [44] + +stuff6Delay: + ror shift ;[45] [53] + brcc doExor6 ;[46] + subi x3, 1 ;[47] + brne common6 ;[48] + lsl shift ;[49] compensate ror after rjmp stuffDelay + nop ;[50] stuffing consists of just waiting 8 cycles + rjmp stuff6Delay ;[51] after ror, C bit is reliably clear +doExor6: + eor x1, x2 ;[48] [56] + ldi x3, 6 ;[49] +common6: +stuff7Delay: + ror shift ;[50] [58] + out USBOUT, x1 ;[51] <--- set bit + brcc doExor7 ;[52] + subi x3, 1 ;[53] + brne common7 ;[54] + lsl shift ;[55] compensate ror after rjmp stuffDelay + rjmp stuff7Delay ;[56] after ror, C bit is reliably clear +doExor7: + eor x1, x2 ;[54] [62] + ldi x3, 6 ;[55] +common7: + ld shift, y+ ;[56] + nop ;[58] + tst cnt ;[59] + out USBOUT, x1 ;[60] [00]<--- set bit + brne txByteLoop ;[61] [01] +;make SE0: + cbr x1, USBMASK ;[02] prepare SE0 [spec says EOP may be 15 to 18 cycles] + lds x2, usbNewDeviceAddr;[03] + lsl x2 ;[05] we compare with left shifted address + subi YL, 2 + 0 ;[06] Only assign address on data packets, not ACK/NAK in r0 + sbci YH, 0 ;[07] + out USBOUT, x1 ;[00] <-- out SE0 -- from now 2 bits = 16 cycles until bus idle +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + breq skipAddrAssign ;[01] + sts usbDeviceAddr, x2 ; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< 0) + echo "$s\n"; + } +} + +function printBit($isAfterSet, $bitNum) +{ + ob_start(); + if($isAfterSet){ +?> + ifioclr USBIN, USBMINUS ;[00] <--- sample + rjmp bit#IsClr ;[01] + andi shift, ~(7 << #) ;[02] + breq unstuff#s ;[03] + in phase, USBIN ;[04] <- phase + rjmp bit@AfterSet ;[05] +unstuff#s: + in phase, USBIN ;[05] <- phase (one cycle too late) + andi fix, ~(1 << #) ;[06] + nop2 ;[-1] + nop2 ;[01] +bit#IsClr: + ifrset phase, USBMINUS ;[03] check phase only if D- changed + lpm ;[04] + in phase, USBIN ;[05] <- phase (one cycle too late) + ori shift, 1 << # ;[06] + + ifioset USBIN, USBMINUS ;[00] <--- sample + rjmp bit#IsSet ;[01] + andi shift, ~(7 << #) ;[02] + breq unstuff#c ;[03] + in phase, USBIN ;[04] <- phase + rjmp bit@AfterClr ;[05] +unstuff#c: + in phase, USBIN ;[05] <- phase (one cycle too late) + andi fix, ~(1 << #) ;[06] + nop2 ;[-1] + nop2 ;[01] +bit#IsSet: + ifrclr phase, USBMINUS ;[03] check phase only if D- changed + lpm ;[04] + in phase, USBIN ;[05] <- phase (one cycle too late) + ori shift, 1 << # ;[06] + +*****************************************************************************/ diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm15.inc b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm15.inc new file mode 100644 index 0000000..401b7f8 --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm15.inc @@ -0,0 +1,423 @@ +/* Name: usbdrvasm15.inc + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: contributed by V. Bosch + * Creation Date: 2007-08-06 + * Tabsize: 4 + * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Revision: $Id: usbdrvasm15.inc 740 2009-04-13 18:23:31Z cs $ + */ + +/* Do not link this file! Link usbdrvasm.S instead, which includes the + * appropriate implementation! + */ + +/* +General Description: +This file is the 15 MHz version of the asssembler part of the USB driver. It +requires a 15 MHz crystal (not a ceramic resonator and not a calibrated RC +oscillator). + +See usbdrv.h for a description of the entire driver. + +Since almost all of this code is timing critical, don't change unless you +really know what you are doing! Many parts require not only a maximum number +of CPU cycles, but even an exact number of cycles! +*/ + +;max stack usage: [ret(2), YL, SREG, YH, bitcnt, shift, x1, x2, x3, x4, cnt] = 12 bytes +;nominal frequency: 15 MHz -> 10.0 cycles per bit, 80.0 cycles per byte +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts + +;---------------------------------------------------------------------------- +; order of registers pushed: +; YL, SREG [sofError] YH, shift, x1, x2, x3, bitcnt, cnt, x4 +;---------------------------------------------------------------------------- +USB_INTR_VECTOR: + push YL ;2 push only what is necessary to sync with edge ASAP + in YL, SREG ;1 + push YL ;2 +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +; +; sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +; sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +;------------------------------------------------------------------------------- +; The following code results in a sampling window of < 1/4 bit +; which meets the spec. +;------------------------------------------------------------------------------- +waitForK: ;- + sbis USBIN, USBMINUS ;1 [00] <-- sample + rjmp foundK ;2 [01] + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK + sbis USBIN, USBMINUS ; <-- sample + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +;------------------------------------------------------------------------------ +; {3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for +; center sampling] +; we have 1 bit time for setup purposes, then sample again. +; Numbers in brackets are cycles from center of first sync (double K) +; bit after the instruction +;------------------------------------------------------------------------------ +foundK: ;- [02] + lds YL, usbInputBufOffset;2 [03+04] tx loop + push YH ;2 [05+06] + clr YH ;1 [07] + subi YL, lo8(-(usbRxBuf)) ;1 [08] [rx loop init] + sbci YH, hi8(-(usbRxBuf)) ;1 [09] [rx loop init] + push shift ;2 [10+11] + ser shift ;1 [12] + sbis USBIN, USBMINUS ;1 [-1] [13] <--sample:we want two bits K (sample 1 cycle too early) + rjmp haveTwoBitsK ;2 [00] [14] + pop shift ;2 [15+16] undo the push from before + pop YH ;2 [17+18] undo the push from before + rjmp waitForK ;2 [19+20] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 20 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: ;- [01] + push x1 ;2 [02+03] + push x2 ;2 [04+05] + push x3 ;2 [06+07] + push bitcnt ;2 [08+09] + in x1, USBIN ;1 [00] [10] <-- sample bit 0 + bst x1, USBMINUS ;1 [01] + bld shift, 0 ;1 [02] + push cnt ;2 [03+04] + ldi cnt, USB_BUFSIZE ;1 [05] + push x4 ;2 [06+07] tx loop + rjmp rxLoop ;2 [08] +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- +unstuff0: ;- [07] (branch taken) + andi x3, ~0x01 ;1 [08] + mov x1, x2 ;1 [09] x2 contains last sampled (stuffed) bit + in x2, USBIN ;1 [00] [10] <-- sample bit 1 again + andi x2, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 1 + ori shift, 0x01 ;1 [03] 0b00000001 + nop ;1 [04] + rjmp didUnstuff0 ;2 [05] +;----------------------------------------------------- +unstuff1: ;- [05] (branch taken) + mov x2, x1 ;1 [06] x1 contains last sampled (stuffed) bit + andi x3, ~0x02 ;1 [07] + ori shift, 0x02 ;1 [08] 0b00000010 + nop ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample bit 2 again + andi x1, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 2 + rjmp didUnstuff1 ;2 [03] +;----------------------------------------------------- +unstuff2: ;- [05] (branch taken) + andi x3, ~0x04 ;1 [06] + ori shift, 0x04 ;1 [07] 0b00000100 + mov x1, x2 ;1 [08] x2 contains last sampled (stuffed) bit + nop ;1 [09] + in x2, USBIN ;1 [00] [10] <-- sample bit 3 + andi x2, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 3 + rjmp didUnstuff2 ;2 [03] +;----------------------------------------------------- +unstuff3: ;- [00] [10] (branch taken) + in x2, USBIN ;1 [01] [11] <-- sample stuffed bit 3 one cycle too late + andi x2, USBMASK ;1 [02] + breq se0Hop ;1 [03] SE0 check for stuffed bit 3 + andi x3, ~0x08 ;1 [04] + ori shift, 0x08 ;1 [05] 0b00001000 + rjmp didUnstuff3 ;2 [06] +;---------------------------------------------------------------------------- +; extra jobs done during bit interval: +; +; bit 0: store, clear [SE0 is unreliable here due to bit dribbling in hubs], +; overflow check, jump to the head of rxLoop +; bit 1: SE0 check +; bit 2: SE0 check, recovery from delay [bit 0 tasks took too long] +; bit 3: SE0 check, recovery from delay [bit 0 tasks took too long] +; bit 4: SE0 check, none +; bit 5: SE0 check, none +; bit 6: SE0 check, none +; bit 7: SE0 check, reconstruct: x3 is 0 at bit locations we changed, 1 at others +;---------------------------------------------------------------------------- +rxLoop: ;- [09] + in x2, USBIN ;1 [00] [10] <-- sample bit 1 (or possibly bit 0 stuffed) + andi x2, USBMASK ;1 [01] + brne SkipSe0Hop ;1 [02] +se0Hop: ;- [02] + rjmp se0 ;2 [03] SE0 check for bit 1 +SkipSe0Hop: ;- [03] + ser x3 ;1 [04] + andi shift, 0xf9 ;1 [05] 0b11111001 + breq unstuff0 ;1 [06] +didUnstuff0: ;- [06] + eor x1, x2 ;1 [07] + bst x1, USBMINUS ;1 [08] + bld shift, 1 ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample bit 2 (or possibly bit 1 stuffed) + andi x1, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 2 + andi shift, 0xf3 ;1 [03] 0b11110011 + breq unstuff1 ;1 [04] do remaining work for bit 1 +didUnstuff1: ;- [04] + eor x2, x1 ;1 [05] + bst x2, USBMINUS ;1 [06] + bld shift, 2 ;1 [07] + nop2 ;2 [08+09] + in x2, USBIN ;1 [00] [10] <-- sample bit 3 (or possibly bit 2 stuffed) + andi x2, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 3 + andi shift, 0xe7 ;1 [03] 0b11100111 + breq unstuff2 ;1 [04] +didUnstuff2: ;- [04] + eor x1, x2 ;1 [05] + bst x1, USBMINUS ;1 [06] + bld shift, 3 ;1 [07] +didUnstuff3: ;- [07] + andi shift, 0xcf ;1 [08] 0b11001111 + breq unstuff3 ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample bit 4 + andi x1, USBMASK ;1 [01] + breq se0Hop ;1 [02] SE0 check for bit 4 + eor x2, x1 ;1 [03] + bst x2, USBMINUS ;1 [04] + bld shift, 4 ;1 [05] +didUnstuff4: ;- [05] + andi shift, 0x9f ;1 [06] 0b10011111 + breq unstuff4 ;1 [07] + nop2 ;2 [08+09] + in x2, USBIN ;1 [00] [10] <-- sample bit 5 + andi x2, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for bit 5 + eor x1, x2 ;1 [03] + bst x1, USBMINUS ;1 [04] + bld shift, 5 ;1 [05] +didUnstuff5: ;- [05] + andi shift, 0x3f ;1 [06] 0b00111111 + breq unstuff5 ;1 [07] + nop2 ;2 [08+09] + in x1, USBIN ;1 [00] [10] <-- sample bit 6 + andi x1, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for bit 6 + eor x2, x1 ;1 [03] + bst x2, USBMINUS ;1 [04] + bld shift, 6 ;1 [05] +didUnstuff6: ;- [05] + cpi shift, 0x02 ;1 [06] 0b00000010 + brlo unstuff6 ;1 [07] + nop2 ;2 [08+09] + in x2, USBIN ;1 [00] [10] <-- sample bit 7 + andi x2, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for bit 7 + eor x1, x2 ;1 [03] + bst x1, USBMINUS ;1 [04] + bld shift, 7 ;1 [05] +didUnstuff7: ;- [05] + cpi shift, 0x04 ;1 [06] 0b00000100 + brlo unstuff7 ;1 [07] + eor x3, shift ;1 [08] reconstruct: x3 is 0 at bit locations we changed, 1 at others + nop ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample bit 0 + st y+, x3 ;2 [01+02] store data + eor x2, x1 ;1 [03] + bst x2, USBMINUS ;1 [04] + bld shift, 0 ;1 [05] + subi cnt, 1 ;1 [06] + brcs overflow ;1 [07] + rjmp rxLoop ;2 [08] +;----------------------------------------------------- +unstuff4: ;- [08] + andi x3, ~0x10 ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample stuffed bit 4 + andi x1, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for stuffed bit 4 + ori shift, 0x10 ;1 [03] + rjmp didUnstuff4 ;2 [04] +;----------------------------------------------------- +unstuff5: ;- [08] + ori shift, 0x20 ;1 [09] + in x2, USBIN ;1 [00] [10] <-- sample stuffed bit 5 + andi x2, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for stuffed bit 5 + andi x3, ~0x20 ;1 [03] + rjmp didUnstuff5 ;2 [04] +;----------------------------------------------------- +unstuff6: ;- [08] + andi x3, ~0x40 ;1 [09] + in x1, USBIN ;1 [00] [10] <-- sample stuffed bit 6 + andi x1, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for stuffed bit 6 + ori shift, 0x40 ;1 [03] + rjmp didUnstuff6 ;2 [04] +;----------------------------------------------------- +unstuff7: ;- [08] + andi x3, ~0x80 ;1 [09] + in x2, USBIN ;1 [00] [10] <-- sample stuffed bit 7 + andi x2, USBMASK ;1 [01] + breq se0 ;1 [02] SE0 check for stuffed bit 7 + ori shift, 0x80 ;1 [03] + rjmp didUnstuff7 ;2 [04] + +macro POP_STANDARD ; 16 cycles + pop x4 + pop cnt + pop bitcnt + pop x3 + pop x2 + pop x1 + pop shift + pop YH + endm +macro POP_RETI ; 5 cycles + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + +;--------------------------------------------------------------------------- +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) +; K = (D+ = 1), (D- = 0) +; Spec allows 7.5 bit times from EOP to SOP for replies +;--------------------------------------------------------------------------- +bitstuffN: ;- [04] + eor x1, x4 ;1 [05] + clr x2 ;1 [06] + nop ;1 [07] + rjmp didStuffN ;1 [08] +;--------------------------------------------------------------------------- +bitstuff6: ;- [04] + eor x1, x4 ;1 [05] + clr x2 ;1 [06] + rjmp didStuff6 ;1 [07] +;--------------------------------------------------------------------------- +bitstuff7: ;- [02] + eor x1, x4 ;1 [03] + clr x2 ;1 [06] + nop ;1 [05] + rjmp didStuff7 ;1 [06] +;--------------------------------------------------------------------------- +sendNakAndReti: ;- [-19] + ldi x3, USBPID_NAK ;1 [-18] + rjmp sendX3AndReti ;1 [-17] +;--------------------------------------------------------------------------- +sendAckAndReti: ;- [-17] + ldi cnt, USBPID_ACK ;1 [-16] +sendCntAndReti: ;- [-16] + mov x3, cnt ;1 [-15] +sendX3AndReti: ;- [-15] + ldi YL, 20 ;1 [-14] x3==r20 address is 20 + ldi YH, 0 ;1 [-13] + ldi cnt, 2 ;1 [-12] +; rjmp usbSendAndReti fallthrough +;--------------------------------------------------------------------------- +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] +;uses: x1...x4, btcnt, shift, cnt, Y +;Numbers in brackets are time since first bit of sync pattern is sent +;We need not to match the transfer rate exactly because the spec demands +;only 1.5% precision anyway. +usbSendAndReti: ;- [-13] 13 cycles until SOP + in x2, USBDDR ;1 [-12] + ori x2, USBMASK ;1 [-11] + sbi USBOUT, USBMINUS ;2 [-09-10] prepare idle state; D+ and D- must have been 0 (no pullups) + in x1, USBOUT ;1 [-08] port mirror for tx loop + out USBDDR, x2 ;1 [-07] <- acquire bus + ; need not init x2 (bitstuff history) because sync starts with 0 + ldi x4, USBMASK ;1 [-06] exor mask + ldi shift, 0x80 ;1 [-05] sync byte is first byte sent + ldi bitcnt, 6 ;1 [-04] +txBitLoop: ;- [-04] [06] + sbrs shift, 0 ;1 [-03] [07] + eor x1, x4 ;1 [-02] [08] + ror shift ;1 [-01] [09] +didStuffN: ;- [09] + out USBOUT, x1 ;1 [00] [10] <-- out N + ror x2 ;1 [01] + cpi x2, 0xfc ;1 [02] + brcc bitstuffN ;1 [03] + dec bitcnt ;1 [04] + brne txBitLoop ;1 [05] + sbrs shift, 0 ;1 [06] + eor x1, x4 ;1 [07] + ror shift ;1 [08] +didStuff6: ;- [08] + nop ;1 [09] + out USBOUT, x1 ;1 [00] [10] <-- out 6 + ror x2 ;1 [01] + cpi x2, 0xfc ;1 [02] + brcc bitstuff6 ;1 [03] + sbrs shift, 0 ;1 [04] + eor x1, x4 ;1 [05] + ror shift ;1 [06] + ror x2 ;1 [07] +didStuff7: ;- [07] + ldi bitcnt, 6 ;1 [08] + cpi x2, 0xfc ;1 [09] + out USBOUT, x1 ;1 [00] [10] <-- out 7 + brcc bitstuff7 ;1 [01] + ld shift, y+ ;2 [02+03] + dec cnt ;1 [04] + brne txBitLoop ;1 [05] +makeSE0: + cbr x1, USBMASK ;1 [06] prepare SE0 [spec says EOP may be 19 to 23 cycles] + lds x2, usbNewDeviceAddr;2 [07+08] + lsl x2 ;1 [09] we compare with left shifted address +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + out USBOUT, x1 ;1 [00] [10] <-- out SE0-- from now 2 bits==20 cycl. until bus idle + subi YL, 20 + 2 ;1 [01] Only assign address on data packets, not ACK/NAK in x3 + sbci YH, 0 ;1 [02] + breq skipAddrAssign ;1 [03] + sts usbDeviceAddr, x2 ;2 [04+05] if not skipped: SE0 is one cycle longer +;---------------------------------------------------------------------------- +;end of usbDeviceAddress transfer +skipAddrAssign: ;- [03/04] + ldi x2, 1< 10.6666666 cycles per bit, 85.333333333 cycles per byte +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG YH, [sofError], bitcnt, shift, x1, x2, x3, x4, cnt + push YL ;[-25] push only what is necessary to sync with edge ASAP + in YL, SREG ;[-23] + push YL ;[-22] + push YH ;[-20] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of < 1/4 bit which meets the spec. + sbis USBIN, USBMINUS ;[-15] + rjmp foundK ;[-14] + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: ;[-12] +;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling] +;we have 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push bitcnt ;[-12] +; [---] ;[-11] + lds YL, usbInputBufOffset;[-10] +; [---] ;[-9] + clr YH ;[-8] + subi YL, lo8(-(usbRxBuf));[-7] [rx loop init] + sbci YH, hi8(-(usbRxBuf));[-6] [rx loop init] + push shift ;[-5] +; [---] ;[-4] + ldi bitcnt, 0x55 ;[-3] [rx loop init] + sbis USBIN, USBMINUS ;[-2] we want two bits K (sample 2 cycles too early) + rjmp haveTwoBitsK ;[-1] + pop shift ;[0] undo the push from before + pop bitcnt ;[2] undo the push from before + rjmp waitForK ;[4] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 21 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: + push x1 ;[1] + push x2 ;[3] + push x3 ;[5] + ldi shift, 0 ;[7] + ldi x3, 1<<4 ;[8] [rx loop init] first sample is inverse bit, compensate that + push x4 ;[9] == leap + + in x1, USBIN ;[11] <-- sample bit 0 + andi x1, USBMASK ;[12] + bst x1, USBMINUS ;[13] + bld shift, 7 ;[14] + push cnt ;[15] + ldi leap, 0 ;[17] [rx loop init] + ldi cnt, USB_BUFSIZE;[18] [rx loop init] + rjmp rxbit1 ;[19] arrives at [21] + +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- + +; duration of unstuffing code should be 10.66666667 cycles. We adjust "leap" +; accordingly to approximate this value in the long run. + +unstuff6: + andi x2, USBMASK ;[03] + ori x3, 1<<6 ;[04] will not be shifted any more + andi shift, ~0x80;[05] + mov x1, x2 ;[06] sampled bit 7 is actually re-sampled bit 6 + subi leap, -1 ;[07] total duration = 11 bits -> subtract 1/3 + rjmp didUnstuff6 ;[08] + +unstuff7: + ori x3, 1<<7 ;[09] will not be shifted any more + in x2, USBIN ;[00] [10] re-sample bit 7 + andi x2, USBMASK ;[01] + andi shift, ~0x80;[02] + subi leap, 2 ;[03] total duration = 10 bits -> add 1/3 + rjmp didUnstuff7 ;[04] + +unstuffEven: + ori x3, 1<<6 ;[09] will be shifted right 6 times for bit 0 + in x1, USBIN ;[00] [10] + andi shift, ~0x80;[01] + andi x1, USBMASK ;[02] + breq se0 ;[03] + subi leap, -1 ;[04] total duration = 11 bits -> subtract 1/3 + nop2 ;[05] + rjmp didUnstuffE ;[06] + +unstuffOdd: + ori x3, 1<<5 ;[09] will be shifted right 4 times for bit 1 + in x2, USBIN ;[00] [10] + andi shift, ~0x80;[01] + andi x2, USBMASK ;[02] + breq se0 ;[03] + subi leap, -1 ;[04] total duration = 11 bits -> subtract 1/3 + nop2 ;[05] + rjmp didUnstuffO ;[06] + +rxByteLoop: + andi x1, USBMASK ;[03] + eor x2, x1 ;[04] + subi leap, 1 ;[05] + brpl skipLeap ;[06] + subi leap, -3 ;1 one leap cycle every 3rd byte -> 85 + 1/3 cycles per byte + nop ;1 +skipLeap: + subi x2, 1 ;[08] + ror shift ;[09] +didUnstuff6: + cpi shift, 0xfc ;[10] + in x2, USBIN ;[00] [11] <-- sample bit 7 + brcc unstuff6 ;[01] + andi x2, USBMASK ;[02] + eor x1, x2 ;[03] + subi x1, 1 ;[04] + ror shift ;[05] +didUnstuff7: + cpi shift, 0xfc ;[06] + brcc unstuff7 ;[07] + eor x3, shift ;[08] reconstruct: x3 is 1 at bit locations we changed, 0 at others + st y+, x3 ;[09] store data +rxBitLoop: + in x1, USBIN ;[00] [11] <-- sample bit 0/2/4 + andi x1, USBMASK ;[01] + eor x2, x1 ;[02] + andi x3, 0x3f ;[03] topmost two bits reserved for 6 and 7 + subi x2, 1 ;[04] + ror shift ;[05] + cpi shift, 0xfc ;[06] + brcc unstuffEven ;[07] +didUnstuffE: + lsr x3 ;[08] + lsr x3 ;[09] +rxbit1: + in x2, USBIN ;[00] [10] <-- sample bit 1/3/5 + andi x2, USBMASK ;[01] + breq se0 ;[02] + eor x1, x2 ;[03] + subi x1, 1 ;[04] + ror shift ;[05] + cpi shift, 0xfc ;[06] + brcc unstuffOdd ;[07] +didUnstuffO: + subi bitcnt, 0xab;[08] == addi 0x55, 0x55 = 0x100/3 + brcs rxBitLoop ;[09] + + subi cnt, 1 ;[10] + in x1, USBIN ;[00] [11] <-- sample bit 6 + brcc rxByteLoop ;[01] + rjmp overflow + +macro POP_STANDARD ; 14 cycles + pop cnt + pop x4 + pop x3 + pop x2 + pop x1 + pop shift + pop bitcnt + endm +macro POP_RETI ; 7 cycles + pop YH + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) +; K = (D+ = 1), (D- = 0) +; Spec allows 7.5 bit times from EOP to SOP for replies + +bitstuffN: + eor x1, x4 ;[5] + ldi x2, 0 ;[6] + nop2 ;[7] + nop ;[9] + out USBOUT, x1 ;[10] <-- out + rjmp didStuffN ;[0] + +bitstuff6: + eor x1, x4 ;[5] + ldi x2, 0 ;[6] Carry is zero due to brcc + rol shift ;[7] compensate for ror shift at branch destination + rjmp didStuff6 ;[8] + +bitstuff7: + ldi x2, 0 ;[2] Carry is zero due to brcc + rjmp didStuff7 ;[3] + + +sendNakAndReti: + ldi x3, USBPID_NAK ;[-18] + rjmp sendX3AndReti ;[-17] +sendAckAndReti: + ldi cnt, USBPID_ACK ;[-17] +sendCntAndReti: + mov x3, cnt ;[-16] +sendX3AndReti: + ldi YL, 20 ;[-15] x3==r20 address is 20 + ldi YH, 0 ;[-14] + ldi cnt, 2 ;[-13] +; rjmp usbSendAndReti fallthrough + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] +;uses: x1...x4, btcnt, shift, cnt, Y +;Numbers in brackets are time since first bit of sync pattern is sent +;We don't match the transfer rate exactly (don't insert leap cycles every third +;byte) because the spec demands only 1.5% precision anyway. +usbSendAndReti: ; 12 cycles until SOP + in x2, USBDDR ;[-12] + ori x2, USBMASK ;[-11] + sbi USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) + in x1, USBOUT ;[-8] port mirror for tx loop + out USBDDR, x2 ;[-7] <- acquire bus +; need not init x2 (bitstuff history) because sync starts with 0 + ldi x4, USBMASK ;[-6] exor mask + ldi shift, 0x80 ;[-5] sync byte is first byte sent +txByteLoop: + ldi bitcnt, 0x35 ;[-4] [6] binary 0011 0101 +txBitLoop: + sbrs shift, 0 ;[-3] [7] + eor x1, x4 ;[-2] [8] + out USBOUT, x1 ;[-1] [9] <-- out N + ror shift ;[0] [10] + ror x2 ;[1] +didStuffN: + cpi x2, 0xfc ;[2] + brcc bitstuffN ;[3] + lsr bitcnt ;[4] + brcc txBitLoop ;[5] + brne txBitLoop ;[6] + + sbrs shift, 0 ;[7] + eor x1, x4 ;[8] +didStuff6: + out USBOUT, x1 ;[-1] [9] <-- out 6 + ror shift ;[0] [10] + ror x2 ;[1] + cpi x2, 0xfc ;[2] + brcc bitstuff6 ;[3] + ror shift ;[4] +didStuff7: + ror x2 ;[5] + sbrs x2, 7 ;[6] + eor x1, x4 ;[7] + nop ;[8] + cpi x2, 0xfc ;[9] + out USBOUT, x1 ;[-1][10] <-- out 7 + brcc bitstuff7 ;[0] [11] + ld shift, y+ ;[1] + dec cnt ;[3] + brne txByteLoop ;[4] +;make SE0: + cbr x1, USBMASK ;[5] prepare SE0 [spec says EOP may be 21 to 25 cycles] + lds x2, usbNewDeviceAddr;[6] + lsl x2 ;[8] we compare with left shifted address + subi YL, 20 + 2 ;[9] Only assign address on data packets, not ACK/NAK in x3 + sbci YH, 0 ;[10] + out USBOUT, x1 ;[11] <-- out SE0 -- from now 2 bits = 22 cycles until bus idle +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + breq skipAddrAssign ;[0] + sts usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< max 52 cycles interrupt disable +;max stack usage: [ret(2), r0, SREG, YL, YH, shift, x1, x2, x3, x4, cnt] = 12 bytes +;nominal frequency: 16.5 MHz -> 11 cycles per bit +; 16.3125 MHz < F_CPU < 16.6875 MHz (+/- 1.1%) +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts + + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG [sofError], r0, YH, shift, x1, x2, x3, x4, cnt + push YL ;[-23] push only what is necessary to sync with edge ASAP + in YL, SREG ;[-21] + push YL ;[-20] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of < 1/4 bit which meets the spec. + sbis USBIN, USBMINUS ;[-15] + rjmp foundK ;[-14] + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: ;[-12] +;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling] +;we have 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push r0 ;[-12] +; [---] ;[-11] + push YH ;[-10] +; [---] ;[-9] + lds YL, usbInputBufOffset;[-8] +; [---] ;[-7] + clr YH ;[-6] + subi YL, lo8(-(usbRxBuf));[-5] [rx loop init] + sbci YH, hi8(-(usbRxBuf));[-4] [rx loop init] + mov r0, x2 ;[-3] [rx loop init] + sbis USBIN, USBMINUS ;[-2] we want two bits K (sample 2 cycles too early) + rjmp haveTwoBitsK ;[-1] + pop YH ;[0] undo the pushes from before + pop r0 ;[2] + rjmp waitForK ;[4] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 22 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: ;[1] + push shift ;[1] + push x1 ;[3] + push x2 ;[5] + push x3 ;[7] + ldi shift, 0xff ;[9] [rx loop init] + ori x3, 0xff ;[10] [rx loop init] == ser x3, clear zero flag + + in x1, USBIN ;[11] <-- sample bit 0 + bst x1, USBMINUS ;[12] + bld shift, 0 ;[13] + push x4 ;[14] == phase +; [---] ;[15] + push cnt ;[16] +; [---] ;[17] + ldi phase, 0 ;[18] [rx loop init] + ldi cnt, USB_BUFSIZE;[19] [rx loop init] + rjmp rxbit1 ;[20] +; [---] ;[21] + +;---------------------------------------------------------------------------- +; Receiver loop (numbers in brackets are cycles within byte after instr) +;---------------------------------------------------------------------------- +/* +byte oriented operations done during loop: +bit 0: store data +bit 1: SE0 check +bit 2: overflow check +bit 3: catch up +bit 4: rjmp to achieve conditional jump range +bit 5: PLL +bit 6: catch up +bit 7: jump, fixup bitstuff +; 87 [+ 2] cycles +------------------------------------------------------------------ +*/ +continueWithBit5: + in x2, USBIN ;[055] <-- bit 5 + eor r0, x2 ;[056] + or phase, r0 ;[057] + sbrc phase, USBMINUS ;[058] + lpm ;[059] optional nop3; modifies r0 + in phase, USBIN ;[060] <-- phase + eor x1, x2 ;[061] + bst x1, USBMINUS ;[062] + bld shift, 5 ;[063] + andi shift, 0x3f ;[064] + in x1, USBIN ;[065] <-- bit 6 + breq unstuff5 ;[066] *** unstuff escape + eor phase, x1 ;[067] + eor x2, x1 ;[068] + bst x2, USBMINUS ;[069] + bld shift, 6 ;[070] +didUnstuff6: ;[ ] + in r0, USBIN ;[071] <-- phase + cpi shift, 0x02 ;[072] + brlo unstuff6 ;[073] *** unstuff escape +didUnstuff5: ;[ ] + nop2 ;[074] +; [---] ;[075] + in x2, USBIN ;[076] <-- bit 7 + eor x1, x2 ;[077] + bst x1, USBMINUS ;[078] + bld shift, 7 ;[079] +didUnstuff7: ;[ ] + eor r0, x2 ;[080] + or phase, r0 ;[081] + in r0, USBIN ;[082] <-- phase + cpi shift, 0x04 ;[083] + brsh rxLoop ;[084] +; [---] ;[085] +unstuff7: ;[ ] + andi x3, ~0x80 ;[085] + ori shift, 0x80 ;[086] + in x2, USBIN ;[087] <-- sample stuffed bit 7 + nop ;[088] + rjmp didUnstuff7 ;[089] +; [---] ;[090] + ;[080] + +unstuff5: ;[067] + eor phase, x1 ;[068] + andi x3, ~0x20 ;[069] + ori shift, 0x20 ;[070] + in r0, USBIN ;[071] <-- phase + mov x2, x1 ;[072] + nop ;[073] + nop2 ;[074] +; [---] ;[075] + in x1, USBIN ;[076] <-- bit 6 + eor r0, x1 ;[077] + or phase, r0 ;[078] + eor x2, x1 ;[079] + bst x2, USBMINUS ;[080] + bld shift, 6 ;[081] no need to check bitstuffing, we just had one + in r0, USBIN ;[082] <-- phase + rjmp didUnstuff5 ;[083] +; [---] ;[084] + ;[074] + +unstuff6: ;[074] + andi x3, ~0x40 ;[075] + in x1, USBIN ;[076] <-- bit 6 again + ori shift, 0x40 ;[077] + nop2 ;[078] +; [---] ;[079] + rjmp didUnstuff6 ;[080] +; [---] ;[081] + ;[071] + +unstuff0: ;[013] + eor r0, x2 ;[014] + or phase, r0 ;[015] + andi x2, USBMASK ;[016] check for SE0 + in r0, USBIN ;[017] <-- phase + breq didUnstuff0 ;[018] direct jump to se0 would be too long + andi x3, ~0x01 ;[019] + ori shift, 0x01 ;[020] + mov x1, x2 ;[021] mov existing sample + in x2, USBIN ;[022] <-- bit 1 again + rjmp didUnstuff0 ;[023] +; [---] ;[024] + ;[014] + +unstuff1: ;[024] + eor r0, x1 ;[025] + or phase, r0 ;[026] + andi x3, ~0x02 ;[027] + in r0, USBIN ;[028] <-- phase + ori shift, 0x02 ;[029] + mov x2, x1 ;[030] + rjmp didUnstuff1 ;[031] +; [---] ;[032] + ;[022] + +unstuff2: ;[035] + eor r0, x2 ;[036] + or phase, r0 ;[037] + andi x3, ~0x04 ;[038] + in r0, USBIN ;[039] <-- phase + ori shift, 0x04 ;[040] + mov x1, x2 ;[041] + rjmp didUnstuff2 ;[042] +; [---] ;[043] + ;[033] + +unstuff3: ;[043] + in x2, USBIN ;[044] <-- bit 3 again + eor r0, x2 ;[045] + or phase, r0 ;[046] + andi x3, ~0x08 ;[047] + ori shift, 0x08 ;[048] + nop ;[049] + in r0, USBIN ;[050] <-- phase + rjmp didUnstuff3 ;[051] +; [---] ;[052] + ;[042] + +unstuff4: ;[053] + andi x3, ~0x10 ;[054] + in x1, USBIN ;[055] <-- bit 4 again + ori shift, 0x10 ;[056] + rjmp didUnstuff4 ;[057] +; [---] ;[058] + ;[048] + +rxLoop: ;[085] + eor x3, shift ;[086] reconstruct: x3 is 0 at bit locations we changed, 1 at others + in x1, USBIN ;[000] <-- bit 0 + st y+, x3 ;[001] +; [---] ;[002] + eor r0, x1 ;[003] + or phase, r0 ;[004] + eor x2, x1 ;[005] + in r0, USBIN ;[006] <-- phase + ser x3 ;[007] + bst x2, USBMINUS ;[008] + bld shift, 0 ;[009] + andi shift, 0xf9 ;[010] +rxbit1: ;[ ] + in x2, USBIN ;[011] <-- bit 1 + breq unstuff0 ;[012] *** unstuff escape + andi x2, USBMASK ;[013] SE0 check for bit 1 +didUnstuff0: ;[ ] Z only set if we detected SE0 in bitstuff + breq se0 ;[014] + eor r0, x2 ;[015] + or phase, r0 ;[016] + in r0, USBIN ;[017] <-- phase + eor x1, x2 ;[018] + bst x1, USBMINUS ;[019] + bld shift, 1 ;[020] + andi shift, 0xf3 ;[021] +didUnstuff1: ;[ ] + in x1, USBIN ;[022] <-- bit 2 + breq unstuff1 ;[023] *** unstuff escape + eor r0, x1 ;[024] + or phase, r0 ;[025] + subi cnt, 1 ;[026] overflow check + brcs overflow ;[027] + in r0, USBIN ;[028] <-- phase + eor x2, x1 ;[029] + bst x2, USBMINUS ;[030] + bld shift, 2 ;[031] + andi shift, 0xe7 ;[032] +didUnstuff2: ;[ ] + in x2, USBIN ;[033] <-- bit 3 + breq unstuff2 ;[034] *** unstuff escape + eor r0, x2 ;[035] + or phase, r0 ;[036] + eor x1, x2 ;[037] + bst x1, USBMINUS ;[038] + in r0, USBIN ;[039] <-- phase + bld shift, 3 ;[040] + andi shift, 0xcf ;[041] +didUnstuff3: ;[ ] + breq unstuff3 ;[042] *** unstuff escape + nop ;[043] + in x1, USBIN ;[044] <-- bit 4 + eor x2, x1 ;[045] + bst x2, USBMINUS ;[046] + bld shift, 4 ;[047] +didUnstuff4: ;[ ] + eor r0, x1 ;[048] + or phase, r0 ;[049] + in r0, USBIN ;[050] <-- phase + andi shift, 0x9f ;[051] + breq unstuff4 ;[052] *** unstuff escape + rjmp continueWithBit5;[053] +; [---] ;[054] + +macro POP_STANDARD ; 16 cycles + pop cnt + pop x4 + pop x3 + pop x2 + pop x1 + pop shift + pop YH + pop r0 + endm +macro POP_RETI ; 5 cycles + pop YL + out SREG, YL + pop YL + endm + +#include "asmcommon.inc" + + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) +; K = (D+ = 1), (D- = 0) +; Spec allows 7.5 bit times from EOP to SOP for replies + +bitstuff7: + eor x1, x4 ;[4] + ldi x2, 0 ;[5] + nop2 ;[6] C is zero (brcc) + rjmp didStuff7 ;[8] + +bitstuffN: + eor x1, x4 ;[5] + ldi x2, 0 ;[6] + lpm ;[7] 3 cycle NOP, modifies r0 + out USBOUT, x1 ;[10] <-- out + rjmp didStuffN ;[0] + +#define bitStatus x3 + +sendNakAndReti: + ldi cnt, USBPID_NAK ;[-19] + rjmp sendCntAndReti ;[-18] +sendAckAndReti: + ldi cnt, USBPID_ACK ;[-17] +sendCntAndReti: + mov r0, cnt ;[-16] + ldi YL, 0 ;[-15] R0 address is 0 + ldi YH, 0 ;[-14] + ldi cnt, 2 ;[-13] +; rjmp usbSendAndReti fallthrough + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] +;uses: x1...x4, shift, cnt, Y +;Numbers in brackets are time since first bit of sync pattern is sent +usbSendAndReti: ; 12 cycles until SOP + in x2, USBDDR ;[-12] + ori x2, USBMASK ;[-11] + sbi USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) + in x1, USBOUT ;[-8] port mirror for tx loop + out USBDDR, x2 ;[-7] <- acquire bus +; need not init x2 (bitstuff history) because sync starts with 0 + ldi x4, USBMASK ;[-6] exor mask + ldi shift, 0x80 ;[-5] sync byte is first byte sent + ldi bitStatus, 0xff ;[-4] init bit loop counter, works for up to 12 bytes +byteloop: +bitloop: + sbrs shift, 0 ;[8] [-3] + eor x1, x4 ;[9] [-2] + out USBOUT, x1 ;[10] [-1] <-- out + ror shift ;[0] + ror x2 ;[1] +didStuffN: + cpi x2, 0xfc ;[2] + brcc bitstuffN ;[3] + nop ;[4] + subi bitStatus, 37 ;[5] 256 / 7 ~=~ 37 + brcc bitloop ;[6] when we leave the loop, bitStatus has almost the initial value + sbrs shift, 0 ;[7] + eor x1, x4 ;[8] + ror shift ;[9] +didStuff7: + out USBOUT, x1 ;[10] <-- out + ror x2 ;[0] + cpi x2, 0xfc ;[1] + brcc bitstuff7 ;[2] + ld shift, y+ ;[3] + dec cnt ;[5] + brne byteloop ;[6] +;make SE0: + cbr x1, USBMASK ;[7] prepare SE0 [spec says EOP may be 21 to 25 cycles] + lds x2, usbNewDeviceAddr;[8] + lsl x2 ;[10] we compare with left shifted address + out USBOUT, x1 ;[11] <-- out SE0 -- from now 2 bits = 22 cycles until bus idle +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + subi YL, 2 ;[0] Only assign address on data packets, not ACK/NAK in r0 + sbci YH, 0 ;[1] + breq skipAddrAssign ;[2] + sts usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< 12 cycles per bit +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts +;register use in receive loop to receive the data bytes: +; shift assembles the byte currently being received +; x1 holds the D+ and D- line state +; x2 holds the previous line state +; cnt holds the number of bytes left in the receive buffer +; x3 holds the higher crc byte (see algorithm below) +; x4 is used as temporary register for the crc algorithm +; x5 is used for unstuffing: when unstuffing the last received bit is inverted in shift (to prevent further +; unstuffing calls. In the same time the corresponding bit in x5 is cleared to mark the bit as beening iverted +; zl lower crc value and crc table index +; zh used for crc table accesses + +;-------------------------------------------------------------------------------------------------------------- +; CRC mods: +; table driven crc checker, Z points to table in prog space +; ZL is the lower crc byte, x3 is the higher crc byte +; x4 is used as temp register to store different results +; the initialization of the crc register is not 0xFFFF but 0xFE54. This is because during the receipt of the +; first data byte an virtual zero data byte is added to the crc register, this results in the correct initial +; value of 0xFFFF at beginning of the second data byte before the first data byte is added to the crc. +; The magic number 0xFE54 results form the crc table: At tabH[0x54] = 0xFF = crcH (required) and +; tabL[0x54] = 0x01 -> crcL = 0x01 xor 0xFE = 0xFF +; bitcnt is renamed to x5 and is used for unstuffing purposes, the unstuffing works like in the 12MHz version +;-------------------------------------------------------------------------------------------------------------- +; CRC algorithm: +; The crc register is formed by x3 (higher byte) and ZL (lower byte). The algorithm uses a 'reversed' form +; i.e. that it takes the least significant bit first and shifts to the right. So in fact the highest order +; bit seen from the polynomial devision point of view is the lsb of ZL. (If this sounds strange to you i +; propose a research on CRC :-) ) +; Each data byte received is xored to ZL, the lower crc byte. This byte now builds the crc +; table index. Next the new high byte is loaded from the table and stored in x4 until we have space in x3 +; (its destination). +; Afterwards the lower table is loaded from the table and stored in ZL (the old index is overwritten as +; we don't need it anymore. In fact this is a right shift by 8 bits.) Now the old crc high value is xored +; to ZL, this is the second shift of the old crc value. Now x4 (the temp reg) is moved to x3 and the crc +; calculation is done. +; Prior to the first byte the two CRC register have to be initialized to 0xFFFF (as defined in usb spec) +; however the crc engine also runs during the receipt of the first byte, therefore x3 and zl are initialized +; to a magic number which results in a crc value of 0xFFFF after the first complete byte. +; +; This algorithm is split into the extra cycles of the different bits: +; bit7: XOR the received byte to ZL +; bit5: load the new high byte to x4 +; bit6: load the lower xor byte from the table, xor zl and x3, store result in zl (=the new crc low value) +; move x4 (the new high byte) to x3, the crc value is ready +; + + +macro POP_STANDARD ; 18 cycles + pop ZH + pop ZL + pop cnt + pop x5 + pop x3 + pop x2 + pop x1 + pop shift + pop x4 + endm +macro POP_RETI ; 7 cycles + pop YH + pop YL + out SREG, YL + pop YL + endm + +macro CRC_CLEANUP_AND_CHECK + ; the last byte has already been xored with the lower crc byte, we have to do the table lookup and xor + ; x3 is the higher crc byte, zl the lower one + ldi ZH, hi8(usbCrcTableHigh);[+1] get the new high byte from the table + lpm x2, Z ;[+2][+3][+4] + ldi ZH, hi8(usbCrcTableLow);[+5] get the new low xor byte from the table + lpm ZL, Z ;[+6][+7][+8] + eor ZL, x3 ;[+7] xor the old high byte with the value from the table, x2:ZL now holds the crc value + cpi ZL, 0x01 ;[+8] if the crc is ok we have a fixed remainder value of 0xb001 in x2:ZL (see usb spec) + brne ignorePacket ;[+9] detected a crc fault -> paket is ignored and retransmitted by the host + cpi x2, 0xb0 ;[+10] + brne ignorePacket ;[+11] detected a crc fault -> paket is ignored and retransmitted by the host + endm + + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG, YH, [sofError], x4, shift, x1, x2, x3, x5, cnt, ZL, ZH + push YL ;[-28] push only what is necessary to sync with edge ASAP + in YL, SREG ;[-26] + push YL ;[-25] + push YH ;[-23] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of < 1/4 bit which meets the spec. + sbis USBIN, USBMINUS ;[-17] + rjmp foundK ;[-16] + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: ;[-15] +;{3, 5} after falling D- edge, average delay: 4 cycles +;bit0 should be at 30 (2.5 bits) for center sampling. Currently at 4 so 26 cylces till bit 0 sample +;use 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push x4 ;[-14] +; [---] ;[-13] + lds YL, usbInputBufOffset;[-12] used to toggle the two usb receive buffers +; [---] ;[-11] + clr YH ;[-10] + subi YL, lo8(-(usbRxBuf));[-9] [rx loop init] + sbci YH, hi8(-(usbRxBuf));[-8] [rx loop init] + push shift ;[-7] +; [---] ;[-6] + ldi shift, 0x80 ;[-5] the last bit is the end of byte marker for the pid receiver loop + clc ;[-4] the carry has to be clear for receipt of pid bit 0 + sbis USBIN, USBMINUS ;[-3] we want two bits K (sample 3 cycles too early) + rjmp haveTwoBitsK ;[-2] + pop shift ;[-1] undo the push from before + pop x4 ;[1] + rjmp waitForK ;[3] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 24 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: + push x1 ;[0] + push x2 ;[2] + push x3 ;[4] crc high byte + ldi x2, 1< jump back and store the byte + ori shift, 0x01 ;[11] invert the last received bit to prevent furhter unstuffing + in x2, USBIN ;[0] we have some free cycles so we could check for bit stuffing errors + andi x5, 0xFE ;[1] mark this bit as inverted (will be corrected before storing shift) + eor x1, x2 ;[2] x1 and x2 have to be different because the stuff bit is always a zero + andi x1, USBMASK ;[3] mask the interesting bits + breq stuffErr ;[4] if the stuff bit is a 1-bit something went wrong + mov x1, x2 ;[5] the next bit expects the last state to be in x1 + rjmp didunstuff0 ;[6] + ;[7] jump delay of rjmp didunstuffX + +unstuff1: ;[11] this is the jump delay of breq unstuffX + in x1, USBIN ;[0] we have some free cycles so we could check for bit stuffing errors + ori shift, 0x02 ;[1] invert the last received bit to prevent furhter unstuffing + andi x5, 0xFD ;[2] mark this bit as inverted (will be corrected before storing shift) + eor x2, x1 ;[3] x1 and x2 have to be different because the stuff bit is always a zero + andi x2, USBMASK ;[4] mask the interesting bits + breq stuffErr ;[5] if the stuff bit is a 1-bit something went wrong + mov x2, x1 ;[6] the next bit expects the last state to be in x2 + nop2 ;[7] + ;[8] + rjmp didunstuff1 ;[9] + ;[10] jump delay of rjmp didunstuffX + +unstuff2: ;[9] this is the jump delay of breq unstuffX + ori shift, 0x04 ;[10] invert the last received bit to prevent furhter unstuffing + andi x5, 0xFB ;[11] mark this bit as inverted (will be corrected before storing shift) + in x2, USBIN ;[0] we have some free cycles so we could check for bit stuffing errors + eor x1, x2 ;[1] x1 and x2 have to be different because the stuff bit is always a zero + andi x1, USBMASK ;[2] mask the interesting bits + breq stuffErr ;[3] if the stuff bit is a 1-bit something went wrong + mov x1, x2 ;[4] the next bit expects the last state to be in x1 + nop2 ;[5] + ;[6] + rjmp didunstuff2 ;[7] + ;[8] jump delay of rjmp didunstuffX + +unstuff3: ;[9] this is the jump delay of breq unstuffX + ori shift, 0x08 ;[10] invert the last received bit to prevent furhter unstuffing + andi x5, 0xF7 ;[11] mark this bit as inverted (will be corrected before storing shift) + in x1, USBIN ;[0] we have some free cycles so we could check for bit stuffing errors + eor x2, x1 ;[1] x1 and x2 have to be different because the stuff bit is always a zero + andi x2, USBMASK ;[2] mask the interesting bits + breq stuffErr ;[3] if the stuff bit is a 1-bit something went wrong + mov x2, x1 ;[4] the next bit expects the last state to be in x2 + nop2 ;[5] + ;[6] + rjmp didunstuff3 ;[7] + ;[8] jump delay of rjmp didunstuffX + + + +; the include has to be here due to branch distance restirctions +#define __USE_CRC__ +#include "asmcommon.inc" + + + +; USB spec says: +; idle = J +; J = (D+ = 0), (D- = 1) +; K = (D+ = 1), (D- = 0) +; Spec allows 7.5 bit times from EOP to SOP for replies +; 7.5 bit times is 90 cycles. ...there is plenty of time + + +sendNakAndReti: + ldi x3, USBPID_NAK ;[-18] + rjmp sendX3AndReti ;[-17] +sendAckAndReti: + ldi cnt, USBPID_ACK ;[-17] +sendCntAndReti: + mov x3, cnt ;[-16] +sendX3AndReti: + ldi YL, 20 ;[-15] x3==r20 address is 20 + ldi YH, 0 ;[-14] + ldi cnt, 2 ;[-13] +; rjmp usbSendAndReti fallthrough + +;usbSend: +;pointer to data in 'Y' +;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] +;uses: x1...x4, btcnt, shift, cnt, Y +;Numbers in brackets are time since first bit of sync pattern is sent + +usbSendAndReti: ; 12 cycles until SOP + in x2, USBDDR ;[-12] + ori x2, USBMASK ;[-11] + sbi USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) + in x1, USBOUT ;[-8] port mirror for tx loop + out USBDDR, x2 ;[-6] <- acquire bus + ldi x2, 0 ;[-6] init x2 (bitstuff history) because sync starts with 0 + ldi x4, USBMASK ;[-5] exor mask + ldi shift, 0x80 ;[-4] sync byte is first byte sent +txByteLoop: + ldi bitcnt, 0x40 ;[-3]=[9] binary 01000000 +txBitLoop: ; the loop sends the first 7 bits of the byte + sbrs shift, 0 ;[-2]=[10] if we have to send a 1 don't change the line state + eor x1, x4 ;[-1]=[11] + out USBOUT, x1 ;[0] + ror shift ;[1] + ror x2 ;[2] transfers the last sent bit to the stuffing history +didStuffN: + nop ;[3] + nop ;[4] + cpi x2, 0xfc ;[5] if we sent six consecutive ones + brcc bitstuffN ;[6] + lsr bitcnt ;[7] + brne txBitLoop ;[8] restart the loop while the 1 is still in the bitcount + +; transmit bit 7 + sbrs shift, 0 ;[9] + eor x1, x4 ;[10] +didStuff7: + ror shift ;[11] + out USBOUT, x1 ;[0] transfer bit 7 to the pins + ror x2 ;[1] move the bit into the stuffing history + cpi x2, 0xfc ;[2] + brcc bitstuff7 ;[3] + ld shift, y+ ;[4] get next byte to transmit + dec cnt ;[5] decrement byte counter + brne txByteLoop ;[7] if we have more bytes start next one + ;[8] branch delay + +;make SE0: + cbr x1, USBMASK ;[8] prepare SE0 [spec says EOP may be 25 to 30 cycles] + lds x2, usbNewDeviceAddr;[9] + lsl x2 ;[11] we compare with left shifted address + out USBOUT, x1 ;[0] <-- out SE0 -- from now 2 bits = 24 cycles until bus idle + subi YL, 20 + 2 ;[1] Only assign address on data packets, not ACK/NAK in x3 + sbci YH, 0 ;[2] +;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: +;set address only after data packet was sent, not after handshake + breq skipAddrAssign ;[3] + sts usbDeviceAddr, x2 ; if not skipped: SE0 is one cycle longer +skipAddrAssign: +;end of usbDeviceAddress transfer + ldi x2, 1< +int main (int argc, char **argv) +{ + int i, j; + for (i=0; i<512; i++){ + unsigned short crc = i & 0xff; + for(j=0; j<8; j++) crc = (crc >> 1) ^ ((crc & 1) ? 0xa001 : 0); + if((i & 7) == 0) printf("\n.byte "); + printf("0x%02x, ", (i > 0xff ? (crc >> 8) : crc) & 0xff); + if(i == 255) printf("\n"); + } + return 0; +} + +// Use the following algorithm to compute CRC values: +ushort computeCrc(uchar *msg, uchar msgLen) +{ + uchar i; + ushort crc = 0xffff; + for(i = 0; i < msgLen; i++) + crc = usbCrcTable16[lo8(crc) ^ msg[i]] ^ hi8(crc); + return crc; +} +*/ + +.balign 256 +usbCrcTableLow: +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41 +.byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 + +; .balign 256 +usbCrcTableHigh: +.byte 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2 +.byte 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04 +.byte 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E +.byte 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8 +.byte 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A +.byte 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC +.byte 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6 +.byte 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10 +.byte 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32 +.byte 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4 +.byte 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE +.byte 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38 +.byte 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA +.byte 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C +.byte 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26 +.byte 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0 +.byte 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62 +.byte 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4 +.byte 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE +.byte 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68 +.byte 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA +.byte 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C +.byte 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76 +.byte 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0 +.byte 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92 +.byte 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54 +.byte 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E +.byte 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98 +.byte 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A +.byte 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C +.byte 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86 +.byte 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 + diff --git a/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm20.inc b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm20.inc new file mode 100644 index 0000000..303abaf --- /dev/null +++ b/adb2usb/uart2usb/vusb-20100715/usbdrv/usbdrvasm20.inc @@ -0,0 +1,360 @@ +/* Name: usbdrvasm20.inc + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Jeroen Benschop + * Based on usbdrvasm16.inc from Christian Starkjohann + * Creation Date: 2008-03-05 + * Tabsize: 4 + * Copyright: (c) 2008 by Jeroen Benschop and OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Revision: $Id: usbdrvasm20.inc 740 2009-04-13 18:23:31Z cs $ + */ + +/* Do not link this file! Link usbdrvasm.S instead, which includes the + * appropriate implementation! + */ + +/* +General Description: +This file is the 20 MHz version of the asssembler part of the USB driver. It +requires a 20 MHz crystal (not a ceramic resonator and not a calibrated RC +oscillator). + +See usbdrv.h for a description of the entire driver. + +Since almost all of this code is timing critical, don't change unless you +really know what you are doing! Many parts require not only a maximum number +of CPU cycles, but even an exact number of cycles! +*/ + +#define leap2 x3 +#ifdef __IAR_SYSTEMS_ASM__ +#define nextInst $+2 +#else +#define nextInst .+0 +#endif + +;max stack usage: [ret(2), YL, SREG, YH, bitcnt, shift, x1, x2, x3, x4, cnt] = 12 bytes +;nominal frequency: 20 MHz -> 13.333333 cycles per bit, 106.666667 cycles per byte +; Numbers in brackets are clocks counted from center of last sync bit +; when instruction starts +;register use in receive loop: +; shift assembles the byte currently being received +; x1 holds the D+ and D- line state +; x2 holds the previous line state +; x4 (leap) is used to add a leap cycle once every three bytes received +; X3 (leap2) is used to add a leap cycle once every three stuff bits received +; bitcnt is used to determine when a stuff bit is due +; cnt holds the number of bytes left in the receive buffer + +USB_INTR_VECTOR: +;order of registers pushed: YL, SREG YH, [sofError], bitcnt, shift, x1, x2, x3, x4, cnt + push YL ;[-28] push only what is necessary to sync with edge ASAP + in YL, SREG ;[-26] + push YL ;[-25] + push YH ;[-23] +;---------------------------------------------------------------------------- +; Synchronize with sync pattern: +;---------------------------------------------------------------------------- +;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] +;sync up with J to K edge during sync pattern -- use fastest possible loops +;The first part waits at most 1 bit long since we must be in sync pattern. +;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to +;waitForJ, ensure that this prerequisite is met. +waitForJ: + inc YL + sbis USBIN, USBMINUS + brne waitForJ ; just make sure we have ANY timeout +waitForK: +;The following code results in a sampling window of < 1/4 bit which meets the spec. + sbis USBIN, USBMINUS ;[-19] + rjmp foundK ;[-18] + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK + sbis USBIN, USBMINUS + rjmp foundK +#if USB_COUNT_SOF + lds YL, usbSofCount + inc YL + sts usbSofCount, YL +#endif /* USB_COUNT_SOF */ +#ifdef USB_SOF_HOOK + USB_SOF_HOOK +#endif + rjmp sofError +foundK: ;[-16] +;{3, 5} after falling D- edge, average delay: 4 cycles +;bit0 should be at 34 for center sampling. Currently at 4 so 30 cylces till bit 0 sample +;use 1 bit time for setup purposes, then sample again. Numbers in brackets +;are cycles from center of first sync (double K) bit after the instruction + push bitcnt ;[-16] +; [---] ;[-15] + lds YL, usbInputBufOffset;[-14] +; [---] ;[-13] + clr YH ;[-12] + subi YL, lo8(-(usbRxBuf));[-11] [rx loop init] + sbci YH, hi8(-(usbRxBuf));[-10] [rx loop init] + push shift ;[-9] +; [---] ;[-8] + ldi shift,0x40 ;[-7] set msb to "1" so processing bit7 can be detected + nop2 ;[-6] +; [---] ;[-5] + ldi bitcnt, 5 ;[-4] [rx loop init] + sbis USBIN, USBMINUS ;[-3] we want two bits K (sample 3 cycles too early) + rjmp haveTwoBitsK ;[-2] + pop shift ;[-1] undo the push from before + pop bitcnt ;[1] + rjmp waitForK ;[3] this was not the end of sync, retry +; The entire loop from waitForK until rjmp waitForK above must not exceed two +; bit times (= 27 cycles). + +;---------------------------------------------------------------------------- +; push more registers and initialize values while we sample the first bits: +;---------------------------------------------------------------------------- +haveTwoBitsK: + push x1 ;[0] + push x2 ;[2] + push x3 ;[4] (leap2) + ldi leap2, 0x55 ;[6] add leap cycle on 2nd,5th,8th,... stuff bit + push x4 ;[7] == leap + ldi leap, 0x55 ;[9] skip leap cycle on 2nd,5th,8th,... byte received + push cnt ;[10] + ldi cnt, USB_BUFSIZE ;[12] [rx loop init] + ldi x2, 1< +#ifndef __IAR_SYSTEMS_ASM__ +# include +#endif + +#define __attribute__(arg) /* not supported on IAR */ + +#ifdef __IAR_SYSTEMS_ASM__ +# define __ASSEMBLER__ /* IAR does not define standard macro for asm */ +#endif + +#ifdef __HAS_ELPM__ +# define PROGMEM __farflash +#else +# define PROGMEM __flash +#endif + +#define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) + +/* The following definitions are not needed by the driver, but may be of some + * help if you port a gcc based project to IAR. + */ +#define cli() __disable_interrupt() +#define sei() __enable_interrupt() +#define wdt_reset() __watchdog_reset() +#define _BV(x) (1 << (x)) + +/* assembler compatibility macros */ +#define nop2 rjmp $+2 /* jump to next instruction */ +#define XL r26 +#define XH r27 +#define YL r28 +#define YH r29 +#define ZL r30 +#define ZH r31 +#define lo8(x) LOW(x) +#define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */ + +/* Depending on the device you use, you may get problems with the way usbdrv.h + * handles the differences between devices. Since IAR does not use #defines + * for MCU registers, we can't check for the existence of a particular + * register with an #ifdef. If the autodetection mechanism fails, include + * definitions for the required USB_INTR_* macros in your usbconfig.h. See + * usbconfig-prototype.h and usbdrv.h for details. + */ + +/* ------------------------------------------------------------------------- */ +#elif __CODEVISIONAVR__ /* check for CodeVision AVR */ +/* ------------------------------------------------------------------------- */ +/* This port is not working (yet) */ + +/* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */ + +#include +#include + +#define __attribute__(arg) /* not supported on IAR */ + +#define PROGMEM __flash +#define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) + +#ifndef __ASSEMBLER__ +static inline void cli(void) +{ + #asm("cli"); +} +static inline void sei(void) +{ + #asm("sei"); +} +#endif +#define _delay_ms(t) delay_ms(t) +#define _BV(x) (1 << (x)) +#define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */ + +#define macro .macro +#define endm .endmacro +#define nop2 rjmp .+0 /* jump to next instruction */ + +/* ------------------------------------------------------------------------- */ +#else /* default development environment is avr-gcc/avr-libc */ +/* ------------------------------------------------------------------------- */ + +#include +#ifdef __ASSEMBLER__ +# define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */ +#else +# include +#endif + +#if USB_CFG_DRIVER_FLASH_PAGE +# define USB_READ_FLASH(addr) pgm_read_byte_far(((long)USB_CFG_DRIVER_FLASH_PAGE << 16) | (long)(addr)) +#else +# define USB_READ_FLASH(addr) pgm_read_byte(addr) +#endif + +#define macro .macro +#define endm .endm +#define nop2 rjmp .+0 /* jump to next instruction */ + +#endif /* development environment */ + +/* for conveniecne, ensure that PRG_RDB exists */ +#ifndef PRG_RDB +# define PRG_RDB(addr) USB_READ_FLASH(addr) +#endif +#endif /* __usbportability_h_INCLUDED__ */ diff --git a/kernel_driver/Kbuild b/kernel_driver/Kbuild new file mode 100644 index 0000000..4a6329c --- /dev/null +++ b/kernel_driver/Kbuild @@ -0,0 +1 @@ +obj-m := macusbfb.o diff --git a/kernel_driver/LICENSE b/kernel_driver/LICENSE new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/kernel_driver/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/kernel_driver/Makefile b/kernel_driver/Makefile new file mode 100644 index 0000000..49accaf --- /dev/null +++ b/kernel_driver/Makefile @@ -0,0 +1,13 @@ +KERNELPATH=/lib/modules/`uname -r`/build +#KERNELPATH=/home/jeroen/dockstar/linux-2.6.35.3 + +macusbfb.ko: macusbfb.c + make -C ${KERNELPATH} M=`pwd` + +install: macusbfb.ko + make -C ${KERNELPATH} M=`pwd` modules_install + +clean: + make -C ${KERNELPATH} M=`pwd` clean + + diff --git a/kernel_driver/macusbfb.c b/kernel_driver/macusbfb.c new file mode 100644 index 0000000..a0191b6 --- /dev/null +++ b/kernel_driver/macusbfb.c @@ -0,0 +1,535 @@ +/* +Framebuffer driver for the USB Macintosh display adapter +Copyright (C) 2010 Jeroen Domburg + +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 . +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRIVER_AUTHOR "Jeroen Domburg, jeroen@spritesmods.com" +#define DRIVER_DESC "Mac-display USB framebuffer driver" + +#define VENDOR_ID 0x1234 +#define PRODUCT_ID 0x55aa + +#define MACFB_HEIGHT 342 +#define MACFB_WIDTH 512 + +#define usb_buffer_alloc usb_alloc_coherent +#define usb_buffer_free usb_free_coherent + +#define BUF_MAX_SIZE 32768 + +/* table of devices that work with this driver */ +static struct usb_device_id id_table [] = { + { USB_DEVICE(VENDOR_ID, PRODUCT_ID) }, + { }, +}; +MODULE_DEVICE_TABLE (usb, id_table); + +struct macusbfbdev { + struct usb_device * udev; + struct fb_info * fbinfo; + unsigned char *fb; + unsigned char *pixels; + unsigned char *oldpixels; + unsigned char *xferbuff; + dma_addr_t xferbuffDmaAddr; + struct usb_anchor submitted; + int gpioVals; + atomic_t writeInProgress; + atomic_t changedWhileWriting; +}; + +static struct fb_fix_screeninfo macusbfb_fbfix __initdata = { + .id = "macusbfb", + .type = FB_TYPE_PACKED_PIXELS, + .visual = FB_VISUAL_TRUECOLOR, + .line_length = MACFB_WIDTH*2, + .accel = FB_ACCEL_NONE, +}; + +static struct fb_var_screeninfo macusbfb_fbvar __initdata = { + .xres = MACFB_WIDTH, + .yres = MACFB_HEIGHT, + .xres_virtual = MACFB_WIDTH, + .yres_virtual = MACFB_HEIGHT, + .bits_per_pixel = 16, + .red = { 11, 5, 0 }, + .green = { 4, 6, 0 }, + .blue = { 0, 5, 0 }, + .left_margin = 0, + .right_margin = 0, + .upper_margin = 0, + .lower_margin = 0, + .vmode = FB_VMODE_NONINTERLACED, +}; + + + +static void sendFramebufferOver(struct fb_info *info); + +static void macusbfb_write_bulk_callback(struct urb *urb) +{ + + struct macusbfbdev *dev; + int status = urb->status; + + dev = urb->context; + + // sync/async unlink faults aren't errors + if (status && + !(status == -ENOENT || + status == -ECONNRESET || + status == -ESHUTDOWN)) { + dbg("USBLCD: %s - nonzero write bulk status received: %d", + __func__, status); + } + + /* free up our allocated buffer */ +// usb_buffer_free(urb->dev, BUF_MAX_SIZE, +// urb->transfer_buffer, urb->transfer_dma); + + + + //Is the picture on the 'tube holy and perfect now? + if (atomic_read(&dev->changedWhileWriting)!=0) { + // *sigh,* something has changed. Let's do it again. + atomic_set(&dev->changedWhileWriting, 0); + sendFramebufferOver(dev->fbinfo); +// printk(KERN_INFO "Macusbfb: USB transfer complete but frame has changed!!\n"); + return; + } else { +// printk(KERN_INFO "Macusbfb: USB transfer complete! Image is perfect now.\n"); + } + + atomic_set(&dev->writeInProgress, 0); + + +// up(&dev->limit_sem); +} + + +static int createCmdStream(unsigned char* newbuff, unsigned char* oldbuff, unsigned char *data) { + int p=0; + int datalen=0; + int x,y; + int starting; //If we send data, will it be in a new packet? + int sizePos; //pos of size indicator of packet + int sizeCnt; //size of packet + int addr; + + for (y=0; y<342; y++) { + sizeCnt=0; + starting=1; + for (x=0; x<64; x++) { + if (newbuff[p]==oldbuff[p]) { + if (sizeCnt!=0) { + data[sizePos]=sizeCnt; + sizeCnt=0; + } + starting=1; + p++; + } else { + oldbuff[p]=newbuff[p]; + if (starting) { + addr=(y*64)+x; +// printk(KERN_INFO "%i\n", addr); + data[datalen++]=0xfa; + data[datalen++]=(addr>>8); + data[datalen++]=addr&0xff; + sizePos=datalen; + sizeCnt=0; + data[datalen++]=1; + starting=0; + } + data[datalen++]=newbuff[p++]; + sizeCnt++; + } + } + if (sizeCnt!=0) { + data[sizePos]=sizeCnt; + } + } + return datalen; +} + + +static void convert16to1bit(unsigned char* in, unsigned char* out) { + int x,y,p,tresh, val; + unsigned char *outp=out; + u16 *inp=(u16 *)in; + for (y=0; y<342; y++) { + for (x=0; x<512; x+=8) { + for (p=0; p<8; p++) { + //Tresh should start at 32 but seemingly my Xorg interprets + //the 565-mode I pass to it as 555... + tresh=16; + if (p&1) tresh-=8; + if (y&1) tresh+=4; + val=(((*inp)>>5)&0x3F); + *outp<<=1; + if (valpar; + unsigned char *buf=dev->xferbuff; + + + /* create a urb, and a buffer for it, and copy the data to the urb */ + usbreq = usb_alloc_urb(0, GFP_KERNEL); + if (!usbreq) { + printk(KERN_INFO "Macusbfb: Can't allocate urb!\n"); + goto err_no_buf; + } + + + convert16to1bit(dev->fb, dev->pixels); + count=createCmdStream(dev->pixels, dev->oldpixels, buf); + + /* initialize the urb properly */ + usbreq->transfer_dma=dev->xferbuffDmaAddr; + usb_fill_bulk_urb(usbreq, dev->udev, + usb_sndbulkpipe(dev->udev, 3), + buf, count, macusbfb_write_bulk_callback, dev); + usbreq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; + + usb_anchor_urb(usbreq, &dev->submitted); + + /* send the data out the bulk port */ + retval = usb_submit_urb(usbreq, GFP_KERNEL); + if (retval) { + err("macusbfb: failed submitting write urb, error %d", retval); + goto error_unanchor; + } + + /* release our reference to this urb, the USB core will eventually free it entirely */ + usb_free_urb(usbreq); + + return; + +error_unanchor: + usb_unanchor_urb(usbreq); + + usb_buffer_free(dev->udev, count, buf, usbreq->transfer_dma); + usb_free_urb(usbreq); +err_no_buf: +// up(&dev->limit_sem); + return; +} + +static void macusbfb_dpy_deferred_io(struct fb_info *info, struct list_head *pagelist) { + struct macusbfbdev *dev=info->par; + + if (atomic_read(&dev->writeInProgress)!=0) { +// printk(KERN_INFO "Macusbfb: Deferred io handler called but write still in progress!\n"); + atomic_set(&dev->changedWhileWriting, 1); + return; + } + atomic_set(&dev->writeInProgress, 1); + sendFramebufferOver(info); +} + +static void macusbfb_fillrect(struct fb_info *info, + const struct fb_fillrect *rect) +{ + struct macusbfbdev *dev = info->par; + return; + sys_fillrect(info, rect); + if (atomic_read(&dev->writeInProgress)!=0) { + atomic_set(&dev->changedWhileWriting, 1); + return; + } + atomic_set(&dev->writeInProgress, 1); + sendFramebufferOver(info); +} + +static void macusbfb_copyarea(struct fb_info *info, + const struct fb_copyarea *area) +{ + struct macusbfbdev *dev = info->par; + sys_copyarea(info, area); + if (atomic_read(&dev->writeInProgress)!=0) { + atomic_set(&dev->changedWhileWriting, 1); + return; + } + atomic_set(&dev->writeInProgress, 1); + sendFramebufferOver(info); +} + +static void macusbfb_imageblit(struct fb_info *info, + const struct fb_image *image) +{ + struct macusbfbdev *dev = info->par; + sys_imageblit(info, image); + if (atomic_read(&dev->writeInProgress)!=0) { + atomic_set(&dev->changedWhileWriting, 1); + return; + } + atomic_set(&dev->writeInProgress, 1); + sendFramebufferOver(info); +} + + +static struct fb_deferred_io macusbfb_defio = { + .delay = HZ/30, + .deferred_io = macusbfb_dpy_deferred_io, +}; + +static struct fb_ops macusbfb_fbops = { + .owner = THIS_MODULE, + .fb_read = fb_sys_read, + .fb_write = fb_sys_write, + .fb_fillrect = macusbfb_fillrect, + .fb_copyarea = macusbfb_copyarea, + .fb_imageblit = macusbfb_imageblit, +}; + + +#define MYDEV_ATTR_SIMPLE_UNSIGNED(name, gpiono) \ +static ssize_t show_attr_##name(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + struct usb_interface *intf = to_usb_interface(dev); \ + struct macusbfbdev *mydev = usb_get_intfdata(intf); \ + \ + return sprintf(buf, "%u\n", mydev->gpioVals&(1<udev->dev, "out of memory\n"); + return -1; + } + + if (val) dev->gpioVals|=(1<gpioVals&=!(1<udev, + usb_sndctrlpipe(dev->udev, 0), + 0x1, //1 -> modify gpio + 0x40, //vendor specific reqtype + val, + gpiono, + buffer, + 8, + 100); +} + +MYDEV_ATTR_SIMPLE_UNSIGNED(fan, 0); +MYDEV_ATTR_SIMPLE_UNSIGNED(display, 1); +MYDEV_ATTR_SIMPLE_UNSIGNED(fddeject, 2); +MYDEV_ATTR_SIMPLE_UNSIGNED(hdled, 3); + +static struct attribute *dev_attrs[] = { + &dev_attr_fan.attr, + &dev_attr_display.attr, + &dev_attr_fddeject.attr, + &dev_attr_hdled.attr, + NULL +}; + +static struct attribute_group dev_attr_grp = { + .attrs = dev_attrs, +}; + +static int macusbfb_probe(struct usb_interface *interface, const struct usb_device_id *id) { + struct usb_device *udev = interface_to_usbdev(interface); + struct macusbfbdev *dev = NULL; + int retval = -ENOMEM; + struct fb_info *info; + + dev = kzalloc(sizeof(struct macusbfbdev), GFP_KERNEL); + if (dev == NULL) { + dev_err(&interface->dev, "Out of memory\n"); + goto error_mem; + } + init_usb_anchor(&dev->submitted); + + //ToDo: oom handling + + dev->fb = vmalloc(roundup((MACFB_WIDTH*MACFB_HEIGHT)*2, PAGE_SIZE)); + if (!dev->fb) goto error_mem; + dev->pixels = vmalloc((MACFB_WIDTH*MACFB_HEIGHT)/8); + if (!dev->pixels) goto error_mem; + dev->oldpixels = vmalloc((MACFB_WIDTH*MACFB_HEIGHT)/8); + if (!dev->oldpixels) goto error_mem; + + dev->udev = usb_get_dev(udev); + usb_set_intfdata (interface, dev); + + //Allocate fb stuff + //The display is 1bit, but nothing is compatible with that so we'll emulate a 16-bit one. + info = framebuffer_alloc(sizeof(struct macusbfbdev*), NULL); + if (!info) goto error; + dev->xferbuff=usb_buffer_alloc(dev->udev, BUF_MAX_SIZE, GFP_KERNEL, &dev->xferbuffDmaAddr); + if (!dev->xferbuff) { + printk(KERN_INFO "Macusbfb: Error alloccing xfer buff!\n"); + goto error2; + } + + info->par=dev; + info->screen_base = (char __force __iomem *) dev->fb; + printk("Screen base = %x\n", (int)info->screen_base); + info->screen_size = MACFB_WIDTH*MACFB_HEIGHT*2; + info->fbops = &macusbfb_fbops; + info->fix = macusbfb_fbfix; + info->fix.smem_len=(MACFB_WIDTH*MACFB_HEIGHT)*2; + info->var = macusbfb_fbvar; + info->pseudo_palette = NULL; + info->flags = FBINFO_FLAG_DEFAULT|FBINFO_VIRTFB; + + //Init deferred IO + info->fbdefio = &macusbfb_defio; + fb_deferred_io_init(info); + +//Klont?!? + dev->fbinfo=info; + atomic_set(&dev->writeInProgress, 0); + atomic_set(&dev->changedWhileWriting, 0); + + if (sysfs_create_group(&interface->dev.kobj, &dev_attr_grp)) goto error; + + if (register_framebuffer(info) < 0) goto fberr; + printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, info->fix.id); + dev_info(&interface->dev, "MacUsbFb device now attached\n"); + + + + return 0; +//ToDo: look more closely at this: this doesn;t free everything. +fberr: + framebuffer_release(info); + printk(KERN_INFO "Macusbfb: Error initing fb!\n"); + +error2: + +error: + printk(KERN_INFO "Macusbfb: Error initing!\n"); + usb_set_intfdata (interface, NULL); + usb_put_dev(dev->udev); + kfree(dev); +error_mem: + printk(KERN_INFO "Macusbfb: Couldn't allocate framebuffer or usb memory!\n"); + return retval; +} + +static void macusbfb_disconnect(struct usb_interface *interface) +{ +//ToDo: _Really_ clean everything up! + struct macusbfbdev *dev; + struct fb_info *info; + + dev = usb_get_intfdata (interface); + info=dev->fbinfo; + + if (info) { + fb_deferred_io_cleanup(info); + unregister_framebuffer(info); + framebuffer_release(info); + } + + sysfs_remove_group(&interface->dev.kobj, &dev_attr_grp); + + /* first remove the files, then set the pointer to NULL */ + usb_set_intfdata (interface, NULL); + + usb_put_dev(dev->udev); + + kfree(dev); + + dev_info(&interface->dev, "MacUsbFb now disconnected\n"); +} + +static struct usb_driver macusbfb_driver = { + .name = "macusbfb", + .probe = macusbfb_probe, + .disconnect = macusbfb_disconnect, + .id_table = id_table, +}; + +static int __init macusbfb_init(void) +{ + int retval = 0; + + retval = usb_register(&macusbfb_driver); + if (retval) + err("usb_register failed. Error number %d", retval); + return retval; +} + +static void __exit macusbfb_exit(void) +{ + usb_deregister(&macusbfb_driver); +} + +module_init (macusbfb_init); +module_exit (macusbfb_exit); + +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); diff --git a/kernel_driver/test.sh b/kernel_driver/test.sh new file mode 100755 index 0000000..998c976 --- /dev/null +++ b/kernel_driver/test.sh @@ -0,0 +1,13 @@ +set -e +sudo rmmod macusbfb || true +sudo rmmod fb || true +sudo rm -f /lib/modules/2.6.34/extra/macusbfb.ko +sudo make clean install +sudo modprobe macusbfb +sleep 2 +#echo bla | sudo tee /dev/fb0 +#sudo Xfbdev :1 +sudo test/test +sudo modprobe snd-usb-audio +mplayer -vo fbdev -zoom -fs -vf scale ~/server/film/Bastian\ -\ You\ got\ my\ love.avi -ao alsa:device=hw=1 +dmesg | tail \ No newline at end of file diff --git a/kernel_driver/test/Makefile b/kernel_driver/test/Makefile new file mode 100644 index 0000000..2948b3c --- /dev/null +++ b/kernel_driver/test/Makefile @@ -0,0 +1,4 @@ +CFLAGS=-g + +test: test.o + gcc -o test test.o \ No newline at end of file diff --git a/kernel_driver/test/bdc.xbm b/kernel_driver/test/bdc.xbm new file mode 100644 index 0000000..ffadcd0 --- /dev/null +++ b/kernel_driver/test/bdc.xbm @@ -0,0 +1,1828 @@ +#define bdc_width 512 +#define b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, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x80, 0x13, 0x10, 0xFA, 0x33, + 0x38, 0xFF, 0x8F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, + 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x11, 0xC1, 0x98, 0x97, 0x5D, 0x61, 0xC8, 0xF7, 0xCD, 0xFC, 0xF2, + 0xEE, 0xF5, 0xCB, 0xF0, 0xDF, 0xFF, 0xFE, 0xFF, 0xA7, 0x2B, 0xFF, 0xFF, + 0xFF, 0xFF, 0xF7, 0xFD, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, + 0x1E, 0x13, 0x02, 0x0C, 0x60, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x19, 0x15, 0xC6, 0x7F, 0x7F, 0x84, 0x37, + 0x8F, 0x7F, 0xFA, 0x8B, 0xBB, 0xF7, 0xDF, 0xFC, 0xFF, 0xFE, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFD, 0xE7, 0xFF, 0xFB, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, + 0x00, 0x06, 0xFE, 0x1F, 0x8C, 0x13, 0x04, 0x06, 0xC0, 0x01, 0x78, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x7F, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x31, 0x21, 0x61, + 0x3F, 0x7B, 0x99, 0x9A, 0xD8, 0xB6, 0xFB, 0xED, 0xBB, 0xF3, 0x4F, 0x8B, + 0xD9, 0xBF, 0xFF, 0xFF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xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x63, 0x20, 0x32, 0x02, + 0xB2, 0xBA, 0x08, 0x38, 0x1C, 0x9A, 0xB9, 0xBA, 0x7A, 0xDB, 0xDB, 0xDB, + 0x9F, 0xDF, 0xBB, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; diff --git a/kernel_driver/test/test b/kernel_driver/test/test new file mode 100755 index 0000000..98eb4a9 Binary files /dev/null and b/kernel_driver/test/test differ diff --git a/kernel_driver/test/test.c b/kernel_driver/test/test.c new file mode 100644 index 0000000..b2d1d53 --- /dev/null +++ b/kernel_driver/test/test.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include + +#define SIZE (512*342*3) + +#include "bdc.xbm" + +int main(int argc, char** argv) { + char *fb; + char *fbp; + char n; + int x; + int p; + int fd=open("/dev/fb0", O_RDWR); + if (fd<0) perror("opening fb"); + fb=mmap(NULL, SIZE, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0); + if (fb==MAP_FAILED) { + perror("Mmap failed"); + exit(0); + } + fbp=fb; + for (x=0; x<((512*342)/8); x++) { + for (p=0; p<8; p++) { + if (bdc_bits[x]&(1< + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/macusbfb/Makefile b/macusbfb/Makefile new file mode 100644 index 0000000..ec8ddc0 --- /dev/null +++ b/macusbfb/Makefile @@ -0,0 +1,95 @@ +########################################################################## +# User configuration and firmware specific object files +########################################################################## + +# The target, flash and ram of the LPC1xxx microprocessor. +# Use for the target the value: LPC11xx, LPC13xx or LPC17xx +TARGET = LPC13xx +FLASH = 32K +SRAM = 8K + +# For USB support the LPC1xxx reserves 384 bytes from the sram, +# if you don't want to use the USB features, just use 0 here. +SRAM_USB = 384 + +VPATH = +OBJS = main.o debug.o font_8x8.o usb.o + +########################################################################## +# Library files +########################################################################## +VPATH += core core/cpu +VPATH += core/systick +VPATH += core/libc core/wdt +OBJS += cpu.o systick.o +OBJS += stdio.o string.o +OBJS += sysinit.o + +########################################################################## +# GNU GCC compiler prefix and location +########################################################################## +CROSS_COMPILE = arm-elf- +AS = $(CROSS_COMPILE)gcc +CC = $(CROSS_COMPILE)gcc +LD = $(CROSS_COMPILE)gcc +SIZE = $(CROSS_COMPILE)size +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump +OUTFILE = firmware + +########################################################################## +# Startup files +########################################################################## + +LD_PATH = lpc1xxx +LD_SCRIPT = $(LD_PATH)/linkscript.ld +LD_TEMP = $(LD_PATH)/memory.ld + +ifeq (LPC11xx,$(TARGET)) + CORTEX_TYPE=m0 +else + CORTEX_TYPE=m3 +endif + +CPU_TYPE = cortex-$(CORTEX_TYPE) +VPATH += lpc1xxx +OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o + +########################################################################## +# Compiler settings, parameters and flags +########################################################################## +# +CFLAGS = -c -Os -I. -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -fno-builtin -g +ASFLAGS = -c -Os -I. -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -D__ASSEMBLY__ -x assembler-with-cpp -g +LDFLAGS = -Wl,--gc-sections -mthumb -g +OCFLAGS = --strip-unneeded + +all: firmware + ../checksum/checksum firmware.bin +#Enable this to write to the firmware to the lpc. Change sdx in wherever your lpc +#shows up. +# sudo rmmod macusbfb || true +# while [ ! -e /dev/sdx ]; do sleep 1; done; sudo mcopy -o -i /dev/sdx firmware.bin ::/; sudo blockdev --flushbufs /dev/sdx + +%.o : %.c + $(CC) $(CFLAGS) -o $@ $< + +%.o : %.s + $(AS) $(ASFLAGS) -o $@ $< + +firmware: $(OBJS) $(SYS_OBJS) + -@echo "MEMORY" > $(LD_TEMP) + -@echo "{" >> $(LD_TEMP) + -@echo " flash(rx): ORIGIN = 0x00000000, LENGTH = $(FLASH)" >> $(LD_TEMP) + -@echo " sram(rwx): ORIGIN = 0x10000000+$(SRAM_USB), LENGTH = $(SRAM)-$(SRAM_USB)" >> $(LD_TEMP) + -@echo "}" >> $(LD_TEMP) + -@echo "INCLUDE $(LD_SCRIPT)" >> $(LD_TEMP) + $(LD) $(LDFLAGS) -T $(LD_TEMP) -o $(OUTFILE).elf $(OBJS) + -@echo "" + $(SIZE) $(OUTFILE).elf + -@echo "" + $(OBJCOPY) $(OCFLAGS) -O binary $(OUTFILE).elf $(OUTFILE).bin + $(OBJCOPY) $(OCFLAGS) -O ihex $(OUTFILE).elf $(OUTFILE).hex + +clean: + rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex diff --git a/macusbfb/asm_routines.s b/macusbfb/asm_routines.s new file mode 100644 index 0000000..234faa1 --- /dev/null +++ b/macusbfb/asm_routines.s @@ -0,0 +1,41 @@ + .syntax unified + .cpu cortex-m3 + .fpu softvfp + .section ".text" + .thumb + + .global _start + .type _start, %function +_start: + +/* fill .bss with 0 using byte stores */ + ldr r0, =_bss + ldr r1, =_ebss + mov r2, #0 +.L0: + strb r2, [r0], #1 + cmp r0, r1 + bcc.n .L0 + +/* copy initialized .data from rom to ram */ + ldr r0, =_data + ldr r1, =_edata + ldr r2, =_ldata +.L1: + ldrb r3, [r2], #1 + strb r3, [r0], #1 + cmp r0, r1 + bcc.n .L1 + +/* branch to main */ + ldr r0, =main+1 + bx r0 + .size _start, .-_start + + + .section ".CRP._0x02FC","a",%progbits + .globl CRP_Key +CRP_Key: + .word 0xFFFFFFFF + + .end diff --git a/macusbfb/build/codelite/LPC1343 Workspace.tags b/macusbfb/build/codelite/LPC1343 Workspace.tags new file mode 100644 index 0000000..97df34d Binary files /dev/null and b/macusbfb/build/codelite/LPC1343 Workspace.tags differ diff --git a/macusbfb/build/codelite/LPC1343 Workspace.workspace b/macusbfb/build/codelite/LPC1343 Workspace.workspace new file mode 100644 index 0000000..f676a7d --- /dev/null +++ b/macusbfb/build/codelite/LPC1343 Workspace.workspace @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/macusbfb/build/codelite/LPC1343 Workspace.workspace.session b/macusbfb/build/codelite/LPC1343 Workspace.workspace.session new file mode 100644 index 0000000..6efcc9f --- /dev/null +++ b/macusbfb/build/codelite/LPC1343 Workspace.workspace.session @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macusbfb/build/codelite/LPC1343_CodeBase.project b/macusbfb/build/codelite/LPC1343_CodeBase.project new file mode 100644 index 0000000..f2d1f28 --- /dev/null +++ b/macusbfb/build/codelite/LPC1343_CodeBase.project @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # Make sure that we are using SWD +monitor interface SWD +# Set monitor speed +monitor speed 1000 +# Set device ID to LPC1343 +monitor flash device = LPC1343 +# Set monitor to little endian +monitor endian little +# Enable flash download +monitor flash download = 1 + +# Transfer the firmware to the device +load "../../firmware.elf" + +# Reset device and start execution +monitor reset + + + + + lpcrc firmware.bin + + + + make clean + make + + + + None + $(WorkspacePath)/../../ + + + + + + + + + + + + + + + + + + + + + + make clean + make + + + + None + $(WorkspacePath) + + + + + + + + + + + + + + + + + diff --git a/macusbfb/build/codelite/tags b/macusbfb/build/codelite/tags new file mode 100644 index 0000000..e8976b0 --- /dev/null +++ b/macusbfb/build/codelite/tags @@ -0,0 +1,4 @@ +rx_data C:\Documents and Settings\Kevin\My Documents\My Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase\main.c /^static chb_rx_data_t rx_data;$/;" variable line:66 +main C:\Documents and Settings\Kevin\My Documents\My Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase\main.c /^int main (void)$/;" function line:70 signature:(void) returns:int +__putchar C:\Documents and Settings\Kevin\My Documents\My Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase\main.c /^void __putchar(char c) $/;" function line:186 signature:(char c) returns:void +puts C:\Documents and Settings\Kevin\My Documents\My Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase\main.c /^int puts ( const char * str )$/;" function line:191 signature:( const char * str ) returns:int diff --git a/macusbfb/build/crossworks/LPC1343_CodeBase.hzp b/macusbfb/build/crossworks/LPC1343_CodeBase.hzp new file mode 100644 index 0000000..a8941d4 --- /dev/null +++ b/macusbfb/build/crossworks/LPC1343_CodeBase.hzp @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macusbfb/build/crossworks/LPC1343_CodeBase.hzs b/macusbfb/build/crossworks/LPC1343_CodeBase.hzs new file mode 100644 index 0000000..e2b2073 --- /dev/null +++ b/macusbfb/build/crossworks/LPC1343_CodeBase.hzs @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macusbfb/build/crossworks/flash_placement.xml b/macusbfb/build/crossworks/flash_placement.xml new file mode 100644 index 0000000..963e460 --- /dev/null +++ b/macusbfb/build/crossworks/flash_placement.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macusbfb/checksum/Makefile b/macusbfb/checksum/Makefile new file mode 100644 index 0000000..b859c2b --- /dev/null +++ b/macusbfb/checksum/Makefile @@ -0,0 +1,3 @@ + +checksum: main.o + gcc -o checksum main.o \ No newline at end of file diff --git a/macusbfb/checksum/main.c b/macusbfb/checksum/main.c new file mode 100644 index 0000000..ac2dbe8 --- /dev/null +++ b/macusbfb/checksum/main.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) { + int fd; + unsigned char* file; + int i; + unsigned long ivt_CRC; + + if (argc!=2) { + printf("Usage: %s file.bin\n"); + exit(0); + } + + fd=open(argv[1], O_RDWR); + if (fd<0) { + perror("opening file"); + exit(1); + } + file=(char*)mmap(NULL, 1024, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0); + if (file==(unsigned char*)-1) { + perror("mmap"); + exit(1); + } + + ivt_CRC = 0; + /* Calculate a native checksum of the little endian vector table: */ + for(i = 0; i < (7*4);) { + ivt_CRC += file[i++]; + ivt_CRC += file[i++] << 8; + ivt_CRC += file[i++] << 16; + ivt_CRC += file[i++] << 24; + } + /* Negate the result and place in the vector at 0x14 as little endian + * again. The resulting vector table should checksum to 0. */ + ivt_CRC = (unsigned long)-ivt_CRC; + for(i = 0; i < 4; i++) { + file[i + (7*4)] = (unsigned char)(ivt_CRC >> (8 * i)); + } + + + /* Check checksum: */ + ivt_CRC = 0; + for(i = 0; i < (0x20);) { + ivt_CRC += file[i++]; + ivt_CRC += file[i++] << 8; + ivt_CRC += file[i++] << 16; + ivt_CRC += file[i++] << 24; + } + printf("Checksum over vector table now is %lu.\n",ivt_CRC); + + + munmap(file, 1024); + close(fd); +} + diff --git a/macusbfb/core/adc/adc.c b/macusbfb/core/adc/adc.c new file mode 100644 index 0000000..d6e5afb --- /dev/null +++ b/macusbfb/core/adc/adc.c @@ -0,0 +1,188 @@ +/**************************************************************************/ +/*! + @file adc.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section Description + + SW-based single-channel A/D conversion. If you wish to convert + multiple ADC channels simultaneously, this code will need to be + modified to work in BURST mode. + + @section Example + + @code + #include "core/cpu/cpu.h" + #include "core/adc/adc.h" + + void main (void) + { + cpuInit(); + adcInit(); + + uint32_t results = 0; + while(1) + { + // Get A/D conversion results from A/D channel 0 + results = adcRead(0); + } + } + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + */ +/**************************************************************************/ + +#include "adc.h" + +/**************************************************************************/ +/*! + @brief Returns the conversion results on the specified ADC channel. + + This function will manually start an A/D conversion on a single + channel and return the results. + + @param[in] channelNum + The A/D channel [0..7] that will be used during the A/D + conversion. (Note that only A/D channel's 0..3 are + configured by default in adcInit.) + + @return 0 if an overrun error occured, otherwise a 10-bit value + containing the A/D conversion results. + @warning Only AD channels 0..3 are configured for A/D in adcInit. + If you wish to use A/D pins 4..7 they will also need to + be added to the adcInit function. +*/ +/**************************************************************************/ +uint32_t adcRead (uint8_t channelNum) +{ + uint32_t regVal, adcData; + + /* make sure that channel number is 0..7 */ + if ( channelNum >= 8 ) + { + // ToDo: Change this to throw an exception back + channelNum = 0; + } + + /* deselect all channels */ + ADC_AD0CR &= ~ADC_AD0CR_SEL_MASK; + + /* switch channel and start converting */ + ADC_AD0CR |= (ADC_AD0CR_START_STARTNOW | (1 << channelNum)); + + /* wait until end of A/D convert */ + while ( 1 ) + { + // Get data register results for the requested channel + regVal = (*(pREG32(ADC_AD0DR0))); // + (4 * channelNum); + + /* read result of A/D conversion */ + if (regVal & ADC_DR_DONE) + { + break; + } + } + + /* stop ADC */ + ADC_AD0CR &= ~ADC_AD0CR_START_MASK; + + /* return 0 if an overrun occurred */ + if ( regVal & ADC_DR_OVERRUN ) + { + return (0); + } + + /* return conversion results */ + adcData = (regVal >> 6) & 0x3FF; + return (adcData); +} + +/**************************************************************************/ +/*! + @brief Initialises the A/D converter and configures channels 0..3 + for 10-bit, SW-controlled A/D conversion. + + @return Nothing +*/ +/**************************************************************************/ +void adcInit (void) +{ + /* Disable Power down bit to the ADC block. */ + SCB_PDRUNCFG &= ~(SCB_PDRUNCFG_ADC); + + /* Enable AHB clock to the ADC. */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_ADC); + + /* Digital pins need to have the 'analog' bit set in addition + to changing their pin function */ + + /* Set AD0 to analog input */ + IOCON_JTAG_TDI_PIO0_11 &= ~(IOCON_JTAG_TDI_PIO0_11_ADMODE_MASK | + IOCON_JTAG_TDI_PIO0_11_FUNC_MASK | + IOCON_JTAG_TDI_PIO0_11_MODE_MASK); + IOCON_JTAG_TDI_PIO0_11 |= (IOCON_JTAG_TDI_PIO0_11_FUNC_AD0 & + IOCON_JTAG_TDI_PIO0_11_ADMODE_ANALOG); + + /* Set AD1 to analog input */ + IOCON_JTAG_TMS_PIO1_0 &= ~(IOCON_JTAG_TMS_PIO1_0_ADMODE_MASK | + IOCON_JTAG_TMS_PIO1_0_FUNC_MASK | + IOCON_JTAG_TMS_PIO1_0_MODE_MASK); + IOCON_JTAG_TMS_PIO1_0 |= (IOCON_JTAG_TMS_PIO1_0_FUNC_AD1 & + IOCON_JTAG_TMS_PIO1_0_ADMODE_ANALOG); + + /* Set AD2 to analog input */ + IOCON_JTAG_TDO_PIO1_1 &= ~(IOCON_JTAG_TDO_PIO1_1_ADMODE_MASK | + IOCON_JTAG_TDO_PIO1_1_FUNC_MASK | + IOCON_JTAG_TDO_PIO1_1_MODE_MASK); + IOCON_JTAG_TDO_PIO1_1 |= (IOCON_JTAG_TDO_PIO1_1_FUNC_AD2 & + IOCON_JTAG_TDO_PIO1_1_ADMODE_ANALOG); + + /* Set AD3 to analog input */ + IOCON_JTAG_nTRST_PIO1_2 &= ~(IOCON_JTAG_nTRST_PIO1_2_ADMODE_MASK | + IOCON_JTAG_nTRST_PIO1_2_FUNC_MASK | + IOCON_JTAG_nTRST_PIO1_2_MODE_MASK); + IOCON_JTAG_nTRST_PIO1_2 |= (IOCON_JTAG_nTRST_PIO1_2_FUNC_AD3 & + IOCON_JTAG_nTRST_PIO1_2_ADMODE_ANALOG); + + /* Note that in SW mode only one channel can be selected at a time (AD0 in this case) + To select multiple channels, ADC_AD0CR_BURST_HWSCANMODE must be used */ + ADC_AD0CR = (ADC_AD0CR_SEL_AD0 | /* SEL=1,select channel 0 on ADC0 */ + (((CFG_CPU_CCLK / SCB_SYSAHBCLKDIV) / 1000000 - 1 ) << 8) | /* CLKDIV = Fpclk / 1000000 - 1 */ + ADC_AD0CR_BURST_SWMODE | /* BURST = 0, no BURST, software controlled */ + ADC_AD0CR_CLKS_10BITS | /* CLKS = 0, 11 clocks/10 bits */ + ADC_AD0CR_START_NOSTART | /* START = 0 A/D conversion stops */ + ADC_AD0CR_EDGE_RISING); /* EDGE = 0 (CAP/MAT signal falling, trigger A/D conversion) */ + + return; +} diff --git a/macusbfb/core/adc/adc.h b/macusbfb/core/adc/adc.h new file mode 100644 index 0000000..e2588a9 --- /dev/null +++ b/macusbfb/core/adc/adc.h @@ -0,0 +1,47 @@ +/**************************************************************************/ +/*! + @file adc.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/**************************************************************************/ + +#ifndef _ADC_H_ +#define _ADC_H_ + +#include "projectconfig.h" + +uint32_t adcRead (uint8_t channelNum); +void adcInit (void); + +#endif diff --git a/macusbfb/core/cmd/cmd.c b/macusbfb/core/cmd/cmd.c new file mode 100644 index 0000000..3685bb1 --- /dev/null +++ b/macusbfb/core/cmd/cmd.c @@ -0,0 +1,260 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. +*******************************************************************/ + +/**************************************************************************/ +/*! + @file cmd.c + @author Christopher Wang (Freaklabs) + Modified by: K. Townsend (microBuilder.eu) + @date 19 May 2010 + + Original code taken from the FreakUSB Open Source USB Device Stack + http://freaklabs.org/index.php/FreakUSB-Open-Source-USB-Device-Stack.html + + If it works well, you can thank Akiba at Freaklabs. If it fails + miserably, you can blame me (since parts of it it were rather + ungraciously modified). :-) + +*/ +/**************************************************************************/ + +#include +#include + +#include "cmd.h" +#include "cmd_tbl.h" + +#ifdef CFG_PRINTF_UART +#include "core/uart/uart.h" +#endif + +#ifdef CFG_PRINTF_USBCDC + #include "core/usbcdc/cdcuser.h" + static char usbcdcBuf [32]; +#endif + +static uint8_t msg[CFG_INTERFACE_MAXMSGSIZE]; +static uint8_t *msg_ptr; + +/**************************************************************************/ +/*! + @brief Polls the relevant incoming message queue to see if anything + is waiting to be processed. +*/ +/**************************************************************************/ +void cmdPoll() +{ + #if defined CFG_PRINTF_UART + while (uartRxBufferDataPending()) + { + uint8_t c = uartRxBufferRead(); + cmdRx(c); + } + #endif + + #if defined CFG_PRINTF_USBCDC + int numBytesToRead, numBytesRead, numAvailByte; + + CDC_OutBufAvailChar (&numAvailByte); + if (numAvailByte > 0) + { + numBytesToRead = numAvailByte > 32 ? 32 : numAvailByte; + numBytesRead = CDC_RdOutBuf (&usbcdcBuf[0], &numBytesToRead); + int i; + for (i = numBytesToRead; i > 0; --i) + { + cmdRx(usbcdcBuf[i-1]); + } + } + #endif +} + +/**************************************************************************/ +/*! + @brief Handles a single incoming character. If a new line is + detected, the entire command will be passed to the command + parser. If a text character is detected, it will be added to + the message buffer until a new line is detected (up to the + maximum queue size, CFG_INTERFACE_MAXMSGSIZE). + + @param[in] c + The character to parse. +*/ +/**************************************************************************/ +void cmdRx(uint8_t c) +{ + // read out the data in the buffer and echo it back to the host. + switch (c) + { + case '\r': + case '\n': + // terminate the msg and reset the msg ptr. then send + // it to the handler for processing. + *msg_ptr = '\0'; + printf("%s", CFG_INTERFACE_NEWLINE); + cmdParse((char *)msg); + msg_ptr = msg; + break; + + case '\b': + printf("%c",c); + if (msg_ptr > msg) + { + msg_ptr--; + } + break; + + default: + printf("%c",c); + *msg_ptr++ = c; + break; + } +} + +/**************************************************************************/ +/*! + @brief Displays the command prompt. The text that appears is defined + in projectconfig.h. +*/ +/**************************************************************************/ +static void cmdMenu() +{ + printf(CFG_INTERFACE_NEWLINE); + printf(CFG_INTERFACE_PROMPT); +} + +/**************************************************************************/ +/*! + @brief Parse the command line. This function tokenizes the command + input, then searches for the command table entry associated + with the commmand. Once found, it will jump to the + corresponding function. + + @param[in] cmd + The entire command string to be parsed +*/ +/**************************************************************************/ +void cmdParse(char *cmd) +{ + size_t argc, i = 0; + char *argv[30]; + + argv[i] = strtok(cmd, " "); + do + { + argv[++i] = strtok(NULL, " "); + } while ((i < 30) && (argv[i] != NULL)); + + argc = i; + for (i=0; i < CMD_COUNT; i++) + { + if (!strcmp(argv[0], cmd_tbl[i].command)) + { + if ((argc == 2) && !strcmp (argv [1], "?")) + { + // Display paramter help menu on 'command ?' + printf ("%s%s%s", cmd_tbl[i].description, CFG_INTERFACE_NEWLINE, CFG_INTERFACE_NEWLINE); + printf ("%s%s", cmd_tbl[i].parameters, CFG_INTERFACE_NEWLINE); + } + else if ((argc - 1) < cmd_tbl[i].minArgs) + { + // Too few arguments supplied + printf ("Too few arguments to command (%d expected)%s", cmd_tbl[i].minArgs, CFG_INTERFACE_NEWLINE); + } + else if ((argc - 1) > cmd_tbl[i].maxArgs) + { + // Too many arguments supplied + printf ("Too many arguments to command (%d maximum)%s", cmd_tbl[i].maxArgs, CFG_INTERFACE_NEWLINE); + } + else + { + // Dispatch command to the appropriate function + cmd_tbl[i].func(argc - 1, &argv [1]); + } + + // Refresh the command prompt + cmdMenu(); + return; + } + } + printf("Command not recognized: '%s'%s", cmd, CFG_INTERFACE_NEWLINE); + + cmdMenu(); +} + +/**************************************************************************/ +/*! + @brief Initialises the command line using the appropriate interface +*/ +/**************************************************************************/ +void cmdInit() +{ + #if defined CFG_INTERFACE && defined CFG_INTERFACE_UART + // Check if UART is already initialised + uart_pcb_t *pcb = uartGetPCB(); + if (!pcb->initialised) + { + uartInit(CFG_UART_BAUDRATE); + } + #endif + + // init the msg ptr + msg_ptr = msg; + + // Show the menu + cmdMenu(); +} + +/**************************************************************************/ +/*! + 'help' command handler +*/ +/**************************************************************************/ +void cmd_help(uint8_t argc, char **argv) +{ + size_t i; + + printf("Command Description%s", CFG_INTERFACE_NEWLINE); + printf("------- -----------%s", CFG_INTERFACE_NEWLINE); + + // Display full command list + for (i=0; i < CMD_COUNT; i++) + { + if (!cmd_tbl[i].hidden) + { + printf ("%-20s %s%s", cmd_tbl[i].command, cmd_tbl[i].description, CFG_INTERFACE_NEWLINE); + } + } + + printf("%sCommand parameters can be seen by entering: ?%s", CFG_INTERFACE_NEWLINE, CFG_INTERFACE_NEWLINE); +} diff --git a/macusbfb/core/cmd/cmd.h b/macusbfb/core/cmd/cmd.h new file mode 100644 index 0000000..b16a1e3 --- /dev/null +++ b/macusbfb/core/cmd/cmd.h @@ -0,0 +1,60 @@ +/**************************************************************************/ +/*! + @file cmd.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef __CMD_H__ +#define __CMD_H__ + +#include "projectconfig.h" + +typedef struct +{ + char *command; + uint8_t minArgs; + uint8_t maxArgs; + uint8_t hidden; + void (*func)(uint8_t argc, char **argv); + const char *description; + const char *parameters; +} cmd_t; + +void cmdPoll(); +void cmdRx(uint8_t c); +void cmdParse(char *cmd); +void cmdInit(); + +#endif \ No newline at end of file diff --git a/macusbfb/core/cpu/cpu.c b/macusbfb/core/cpu/cpu.c new file mode 100644 index 0000000..a9db00c --- /dev/null +++ b/macusbfb/core/cpu/cpu.c @@ -0,0 +1,191 @@ +/**************************************************************************/ +/*! + @file cpu.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Initialises the CPU and any core clocks. By default, the core clock + is set to run at 72MHz. In order to reduce power consumption all pins + are set to GPIO and input by cpuInit. + + @section EXAMPLE + @code + #include "lpc134x.h" + #include "core/cpu/cpu.h" + + int main (void) + { + // Initialise the CPU and setup the PLL + cpuInit(); + + while(1) + { + } + } + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "cpu.h" +#include "core/gpio/gpio.h" + +/**************************************************************************/ +/*! + @brief Configures the main clock/PLL + + The speed at which the MCU operates is set here using the SCB_PLLCTRL + register, and the SCB_PLLCLKSEL register can be used to select which + oscillator to use to generate the system clocks (the internal 12MHz + oscillator or an external crystal). + + @param[in] multiplier + The PLL multiplier + +*/ +/**************************************************************************/ +void cpuPllSetup (cpuMultiplier_t multiplier) +{ + uint32_t i; + + // Power up system oscillator + SCB_PDRUNCFG &= ~(SCB_PDRUNCFG_SYSOSC_MASK); + + // Setup the crystal input (bypass disabled, 1-20MHz crystal) + SCB_SYSOSCCTRL = (SCB_SYSOSCCTRL_BYPASS_DISABLED | SCB_SYSOSCCTRL_FREQRANGE_1TO20MHZ); + + for (i = 0; i < 200; i++) + { + __asm volatile ("NOP"); + } + + // Configure PLL + SCB_PLLCLKSEL = SCB_CLKSEL_SOURCE_MAINOSC; // Select external crystal as PLL clock source + SCB_PLLCLKUEN = SCB_PLLCLKUEN_UPDATE; // Update clock source + SCB_PLLCLKUEN = SCB_PLLCLKUEN_DISABLE; // Toggle update register once + SCB_PLLCLKUEN = SCB_PLLCLKUEN_UPDATE; // Update clock source again + + // Wait until the clock is updated + while (!(SCB_PLLCLKUEN & SCB_PLLCLKUEN_UPDATE)); + + // Set clock speed + switch (multiplier) + { + case CPU_MULTIPLIER_2: + SCB_PLLCTRL = (SCB_PLLCTRL_MULT_2 | (1 << SCB_PLLCTRL_DIV_BIT)); + break; + case CPU_MULTIPLIER_3: + SCB_PLLCTRL = (SCB_PLLCTRL_MULT_3 | (1 << SCB_PLLCTRL_DIV_BIT)); + break; + case CPU_MULTIPLIER_4: + SCB_PLLCTRL = (SCB_PLLCTRL_MULT_4 | (1 << SCB_PLLCTRL_DIV_BIT)); + break; + case CPU_MULTIPLIER_5: + SCB_PLLCTRL = (SCB_PLLCTRL_MULT_5 | (1 << SCB_PLLCTRL_DIV_BIT)); + break; + case CPU_MULTIPLIER_6: + SCB_PLLCTRL = (SCB_PLLCTRL_MULT_6 | (1 << SCB_PLLCTRL_DIV_BIT)); + break; + case CPU_MULTIPLIER_1: + default: + SCB_PLLCTRL = (SCB_PLLCTRL_MULT_1 | (1 << SCB_PLLCTRL_DIV_BIT)); + break; + } + + // Enable system PLL + SCB_PDRUNCFG &= ~(SCB_PDRUNCFG_SYSPLL_MASK); + + // Wait for PLL to lock + while (!(SCB_PLLSTAT & SCB_PLLSTAT_LOCK)); + + // Setup main clock (use PLL output) + SCB_MAINCLKSEL = SCB_MAINCLKSEL_SOURCE_SYSPLLCLKOUT; + SCB_MAINCLKUEN = SCB_MAINCLKUEN_UPDATE; // Update clock source + SCB_MAINCLKUEN = SCB_MAINCLKUEN_DISABLE; // Toggle update register once + SCB_MAINCLKUEN = SCB_MAINCLKUEN_UPDATE; + + // Wait until the clock is updated + while (!(SCB_MAINCLKUEN & SCB_MAINCLKUEN_UPDATE)); + + // Disable USB clock by default (enabled in USB code) + SCB_PDRUNCFG |= (SCB_PDSLEEPCFG_USBPAD_PD); // Power-down USB PHY + SCB_PDRUNCFG |= (SCB_PDSLEEPCFG_USBPLL_PD); // Power-down USB PLL + + // Set system AHB clock + SCB_SYSAHBCLKDIV = SCB_SYSAHBCLKDIV_DIV1; + + // Enabled IOCON clock for I/O related peripherals + SCB_SYSAHBCLKCTRL |= SCB_SYSAHBCLKCTRL_IOCON; +} + +/**************************************************************************/ +/*! + @brief Initialises the CPU, setting up the PLL, etc. +*/ +/**************************************************************************/ +void cpuInit (void) +{ + + // Set all GPIO pins to input by default + GPIO_GPIO0DIR &= ~(GPIO_IO_ALL); + GPIO_GPIO1DIR &= ~(GPIO_IO_ALL); + GPIO_GPIO2DIR &= ~(GPIO_IO_ALL); + GPIO_GPIO3DIR &= ~(GPIO_IO_ALL); + + // Setup PLL (etc.) + cpuPllSetup(CPU_MULTIPLIER_6); +} + +/**************************************************************************/ +/*! + @brief Get's the CPU Device ID +*/ +/**************************************************************************/ +cpuDeviceID_t cpuGetDeviceID (void) +{ + switch (SCB_DEVICEID) + { + case (SCB_DEVICEID_LPC1311FHN33): + return cpuDeviceID_LPC1311; + case (SCB_DEVICEID_LPC1313FHN33): + return cpuDeviceID_LPC1313; + case (SCB_DEVICEID_LPC1342FHN33): + return cpuDeviceID_LPC1342; + case (SCB_DEVICEID_LPC1343FHN33): + return cpuDeviceID_LPC1343; + default: + return cpuDeviceID_Unknown; + } + return cpuDeviceID_Unknown; +} diff --git a/macusbfb/core/cpu/cpu.h b/macusbfb/core/cpu/cpu.h new file mode 100644 index 0000000..fbb764d --- /dev/null +++ b/macusbfb/core/cpu/cpu.h @@ -0,0 +1,79 @@ +/**************************************************************************/ +/*! + @file cpu.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _CPU_H_ +#define _CPU_H_ + +#include "projectconfig.h" + +/**************************************************************************/ +/*! + @brief Indicates the value for the PLL multiplier +*/ +/**************************************************************************/ +typedef enum +{ + CPU_MULTIPLIER_1 = 0, + CPU_MULTIPLIER_2, + CPU_MULTIPLIER_3, + CPU_MULTIPLIER_4, + CPU_MULTIPLIER_5, + CPU_MULTIPLIER_6 +} +cpuMultiplier_t; + +/**************************************************************************/ +/*! + @brief Indicates the value returned by the DEVICEID register +*/ +/**************************************************************************/ +typedef enum +{ + cpuDeviceID_Unknown = 0, + cpuDeviceID_LPC1311, + cpuDeviceID_LPC1313, + cpuDeviceID_LPC1342, + cpuDeviceID_LPC1343 +} +cpuDeviceID_t; + +void cpuPllSetup (cpuMultiplier_t multiplier); +void cpuInit (void); +cpuDeviceID_t cpuGetDeviceID (void); + +#endif \ No newline at end of file diff --git a/macusbfb/core/gpio/gpio.c b/macusbfb/core/gpio/gpio.c new file mode 100644 index 0000000..bf3c117 --- /dev/null +++ b/macusbfb/core/gpio/gpio.c @@ -0,0 +1,665 @@ +/**************************************************************************/ +/*! + @file gpio.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Controls the general purpose digital IO. + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "gpio.h" + +#ifdef CFG_CHIBI +#include "drivers/chibi/chb_drvr.h" +volatile uint32_t chibi_counter = 0; +#endif + +volatile uint32_t gpio0_counter = 0; +volatile uint32_t gpio1_counter = 0; +volatile uint32_t gpio2_counter = 0; +volatile uint32_t gpio3_counter = 0; +volatile uint32_t p0_1_counter = 0; +volatile uint32_t p1_1_counter = 0; +volatile uint32_t p2_1_counter = 0; +volatile uint32_t p3_1_counter = 0; + +/**************************************************************************/ +/*! + @brief IRQ Handler for GPIO port 0 (currently checks pin 0.1) +*/ +/**************************************************************************/ +void PIOINT0_IRQHandler(void) +{ + uint32_t regVal; + + gpio0_counter++; + + regVal = gpioIntStatus(0, 1); + if (regVal) + { + p0_1_counter++; + gpioIntClear(0, 1); + } + return; +} + +/**************************************************************************/ +/*! + @brief IRQ Handler for GPIO port 1 (currently checks pin 1.1) +*/ +/**************************************************************************/ +void PIOINT1_IRQHandler(void) +{ + uint32_t regVal; + + gpio1_counter++; + +#ifdef CFG_CHIBI + // Check for interrupt on 1.8 + regVal = gpioIntStatus(1, 8); + if (regVal) + { + chibi_counter++; + chb_ISR_Handler(); + gpioIntClear(1, 8); + } +#else + regVal = gpioIntStatus(1, 1); + if ( regVal ) + { + p1_1_counter++; + gpioIntClear(1, 1); + } +#endif + + return; +} + +/**************************************************************************/ +/*! + @brief IRQ Handler for GPIO port 2 (currently checks pin 2.1) +*/ +/**************************************************************************/ +void PIOINT2_IRQHandler(void) +{ + uint32_t regVal; + + gpio2_counter++; + regVal = gpioIntStatus(2, 1); + if ( regVal ) + { + p2_1_counter++; + gpioIntClear(2, 1); + } + return; +} + +/**************************************************************************/ +/*! + @brief IRQ Handler for GPIO port 3 (currently checks pin 3.1) +*/ +/**************************************************************************/ +void PIOINT3_IRQHandler(void) +{ + uint32_t regVal; + + gpio3_counter++; + regVal = gpioIntStatus(3, 1); + if ( regVal ) + { + p3_1_counter++; + gpioIntClear(3, 1); + } + return; +} + +/**************************************************************************/ +/*! + @brief Initialises GPIO and enables the GPIO interrupt + handler for all GPIO ports. +*/ +/**************************************************************************/ +void gpioInit (void) +{ + /* Enable AHB clock to the GPIO domain. */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_GPIO); + + /* Set up NVIC when I/O pins are configured as external interrupts. */ + NVIC_EnableIRQ(EINT0_IRQn); + NVIC_EnableIRQ(EINT1_IRQn); + NVIC_EnableIRQ(EINT2_IRQn); + NVIC_EnableIRQ(EINT3_IRQn); + return; +} + +/**************************************************************************/ +/*! + @brief Sets the direction (input/output) for a specific port pin + + @param[in] portNum + The port number (0..3) + @param[in] bitPos + The bit position (0..11) + @param[in] dir + The pin direction (gpioDirection_Input or + gpioDirection_Output) +*/ +/**************************************************************************/ +void gpioSetDir (uint32_t portNum, uint32_t bitPos, gpioDirection_t dir) +{ + switch (portNum) + { + case 0: + if (gpioDirection_Output == dir) + { + GPIO_GPIO0DIR |= (1 << bitPos); + } + else + { + GPIO_GPIO0DIR &= ~(1 << bitPos); + } + break; + case 1: + if (gpioDirection_Output == dir) + { + GPIO_GPIO1DIR |= (1 << bitPos); + } + else + { + GPIO_GPIO1DIR &= ~(1 << bitPos); + } + break; + case 2: + if (gpioDirection_Output == dir) + { + GPIO_GPIO2DIR |= (1 << bitPos); + } + else + { + GPIO_GPIO2DIR &= ~(1 << bitPos); + } + break; + case 3: + if (gpioDirection_Output == dir) + { + GPIO_GPIO3DIR |= (1 << bitPos); + } + else + { + GPIO_GPIO3DIR &= ~(1 << bitPos); + } + break; + } +} + +/**************************************************************************/ +/*! + @brief Gets the value for a specific port pin + + @param[in] portNum + The port number (0..3) + @param[in] bitPos + The bit position (0..31) + + @return The current value for the specified port pin (0..1) +*/ +/**************************************************************************/ +uint32_t gpioGetValue (uint32_t portNum, uint32_t bitPos) +{ + uint32_t value = 0; + + switch (portNum) + { + case 0: + value = (GPIO_GPIO0DATA & (1 << bitPos)) ? 1 : 0; + break; + case 1: + value = (GPIO_GPIO1DATA & (1 << bitPos)) ? 1 : 0; + break; + case 2: + value = (GPIO_GPIO2DATA & (1 << bitPos)) ? 1 : 0; + break; + case 3: + value = (GPIO_GPIO3DATA & (1 << bitPos)) ? 1 : 0; + break; + default: + break; + } + + return value; +} + +/**************************************************************************/ +/*! + @brief Sets the value for a specific port pin (only relevant when a + pin is configured as output). + + @param[in] portNum + The port number (0..3) + @param[in] bitPos + The bit position (0..31) + @param[in] bitValue + The value to set for the specified bit (0..1). 0 will set + the pin low and 1 will set the pin high. +*/ +/**************************************************************************/ +void gpioSetValue (uint32_t portNum, uint32_t bitPos, uint32_t bitVal) +{ + switch (portNum) + { + case 0: + if (1 == bitVal) + { + GPIO_GPIO0DATA |= (1 << bitPos); + } + else + { + GPIO_GPIO0DATA &= ~(1 << bitPos); + } + break; + case 1: + if (1 == bitVal) + { + GPIO_GPIO1DATA |= (1 << bitPos); + } + else + { + GPIO_GPIO1DATA &= ~(1 << bitPos); + } + break; + case 2: + if (1 == bitVal) + { + GPIO_GPIO2DATA |= (1 << bitPos); + } + else + { + GPIO_GPIO2DATA &= ~(1 << bitPos); + } + break; + case 3: + if (1 == bitVal) + { + GPIO_GPIO3DATA |= (1 << bitPos); + } + else + { + GPIO_GPIO3DATA &= ~(1 << bitPos); + } + break; + default: + break; + } +} + +/**************************************************************************/ +/*! + @brief Sets the interrupt sense, event, etc. + + @param[in] portNum + The port number (0..3) + @param[in] bitPos + The bit position (0..31) + @param[in] sense + Whether the interrupt should be configured as edge or level + sensitive. + @param[in] edge + Whether one edge or both trigger an interrupt. + @param[in] event + Whether the rising or the falling edge (high or low) + should be used to trigger the interrupt. + + @section Example + + @code + // Initialise gpio + gpioInit(); + // Set GPIO1.8 to input + gpioSetDir(1, 8, gpioDirection_Input); + // Disable the internal pullup/down resistor on P1.8 + gpioSetPullup (&IOCON_PIO1_8, gpioPullupMode_Inactive); + // Setup an interrupt on GPIO1.8 + gpioSetInterrupt(1, // Port + 8, // Pin + gpioInterruptSense_Edge, // Edge/Level Sensitive + gpioInterruptEdge_Single, // Single/Double Edge + gpioInterruptEvent_ActiveHigh); // Rising/Falling + // Enable the interrupt + gpioIntEnable(1, 8); + @endcode +*/ +/**************************************************************************/ +void gpioSetInterrupt (uint32_t portNum, uint32_t bitPos, gpioInterruptSense_t sense, gpioInterruptEdge_t edge, gpioInterruptEvent_t event) +{ + switch (portNum) + { + case 0: + if (gpioInterruptSense_Edge) + { + GPIO_GPIO0IS &= ~(0x1<= I2C_MAX_TIMEOUT ) + { + retVal = FALSE; + break; + } + timeout++; + } + return( retVal ); +} + +/***************************************************************************** +** Function name: I2CStop +** +** Descriptions: Set the I2C stop condition, if the routine +** never exit, it's a fatal bus error. +** +** parameters: None +** Returned value: true or never return +** +*****************************************************************************/ +uint32_t i2cStop( void ) +{ + I2C_I2CCONSET = I2C_I2CCONSET_STO; /* Set Stop flag */ + I2C_I2CCONCLR = I2C_I2CCONCLR_SIC; /* Clear SI flag */ + + /*--- Wait for STOP detected ---*/ + while( I2C_I2CCONSET & I2C_I2CCONSET_STO ); + return TRUE; +} + +/***************************************************************************** +** Function name: I2CInit +** +** Descriptions: Initialize I2C controller +** +** parameters: mode is I2CMODE_MASTER or I2CMODE_SLAVE +** Returned value: true or false, return false if the I2C +** interrupt handler was not installed correctly +** +*****************************************************************************/ +uint32_t i2cInit( i2cMode_t mode ) +{ + /* It seems to be bit0 is for I2C, different from + UM. To be retested along with SSP reset. SSP and I2C + reset are overlapped, a known bug, for now, both SSP + and I2C use bit 0 for reset enable. Once the problem + is fixed, change to "#if 1". */ +#if 1 + SCB_PRESETCTRL |= (0x1<<1); +#else + SCB_PRESETCTRL |= (0x1<<0); +#endif + + // Enable I2C clock + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_I2C); + + // Configure pin 0.4 for SCL + IOCON_PIO0_4 &= ~(IOCON_PIO0_4_FUNC_MASK | IOCON_PIO0_4_I2CMODE_MASK); + IOCON_PIO0_4 |= (IOCON_PIO0_4_FUNC_I2CSCL); + + // Configure pin 0.5 for SDA + IOCON_PIO0_5 &= ~(IOCON_PIO0_5_FUNC_MASK | IOCON_PIO0_5_I2CMODE_MASK); + IOCON_PIO0_5 |= IOCON_PIO0_5_FUNC_I2CSDA; + + // Clear flags + I2C_I2CCONCLR = I2C_I2CCONCLR_AAC | + I2C_I2CCONCLR_SIC | + I2C_I2CCONCLR_STAC | + I2C_I2CCONCLR_I2ENC; + + // See p.128 for appropriate values for SCLL and SCLH +#if I2C_FAST_MODE_PLUS + IOCON_PIO0_4 |= (IOCON_PIO0_4_I2CMODE_FASTPLUSI2C); + IOCON_PIO0_5 |= (IOCON_PIO0_5_I2CMODE_FASTPLUSI2C); + I2C_I2CSCLL = I2C_SCLL_HS_SCLL; + I2C_I2CSCLH = I2C_SCLH_HS_SCLH; +#else + I2C_I2CSCLL = I2C_SCLL_SCLL; + I2C_I2CSCLH = I2C_SCLH_SCLH; +#endif + + if ( mode == I2CMODE_SLAVE ) + { + I2C_I2CADR0 = I2C_SLAVEADDR; + } + + /* Enable the I2C Interrupt */ + NVIC_EnableIRQ(I2C_IRQn); + I2C_I2CCONSET = I2C_I2CCONSET_I2EN; + + return( TRUE ); +} + +/***************************************************************************** +** Function name: I2CEngine +** +** Descriptions: The routine to complete a I2C transaction +** from start to stop. All the intermitten +** steps are handled in the interrupt handler. +** Before this routine is called, the read +** length, write length, I2C master buffer, +** and I2C command fields need to be filled. +** see i2cmst.c for more details. +** +** parameters: None +** Returned value: true or false, return false only if the +** start condition can never be generated and +** timed out. +** +*****************************************************************************/ +uint32_t i2cEngine( void ) +{ + I2CMasterState = I2CSTATE_IDLE; + RdIndex = 0; + WrIndex = 0; + if ( i2cStart() != TRUE ) + { + i2cStop(); + return ( FALSE ); + } + + while ( 1 ) + { + if ( I2CMasterState == I2CSTATE_DATA_NACK ) + { + i2cStop(); + break; + } + } + return ( TRUE ); +} diff --git a/macusbfb/core/i2c/i2c.h b/macusbfb/core/i2c/i2c.h new file mode 100644 index 0000000..530f7b0 --- /dev/null +++ b/macusbfb/core/i2c/i2c.h @@ -0,0 +1,98 @@ +/**************************************************************************/ +/*! + @file i2c.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _I2C_H_ +#define _I2C_H_ + +#define I2C_FAST_MODE_PLUS 0 + +#define I2C_BUFSIZE 12 +#define I2C_MAX_TIMEOUT 0xFF + +#define I2C_SLAVEADDR 0xA0 + +#define I2C_SCLH_SCLH 0x00000180 /* I2C SCL Duty Cycle High Reg */ +#define I2C_SCLL_SCLL 0x00000180 /* I2C SCL Duty Cycle Low Reg */ +#define I2C_SCLH_HS_SCLH 0x00000030 /* Fast Plus I2C SCL Duty Cycle High Reg */ +#define I2C_SCLL_HS_SCLL 0x00000030 /* Fast Plus I2C SCL Duty Cycle Low Reg */ + +#include "projectconfig.h" + +typedef enum i2cMode_e +{ + I2CMODE_MASTER = 0x01, + I2CMODE_SLAVE = 0x02 +} +i2cMode_t; + +typedef enum i2cErr_e +{ + I2CERR_BUSERROR = 0x00, + I2CERR_STARTTX = 0x08, + I2CERR_REPEATEDSTARTTX = 0x10, + I2CERR_SLAWTX_ACKRX = 0x18, + I2CERR_SLAWTX_NACKRX = 0x20, + I2CERR_DATTX_ACKRX = 0x28, + I2CERR_DATTX_NACKRX = 0x30, + I2CERR_ARBLOST = 0x38, + I2CERR_SLARTX_ACKRX = 0x40, + I2CERR_SLARTX_NACKRX = 0x48, + I2CERR_DATRX_ACKTX = 0x50, + I2CERR_DATRX_NACKTX = 0x58, + I2CERR_NOINFO = 0xf8 +} +i2cErr_t; + +typedef enum i2cState_e +{ + I2CSTATE_IDLE = 0, + I2CSTATE_STARTED, + I2CSTATE_RESTARTED, + I2CSTATE_REPEATED_START, + I2CSTATE_DATA_ACK, + I2CSTATE_DATA_NACK +} +i2cState_t; + +extern void I2C_IRQHandler( void ); +extern uint32_t i2cInit( i2cMode_t mode ); +extern uint32_t i2cStart( void ); +extern uint32_t i2cStop( void ); +extern uint32_t i2cEngine( void ); + +#endif diff --git a/macusbfb/core/libc/stdio.c b/macusbfb/core/libc/stdio.c new file mode 100755 index 0000000..0ec7887 --- /dev/null +++ b/macusbfb/core/libc/stdio.c @@ -0,0 +1,475 @@ +/* + * Software License Agreement (BSD License) + * + * Based on original stdio.c released by Atmel + * Copyright (c) 2008, Atmel Corporation + * All rights reserved. + * + * Modified by Roel Verdult, Copyright (c) 2010 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include + +//------------------------------------------------------------------------------ +// Local Definitions +//------------------------------------------------------------------------------ + +// Maximum string size allowed (in bytes). +#define MAX_STRING_SIZE 100 + +//------------------------------------------------------------------------------ +// Global Variables +//------------------------------------------------------------------------------ + +// Required for proper compilation. +//struct _reent r = {0, (FILE*) 0, (FILE*) 1, (FILE*) 0}; +//struct _reent *_impure_ptr = &r; + +//------------------------------------------------------------------------------ +// Local Functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Writes a character inside the given string. Returns 1. +// \param pStr Storage string. +// \param c Character to write. +//------------------------------------------------------------------------------ +signed int append_char(char *pStr, char c) +{ + *pStr = c; + return 1; +} + +//------------------------------------------------------------------------------ +// Writes a string inside the given string. +// Returns the size of the written +// string. +// \param pStr Storage string. +// \param pSource Source string. +//------------------------------------------------------------------------------ +signed int PutString(char *pStr, char fill, signed int width, const char *pSource) +{ + signed int num = 0; + + while (*pSource != 0) { + + *pStr++ = *pSource++; + num++; + } + + width -= num; + while (width > 0) { + + *pStr++ = fill; + num++; + width--; + } + + return num; +} + +//------------------------------------------------------------------------------ +// Writes an unsigned int inside the given string, using the provided fill & +// width parameters. +// Returns the size in characters of the written integer. +// \param pStr Storage string. +// \param fill Fill character. +// \param width Minimum integer width. +// \param value Integer value. +//------------------------------------------------------------------------------ +signed int PutUnsignedInt( + char *pStr, + char fill, + signed int width, + unsigned int value) +{ + signed int num = 0; + + // Take current digit into account when calculating width + width--; + + // Recursively write upper digits + if ((value / 10) > 0) { + + num = PutUnsignedInt(pStr, fill, width, value / 10); + pStr += num; + } + // Write filler characters + else { + + while (width > 0) { + + append_char(pStr, fill); + pStr++; + num++; + width--; + } + } + + // Write lower digit + num += append_char(pStr, (value % 10) + '0'); + + return num; +} + +//------------------------------------------------------------------------------ +// Writes a signed int inside the given string, using the provided fill & width +// parameters. +// Returns the size of the written integer. +// \param pStr Storage string. +// \param fill Fill character. +// \param width Minimum integer width. +// \param value Signed integer value. +//------------------------------------------------------------------------------ +signed int PutSignedInt( + char *pStr, + char fill, + signed int width, + signed int value) +{ + signed int num = 0; + unsigned int absolute; + + // Compute absolute value + if (value < 0) { + + absolute = -value; + } + else { + + absolute = value; + } + + // Take current digit into account when calculating width + width--; + + // Recursively write upper digits + if ((absolute / 10) > 0) { + + if (value < 0) { + + num = PutSignedInt(pStr, fill, width, -(absolute / 10)); + } + else { + + num = PutSignedInt(pStr, fill, width, absolute / 10); + } + pStr += num; + } + else { + + // Reserve space for sign + if (value < 0) { + + width--; + } + + // Write filler characters + while (width > 0) { + + append_char(pStr, fill); + pStr++; + num++; + width--; + } + + // Write sign + if (value < 0) { + + num += append_char(pStr, '-'); + pStr++; + } + } + + // Write lower digit + num += append_char(pStr, (absolute % 10) + '0'); + + return num; +} + +//------------------------------------------------------------------------------ +// Writes an hexadecimal value into a string, using the given fill, width & +// capital parameters. +// Returns the number of char written. +// \param pStr Storage string. +// \param fill Fill character. +// \param width Minimum integer width. +// \param maj Indicates if the letters must be printed in lower- or upper-case. +// \param value Hexadecimal value. +//------------------------------------------------------------------------------ +signed int PutHexa( + char *pStr, + char fill, + signed int width, + unsigned char maj, + unsigned int value) +{ + signed int num = 0; + + // Decrement width + width--; + + // Recursively output upper digits + if ((value >> 4) > 0) { + + num += PutHexa(pStr, fill, width, maj, value >> 4); + pStr += num; + } + // Write filler chars + else { + + while (width > 0) { + + append_char(pStr, fill); + pStr++; + num++; + width--; + } + } + + // Write current digit + if ((value & 0xF) < 10) { + + append_char(pStr, (value & 0xF) + '0'); + } + else if (maj) { + + append_char(pStr, (value & 0xF) - 10 + 'A'); + } + else { + + append_char(pStr, (value & 0xF) - 10 + 'a'); + } + num++; + + return num; +} + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Stores the result of a formatted string into another string. Format +/// arguments are given in a va_list instance. +/// Return the number of characters written. +/// \param pStr Destination string. +/// \param length Length of Destination string. +/// \param pFormat Format string. +/// \param ap Argument list. +//------------------------------------------------------------------------------ +signed int vsnprintf(char *pStr, size_t length, const char *pFormat, va_list ap) +{ + char fill; + unsigned char width; + signed int num = 0; + signed int size = 0; + + // Clear the string + if (pStr) { + + *pStr = 0; + } + + // Phase string + while (*pFormat != 0 && size < length) { + + // Normal character + if (*pFormat != '%') { + + *pStr++ = *pFormat++; + size++; + } + // Escaped '%' + else if (*(pFormat+1) == '%') { + + *pStr++ = '%'; + pFormat += 2; + size++; + } + // Token delimiter + else { + + fill = ' '; + width = 0; + pFormat++; + + // Parse filler + if (*pFormat == '0') { + + fill = '0'; + pFormat++; + } + + // Ignore justifier + if (*pFormat == '-') { + pFormat++; + } + + // Parse width + while ((*pFormat >= '0') && (*pFormat <= '9')) { + + width = (width*10) + *pFormat-'0'; + pFormat++; + } + + // Check if there is enough space + if (size + width > length) { + + width = length - size; + } + + // Parse type + switch (*pFormat) { + case 'd': + case 'i': num = PutSignedInt(pStr, fill, width, va_arg(ap, signed int)); break; + case 'u': num = PutUnsignedInt(pStr, fill, width, va_arg(ap, unsigned int)); break; + case 'x': num = PutHexa(pStr, fill, width, 0, va_arg(ap, unsigned int)); break; + case 'X': num = PutHexa(pStr, fill, width, 1, va_arg(ap, unsigned int)); break; + case 's': num = PutString(pStr, fill, width, va_arg(ap, char *)); break; + case 'c': num = append_char(pStr, va_arg(ap, unsigned int)); break; + default: + return EOF; + } + + pFormat++; + pStr += num; + size += num; + } + } + + // NULL-terminated (final \0 is not counted) + if (size < length) { + + *pStr = 0; + } + else { + + *(--pStr) = 0; + size--; + } + + return size; +} + +//------------------------------------------------------------------------------ +/// Stores the result of a formatted string into another string. Format +/// arguments are given in a va_list instance. +/// Return the number of characters written. +/// \param pString Destination string. +/// \param length Length of Destination string. +/// \param pFormat Format string. +/// \param ... Other arguments +//------------------------------------------------------------------------------ +signed int snprintf(char *pString, size_t length, const char *pFormat, ...) +{ + va_list ap; + signed int rc; + + va_start(ap, pFormat); + rc = vsnprintf(pString, length, pFormat, ap); + va_end(ap); + + return rc; +} + +//------------------------------------------------------------------------------ +/// Stores the result of a formatted string into another string. Format +/// arguments are given in a va_list instance. +/// Return the number of characters written. +/// \param pString Destination string. +/// \param pFormat Format string. +/// \param ap Argument list. +//------------------------------------------------------------------------------ +signed int vsprintf(char *pString, const char *pFormat, va_list ap) +{ + return vsnprintf(pString, MAX_STRING_SIZE, pFormat, ap); +} + +//------------------------------------------------------------------------------ +/// Outputs a formatted string on the DBGU stream. Format arguments are given +/// in a va_list instance. +/// \param pFormat Format string +/// \param ap Argument list. +//------------------------------------------------------------------------------ +signed int vprintf(const char *pFormat, va_list ap) +{ + char pStr[MAX_STRING_SIZE]; + char pError[] = "stdio.c: increase MAX_STRING_SIZE\r\n"; + + // Write formatted string in buffer + if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) { + + puts(pError); + while (1); // Increase MAX_STRING_SIZE + } + + // Display string + return puts(pStr); +} + +//------------------------------------------------------------------------------ +/// Outputs a formatted string on the DBGU stream, using a variable number of +/// arguments. +/// \param pFormat Format string. +//------------------------------------------------------------------------------ +signed int printf(const char *pFormat, ...) +{ + va_list ap; + signed int result; + + // Forward call to vprintf + va_start(ap, pFormat); + result = vprintf(pFormat, ap); + va_end(ap); + + return result; +} + + +//------------------------------------------------------------------------------ +/// Writes a formatted string inside another string. +/// \param pStr Storage string. +/// \param pFormat Format string. +//------------------------------------------------------------------------------ +signed int sprintf(char *pStr, const char *pFormat, ...) +{ + va_list ap; + signed int result; + + // Forward call to vsprintf + va_start(ap, pFormat); + result = vsprintf(pStr, pFormat, ap); + va_end(ap); + + return result; +} \ No newline at end of file diff --git a/macusbfb/core/libc/string.c b/macusbfb/core/libc/string.c new file mode 100755 index 0000000..733fc06 --- /dev/null +++ b/macusbfb/core/libc/string.c @@ -0,0 +1,311 @@ +/* + * Software License Agreement (BSD License) + * + * Based on original stdio.c released by Atmel + * Copyright (c) 2008, Atmel Corporation + * All rights reserved. + * + * Modified by Roel Verdult, Copyright (c) 2010 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Copies data from a source buffer into a destination buffer. The two buffers +/// must NOT overlap. Returns the destination buffer. +/// \param pDestination Destination buffer. +/// \param pSource Source buffer. +/// \param num Number of bytes to copy. +//------------------------------------------------------------------------------ +void * memcpy(void *pDestination, const void *pSource, size_t num) +{ + unsigned char *pByteDestination; + unsigned char *pByteSource; + unsigned int *pAlignedSource = (unsigned int *) pSource; + unsigned int *pAlignedDestination = (unsigned int *) pDestination; + + // If num is more than 4 bytes, and both dest. and source are aligned, + // then copy dwords + if ((((unsigned int) pAlignedDestination & 0x3) == 0) + && (((unsigned int) pAlignedSource & 0x3) == 0) + && (num >= 4)) { + + while (num >= 4) { + + *pAlignedDestination++ = *pAlignedSource++; + num -= 4; + } + } + + // Copy remaining bytes + pByteDestination = (unsigned char *) pAlignedDestination; + pByteSource = (unsigned char *) pAlignedSource; + while (num--) { + + *pByteDestination++ = *pByteSource++; + } + + return pDestination; +} + +//------------------------------------------------------------------------------ +/// Fills a memory region with the given value. Returns a pointer to the +/// memory region. +/// \param pBuffer Pointer to the start of the memory region to fill +/// \param value Value to fill the region with +/// \param num Size to fill in bytes +//------------------------------------------------------------------------------ +void * memset(void *pBuffer, int value, size_t num) +{ + unsigned char *pByteDestination; + unsigned int *pAlignedDestination = (unsigned int *) pBuffer; + unsigned int alignedValue = (value << 24) | (value << 16) | (value << 8) | value; + + // Set words if possible + if ((((unsigned int) pAlignedDestination & 0x3) == 0) && (num >= 4)) { + while (num >= 4) { + *pAlignedDestination++ = alignedValue; + num -= 4; + } + } + // Set remaining bytes + pByteDestination = (unsigned char *) pAlignedDestination; + while (num--) { + *pByteDestination++ = value; + } + return pBuffer; +} + +void* memmove(void *s1, const void *s2, size_t n) +{ + char *s=(char*)s2, *d=(char*)s1; + + if(d > s){ + s+=n-1; + d+=n-1; + while(n){ + *d--=*s--; + n--; + } + }else if(d < s) + while(n){ + *d++=*s++; + n--; + } + return s1; +} + + +//----------------------------------------------------------------------------- +/// Search a character in the given string. +/// Returns a pointer to the character location. +/// \param pString Pointer to the start of the string to search. +/// \param character The character to find. +//----------------------------------------------------------------------------- +char * strchr(const char *pString, int character) +{ + char * p = (char *)pString; + char c = character & 0xFF; + + while(*p != c) { + if (*p == 0) { + return 0; + } + p++; + } + return p; +} + +//----------------------------------------------------------------------------- +/// Return the length of a given string +/// \param pString Pointer to the start of the string. +//----------------------------------------------------------------------------- +size_t strlen(const char *pString) +{ + unsigned int length = 0; + + while(*pString++ != 0) { + length++; + } + return length; +} + + +//----------------------------------------------------------------------------- +/// Search a character backword from the end of given string. +/// Returns a pointer to the character location. +/// \param pString Pointer to the start of the string to search. +/// \param character The character to find. +//----------------------------------------------------------------------------- +char * strrchr(const char *pString, int character) +{ + char *p = 0; + + while(*pString != 0) { + if (*pString++ == character) { + p = (char*)pString; + } + } + return p; +} + +//----------------------------------------------------------------------------- +/// Copy from source string to destination string +/// Return a pointer to the destination string +/// \param pDestination Pointer to the destination string. +/// \param pSource Pointer to the source string. +//----------------------------------------------------------------------------- +char * strcpy(char *pDestination, const char *pSource) +{ + char *pSaveDest = pDestination; + + for(; (*pDestination = *pSource) != 0; ++pSource, ++pDestination); + return pSaveDest; +} + +//----------------------------------------------------------------------------- +/// Compare the first specified bytes of 2 given strings +/// Return 0 if equals +/// Return >0 if 1st string > 2nd string +/// Return <0 if 1st string < 2nd string +/// \param pString1 Pointer to the start of the 1st string. +/// \param pString2 Pointer to the start of the 2nd string. +/// \param count Number of bytes that should be compared. +//----------------------------------------------------------------------------- +int strncmp(const char *pString1, const char *pString2, size_t count) +{ + int r; + + while(count) { + r = *pString1 - *pString2; + if (r == 0) { + if (*pString1 == 0) { + break; + } + pString1++; + pString2++; + count--; + continue; + } + return r; + } + return 0; +} + +//----------------------------------------------------------------------------- +/// Copy the first number of bytes from source string to destination string +/// Return the pointer to the destination string. +/// \param pDestination Pointer to the start of destination string. +/// \param pSource Pointer to the start of the source string. +/// \param count Number of bytes that should be copied. +//----------------------------------------------------------------------------- +char * strncpy(char *pDestination, const char *pSource, size_t count) +{ + char *pSaveDest = pDestination; + + while (count) { + *pDestination = *pSource; + if (*pSource == 0) { + break; + } + pDestination++; + pSource++; + count--; + } + return pSaveDest; +} + +// Following code is based on the BSD licensed code released by UoC +// Copyright (c) 1988 Regents of the University of California + +int strcmp(const char *s1, const char *s2) +{ + while (*s1 == *s2++) + if (*s1++ == 0) + return (0); + return (*(unsigned char *)s1 - *(unsigned char *)--s2); +} + +char *strtok(char *s, const char *delim) +{ + static char *last; + return strtok_r(s, delim, &last); +} + +char *strtok_r(char *s, const char *delim, char **last) +{ + char *spanp; + int c, sc; + char *tok; + + + if (s == NULL && (s = *last) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += strspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0;) { + if (c == sc) + goto cont; + } + + if (c == 0) { /* no non-delimiter characters */ + *last = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s++; + spanp = (char *)delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *last = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/macusbfb/core/pmu/pmu.c b/macusbfb/core/pmu/pmu.c new file mode 100644 index 0000000..204a1d0 --- /dev/null +++ b/macusbfb/core/pmu/pmu.c @@ -0,0 +1,380 @@ +/**************************************************************************/ +/*! + @file pmu.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Controls the power management features of the LPC1343, allowing you + to enter sleep/deep-sleep or deep power-down mode. + + For examples of how to enter either mode, see the comments for the + functions pmuSleep(), pmuDeepSleep() and pmuPowerDown(). + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "core/gpio/gpio.h" +#include "core/cpu/cpu.h" +#include "core/timer32/timer32.h" +#include "pmu.h" + +#define PMU_WDTCLOCKSPEED_HZ 10000 + +/**************************************************************************/ +/*! + Wakeup interrupt handler +*/ +/**************************************************************************/ +void WAKEUP_IRQHandler(void) +{ + uint32_t regVal; + + // Disable the deep sleep timer + TMR_TMR32B0TCR = TMR_TMR32B0TCR_COUNTERENABLE_DISABLED; + + /* This handler takes care of all the port pins if they + are configured as wakeup source. */ + regVal = SCB_STARTSRP0; + if (regVal != 0) + { + SCB_STARTRSRP0CLR = regVal; + } + + // Reconfigure system clock/PLL + cpuPllSetup(CPU_MULTIPLIER_6); + + // Reconfigure CT32B0 + timer32Init(0, TIMER32_DEFAULTINTERVAL); + timer32Enable(0); + + /* See tracker for bug report. */ + __asm volatile ("NOP"); + + return; +} + +/**************************************************************************/ +/*! + Setup the clock for the watchdog timer. The default setting is 10kHz. +*/ +/**************************************************************************/ +static void pmuWDTClockInit (void) +{ + /* Configure watchdog clock */ + /* Freq. = 0.5MHz, div = 50: WDT_OSC = 10kHz */ + SCB_WDTOSCCTRL = SCB_WDTOSCCTRL_FREQSEL_0_5MHZ | + SCB_WDTOSCCTRL_DIVSEL_DIV50; + + /* Set clock source (use internal oscillator) */ + // SCB_WDTCLKSEL = SCB_WDTCLKSEL_SOURCE_INPUTCLOCK; + SCB_WDTCLKSEL = SCB_WDTCLKSEL_SOURCE_INTERNALOSC; + SCB_WDTCLKUEN = SCB_WDTCLKUEN_UPDATE; + SCB_WDTCLKUEN = SCB_WDTCLKUEN_DISABLE; + SCB_WDTCLKUEN = SCB_WDTCLKUEN_UPDATE; + + /* Wait until updated */ + while (!(SCB_WDTCLKUEN & SCB_WDTCLKUEN_UPDATE)); + + /* Set divider */ + SCB_WDTCLKDIV = SCB_WDTCLKDIV_DIV1; + + /* Enable WDT clock */ + SCB_PDRUNCFG &= ~(SCB_PDRUNCFG_WDTOSC); + + // Switch main clock to WDT output + SCB_MAINCLKSEL = SCB_MAINCLKSEL_SOURCE_WDTOSC; + SCB_MAINCLKUEN = SCB_MAINCLKUEN_UPDATE; // Update clock source + SCB_MAINCLKUEN = SCB_MAINCLKUEN_DISABLE; // Toggle update register once + SCB_MAINCLKUEN = SCB_MAINCLKUEN_UPDATE; + + // Wait until the clock is updated + while (!(SCB_MAINCLKUEN & SCB_MAINCLKUEN_UPDATE)); +} + +/**************************************************************************/ +/*! + @brief Initialises the power management unit +*/ +/**************************************************************************/ +void pmuInit( void ) +{ + /* Enable all clocks, even those turned off at power up. */ + SCB_PDRUNCFG &= ~(SCB_PDRUNCFG_WDTOSC_MASK | + SCB_PDRUNCFG_SYSOSC_MASK | + SCB_PDRUNCFG_ADC_MASK); + + return; +} + +/**************************************************************************/ +/*! + @brief Puts select peripherals in sleep mode. + + This function will put the device into sleep mode. Most gpio pins + can be used to wake the device up, but the pins must first be + configured for this in pmuInit. + + @section Example + + @code + // Configure wakeup sources before going into sleep/deep-sleep. + // By default, pin 0.1 is configured as wakeup source (falling edge) + pmuInit(); + + // Enter sleep mode + pmuSleep(); + @endcode +*/ +/**************************************************************************/ +void pmuSleep() +{ + SCB_PDAWAKECFG = SCB_PDRUNCFG; + __asm volatile ("WFI"); + return; +} + +/**************************************************************************/ +/*! + @brief Turns off select peripherals and puts the device in deep-sleep + mode. + + The device can be configured to wakeup from deep-sleep mode after a + specified delay by supplying a non-zero value to the wakeupSeconds + parameter. This will configure CT32B0 to toggle pin 0.1 (CT32B0_MAT2) + after x seconds, waking the device up. The timer will be configured + to run off the WDT OSC while in deep-sleep mode, meaning that WDTOSC + should not be powered off (using the sleepCtrl parameter) when a + wakeup delay is specified. + + The sleepCtrl parameter is used to indicate which peripherals should + be put in sleep mode (see the SCB_PDSLEEPCFG register for details). + + @param[in] sleepCtrl + The bits to set in the SCB_PDSLEEPCFG register. This + controls which peripherals will be put in sleep mode. + @param[in] wakeupSeconds + The number of seconds to wait until the device will + wakeup. If you do not wish to wakeup after a specific + delay, enter a value of 0. + + @code + uint32_t pmuRegVal; + + // Initialise power management unit + pmuInit(); + + // Put peripherals into sleep mode + pmuRegVal = SCB_PDSLEEPCFG_IRCOUT_PD | + SCB_PDSLEEPCFG_IRC_PD | + SCB_PDSLEEPCFG_FLASH_PD | + SCB_PDSLEEPCFG_USBPLL_PD | + SCB_PDSLEEPCFG_SYSPLL_PD | + SCB_PDSLEEPCFG_SYSOSC_PD | + SCB_PDSLEEPCFG_ADC_PD | + SCB_PDSLEEPCFG_BOD_PD; + + // Enter deep sleep mode (wakeup after 5 seconds) + // By default, pin 0.1 is configured as wakeup source + pmuDeepSleep(pmuRegVal, 5); + @endcode +*/ +/**************************************************************************/ +void pmuDeepSleep(uint32_t sleepCtrl, uint32_t wakeupSeconds) +{ + SCB_PDAWAKECFG = SCB_PDRUNCFG; + sleepCtrl |= (1 << 9) | (1 << 11); + SCB_PDSLEEPCFG = sleepCtrl; + SCB_SCR |= SCB_SCR_SLEEPDEEP; + + /* Configure system to run from WDT and set TMR32B0 for wakeup */ + if (wakeupSeconds > 0) + { + // Make sure WDTOSC isn't disabled in PDSLEEPCFG + SCB_PDSLEEPCFG &= ~(SCB_PDSLEEPCFG_WDTOSC_PD); + + // Disable 32-bit timer 0 if currently in use + TMR_TMR32B0TCR = TMR_TMR32B0TCR_COUNTERENABLE_DISABLED; + + // Disable internal pullup on 0.1 + gpioSetPullup(&IOCON_PIO0_1, gpioPullupMode_Inactive); + + // Reconfigure clock to run from WDTOSC + pmuWDTClockInit(); + + /* Enable the clock for CT32B0 */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT32B0); + + /* Configure 0.1 as Timer0_32 MAT2 */ + IOCON_PIO0_1 &= ~IOCON_PIO0_1_FUNC_MASK; + IOCON_PIO0_1 |= IOCON_PIO0_1_FUNC_CT32B0_MAT2; + + /* Set appropriate timer delay */ + TMR_TMR32B0MR0 = PMU_WDTCLOCKSPEED_HZ * wakeupSeconds; + + /* Configure match control register to raise an interrupt and reset on MR0 */ + TMR_TMR32B0MCR |= (TMR_TMR32B0MCR_MR0_INT_ENABLED | TMR_TMR32B0MCR_MR0_RESET_ENABLED); + + /* Configure external match register to set 0.1 high on match */ + TMR_TMR32B0EMR &= ~(0xFF<<4); // Clear EMR config bits + TMR_TMR32B0EMR |= TMR_TMR32B0EMR_EMC2_HIGH; // Set MAT2 (0.1) high on match + + /* Enable wakeup interrupts (any I/O pin can be used as a wakeup source) */ + //NVIC_EnableIRQ(WAKEUP0_IRQn); // P0.0 + NVIC_EnableIRQ(WAKEUP1_IRQn); // P0.1 (CT32B0_MAT2) + //NVIC_EnableIRQ(WAKEUP2_IRQn); // P0.2 + //NVIC_EnableIRQ(WAKEUP3_IRQn); // P0.3 + //NVIC_EnableIRQ(WAKEUP4_IRQn); // P0.4 + //NVIC_EnableIRQ(WAKEUP5_IRQn); // P0.5 + //NVIC_EnableIRQ(WAKEUP6_IRQn); // P0.6 + //NVIC_EnableIRQ(WAKEUP7_IRQn); // P0.7 + //NVIC_EnableIRQ(WAKEUP8_IRQn); // P0.8 + //NVIC_EnableIRQ(WAKEUP9_IRQn); // P0.9 + //NVIC_EnableIRQ(WAKEUP10_IRQn); // P0.10 + //NVIC_EnableIRQ(WAKEUP11_IRQn); // P0.11 + //NVIC_EnableIRQ(WAKEUP12_IRQn); // P1.0 + //NVIC_EnableIRQ(WAKEUP13_IRQn); // P1.1 + //NVIC_EnableIRQ(WAKEUP14_IRQn); // P1.2 + //NVIC_EnableIRQ(WAKEUP15_IRQn); // P1.3 + //NVIC_EnableIRQ(WAKEUP16_IRQn); // P1.4 + //NVIC_EnableIRQ(WAKEUP17_IRQn); // P1.5 + //NVIC_EnableIRQ(WAKEUP18_IRQn); // P1.6 + //NVIC_EnableIRQ(WAKEUP19_IRQn); // P1.7 + //NVIC_EnableIRQ(WAKEUP20_IRQn); // P1.8 + //NVIC_EnableIRQ(WAKEUP21_IRQn); // P1.9 + //NVIC_EnableIRQ(WAKEUP22_IRQn); // P1.10 + //NVIC_EnableIRQ(WAKEUP23_IRQn); // P1.11 + //NVIC_EnableIRQ(WAKEUP24_IRQn); // P2.0 + //NVIC_EnableIRQ(WAKEUP25_IRQn); // P2.1 + //NVIC_EnableIRQ(WAKEUP26_IRQn); // P2.2 + //NVIC_EnableIRQ(WAKEUP27_IRQn); // P2.3 + //NVIC_EnableIRQ(WAKEUP28_IRQn); // P2.4 + //NVIC_EnableIRQ(WAKEUP29_IRQn); // P2.5 + //NVIC_EnableIRQ(WAKEUP30_IRQn); // P2.6 + //NVIC_EnableIRQ(WAKEUP31_IRQn); // P2.7 + //NVIC_EnableIRQ(WAKEUP32_IRQn); // P2.8 + //NVIC_EnableIRQ(WAKEUP33_IRQn); // P2.9 + //NVIC_EnableIRQ(WAKEUP34_IRQn); // P2.10 + //NVIC_EnableIRQ(WAKEUP35_IRQn); // P2.11 + //NVIC_EnableIRQ(WAKEUP36_IRQn); // P3.0 + //NVIC_EnableIRQ(WAKEUP37_IRQn); // P3.1 + //NVIC_EnableIRQ(WAKEUP38_IRQn); // P3.2 + //NVIC_EnableIRQ(WAKEUP39_IRQn); // P3.3 + + /* Use RISING EDGE for wakeup detection. */ + SCB_STARTAPRP0 |= SCB_STARTAPRP0_APRPIO0_1; + + /* Clear all wakeup sources */ + SCB_STARTRSRP0CLR = SCB_STARTRSRP0CLR_MASK; + + /* Enable Port 0.1 as wakeup source. */ + SCB_STARTERP0 |= SCB_STARTERP0_ERPIO0_1; + + /* Start the timer */ + TMR_TMR32B0TCR = TMR_TMR32B0TCR_COUNTERENABLE_ENABLED; + } + + __asm volatile ("WFI"); + return; +} + +/**************************************************************************/ +/*! + @brief Puts the device in deep power-down mode. + + This function will configure the PMU control register and enter + deep power-down mode. Pre-determined values are stored in the four + general-purpose registers (PMU_GPREG0..3), which can be used to persist + any essential system settings while the device is in deep power-down + mode, so long as 3.3V is still available. + + @warning The only way to wake a device up from deep power-down mode + is to set a low-level on P1.4. If 3.3V power is lost, the + values stored in the four general-purpose registers will + also be lost. + + @section Example + + @code + #include "core/cpu/cpu.h" + #include "core/pmu/pmu.h" + + int main(void) + { + cpuInit(); + pmuInit(); + + // Enter power-down mode + pmuPowerDown(); + + while(1) + { + // Device was woken up by WAKEUP pin + } + } + @endcode +*/ +/**************************************************************************/ +void pmuPowerDown( void ) +{ + uint32_t regVal; + + if ( (PMU_PMUCTRL & ((0x1<<8) | (PMU_PMUCTRL_DPDFLAG))) != 0x0 ) + { + /* Check sleep and deep power down bits. If sleep and/or + deep power down mode are entered, clear the PCON bits. */ + regVal = PMU_PMUCTRL; + regVal |= ((0x1<<8) | + (PMU_PMUCTRL_DPDEN_SLEEP) | + (PMU_PMUCTRL_DPDFLAG)); + PMU_PMUCTRL = regVal; + + if ( (PMU_GPREG0 != 0x12345678)||(PMU_GPREG1 != 0x87654321) + ||(PMU_GPREG2 != 0x56781234)||(PMU_GPREG3 != 0x43218765) ) + { + while (1); + } + } + else + { + /* If in neither sleep nor deep-sleep mode, enter deep power down mode. */ + PMU_GPREG0 = 0x12345678; + PMU_GPREG1 = 0x87654321; + PMU_GPREG2 = 0x56781234; + PMU_GPREG3 = 0x43218765; + SCB_SCR |= SCB_SCR_SLEEPDEEP; + PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN; + __asm volatile ("WFI"); + } + return; +} diff --git a/macusbfb/core/pmu/pmu.h b/macusbfb/core/pmu/pmu.h new file mode 100644 index 0000000..58504e6 --- /dev/null +++ b/macusbfb/core/pmu/pmu.h @@ -0,0 +1,50 @@ +/**************************************************************************/ +/*! + @file pmu.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef __PMU_H__ +#define __PMU_H__ + +#include "projectconfig.h" + +void WAKEUP_IRQHandler( void ); +void pmuInit( void ); +void pmuSleep( void ); +void pmuDeepSleep(uint32_t sleepCtrl, uint32_t wakeupSeconds); +void pmuPowerDown( void ); + +#endif diff --git a/macusbfb/core/ssp/ssp.c b/macusbfb/core/ssp/ssp.c new file mode 100644 index 0000000..54f32ee --- /dev/null +++ b/macusbfb/core/ssp/ssp.c @@ -0,0 +1,293 @@ +/**************************************************************************/ +/*! + @file ssp.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Generic code for SSP/SPI communications. By default, the SSP block + is initialised in SPI master mode. + + @section Example + + @code + #include "core/cpu/cpu.h" + #include "core/ssp/ssp.h" + ... + cpuInit(); + sspInit(0, sspClockPolarity_High, sspClockPhase_RisingEdge); + ... + uint8_t request[SSP_FIFOSIZE]; + uint8_t response[SSP_FIFOSIZE]; + + // Send 0x9C to the slave device and wait for a response + request[0] = 0x80 | 0x1C; + // Toggle the select pin + ssp0Select(); + // Send 1 byte from the request buffer + sspSend(0, (uint8_t *)&request, 1); + // Receive 1 byte into the response buffer + sspReceive(0, (uint8_t *)&response, 1); + // Reset the select pin + ssp0Deselect(); + // Print the results + debug_printf("Ox%x ", response[0]); + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include "ssp.h" +#include "core/gpio/gpio.h" + +/* Statistics for all interrupts */ +volatile uint32_t interruptRxStat = 0; +volatile uint32_t interruptOverRunStat = 0; +volatile uint32_t interruptRxTimeoutStat = 0; + +/**************************************************************************/ +/*! + @brief SSP0 interrupt handler for SPI communication + + The algorithm is, if RXFIFO is at least half full, + start receive until it's empty; if TXFIFO is at least + half empty, start transmit until it's full. + This will maximize the use of both FIFOs and performance. +*/ +/**************************************************************************/ +void SSP_IRQHandler (void) +{ + uint32_t regValue; + + regValue = SSP_SSP0MIS; + + /* Check for overrun interrupt */ + if ( regValue & SSP_SSP0MIS_RORMIS_FRMRCVD ) + { + interruptOverRunStat++; + SSP_SSP0ICR = SSP_SSP0ICR_RORIC_CLEAR; // Clear interrupt + } + + /* Check for timeout interrupt */ + if ( regValue & SSP_SSP0MIS_RTMIS_NOTEMPTY ) + { + interruptRxTimeoutStat++; + SSP_SSP0ICR = SSP_SSP0ICR_RTIC_CLEAR; // Clear interrupt + } + + /* Check if Rx buffer is at least half-full */ + if ( regValue & SSP_SSP0MIS_RXMIS_HALFFULL ) + { + // ToDo: Receive until it's empty + interruptRxStat++; + } + return; +} + +/**************************************************************************/ +/*! + @brief Initialises the SSP0 port + + By default, SSP0 is set to SPI frame-format with 8-bit data. Pin 2.11 + is routed to serve as serial clock (SCK), and SSEL (0.2) is set to + GPIO to allow manual control of when the SPI port is enabled or + disabled. Overrun and timeout interrupts are both enabled. + + @param[in] portNum + The SPI port to use (0..1) + @param[in] polarity + Indicates whether the clock should be held high + (sspClockPolarity_High) or low (sspClockPolarity_Low) + when inactive. + @param[in] phase + Indicates whether new bits start on the leading + (sspClockPhase_RisingEdge) or falling + (sspClockPhase_FallingEdge) edge of clock transitions. + + @note sspSelect() and sspDeselect() macros have been defined in + ssp.h to control the SSEL line without having to know the + specific pin being used. +*/ +/**************************************************************************/ +void sspInit (uint8_t portNum, sspClockPolarity_t polarity, sspClockPhase_t phase) +{ + gpioInit(); + + if (portNum == 0) + { + /* Reset SSP */ + SCB_PRESETCTRL &= ~SCB_PRESETCTRL_SSP0_MASK; + SCB_PRESETCTRL |= SCB_PRESETCTRL_SSP0_RESETDISABLED; + + /* Enable AHB clock to the SSP domain. */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_SSP0); + + /* Divide by 1 (SSPCLKDIV also enables to SSP CLK) */ + // SCB_SSP0CLKDIV = SCB_SSP0CLKDIV_DIV1; // 1 = 4.0MHz + SCB_SSP0CLKDIV = SCB_SSP0CLKDIV_DIV10; // 10 = 400 KHz + + /* Set P0.8 to SSP MISO */ + IOCON_PIO0_8 &= ~IOCON_PIO0_8_FUNC_MASK; + IOCON_PIO0_8 |= IOCON_PIO0_8_FUNC_MISO0; + + /* Set P0.9 to SSP MOSI */ + IOCON_PIO0_9 &= ~IOCON_PIO0_9_FUNC_MASK; + IOCON_PIO0_9 |= IOCON_PIO0_9_FUNC_MOSI0; + + /* Set 2.11 to SSP SCK (0.6 and 0.10 can also be used) */ + IOCON_SCKLOC = IOCON_SCKLOC_SCKPIN_PIO2_11; + IOCON_PIO2_11 = IOCON_PIO2_11_FUNC_SCK0; + + /* Set P0.2/SSEL to GPIO output and high */ + IOCON_PIO0_2 &= ~IOCON_PIO0_2_FUNC_MASK; + IOCON_PIO0_2 |= IOCON_PIO0_2_FUNC_GPIO; + gpioSetDir(SSP0_CSPORT, SSP0_CSPIN, 1); + gpioSetValue(SSP0_CSPORT, SSP0_CSPIN, 1); + gpioSetPullup(&IOCON_PIO0_2, gpioPullupMode_Inactive); // Board has external pull-up + + /* DIV1 -- (PCLK / (CPSDVSR × [SCR+1])) = (72,000,000 / (2 x [8 + 1])) = 4.0 MHz */ + /* DIV10 -- (PCLK / (CPSDVSR × [SCR+1])) = (7,200,000 / (2 x [8 + 1])) = 400 KHz */ + uint32_t configReg = ( SSP_SSP0CR0_DSS_8BIT // Data size = 8-bit + | SSP_SSP0CR0_FRF_SPI // Frame format = SPI + | SSP_SSP0CR0_SCR_8); // Serial clock rate = 8 + + // Set clock polarity + if (polarity == sspClockPolarity_High) + configReg |= SSP_SSP0CR0_CPOL_HIGH; // Clock polarity = High between frames + else + configReg &= ~SSP_SSP0CR0_CPOL_MASK; // Clock polarity = Low between frames + + // Set edge transition + if (phase == sspClockPhase_FallingEdge) + configReg |= SSP_SSP0CR0_CPHA_SECOND; // Clock out phase = Trailing edge clock transition + else + configReg &= ~SSP_SSP0CR0_CPHA_MASK; // Clock out phase = Leading edge clock transition + + // Assign config values to SSP0CR0 + SSP_SSP0CR0 = configReg; + + /* Clock prescale register must be even and at least 2 in master mode */ + SSP_SSP0CPSR = SSP_SSP0CPSR_CPSDVSR_DIV2; + + /* Clear the Rx FIFO */ + uint8_t i, Dummy=Dummy; + for ( i = 0; i < SSP_FIFOSIZE; i++ ) + { + Dummy = SSP_SSP0DR; + } + + /* Enable the SSP Interrupt */ + NVIC_EnableIRQ(SSP_IRQn); + + /* Set SSPINMS registers to enable interrupts + * enable all error related interrupts */ + SSP_SSP0IMSC = ( SSP_SSP0IMSC_RORIM_ENBL // Enable overrun interrupt + | SSP_SSP0IMSC_RTIM_ENBL); // Enable timeout interrupt + + /* Enable device and set it to master mode, no loopback */ + SSP_SSP0CR1 = SSP_SSP0CR1_SSE_ENABLED | SSP_SSP0CR1_MS_MASTER | SSP_SSP0CR1_LBM_NORMAL; + } + + return; +} + +/**************************************************************************/ +/*! + @brief Sends a block of data to the SSP0 port + + @param[in] portNum + The SPI port to use (0..1) + @param[in] buf + Pointer to the data buffer + @param[in] length + Block length of the data buffer +*/ +/**************************************************************************/ +void sspSend (uint8_t portNum, uint8_t *buf, uint32_t length) +{ + uint32_t i; + uint8_t Dummy = Dummy; + + if (portNum == 0) + { + for (i = 0; i < length; i++) + { + /* Move on only if NOT busy and TX FIFO not full. */ + while ((SSP_SSP0SR & (SSP_SSP0SR_TNF_NOTFULL | SSP_SSP0SR_BSY_BUSY)) != SSP_SSP0SR_TNF_NOTFULL); + SSP_SSP0DR = *buf; + buf++; + + while ( (SSP_SSP0SR & (SSP_SSP0SR_BSY_BUSY|SSP_SSP0SR_RNE_NOTEMPTY)) != SSP_SSP0SR_RNE_NOTEMPTY ); + /* Whenever a byte is written, MISO FIFO counter increments, Clear FIFO + on MISO. Otherwise, when SSP0Receive() is called, previous data byte + is left in the FIFO. */ + Dummy = SSP_SSP0DR; + } + } + + return; +} + +/**************************************************************************/ +/*! + @brief Receives a block of data from the SSP0 port + + @param[in] portNum + The SPI port to use (0..1) + @param[in] buf + Pointer to the data buffer + @param[in] length + Block length of the data buffer +*/ +/**************************************************************************/ +void sspReceive(uint8_t portNum, uint8_t *buf, uint32_t length) +{ + uint32_t i; + + if (portNum == 0) + { + for ( i = 0; i < length; i++ ) + { + /* As long as the receive FIFO is not empty, data can be received. */ + SSP_SSP0DR = 0xFF; + + /* Wait until the Busy bit is cleared */ + while ( (SSP_SSP0SR & (SSP_SSP0SR_BSY_BUSY|SSP_SSP0SR_RNE_NOTEMPTY)) != SSP_SSP0SR_RNE_NOTEMPTY ); + + *buf = SSP_SSP0DR; + buf++; + } + } + + return; +} + diff --git a/macusbfb/core/ssp/ssp.h b/macusbfb/core/ssp/ssp.h new file mode 100644 index 0000000..19b2ca9 --- /dev/null +++ b/macusbfb/core/ssp/ssp.h @@ -0,0 +1,85 @@ +/**************************************************************************/ +/*! + @file ssp.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _SSP_H_ +#define _SSP_H_ + +#include "projectconfig.h" +#include "core/gpio/gpio.h" + +#define SSP_FIFOSIZE 8 /* SPI read and write buffer size */ +#define SSP_MAX_TIMEOUT 0xFF + +#define SSP0_CSPORT 0 +#define SSP0_CSPIN 2 + +/* Macro definitions to enable and disable SPI */ +#define ssp0Select() do {gpioSetValue(SSP0_CSPORT, SSP0_CSPIN, 0);} while (0) +#define ssp0Deselect() do {gpioSetValue(SSP0_CSPORT, SSP0_CSPIN, 1);} while (0) + +/**************************************************************************/ +/*! + Indicates whether the clock should be high or low between frames. +*/ +/**************************************************************************/ +typedef enum sspClockPolarity_e +{ + sspClockPolarity_Low = 0, + sspClockPolarity_High +} +sspClockPolarity_t; + +/**************************************************************************/ +/*! + Indicates whether the bits start at the rising or falling edge of + the clock transition. +*/ +/**************************************************************************/ +typedef enum sspClockPhase_e +{ + sspClockPhase_RisingEdge = 0, + sspClockPhase_FallingEdge +} +sspClockPhase_t; + +extern void SSP_IRQHandler (void); +void sspInit (uint8_t portNum, sspClockPolarity_t polarity, sspClockPhase_t phase); +void sspSend (uint8_t portNum, uint8_t *buf, uint32_t length); +void sspReceive (uint8_t portNum, uint8_t *buf, uint32_t length); + +#endif diff --git a/macusbfb/core/systick/systick.c b/macusbfb/core/systick/systick.c new file mode 100644 index 0000000..8bccc94 --- /dev/null +++ b/macusbfb/core/systick/systick.c @@ -0,0 +1,135 @@ +/**************************************************************************/ +/*! + @file systick.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Controls the 24-bit 'system tick' clock, which can be used as a + generic timer or to control time sharing with an embedded real-time + operating system (such as FreeRTOS). + + @section Example + + @code + #include "core/cpu/cpu.h" + #include "core/systick/systick.h" + + void main (void) + { + cpuInit(); + + // Start systick timer with one tick every 10ms + systickInit(10); + + while(1) + { + } + } + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "systick.h" + +#ifdef CFG_SDCARD +#include "drivers/fatfs/diskio.h" +volatile uint32_t fatTicks = 0; +#endif + +volatile uint32_t msTicks; // 1ms tick counter + +void SysTick_Handler (void) +{ + msTicks++; + + #ifdef CFG_SDCARD + fatTicks++; + if (fatTicks == 10) + { + fatTicks = 0; + disk_timerproc(); + } + #endif +} + +static uint32_t systickConfig(uint32_t ticks) +{ + // Check if 'ticks' is greater than maximum value + if (ticks > SYSTICK_STRELOAD_MASK) + { + return (1); + } + + // Set reload register + SYSTICK_STRELOAD = (ticks & SYSTICK_STRELOAD_MASK) - 1; + + // Load the systick counter value + SYSTICK_STCURR = 0; + + // Enable systick IRQ and timer + SYSTICK_STCTRL = SYSTICK_STCTRL_CLKSOURCE | + SYSTICK_STCTRL_TICKINT | + SYSTICK_STCTRL_ENABLE; + + return (0); +} + + +void systickInit (uint32_t delayMs) +{ + systickConfig ((CFG_CPU_CCLK / 1000) * delayMs); +} + +void systickDelay (uint32_t delayTicks) +{ + uint32_t curTicks; + curTicks = msTicks; + + // Make sure delay is at least 1 tick in case of division, etc. + if (delayTicks == 0) delayTicks = 1; + + if (curTicks > 0x00FFFFFF - delayTicks) + { + // Rollover will occur during delay + while (msTicks >= curTicks) + { + while (msTicks < (delayTicks - (0x00FFFFFF - curTicks))); + } + } + else + { + while ((msTicks - curTicks) < delayTicks); + } +} diff --git a/macusbfb/core/systick/systick.h b/macusbfb/core/systick/systick.h new file mode 100644 index 0000000..cf19955 --- /dev/null +++ b/macusbfb/core/systick/systick.h @@ -0,0 +1,47 @@ +/**************************************************************************/ +/*! + @file systick.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _SYSTICK_H_ +#define _SYSTICK_H_ + +#include "projectconfig.h" + +void systickInit (uint32_t delayMs); +void systickDelay (uint32_t delayTicks) ; + +#endif \ No newline at end of file diff --git a/macusbfb/core/timer16/timer16.c b/macusbfb/core/timer16/timer16.c new file mode 100644 index 0000000..ec48c5d --- /dev/null +++ b/macusbfb/core/timer16/timer16.c @@ -0,0 +1,476 @@ +/**************************************************************************/ +/*! + @file timer16.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Generic code for both 16-bit timers. + + @warning 16-bit timers are limited to roughly ~0.91ms (or 910uS) on + a system running at 72MHz since: + @code + 1 mS = CFG_CPU_CCLK / 1000 + = 72000000 / 1000 + = 72000 'ticks' + @endcode + Meaning that 0xFFFF (65535) 'ticks' = 0.910208 milliseconds + or 910 microseconds. + + @section Example + + @code + #include "/core/cpu/cpu.h" + #include "/core/timer16/timer16.h" + + // Instantiated in timer16.h + extern volatile uint32_t timer16_0_counter; + ... + cpuInit(); + + // Initialise timer0 with a delay of 0xFFFF, which will cause the + // timer interrupt to fire every 65535 ticks and increment + // timer16_0_counter by 1 + timer16Init(0, 0xFFFF); + + // Enable the timer + timer16Enable(0); + + // At this point timer16_0_counter should start incrementing by 1 + // every 65535 ticks + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "timer16.h" + +volatile uint32_t timer16_0_counter = 0; +volatile uint32_t timer16_1_counter = 0; + +/**************************************************************************/ +/*! + @brief Causes a blocking delay for the specified number of + clock ticks. + + @note The exact duration of this delay depends on the speed of the + system clock, but it will invariably be short because of the + 16-bit limitation. For example, on a system with a 72MHz + clock, a 1mS delay would be equal to 72,000 ticks, which is + already above the maximum 16-bit value of 65,535. Thus, the + maximum delay measured in mS with a 72MHz clock is ~0.91mS. + + @param[in] timerNum + The 16-bit timer to user (0..1) + @param[in] delayInTicks + The number of clock ticks to delay (0..65534) + + @section Example + + @code + #include "/core/cpu/cpu.h" + #include "/core/timer16/timer16.h" + + int main(void) + { + cpuInit(); + + // Initialise timer 0 ... delay is provided but not used here + timer16Init(0, 0xFFFF); + + // Enable the timer + timer16Enable(0); + + while(1) + { + // Cause blocking delay for 36000 ticks (0.5mS @ 72MHz) + // Note: The delay must be 65534 or less (16-bit value) + timer16DelayTicks(0, 36000); + } + } + @endcode +*/ +/**************************************************************************/ +void timer16DelayTicks(uint8_t timerNum, uint16_t delayInTicks) +{ + // ToDo: Verify incoming value + + if (timerNum == 0) + { + /* Reset the timer */ + TMR_TMR16B0TCR = TMR_TMR16B0TCR_COUNTERRESET_ENABLED; + + /* Set the prescaler to zero */ + TMR_TMR16B0PR = 0x00; + + TMR_TMR16B0MR0 = delayInTicks; + + /* Reset all interrupts */ + TMR_TMR16B0IR = TMR_TMR16B0IR_MASK_ALL; + + /* Stop timer on match (MR0) */ + TMR_TMR16B0MCR = TMR_TMR16B0MCR_MR0_STOP_ENABLED; + + /* Start timer */ + TMR_TMR16B0TCR = TMR_TMR16B0TCR_COUNTERENABLE_ENABLED; + + /* Wait until the delay time has elapsed */ + while (TMR_TMR16B0TCR & TMR_TMR16B0TCR_COUNTERENABLE_ENABLED); + } + + else if (timerNum == 1) + { + /* Reset the timer */ + TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERRESET_ENABLED; + + /* Set the prescaler to zero */ + TMR_TMR16B1PR = 0x00; + + TMR_TMR16B1MR0 = delayInTicks; + + /* Reset all interrupts */ + TMR_TMR16B1IR = TMR_TMR16B1IR_MASK_ALL; + + /* Stop timer on match (MR0) */ + TMR_TMR16B1MCR = TMR_TMR16B1MCR_MR0_STOP_ENABLED; + + /* Start timer */ + TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_ENABLED; + + /* Wait until the delay time has elapsed */ + while (TMR_TMR16B1TCR & TMR_TMR16B1TCR_COUNTERENABLE_ENABLED); + } + + return; +} + +/**************************************************************************/ +/*! + @brief Causes a blocking delay for the specified number of + microseconds + + @warning The maximum delay in uS will depend on the clock speed, + but running at 72MHz the maximum delay (MR = 0xFFFF) + would be 910uS (0xFFFF / 72 = 910), or 0.91 milliseconds. + + @param[in] timerNum + The 16-bit timer to user (0..1) + @param[in] delayInUs + The number of microseconds to wait + + @section Example + + @code + #include "/core/cpu/cpu.h" + #include "/core/timer16/timer16.h" + + int main(void) + { + cpuInit(); + + // Initialise timer 0 ... delay is provided but not used here + timer16Init(0, 0xFFFF); + + // Enable the timer + timer16Enable(0); + + while(1) + { + // Cause blocking delay for 500 microseconds (0.5mS) + timer16DelayUS(0, 500); + } + } + @endcode +*/ +/**************************************************************************/ +void timer16DelayUS(uint8_t timerNum, uint16_t delayInUS) +{ + // ToDo: Check if the appropriate timer is enabled first? + + if (timerNum == 0) + { + /* Reset the timer */ + TMR_TMR16B0TCR = TMR_TMR16B0TCR_COUNTERRESET_ENABLED; + + /* Set the prescaler to zero */ + TMR_TMR16B0PR = 0x00; + + TMR_TMR16B0MR0 = delayInUS * ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV)/1000000); + + /* Reset all interrupts */ + TMR_TMR16B0IR = TMR_TMR16B0IR_MASK_ALL; + + /* Stop timer on match (MR0) */ + TMR_TMR16B0MCR = TMR_TMR16B0MCR_MR0_STOP_ENABLED; + + /* Start timer */ + TMR_TMR16B0TCR = TMR_TMR16B0TCR_COUNTERENABLE_ENABLED; + + /* Wait until the delay time has elapsed */ + while (TMR_TMR16B0TCR & TMR_TMR16B0TCR_COUNTERENABLE_ENABLED); + } + + else if (timerNum == 1) + { + /* Reset the timer */ + TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERRESET_ENABLED; + + /* Set the prescaler to zero */ + TMR_TMR16B1PR = 0x00; + + TMR_TMR16B1MR0 = delayInUS * ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV)/1000000); + + /* Reset all interrupts */ + TMR_TMR16B1IR = TMR_TMR16B1IR_MASK_ALL; + + /* Stop timer on match (MR0) */ + TMR_TMR16B1MCR = TMR_TMR16B1MCR_MR0_STOP_ENABLED; + + /* Start timer */ + TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_ENABLED; + + /* Wait until the delay time has elapsed */ + while (TMR_TMR16B1TCR & TMR_TMR16B1TCR_COUNTERENABLE_ENABLED); + } + + return; +} + +/**************************************************************************/ +/*! + @brief Interrupt handler for 16-bit timer 0 +*/ +/**************************************************************************/ +void TIMER16_0_IRQHandler(void) +{ + /* Clear the interrupt flag */ + TMR_TMR16B0IR = TMR_TMR16B0IR_MR0; + + /* Increment timer counter by 1 (it will automatically roll back to 0) */ + timer16_0_counter++; + return; +} + +/**************************************************************************/ +/*! + @brief Interrupt handler for 16-bit timer 1 +*/ +/**************************************************************************/ +void TIMER16_1_IRQHandler(void) +{ + /* Clear the interrupt flag */ + TMR_TMR16B1IR = TMR_TMR16B1IR_MR0; + + /* Increment timer counter by 1 (it will automatically roll back to 0) */ + timer16_1_counter++; + return; +} + +/**************************************************************************/ +/*! + @brief Enables the specified timer + + @param[in] timerNum + The 16-bit timer to enable (0..1) +*/ +/**************************************************************************/ +void timer16Enable(uint8_t timerNum) +{ + if ( timerNum == 0 ) + { + TMR_TMR16B0TCR = TMR_TMR16B0TCR_COUNTERENABLE_ENABLED; + } + + else if (timerNum == 1) + { + TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_ENABLED; + } + + return; +} + +/**************************************************************************/ +/*! + @brief Disables the specified timer + + @param[in] timerNum + The 16-bit timer to disable (0..1) +*/ +/**************************************************************************/ +void timer16Disable(uint8_t timerNum) +{ + if ( timerNum == 0 ) + { + TMR_TMR16B0TCR = TMR_TMR16B0TCR_COUNTERENABLE_DISABLED; + } + + else if (timerNum == 1) + { + TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_DISABLED; + } + + return; +} + +/**************************************************************************/ +/*! + @brief Resets the specified timer + + @param[in] timerNum + The 16-bit timer to reset (0..1) +*/ +/**************************************************************************/ +void timer16Reset(uint8_t timerNum) +{ + uint32_t regVal; + + if ( timerNum == 0 ) + { + regVal = TMR_TMR16B0TCR; + regVal |= TMR_TMR16B0TCR_COUNTERRESET_ENABLED; + TMR_TMR16B0TCR = regVal; + } + + else if (timerNum == 1) + { + regVal = TMR_TMR16B1TCR; + regVal |= TMR_TMR16B1TCR_COUNTERRESET_ENABLED; + TMR_TMR16B1TCR = regVal; + } + + return; +} + +/**************************************************************************/ +/*! + @brief Initialises the specified 16-bit timer, sets the timer + interval, resets the timer, and configures the interrupt + handler. + + Initialises a 16-bit timer with the supplied timer interval (the + amount of time that passes between each timer 'tick'). Every time that + this interval elapses, the timer's interrupt will be fired and the + appropriate counter variable will be incremented by one (For example, + with CT16B0, 'timer16_0_counter' would be incremented). + + @param[in] timerNum + The 16-bit timer to initiliase (0..1) + @param[in] timerInterval + The number of clock 'ticks' between resets (0..65534) + + @warning Care needs to be taken when configuring the timers since + the pins are all multiplexed with other peripherals. This + code is provided as a starting point, but it will need to + be adjusted according to your own situation and + pin/peripheral requirements +*/ +/**************************************************************************/ +void timer16Init(uint8_t timerNum, uint16_t timerInterval) +{ + // If timerInterval is invalid, use the default value + if (timerInterval < 1) + { + timerInterval = TIMER16_DEFAULTINTERVAL; + } + + if ( timerNum == 0 ) + { + /* Enable the clock for CT16B0 */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B0); + + /* The physical pins associated with CT16B0 are not enabled by + default in order to avoid conflicts with other peripherals. + Pin 0.10 (CT16B0_MAT2), for example, can not be used while + debugging with a hardware debugger. If you require one or + more of these pins, simply uncomment the code below */ + + /* Configure PIO0.2 as Timer0_16 CAP0 */ + // IOCON_PIO0_2 &= ~IOCON_PIO0_2_FUNC_MASK; + // IOCON_PIO0_2 |= IOCON_PIO0_2_FUNC_CT16B0_CAP0; + + /* Configure PIO0.8 as Timer0_16 MAT0 */ + // IOCON_PIO0_8 &= ~IOCON_PIO0_8_FUNC_MASK; + // IOCON_PIO0_8 |= IOCON_PIO0_8_FUNC_CT16B0_MAT0; + + /* Configure PIO0.9 as Timer0_16 MAT1 */ + // IOCON_PIO0_9 &= ~IOCON_PIO0_9_FUNC_MASK; + // IOCON_PIO0_9 |= IOCON_PIO0_9_FUNC_CT16B0_MAT1; + + /* Configure PIO0.10 as Timer0_16 MAT3 */ + // IOCON_JTAG_TCK_PIO0_10 &= ~IOCON_JTAG_TCK_PIO0_10_FUNC_MASK; + // IOCON_JTAG_TCK_PIO0_10 |= IOCON_JTAG_TCK_PIO0_10_FUNC_CT16B0_MAT2; + + timer16_0_counter = 0; + TMR_TMR16B0MR0 = timerInterval; + + /* Configure match control register to raise an interrupt and reset on MR0 */ + TMR_TMR16B0MCR = (TMR_TMR16B0MCR_MR0_INT_ENABLED | TMR_TMR16B0MCR_MR0_RESET_ENABLED); + + /* Enable the TIMER0 interrupt */ + NVIC_EnableIRQ(TIMER_16_0_IRQn); + } + + else if ( timerNum == 1 ) + { + /* Enable the clock for CT16B1 */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1); + + /* The physical pins associated with CT16B0 are not enabled by + default in order to avoid conflicts with other peripherals. + Pin 0.10 (CT16B0_MAT2), for example, can not be used while + debugging with a hardware debugger. If you require one or + more of these pins, simply uncomment the code below */ + + /* Configure PIO1.8 as Timer1_16 CAP0 */ + // IOCON_PIO1_8 &= ~IOCON_PIO1_8_FUNC_MASK; + // IOCON_PIO1_8 |= IOCON_PIO1_8_FUNC_CT16B1_CAP0; + + /* Configure PIO1.9 as Timer1_16 MAT0 */ + // IOCON_PIO1_9 &= ~IOCON_PIO1_9_FUNC_MASK; + // IOCON_PIO1_9 |= IOCON_PIO1_9_FUNC_CT16B1_MAT0; + + /* Configure PIO1.10 as Timer1_16 MAT1 */ + // IOCON_PIO1_10 &= ~IOCON_PIO1_10_FUNC_MASK; + // IOCON_PIO1_10 |= IOCON_PIO1_10_FUNC_CT16B1_MAT1; + + timer16_1_counter = 0; + TMR_TMR16B1MR0 = timerInterval; + + /* Configure match control register to raise an interrupt and reset on MR0 */ + TMR_TMR16B1MCR = (TMR_TMR16B1MCR_MR0_INT_ENABLED | TMR_TMR16B1MCR_MR0_RESET_ENABLED); + + /* Enable the TIMER1 Interrupt */ + NVIC_EnableIRQ(TIMER_16_1_IRQn); + } + return; +} diff --git a/macusbfb/core/timer16/timer16.h b/macusbfb/core/timer16/timer16.h new file mode 100644 index 0000000..dda4d9c --- /dev/null +++ b/macusbfb/core/timer16/timer16.h @@ -0,0 +1,59 @@ +/**************************************************************************/ +/*! + @file timer16.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef __TIMER16_H__ +#define __TIMER16_H__ + +#include "projectconfig.h" + +#define TIMER16_DEFAULTINTERVAL (0xFFFF) // ~0.91mS @ 72MHz, ~1.37mS @ 48MHz + +#define TIMER16_CCLK_100US ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 10000) +#define TIMER16_CCLK_1MS ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 1000) + +void TIMER16_0_IRQHandler(void); +void TIMER16_1_IRQHandler(void); + +void timer16DelayTicks(uint8_t timerNum, uint16_t delayInTicks); +void timer16DelayUS(uint8_t timerNum, uint16_t delayInUS); +void timer16Enable(uint8_t timerNum); +void timer16Disable(uint8_t timerNum); +void timer16Reset(uint8_t timerNum); +void timer16Init(uint8_t timerNum, uint16_t timerInterval); + +#endif diff --git a/macusbfb/core/timer32/timer32.c b/macusbfb/core/timer32/timer32.c new file mode 100644 index 0000000..cccd377 --- /dev/null +++ b/macusbfb/core/timer32/timer32.c @@ -0,0 +1,344 @@ +/**************************************************************************/ +/*! + @file timer32.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Generic code for 32-bit timers. By default, the timers are configured + to generate an interrupt once every 100 microseconds, incrementing a + global variable once per tick. + + @warning Please note that the ROM-based USB drivers on the LPC1343 + require the use of 32-bit Timer 1. If you plan on using the + ROM-based USB functionality, you should restrict your timer + usage to 32-bit timer 0. + + @section Example + + @code + #include "/core/cpu/cpu.h" + #include "/core/timer32/timer32.h" + ... + cpuInit(); + + // Initialise 32-bit timer 0 with 100uS ticks + timer32Init(0, TIMER32_DEFAULTINTERVAL); + + // Enable timer 0 + timer32Enable(0); + + // Cause a blocking delay for 1 second (1000mS) + timer32Delay(0, TIMER32_DELAY_1MS * 1000); + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "timer32.h" + +volatile uint32_t timer32_0_counter = 0; +volatile uint32_t timer32_1_counter = 0; + +/**************************************************************************/ +/*! + @brief Causes a blocking delay for the specified number of + timer ticks. The duration of each 'tick' is determined by + the 'timerInterval' property supplied to timer32Init. + + @param[in] timerNum + The 32-bit timer to user (0..1) + @param[in] delay + The number of counter increments to wait +*/ +/**************************************************************************/ +void timer32Delay(uint8_t timerNum, uint32_t delay) +{ + uint32_t curTicks; + + if (timerNum == 0) + { + curTicks = timer32_0_counter; + if (curTicks > 0xFFFFFFFF - delay) + { + // Rollover will occur during delay + while (timer32_0_counter >= curTicks) + { + while (timer32_0_counter < (delay - (0xFFFFFFFF - curTicks))); + } + } + else + { + while ((timer32_0_counter - curTicks) < delay); + } + } + + else if (timerNum == 1) + { + curTicks = timer32_1_counter; + if (curTicks > 0xFFFFFFFF - delay) + { + // Rollover will occur during delay + while (timer32_1_counter >= curTicks) + { + while (timer32_1_counter < (delay - (0xFFFFFFFF - curTicks))); + } + } + else + { + while ((timer32_1_counter - curTicks) < delay); + } + } + + return; +} + +/**************************************************************************/ +/*! + @brief Interrupt handler for 32-bit timer 0 +*/ +/**************************************************************************/ +void TIMER32_0_IRQHandler(void) +{ + /* Clear the interrupt flag */ + TMR_TMR32B0IR = TMR_TMR32B0IR_MR0; + + /* If you wish to perform some action after each timer 'tick' (such as + incrementing a counter variable) you can do so here */ + timer32_0_counter++; + + return; +} + +/**************************************************************************/ +/*! + @brief Interrupt handler for 32-bit timer 1 +*/ +/**************************************************************************/ +void TIMER32_1_IRQHandler(void) +{ + /* Clear the interrupt flag */ + TMR_TMR32B1IR = TMR_TMR32B1IR_MR0; + + /* If you wish to perform some action after each timer 'tick' (such as + incrementing a counter variable) you can do so here */ + timer32_1_counter++; + + return; +} + +/**************************************************************************/ +/*! + @brief Enables the specified timer + + @param[in] timerNum + The 32-bit timer to enable (0..1) +*/ +/**************************************************************************/ +void timer32Enable(uint8_t timerNum) +{ + if ( timerNum == 0 ) + { + TMR_TMR32B0TCR = TMR_TMR32B0TCR_COUNTERENABLE_ENABLED; + } + + else if (timerNum == 1) + { + TMR_TMR32B1TCR = TMR_TMR32B1TCR_COUNTERENABLE_ENABLED; + } + + return; +} + +/**************************************************************************/ +/*! + @brief Disables the specified timer + + @param[in] timerNum + The 32-bit timer to disable (0..1) +*/ +/**************************************************************************/ +void timer32Disable(uint8_t timerNum) +{ + if ( timerNum == 0 ) + { + TMR_TMR32B0TCR = TMR_TMR32B0TCR_COUNTERENABLE_DISABLED; + } + + else if (timerNum == 1) + { + TMR_TMR32B1TCR = TMR_TMR32B1TCR_COUNTERENABLE_DISABLED; + } + + return; +} + +/**************************************************************************/ +/*! + @brief Resets the specified timer + + @param[in] timerNum + The 32-bit timer to reset (0..1) +*/ +/**************************************************************************/ +void timer32Reset(uint8_t timerNum) +{ + uint32_t regVal; + + if ( timerNum == 0 ) + { + regVal = TMR_TMR32B0TCR; + regVal |= TMR_TMR32B0TCR_COUNTERRESET_ENABLED; + TMR_TMR32B0TCR = regVal; + } + + else if (timerNum == 1) + { + regVal = TMR_TMR32B1TCR; + regVal |= TMR_TMR32B1TCR_COUNTERRESET_ENABLED; + TMR_TMR32B1TCR = regVal; + } + + return; +} + +/**************************************************************************/ +/*! + @brief Initialises the specified 32-bit timer, and configures the + timer to raise an interrupt and reset on match on MR0. + + @param[in] timerNum + The 32-bit timer to initiliase (0..1) + @param[in] timerInterval + The number of clock 'ticks' between resets (0..0xFFFFFFFF) + + @note Care needs to be taken when configuring the timers since the + pins are all multiplexed with other peripherals. This code is + provided as a starting point, but it will need to be adjusted + according to your own situation and pin/peripheral requirements +*/ +/**************************************************************************/ +void timer32Init(uint8_t timerNum, uint32_t timerInterval) +{ + // If timerInterval is invalid, use the default value + if (timerInterval < 1) + { + timerInterval = TIMER32_DEFAULTINTERVAL; + } + + if ( timerNum == 0 ) + { + /* Enable the clock for CT32B0 */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT32B0); + + /* The physical pins associated with CT32B0 are not enabled by + default in order to avoid conflicts with other peripherals. If + you wish to use any of the pin-dependant functionality, simply + uncomment the appropriate lines below. */ + + /* Configure PIO1.5 as Timer0_32 CAP0 */ + // IOCON_PIO1_5 &= ~IOCON_PIO1_5_FUNC_MASK; + // IOCON_PIO1_5 |= IOCON_PIO1_5_FUNC_CT32B0_CAP0; + + /* Configure PIO1.6 as Timer0_32 MAT0 */ + // IOCON_PIO1_6 &= ~IOCON_PIO1_6_FUNC_MASK; + // IOCON_PIO1_6 |= IOCON_PIO1_6_FUNC_CT32B0_MAT0; + + /* Configure PIO1.7 as Timer0_32 MAT1 */ + // IOCON_PIO1_7 &= ~IOCON_PIO1_7_FUNC_MASK; + // IOCON_PIO1_7 |= IOCON_PIO1_7_FUNC_CT32B0_MAT1; + + /* Configure PIO0.1 as Timer0_32 MAT2 */ + // IOCON_PIO0_1 &= ~IOCON_PIO0_1_FUNC_MASK; + // IOCON_PIO0_1 |= IOCON_PIO0_1_FUNC_CT32B0_MAT2; + + /* Configure PIO0.11 as Timer0_32 MAT3 */ + /* Note: This pint can not be used with JTAG/SWD */ + // IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK; + // IOCON_JTAG_TDI_PIO0_11 |= IOCON_JTAG_TDI_PIO0_11_FUNC_CT32B0_MAT3; + + timer32_0_counter = 0; + TMR_TMR32B0MR0 = timerInterval; + + /* Configure match control register to raise an interrupt and reset on MR0 */ + TMR_TMR32B0MCR = (TMR_TMR32B0MCR_MR0_INT_ENABLED | TMR_TMR32B0MCR_MR0_RESET_ENABLED); + + /* Enable the TIMER0 interrupt */ + NVIC_EnableIRQ(TIMER_32_0_IRQn); + } + + else if ( timerNum == 1 ) + { + /* Enable the clock for CT32B1 */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT32B1); + + /* The physical pins associated with CT32B0 are not enabled by + default in order to avoid conflicts with other peripherals. */ + + /* Configure PIO1.0 as Timer1_32 CAP0 */ + /* Note: This pint can not be used with JTAG/SWD */ + // IOCON_JTAG_TMS_PIO1_0 &= ~IOCON_JTAG_TMS_PIO1_0_FUNC_MASK; + // IOCON_JTAG_TMS_PIO1_0 |= IOCON_JTAG_TMS_PIO1_0_FUNC_CT32B1_CAP0; + + /* Configure PIO1.1 as Timer1_32 MAT0 */ + /* Note: This pint can not be used with JTAG/SWD */ + // IOCON_JTAG_TDO_PIO1_1 &= ~IOCON_JTAG_TDO_PIO1_1_FUNC_MASK; + // IOCON_JTAG_TDO_PIO1_1 |= IOCON_JTAG_TDO_PIO1_1_FUNC_CT32B1_MAT0; + + /* Configure PIO1.2 as Timer1_32 MAT1 */ + /* Note: This pint can not be used with JTAG/SWD */ + // IOCON_JTAG_nTRST_PIO1_2 &= ~IOCON_JTAG_nTRST_PIO1_2_FUNC_MASK; + // IOCON_JTAG_nTRST_PIO1_2 |= IOCON_JTAG_nTRST_PIO1_2_FUNC_CT32B1_MAT1; + + /* Configure PIO1.3 as Timer1_32 MAT2 */ + /* Note: This pint can not be used with JTAG/SWD */ + // IOCON_SWDIO_PIO1_3 &= ~IOCON_SWDIO_PIO1_3_FUNC_MASK; + // IOCON_SWDIO_PIO1_3 |= IOCON_SWDIO_PIO1_3_FUNC_CT32B1_MAT2; + + /* Configure PIO1.4 as Timer1_32 MAT3 */ + // IOCON_PIO1_4 &= ~IOCON_PIO1_4_FUNC_MASK; + // IOCON_PIO1_4 |= IOCON_PIO1_4_FUNC_CT32B1_MAT3; + + timer32_1_counter = 0; + TMR_TMR32B1MR0 = timerInterval; + + /* Configure match control register to raise an interrupt and reset on MR0 */ + TMR_TMR32B1MCR = (TMR_TMR32B1MCR_MR0_INT_ENABLED | TMR_TMR32B1MCR_MR0_RESET_ENABLED); + + /* Enable the TIMER1 Interrupt */ + NVIC_EnableIRQ(TIMER_32_1_IRQn); + } + return; +} + + diff --git a/macusbfb/core/timer32/timer32.h b/macusbfb/core/timer32/timer32.h new file mode 100644 index 0000000..ef2dc5e --- /dev/null +++ b/macusbfb/core/timer32/timer32.h @@ -0,0 +1,66 @@ +/**************************************************************************/ +/*! + @file timer32.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef __TIMER32_H__ +#define __TIMER32_H__ + +#include "projectconfig.h" + +#define TIMER32_CCLK_1US ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 1000000) +#define TIMER32_CCLK_10US ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 100000) +#define TIMER32_CCLK_100US ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 10000) +#define TIMER32_CCLK_1MS ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 1000) +#define TIMER32_CCLK_10MS ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 100) +#define TIMER32_CCLK_100MS ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 10) +#define TIMER32_CCLK_1S (CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) +#define TIMER32_DEFAULTINTERVAL (TIMER32_CCLK_100US) + +#define TIMER32_DELAY_100US (1) // 100uS delay = 1 tick +#define TIMER32_DELAY_1MS (10) // 1mS delay = 10 ticks +#define TIMER32_DELAY_1S (10000) // 1S delay = 10000 ticks + +void TIMER32_0_IRQHandler(void); +void TIMER32_1_IRQHandler(void); + +void timer32Delay(uint8_t timerNum, uint32_t delay); +void timer32Enable(uint8_t timerNum); +void timer32Disable(uint8_t timerNum); +void timer32Reset(uint8_t timerNum); +void timer32Init(uint8_t timerNum, uint32_t timerInterval); + +#endif diff --git a/macusbfb/core/uart/uart.c b/macusbfb/core/uart/uart.c new file mode 100644 index 0000000..ca91562 --- /dev/null +++ b/macusbfb/core/uart/uart.c @@ -0,0 +1,346 @@ +/**************************************************************************/ +/*! + @file uart.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Generic code for UART-based communication. Incoming text is stored + in a FIFO Queue for safer processing. + + @section Example: Sending text via UART + + @code + #include "core/cpu/cpu.h" + #include "core/uart/uart.h" + ... + #define UARTBUFFERSIZE 5 + ... + cpuInit(); + uartInit(57600); + ... + uint8_t uartBuffer[UARTBUFFERSIZE] = { 'T', 'e', 's', 't', '\n' }; + + // Send contents of uartBuffer + uartSend((uint8_t *)uartBuffer, UARTBUFFERSIZE); + @endcode + + @section Example: Reading from UART + + @code + + #include "core/cpu/cpu.h" + #include "core/uart/uart.h" + + cpuInit(); + uartInit(57600); + + // Get a reference to the UART control block + uart_pcb_t *pcb = uartGetPCB(); + + // Read any text available in the queue + while (uartRxBufferDataPending()) + { + // Read the first available character + uint8_t c = uartRxBufferRead(); + + // read out the data in the buffer and echo it back to the host. + switch (c) + { + case '\r': + printf("\n\r"); + break; + default: + printf("%c", c); + break; + } + } + + #endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include + +#include "uart.h" + +#ifdef CFG_INTERFACE_UART + #include "core/cmd/cmd.h" +#endif + +/**************************************************************************/ +/*! + UART protocol control block, which is used to safely access the + RX FIFO buffer from elsewhere in the code. This should be accessed + through 'uartGetPCB()'. +*/ +/**************************************************************************/ +static uart_pcb_t pcb; + +/**************************************************************************/ +/*! + IRQ to handle incoming data, etc. +*/ +/**************************************************************************/ +void UART_IRQHandler(void) +{ + uint8_t IIRValue, LSRValue; + uint8_t Dummy = Dummy; + + IIRValue = UART_U0IIR; + IIRValue &= ~(UART_U0IIR_IntStatus_MASK); /* skip pending bit in IIR */ + IIRValue &= UART_U0IIR_IntId_MASK; /* check bit 1~3, interrupt identification */ + + // 1.) Check receiver line status + if (IIRValue == UART_U0IIR_IntId_RLS) + { + LSRValue = UART_U0LSR; + // Check for errors + if (LSRValue & (UART_U0LSR_OE | UART_U0LSR_PE | UART_U0LSR_FE | UART_U0LSR_RXFE | UART_U0LSR_BI)) + { + /* There are errors or break interrupt */ + /* Read LSR will clear the interrupt */ + pcb.status = LSRValue; + Dummy = UART_U0RBR; /* Dummy read on RX to clear interrupt, then bail out */ + return; + } + // No error and receive data is ready + if (LSRValue & UART_U0LSR_RDR_DATA) + { + /* If no error on RLS, normal ready, save into the data buffer. */ + /* Note: read RBR will clear the interrupt */ + uartRxBufferWrite(UART_U0RBR); + } + } + + // 2.) Check receive data available + else if (IIRValue == UART_U0IIR_IntId_RDA) + { + // Add incoming text to UART buffer + uartRxBufferWrite(UART_U0RBR); + } + + // 3.) Check character timeout indicator + else if (IIRValue == UART_U0IIR_IntId_CTI) + { + /* Bit 9 as the CTI error */ + pcb.status |= 0x100; + } + + // 4.) Check THRE (transmit holding register empty) + else if (IIRValue == UART_U0IIR_IntId_THRE) + { + /* Check status in the LSR to see if valid data in U0THR or not */ + LSRValue = UART_U0LSR; + if (LSRValue & UART_U0LSR_THRE) + { + pcb.pending_tx_data = 0; + } + else + { + pcb.pending_tx_data= 1; + } + } + return; +} + +/**************************************************************************/ +/*! + @brief Get a pointer to the UART's protocol control block, which can + be used to control the RX FIFO buffer and check whether UART + has already been initialised or not. + + @section Example + + @code + // Make sure that UART is initialised + uart_pcb_t *pcb = uartGetPCB(); + if (!pcb->initialised) + { + uartInit(CFG_UART_BAUDRATE); + } + @endcode + +*/ +/**************************************************************************/ +uart_pcb_t *uartGetPCB() +{ + return &pcb; +} + +/**************************************************************************/ +/*! + @brief Initialises UART at the specified baud rate. + + @param[in] baudRate + The baud rate to use when configuring the UART. +*/ +/**************************************************************************/ +void uartInit(uint32_t baudrate) +{ + uint32_t fDiv; + uint32_t regVal; + + NVIC_DisableIRQ(UART_IRQn); + + // Clear protocol control blocks + memset(&pcb, 0, sizeof(uart_pcb_t)); + pcb.pending_tx_data = 0; + uartRxBufferInit(); + + /* Set 1.6 UART RXD */ + IOCON_PIO1_6 &= ~IOCON_PIO1_6_FUNC_MASK; + IOCON_PIO1_6 |= IOCON_PIO1_6_FUNC_UART_RXD; + + /* Set 1.7 UART TXD */ + IOCON_PIO1_7 &= ~IOCON_PIO1_7_FUNC_MASK; + IOCON_PIO1_7 |= IOCON_PIO1_7_FUNC_UART_TXD; + + /* Enable UART clock */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_UART); + SCB_UARTCLKDIV = SCB_UARTCLKDIV_DIV1; /* divided by 1 */ + + /* 8 bits, no Parity, 1 Stop bit */ + UART_U0LCR = (UART_U0LCR_Word_Length_Select_8Chars | + UART_U0LCR_Stop_Bit_Select_1Bits | + UART_U0LCR_Parity_Disabled | + UART_U0LCR_Parity_Select_OddParity | + UART_U0LCR_Break_Control_Disabled | + UART_U0LCR_Divisor_Latch_Access_Enabled); + + /* Baud rate */ + regVal = SCB_UARTCLKDIV; + fDiv = (((CFG_CPU_CCLK * SCB_SYSAHBCLKDIV)/regVal)/16)/baudrate; + + UART_U0DLM = fDiv / 256; + UART_U0DLL = fDiv % 256; + + /* Set DLAB back to 0 */ + UART_U0LCR = (UART_U0LCR_Word_Length_Select_8Chars | + UART_U0LCR_Stop_Bit_Select_1Bits | + UART_U0LCR_Parity_Disabled | + UART_U0LCR_Parity_Select_OddParity | + UART_U0LCR_Break_Control_Disabled | + UART_U0LCR_Divisor_Latch_Access_Disabled); + + /* Enable and reset TX and RX FIFO. */ + UART_U0FCR = (UART_U0FCR_FIFO_Enabled | + UART_U0FCR_Rx_FIFO_Reset | + UART_U0FCR_Tx_FIFO_Reset); + + /* Read to clear the line status. */ + regVal = UART_U0LSR; + + /* Ensure a clean start, no data in either TX or RX FIFO. */ + while (( UART_U0LSR & (UART_U0LSR_THRE|UART_U0LSR_TEMT)) != (UART_U0LSR_THRE|UART_U0LSR_TEMT) ); + while ( UART_U0LSR & UART_U0LSR_RDR_DATA ) + { + /* Dump data from RX FIFO */ + regVal = UART_U0RBR; + } + + /* Set the initialised flag in the protocol control block */ + pcb.initialised = 1; + + /* Enable the UART Interrupt */ + NVIC_EnableIRQ(UART_IRQn); + UART_U0IER = UART_U0IER_RBR_Interrupt_Enabled | UART_U0IER_RLS_Interrupt_Enabled; + + return; +} + +/**************************************************************************/ +/*! + @brief Sends the contents of supplied text buffer over UART. + + @param[in] bufferPtr + Pointer to the text buffer + @param[in] bufferPtr + The size of the text buffer + + @section Example + + @code + // Set 5-character text buffer + uint8_t uartBuffer[5] = { 'T', 'e', 's', 't', '\n' }; + // Send contents of uartBuffer + uartSend((uint8_t *)uartBuffer, 5); + @endcode + +*/ +/**************************************************************************/ +void uartSend (uint8_t *bufferPtr, uint32_t length) +{ + while (length != 0) + { + /* THRE status, contain valid data */ + while ( !(UART_U0LSR & UART_U0LSR_THRE) ); + UART_U0THR = *bufferPtr; + + bufferPtr++; + length--; + } + + return; +} + +/**************************************************************************/ +/*! + @brief Sends a single byte over UART. + + @param[in] byte + Byte value to send + + @section Example + + @code + // Send 0xFF over UART + uartSendByte(0xFF); + // Send 'B' over UART (note single quotes) + uartSendByte('B'); + @endcode + +*/ +/**************************************************************************/ +void uartSendByte (uint8_t byte) +{ + /* THRE status, contain valid data */ + while ( !(UART_U0LSR & UART_U0LSR_THRE) ); + UART_U0THR = byte; + + return; +} + + + diff --git a/macusbfb/core/uart/uart.h b/macusbfb/core/uart/uart.h new file mode 100644 index 0000000..4cf3a45 --- /dev/null +++ b/macusbfb/core/uart/uart.h @@ -0,0 +1,76 @@ +/**************************************************************************/ +/*! + @file uart.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef __UART_H__ +#define __UART_H__ + +#include "projectconfig.h" + +// Buffer used for circular fifo +typedef struct _uart_buffer_t +{ + uint8_t ep_dir; + volatile uint8_t len; + volatile uint8_t wr_ptr; + volatile uint8_t rd_ptr; + uint8_t buf[CFG_UART_BUFSIZE]; +} uart_buffer_t; + +// UART Protocol control block +typedef struct _uart_pcb_t +{ + BOOL initialised; + uint32_t status; + uint32_t pending_tx_data; + uart_buffer_t rxfifo; +} uart_pcb_t; + +void UART_IRQHandler(void); +uart_pcb_t *uartGetPCB(); +void uartInit(uint32_t Baudrate); +void uartSend(uint8_t *BufferPtr, uint32_t Length); +void uartSendByte (uint8_t byte); + +// Rx Buffer access control +void uartRxBufferInit(); +uint8_t uartRxBufferRead(); +void uartRxBufferWrite(uint8_t data); +void uartRxBufferClearFIFO(); +uint8_t uartRxBufferDataPending(); + +#endif diff --git a/macusbfb/core/uart/uart_buf.c b/macusbfb/core/uart/uart_buf.c new file mode 100644 index 0000000..48b153b --- /dev/null +++ b/macusbfb/core/uart/uart_buf.c @@ -0,0 +1,129 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. +*******************************************************************/ + +/**************************************************************************/ +/*! + @file uart_buf.c + @author Christopher Wang (Freaklabs) + Modified by: K. Townsend (microBuilder.eu) + @date 19 May 2010 + + Original code taken from the FreakUSB Open Source USB Device Stack + http://freaklabs.org/index.php/FreakUSB-Open-Source-USB-Device-Stack.html + + If it works well, you can thank Akiba at Freaklabs. If it fails + miserably, you can blame me (since parts of it it were rather + ungraciously modified). :-) + +*/ +/**************************************************************************/ + +#include "uart.h" + +/**************************************************************************/ +/*! + Initialises the RX FIFO buffer +*/ +/**************************************************************************/ +void uartRxBufferInit() +{ + uart_pcb_t *pcb = uartGetPCB(); + pcb->rxfifo.len = 0; +} + +/**************************************************************************/ +/*! + Read one byte out of the RX buffer. This function will return the byte + located at the array index of the read pointer, and then increment the + read pointer index. If the read pointer exceeds the maximum buffer + size, it will roll over to zero. +*/ +/**************************************************************************/ +uint8_t uartRxBufferRead() +{ + uart_pcb_t *pcb = uartGetPCB(); + uint8_t data; + + data = pcb->rxfifo.buf[pcb->rxfifo.rd_ptr]; + pcb->rxfifo.rd_ptr = (pcb->rxfifo.rd_ptr + 1) % CFG_UART_BUFSIZE; + pcb->rxfifo.len--; + return data; +} + +/**************************************************************************/ +/*! + Write one byte into the RX buffer. This function will write one + byte into the array index specified by the write pointer and increment + the write index. If the write index exceeds the max buffer size, then it + will roll over to zero. +*/ +/**************************************************************************/ +void uartRxBufferWrite(uint8_t data) +{ + uart_pcb_t *pcb = uartGetPCB(); + + pcb->rxfifo.buf[pcb->rxfifo.wr_ptr] = data; + pcb->rxfifo.wr_ptr = (pcb->rxfifo.wr_ptr + 1) % CFG_UART_BUFSIZE; + pcb->rxfifo.len++; +} + +/**************************************************************************/ +/*! + Clear the fifo read and write pointers and set the length to zero. +*/ +/**************************************************************************/ +void uartRxBufferClearFIFO() +{ + uart_pcb_t *pcb = uartGetPCB(); + + pcb->rxfifo.rd_ptr = 0; + pcb->rxfifo.wr_ptr = 0; + pcb->rxfifo.len = 0; +} + +/**************************************************************************/ +/*! + Check whether there is any data pending on the RX buffer. +*/ +/**************************************************************************/ +uint8_t uartRxBufferDataPending() +{ + uart_pcb_t *pcb = uartGetPCB(); + + if (pcb->rxfifo.len != 0) + { + return 1; + } + + return 0; +} diff --git a/macusbfb/core/usbcdc/cdc.h b/macusbfb/core/usbcdc/cdc.h new file mode 100644 index 0000000..f7af7d3 --- /dev/null +++ b/macusbfb/core/usbcdc/cdc.h @@ -0,0 +1,236 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: CDC.h + * Purpose: USB Communication Device Class Definitions + * Version: V1.00 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#ifndef __CDC_H +#define __CDC_H + +/*---------------------------------------------------------------------------- + * Definitions based on usbcdc11.pdf (www.usb.org) + *---------------------------------------------------------------------------*/ +// Communication device class specification version 1.10 +#define CDC_V1_10 0x0110 + +// Communication interface class code +// (usbcdc11.pdf, 4.2, Table 15) +#define CDC_COMMUNICATION_INTERFACE_CLASS 0x02 + +// Communication interface class subclass codes +// (usbcdc11.pdf, 4.3, Table 16) +#define CDC_DIRECT_LINE_CONTROL_MODEL 0x01 +#define CDC_ABSTRACT_CONTROL_MODEL 0x02 +#define CDC_TELEPHONE_CONTROL_MODEL 0x03 +#define CDC_MULTI_CHANNEL_CONTROL_MODEL 0x04 +#define CDC_CAPI_CONTROL_MODEL 0x05 +#define CDC_ETHERNET_NETWORKING_CONTROL_MODEL 0x06 +#define CDC_ATM_NETWORKING_CONTROL_MODEL 0x07 + +// Communication interface class control protocol codes +// (usbcdc11.pdf, 4.4, Table 17) +#define CDC_PROTOCOL_COMMON_AT_COMMANDS 0x01 + +// Data interface class code +// (usbcdc11.pdf, 4.5, Table 18) +#define CDC_DATA_INTERFACE_CLASS 0x0A + +// Data interface class protocol codes +// (usbcdc11.pdf, 4.7, Table 19) +#define CDC_PROTOCOL_ISDN_BRI 0x30 +#define CDC_PROTOCOL_HDLC 0x31 +#define CDC_PROTOCOL_TRANSPARENT 0x32 +#define CDC_PROTOCOL_Q921_MANAGEMENT 0x50 +#define CDC_PROTOCOL_Q921_DATA_LINK 0x51 +#define CDC_PROTOCOL_Q921_MULTIPLEXOR 0x52 +#define CDC_PROTOCOL_V42 0x90 +#define CDC_PROTOCOL_EURO_ISDN 0x91 +#define CDC_PROTOCOL_V24_RATE_ADAPTATION 0x92 +#define CDC_PROTOCOL_CAPI 0x93 +#define CDC_PROTOCOL_HOST_BASED_DRIVER 0xFD +#define CDC_PROTOCOL_DESCRIBED_IN_PUFD 0xFE + +// Type values for bDescriptorType field of functional descriptors +// (usbcdc11.pdf, 5.2.3, Table 24) +#define CDC_CS_INTERFACE 0x24 +#define CDC_CS_ENDPOINT 0x25 + +// Type values for bDescriptorSubtype field of functional descriptors +// (usbcdc11.pdf, 5.2.3, Table 25) +#define CDC_HEADER 0x00 +#define CDC_CALL_MANAGEMENT 0x01 +#define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02 +#define CDC_DIRECT_LINE_MANAGEMENT 0x03 +#define CDC_TELEPHONE_RINGER 0x04 +#define CDC_REPORTING_CAPABILITIES 0x05 +#define CDC_UNION 0x06 +#define CDC_COUNTRY_SELECTION 0x07 +#define CDC_TELEPHONE_OPERATIONAL_MODES 0x08 +#define CDC_USB_TERMINAL 0x09 +#define CDC_NETWORK_CHANNEL 0x0A +#define CDC_PROTOCOL_UNIT 0x0B +#define CDC_EXTENSION_UNIT 0x0C +#define CDC_MULTI_CHANNEL_MANAGEMENT 0x0D +#define CDC_CAPI_CONTROL_MANAGEMENT 0x0E +#define CDC_ETHERNET_NETWORKING 0x0F +#define CDC_ATM_NETWORKING 0x10 + +// CDC class-specific request codes +// (usbcdc11.pdf, 6.2, Table 46) +// see Table 45 for info about the specific requests. +#define CDC_SEND_ENCAPSULATED_COMMAND 0x00 +#define CDC_GET_ENCAPSULATED_RESPONSE 0x01 +#define CDC_SET_COMM_FEATURE 0x02 +#define CDC_GET_COMM_FEATURE 0x03 +#define CDC_CLEAR_COMM_FEATURE 0x04 +#define CDC_SET_AUX_LINE_STATE 0x10 +#define CDC_SET_HOOK_STATE 0x11 +#define CDC_PULSE_SETUP 0x12 +#define CDC_SEND_PULSE 0x13 +#define CDC_SET_PULSE_TIME 0x14 +#define CDC_RING_AUX_JACK 0x15 +#define CDC_SET_LINE_CODING 0x20 +#define CDC_GET_LINE_CODING 0x21 +#define CDC_SET_CONTROL_LINE_STATE 0x22 +#define CDC_SEND_BREAK 0x23 +#define CDC_SET_RINGER_PARMS 0x30 +#define CDC_GET_RINGER_PARMS 0x31 +#define CDC_SET_OPERATION_PARMS 0x32 +#define CDC_GET_OPERATION_PARMS 0x33 +#define CDC_SET_LINE_PARMS 0x34 +#define CDC_GET_LINE_PARMS 0x35 +#define CDC_DIAL_DIGITS 0x36 +#define CDC_SET_UNIT_PARAMETER 0x37 +#define CDC_GET_UNIT_PARAMETER 0x38 +#define CDC_CLEAR_UNIT_PARAMETER 0x39 +#define CDC_GET_PROFILE 0x3A +#define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40 +#define CDC_SET_ETHERNET_PMP_FILTER 0x41 +#define CDC_GET_ETHERNET_PMP_FILTER 0x42 +#define CDC_SET_ETHERNET_PACKET_FILTER 0x43 +#define CDC_GET_ETHERNET_STATISTIC 0x44 +#define CDC_SET_ATM_DATA_FORMAT 0x50 +#define CDC_GET_ATM_DEVICE_STATISTICS 0x51 +#define CDC_SET_ATM_DEFAULT_VC 0x52 +#define CDC_GET_ATM_VC_STATISTICS 0x53 + +// Communication feature selector codes +// (usbcdc11.pdf, 6.2.2..6.2.4, Table 47) +#define CDC_ABSTRACT_STATE 0x01 +#define CDC_COUNTRY_SETTING 0x02 + +// Feature Status returned for ABSTRACT_STATE Selector +// (usbcdc11.pdf, 6.2.3, Table 48) +#define CDC_IDLE_SETTING (1 << 0) +#define CDC_DATA_MULTPLEXED_STATE (1 << 1) + + +// Control signal bitmap values for the SetControlLineState request +// (usbcdc11.pdf, 6.2.14, Table 51) +#define CDC_DTE_PRESENT (1 << 0) +#define CDC_ACTIVATE_CARRIER (1 << 1) + +// CDC class-specific notification codes +// (usbcdc11.pdf, 6.3, Table 68) +// see Table 67 for Info about class-specific notifications +#define CDC_NOTIFICATION_NETWORK_CONNECTION 0x00 +#define CDC_RESPONSE_AVAILABLE 0x01 +#define CDC_AUX_JACK_HOOK_STATE 0x08 +#define CDC_RING_DETECT 0x09 +#define CDC_NOTIFICATION_SERIAL_STATE 0x20 +#define CDC_CALL_STATE_CHANGE 0x28 +#define CDC_LINE_STATE_CHANGE 0x29 +#define CDC_CONNECTION_SPEED_CHANGE 0x2A + +// UART state bitmap values (Serial state notification). +// (usbcdc11.pdf, 6.3.5, Table 69) +#define CDC_SERIAL_STATE_OVERRUN (1 << 6) // receive data overrun error has occurred +#define CDC_SERIAL_STATE_PARITY (1 << 5) // parity error has occurred +#define CDC_SERIAL_STATE_FRAMING (1 << 4) // framing error has occurred +#define CDC_SERIAL_STATE_RING (1 << 3) // state of ring signal detection +#define CDC_SERIAL_STATE_BREAK (1 << 2) // state of break detection +#define CDC_SERIAL_STATE_TX_CARRIER (1 << 1) // state of transmission carrier +#define CDC_SERIAL_STATE_RX_CARRIER (1 << 0) // state of receiver carrier + + +/*---------------------------------------------------------------------------- + * Structures based on usbcdc11.pdf (www.usb.org) + *---------------------------------------------------------------------------*/ + +// Header functional descriptor +// (usbcdc11.pdf, 5.2.3.1) +// This header must precede any list of class-specific descriptors. +typedef struct _CDC_HEADER_DESCRIPTOR{ + uint8_t bFunctionLength; // size of this descriptor in bytes + uint8_t bDescriptorType; // CS_INTERFACE descriptor type + uint8_t bDescriptorSubtype; // Header functional descriptor subtype + uint16_t bcdCDC; // USB CDC specification release version +} __attribute__((packed)) CDC_HEADER_DESCRIPTOR; + +//Call management functional descriptor +// (usbcdc11.pdf, 5.2.3.2) +// Describes the processing of calls for the communication class interface. +typedef struct _CDC_CALL_MANAGEMENT_DESCRIPTOR { + uint8_t bFunctionLength; // size of this descriptor in bytes + uint8_t bDescriptorType; // CS_INTERFACE descriptor type + uint8_t bDescriptorSubtype; // call management functional descriptor subtype + uint8_t bmCapabilities; // capabilities that this configuration supports + uint8_t bDataInterface; // interface number of the data class interface used for call management (optional) +} __attribute__((packed)) CDC_CALL_MANAGEMENT_DESCRIPTOR; + +// Abstract control management functional descriptor +// (usbcdc11.pdf, 5.2.3.3) +// Describes the command supported by the communication interface class with the Abstract Control Model subclass code. +typedef struct _CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR { + uint8_t bFunctionLength; // size of this descriptor in bytes + uint8_t bDescriptorType; // CS_INTERFACE descriptor type + uint8_t bDescriptorSubtype; // abstract control management functional descriptor subtype + uint8_t bmCapabilities; // capabilities supported by this configuration +} __attribute__((packed)) CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR; + +// Union functional descriptors +// (usbcdc11.pdf, 5.2.3.8) +// Describes the relationship between a group of interfaces that can be considered to form a functional unit. +typedef struct _CDC_UNION_DESCRIPTOR { + uint8_t bFunctionLength; // size of this descriptor in bytes + uint8_t bDescriptorType; // CS_INTERFACE descriptor type + uint8_t bDescriptorSubtype; // union functional descriptor subtype + uint8_t bMasterInterface; // interface number designated as master +} __attribute__((packed)) CDC_UNION_DESCRIPTOR; + +// Union functional descriptors with one slave interface +// (usbcdc11.pdf, 5.2.3.8) +typedef struct _CDC_UNION_1SLAVE_DESCRIPTOR { + CDC_UNION_DESCRIPTOR sUnion; // Union functional descriptor + uint8_t bSlaveInterfaces[1]; // Slave interface 0 +} __attribute__((packed)) CDC_UNION_1SLAVE_DESCRIPTOR; + +// Line coding structure +// Format of the data returned when a GetLineCoding request is received +// (usbcdc11.pdf, 6.2.13) +typedef struct _CDC_LINE_CODING { + uint32_t dwDTERate; // Data terminal rate in bits per second + uint8_t bCharFormat; // Number of stop bits + uint8_t bParityType; // Parity bit type + uint8_t bDataBits; // Number of data bits +} __attribute__((packed)) CDC_LINE_CODING; + +// Notification header +// Data sent on the notification endpoint must follow this header. +// see USB_SETUP_PACKET in file usb.h +typedef USB_SETUP_PACKET CDC_NOTIFICATION_HEADER; + +#endif /* __CDC_H */ + diff --git a/macusbfb/core/usbcdc/cdcuser.c b/macusbfb/core/usbcdc/cdcuser.c new file mode 100644 index 0000000..07236df --- /dev/null +++ b/macusbfb/core/usbcdc/cdcuser.c @@ -0,0 +1,371 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: cdcuser.c + * Purpose: USB Communication Device Class User module + * Version: V1.10 + *---------------------------------------------------------------------------- +* This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#include "projectconfig.h" + +#include "usb.h" +#include "usbhw.h" +#include "usbcfg.h" +#include "usbcore.h" +#include "cdc.h" +#include "cdcuser.h" + +// unsigned char BulkBufIn [USB_CDC_BUFSIZE]; // Buffer to store USB IN packet +unsigned char BulkBufOut [USB_CDC_BUFSIZE]; // Buffer to store USB OUT packet +unsigned char NotificationBuf [10]; + +CDC_LINE_CODING CDC_LineCoding = {9600, 0, 0, 8}; +unsigned short CDC_SerialState = 0x0000; +unsigned short CDC_DepInEmpty = 1; // Data IN EP is empty + +/*---------------------------------------------------------------------------- + We need a buffer for incoming data on USB port because USB receives + much faster than UART transmits + *---------------------------------------------------------------------------*/ +/* Buffer masks */ +#define CDC_BUF_SIZE (64) // Output buffer in bytes (power 2) + // large enough for file transfer +#define CDC_BUF_MASK (CDC_BUF_SIZE-1ul) + +/* Buffer read / write macros */ +#define CDC_BUF_RESET(cdcBuf) (cdcBuf.rdIdx = cdcBuf.wrIdx = 0) +#define CDC_BUF_WR(cdcBuf, dataIn) (cdcBuf.data[CDC_BUF_MASK & cdcBuf.wrIdx++] = (dataIn)) +#define CDC_BUF_RD(cdcBuf) (cdcBuf.data[CDC_BUF_MASK & cdcBuf.rdIdx++]) +#define CDC_BUF_EMPTY(cdcBuf) (cdcBuf.rdIdx == cdcBuf.wrIdx) +#define CDC_BUF_FULL(cdcBuf) (cdcBuf.rdIdx == cdcBuf.wrIdx+1) +#define CDC_BUF_COUNT(cdcBuf) (CDC_BUF_MASK & (cdcBuf.wrIdx - cdcBuf.rdIdx)) + + +// CDC output buffer +typedef struct __CDC_BUF_T +{ + unsigned char data[CDC_BUF_SIZE]; + unsigned int wrIdx; + unsigned int rdIdx; +} CDC_BUF_T; + +CDC_BUF_T CDC_OutBuf; // buffer for all CDC Out data + +/*---------------------------------------------------------------------------- + read data from CDC_OutBuf + *---------------------------------------------------------------------------*/ +int CDC_RdOutBuf (char *buffer, const int *length) +{ + int bytesToRead, bytesRead; + + /* Read *length bytes, block if *bytes are not avaialable */ + bytesToRead = *length; + bytesToRead = (bytesToRead < (*length)) ? bytesToRead : (*length); + bytesRead = bytesToRead; + + + // ... add code to check for underrun + + while (bytesToRead--) { + *buffer++ = CDC_BUF_RD(CDC_OutBuf); + } + return (bytesRead); +} + +/*---------------------------------------------------------------------------- + write data to CDC_OutBuf + *---------------------------------------------------------------------------*/ +int CDC_WrOutBuf (const char *buffer, int *length) +{ + int bytesToWrite, bytesWritten; + + // Write *length bytes + bytesToWrite = *length; + bytesWritten = bytesToWrite; + + + // ... add code to check for overwrite + + while (bytesToWrite) { + CDC_BUF_WR(CDC_OutBuf, *buffer++); // Copy Data to buffer + bytesToWrite--; + } + + return (bytesWritten); +} + +/*---------------------------------------------------------------------------- + check if character(s) are available at CDC_OutBuf + *---------------------------------------------------------------------------*/ +int CDC_OutBufAvailChar (int *availChar) +{ + *availChar = CDC_BUF_COUNT(CDC_OutBuf); + + return (0); +} +/* end Buffer handling */ + + +/*---------------------------------------------------------------------------- + CDC Initialisation + Initializes the data structures and serial port + Parameters: None + Return Value: None + *---------------------------------------------------------------------------*/ +void CDC_Init (void) +{ + CDC_DepInEmpty = 1; + CDC_SerialState = CDC_GetSerialState(); + + CDC_BUF_RESET(CDC_OutBuf); +} + + +/*---------------------------------------------------------------------------- + CDC SendEncapsulatedCommand Request Callback + Called automatically on CDC SEND_ENCAPSULATED_COMMAND Request + Parameters: None (global SetupPacket and EP0Buf) + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_SendEncapsulatedCommand (void) +{ + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC GetEncapsulatedResponse Request Callback + Called automatically on CDC Get_ENCAPSULATED_RESPONSE Request + Parameters: None (global SetupPacket and EP0Buf) + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_GetEncapsulatedResponse (void) +{ + /* ... add code to handle request */ + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC SetCommFeature Request Callback + Called automatically on CDC Set_COMM_FATURE Request + Parameters: FeatureSelector + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_SetCommFeature (unsigned short wFeatureSelector) +{ + /* ... add code to handle request */ + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC GetCommFeature Request Callback + Called automatically on CDC Get_COMM_FATURE Request + Parameters: FeatureSelector + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_GetCommFeature (unsigned short wFeatureSelector) +{ + /* ... add code to handle request */ + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC ClearCommFeature Request Callback + Called automatically on CDC CLEAR_COMM_FATURE Request + Parameters: FeatureSelector + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_ClearCommFeature (unsigned short wFeatureSelector) +{ + /* ... add code to handle request */ + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC SetLineCoding Request Callback + Called automatically on CDC SET_LINE_CODING Request + Parameters: none (global SetupPacket and EP0Buf) + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_SetLineCoding (void) +{ + CDC_LineCoding.dwDTERate = (EP0Buf[0] << 0) + | (EP0Buf[1] << 8) + | (EP0Buf[2] << 16) + | (EP0Buf[3] << 24); + CDC_LineCoding.bCharFormat = EP0Buf[4]; + CDC_LineCoding.bParityType = EP0Buf[5]; + CDC_LineCoding.bDataBits = EP0Buf[6]; + + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC GetLineCoding Request Callback + Called automatically on CDC GET_LINE_CODING Request + Parameters: None (global SetupPacket and EP0Buf) + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_GetLineCoding (void) +{ + EP0Buf[0] = (CDC_LineCoding.dwDTERate >> 0) & 0xFF; + EP0Buf[1] = (CDC_LineCoding.dwDTERate >> 8) & 0xFF; + EP0Buf[2] = (CDC_LineCoding.dwDTERate >> 16) & 0xFF; + EP0Buf[3] = (CDC_LineCoding.dwDTERate >> 24) & 0xFF; + EP0Buf[4] = CDC_LineCoding.bCharFormat; + EP0Buf[5] = CDC_LineCoding.bParityType; + EP0Buf[6] = CDC_LineCoding.bDataBits; + + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC SetControlLineState Request Callback + Called automatically on CDC SET_CONTROL_LINE_STATE Request + Parameters: ControlSignalBitmap + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_SetControlLineState (unsigned short wControlSignalBitmap) { + + /* ... add code to handle request */ + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC SendBreak Request Callback + Called automatically on CDC Set_COMM_FATURE Request + Parameters: 0xFFFF start of Break + 0x0000 stop of Break + 0x#### Duration of Break + Return Value: TRUE - Success, FALSE - Error + *---------------------------------------------------------------------------*/ +uint32_t CDC_SendBreak (unsigned short wDurationOfBreak) { + + /* ... add code to handle request */ + return (TRUE); +} + + +/*---------------------------------------------------------------------------- + CDC_BulkIn call on DataIn Request + Parameters: none + Return Value: none + *---------------------------------------------------------------------------*/ +void CDC_BulkIn(void) +{ +// int numBytesRead, numBytesAvail; +// +// // ToDo: Modify BulkIn to send incoming data to USB +// +// ser_AvailChar (&numBytesAvail); +// +// // ... add code to check for overwrite +// +// numBytesRead = ser_Read ((char *)&BulkBufIn[0], &numBytesAvail); +// +// // send over USB +// if (numBytesRead > 0) { +// USB_WriteEP (CDC_DEP_IN, &BulkBufIn[0], numBytesRead); +// } +// else { +// CDC_DepInEmpty = 1; +// } +// +// +} + + +/*---------------------------------------------------------------------------- + CDC_BulkOut call on DataOut Request + Parameters: none + Return Value: none + *---------------------------------------------------------------------------*/ +void CDC_BulkOut(void) +{ + int numBytesRead; + + // get data from USB into intermediate buffer + numBytesRead = USB_ReadEP(CDC_DEP_OUT, &BulkBufOut[0]); + + // ... add code to check for overwrite + + // store data in a buffer to transmit it over serial interface + CDC_WrOutBuf ((char *)&BulkBufOut[0], &numBytesRead); +} + + +/*---------------------------------------------------------------------------- + Get the SERIAL_STATE as defined in usbcdc11.pdf, 6.3.5, Table 69. + Parameters: none + Return Value: SerialState as defined in usbcdc11.pdf + *---------------------------------------------------------------------------*/ +unsigned short CDC_GetSerialState (void) +{ + // unsigned short temp; + + CDC_SerialState = 0; + // ser_LineState (&temp); + // + // if (temp & 0x8000) CDC_SerialState |= CDC_SERIAL_STATE_RX_CARRIER; + // if (temp & 0x2000) CDC_SerialState |= CDC_SERIAL_STATE_TX_CARRIER; + // if (temp & 0x0010) CDC_SerialState |= CDC_SERIAL_STATE_BREAK; + // if (temp & 0x4000) CDC_SerialState |= CDC_SERIAL_STATE_RING; + // if (temp & 0x0008) CDC_SerialState |= CDC_SERIAL_STATE_FRAMING; + // if (temp & 0x0004) CDC_SerialState |= CDC_SERIAL_STATE_PARITY; + // if (temp & 0x0002) CDC_SerialState |= CDC_SERIAL_STATE_OVERRUN; + + return (CDC_SerialState); +} + + +/*---------------------------------------------------------------------------- + Send the SERIAL_STATE notification as defined in usbcdc11.pdf, 6.3.5. + *---------------------------------------------------------------------------*/ +void CDC_NotificationIn (void) +{ + NotificationBuf[0] = 0xA1; // bmRequestType + NotificationBuf[1] = CDC_NOTIFICATION_SERIAL_STATE; // bNotification (SERIAL_STATE) + NotificationBuf[2] = 0x00; // wValue + NotificationBuf[3] = 0x00; + NotificationBuf[4] = 0x00; // wIndex (Interface #, LSB first) + NotificationBuf[5] = 0x00; + NotificationBuf[6] = 0x02; // wLength (Data length = 2 bytes, LSB first) + NotificationBuf[7] = 0x00; + NotificationBuf[8] = (CDC_SerialState >> 0) & 0xFF; // UART State Bitmap (16bits, LSB first) + NotificationBuf[9] = (CDC_SerialState >> 8) & 0xFF; + + USB_WriteEP (CDC_CEP_IN, &NotificationBuf[0], 10); // send notification +} + +extern void usbcdcSendByte(uint8_t c) +{ + // Ugly delay required ... need to add buffer and handle this better! :-) + uint32_t i, delay; + delay = ((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 25000); + for ( i = 0; i < delay; i++ ) + { + __asm("nop"); + } + + // Send byte to EP + USB_WriteEP (CDC_DEP_IN, (unsigned char *)&c, 1); + CDC_DepInEmpty = 1; +} + diff --git a/macusbfb/core/usbcdc/cdcuser.h b/macusbfb/core/usbcdc/cdcuser.h new file mode 100644 index 0000000..0730e7a --- /dev/null +++ b/macusbfb/core/usbcdc/cdcuser.h @@ -0,0 +1,65 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: cdcuser.h + * Purpose: USB Communication Device Class User module Definitions + * Version: V1.10 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#ifndef __CDCUSER_H__ +#define __CDCUSER_H__ + +/* CDC buffer handling */ +extern int CDC_RdOutBuf (char *buffer, const int *length); +extern int CDC_WrOutBuf (const char *buffer, int *length); +extern int CDC_OutBufAvailChar (int *availChar); + + +/* CDC Data In/Out Endpoint Address */ +#define CDC_DEP_IN 0x83 +#define CDC_DEP_OUT 0x03 + +/* CDC Communication In Endpoint Address */ +#define CDC_CEP_IN 0x81 + +/* CDC Requests Callback Functions */ +extern uint32_t CDC_SendEncapsulatedCommand (void); +extern uint32_t CDC_GetEncapsulatedResponse (void); +extern uint32_t CDC_SetCommFeature (unsigned short wFeatureSelector); +extern uint32_t CDC_GetCommFeature (unsigned short wFeatureSelector); +extern uint32_t CDC_ClearCommFeature (unsigned short wFeatureSelector); +extern uint32_t CDC_GetLineCoding (void); +extern uint32_t CDC_SetLineCoding (void); +extern uint32_t CDC_SetControlLineState (unsigned short wControlSignalBitmap); +extern uint32_t CDC_SendBreak (unsigned short wDurationOfBreak); + +/* CDC Bulk Callback Functions */ +extern void CDC_BulkIn (void); +extern void CDC_BulkOut (void); + +/* CDC Notification Callback Function */ +extern void CDC_NotificationIn (void); + +/* CDC Initialization Function */ +extern void CDC_Init (void); + +/* CDC prepare the SERAIAL_STATE */ +extern unsigned short CDC_GetSerialState (void); + +/* flow control */ +extern unsigned short CDC_DepInEmpty; // DataEndPoint IN empty + +extern void usbcdcSendByte(uint8_t c); + +#endif /* __CDCUSER_H__ */ + diff --git a/macusbfb/core/usbcdc/config.h b/macusbfb/core/usbcdc/config.h new file mode 100644 index 0000000..28af6b5 --- /dev/null +++ b/macusbfb/core/usbcdc/config.h @@ -0,0 +1,41 @@ +/***************************************************************************** + * config.h: config file for usbcdc example for NXP LPC13xx Family + * Microprocessors + * + * Copyright(C) 2008, NXP Semiconductor + * All rights reserved. + * + * History + * 2008.07.19 ver 1.00 Preliminary version, first Release + * +******************************************************************************/ + +/* +Overview: + This example shows how to use the USB driver to implement a CDC class USB peripheral. + To run this example, you must attach a USB cable to the board. See + the "Getting Started Guide" appendix for details. + +How to use: + Click the debug toolbar button. + Click the go button. + Plug the LPCXpresso's target side into a PC using a USB cable retrofit + or a 3rd party base board. + + * You should be able to see a new COM port on your PC. +*/ + +#define NXP_VID 0x1FC9 +#define MY_VID 0x???? + +#define USB_VENDOR_ID NXP_VID // Vendor ID +#define USB_PROD_ID 0x0003 // Product ID +#define USB_DEVICE 0x0100 // Device ID + +#define LED_PORT 0 // Port for led +#define LED_BIT 7 // Bit on port for led + + +/********************************************************************************* +** End Of File +*********************************************************************************/ diff --git a/macusbfb/core/usbcdc/usb.h b/macusbfb/core/usbcdc/usb.h new file mode 100644 index 0000000..6ba0aeb --- /dev/null +++ b/macusbfb/core/usbcdc/usb.h @@ -0,0 +1,228 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usb.h + * Purpose: USB Definitions + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#ifndef __USB_H__ +#define __USB_H__ + + +typedef union { + uint16_t W; + struct { + uint8_t L; + uint8_t H; + } __attribute__((packed)) WB; +} __attribute__((packed)) WORD_BYTE; + + +/* bmRequestType.Dir */ +#define REQUEST_HOST_TO_DEVICE 0 +#define REQUEST_DEVICE_TO_HOST 1 + +/* bmRequestType.Type */ +#define REQUEST_STANDARD 0 +#define REQUEST_CLASS 1 +#define REQUEST_VENDOR 2 +#define REQUEST_RESERVED 3 + +/* bmRequestType.Recipient */ +#define REQUEST_TO_DEVICE 0 +#define REQUEST_TO_INTERFACE 1 +#define REQUEST_TO_ENDPOINT 2 +#define REQUEST_TO_OTHER 3 + +/* bmRequestType Definition */ +typedef union _REQUEST_TYPE { + struct _BM { + uint8_t Recipient : 5; + uint8_t Type : 2; + uint8_t Dir : 1; + } __attribute__((packed)) BM; + uint8_t B; +} __attribute__((packed)) REQUEST_TYPE; + +/* USB Standard Request Codes */ +#define USB_REQUEST_GET_STATUS 0 +#define USB_REQUEST_CLEAR_FEATURE 1 +#define USB_REQUEST_SET_FEATURE 3 +#define USB_REQUEST_SET_ADDRESS 5 +#define USB_REQUEST_GET_DESCRIPTOR 6 +#define USB_REQUEST_SET_DESCRIPTOR 7 +#define USB_REQUEST_GET_CONFIGURATION 8 +#define USB_REQUEST_SET_CONFIGURATION 9 +#define USB_REQUEST_GET_INTERFACE 10 +#define USB_REQUEST_SET_INTERFACE 11 +#define USB_REQUEST_SYNC_FRAME 12 + +/* USB GET_STATUS Bit Values */ +#define USB_GETSTATUS_SELF_POWERED 0x01 +#define USB_GETSTATUS_REMOTE_WAKEUP 0x02 +#define USB_GETSTATUS_ENDPOINT_STALL 0x01 + +/* USB Standard Feature selectors */ +#define USB_FEATURE_ENDPOINT_STALL 0 +#define USB_FEATURE_REMOTE_WAKEUP 1 + +/* USB Default Control Pipe Setup Packet */ +typedef struct _USB_SETUP_PACKET { + REQUEST_TYPE bmRequestType; + uint8_t bRequest; + WORD_BYTE wValue; + WORD_BYTE wIndex; + uint16_t wLength; +} __attribute__((packed)) USB_SETUP_PACKET; + + +/* USB Descriptor Types */ +#define USB_DEVICE_DESCRIPTOR_TYPE 1 +#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2 +#define USB_STRING_DESCRIPTOR_TYPE 3 +#define USB_INTERFACE_DESCRIPTOR_TYPE 4 +#define USB_ENDPOINT_DESCRIPTOR_TYPE 5 +#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6 +#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7 +#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8 +#define USB_OTG_DESCRIPTOR_TYPE 9 +#define USB_DEBUG_DESCRIPTOR_TYPE 10 +#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11 + +/* USB Device Classes */ +#define USB_DEVICE_CLASS_RESERVED 0x00 +#define USB_DEVICE_CLASS_AUDIO 0x01 +#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 +#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 +#define USB_DEVICE_CLASS_MONITOR 0x04 +#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05 +#define USB_DEVICE_CLASS_POWER 0x06 +#define USB_DEVICE_CLASS_PRINTER 0x07 +#define USB_DEVICE_CLASS_STORAGE 0x08 +#define USB_DEVICE_CLASS_HUB 0x09 +#define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF +#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF + +/* bmAttributes in Configuration Descriptor */ +#define USB_CONFIG_POWERED_MASK 0x40 +#define USB_CONFIG_BUS_POWERED 0x80 +#define USB_CONFIG_SELF_POWERED 0xC0 +#define USB_CONFIG_REMOTE_WAKEUP 0x20 + +/* bMaxPower in Configuration Descriptor */ +#define USB_CONFIG_POWER_MA(mA) ((mA)/2) + +/* bEndpointAddress in Endpoint Descriptor */ +#define USB_ENDPOINT_DIRECTION_MASK 0x80 +#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) +#define USB_ENDPOINT_IN(addr) ((addr) | 0x80) + +/* bmAttributes in Endpoint Descriptor */ +#define USB_ENDPOINT_TYPE_MASK 0x03 +#define USB_ENDPOINT_TYPE_CONTROL 0x00 +#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 +#define USB_ENDPOINT_TYPE_BULK 0x02 +#define USB_ENDPOINT_TYPE_INTERRUPT 0x03 +#define USB_ENDPOINT_SYNC_MASK 0x0C +#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00 +#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04 +#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08 +#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C +#define USB_ENDPOINT_USAGE_MASK 0x30 +#define USB_ENDPOINT_USAGE_DATA 0x00 +#define USB_ENDPOINT_USAGE_FEEDBACK 0x10 +#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20 +#define USB_ENDPOINT_USAGE_RESERVED 0x30 + +/* USB Standard Device Descriptor */ +typedef struct _USB_DEVICE_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} __attribute__((packed)) USB_DEVICE_DESCRIPTOR; + +/* USB 2.0 Device Qualifier Descriptor */ +typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t bNumConfigurations; + uint8_t bReserved; +} __attribute__((packed)) USB_DEVICE_QUALIFIER_DESCRIPTOR; + +/* USB Standard Configuration Descriptor */ +typedef struct _USB_CONFIGURATION_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; +} __attribute__((packed)) USB_CONFIGURATION_DESCRIPTOR; + +/* USB Standard Interface Descriptor */ +typedef struct _USB_INTERFACE_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} __attribute__((packed)) USB_INTERFACE_DESCRIPTOR; + +/* USB Standard Endpoint Descriptor */ +typedef struct _USB_ENDPOINT_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} __attribute__((packed)) USB_ENDPOINT_DESCRIPTOR; + +/* USB String Descriptor */ +typedef struct _USB_STRING_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bString/*[]*/; +} __attribute__((packed)) USB_STRING_DESCRIPTOR; + +/* USB Common Descriptor */ +typedef struct _USB_COMMON_DESCRIPTOR { + uint8_t bLength; + uint8_t bDescriptorType; +} __attribute__((packed)) USB_COMMON_DESCRIPTOR; + + +#endif /* __USB_H__ */ diff --git a/macusbfb/core/usbcdc/usbcfg.h b/macusbfb/core/usbcdc/usbcfg.h new file mode 100644 index 0000000..3e0acf2 --- /dev/null +++ b/macusbfb/core/usbcdc/usbcfg.h @@ -0,0 +1,157 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usbcfg.h + * Purpose: USB Custom Configuration + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------- + * History: + * V1.20 Added vendor specific support + * V1.00 Initial Version + *---------------------------------------------------------------------------*/ + +#ifndef __USBCFG_H__ +#define __USBCFG_H__ + + +//*** <<< Use Configuration Wizard in Context Menu >>> *** + + +/* +// USB Configuration +// USB Power +// Default Power Setting +// <0=> Bus-powered +// <1=> Self-powered +// Max Number of Interfaces <1-256> +// Max Number of Endpoints <1-32> +// Max Endpoint 0 Packet Size +// <8=> 8 Bytes <16=> 16 Bytes <32=> 32 Bytes <64=> 64 Bytes +// DMA Transfer +// Use DMA for selected Endpoints +// Endpoint 0 Out +// Endpoint 0 In +// Endpoint 1 Out +// Endpoint 1 In +// Endpoint 2 Out +// Endpoint 2 In +// Endpoint 3 Out +// Endpoint 3 In +// Endpoint 4 Out +// Endpoint 4 In +// +// +*/ + +#define USB_POWER 0 +#define USB_IF_NUM 1 +#define USB_LOGIC_EP_NUM 5 +#define USB_EP_NUM 10 +#define USB_MAX_PACKET0 64 + +/* +// USB Event Handlers +// Device Events +// Power Event +// Reset Event +// Suspend Event +// Resume Event +// Remote Wakeup Event +// Start of Frame Event +// Error Event +// +// Endpoint Events +// Endpoint 0 Event +// Endpoint 1 Event +// Endpoint 2 Event +// Endpoint 3 Event +// Endpoint 4 Event +// Endpoint 5 Event +// Endpoint 6 Event +// Endpoint 7 Event +// Endpoint 8 Event +// Endpoint 9 Event +// Endpoint 10 Event +// Endpoint 11 Event +// Endpoint 12 Event +// Endpoint 13 Event +// Endpoint 14 Event +// Endpoint 15 Event +// +// USB Core Events +// Set Configuration Event +// Set Interface Event +// Set/Clear Feature Event +// +// +*/ + +#define USB_POWER_EVENT 0 +#define USB_RESET_EVENT 1 +#define USB_SUSPEND_EVENT 1 +#define USB_RESUME_EVENT 1 +#define USB_WAKEUP_EVENT 0 +#define USB_SOF_EVENT 0 +#define USB_ERROR_EVENT 0 +#define USB_EP_EVENT 0x000B +#define USB_CONFIGURE_EVENT 1 +#define USB_INTERFACE_EVENT 0 +#define USB_FEATURE_EVENT 0 + + +/* +// USB Class Support +// enables USB Class specific Requests +// Human Interface Device (HID) +// Interface Number <0-255> +// +// Mass Storage +// Interface Number <0-255> +// +// Audio Device +// Control Interface Number <0-255> +// Streaming Interface 1 Number <0-255> +// Streaming Interface 2 Number <0-255> +// +// Communication Device +// Control Interface Number <0-255> +// Bulk Interface Number <0-255> +// Max Communication Device Buffer Size +// <8=> 8 Bytes <16=> 16 Bytes <32=> 32 Bytes <64=> 64 Bytes +// +// +*/ + +#define USB_CLASS 1 +#define USB_HID 0 +#define USB_HID_IF_NUM 0 +#define USB_MSC 0 +#define USB_MSC_IF_NUM 0 +#define USB_AUDIO 0 +#define USB_ADC_CIF_NUM 0 +#define USB_ADC_SIF1_NUM 1 +#define USB_ADC_SIF2_NUM 2 +#define USB_CDC 1 +#define USB_CDC_CIF_NUM 0 +#define USB_CDC_DIF_NUM 1 +#define USB_CDC_BUFSIZE 64 + +/* +// USB Vendor Support +// enables USB Vendor specific Requests +// +*/ +#define USB_VENDOR 0 + + +#endif /* __USBCFG_H__ */ diff --git a/macusbfb/core/usbcdc/usbcore.c b/macusbfb/core/usbcdc/usbcore.c new file mode 100644 index 0000000..f422aab --- /dev/null +++ b/macusbfb/core/usbcdc/usbcore.c @@ -0,0 +1,1057 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usbcore.c + * Purpose: USB Core Module + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------- + * History: + * V1.20 Added vendor specific requests + * Changed string descriptor handling + * Reworked Endpoint0 + * V1.00 Initial Version + *----------------------------------------------------------------------------*/ +#include "projectconfig.h" + +#include "usb.h" +#include "usbcfg.h" +#include "usbhw.h" +#include "usbcore.h" +#include "usbdesc.h" +#include "usbuser.h" + +#if (USB_CLASS) + +#if (USB_AUDIO) +#include "audio.h" +#include "adcuser.h" +#endif + +#if (USB_HID) +#include "hid.h" +#include "hiduser.h" +#endif + +#if (USB_MSC) +#include "msc.h" +#include "mscuser.h" +extern MSC_CSW CSW; +#endif + +#if (USB_CDC) +#include "cdc.h" +#include "cdcuser.h" +#endif + +#endif + +#if (USB_VENDOR) +#include "vendor.h" +#endif + +uint16_t USB_DeviceStatus; +uint8_t USB_DeviceAddress; +volatile uint8_t USB_Configuration; +uint32_t USB_EndPointMask; +uint32_t USB_EndPointHalt; +uint32_t USB_EndPointStall; /* EP must stay stalled */ +uint8_t USB_NumInterfaces; +uint8_t USB_AltSetting[USB_IF_NUM]; + +uint8_t EP0Buf[USB_MAX_PACKET0]; + + +USB_EP_DATA EP0Data; + +USB_SETUP_PACKET SetupPacket; + + +/* + * Reset USB Core + * Parameters: None + * Return Value: None + */ + +void USB_ResetCore (void) { + + USB_DeviceStatus = USB_POWER; + USB_DeviceAddress = 0; + USB_Configuration = 0; + USB_EndPointMask = 0x00010001; + USB_EndPointHalt = 0x00000000; + USB_EndPointStall = 0x00000000; +} + + +/* + * USB Request - Setup Stage + * Parameters: None (global SetupPacket) + * Return Value: None + */ + +void USB_SetupStage (void) { + USB_ReadEP(0x00, (uint8_t *)&SetupPacket); +} + + +/* + * USB Request - Data In Stage + * Parameters: None (global EP0Data) + * Return Value: None + */ + +void USB_DataInStage (void) { + uint32_t cnt; + + if (EP0Data.Count > USB_MAX_PACKET0) { + cnt = USB_MAX_PACKET0; + } else { + cnt = EP0Data.Count; + } + cnt = USB_WriteEP(0x80, EP0Data.pData, cnt); + EP0Data.pData += cnt; + EP0Data.Count -= cnt; +} + + +/* + * USB Request - Data Out Stage + * Parameters: None (global EP0Data) + * Return Value: None + */ + +void USB_DataOutStage (void) { + uint32_t cnt; + + cnt = USB_ReadEP(0x00, EP0Data.pData); + EP0Data.pData += cnt; + EP0Data.Count -= cnt; +} + + +/* + * USB Request - Status In Stage + * Parameters: None + * Return Value: None + */ + +void USB_StatusInStage (void) { + USB_WriteEP(0x80, NULL, 0); +} + + +/* + * USB Request - Status Out Stage + * Parameters: None + * Return Value: None + */ + +void USB_StatusOutStage (void) { + USB_ReadEP(0x00, EP0Buf); +} + + +/* + * Get Status USB Request + * Parameters: None (global SetupPacket) + * Return Value: TRUE - Success, FALSE - Error + */ + +static inline uint32_t USB_ReqGetStatus (void) { + uint32_t n, m; + + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_DEVICE: + EP0Data.pData = (uint8_t *)&USB_DeviceStatus; + break; + case REQUEST_TO_INTERFACE: + if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) { + *((uint16_t __attribute__((packed)) *)EP0Buf) = 0; + EP0Data.pData = EP0Buf; + } else { + return (FALSE); + } + break; + case REQUEST_TO_ENDPOINT: + n = SetupPacket.wIndex.WB.L & 0x8F; + m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); + if (((USB_Configuration != 0) || ((n & 0x0F) == 0)) && (USB_EndPointMask & m)) { + *((uint16_t __attribute__((packed)) *)EP0Buf) = (USB_EndPointHalt & m) ? 1 : 0; + EP0Data.pData = EP0Buf; + } else { + return (FALSE); + } + break; + default: + return (FALSE); + } + return (TRUE); +} + + +/* + * Set/Clear Feature USB Request + * Parameters: sc: 0 - Clear, 1 - Set + * (global SetupPacket) + * Return Value: TRUE - Success, FALSE - Error + */ + +static inline uint32_t USB_ReqSetClrFeature (uint32_t sc) { + uint32_t n, m; + + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_DEVICE: + if (SetupPacket.wValue.W == USB_FEATURE_REMOTE_WAKEUP) { + if (sc) { + USB_WakeUpCfg(TRUE); + USB_DeviceStatus |= USB_GETSTATUS_REMOTE_WAKEUP; + } else { + USB_WakeUpCfg(FALSE); + USB_DeviceStatus &= ~USB_GETSTATUS_REMOTE_WAKEUP; + } + } else { + return (FALSE); + } + break; + case REQUEST_TO_INTERFACE: + return (FALSE); + case REQUEST_TO_ENDPOINT: + n = SetupPacket.wIndex.WB.L & 0x8F; + m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); + if ((USB_Configuration != 0) && ((n & 0x0F) != 0) && (USB_EndPointMask & m)) { + if (SetupPacket.wValue.W == USB_FEATURE_ENDPOINT_STALL) { + if (sc) { + USB_SetStallEP(n); + USB_EndPointHalt |= m; + } else { + if ((USB_EndPointStall & m) != 0) { + return (TRUE); + } + USB_ClrStallEP(n); +#if (USB_MSC) + if ((n == MSC_EP_IN) && ((USB_EndPointHalt & m) != 0)) { + /* Compliance Test: rewrite CSW after unstall */ + if (CSW.dSignature == MSC_CSW_Signature) { + USB_WriteEP(MSC_EP_IN, (uint8_t *)&CSW, sizeof(CSW)); + } + } +#endif + USB_EndPointHalt &= ~m; + } + } else { + return (FALSE); + } + } else { + return (FALSE); + } + break; + default: + return (FALSE); + } + return (TRUE); +} + + +/* + * Set Address USB Request + * Parameters: None (global SetupPacket) + * Return Value: TRUE - Success, FALSE - Error + */ + +static inline uint32_t USB_ReqSetAddress (void) { + + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_DEVICE: + USB_DeviceAddress = 0x80 | SetupPacket.wValue.WB.L; + break; + default: + return (FALSE); + } + return (TRUE); +} + + +/* + * Get Descriptor USB Request + * Parameters: None (global SetupPacket) + * Return Value: TRUE - Success, FALSE - Error + */ + +static inline uint32_t USB_ReqGetDescriptor (void) { + uint8_t *pD; + uint32_t len, n; + + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_DEVICE: + switch (SetupPacket.wValue.WB.H) { + case USB_DEVICE_DESCRIPTOR_TYPE: + EP0Data.pData = (uint8_t *)USB_DeviceDescriptor; + len = USB_DEVICE_DESC_SIZE; + break; + case USB_CONFIGURATION_DESCRIPTOR_TYPE: + pD = (uint8_t *)USB_ConfigDescriptor; + for (n = 0; n != SetupPacket.wValue.WB.L; n++) { + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength != 0) { + pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength; + } + } + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength == 0) { + return (FALSE); + } + EP0Data.pData = pD; + len = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength; + break; + case USB_STRING_DESCRIPTOR_TYPE: + pD = (uint8_t *)USB_StringDescriptor; + for (n = 0; n != SetupPacket.wValue.WB.L; n++) { + if (((USB_STRING_DESCRIPTOR *)pD)->bLength != 0) { + pD += ((USB_STRING_DESCRIPTOR *)pD)->bLength; + } + } + if (((USB_STRING_DESCRIPTOR *)pD)->bLength == 0) { + return (FALSE); + } + EP0Data.pData = pD; + len = ((USB_STRING_DESCRIPTOR *)EP0Data.pData)->bLength; + break; + default: + return (FALSE); + } + break; + case REQUEST_TO_INTERFACE: + switch (SetupPacket.wValue.WB.H) { +#if USB_HID + case HID_HID_DESCRIPTOR_TYPE: + if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) { + return (FALSE); /* Only Single HID Interface is supported */ + } + EP0Data.pData = (uint8_t *)USB_ConfigDescriptor + HID_DESC_OFFSET; + len = HID_DESC_SIZE; + break; + case HID_REPORT_DESCRIPTOR_TYPE: + if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) { + return (FALSE); /* Only Single HID Interface is supported */ + } + EP0Data.pData = (uint8_t *)HID_ReportDescriptor; + len = HID_ReportDescSize; + break; + case HID_PHYSICAL_DESCRIPTOR_TYPE: + return (FALSE); /* HID Physical Descriptor is not supported */ +#endif + default: + return (FALSE); + } + break; + default: + return (FALSE); + } + + if (EP0Data.Count > len) { + EP0Data.Count = len; + } + + return (TRUE); +} + +/* + * Get Configuration USB Request + * Parameters: None (global SetupPacket) + * Return Value: TRUE - Success, FALSE - Error + */ + +static inline uint32_t USB_ReqGetConfiguration (void) { + + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_DEVICE: + // Added cast to avoid warnings due to USB_Configuration being volatile (KTownsend) + EP0Data.pData = (uint8_t *)&USB_Configuration; + break; + default: + return (FALSE); + } + return (TRUE); +} + +/* + * Set Configuration USB Request + * Parameters: None (global SetupPacket) + * Return Value: TRUE - Success, FALSE - Error + */ + +static inline uint32_t USB_ReqSetConfiguration (void) { + USB_COMMON_DESCRIPTOR *pD; + uint32_t alt = 0; + uint32_t n, m; + + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_DEVICE: + + if (SetupPacket.wValue.WB.L) { + pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor; + while (pD->bLength) { + switch (pD->bDescriptorType) { + case USB_CONFIGURATION_DESCRIPTOR_TYPE: + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue == SetupPacket.wValue.WB.L) { + USB_Configuration = SetupPacket.wValue.WB.L; + USB_NumInterfaces = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->bNumInterfaces; + for (n = 0; n < USB_IF_NUM; n++) { + USB_AltSetting[n] = 0; + } + for (n = 1; n < 16; n++) { + if (USB_EndPointMask & (1 << n)) { + USB_DisableEP(n); + } + if (USB_EndPointMask & ((1 << 16) << n)) { + USB_DisableEP(n | 0x80); + } + } + USB_EndPointMask = 0x00010001; + USB_EndPointHalt = 0x00000000; + USB_EndPointStall= 0x00000000; + USB_Configure(TRUE); + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bmAttributes & USB_CONFIG_POWERED_MASK) { + USB_DeviceStatus |= USB_GETSTATUS_SELF_POWERED; + } else { + USB_DeviceStatus &= ~USB_GETSTATUS_SELF_POWERED; + } + } else { + UsbAddPtr((void **)&pD, ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength); + continue; + } + break; + case USB_INTERFACE_DESCRIPTOR_TYPE: + alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting; + break; + case USB_ENDPOINT_DESCRIPTOR_TYPE: + if (alt == 0) { + n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F; + m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); + USB_EndPointMask |= m; + USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD); + USB_EnableEP(n); + USB_ResetEP(n); + } + break; + } + UsbAddPtr((void **)&pD, pD->bLength); + } + } + else { + USB_Configuration = 0; + for (n = 1; n < 16; n++) { + if (USB_EndPointMask & (1 << n)) { + USB_DisableEP(n); + } + if (USB_EndPointMask & ((1 << 16) << n)) { + USB_DisableEP(n | 0x80); + } + } + USB_EndPointMask = 0x00010001; + USB_EndPointHalt = 0x00000000; + USB_EndPointStall = 0x00000000; + USB_Configure(FALSE); + } + + if (USB_Configuration != SetupPacket.wValue.WB.L) { + return (FALSE); + } + break; + default: + return (FALSE); + } + return (TRUE); +} + + +/* + * Get Interface USB Request + * Parameters: None (global SetupPacket) + * Return Value: TRUE - Success, FALSE - Error + */ + +static inline uint32_t USB_ReqGetInterface (void) { + + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_INTERFACE: + if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) { + EP0Data.pData = USB_AltSetting + SetupPacket.wIndex.WB.L; + } else { + return (FALSE); + } + break; + default: + return (FALSE); + } + return (TRUE); +} + + +/* + * Set Interface USB Request + * Parameters: None (global SetupPacket) + * Return Value: TRUE - Success, FALSE - Error + */ + +static inline uint32_t USB_ReqSetInterface (void) { + USB_COMMON_DESCRIPTOR *pD; + uint32_t ifn = 0, alt = 0, old = 0, msk = 0; + uint32_t n, m; + uint32_t set; + + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_INTERFACE: + if (USB_Configuration == 0) return (FALSE); + set = FALSE; + pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor; + while (pD->bLength) { + switch (pD->bDescriptorType) { + case USB_CONFIGURATION_DESCRIPTOR_TYPE: + if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue != USB_Configuration) { + UsbAddPtr((void **)&pD, ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength); + continue; + } + break; + case USB_INTERFACE_DESCRIPTOR_TYPE: + ifn = ((USB_INTERFACE_DESCRIPTOR *)pD)->bInterfaceNumber; + alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting; + msk = 0; + if ((ifn == SetupPacket.wIndex.WB.L) && (alt == SetupPacket.wValue.WB.L)) { + set = TRUE; + old = USB_AltSetting[ifn]; + USB_AltSetting[ifn] = (uint8_t)alt; + } + break; + case USB_ENDPOINT_DESCRIPTOR_TYPE: + if (ifn == SetupPacket.wIndex.WB.L) { + n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F; + m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); + if (alt == SetupPacket.wValue.WB.L) { + USB_EndPointMask |= m; + USB_EndPointHalt &= ~m; + USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD); + USB_EnableEP(n); + USB_ResetEP(n); + msk |= m; + } + else if ((alt == old) && ((msk & m) == 0)) { + USB_EndPointMask &= ~m; + USB_EndPointHalt &= ~m; + USB_DisableEP(n); + } + } + break; + } + UsbAddPtr((void **)&pD, pD->bLength); + } + break; + default: + return (FALSE); + } + + return (set); +} + +/* + * USB Endpoint 0 Event Callback + * Parameters: event + * Return Value: none + */ + +void USB_EndPoint0 (uint32_t event) { + + switch (event) { + case USB_EVT_SETUP: + USB_SetupStage(); + USB_DirCtrlEP(SetupPacket.bmRequestType.BM.Dir); + EP0Data.Count = SetupPacket.wLength; /* Number of bytes to transfer */ + switch (SetupPacket.bmRequestType.BM.Type) { + + case REQUEST_STANDARD: + switch (SetupPacket.bRequest) { + case USB_REQUEST_GET_STATUS: + if (!USB_ReqGetStatus()) { + goto stall_i; + } + USB_DataInStage(); + break; + + case USB_REQUEST_CLEAR_FEATURE: + if (!USB_ReqSetClrFeature(0)) { + goto stall_i; + } + USB_StatusInStage(); +#if USB_FEATURE_EVENT + USB_Feature_Event(); +#endif + break; + + case USB_REQUEST_SET_FEATURE: + if (!USB_ReqSetClrFeature(1)) { + goto stall_i; + } + USB_StatusInStage(); +#if USB_FEATURE_EVENT + USB_Feature_Event(); +#endif + break; + + case USB_REQUEST_SET_ADDRESS: + if (!USB_ReqSetAddress()) { + goto stall_i; + } + USB_StatusInStage(); + break; + + case USB_REQUEST_GET_DESCRIPTOR: + if (!USB_ReqGetDescriptor()) { + goto stall_i; + } + USB_DataInStage(); + break; + + case USB_REQUEST_SET_DESCRIPTOR: +/*stall_o:*/ USB_SetStallEP(0x00); /* not supported */ + EP0Data.Count = 0; + break; + + case USB_REQUEST_GET_CONFIGURATION: + if (!USB_ReqGetConfiguration()) { + goto stall_i; + } + USB_DataInStage(); + break; + + case USB_REQUEST_SET_CONFIGURATION: + if (!USB_ReqSetConfiguration()) { + goto stall_i; + } + USB_StatusInStage(); +#if USB_CONFIGURE_EVENT + USB_Configure_Event(); +#endif + break; + + case USB_REQUEST_GET_INTERFACE: + if (!USB_ReqGetInterface()) { + goto stall_i; + } + USB_DataInStage(); + break; + + case USB_REQUEST_SET_INTERFACE: + if (!USB_ReqSetInterface()) { + goto stall_i; + } + USB_StatusInStage(); +#if USB_INTERFACE_EVENT + USB_Interface_Event(); +#endif + break; + + default: + goto stall_i; + } + break; /* end case REQUEST_STANDARD */ + +#if USB_CLASS + case REQUEST_CLASS: + switch (SetupPacket.bmRequestType.BM.Recipient) { + + case REQUEST_TO_DEVICE: + goto stall_i; /* not supported */ + + case REQUEST_TO_INTERFACE: +#if USB_HID + if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { /* IF number correct? */ + switch (SetupPacket.bRequest) { + case HID_REQUEST_GET_REPORT: + if (HID_GetReport()) { + EP0Data.pData = EP0Buf; /* point to data to be sent */ + USB_DataInStage(); /* send requested data */ + goto setup_class_ok; + } + break; + case HID_REQUEST_SET_REPORT: + EP0Data.pData = EP0Buf; /* data to be received */ + goto setup_class_ok; + case HID_REQUEST_GET_IDLE: + if (HID_GetIdle()) { + EP0Data.pData = EP0Buf; /* point to data to be sent */ + USB_DataInStage(); /* send requested data */ + goto setup_class_ok; + } + break; + case HID_REQUEST_SET_IDLE: + if (HID_SetIdle()) { + USB_StatusInStage(); /* send Acknowledge */ + goto setup_class_ok; + } + break; + case HID_REQUEST_GET_PROTOCOL: + if (HID_GetProtocol()) { + EP0Data.pData = EP0Buf; /* point to data to be sent */ + USB_DataInStage(); /* send requested data */ + goto setup_class_ok; + } + break; + case HID_REQUEST_SET_PROTOCOL: + if (HID_SetProtocol()) { + USB_StatusInStage(); /* send Acknowledge */ + goto setup_class_ok; + } + break; + } + } +#endif /* USB_HID */ +#if USB_MSC + if (SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) { /* IF number correct? */ + switch (SetupPacket.bRequest) { + case MSC_REQUEST_RESET: + if ((SetupPacket.wValue.W == 0) && /* RESET with invalid parameters -> STALL */ + (SetupPacket.wLength == 0)) { + if (MSC_Reset()) { + USB_StatusInStage(); + goto setup_class_ok; + } + } + break; + case MSC_REQUEST_GET_MAX_LUN: + if ((SetupPacket.wValue.W == 0) && /* GET_MAX_LUN with invalid parameters -> STALL */ + (SetupPacket.wLength == 1)) { + if (MSC_GetMaxLUN()) { + EP0Data.pData = EP0Buf; + USB_DataInStage(); + goto setup_class_ok; + } + } + break; + } + } +#endif /* USB_MSC */ +#if USB_AUDIO + if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */ + (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || + (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) { + switch (SetupPacket.bRequest) { + case AUDIO_REQUEST_GET_CUR: + case AUDIO_REQUEST_GET_MIN: + case AUDIO_REQUEST_GET_MAX: + case AUDIO_REQUEST_GET_RES: + if (ADC_IF_GetRequest()) { + EP0Data.pData = EP0Buf; /* point to data to be sent */ + USB_DataInStage(); /* send requested data */ + goto setup_class_ok; + } + break; + case AUDIO_REQUEST_SET_CUR: +// case AUDIO_REQUEST_SET_MIN: +// case AUDIO_REQUEST_SET_MAX: +// case AUDIO_REQUEST_SET_RES: + EP0Data.pData = EP0Buf; /* data to be received */ + goto setup_class_ok; + } + } +#endif /* USB_AUDIO */ +#if USB_CDC + if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */ + (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) { + switch (SetupPacket.bRequest) { + case CDC_SEND_ENCAPSULATED_COMMAND: + EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ + goto setup_class_ok; + case CDC_GET_ENCAPSULATED_RESPONSE: + if (CDC_GetEncapsulatedResponse()) { + EP0Data.pData = EP0Buf; /* point to data to be sent */ + USB_DataInStage(); /* send requested data */ + goto setup_class_ok; + } + break; + case CDC_SET_COMM_FEATURE: + EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ + goto setup_class_ok; + case CDC_GET_COMM_FEATURE: + if (CDC_GetCommFeature(SetupPacket.wValue.W)) { + EP0Data.pData = EP0Buf; /* point to data to be sent */ + USB_DataInStage(); /* send requested data */ + goto setup_class_ok; + } + break; + case CDC_CLEAR_COMM_FEATURE: + if (CDC_ClearCommFeature(SetupPacket.wValue.W)) { + USB_StatusInStage(); /* send Acknowledge */ + goto setup_class_ok; + } + break; + case CDC_SET_LINE_CODING: + EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ + goto setup_class_ok; + case CDC_GET_LINE_CODING: + if (CDC_GetLineCoding()) { + EP0Data.pData = EP0Buf; /* point to data to be sent */ + USB_DataInStage(); /* send requested data */ + goto setup_class_ok; + } + break; + case CDC_SET_CONTROL_LINE_STATE: + if (CDC_SetControlLineState(SetupPacket.wValue.W)) { + USB_StatusInStage(); /* send Acknowledge */ + goto setup_class_ok; + } + break; + case CDC_SEND_BREAK: + if (CDC_SendBreak(SetupPacket.wValue.W)) { + USB_StatusInStage(); /* send Acknowledge */ + goto setup_class_ok; + } + break; + } + } +#endif /* USB_CDC */ + goto stall_i; /* not supported */ + /* end case REQUEST_TO_INTERFACE */ + + case REQUEST_TO_ENDPOINT: +#if USB_AUDIO + switch (SetupPacket.bRequest) { + case AUDIO_REQUEST_GET_CUR: + case AUDIO_REQUEST_GET_MIN: + case AUDIO_REQUEST_GET_MAX: + case AUDIO_REQUEST_GET_RES: + if (ADC_EP_GetRequest()) { + EP0Data.pData = EP0Buf; /* point to data to be sent */ + USB_DataInStage(); /* send requested data */ + goto setup_class_ok; + } + break; + case AUDIO_REQUEST_SET_CUR: +// case AUDIO_REQUEST_SET_MIN: +// case AUDIO_REQUEST_SET_MAX: +// case AUDIO_REQUEST_SET_RES: + EP0Data.pData = EP0Buf; /* data to be received */ + goto setup_class_ok; + } +#endif /* USB_AUDIO */ + goto stall_i; + /* end case REQUEST_TO_ENDPOINT */ + + default: + goto stall_i; + } +setup_class_ok: /* request finished successfully */ + break; /* end case REQUEST_CLASS */ +#endif /* USB_CLASS */ + +#if USB_VENDOR + case REQUEST_VENDOR: + switch (SetupPacket.bmRequestType.BM.Recipient) { + + case REQUEST_TO_DEVICE: + if (!USB_ReqVendorDev(TRUE)) { + goto stall_i; /* not supported */ + } + break; + + case REQUEST_TO_INTERFACE: + if (!USB_ReqVendorIF(TRUE)) { + goto stall_i; /* not supported */ + } + break; + + case REQUEST_TO_ENDPOINT: + if (!USB_ReqVendorEP(TRUE)) { + goto stall_i; /* not supported */ + } + break; + + default: + goto stall_i; + } + + if (SetupPacket.wLength) { + if (SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) { + USB_DataInStage(); + } + } else { + USB_StatusInStage(); + } + + break; /* end case REQUEST_VENDOR */ +#endif /* USB_VENDOR */ + + default: +stall_i: USB_SetStallEP(0x80); + EP0Data.Count = 0; + break; + } + break; /* end case USB_EVT_SETUP */ + + case USB_EVT_OUT: + if (SetupPacket.bmRequestType.BM.Dir == REQUEST_HOST_TO_DEVICE) { + if (EP0Data.Count) { /* still data to receive ? */ + USB_DataOutStage(); /* receive data */ + if (EP0Data.Count == 0) { /* data complete ? */ + switch (SetupPacket.bmRequestType.BM.Type) { + + case REQUEST_STANDARD: + goto stall_i; /* not supported */ + +#if (USB_CLASS) + case REQUEST_CLASS: + switch (SetupPacket.bmRequestType.BM.Recipient) { + case REQUEST_TO_DEVICE: + goto stall_i; /* not supported */ + + case REQUEST_TO_INTERFACE: +#if USB_HID + if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { /* IF number correct? */ + switch (SetupPacket.bRequest) { + case HID_REQUEST_SET_REPORT: + if (HID_SetReport()) { + USB_StatusInStage(); /* send Acknowledge */ + goto out_class_ok; + } + break; + } + } +#endif /* USB_HID */ +#if USB_AUDIO + if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */ + (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || + (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) { + switch (SetupPacket.bRequest) { + case AUDIO_REQUEST_SET_CUR: +// case AUDIO_REQUEST_SET_MIN: +// case AUDIO_REQUEST_SET_MAX: +// case AUDIO_REQUEST_SET_RES: + if (ADC_IF_SetRequest()) { + USB_StatusInStage(); /* send Acknowledge */ + goto out_class_ok; + } + break; + } + } +#endif /* USB_AUDIO */ +#if USB_CDC + if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */ + (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) { + switch (SetupPacket.bRequest) { + case CDC_SEND_ENCAPSULATED_COMMAND: + if (CDC_SendEncapsulatedCommand()) { + USB_StatusInStage(); /* send Acknowledge */ + goto out_class_ok; + } + break; + case CDC_SET_COMM_FEATURE: + if (CDC_SetCommFeature(SetupPacket.wValue.W)) { + USB_StatusInStage(); /* send Acknowledge */ + goto out_class_ok; + } + break; + case CDC_SET_LINE_CODING: + if (CDC_SetLineCoding()) { + USB_StatusInStage(); /* send Acknowledge */ + goto out_class_ok; + } + break; + } + } +#endif /* USB_CDC */ + goto stall_i; + /* end case REQUEST_TO_INTERFACE */ + + case REQUEST_TO_ENDPOINT: +#if USB_AUDIO + switch (SetupPacket.bRequest) { + case AUDIO_REQUEST_SET_CUR: +// case AUDIO_REQUEST_SET_MIN: +// case AUDIO_REQUEST_SET_MAX: +// case AUDIO_REQUEST_SET_RES: + if (ADC_EP_SetRequest()) { + USB_StatusInStage(); /* send Acknowledge */ + goto out_class_ok; + } + break; + } +#endif /* USB_AUDIO */ + goto stall_i; + /* end case REQUEST_TO_ENDPOINT */ + + default: + goto stall_i; + } +out_class_ok: /* request finished successfully */ + break; /* end case REQUEST_CLASS */ +#endif /* USB_CLASS */ + +#if USB_VENDOR + case REQUEST_VENDOR: + switch (SetupPacket.bmRequestType.BM.Recipient) { + + case REQUEST_TO_DEVICE: + if (!USB_ReqVendorDev(FALSE)) { + goto stall_i; /* not supported */ + } + break; + + case REQUEST_TO_INTERFACE: + if (!USB_ReqVendorIF(FALSE)) { + goto stall_i; /* not supported */ + } + break; + + case REQUEST_TO_ENDPOINT: + if (!USB_ReqVendorEP(FALSE)) { + goto stall_i; /* not supported */ + } + break; + + default: + goto stall_i; + } + + USB_StatusInStage(); + + break; /* end case REQUEST_VENDOR */ +#endif /* USB_VENDOR */ + + default: + goto stall_i; + } + } + } + } else { + USB_StatusOutStage(); /* receive Acknowledge */ + } + break; /* end case USB_EVT_OUT */ + + case USB_EVT_IN : + if (SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) { + USB_DataInStage(); /* send data */ + } else { + if (USB_DeviceAddress & 0x80) { + USB_DeviceAddress &= 0x7F; + USB_SetAddress(USB_DeviceAddress); + } + } + break; /* end case USB_EVT_IN */ + + case USB_EVT_OUT_STALL: + USB_ClrStallEP(0x00); + break; + + case USB_EVT_IN_STALL: + USB_ClrStallEP(0x80); + break; + + } +} diff --git a/macusbfb/core/usbcdc/usbcore.h b/macusbfb/core/usbcdc/usbcore.h new file mode 100644 index 0000000..4ee6630 --- /dev/null +++ b/macusbfb/core/usbcdc/usbcore.h @@ -0,0 +1,87 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usbcore.h + * Purpose: USB Core Definitions + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#ifndef __USBCORE_H__ +#define __USBCORE_H__ + +#include "usbcfg.h" + +/* USB Endpoint Data Structure */ +typedef struct _USB_EP_DATA { + uint8_t *pData; + uint16_t Count; +} USB_EP_DATA; + +/* USB Core Global Variables */ +extern uint16_t USB_DeviceStatus; +extern uint8_t USB_DeviceAddress; +volatile extern uint8_t USB_Configuration; +extern uint32_t USB_EndPointMask; +extern uint32_t USB_EndPointHalt; +extern uint32_t USB_EndPointStall; +extern uint8_t USB_AltSetting[USB_IF_NUM]; + +/* USB Endpoint 0 Buffer */ +extern uint8_t EP0Buf[USB_MAX_PACKET0]; + +/* USB Endpoint 0 Data Info */ +extern USB_EP_DATA EP0Data; + +/* USB Setup Packet */ +extern USB_SETUP_PACKET SetupPacket; + +/* USB Core Functions */ +extern void USB_ResetCore (void); + +/* Newer C compilers make it really difficult to add + * an integer to a pointer */ +static inline void UsbAddPtr(void **vpptr, uint32_t n); + +/* + * Add a number of bytes to a pointer's address + * Harder than you might think. Some compilers say: + * Expected an lvalue -- Assignment expects its first operand to be + * an lvalue. Please note that a cast removes the lvaluedness of an + * expression. + * + * vpptr = void pointer to pointer + * n = number of bytes to add to pointer + * Call looks like: AddPtr((void **)&myPointer, 8); + */ +static inline void UsbAddPtr(void **vpptr, uint32_t n) +{ + /* Declare a pointer to a pointer to a byte. Only a byte pointer + * can be incremented by a number of bytes. Other pointers will + * increment by a multiple of what they point to. + */ + uint8_t **bpptr; + + /* Convert our void pointer to a pointer to a byte pointer to a pointer */ + bpptr = (uint8_t **)vpptr; + + /* Add 'n' bytes to our pointer value */ + (*bpptr) += n; +} + + + + + + + +#endif /* __USBCORE_H__ */ diff --git a/macusbfb/core/usbcdc/usbdesc.c b/macusbfb/core/usbcdc/usbdesc.c new file mode 100644 index 0000000..56a5001 --- /dev/null +++ b/macusbfb/core/usbcdc/usbdesc.c @@ -0,0 +1,202 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usbdesc.c + * Purpose: USB Descriptors + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------- + * History: + * V1.20 Changed string descriptor handling + * V1.00 Initial Version + *---------------------------------------------------------------------------*/ +#include "projectconfig.h" +#include "usb.h" +#include "cdc.h" +#include "usbcfg.h" +#include "usbdesc.h" +#include "config.h" + + +/* USB Standard Device Descriptor */ +const uint8_t USB_DeviceDescriptor[] = { + USB_DEVICE_DESC_SIZE, /* bLength */ + USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ + WBVAL(0x0200), /* 2.0 */ /* bcdUSB */ + USB_DEVICE_CLASS_COMMUNICATIONS, /* bDeviceClass CDC*/ + 0x00, /* bDeviceSubClass */ + 0x00, /* bDeviceProtocol */ + USB_MAX_PACKET0, /* bMaxPacketSize0 */ + WBVAL(USB_VENDOR_ID), /* idVendor */ + WBVAL(USB_PROD_ID), /* idProduct */ + WBVAL(USB_DEVICE), /* 1.00 */ /* bcdDevice */ + 0x01, /* iManufacturer */ + 0x02, /* iProduct */ + 0x03, /* iSerialNumber */ + 0x01 /* bNumConfigurations: one possible configuration*/ +}; + +/* USB Configuration Descriptor */ +/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ +const uint8_t USB_ConfigDescriptor[] = { +/* Configuration 1 */ + USB_CONFIGUARTION_DESC_SIZE, /* bLength */ + USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */ + WBVAL( /* wTotalLength */ + 1*USB_CONFIGUARTION_DESC_SIZE + + 1*USB_INTERFACE_DESC_SIZE + /* communication interface */ + 0x0013 + /* CDC functions */ + 1*USB_ENDPOINT_DESC_SIZE + /* interrupt endpoint */ + 1*USB_INTERFACE_DESC_SIZE + /* data interface */ + 2*USB_ENDPOINT_DESC_SIZE /* bulk endpoints */ + ), + 0x02, /* bNumInterfaces */ + 0x01, /* bConfigurationValue: 0x01 is used to select this configuration */ + 0x00, /* iConfiguration: no string to describe this configuration */ + USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */ +/*USB_CONFIG_REMOTE_WAKEUP*/, + USB_CONFIG_POWER_MA(100), /* bMaxPower, device power consumption is 100 mA */ +/* Interface 0, Alternate Setting 0, Communication class interface descriptor */ + USB_INTERFACE_DESC_SIZE, /* bLength */ + USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ + USB_CDC_CIF_NUM, /* bInterfaceNumber: Number of Interface */ + 0x00, /* bAlternateSetting: Alternate setting */ + 0x01, /* bNumEndpoints: One endpoint used */ + CDC_COMMUNICATION_INTERFACE_CLASS, /* bInterfaceClass: Communication Interface Class */ + CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass: Abstract Control Model */ + 0x00, /* bInterfaceProtocol: no protocol used */ + 0x5E, /* iInterface: */ +/*Header Functional Descriptor*/ + 0x05, /* bLength: Endpoint Descriptor size */ + CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */ + CDC_HEADER, /* bDescriptorSubtype: Header Func Desc */ + WBVAL(CDC_V1_10), /* 1.10 */ /* bcdCDC */ +/*Call Management Functional Descriptor*/ + 0x05, /* bFunctionLength */ + CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */ + CDC_CALL_MANAGEMENT, /* bDescriptorSubtype: Call Management Func Desc */ + 0x01, /* bmCapabilities: device handles call management */ + 0x01, /* bDataInterface: CDC data IF ID */ +/*Abstract Control Management Functional Descriptor*/ + 0x04, /* bFunctionLength */ + CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */ + CDC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype: Abstract Control Management desc */ + 0x02, /* bmCapabilities: SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported */ +/*Union Functional Descriptor*/ + 0x05, /* bFunctionLength */ + CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */ + CDC_UNION, /* bDescriptorSubtype: Union func desc */ + USB_CDC_CIF_NUM, /* bMasterInterface: Communication class interface is master */ + USB_CDC_DIF_NUM, /* bSlaveInterface0: Data class interface is slave 0 */ +/*Endpoint 1 Descriptor*/ /* event notification (optional) */ + USB_ENDPOINT_DESC_SIZE, /* bLength */ + USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ + USB_ENDPOINT_IN(1), /* bEndpointAddress */ + USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ + WBVAL(0x0010), /* wMaxPacketSize */ + 0x02, /* 2ms */ /* bInterval */ +/* Interface 1, Alternate Setting 0, Data class interface descriptor*/ + USB_INTERFACE_DESC_SIZE, /* bLength */ + USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ + USB_CDC_DIF_NUM, /* bInterfaceNumber: Number of Interface */ + 0x00, /* bAlternateSetting: no alternate setting */ + 0x02, /* bNumEndpoints: two endpoints used */ + CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass: Data Interface Class */ + 0x00, /* bInterfaceSubClass: no subclass available */ + 0x00, /* bInterfaceProtocol: no protocol used */ + 0x5E, /* iInterface: */ +/* Endpoint, EP3 Bulk Out */ + USB_ENDPOINT_DESC_SIZE, /* bLength */ + USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ + USB_ENDPOINT_OUT(3), /* bEndpointAddress */ + USB_ENDPOINT_TYPE_BULK, /* bmAttributes */ + WBVAL(USB_CDC_BUFSIZE), /* wMaxPacketSize */ + 0x00, /* bInterval: ignore for Bulk transfer */ +/* Endpoint, EP3 Bulk In */ + USB_ENDPOINT_DESC_SIZE, /* bLength */ + USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ + USB_ENDPOINT_IN(3), /* bEndpointAddress */ + USB_ENDPOINT_TYPE_BULK, /* bmAttributes */ + WBVAL(USB_CDC_BUFSIZE), /* wMaxPacketSize */ + 0x00, /* bInterval: ignore for Bulk transfer */ +/* Terminator */ + 0 /* bLength */ +}; + + + + +/* USB String Descriptor (optional) */ +const uint8_t USB_StringDescriptor[] = { +/* Index 0x00: LANGID Codes */ + 0x04, /* bLength */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + WBVAL(0x0409), /* US English */ /* wLANGID */ +/* Index 0x01: Manufacturer */ + (13*2 + 2), /* bLength (13 Char + Type + lenght) */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + 'N',0, + 'X',0, + 'P',0, + ' ',0, + 'S',0, + 'E',0, + 'M',0, + 'I',0, + 'C',0, + 'O',0, + 'N',0, + 'D',0, + ' ',0, +/* Index 0x02: Product */ + (17*2 + 2), /* bLength ( 17 Char + Type + lenght) */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + 'N',0, + 'X',0, + 'P',0, + ' ',0, + 'L',0, + 'P',0, + 'C',0, + '1',0, + '3',0, + 'x',0, + 'x',0, + ' ',0, + 'V',0, + 'C',0, + 'O',0, + 'M',0, + ' ',0, +/* Index 0x03: Serial Number */ + (12*2 + 2), /* bLength (12 Char + Type + lenght) */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + 'D',0, + 'E',0, + 'M',0, + 'O',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, +/* Index 0x04: Interface 0, Alternate Setting 0 */ + ( 4*2 + 2), /* bLength (4 Char + Type + lenght) */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + 'V',0, + 'C',0, + 'O',0, + 'M',0, +}; diff --git a/macusbfb/core/usbcdc/usbdesc.h b/macusbfb/core/usbcdc/usbdesc.h new file mode 100644 index 0000000..b6eeddc --- /dev/null +++ b/macusbfb/core/usbcdc/usbdesc.h @@ -0,0 +1,35 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usbdesc.h + * Purpose: USB Descriptors Definitions + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#ifndef __USBDESC_H__ +#define __USBDESC_H__ + + +#define WBVAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF) + +#define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR)) +#define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR)) +#define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR)) +#define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR)) + +extern const uint8_t USB_DeviceDescriptor[]; +extern const uint8_t USB_ConfigDescriptor[]; +extern const uint8_t USB_StringDescriptor[]; + + +#endif /* __USBDESC_H__ */ diff --git a/macusbfb/core/usbcdc/usbhw.c b/macusbfb/core/usbcdc/usbhw.c new file mode 100644 index 0000000..8c52b28 --- /dev/null +++ b/macusbfb/core/usbcdc/usbhw.c @@ -0,0 +1,568 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usbhw.c + * Purpose: USB Hardware Layer Module for Philips LPC17xx + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------- + * History: + * V1.20 Added USB_ClearEPBuf + * V1.00 Initial Version + *----------------------------------------------------------------------------*/ +#include "projectconfig.h" /* LPC13xx definitions */ +#include "usb.h" +#include "usbcfg.h" +#include "usbreg.h" +#include "usbhw.h" +#include "usbcore.h" +#include "usbuser.h" + + +/* + * USB and IO Clock configuration only. + * The same as call PeriClkIOInit(IOCON_USB); + * The purpose is to reduce the code space for + * overall USB project and reserve code space for + * USB debugging. + * Parameters: None + * Return Value: None + */ +void USBIOClkConfig( void ) +{ + /* Enable AHB clock to the GPIO domain. */ + SCB_SYSAHBCLKCTRL |= SCB_SYSAHBCLKCTRL_GPIO; + + /* Enable Timer32_1, IOCON, and USB blocks */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT32B1 | SCB_SYSAHBCLKCTRL_IOCON | SCB_SYSAHBCLKCTRL_USB_REG); + + // Setup USB clock + SCB_PDRUNCFG &= ~(SCB_PDSLEEPCFG_USBPAD_PD); // Power-up USB PHY + SCB_PDRUNCFG &= ~(SCB_PDSLEEPCFG_USBPLL_PD); // Power-up USB PLL + + SCB_USBPLLCLKSEL = SCB_USBPLLCLKSEL_SOURCE_MAINOSC; // Select PLL Input + SCB_USBPLLCLKUEN = SCB_USBPLLCLKUEN_UPDATE; // Update Clock Source + SCB_USBPLLCLKUEN = SCB_USBPLLCLKUEN_DISABLE; // Toggle Update Register + SCB_USBPLLCLKUEN = SCB_USBPLLCLKUEN_UPDATE; + + // Wait until the USB clock is updated + while (!(SCB_USBPLLCLKUEN & SCB_USBPLLCLKUEN_UPDATE)); + + // Set USB clock to 48MHz (12MHz x 4) + SCB_USBPLLCTRL = (SCB_USBPLLCTRL_MULT_4); + while (!(SCB_USBPLLSTAT & SCB_USBPLLSTAT_LOCK)); // Wait Until PLL Locked + SCB_USBCLKSEL = SCB_USBCLKSEL_SOURCE_USBPLLOUT; + + // Set USB pin functions + IOCON_PIO0_1 &= ~IOCON_PIO0_1_FUNC_MASK; + IOCON_PIO0_1 |= IOCON_PIO0_1_FUNC_CLKOUT; // CLK OUT + IOCON_PIO0_3 &= ~IOCON_PIO0_3_FUNC_MASK; + IOCON_PIO0_3 |= IOCON_PIO0_3_FUNC_USB_VBUS; // VBus + IOCON_PIO0_6 &= ~IOCON_PIO0_6_FUNC_MASK; + IOCON_PIO0_6 |= IOCON_PIO0_6_FUNC_USB_CONNECT; // Soft Connect + + return; +} + +/* + * Delay number of clock cycles + * Parameters: Delay length + * Return Value: None + */ + +void delay (uint32_t length ) +{ + uint32_t i; + + for ( i = 0; i < length; i++ ) + { + __asm("nop"); + } + return; +} + +/* + * Get Endpoint Physical Address + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * Return Value: Endpoint Physical Address + */ + +uint32_t EPAdr (uint32_t EPNum) +{ + uint32_t val; + + val = (EPNum & 0x0F) << 1; + if (EPNum & 0x80) { + val += 1; + } + return (val); +} + + +/* + * Write Command + * Parameters: cmd: Command + * Return Value: None + */ + +void WrCmd (uint32_t cmd) +{ + USB_DEVINTCLR = CCEMTY_INT; + USB_CMDCODE = cmd; + while ((USB_DEVINTST & (CCEMTY_INT | DEV_STAT_INT)) == 0); +} + + +/* + * Write Command Data + * Parameters: cmd: Command + * val: Data + * Return Value: None + */ + +void WrCmdDat (uint32_t cmd, uint32_t val) +{ + WrCmd(cmd); + WrCmd(val); +} + + +/* + * Write Command to Endpoint + * Parameters: cmd: Command + * val: Data + * Return Value: None + */ + +void WrCmdEP (uint32_t EPNum, uint32_t cmd) +{ + WrCmd(CMD_SEL_EP(EPAdr(EPNum))); + WrCmd(cmd); +} + + +/* + * Read Command Data + * Parameters: cmd: Command + * Return Value: Data Value + */ + +uint32_t RdCmdDat (uint32_t cmd) +{ + USB_DEVINTCLR = CCEMTY_INT | CDFULL_INT; + USB_CMDCODE = cmd; + while ((USB_DEVINTST & (CDFULL_INT | DEV_STAT_INT)) == 0); + return (USB_CMDDATA); +} + + +/* + * USB Initialize Function + * Called by the User to initialize USB + * Return Value: None + */ + +void USB_Init (void) +{ + // Setup USB clock and pins + USBIOClkConfig(); + +#if USB_FIQ_EVENT + /* It's important that only BULK and FRAME(ISO) can be routed + to FIQ. */ + USB_DEVFIQSEL = 0x01; /* SOF Use FIQ */ + + /* Enable the USB Interrupt */ + NVIC_EnableIRQ(USB_FIQn); +#endif + + /* Enable the USB Interrupt */ + NVIC_EnableIRQ(USB_IRQn); + + USB_Reset(); + USB_SetAddress(0); + return; +} + + +/* + * USB Connect Function + * Called by the User to Connect/Disconnect USB + * Parameters: con: Connect/Disconnect + * Return Value: None + */ + +void USB_Connect (uint32_t con) +{ + WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(con ? DEV_CON : 0)); +} + + +/* + * USB Reset Function + * Called automatically on USB Reset + * Return Value: None + */ + +void USB_Reset (void) +{ + USB_DEVINTCLR = 0x000FFFFF; + /* Enable all eight(8) EPs, note: EP won't be ready until it's + configured/enabled when device sending SetEPStatus command + to the command engine. */ + USB_DEVINTEN = DEV_STAT_INT | (0xFF<<1) | + (USB_SOF_EVENT ? FRAME_INT : 0); + return; +} + + +/* + * USB Suspend Function + * Called automatically on USB Suspend + * Return Value: None + */ + +void USB_Suspend (void) +{ + /* Performed by Hardware */ +} + + +/* + * USB Resume Function + * Called automatically on USB Resume + * Return Value: None + */ + +void USB_Resume (void) +{ + /* Performed by Hardware */ +} + + +/* + * USB Remote Wakeup Function + * Called automatically on USB Remote Wakeup + * Return Value: None + */ + +void USB_WakeUp (void) +{ + if (USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP) + { + WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON)); + } +} + + +/* + * USB Remote Wakeup Configuration Function + * Parameters: cfg: Enable/Disable + * Return Value: None + */ + +void USB_WakeUpCfg (uint32_t cfg) +{ + cfg = cfg; /* Not needed */ +} + + +/* + * USB Set Address Function + * Parameters: adr: USB Address + * Return Value: None + */ + +void USB_SetAddress (uint32_t adr) +{ + WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Don't wait for next */ + WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Setup Status Phase */ +} + + +/* + * USB Configure Function + * Parameters: cfg: Configure/Deconfigure + * Return Value: None + */ + +void USB_Configure (uint32_t cfg) +{ + WrCmdDat(CMD_CFG_DEV, DAT_WR_BYTE(cfg ? CONF_DVICE : 0)); + return; +} + + +/* + * Configure USB Endpoint according to Descriptor + * Parameters: pEPD: Pointer to Endpoint Descriptor + * Return Value: None + */ + +void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) +{ + return; +} + + +/* + * Set Direction for USB Control Endpoint + * Parameters: dir: Out (dir == 0), In (dir <> 0) + * Return Value: None + */ + +void USB_DirCtrlEP (uint32_t dir) +{ + dir = dir; /* Not needed */ +} + + +/* + * Enable USB Endpoint + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * Return Value: None + */ + +void USB_EnableEP (uint32_t EPNum) +{ + WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0)); +} + + +/* + * Disable USB Endpoint + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * Return Value: None + */ + +void USB_DisableEP (uint32_t EPNum) +{ + WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(EP_STAT_DA)); +} + + +/* + * Reset USB Endpoint + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * Return Value: None + */ + +void USB_ResetEP (uint32_t EPNum) +{ + WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0)); +} + + +/* + * Set Stall for USB Endpoint + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * Return Value: None + */ + +void USB_SetStallEP (uint32_t EPNum) +{ + WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(EP_STAT_ST)); +} + + +/* + * Clear Stall for USB Endpoint + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * Return Value: None + */ + +void USB_ClrStallEP (uint32_t EPNum) +{ + WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0)); +} + + +/* + * Clear USB Endpoint Buffer + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * Return Value: None + */ + +void USB_ClearEPBuf (uint32_t EPNum) +{ + WrCmdEP(EPNum, CMD_CLR_BUF); +} + + +/* + * Read USB Endpoint Data + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * pData: Pointer to Data Buffer + * Return Value: Number of bytes read + */ + +uint32_t USB_ReadEP (uint32_t EPNum, uint8_t *pData) +{ + uint32_t cnt, n; + + USB_CTRL = ((EPNum & 0x0F) << 2) | CTRL_RD_EN; + /* 3 clock cycles to fetch the packet length from RAM. */ + delay( 5 ); + + do + { + cnt = USB_RXPLEN; + } while ((cnt & PKT_DV) == 0); + cnt &= PKT_LNGTH_MASK; + + for (n = 0; n < (cnt + 3) / 4; n++) + { + *((uint32_t __attribute__((packed)) *)pData) = USB_RXDATA; + pData += 4; + } + + USB_CTRL = 0; + + if ((EPNum & 0x80) != 0x04) + { /* Non-Isochronous Endpoint */ + WrCmdEP(EPNum, CMD_CLR_BUF); + } + + return (cnt); +} + + +/* + * Write USB Endpoint Data + * Parameters: EPNum: Endpoint Number + * EPNum.0..3: Address + * EPNum.7: Dir + * pData: Pointer to Data Buffer + * cnt: Number of bytes to write + * Return Value: Number of bytes written + */ + +uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt) +{ + uint32_t n; + + USB_CTRL = ((EPNum & 0x0F) << 2) | CTRL_WR_EN; + /* 3 clock cycles to fetch the packet length from RAM. */ + delay( 5 ); + USB_TXPLEN = cnt; + + for (n = 0; n < (cnt + 3) / 4; n++) + { + USB_TXDATA = *((uint32_t __attribute__((packed)) *)pData); + pData += 4; + } + + USB_CTRL = 0; + + WrCmdEP(EPNum, CMD_VALID_BUF); + + return (cnt); +} + +/* + * Get USB Last Frame Number + * Parameters: None + * Return Value: Frame Number + */ + +uint32_t USB_GetFrame (void) +{ + uint32_t val; + + WrCmd(CMD_RD_FRAME); + val = RdCmdDat(DAT_RD_FRAME); + val = val | (RdCmdDat(DAT_RD_FRAME) << 8); + + return (val); +} + + +/* + * USB Interrupt Service Routine + */ + +#ifdef CFG_USBCDC +void USB_IRQHandler (void) +{ + uint32_t disr, val, n, m; + + disr = USB_DEVINTST; /* Device Interrupt Status */ + USB_DEVINTCLR = disr; + + /* Device Status Interrupt (Reset, Connect change, Suspend/Resume) */ + if (disr & DEV_STAT_INT) + { + WrCmd(CMD_GET_DEV_STAT); + val = RdCmdDat(DAT_GET_DEV_STAT); /* Device Status */ + if (val & DEV_RST) { /* Reset */ + USB_Reset(); + } + if (val & DEV_CON_CH) { /* Connect change */ + } + if (val & DEV_SUS_CH) { /* Suspend/Resume */ + } + goto isr_end; + } + + + /* Endpoint's Interrupt */ + if (disr & (0xFF<<1)) { + /* if any of the EP0 through EP7 is set, or bit 1 through 9 on disr */ + for (n = 0; n < USB_EP_NUM; n++) { /* Check All Endpoints */ + /* skip frame interrupt at bit 0 in disr */ +// if (disr & ((1 << n)<<1)) { + if ((disr>>1) & (1 << n)) { + m = n >> 1; + /* clear EP interrupt by sending cmd to the command engine. */ + WrCmd(CMD_SEL_EP_CLRI(n)); + val = RdCmdDat(DAT_SEL_EP_CLRI(n)); + if ((n & 1) == 0) { /* OUT Endpoint */ + if (n == 0) { /* Control OUT Endpoint */ + if (val & EP_SEL_STP) { /* Setup Packet */ + if (USB_P_EP[0]) { + USB_P_EP[0](USB_EVT_SETUP); + continue; + } + } + } + if (USB_P_EP[m]) { + USB_P_EP[m](USB_EVT_OUT); + } + } else { /* IN Endpoint */ + if (USB_P_EP[m]) { + USB_P_EP[m](USB_EVT_IN); + } + } + } + } + } +isr_end: + return; +} + +#endif \ No newline at end of file diff --git a/macusbfb/core/usbcdc/usbhw.h b/macusbfb/core/usbcdc/usbhw.h new file mode 100644 index 0000000..f31d7d3 --- /dev/null +++ b/macusbfb/core/usbcdc/usbhw.h @@ -0,0 +1,62 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usbhw.h + * Purpose: USB Hardware Layer Definitions + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------- + * History: + * V1.20 Added USB_ClearEPBuf + * V1.00 Initial Version + *----------------------------------------------------------------------------*/ + +#ifndef __USBHW_H__ +#define __USBHW_H__ + + +/* USB Error Codes */ +#define USB_ERR_PID 0x0001 /* PID Error */ +#define USB_ERR_UEPKT 0x0002 /* Unexpected Packet */ +#define USB_ERR_DCRC 0x0004 /* Data CRC Error */ +#define USB_ERR_TIMOUT 0x0008 /* Bus Time-out Error */ +#define USB_ERR_EOP 0x0010 /* End of Packet Error */ +#define USB_ERR_B_OVRN 0x0020 /* Buffer Overrun */ +#define USB_ERR_BTSTF 0x0040 /* Bit Stuff Error */ +#define USB_ERR_TGL 0x0080 /* Toggle Bit Error */ + +/* USB Hardware Functions */ +extern void USBIOClkConfig (void); +extern void USB_Init (void); +extern void USB_Connect (uint32_t con); +extern void USB_Reset (void); +extern void USB_Suspend (void); +extern void USB_Resume (void); +extern void USB_WakeUp (void); +extern void USB_WakeUpCfg (uint32_t cfg); +extern void USB_SetAddress (uint32_t adr); +extern void USB_Configure (uint32_t cfg); +extern void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD); +extern void USB_DirCtrlEP (uint32_t dir); +extern void USB_EnableEP (uint32_t EPNum); +extern void USB_DisableEP (uint32_t EPNum); +extern void USB_ResetEP (uint32_t EPNum); +extern void USB_SetStallEP (uint32_t EPNum); +extern void USB_ClrStallEP (uint32_t EPNum); +extern void USB_ClearEPBuf (uint32_t EPNum); +extern uint32_t USB_ReadEP (uint32_t EPNum, uint8_t *pData); +extern uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt); +extern uint32_t USB_GetFrame(void); +extern void USB_IRQHandler (void); + + +#endif /* __USBHW_H__ */ diff --git a/macusbfb/core/usbcdc/usbreg.h b/macusbfb/core/usbcdc/usbreg.h new file mode 100644 index 0000000..d059e6a --- /dev/null +++ b/macusbfb/core/usbcdc/usbreg.h @@ -0,0 +1,134 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: USBREG.H + * Purpose: USB Hardware Layer Definitions for NXP LPC13xx + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#ifndef __USBREG_H +#define __USBREG_H + +/* Device Interrupt Bit Definitions */ +#define FRAME_INT (0x1<<0) +#define EP0_INT (0x1<<1) +#define EP1_INT (0x1<<2) +#define EP2_INT (0x1<<3) +#define EP3_INT (0x1<<4) +#define EP4_INT (0x1<<5) +#define EP5_INT (0x1<<6) +#define EP6_INT (0x1<<7) +#define EP7_INT (0x1<<8) +#define DEV_STAT_INT (0x1<<9) +#define CCEMTY_INT (0x1<<10) +#define CDFULL_INT (0x1<<11) +#define RxENDPKT_INT (0x1<<12) +#define TxENDPKT_INT (0x1<<13) + +/* Rx & Tx Packet Length Definitions */ +#define PKT_LNGTH_MASK 0x000003FF +#define PKT_DV 0x00000400 +#define PKT_RDY 0x00000800 + +/* USB Control Definitions */ +#define CTRL_RD_EN 0x00000001 +#define CTRL_WR_EN 0x00000002 + +/* Command Codes */ +#define CMD_SET_ADDR 0x00D00500 +#define CMD_CFG_DEV 0x00D80500 +#define CMD_SET_MODE 0x00F30500 +#define CMD_RD_INT 0x00F40500 +#define DAT_RD_INT 0x00F40200 +#define CMD_RD_FRAME 0x00F50500 +#define DAT_RD_FRAME 0x00F50200 +#define CMD_RD_CHIP_ID 0x00FD0500 +#define DAT_RD_CHIP_ID 0x00FD0200 + +#define CMD_SET_DEV_STAT 0x00FE0500 +#define CMD_GET_DEV_STAT 0x00FE0500 +#define DAT_GET_DEV_STAT 0x00FE0200 +#define CMD_GET_ERR_CODE 0x00FF0500 +#define DAT_GET_ERR_CODE 0x00FF0200 + +#define DAT_WR_BYTE(x) (0x00000100 | ((x) << 16)) +#define CMD_SEL_EP(x) (0x00000500 | ((x) << 16)) +#define DAT_SEL_EP(x) (0x00000200 | ((x) << 16)) +#define CMD_SEL_EP_CLRI(x) (0x00400500 | ((x) << 16)) +#define DAT_SEL_EP_CLRI(x) (0x00400200 | ((x) << 16)) +#define CMD_SET_EP_STAT(x) (0x00400500 | ((x) << 16)) +#define CMD_CLR_BUF 0x00F20500 +#define CMD_VALID_BUF 0x00FA0500 + +/* Device Address Register Definitions */ +#define DEV_ADDR_MASK 0x7F +#define DEV_EN 0x80 + +/* Device Configure Register Definitions */ +#define CONF_DVICE 0x01 + +/* Device Mode Register Definitions */ +#define AP_CLK 0x01 +#define INAK_CI 0x02 +#define INAK_CO 0x04 +#define INAK_AI 0x08 +#define INAK_AO 0x10 + +/* Device Status Register Definitions */ +#define DEV_CON 0x01 +#define DEV_CON_CH 0x02 +#define DEV_SUS 0x04 +#define DEV_SUS_CH 0x08 +#define DEV_RST 0x10 + +/* Error Code Register Definitions */ +#define ERR_EC_MASK 0x0F +#define ERR_EA 0x10 + +/* Error Status Register Definitions */ +#define ERR_NOERROR 0x00 +#define ERR_PID_ENCODE 0x01 +#define ERR_UNKNOWN_PID 0x02 +#define ERR_UNEXPECT_PKT 0x03 +#define ERR_TCRC 0x04 +#define ERR_DCRC 0x05 +#define ERR_TIMEOUT 0x06 +#define ERR_BABBIE 0x07 +#define ERR_EOF_PKT 0x08 +#define ERR_TX_RX_NAK 0x09 +#define ERR_SENT_STALL 0x0A +#define ERR_BUF_OVERRUN 0x0B +#define ERR_SENT_EPT_PKT 0x0C +#define ERR_BIT_STUFF 0x0D +#define ERR_SYNC 0x0E +#define ERR_TOGGLE_BIT 0x0F + +/* Endpoint Select Register Definitions */ +#define EP_SEL_F 0x01 +#define EP_SEL_ST 0x02 +#define EP_SEL_STP 0x04 +#define EP_SEL_PO 0x08 +#define EP_SEL_EPN 0x10 +#define EP_SEL_B_1_FULL 0x20 +#define EP_SEL_B_2_FULL 0x40 + +/* Endpoint Status Register Definitions */ +#define EP_STAT_ST 0x01 +#define EP_STAT_DA 0x20 +#define EP_STAT_RF_MO 0x40 +#define EP_STAT_CND_ST 0x80 + +/* Clear Buffer Register Definitions */ +#define CLR_BUF_PO 0x01 + +#endif /* __USBREG_H */ diff --git a/macusbfb/core/usbcdc/usbuser.c b/macusbfb/core/usbcdc/usbuser.c new file mode 100644 index 0000000..54f7b9e --- /dev/null +++ b/macusbfb/core/usbcdc/usbuser.c @@ -0,0 +1,208 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usbuser.c + * Purpose: USB Custom User Module + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ +#include "projectconfig.h" + +#include "usb.h" +#include "usbcfg.h" +#include "usbhw.h" +#include "usbcore.h" +#include "usbuser.h" +#include "cdcuser.h" + + +/* + * USB Power Event Callback + * Called automatically on USB Power Event + * Parameter: power: On(TRUE)/Off(FALSE) + */ + +#if USB_POWER_EVENT +void USB_Power_Event (uint32_t power) { +} +#endif + + +/* + * USB Reset Event Callback + * Called automatically on USB Reset Event + */ + +#if USB_RESET_EVENT +void USB_Reset_Event (void) { + USB_ResetCore(); +} +#endif + + +/* + * USB Suspend Event Callback + * Called automatically on USB Suspend Event + */ + +#if USB_SUSPEND_EVENT +void USB_Suspend_Event (void) { +} +#endif + + +/* + * USB Resume Event Callback + * Called automatically on USB Resume Event + */ + +#if USB_RESUME_EVENT +void USB_Resume_Event (void) { +} +#endif + + +/* + * USB Remote Wakeup Event Callback + * Called automatically on USB Remote Wakeup Event + */ + +#if USB_WAKEUP_EVENT +void USB_WakeUp_Event (void) { +} +#endif + + +/* + * USB Start of Frame Event Callback + * Called automatically on USB Start of Frame Event + */ + +#if USB_SOF_EVENT +void USB_SOF_Event (void) { +} +#endif + + +/* + * USB Error Event Callback + * Called automatically on USB Error Event + * Parameter: error: Error Code + */ + +#if USB_ERROR_EVENT +void USB_Error_Event (uint32_t error) { +} +#endif + + +/* + * USB Set Configuration Event Callback + * Called automatically on USB Set Configuration Request + */ + +#if USB_CONFIGURE_EVENT +void USB_Configure_Event (void) { + + if (USB_Configuration) { /* Check if USB is configured */ + /* add your code here */ + } +} +#endif + + +/* + * USB Set Interface Event Callback + * Called automatically on USB Set Interface Request + */ + +#if USB_INTERFACE_EVENT +void USB_Interface_Event (void) { +} +#endif + + +/* + * USB Set/Clear Feature Event Callback + * Called automatically on USB Set/Clear Feature Request + */ + +#if USB_FEATURE_EVENT +void USB_Feature_Event (void) { +} +#endif + + +#define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL) + +/* USB Endpoint Events Callback Pointers */ +void (* const USB_P_EP[USB_LOGIC_EP_NUM]) (uint32_t event) = { + P_EP(0), + P_EP(1), + P_EP(2), + P_EP(3), + P_EP(4), +}; + + +/* + * USB Endpoint 1 Event Callback + * Called automatically on USB Endpoint 1 Event + * Parameter: event + */ + +void USB_EndPoint1 (uint32_t event) { + uint16_t temp; + static uint16_t serialState; + + switch (event) { + case USB_EVT_IN: + temp = CDC_GetSerialState(); + if (serialState != temp) { + serialState = temp; + CDC_NotificationIn(); /* send SERIAL_STATE notification */ + } + break; + } +} + + +/* + * USB Endpoint 2 Event Callback + * Called automatically on USB Endpoint 2 Event + * Parameter: event + */ + +void USB_EndPoint2 (uint32_t event) +{ + event = event; +} + + +/* + * USB Endpoint 3 Event Callback + * Called automatically on USB Endpoint 3 Event + * Parameter: event + */ + +void USB_EndPoint3 (uint32_t event) { + switch (event) { + case USB_EVT_OUT: + CDC_BulkOut (); /* data received from Host */ + break; + case USB_EVT_IN: + CDC_BulkIn (); /* data expected from Host */ + break; + } +} + + diff --git a/macusbfb/core/usbcdc/usbuser.h b/macusbfb/core/usbcdc/usbuser.h new file mode 100644 index 0000000..e4109ec --- /dev/null +++ b/macusbfb/core/usbcdc/usbuser.h @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: USBUSER.H + * Purpose: USB Custom User Definitions + * Version: V1.10 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2005-2009 Keil Software. + *---------------------------------------------------------------------------*/ + +#ifndef __USBUSER_H__ +#define __USBUSER_H__ + + +/* USB Device Events Callback Functions */ +extern void USB_Power_Event (uint32_t power); +extern void USB_Reset_Event (void); +extern void USB_Suspend_Event (void); +extern void USB_Resume_Event (void); +extern void USB_WakeUp_Event (void); +extern void USB_SOF_Event (void); +extern void USB_Error_Event (uint32_t error); + +/* USB Endpoint Callback Events */ +#define USB_EVT_SETUP 1 /* Setup Packet */ +#define USB_EVT_OUT 2 /* OUT Packet */ +#define USB_EVT_IN 3 /* IN Packet */ +#define USB_EVT_OUT_NAK 4 /* OUT Packet - Not Acknowledged */ +#define USB_EVT_IN_NAK 5 /* IN Packet - Not Acknowledged */ +#define USB_EVT_OUT_STALL 6 /* OUT Packet - Stalled */ +#define USB_EVT_IN_STALL 7 /* IN Packet - Stalled */ + +/* USB Endpoint Events Callback Pointers */ +extern void (* const USB_P_EP[USB_LOGIC_EP_NUM])(uint32_t event); + +/* USB Endpoint Events Callback Functions */ +extern void USB_EndPoint0 (uint32_t event); +extern void USB_EndPoint1 (uint32_t event); +extern void USB_EndPoint2 (uint32_t event); +extern void USB_EndPoint3 (uint32_t event); +extern void USB_EndPoint4 (uint32_t event); + +/* USB Core Events Callback Functions */ +extern void USB_Configure_Event (void); +extern void USB_Interface_Event (void); +extern void USB_Feature_Event (void); + + +#endif /* __USBUSER_H__ */ diff --git a/macusbfb/core/usbhid-rom/rom_drivers.h b/macusbfb/core/usbhid-rom/rom_drivers.h new file mode 100644 index 0000000..1026608 --- /dev/null +++ b/macusbfb/core/usbhid-rom/rom_drivers.h @@ -0,0 +1,76 @@ +/**************************************************************************/ +/*! + @file rom_drivers.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef ROM_DRIVERS_H_ +#define ROM_DRIVERS_H_ + +#include "sysdefs.h" + +typedef struct _USB_DEVICE_INFO +{ + uint16_t DevType; + uint32_t DevDetailPtr; +} USB_DEV_INFO; + +typedef struct _USBD +{ + void (*init_clk_pins)(void); + void (*isr)(void); + void (*init)( USB_DEV_INFO * DevInfoPtr ); + void (*connect)(uint32_t con); +} USBD; + +typedef struct _ROM +{ + const USBD * pUSBD; +} ROM; + +typedef struct _HID_DEVICE_INFO +{ + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint32_t StrDescPtr; + uint8_t InReportCount; + uint8_t OutReportCount; + uint8_t SampleInterval; + void (*InReport)(uint8_t src[], uint32_t length); + void (*OutReport)(uint8_t dst[], uint32_t length); +} HID_DEVICE_INFO; + +#endif diff --git a/macusbfb/core/usbhid-rom/usb.h b/macusbfb/core/usbhid-rom/usb.h new file mode 100644 index 0000000..2e55b8c --- /dev/null +++ b/macusbfb/core/usbhid-rom/usb.h @@ -0,0 +1,240 @@ +/*---------------------------------------------------------------------------- + * U S B - K e r n e l + *---------------------------------------------------------------------------- + * Name: usb.h + * Purpose: USB Definitions + * Version: V1.20 + *---------------------------------------------------------------------------- + * This software is supplied "AS IS" without any warranties, express, + * implied or statutory, including but not limited to the implied + * warranties of fitness for purpose, satisfactory quality and + * noninfringement. Keil extends you a royalty-free right to reproduce + * and distribute executable files created using this software for use + * on NXP Semiconductors LPC microcontroller devices only. Nothing else + * gives you the right to use this software. + * + * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#ifndef __USB_H__ +#define __USB_H__ + +#include "sysdefs.h" + +typedef union +{ + uint16_t W; + struct + { + uint8_t L; + uint8_t H; + } __attribute__ ((packed)) WB; +} __attribute__ ((packed)) WORD_BYTE; + + +/* bmRequestType.Dir */ +#define REQUEST_HOST_TO_DEVICE 0 +#define REQUEST_DEVICE_TO_HOST 1 + +/* bmRequestType.Type */ +#define REQUEST_STANDARD 0 +#define REQUEST_CLASS 1 +#define REQUEST_VENDOR 2 +#define REQUEST_RESERVED 3 + +/* bmRequestType.Recipient */ +#define REQUEST_TO_DEVICE 0 +#define REQUEST_TO_INTERFACE 1 +#define REQUEST_TO_ENDPOINT 2 +#define REQUEST_TO_OTHER 3 + +/* bmRequestType Definition */ +typedef union _REQUEST_TYPE +{ + struct _BM + { + uint8_t Recipient : 5; + uint8_t Type : 2; + uint8_t Dir : 1; + } __attribute__ ((packed)) BM; + uint8_t B; +} __attribute__ ((packed)) REQUEST_TYPE; + +/* USB Standard Request Codes */ +#define USB_REQUEST_GET_STATUS 0 +#define USB_REQUEST_CLEAR_FEATURE 1 +#define USB_REQUEST_SET_FEATURE 3 +#define USB_REQUEST_SET_ADDRESS 5 +#define USB_REQUEST_GET_DESCRIPTOR 6 +#define USB_REQUEST_SET_DESCRIPTOR 7 +#define USB_REQUEST_GET_CONFIGURATION 8 +#define USB_REQUEST_SET_CONFIGURATION 9 +#define USB_REQUEST_GET_INTERFACE 10 +#define USB_REQUEST_SET_INTERFACE 11 +#define USB_REQUEST_SYNC_FRAME 12 + +/* USB GET_STATUS Bit Values */ +#define USB_GETSTATUS_SELF_POWERED 0x01 +#define USB_GETSTATUS_REMOTE_WAKEUP 0x02 +#define USB_GETSTATUS_ENDPOINT_STALL 0x01 + +/* USB Standard Feature selectors */ +#define USB_FEATURE_ENDPOINT_STALL 0 +#define USB_FEATURE_REMOTE_WAKEUP 1 + +/* USB Default Control Pipe Setup Packet */ +typedef struct _USB_SETUP_PACKET +{ + REQUEST_TYPE bmRequestType; + uint8_t bRequest; + WORD_BYTE wValue; + WORD_BYTE wIndex; + uint16_t wLength; +} __attribute__ ((packed)) USB_SETUP_PACKET; + + +/* USB Descriptor Types */ +#define USB_DEVICE_DESCRIPTOR_TYPE 1 +#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2 +#define USB_STRING_DESCRIPTOR_TYPE 3 +#define USB_INTERFACE_DESCRIPTOR_TYPE 4 +#define USB_ENDPOINT_DESCRIPTOR_TYPE 5 +#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6 +#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7 +#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8 +#define USB_OTG_DESCRIPTOR_TYPE 9 +#define USB_DEBUG_DESCRIPTOR_TYPE 10 +#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11 + +/* USB Device Classes */ +#define USB_DEVICE_CLASS_RESERVED 0x00 +#define USB_DEVICE_CLASS_AUDIO 0x01 +#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 +#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 +#define USB_DEVICE_CLASS_MONITOR 0x04 +#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05 +#define USB_DEVICE_CLASS_POWER 0x06 +#define USB_DEVICE_CLASS_PRINTER 0x07 +#define USB_DEVICE_CLASS_STORAGE 0x08 +#define USB_DEVICE_CLASS_HUB 0x09 +#define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF +#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF + +/* bmAttributes in Configuration Descriptor */ +#define USB_CONFIG_POWERED_MASK 0x40 +#define USB_CONFIG_BUS_POWERED 0x80 +#define USB_CONFIG_SELF_POWERED 0xC0 +#define USB_CONFIG_REMOTE_WAKEUP 0x20 + +/* bMaxPower in Configuration Descriptor */ +#define USB_CONFIG_POWER_MA(mA) ((mA)/2) + +/* bEndpointAddress in Endpoint Descriptor */ +#define USB_ENDPOINT_DIRECTION_MASK 0x80 +#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) +#define USB_ENDPOINT_IN(addr) ((addr) | 0x80) + +/* bmAttributes in Endpoint Descriptor */ +#define USB_ENDPOINT_TYPE_MASK 0x03 +#define USB_ENDPOINT_TYPE_CONTROL 0x00 +#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 +#define USB_ENDPOINT_TYPE_BULK 0x02 +#define USB_ENDPOINT_TYPE_INTERRUPT 0x03 +#define USB_ENDPOINT_SYNC_MASK 0x0C +#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00 +#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04 +#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08 +#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C +#define USB_ENDPOINT_USAGE_MASK 0x30 +#define USB_ENDPOINT_USAGE_DATA 0x00 +#define USB_ENDPOINT_USAGE_FEEDBACK 0x10 +#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20 +#define USB_ENDPOINT_USAGE_RESERVED 0x30 + +/* USB Standard Device Descriptor */ +typedef struct _USB_DEVICE_DESCRIPTOR +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} __attribute__ ((packed)) USB_DEVICE_DESCRIPTOR; + +/* USB 2.0 Device Qualifier Descriptor */ +typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t bNumConfigurations; + uint8_t bReserved; +} __attribute__ ((packed)) USB_DEVICE_QUALIFIER_DESCRIPTOR; + +/* USB Standard Configuration Descriptor */ +typedef struct _USB_CONFIGURATION_DESCRIPTOR +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; +} __attribute__ ((packed)) USB_CONFIGURATION_DESCRIPTOR; + +/* USB Standard Interface Descriptor */ +typedef struct _USB_INTERFACE_DESCRIPTOR +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} __attribute__ ((packed)) USB_INTERFACE_DESCRIPTOR; + +/* USB Standard Endpoint Descriptor */ +typedef struct _USB_ENDPOINT_DESCRIPTOR +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} __attribute__ ((packed)) USB_ENDPOINT_DESCRIPTOR; + +/* USB String Descriptor */ +typedef struct _USB_STRING_DESCRIPTOR +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bString/*[]*/; +} __attribute__ ((packed)) USB_STRING_DESCRIPTOR; + +/* USB Common Descriptor */ +typedef struct _USB_COMMON_DESCRIPTOR +{ + uint8_t bLength; + uint8_t bDescriptorType; +} __attribute__ ((packed)) USB_COMMON_DESCRIPTOR; + +#endif diff --git a/macusbfb/core/usbhid-rom/usbconfig.c b/macusbfb/core/usbhid-rom/usbconfig.c new file mode 100644 index 0000000..a9dc375 --- /dev/null +++ b/macusbfb/core/usbhid-rom/usbconfig.c @@ -0,0 +1,111 @@ +/**************************************************************************/ +/*! + @file usbconfig.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "usb.h" +#include "usbconfig.h" + +/* USB String Descriptor (optional) */ +const uint8_t USB_HIDStringDescriptor[] = +{ + /* Index 0x00: LANGID Codes */ + 0x04, /* bLength */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + WBVAL(0x0409), /* US English */ /* wLANGID */ + /* Index 0x04: Manufacturer */ + 0x1C, /* bLength */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + 'm',0, + 'i',0, + 'c',0, + 'r',0, + 'o',0, + 'B',0, + 'u',0, + 'i',0, + 'l',0, + 'd',0, + 'e',0, + 'r',0, + ' ',0, + /* Index 0x20: Product */ + 0x28, /* bLength */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + 'L',0, + 'P',0, + 'C',0, + '1',0, + '3',0, + '4',0, + '3',0, + ' ',0, + 'R',0, + 'e',0, + 'f',0, + '.',0, + ' ',0, + 'B',0, + 'o',0, + 'a',0, + 'r',0, + 'd',0, + ' ',0, + /* Index 0x48: Serial Number */ + 0x1A, /* bLength */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + '0',0, + /* Index 0x62: Interface 0, Alternate Setting 0 */ + 0x0E, /* bLength */ + USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ + 'H',0, + 'I',0, + 'D',0, + ' ',0, + ' ',0, + ' ',0, +}; diff --git a/macusbfb/core/usbhid-rom/usbconfig.h b/macusbfb/core/usbhid-rom/usbconfig.h new file mode 100644 index 0000000..c279b84 --- /dev/null +++ b/macusbfb/core/usbhid-rom/usbconfig.h @@ -0,0 +1,68 @@ +/**************************************************************************/ +/*! + @file usbconfig.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _USBCONFIG_H_ +#define _USBCONFIG_H_ + +#define USB_VID 0x1FC9 + +#define USB_VENDOR_ID USB_VID // Vendor ID +#define USB_PROD_ID 0x0003 // Product ID +#define USB_DEVICE 0x0100 // Device ID + +#define WBVAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF) + +#define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR)) +#define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR)) +#define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR)) +#define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR)) + +#define HID_DESC_OFFSET 0x0012 +#define HID_DESC_SIZE (sizeof(HID_DESCRIPTOR)) +#define HID_REPORT_DESC_SIZE (sizeof(HID_ReportDescriptor)) + +#include "projectconfig.h" + +extern const uint8_t USB_DeviceDescriptor[]; +extern const uint8_t USB_ConfigDescriptor[]; +extern const uint8_t USB_HIDStringDescriptor[]; + +extern const uint8_t HID_ReportDescriptor[]; +extern const uint16_t HID_ReportDescSize; + +#endif \ No newline at end of file diff --git a/macusbfb/core/usbhid-rom/usbhid.c b/macusbfb/core/usbhid-rom/usbhid.c new file mode 100644 index 0000000..af34cf1 --- /dev/null +++ b/macusbfb/core/usbhid-rom/usbhid.c @@ -0,0 +1,181 @@ +/**************************************************************************/ +/*! + @file usbhid.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "core/usbhid-rom/usb.h" +#include "core/usbhid-rom/usbconfig.h" +#include "core/usbhid-rom/rom_drivers.h" +#include "core/gpio/gpio.h" + +#include "usbhid.h" + +USB_DEV_INFO DeviceInfo; +HID_DEVICE_INFO HidDevInfo; +ROM ** rom = (ROM **)0x1fff1ff8; + +/**************************************************************************/ +/*! + @brief Gets the HID In Report (the report going from the LPC1343 to + the USB host) +*/ +/**************************************************************************/ +void usbHIDGetInReport (uint8_t src[], uint32_t length) +{ + uint8_t PCInReportData = 0; + + // ToDo: Move this logic elsewhere to keep code 'generic' + + // If LED enabled set bit 0 to 1 + if (!gpioGetValue(CFG_LED_PORT, CFG_LED_PIN)) + { + PCInReportData |= 1<<0; + } + + src[0] = PCInReportData; +} + +/**************************************************************************/ +/*! + @brief Sets the HID Out Report (the report coming in from the USB + host to the LPC1343). +*/ +/**************************************************************************/ +void usbHIDSetOutReport (uint8_t dst[], uint32_t length) +{ + uint8_t PCOutReportData = dst[0]; + // Check bit 0 in the incoming report to determine is LED should + // be enabled or disabled (1 = enabled, 0 = disabled) + if (PCOutReportData & (1<<0)) + { + // Enable LED (set low) + gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, 0); + } + else + { + // Disable LED (set high) + gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, 1); + } +} + +/**************************************************************************/ +/*! + @brief Initialises the USB port + + The ROM-based USB HID code is capable of configuring the PLL and pins + for USB, but there seems to be a bug in the code that sets the system + clock to 48MHz (normally the USB and System clocks can be configured + seperately). As such, this code does not use the "init_clk_pins()" + function in the rom, and the USB clock and pins are manually + configured. +*/ +/**************************************************************************/ +void usbHIDInit (void) +{ + // Setup USB clock + SCB_PDRUNCFG &= ~(SCB_PDSLEEPCFG_USBPAD_PD); // Power-up USB PHY + SCB_PDRUNCFG &= ~(SCB_PDSLEEPCFG_USBPLL_PD); // Power-up USB PLL + + SCB_USBPLLCLKSEL = SCB_USBPLLCLKSEL_SOURCE_MAINOSC; // Select PLL Input + SCB_USBPLLCLKUEN = SCB_USBPLLCLKUEN_UPDATE; // Update Clock Source + SCB_USBPLLCLKUEN = SCB_USBPLLCLKUEN_DISABLE; // Toggle Update Register + SCB_USBPLLCLKUEN = SCB_USBPLLCLKUEN_UPDATE; + + // Wait until the USB clock is updated + while (!(SCB_USBPLLCLKUEN & SCB_USBPLLCLKUEN_UPDATE)); + + // Set USB clock to 48MHz (12MHz x 4) + SCB_USBPLLCTRL = (SCB_USBPLLCTRL_MULT_4); + while (!(SCB_USBPLLSTAT & SCB_USBPLLSTAT_LOCK)); // Wait Until PLL Locked + SCB_USBCLKSEL = SCB_USBCLKSEL_SOURCE_USBPLLOUT; + + // Set USB pin functions + IOCON_PIO0_1 &= ~IOCON_PIO0_1_FUNC_MASK; + IOCON_PIO0_1 |= IOCON_PIO0_1_FUNC_CLKOUT; // CLK OUT + IOCON_PIO0_3 &= ~IOCON_PIO0_3_FUNC_MASK; + IOCON_PIO0_3 |= IOCON_PIO0_3_FUNC_USB_VBUS; // VBus + IOCON_PIO0_6 &= ~IOCON_PIO0_6_FUNC_MASK; + IOCON_PIO0_6 |= IOCON_PIO0_6_FUNC_USB_CONNECT; // Soft Connect + + // Disable internal resistor on VBUS (0.3) + gpioSetPullup(&IOCON_PIO0_3, gpioPullupMode_Inactive); + + // HID Device Info + volatile int n; + HidDevInfo.idVendor = USB_VENDOR_ID; + HidDevInfo.idProduct = USB_PROD_ID; + HidDevInfo.bcdDevice = USB_DEVICE; + HidDevInfo.StrDescPtr = (uint32_t)&USB_HIDStringDescriptor[0]; + #ifdef CFG_USBHID_EXAMPLE + HidDevInfo.InReportCount = 2; + HidDevInfo.OutReportCount = 2; + #else + HidDevInfo.InReportCount = 1; + HidDevInfo.OutReportCount = 1; + #endif + HidDevInfo.SampleInterval = 0x20; + HidDevInfo.InReport = usbHIDGetInReport; + HidDevInfo.OutReport = usbHIDSetOutReport; + + DeviceInfo.DevType = USB_DEVICE_CLASS_HUMAN_INTERFACE; + DeviceInfo.DevDetailPtr = (uint32_t)&HidDevInfo; + + /* Enable Timer32_1, IOCON, and USB blocks (for USB ROM driver) */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT32B1 | SCB_SYSAHBCLKCTRL_IOCON | SCB_SYSAHBCLKCTRL_USB_REG); + + /* Use pll and pin init function in rom */ + /* Warning: This will also set the system clock to 48MHz! */ + // (*rom)->pUSBD->init_clk_pins(); + + /* insert a delay between clk init and usb init */ + for (n = 0; n < 75; n++) {__asm("nop");} + + (*rom)->pUSBD->init(&DeviceInfo); /* USB Initialization */ + (*rom)->pUSBD->connect(TRUE); /* USB Connect */ +} + +/**************************************************************************/ +/*! + @brief Passes the USB interrupt to the internal ROM-based handler +*/ +/**************************************************************************/ +#ifdef CFG_USBHID +void USB_IRQHandler() +{ + (*rom)->pUSBD->isr(); +} +#endif + diff --git a/macusbfb/core/usbhid-rom/usbhid.h b/macusbfb/core/usbhid-rom/usbhid.h new file mode 100644 index 0000000..2c284d8 --- /dev/null +++ b/macusbfb/core/usbhid-rom/usbhid.h @@ -0,0 +1,48 @@ +/**************************************************************************/ +/*! + @file usbhid.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _USBCONFIG_H_ +#define _USBCONFIG_H_ + +#include "projectconfig.h" + +void usbHIDGetInReport (uint8_t src[], uint32_t length); +void usbHIDSetOutReport (uint8_t dst[], uint32_t length); +void usbHIDInit (void); + +#endif diff --git a/macusbfb/core/wdt/wdt.c b/macusbfb/core/wdt/wdt.c new file mode 100644 index 0000000..08e6421 --- /dev/null +++ b/macusbfb/core/wdt/wdt.c @@ -0,0 +1,145 @@ +/**************************************************************************/ +/*! + @file wdt.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Sets up the watchdog timer (WDT). The WDT allows you to monitor + whether the device is still executing properly. If the watchdog + isn't 'fed' within a pre-determined delay, it will raise an interrupt + allowing you to decide if you want to reset the device, etc. + + @code + #include "core/cpu/cpu.h" + #include "core/wdt/wdt.h" + ... + cpuInit(); + wdtInit(); + wdtFeed(); + ... + while (1) + { + // Keep the watchdog happy by regularly feeding it + wdtFeed(); + } + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "wdt.h" + +#define WDT_FEED_VALUE (0x003FFFFF) + +volatile uint32_t wdt_counter; + +/**************************************************************************/ +/*! + IRQ Handler when the watchdog times out. Any actions that you wish + to take when a timeout occurs should be called from here. +*/ +/**************************************************************************/ +void WDT_IRQHandler(void) +{ + /* Clear the time-out interrupt flag */ + WDT_WDMOD &= ~WDT_WDMOD_WDTOF; + wdt_counter++; +} + +/**************************************************************************/ +/*! + Setup the clock for the watchdog timer. The default setting is 250kHz. +*/ +/**************************************************************************/ +static void wdtClockSetup (void) +{ + /* Watchdog Configuration */ + /* Freq. = 0.5MHz, div = 2: WDT_OSC = 250kHz */ + SCB_WDTOSCCTRL = SCB_WDTOSCCTRL_FREQSEL_0_5MHZ | + SCB_WDTOSCCTRL_DIVSEL_DIV2; + + /* Set clock source (use external crystal) */ + SCB_WDTCLKSEL = SCB_WDTCLKSEL_SOURCE_INPUTCLOCK; + SCB_WDTCLKUEN = SCB_WDTCLKUEN_UPDATE; + SCB_WDTCLKUEN = SCB_WDTCLKUEN_DISABLE; + SCB_WDTCLKUEN = SCB_WDTCLKUEN_UPDATE; + + /* Wait until updated */ + while (!(SCB_WDTCLKUEN & SCB_WDTCLKUEN_UPDATE)); + + /* Set divider */ + SCB_WDTCLKDIV = SCB_WDTCLKDIV_DIV1; + + /* Enable WDT clock */ + SCB_PDRUNCFG &= ~(SCB_PDRUNCFG_WDTOSC); +} + +/**************************************************************************/ +/*! + Initialises the watchdog timer and sets up the interrupt. +*/ +/**************************************************************************/ +void wdtInit (void) +{ + /* Setup the WDT clock */ + wdtClockSetup(); + + /* Enable AHB clock to the WDT domain. */ + SCB_SYSAHBCLKCTRL |= SCB_SYSAHBCLKCTRL_WDT; + + wdt_counter = 0; + + /* Enable the WDT interrupt */ + NVIC_EnableIRQ(WDT_IRQn); + + /* Set timeout value (must be at least 0x000000FF) */ + WDT_WDTC = WDT_FEED_VALUE; + + /* Enable the watchdog timer (without system reset) */ + WDT_WDMOD = WDT_WDMOD_WDEN_ENABLED | + WDT_WDMOD_WDRESET_DISABLED; +} + +/**************************************************************************/ +/*! + Feeds the watchdog to keep it from timing out. +*/ +/**************************************************************************/ +void wdtFeed (void) +{ + /* Pet the watchdog */ + WDT_WDFEED = WDT_WDFEED_FEED1; + WDT_WDFEED = WDT_WDFEED_FEED2; +} + diff --git a/macusbfb/core/wdt/wdt.h b/macusbfb/core/wdt/wdt.h new file mode 100644 index 0000000..b52a91f --- /dev/null +++ b/macusbfb/core/wdt/wdt.h @@ -0,0 +1,47 @@ +/**************************************************************************/ +/*! + @file wdt.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _WDT_H_ +#define _WDT_H_ + +#include "projectconfig.h" + +void wdtInit (void); +void wdtFeed (void); + +#endif \ No newline at end of file diff --git a/macusbfb/debug.c b/macusbfb/debug.c new file mode 100644 index 0000000..efc9cd5 --- /dev/null +++ b/macusbfb/debug.c @@ -0,0 +1,60 @@ +/* +Firmware for a Macintosh display adapter connected over USB +Copyright (C) 2010 Jeroen Domburg + +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 . +*/ + +extern unsigned char fontdata_8x8[]; +extern void dramSetByte(int x, int y, char byte); + + +/**************************************************************************/ +/*! + @brief Sends a single byte to a pre-determined peripheral (UART, etc.). + + @param[in] byte + Byte value to send +*/ +/**************************************************************************/ +void __putchar(const char c) { + static int x=0; + static int y=0; + if (c=='\n') { + x=0; + y+=8; + } else { + int i; + for (i=0; i<8; i++) { + dramSetByte(x,y+i,fontdata_8x8[c*8+i]); + } + x+=1; + } +} + +/**************************************************************************/ +/*! + @brief Sends a string to a pre-determined end point (UART, etc.). + + @param[in] str + Text to send +*/ +/**************************************************************************/ +int puts(const char * str) +{ + while(*str) __putchar(*str++); + return 0; +} + + diff --git a/macusbfb/drivers/chibi/chb.c b/macusbfb/drivers/chibi/chb.c new file mode 100644 index 0000000..11860f1 --- /dev/null +++ b/macusbfb/drivers/chibi/chb.c @@ -0,0 +1,202 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +#include +#include + +#include "chb.h" +#include "chb_drvr.h" +#include "chb_buf.h" + +static chb_pcb_t pcb; + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_init() +{ + memset(&pcb, 0, sizeof(chb_pcb_t)); + pcb.src_addr = chb_get_short_addr(); + chb_drvr_init(); +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +chb_pcb_t *chb_get_pcb() +{ + return &pcb; +} + +/**************************************************************************/ +/*! + Requires the dest addr, location to store data, and len of payload. + Returns the length of the hdr. +*/ +/**************************************************************************/ +static U8 chb_gen_hdr(U8 *hdr, U16 addr, U8 len) +{ + U8 *hdr_ptr = hdr; + + // calc frame size and put in 0 position of array + // frame size = hdr sz + payload len + fcs len + *hdr_ptr++ = CHB_HDR_SZ + len + CHB_FCS_LEN; + + // use default fcf byte 0 val but test for ack request. we won't request + // ack if broadcast. all other cases we will. + *hdr_ptr++ = CHB_FCF_BYTE_0 | ((addr != 0xFFFF) << CHB_ACK_REQ_POS); + *hdr_ptr++ = CHB_FCF_BYTE_1; + + *hdr_ptr++ = pcb.seq++; + + // fill out dest pan ID, dest addr, src addr + *(U16 *)hdr_ptr = CHB_PAN_ID; + hdr_ptr += sizeof(U16); + *(U16 *)hdr_ptr = addr; + hdr_ptr += sizeof(U16); + *(U16 *)hdr_ptr = pcb.src_addr; + hdr_ptr += sizeof(U16); + + // return the len of the header + return hdr_ptr - hdr; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +U8 chb_write(U16 addr, U8 *data, U8 len) +{ + U8 status, frm_len, hdr_len, hdr[CHB_HDR_SZ + 1]; + + while (len > 0) + { + // calculate which frame len to use. if greater than max payload, split + // up operation. + frm_len = (len > CHB_MAX_PAYLOAD) ? CHB_MAX_PAYLOAD : len; + + // gen frame header + hdr_len = chb_gen_hdr(hdr, addr, len); + + // send data to chip + status = chb_tx(hdr, data, len); + + if (status != CHB_SUCCESS) + { + switch (status) + { + case RADIO_SUCCESS: + // fall through + case CHB_SUCCESS_DATA_PENDING: + pcb.txd_success++; + break; + + case CHB_NO_ACK: + pcb.txd_noack++; + break; + + case CHB_CHANNEL_ACCESS_FAILURE: + pcb.txd_channel_fail++; + break; + + default: + break; + } + return status; + } + + // adjust len and restart + len = len - frm_len; + } + return CHB_SUCCESS; +} + +/**************************************************************************/ +/*! + Read data from the buffer. Need to pass in a buffer of at leasts max frame + size and two 16-bit containers for the src and dest addresses. + + The read function will automatically populate the addresses and the data with + the frm payload. It will then return the len of the payload. +*/ +/**************************************************************************/ +U8 chb_read(chb_rx_data_t *rx) +{ + U8 i, len, *data_ptr; + + data_ptr = rx->data; + + // first byte is always len. check it to make sure + // we have a valid len byte. + if ((len = chb_buf_read()) > CHB_MAX_FRAME_LENGTH) + { + return 0; + } + *data_ptr++ = len; + + // load the rest of the data into buffer + for (i=0; idata + 6; // location of dest addr + rx->dest_addr = *(U16 *)data_ptr; + data_ptr += sizeof(U16); + rx->src_addr = *(U16 *)data_ptr; + data_ptr += sizeof(U16); + + // move the payload down to the beginning of the data buffer + memmove(rx->data, data_ptr, len - CHB_HDR_SZ); + + // if the data in the rx buf is 0, then clear the rx_flag. otherwise, keep it raised + if (!chb_buf_get_len()) + { + pcb.data_rcv = false; + } + + // finally, return the len of the payload + return len - CHB_HDR_SZ - CHB_FCS_LEN; +} + diff --git a/macusbfb/drivers/chibi/chb.h b/macusbfb/drivers/chibi/chb.h new file mode 100644 index 0000000..1a5dd00 --- /dev/null +++ b/macusbfb/drivers/chibi/chb.h @@ -0,0 +1,99 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +#ifndef CHIBI_H +#define CHIBI_H + +#include "types.h" + +#define CHB_HDR_SZ 9 // FCF + seq + pan_id + dest_addr + src_addr (1 + 2 + 1 + 2 + 2 + 2) +#define CHB_FCS_LEN 2 +#define CHB_MAX_PAYLOAD 100 + + +// frame_type = data +// security enabled = false +// frame pending = false +// ack request = false +// pan ID compression = true +#define CHB_FCF_BYTE_0 0x41 + +// dest addr = 16-bit +// frame version = 802.15.4 (not 2003) +// src addr = 16-bit +#define CHB_FCF_BYTE_1 0x98 + +#define CHB_ACK_REQ_POS 5 + +enum +{ + CHB_SUCCESS = 0, + CHB_SUCCESS_DATA_PENDING = 1, + CHB_CHANNEL_ACCESS_FAILURE = 3, + CHB_NO_ACK = 5, + CHB_INVALID = 7 +}; + +// Chibi Protocol control block +typedef struct +{ + U16 src_addr; + U8 seq; + volatile bool data_rcv; + volatile bool tx_end; + + // stats + U16 rcvd_xfers; + U16 txd_success; + U16 txd_noack; + U16 txd_channel_fail; + U16 underrun; + U8 battlow; + U8 ed; + U8 crc; +} chb_pcb_t; + +typedef struct +{ + U8 len; + U16 src_addr; + U16 dest_addr; + U8 data[CHB_MAX_PAYLOAD]; +} chb_rx_data_t; + +void chb_init(); +chb_pcb_t *chb_get_pcb(); +U8 chb_write(U16 addr, U8 *data, U8 len); +U8 chb_read(chb_rx_data_t *rx); + +#endif diff --git a/macusbfb/drivers/chibi/chb_buf.c b/macusbfb/drivers/chibi/chb_buf.c new file mode 100644 index 0000000..5624e58 --- /dev/null +++ b/macusbfb/drivers/chibi/chb_buf.c @@ -0,0 +1,87 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +#include +#include "chb_buf.h" + +static U8 chb_buf[CHB_BUF_SZ]; +static U8 rd_ptr, wr_ptr, len; + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_buf_init() +{ + rd_ptr = 0; + wr_ptr = 0; + len = 0; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_buf_write(U8 data) +{ + chb_buf[wr_ptr] = data; + wr_ptr = (wr_ptr + 1) % CHB_BUF_SZ; + len++; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +U8 chb_buf_read() +{ + U8 data; + + data = chb_buf[rd_ptr]; + rd_ptr = (rd_ptr + 1) % CHB_BUF_SZ; + len--; + return data; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +U8 chb_buf_get_len() +{ + return len; +} diff --git a/macusbfb/drivers/chibi/chb_buf.h b/macusbfb/drivers/chibi/chb_buf.h new file mode 100644 index 0000000..6b69d1e --- /dev/null +++ b/macusbfb/drivers/chibi/chb_buf.h @@ -0,0 +1,46 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +#ifndef CHB_BUF_H +#define CHB_BUF_H + +#include "types.h" + +#define CHB_BUF_SZ 128 + +void chb_buf_init(); +void chb_buf_write(U8 data); +U8 chb_buf_read(); +U8 chb_buf_get_len(); + +#endif diff --git a/macusbfb/drivers/chibi/chb_drvr.c b/macusbfb/drivers/chibi/chb_drvr.c new file mode 100644 index 0000000..a1d29c9 --- /dev/null +++ b/macusbfb/drivers/chibi/chb_drvr.c @@ -0,0 +1,890 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +#include +#include "chb.h" +#include "chb_drvr.h" +#include "chb_buf.h" +#include "chb_spi.h" +#include "chb_eeprom.h" + +#include "core/systick/systick.h" + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +static U8 chb_get_state() +{ + return chb_reg_read(TRX_STATUS) & 0x1f; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +static U8 chb_get_status() +{ + return chb_reg_read(TRX_STATE) >> CHB_TRAC_STATUS_POS; +} + +/**************************************************************************/ +/*! + Cause a blocking delay for x microseconds +*/ +/**************************************************************************/ +static void chb_delay_us(U16 usec) +{ + U8 ticks = CFG_CPU_CCLK / 1000000; + do + { + do + { + __asm volatile("nop"); + } while (--ticks); + } while (--usec); +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_reset() +{ + CHB_RST_DISABLE(); + CHB_SLPTR_DISABLE(); + + // wait a bit while transceiver wakes up + chb_delay_us(TIME_P_ON_TO_CLKM_AVAIL); + + // reset the device + CHB_RST_ENABLE(); + chb_delay_us(TIME_RST_PULSE_WIDTH); + CHB_RST_DISABLE(); + + // check that we have the part number that we're expecting + while (1) + { + // if you're stuck in this loop, that means that you're not reading + // the version and part number register correctly. possible that version number + // changes. if so, update version num in header file + if ((chb_reg_read(VERSION_NUM) == CHB_AT86RF212_VER_NUM) && (chb_reg_read(PART_NUM) == CHB_AT86RF212_PART_NUM)) + { + break; + } + } +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +U8 chb_reg_read(U8 addr) +{ + U8 val = 0; + + /* Add the register read command to the register address. */ + addr |= 0x80; + + CHB_ENTER_CRIT(); + CHB_SPI_ENABLE(); + + /*Send Register address and read register content.*/ + val = chb_xfer_byte(addr); + val = chb_xfer_byte(val); + + CHB_SPI_DISABLE(); + CHB_LEAVE_CRIT(); + + return val; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +U16 chb_reg_read16(U8 addr) +{ + U8 i; + U16 val = 0; + + for (i=0; i<2; i++) + { + addr |= chb_reg_read(addr + i) << (8 * i); + } + return val; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_reg_write(U8 addr, U8 val) +{ + U8 dummy; + + /* Add the Register Write command to the address. */ + addr |= 0xC0; + + CHB_ENTER_CRIT(); + CHB_SPI_ENABLE(); + + /*Send Register address and write register content.*/ + dummy = chb_xfer_byte(addr); + dummy = chb_xfer_byte(val); + + CHB_SPI_DISABLE(); + CHB_LEAVE_CRIT(); +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_reg_write16(U8 addr, U16 val) +{ + U8 i; + + for (i=0; i<2; i++) + { + chb_reg_write(addr + i, val >> (8 * i)); + } +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_reg_write64(U8 addr, U8 *val) +{ + U8 i; + + for (i=0; i<8; i++) + { + chb_reg_write(addr + i, *(val + i)); + } +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_reg_read_mod_write(U8 addr, U8 val, U8 mask) +{ + U8 tmp; + + tmp = chb_reg_read(addr); + val &= mask; // mask off stray bits from val + tmp &= ~mask; // mask off bits in reg val + tmp |= val; // copy val into reg val + chb_reg_write(addr, tmp); // write back to reg +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_frame_write(U8 *hdr, U8 hdr_len, U8 *data, U8 data_len) +{ + U8 i, dummy; + + // dont allow transmission longer than max frame size + if ((hdr_len + data_len) > 127) + { + return; + } + + // initiate spi transaction + CHB_ENTER_CRIT(); + CHB_SPI_ENABLE(); + + // send fifo write command + dummy = chb_xfer_byte(CHB_SPI_CMD_FW); + + // write hdr contents to fifo + for (i=0; i= CHB_MIN_FRAME_LENGTH) && (len <= CHB_MAX_FRAME_LENGTH)) + { + chb_buf_write(len); + + for (i=0; i 3) + { + channel = 0; + } + + channel = (channel << 1) + 11; + + chb_reg_read_mod_write(CC_CTRL_1, 0x4, 0x7); // set 769 MHz base frequency for China + chb_reg_write(CC_CTRL_0, channel); // set the center frequency for the channel + +#else + //if (channel == 0) + //{ + // // Channel 0 is for European use only. make sure we are using channel page 2, + // // channel 0 settings for 100 kbps + // if ((chb_reg_read(TRX_CTRL_2) & 0x3f) != 0x08) + // { + // chb_reg_read_mod_write(TRX_CTRL_2, 0x08, 0x3f); + // } + //} + //else if (channel > 10) + //{ + // // if the channel is out of bounds for page 2, then default to channel 1 and + // // assume we're on the US frequency of 915 MHz + // channel = 1; + // if ((chb_reg_read(TRX_CTRL_2) & 0x3f) != 0x0c) + // { + // chb_reg_read_mod_write(TRX_CTRL_2, 0x0c, 0x3f); + // } + //} + //else + //{ + // // Channels 1-10 are for US frequencies of 915 MHz + // if ((chb_reg_read(TRX_CTRL_2) & 0x3f) != 0x0c) + // { + // chb_reg_read_mod_write(TRX_CTRL_2, 0x0c, 0x3f); + // } + //} + + chb_reg_read_mod_write(PHY_CC_CCA, channel, 0x1f); +#endif + + // add a delay to allow the PLL to lock if in active mode. + state = chb_get_state(); + if ((state == RX_ON) || (state == PLL_ON)) + { + chb_delay_us(TIME_PLL_LOCK_TIME); + } + + return ((chb_reg_read(PHY_CC_CCA) & 0x1f) == channel) ? RADIO_SUCCESS : RADIO_TIMED_OUT; +} + +/**************************************************************************/ +/*! + Set the power level +*/ +/**************************************************************************/ +void chb_set_pwr(U8 val) +{ + chb_reg_write(PHY_TX_PWR, val); +} + +/**************************************************************************/ +/*! + Set the TX/RX state machine state. Some manual manipulation is required + for certain operations. Check the datasheet for more details on the state + machine and manipulations. +*/ +/**************************************************************************/ +U8 chb_set_state(U8 state) +{ + U8 curr_state, delay; + + // if we're sleeping then don't allow transition + if (gpioGetValue(CHB_SLPTRPORT, CHB_SLPTRPIN)) + { + return RADIO_WRONG_STATE; + } + + // if we're in a transition state, wait for the state to become stable + curr_state = chb_get_state(); + if ((curr_state == BUSY_TX_ARET) || (curr_state == BUSY_RX_AACK) || (curr_state == BUSY_RX) || (curr_state == BUSY_TX)) + { + while (chb_get_state() == curr_state); + } + + // At this point it is clear that the requested new_state is: + // TRX_OFF, RX_ON, PLL_ON, RX_AACK_ON or TX_ARET_ON. + // we need to handle some special cases before we transition to the new state + switch (state) + { + case TRX_OFF: + /* Go to TRX_OFF from any state. */ + CHB_SLPTR_DISABLE(); + chb_reg_read_mod_write(TRX_STATE, CMD_FORCE_TRX_OFF, 0x1f); + chb_delay_us(TIME_ALL_STATES_TRX_OFF); + break; + + case TX_ARET_ON: + if (curr_state == RX_AACK_ON) + { + /* First do intermediate state transition to PLL_ON, then to TX_ARET_ON. */ + chb_reg_read_mod_write(TRX_STATE, CMD_PLL_ON, 0x1f); + chb_delay_us(TIME_RX_ON_PLL_ON); + } + break; + + case RX_AACK_ON: + if (curr_state == TX_ARET_ON) + { + /* First do intermediate state transition to RX_ON, then to RX_AACK_ON. */ + chb_reg_read_mod_write(TRX_STATE, CMD_RX_ON, 0x1f); + chb_delay_us(TIME_PLL_ON_RX_ON); + } + break; + } + + /* Now we're okay to transition to any new state. */ + chb_reg_read_mod_write(TRX_STATE, state, 0x1f); + + /* When the PLL is active most states can be reached in 1us. However, from */ + /* TRX_OFF the PLL needs time to activate. */ + delay = (curr_state == TRX_OFF) ? TIME_TRX_OFF_PLL_ON : TIME_RX_ON_PLL_ON; + chb_delay_us(delay); + + if (chb_get_state() == state) + { + return RADIO_SUCCESS; + } + return RADIO_TIMED_OUT; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_set_ieee_addr(U8 *addr) +{ + chb_eeprom_write(CHB_EEPROM_IEEE_ADDR, addr, 8); + chb_reg_write64(IEEE_ADDR_0, addr); +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_get_ieee_addr(U8 *addr) +{ + chb_eeprom_read(CHB_EEPROM_IEEE_ADDR, addr, 8); +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_set_short_addr(U16 addr) +{ + U8 *addr_ptr = (U8 *)&addr; + chb_pcb_t *pcb = chb_get_pcb(); + + chb_eeprom_write(CHB_EEPROM_SHORT_ADDR, addr_ptr, 2); + chb_reg_write16(SHORT_ADDR_0, addr); + pcb->src_addr = addr; +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +U16 chb_get_short_addr() +{ + int16_t addr; + + chb_eeprom_read(CHB_EEPROM_SHORT_ADDR, (uint8_t*)&addr, 2); + return addr; +} +/**************************************************************************/ +/*! + Set the high gain mode pin for the CC1190 +*/ +/**************************************************************************/ +#if (CHB_CC1190_PRESENT) +void chb_set_hgm(U8 enb) +{ + if (enb) + { + gpioSetValue(CHB_CC1190_HGM_PORT, CHB_CC1190_HGM_PIN, 1); + } + else + { + gpioSetValue(CHB_CC1190_HGM_PORT, CHB_CC1190_HGM_PIN, 0); + } +} +#endif + +/**************************************************************************/ +/*! + Load the data into the fifo, initiate a transmission attempt, + and return the status of the transmission attempt. +*/ +/**************************************************************************/ +U8 chb_tx(U8 *hdr, U8 *data, U8 len) +{ + U8 state = chb_get_state(); + chb_pcb_t *pcb = chb_get_pcb(); + + if ((state == BUSY_TX) || (state == BUSY_TX_ARET)) + { + return RADIO_WRONG_STATE; + } + + // TODO: check why we need to transition to the off state before we go to tx_aret_on + chb_set_state(TRX_OFF); + chb_set_state(TX_ARET_ON); + + // TODO: try and start the frame transmission by writing TX_START command instead of toggling + // sleep pin...i just feel like it's kind of weird... + + // write frame to buffer. first write header into buffer (add 1 for len byte), then data. + chb_frame_write(hdr, CHB_HDR_SZ + 1, data, len); + + // TEST - check data in buffer + //{ + // U8 i, len, tmp[30]; + // + // len = 1 + CHB_HDR_SZ + len; + // chb_sram_read(0, len, tmp); + // for (i=0; itx_end); + pcb->tx_end = false; + + // check the status of the transmission + return chb_get_status(); +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +static void chb_radio_init() +{ + U8 ieee_addr[8]; + + // reset chip + chb_reset(); + + // disable intps while we config the radio + chb_reg_write(IRQ_MASK, 0); + + // force transceiver off while we configure the intps + chb_reg_read_mod_write(TRX_STATE, CMD_FORCE_TRX_OFF, 0x1F); + + // make sure the transceiver is in the off state before proceeding + while ((chb_reg_read(TRX_STATUS) & 0x1f) != TRX_OFF); + + // set radio cfg parameters + // **note** uncomment if these will be set to something other than default + //chb_reg_read_mod_write(XAH_CTRL_0, CHB_MAX_FRAME_RETRIES << CHB_MAX_FRAME_RETRIES_POS, 0xF << CHB_MAX_FRAME_RETRIES_POS); + //chb_reg_read_mod_write(XAH_CTRL_0, CHB_MAX_CSMA_RETRIES << CHB_MAX_CSMA_RETIRES_POS, 0x7 << CHB_MAX_CSMA_RETIRES_POS); + //chb_reg_read_mod_write(CSMA_SEED_1, CHB_CSMA_SEED1 << CHB_CSMA_SEED1_POS, 0x7 << CHB_CSMA_SEED1_POS); + //chb_ret_write(CSMA_SEED0, CHB_CSMA_SEED0); + //chb_reg_read_mod_write(PHY_CC_CCA, CHB_CCA_MODE << CHB_CCA_MODE_POS,0x3 << CHB_CCA_MODE_POS); + //chb_reg_write(CCA_THRES, CHB_CCA_ED_THRES); + + // set frame version that we'll accept + chb_reg_read_mod_write(CSMA_SEED_1, CHB_FRM_VER << CHB_FVN_POS, 3 << CHB_FVN_POS); + + // set interrupt mask + // re-enable intps while we config the radio + chb_reg_write(IRQ_MASK, (1<ed = chb_reg_read(PHY_ED_LEVEL); + + // get the crc + pcb->crc = (chb_reg_read(PHY_RSSI) & (1<<7)) ? 1 : 0; + + // if the crc is not valid, then do not read the frame and set the rx flag + if (pcb->crc) + { + // get the data + chb_frame_read(); + pcb->rcvd_xfers++; + pcb->data_rcv = true; + } + } + else + { + pcb->tx_end = true; + } + intp_src &= ~CHB_IRQ_TRX_END_MASK; + while (chb_set_state(RX_AACK_ON) != RADIO_SUCCESS); + } + else if (intp_src & CHB_IRQ_TRX_UR_MASK) + { + intp_src &= ~CHB_IRQ_TRX_UR_MASK; + pcb->underrun++; + } + else if (intp_src & CHB_IRQ_PLL_UNLOCK_MASK) + { + intp_src &= ~CHB_IRQ_PLL_UNLOCK_MASK; + } + else if (intp_src & CHB_IRQ_PLL_LOCK_MASK) + { + intp_src &= ~CHB_IRQ_PLL_LOCK_MASK; + } + else if (intp_src & CHB_IRQ_BAT_LOW_MASK) + { + intp_src &= ~CHB_IRQ_BAT_LOW_MASK; + pcb->battlow++; + } + else + { + } + } + CHB_LEAVE_CRIT(); +} diff --git a/macusbfb/drivers/chibi/chb_drvr.h b/macusbfb/drivers/chibi/chb_drvr.h new file mode 100644 index 0000000..d2b502a --- /dev/null +++ b/macusbfb/drivers/chibi/chb_drvr.h @@ -0,0 +1,368 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +#ifndef CHIBI_DRVR_H +#define CHIBI_DRVR_H + +#include "types.h" +#include "projectconfig.h" +#include "core/gpio/gpio.h" + +#define CHB_CC1190_PRESENT 0 /// Set to 1 if CC1190 is being used +#define CHB_CHINA 0 +#define CHB_EEPROM_IEEE_ADDR CFG_CHIBI_EEPROM_IEEEADDR +#define CHB_EEPROM_SHORT_ADDR CFG_CHIBI_EEPROM_SHORTADDR +#define CHB_AT86RF212_VER_NUM 0x01 +#define CHB_AT86RF212_PART_NUM 0x07 +// #define CHB_BPSK 0 // set to 1 if want to use BPSK rather than OQPSK + +#define CHB_SPI_CMD_RW 0xC0 /**< Register Write (short mode). */ +#define CHB_SPI_CMD_RR 0x80 /**< Register Read (short mode). */ +#define CHB_SPI_CMD_FW 0x60 /**< Frame Transmit Mode (long mode). */ +#define CHB_SPI_CMD_FR 0x20 /**< Frame Receive Mode (long mode). */ +#define CHB_SPI_CMD_SW 0x40 /**< SRAM Write. */ +#define CHB_SPI_CMD_SR 0x00 /**< SRAM Read. */ +#define CHB_SPI_CMD_RADDRM 0x7F /**< Register Address Mask. */ + +#define CHB_IRQ_BAT_LOW_MASK 0x80 /**< Mask for the BAT_LOW interrupt. */ +#define CHB_IRQ_TRX_UR_MASK 0x40 /**< Mask for the TRX_UR interrupt. */ +#define CHB_IRQ_TRX_END_MASK 0x08 /**< Mask for the TRX_END interrupt. */ +#define CHB_IRQ_RX_START_MASK 0x04 /**< Mask for the RX_START interrupt. */ +#define CHB_IRQ_PLL_UNLOCK_MASK 0x02 /**< Mask for the PLL_UNLOCK interrupt. */ +#define CHB_IRQ_PLL_LOCK_MASK 0x01 /**< Mask for the PLL_LOCK interrupt. */ + +#define CHB_EINTPORT 1 +#define CHB_EINTPIN 8 +#define CHB_EINTPIN_IOCONREG IOCON_PIO1_8 +#define CHB_RSTPORT 1 +#define CHB_RSTPIN 9 +#define CHB_RSTPIN_IOCONREG IOCON_PIO1_9 +#define CHB_SLPTRPORT 1 +#define CHB_SLPTRPIN 10 +#define CHB_SLPTRPIN_IOCONREG IOCON_PIO1_10 + +// if CC1190 present, set up the ports and pins for high gain mode control +#if (CHB_CC1190_PRESENT) + #define CHB_CC1190_HGM_PORT 1 + #define CHB_CC1190_HGM_PIN 11 + #define CHB_CC1190_HGM_IOCONREG IOCON_PIO1_11 +#endif + +//#define CHB_DDR_SLPTR DDRF +//#define CHB_DDR_RST DDRF +//#define CHB_RADIO_IRQ INT6_vect +//#define CHB_RADIO_IRQ_PIN INT6 + +#define CHB_ENTER_CRIT() __disable_irq() +#define CHB_LEAVE_CRIT() __enable_irq() +#define CHB_RST_ENABLE() do {gpioSetValue(CHB_RSTPORT, CHB_RSTPIN, 0); systickDelay(1 / CFG_SYSTICK_DELAY_IN_MS);} while (0) +#define CHB_RST_DISABLE() do {gpioSetValue(CHB_RSTPORT, CHB_RSTPIN, 1); systickDelay(1 / CFG_SYSTICK_DELAY_IN_MS);} while (0) +#define CHB_SLPTR_ENABLE() do {gpioSetValue(CHB_SLPTRPORT, CHB_SLPTRPIN, 1); systickDelay(1 / CFG_SYSTICK_DELAY_IN_MS);} while (0) +#define CHB_SLPTR_DISABLE() do {gpioSetValue(CHB_SLPTRPORT, CHB_SLPTRPIN, 0); systickDelay(1 / CFG_SYSTICK_DELAY_IN_MS);} while (0) + +// CCA constants +enum +{ + CCA_ED = 1, /**< Use energy detection above threshold mode. */ + CCA_CARRIER_SENSE = 2, /**< Use carrier sense mode. */ + CCA_CARRIER_SENSE_WITH_ED = 3 /**< Use a combination of both energy detection and carrier sense. */ +}; + +// configuration parameters +enum +{ + CHB_CHANNEL = 1, + CHB_PAN_ID = 0x1234, + CHB_TX_PWR = 0x0, + CHB_SHORT_ADDR = 0x0, + CHB_IEEE_ADDR = 0x0, + CHB_MAX_FRAME_RETRIES = 3, + CHB_MAX_CSMA_RETRIES = 4, + CHB_CCA_MODE = CCA_ED, + CHB_MIN_BE = 3, + CHB_MAX_BE = 5, + CHB_CCA_ED_THRES = 0x7, + CHB_CSMA_SEED0 = 0, + CHB_CSMA_SEED1 = 0, + CHB_FRM_VER = 1 // accept 802.15.4 ver 0 or 1 frames +}; + +// register addresses +enum +{ + TRX_STATUS = 0x01, + TRX_STATE = 0x02, + TRX_CTRL_0 = 0x03, + TRX_CTRL_1 = 0x04, + PHY_TX_PWR = 0x05, + PHY_RSSI = 0x06, + PHY_ED_LEVEL = 0x07, + PHY_CC_CCA = 0x08, + CCA_THRES = 0x09, + RX_CTRL = 0x0a, + SFD_VALUE = 0x0b, + TRX_CTRL_2 = 0x0c, + ANT_DIV = 0x0d, + IRQ_MASK = 0x0e, + IRQ_STATUS = 0x0f, + VREG_CTRL = 0x10, + BATMON = 0x11, + XOSC_CTRL = 0x12, + CC_CTRL_0 = 0x13, + CC_CTRL_1 = 0x14, + RX_SYN = 0x15, + RF_CTRL_0 = 0x16, + XAH_CTRL_1 = 0x17, + FTN_CTRL = 0x18, + RF_CTRL_1 = 0x19, + PLL_CF = 0x1a, + PLL_DCU = 0x1b, + PART_NUM = 0x1c, + VERSION_NUM = 0x1d, + MAN_ID_0 = 0x1e, + MAN_ID_1 = 0x1f, + SHORT_ADDR_0 = 0x20, + SHORT_ADDR_1 = 0x21, + PAN_ID_0 = 0x22, + PAN_ID_1 = 0x23, + IEEE_ADDR_0 = 0x24, + IEEE_ADDR_1 = 0x25, + IEEE_ADDR_2 = 0x26, + IEEE_ADDR_3 = 0x27, + IEEE_ADDR_4 = 0x28, + IEEE_ADDR_5 = 0x29, + IEEE_ADDR_6 = 0x2a, + IEEE_ADDR_7 = 0x2b, + XAH_CTRL_0 = 0x2c, + CSMA_SEED_0 = 0x2d, + CSMA_SEED_1 = 0x2e, + CSMA_BE = 0x2f +}; + +// random defines +enum +{ + CHB_MAX_FRAME_RETRIES_POS = 4, + CHB_MAX_CSMA_RETIRES_POS = 1, + CHB_CSMA_SEED1_POS = 0, + CHB_CCA_MODE_POS = 5, + CHB_AUTO_CRC_POS = 5, + CHB_TRX_END_POS = 3, + CHB_TRAC_STATUS_POS = 5, + CHB_FVN_POS = 6, + CHB_OQPSK_TX_OFFSET = 2, + CHB_BPSK_TX_OFFSET = 3, + CHB_MIN_FRAME_LENGTH = 3, + CHB_MAX_FRAME_LENGTH = 0x7f, + CHB_PA_EXT_EN_POS = 7 +}; + +// transceiver timing +enum{ + TIME_RST_PULSE_WIDTH = 1, + TIME_P_ON_TO_CLKM_AVAIL = 380, + TIME_SLEEP_TO_TRX_OFF = 240, + TIME_TRX_OFF_TO_SLEEP = 35, + TIME_PLL_ON_TRX_OFF = 1, + TIME_TRX_OFF_RX_ON = 110, + TIME_RX_ON_TRX_OFF = 1, + TIME_PLL_ON_RX_ON = 1, + TIME_RX_ON_PLL_ON = 1, + TIME_PLL_LOCK_TIME = 110, + TIME_BUSY_TX_PLL_ON = 32, + TIME_ALL_STATES_TRX_OFF = 1, + TIME_RESET_TRX_OFF = 26, + TIME_TRX_IRQ_DELAY = 9, + TIME_TRX_OFF_PLL_ON = 110, + TIME_IRQ_PROCESSING_DLY = 32 +}; + +// trac status +enum{ + TRAC_SUCCESS = 0, + TRAC_SUCCESS_DATA_PENDING = 1, + TRAC_WAIT_FOR_ACK = 2, + TRAC_CHANNEL_ACCESS_FAIL = 3, + TRAC_NO_ACK = 5, + TRAC_INVALID = 7 +}; + +// radio statuses +enum{ + RADIO_SUCCESS = 0x40, /**< The requested service was performed successfully. */ + RADIO_UNSUPPORTED_DEVICE, /**< The connected device is not an Atmel AT86RF212. */ + RADIO_INVALID_ARGUMENT, /**< One or more of the supplied function arguments are invalid. */ + RADIO_TIMED_OUT, /**< The requested service timed out. */ + RADIO_WRONG_STATE, /**< The end-user tried to do an invalid state transition. */ + RADIO_BUSY_STATE, /**< The radio transceiver is busy receiving or transmitting. */ + RADIO_STATE_TRANSITION_FAILED, /**< The requested state transition could not be completed. */ + RADIO_CCA_IDLE, /**< Channel is clear, available to transmit a new frame. */ + RADIO_CCA_BUSY, /**< Channel busy. */ + RADIO_TRX_BUSY, /**< Transceiver is busy receiving or transmitting data. */ + RADIO_BAT_LOW, /**< Measured battery voltage is lower than voltage threshold. */ + RADIO_BAT_OK, /**< Measured battery voltage is above the voltage threshold. */ + RADIO_CRC_FAILED, /**< The CRC failed for the actual frame. */ + RADIO_CHANNEL_ACCESS_FAILURE, /**< The channel access failed during the auto mode. */ + RADIO_NO_ACK, /**< No acknowledge frame was received. */ +}; + +// transceiver commands +enum +{ + CMD_NOP = 0, + CMD_TX_START = 2, + CMD_FORCE_TRX_OFF = 3, + CMD_FORCE_PLL_ON = 4, + CMD_RX_ON = 6, + CMD_TRX_OFF = 8, + CMD_PLL_ON = 9, + CMD_RX_AACK_ON = 22, + CMD_TX_ARET_ON = 25 +}; + +// transceiver states +enum +{ + P_ON = 0, + BUSY_RX = 1, + BUSY_TX = 2, + RX_ON = 6, + TRX_OFF = 8, + PLL_ON = 9, + SLEEP = 15, + BUSY_RX_AACK = 17, + BUSY_TX_ARET = 18, + RX_AACK_ON = 22, + TX_ARET_ON = 25, + RX_ON_NOCLK = 28, + RX_AACK_ON_NOCLK = 29, + BUSY_RX_AACK_NOCLK = 30, + TRANS_IN_PROG = 31 +}; + +// transceiver interrupt register +enum +{ + IRQ_PLL_LOCK = 0, + IRQ_PLL_UNLOCK = 1, + IRQ_RX_START = 2, + IRQ_TRX_END = 3, + IRQ_CCA_ED_READY = 4, + IRQ_AMI = 5, + IRQ_TRX_UR = 6, + IRQ_BAT_LOW = 7 +}; + +// transceiver modes +enum +{ + OQPSK_868MHZ = 0, + OQPSK_915MHZ = 1, + OQPSK_780MHZ = 2, + BPSK40_915MHZ = 3, + BPSK20_868MHZ = 4 +}; + +// See Table 7-15 for details +enum +{ + CHB_PWR_EU1_2DBM = 0x63, // EU (868MHz) Linearized PA mode + CHB_PWR_EU1_1DBM = 0x64, // Note: BPSK 20kbit/s only! + CHB_PWR_EU1_0DBM = 0x65, + CHB_PWR_EU2_5DBM = 0xE7, // EU (868MHz) Boost mode (but > supply current) + CHB_PWR_EU2_4DBM = 0xE8, // 4-5dBM BPSK 20 kbit/s only! + CHB_PWR_EU2_3DBM = 0xE9, // 0-3dBM O-QPSK 100/200/400 kbit/s or BPSK + CHB_PWR_EU2_2DBM = 0xEA, + CHB_PWR_EU2_1DBM = 0xCB, + CHB_PWR_EU2_0DBM = 0xAB, + CHB_PWR_NA_10DBM = 0xC0, // North America (915MHz) + CHB_PWR_NA_9DBM = 0xA1, + CHB_PWR_NA_8DBM = 0x81, + CHB_PWR_NA_7DBM = 0x82, + CHB_PWR_NA_6DBM = 0x83, + CHB_PWR_NA_5DBM = 0x60, + CHB_PWR_NA_4DBM = 0x61, + CHB_PWR_NA_3DBM = 0x41, + CHB_PWR_NA_2DBM = 0x42, + CHB_PWR_NA_1DBM = 0x22, + CHB_PWR_NA_0DBM = 0x23, + CHB_PWR_CHINA_5DBM = 0xE7, // China (780MHz) + CHB_PWR_CHINA_4DBM = 0xE8, + CHB_PWR_CHINA_3DBM = 0xE9, + CHB_PWR_CHINA_2DBM = 0xEA, + CHB_PWR_CHINA_1DBM = 0xCA, + CHB_PWR_CHINA_0DBM = 0xAA +}; + +// init +void chb_drvr_init(); + +// data access +U8 chb_reg_read(U8 addr); +U16 chb_reg_read16(U8 addr); +void chb_reg_write(U8 addr, U8 val); +void chb_reg_write16(U8 addr, U16 val); +void chb_reg_write64(U8 addr, U8 *val); +void chb_reg_read_mod_write(U8 addr, U8 val, U8 mask); +void chb_frame_write(U8 *hdr, U8 hdr_len, U8 *data, U8 data_len); + +// general configuration +void chb_set_mode(U8 mode); +U8 chb_set_channel(U8 channel); +void chb_set_pwr(U8 val); +void chb_set_ieee_addr(U8 *addr); +void chb_get_ieee_addr(U8 *addr); +void chb_set_short_addr(U16 addr); +U16 chb_get_short_addr(); +U8 chb_set_state(U8 state); + +// Power management +U8 chb_radio_sleep(void); + +// data transmit +U8 chb_tx(U8 *hdr, U8 *data, U8 len); + +#if (CHB_CC1190_PRESENT) + void chb_set_hgm(U8 enb); +#endif + +#ifdef CHB_DEBUG +// sram access +void chb_sram_read(U8 addr, U8 len, U8 *data); +void chb_sram_write(U8 addr, U8 len, U8 *data); +#endif + +void chb_ISR_Handler (void); + +#endif + diff --git a/macusbfb/drivers/chibi/chb_eeprom.c b/macusbfb/drivers/chibi/chb_eeprom.c new file mode 100644 index 0000000..4d8dd5e --- /dev/null +++ b/macusbfb/drivers/chibi/chb_eeprom.c @@ -0,0 +1,85 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +/*! + \file + \ingroup + + +*/ +/**************************************************************************/ +#include "chb_eeprom.h" +#include "drivers/eeprom/mcp24aa/mcp24aa.h" + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_eeprom_write(uint16_t addr, uint8_t *buf, uint16_t size) +{ + // Instantiate error message placeholder + mcp24aaError_e error = MCP24AA_ERROR_OK; + + // Write the address one byte at a time + uint16_t a = 0; + while (a < size) + { + error = mcp24aaWriteByte(addr + a, buf[a]); + if (error) + { + // ToDo: Handle any errors + } + a++; + } +} + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_eeprom_read(uint16_t addr, uint8_t *buf, uint16_t size) +{ + // Instantiate error message placeholder + mcp24aaError_e error = MCP24AA_ERROR_OK; + + // Read the contents of address 0x0125 + error = mcp24aaReadBuffer(addr, buf, size); + + if (error) + { + // ToDo: Handle any errors + } +} + diff --git a/macusbfb/drivers/chibi/chb_eeprom.h b/macusbfb/drivers/chibi/chb_eeprom.h new file mode 100644 index 0000000..3c3df71 --- /dev/null +++ b/macusbfb/drivers/chibi/chb_eeprom.h @@ -0,0 +1,50 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +/*! + \file + \ingroup + + +*/ +/**************************************************************************/ +#ifndef CHB_EEPROM_H +#define CHB_EEPROM_H + +#include "projectconfig.h" +#include "types.h" + +void chb_eeprom_write(U16 addr, U8 *buf, U16 size); +void chb_eeprom_read(U16 addr, U8 *buf, U16 size); + +#endif diff --git a/macusbfb/drivers/chibi/chb_spi.c b/macusbfb/drivers/chibi/chb_spi.c new file mode 100644 index 0000000..e552184 --- /dev/null +++ b/macusbfb/drivers/chibi/chb_spi.c @@ -0,0 +1,77 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +/*! + \file + \ingroup + + +*/ +/**************************************************************************/ +#include "chb.h" +#include "chb_spi.h" +#include "core/ssp/ssp.h" + +/**************************************************************************/ +/*! + +*/ +/**************************************************************************/ +void chb_spi_init() +{ + // initialise spi, high between frames and transition on trailing edge + sspInit(0, sspClockPolarity_High, sspClockPhase_FallingEdge); + + // set the slave select to idle + CHB_SPI_DISABLE(); +} + +/**************************************************************************/ +/*! + This function both reads and writes data. For write operations, include data + to be written as argument. For read ops, use dummy data as arg. Returned + data is read byte val. +*/ +/**************************************************************************/ +U8 chb_xfer_byte(U8 data) +{ + /* Move on only if NOT busy and TX FIFO not full */ + while ((SSP_SSP0SR & (SSP_SSP0SR_TNF_MASK | SSP_SSP0SR_BSY_MASK)) != SSP_SSP0SR_TNF_NOTFULL); + SSP_SSP0DR = data; + + /* Wait until the busy bit is cleared and receive buffer is not empty */ + while ((SSP_SSP0SR & (SSP_SSP0SR_BSY_MASK | SSP_SSP0SR_RNE_MASK)) != SSP_SSP0SR_RNE_NOTEMPTY); + + // Read the queue + return SSP_SSP0DR; +} diff --git a/macusbfb/drivers/chibi/chb_spi.h b/macusbfb/drivers/chibi/chb_spi.h new file mode 100644 index 0000000..220feb7 --- /dev/null +++ b/macusbfb/drivers/chibi/chb_spi.h @@ -0,0 +1,62 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + +*******************************************************************/ +/*! + \file + \ingroup + + +*/ +/**************************************************************************/ + +#ifndef CHB_SPI_H +#define CHB_SPI_H + +#include "projectconfig.h" +#include "core/gpio/gpio.h" + +#define CHB_SSPORT (0) // P0.2 = SSEL +#define CHB_SSPIN (2) + +#define CHB_SPI_ENABLE() do {gpioSetValue(CHB_SSPORT, CHB_SSPIN, 0);} while (0) // Drive SSEL low +#define CHB_SPI_DISABLE() do {gpioSetValue(CHB_SSPORT, CHB_SSPIN, 1);} while (0) // Drive SSEL high + +#define CHB_SPIPORT 0 +#define CHB_SCK 1 // PB.1 - Output: SPI Serial Clock (SCLK) +#define CHB_MOSI 2 // PB.2 - Output: SPI Master out - slave in (MOSI) +#define CHB_MISO 3 // PB.3 - Input: SPI Master in - slave out (MISO) + +void chb_spi_init(); +U8 chb_xfer_byte(U8 data); + +#endif diff --git a/macusbfb/drivers/chibi/types.h b/macusbfb/drivers/chibi/types.h new file mode 100644 index 0000000..c551bbc --- /dev/null +++ b/macusbfb/drivers/chibi/types.h @@ -0,0 +1,54 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. +*******************************************************************/ +/*! + \file types.h + \ingroup usb +*/ +/*******************************************************************/ +#ifndef TYPES_H +#define TYPES_H + +#include +#include + +// Standard data types +typedef uint8_t U8; /// Generic 8 bit unsigned data type +typedef uint16_t U16; /// Generic 16 bit unsigned data type +typedef uint32_t U32; /// Generic 32 bit unsigned data type +typedef uint64_t U64; /// Generic 64 bit unsigned data type + +typedef int8_t S8; /// Generic 8 bit signed data type +typedef int16_t S16; /// Generic 16 bit signed data type +typedef int32_t S32; /// Generic 32 bit signed data type + +#endif diff --git a/macusbfb/drivers/eeprom/at25040/at25040.c b/macusbfb/drivers/eeprom/at25040/at25040.c new file mode 100644 index 0000000..49e50f1 --- /dev/null +++ b/macusbfb/drivers/eeprom/at25040/at25040.c @@ -0,0 +1,297 @@ +/**************************************************************************/ +/*! + @file at25040.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Driver for Atmel's AT25010a/AT25020a/AT25040a 1K/2K/4K serial EEPROM. + + @note The AT25xxx has an 8-byte buffer, including 1 command byte + and one address offset byte, meaning that a maximum of 6 + bytes can be read or written in one operation. An error + will be returned if a value greater than 6 is passed in + for bufferLength with the eepromRead and eepromWrite + methods. + + @section Example + + @code + #include "core/cpu/cpu.h" + #include "drivers/eeprom/at25040/at25040.h" + + int main(void) + { + cpuInit(); + at25Init(); + + // Set read and write buffers + uint8_t wBuffer[1]; + uint8_t rBuffer[1]; + + // Instantiate error message placeholder + at25Error_e error = AT25_ERROR_OK; + + // Write 0xAA to EEPROM at address 0x0000 + wBuffer[0] = 0xAA; + error = at25Write(0x0000, wBuffer, 1); + if (error) + { + // Log the error message or take appropriate actions + switch (error) + { + case (AT25_ERROR_TIMEOUT_WFINISH): + // EEPROM timed out waiting for the write to finish + break; + case (AT25_ERROR_TIMEOUT_WE): + // EEPROM timed out waiting for write-enable + break; + case (AT25_ERROR_ADDRERR): + // Address is out of range + break; + } + } + + // Read the EEPROM at address 0x0000 + at25Read(0x0000, rBuffer, 1); + ... + } + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "at25040.h" +#include "core/ssp/ssp.h" +#include "core/gpio/gpio.h" + +#define AT25_SELECT() gpioSetValue(0, 2, 0) +#define AT25_DESELECT() gpioSetValue(0, 2, 1) + +uint32_t i, timeout; +uint8_t src_addr[SSP_FIFOSIZE]; +uint8_t dest_addr[SSP_FIFOSIZE]; + +/**************************************************************************/ +/*! + @brief Sends the write enable command (WREN/0x06) +*/ +/**************************************************************************/ +static void at25WriteEnable() +{ + AT25_SELECT(); + src_addr[0] = AT25_WREN; + sspSend(0, (uint8_t *)src_addr, 1); + AT25_DESELECT(); + + // Delay for at least 250nS (1nS @ 72MHz = ~0.0072 ticks) + for (i = 0; i < 100; i++); +} + +/**************************************************************************/ +/*! + @brief Gets the value of the Read Status Register (RDSR/0x05) + + @return The 8-bit value returned by the Read Status Register +*/ +/**************************************************************************/ +static uint8_t at25GetRSR() +{ + AT25_SELECT(); + src_addr[0] = AT25_RDSR; + sspSend(0, (uint8_t *)src_addr, 1); + sspReceive(0, (uint8_t *)dest_addr, 1); + AT25_DESELECT(); + return dest_addr[0] & (AT25_RDSR_WEN | AT25_RDSR_RDY); +} + +/**************************************************************************/ +/*! + @brief Initialises the SPI block (CLK set low when inactive, trigger + on leading edge). +*/ +/**************************************************************************/ +void at25Init (void) +{ + sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge); +} + +/**************************************************************************/ +/*! + @brief Reads the specified number of bytes from the supplied address. + + This function will read one or more bytes starting at the supplied + address. + + @param[in] address + The 16-bit address where the read will start. The maximum + value for the address depends on the size of the EEPROM + @param[in] *buffer + Pointer to the buffer that will store the read results + @param[in] bufferLength + Length of the buffer +*/ +/**************************************************************************/ +at25Error_e at25Read (uint16_t address, uint8_t *buffer, uint32_t bufferLength) +{ + if (address >= AT25_MAXADDRESS) + { + return AT25_ERROR_ADDRERR; + } + + if (bufferLength > 6) + { + return AT25_ERROR_BUFFEROVERFLOW; + } + + timeout = 0; + while ( timeout < SSP_MAX_TIMEOUT ) + { + // Wait until the device is ready + uint8_t status = at25GetRSR() & AT25_RDSR_RDY; + if (status == 0) + { + break; + } + timeout++; + } + if ( timeout == SSP_MAX_TIMEOUT ) + { + return AT25_ERROR_TIMEOUT_WE; + } + + AT25_SELECT(); + // Read command (0x03), append A8 if > addr 256 bytes + src_addr[0] = address > 0xFF ? AT25_READ | AT25_A8 : AT25_READ; + src_addr[1] = (address); + sspSend(0, (uint8_t *)src_addr, 2); + sspReceive(0, (uint8_t *)&dest_addr[2], bufferLength); + AT25_DESELECT(); + + // Fill response buffer + for (i = 0; i < bufferLength; i++) + { + buffer[i] = dest_addr[i + 2]; + } + + return AT25_ERROR_OK; +} + +/**************************************************************************/ +/*! + @brief Writes the supplied bytes at a specified address. + + This function will write one or more bytes starting at the supplied + address. + + @param[in] address + The 16-bit address where the write will start. The + maximum value for the address depends on the size of the + EEPROM + @param[in] *buffer + Pointer to the buffer that contains the values to write. + @param[in] bufferLength + Length of the buffer +*/ +/**************************************************************************/ +at25Error_e at25Write (uint16_t address, uint8_t *buffer, uint32_t bufferLength) +{ + if (address >= AT25_MAXADDRESS) + { + return AT25_ERROR_ADDRERR; + } + + if (bufferLength > 6) + { + return AT25_ERROR_BUFFEROVERFLOW; + } + + // Set write enable latch + at25WriteEnable(); + + timeout = 0; + while ( timeout < SSP_MAX_TIMEOUT ) + { + // Wait until the device is write enabled + if (at25GetRSR() == AT25_RDSR_WEN) + { + break; + } + timeout++; + } + if ( timeout == SSP_MAX_TIMEOUT ) + { + return AT25_ERROR_TIMEOUT_WE; + } + + for (i = 0; i < bufferLength; i++) // Init RD and WR buffer + { + src_addr[i+2] = buffer[i]; // leave two bytes for cmd and offset(8 bits) + dest_addr[i] = 0; + } + + AT25_SELECT(); + // Write command (0x02), append A8 if addr > 256 bytes + src_addr[0] = address > 0xFF ? AT25_WRITE | AT25_A8 : AT25_WRITE; + src_addr[1] = (address); + sspSend(0, (uint8_t *)src_addr, bufferLength + 2); + AT25_DESELECT(); + + // Wait at least 3ms + for (i = 0; i < ((CFG_CPU_CCLK / 1000) * 3); i++); + + timeout = 0; + while ( timeout < SSP_MAX_TIMEOUT ) + { + // Check status to see if write cycle is done or not + AT25_SELECT(); + src_addr[0] = AT25_RDSR; + sspSend(0, (uint8_t *)src_addr, 1); + sspReceive(0, (uint8_t *)dest_addr, 1); + AT25_DESELECT(); + // Wait until device is ready + if ((dest_addr[0] & AT25_RDSR_RDY) == 0x00) + { + break; + } + timeout++; + } + if ( timeout == SSP_MAX_TIMEOUT ) + { + return AT25_ERROR_TIMEOUT_WFINISH; + } + + for (i = 0; i < 300; i++); // Wait at least 250ns + + return AT25_ERROR_OK; +} diff --git a/macusbfb/drivers/eeprom/at25040/at25040.h b/macusbfb/drivers/eeprom/at25040/at25040.h new file mode 100644 index 0000000..f9d720e --- /dev/null +++ b/macusbfb/drivers/eeprom/at25040/at25040.h @@ -0,0 +1,85 @@ +/**************************************************************************/ +/*! + @file at25040.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _AT25040_H_ +#define _AT25040_H_ + +#include "projectconfig.h" + +#define AT25_RDSR_RDY 0x01 +#define AT25_RDSR_WEN 0x02 +#define AT25_A8 0x08 // For addresses > 0xFF (AT25040 only) A8 must be added to R/W commands +#define AT25_MAXADDRESS 0x0200 // AT25040 = 0X0200, AT25020 = 0x100, AT25010 = 0x80 + +/**************************************************************************/ +/*! + AT25040 Commands +*/ +/**************************************************************************/ +typedef enum +{ + AT25_WREN = 0x06, + AT25_WRDI = 0x04, + AT25_RDSR = 0x05, + AT25_WRSR = 0x01, + AT25_READ = 0x03, + AT25_WRITE = 0x02 +} at25_Commands_e; + +/**************************************************************************/ +/*! + Error messages +*/ +/**************************************************************************/ +typedef enum +{ + AT25_ERROR_OK = 0, // Everything executed normally + AT25_ERROR_TIMEOUT_WE, // Timed out waiting for write enable status + AT25_ERROR_TIMEOUT_WFINISH, // Timed out waiting for write to finish + AT25_ERROR_ADDRERR, // Address out of range + AT25_ERROR_BUFFEROVERFLOW, // Max 6 bytes can be read/written in one operation + AT2_ERROR_LAST +} +at25Error_e; + +void at25Init (void); +at25Error_e at25Read (uint16_t address, uint8_t *buffer, uint32_t bufferLength); +at25Error_e at25Write (uint16_t address, uint8_t *buffer, uint32_t bufferLength); + +#endif diff --git a/macusbfb/drivers/eeprom/mcp24aa/mcp24aa.c b/macusbfb/drivers/eeprom/mcp24aa/mcp24aa.c new file mode 100644 index 0000000..6782fab --- /dev/null +++ b/macusbfb/drivers/eeprom/mcp24aa/mcp24aa.c @@ -0,0 +1,325 @@ +/**************************************************************************/ +/*! + @file mcp24aa.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Driver for Microchip's 24AA32AF serial EEPROM. This driver assumes + that the address is set to 1010 000. + + @section Example + + @code + #include "core/cpu/cpu.h" + #include "drivers/eeprom/mcp24aa/mcp24aa.h" + + int main(void) + { + cpuInit(); + + mcp24aaInit(); + + // Instantiate error message placeholder + mcp24aaError_e error = MCP24AA_ERROR_OK; + + // Create read buffer (1 byte) + uint8_t buffer[1] = { 0x00 }; + + // Write 0xCC at address 0x125 + error = mcp24aaWriteByte(0x0125, 0xCC); + if (error) + { + // Handle any errors + switch (error) + { + case (MCP24AA_ERROR_I2CINIT): + // Unable to initialise I2C + break; + case (MCP24AA_ERROR_ADDRERR): + // Address out of range + break; + default: + break; + } + } + + // Read the contents of address 0x0125 + error = MCP24AA_ERROR_OK; + error = mcp24aaReadByte(0x0125, buffer); + if (error) + { + // Handle any errors + switch (error) + { + case (MCP24AA_ERROR_I2CINIT): + // Unable to initialise I2C + break; + case (MCP24AA_ERROR_ADDRERR): + // Address out of range + break; + default: + break; + } + } + + uint8_t results = buffer[0]; + } + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "mcp24aa.h" +#include "core/systick/systick.h" +#include "core/i2c/i2c.h" + +extern volatile uint8_t I2CMasterBuffer[I2C_BUFSIZE]; +extern volatile uint8_t I2CSlaveBuffer[I2C_BUFSIZE]; +extern volatile uint32_t I2CReadLength, I2CWriteLength; + +uint32_t i, timeout; + +/**************************************************************************/ +/*! + @brief Initialises the I2C block +*/ +/**************************************************************************/ +mcp24aaError_e mcp24aaInit() +{ + // Initialise I2C + if (i2cInit(I2CMODE_MASTER) == FALSE) + { + return MCP24AA_ERROR_I2CINIT; /* Fatal error */ + } + return MCP24AA_ERROR_OK; +} + +/**************************************************************************/ +/*! + @brief Reads the specified number of bytes from the supplied address. + + This function will read one or more bytes starting at the supplied + address. A maximum of 8 bytes can be read in one operation. + + @param[in] address + The 16-bit address where the read will start. The maximum + value for the address depends on the size of the EEPROM + @param[in] *buffer + Pointer to the buffer that will store the read results + @param[in] bufferLength + Length of the buffer +*/ +/**************************************************************************/ +mcp24aaError_e mcp24aaReadBuffer (uint16_t address, uint8_t *buffer, uint32_t bufferLength) +{ + if (address >= MCP24AA_MAXADDR) + { + return MCP24AA_ERROR_ADDRERR; + } + + if (bufferLength > 8) + { + return MCP24AA_ERROR_BUFFEROVERFLOW; + } + + // ToDo: Check if I2C is ready + + // Clear buffers + for ( i = 0; i < I2C_BUFSIZE; i++ ) + { + I2CMasterBuffer[i] = 0x00; + I2CSlaveBuffer[i] = 0x00; + } + + // Write address bits to enable random read + I2CWriteLength = 3; + I2CReadLength = bufferLength; + I2CMasterBuffer[0] = MCP24AA_ADDR; // I2C device address + I2CMasterBuffer[1] = ((address >> 8) & 0xFF); // Address (high byte) + I2CMasterBuffer[2] = (address & 0xFF); // Address (low byte) + // If you wish to read, you need to append the address w/read bit, though this + // needs to be placed one bit higher than the size of I2CWriteLength which + // may be unexpected + I2CMasterBuffer[3] = MCP24AA_ADDR | MCP24AA_READBIT; + + // Transmit command + i2cEngine(); + + // Fill response buffer + for (i = 0; i < bufferLength; i++) + { + buffer[i] = I2CSlaveBuffer[i]; + } + + return MCP24AA_ERROR_OK; +} + +/**************************************************************************/ +/*! + @brief Writes the supplied bytes at a specified address. + + This function will write one or more bytes starting at the supplied + address. A maximum of 8 bytes can be written in one operation. + + @param[in] address + The 16-bit address where the write will start. The + maximum value for the address depends on the size of the + EEPROM + @param[in] *buffer + Pointer to the buffer that contains the values to write. + @param[in] bufferLength + Length of the buffer +*/ +/**************************************************************************/ +mcp24aaError_e mcp24aaWriteBuffer (uint16_t address, uint8_t *buffer, uint32_t bufferLength) +{ + if (address >= MCP24AA_MAXADDR) + { + return MCP24AA_ERROR_ADDRERR; + } + + if (bufferLength > 8) + { + return MCP24AA_ERROR_BUFFEROVERFLOW; + } + + // ToDo: Check if I2C is ready + + // Clear write buffer + for ( i = 0; i < I2C_BUFSIZE; i++ ) + { + I2CMasterBuffer[i] = 0x00; + } + + // Write address bits and data to the master buffer + I2CWriteLength = 3 + bufferLength; + I2CReadLength = 0; + I2CMasterBuffer[0] = MCP24AA_ADDR; // I2C device address + I2CMasterBuffer[1] = ((address >> 8) & (0xFF)); // Address (high byte) + I2CMasterBuffer[2] = (address & 0xFF); // Address (low byte) + for (i = 0; i < bufferLength; i++) + { + I2CMasterBuffer[i+3] = buffer[i]; + } + + // Transmit command + i2cEngine(); + + // Wait at least 10ms + systickDelay(10 / CFG_SYSTICK_DELAY_IN_MS); + + return MCP24AA_ERROR_OK; +} + +/**************************************************************************/ +/*! + @brief Reads one byte from the supplied address. + + This function will read one byte starting at the supplied address. + + @param[in] address + The 16-bit address where the read will start. The maximum + value for the address depends on the size of the EEPROM + @param[in] *buffer + Pointer to the buffer that will store the read results + + @code + #include "core/cpu/cpu/h" + #include "drivers/eeprom/mcp24aa/mcp24aa.h" + ... + cpuInit(); + mcp24aaInit(); + + // Create read buffer (1 byte) + uint8_t buffer[1] = { 0x00 }; + + // Write 0xEE and address 0x0120 + mcp24aaWriteByte(0x0120, 0xEE); + + // Populate buffer with contents of 0x0120 + mcp24aaReadByte(0x0120, buffer); + + // results should equal 0xEE + uint8_t results = buffer[0]; + @endcode +*/ +/**************************************************************************/ +mcp24aaError_e mcp24aaReadByte (uint16_t address, uint8_t *buffer) +{ + return mcp24aaReadBuffer(address, buffer, 1); +} + +/**************************************************************************/ +/*! + @brief Writes one byte to the supplied address. + + This function will write one byte at the supplied address. + + @param[in] address + The 16-bit address where the write will start. The maximum + value for the address depends on the size of the EEPROM + @param[in] value + The data to be written to the EEPROM + + @code + #include "core/cpu/cpu/h" + #include "drivers/eeprom/mcp24aa/mcp24aa.h" + ... + cpuInit(); + mcp24aaInit(); + + // Create read buffer (1 byte) + uint8_t buffer[1] = { 0x00 }; + + // Write 0xEE and address 0x0120 + mcp24aaWriteByte(0x0120, 0xEE); + + // Populate buffer with contents of 0x0120 + mcp24aaReadByte(0x0120, buffer); + + // results should equal 0xEE + uint8_t results = buffer[0]; + @endcode +*/ +/**************************************************************************/ +mcp24aaError_e mcp24aaWriteByte (uint16_t address, uint8_t value) +{ + // Set read buffer + uint8_t wBuffer[1]; + + // Write byte to EEPROM at specified address + wBuffer[0] = value; + return mcp24aaWriteBuffer(address, wBuffer, 1); +} + diff --git a/macusbfb/drivers/eeprom/mcp24aa/mcp24aa.h b/macusbfb/drivers/eeprom/mcp24aa/mcp24aa.h new file mode 100644 index 0000000..ac55468 --- /dev/null +++ b/macusbfb/drivers/eeprom/mcp24aa/mcp24aa.h @@ -0,0 +1,67 @@ +/**************************************************************************/ +/*! + @file mcp24aa.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _MCP24AA_H_ +#define _MCP24AA_H_ + +#include "projectconfig.h" + +#define MCP24AA_ADDR 0xA0 // 10100000 +#define MCP24AA_RW 0x01 +#define MCP24AA_READBIT 0x01 +#define MCP24AA_MAXADDR 0xFFF // 4K = 4096 + +typedef enum +{ + MCP24AA_ERROR_OK = 0, // Everything executed normally + MCP24AA_ERROR_I2CINIT, // Unable to initialise I2C + MCP24AA_ERROR_I2CBUSY, // I2C already in use + MCP24AA_ERROR_ADDRERR, // Address out of range + MCP24AA_ERROR_BUFFEROVERFLOW, // Max 8 bytes can be read/written in one operation + MCP24AA_ERROR_LAST +} +mcp24aaError_e; + +mcp24aaError_e mcp24aaInit (void); +mcp24aaError_e mcp24aaReadBuffer (uint16_t address, uint8_t *buffer, uint32_t bufferLength); +mcp24aaError_e mcp24aaWriteBuffer (uint16_t address, uint8_t *buffer, uint32_t bufferLength); +mcp24aaError_e mcp24aaReadByte (uint16_t address, uint8_t *buffer); +mcp24aaError_e mcp24aaWriteByte (uint16_t address, uint8_t value); + + +#endif diff --git a/macusbfb/drivers/fatfs/ccsbcs.c b/macusbfb/drivers/fatfs/ccsbcs.c new file mode 100644 index 0000000..968192f --- /dev/null +++ b/macusbfb/drivers/fatfs/ccsbcs.c @@ -0,0 +1,540 @@ +/*------------------------------------------------------------------------*/ +/* Unicode - Local code bidirectional converter (C)ChaN, 2009 */ +/* (SBCS code pages) */ +/*------------------------------------------------------------------------*/ +/* 437 U.S. (OEM) +/ 720 Arabic (OEM) +/ 1256 Arabic (Windows) +/ 737 Greek (OEM) +/ 1253 Greek (Windows) +/ 1250 Central Europe (Windows) +/ 775 Baltic (OEM) +/ 1257 Baltic (Windows) +/ 850 Multilingual Latin 1 (OEM) +/ 852 Latin 2 (OEM) +/ 1252 Latin 1 (Windows) +/ 855 Cyrillic (OEM) +/ 1251 Cyrillic (Windows) +/ 866 Russian (OEM) +/ 857 Turkish (OEM) +/ 1254 Turkish (Windows) +/ 858 Multilingual Latin 1 + Euro (OEM) +/ 862 Hebrew (OEM) +/ 1255 Hebrew (Windows) +/ 874 Thai (OEM, Windows) +/ 1258 Vietnam (OEM, Windows) +*/ + +#include "ff.h" + + +#if _CODE_PAGE == 437 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, + 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, + 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, + 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, + 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, + 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, + 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 720 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */ + 0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7, + 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9, + 0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627, + 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F, + 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, + 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642, + 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A, + 0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0xO650, 0x2248, + 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 737 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */ + 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, + 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0, + 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, + 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8, + 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, + 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, + 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD, + 0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E, + 0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248, + 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 775 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */ + 0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107, + 0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A, + 0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4, + 0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6, + 0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118, + 0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D, + 0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B, + 0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144, + 0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019, + 0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E, + 0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 850 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, + 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, + 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, + 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, + 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE, + 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580, + 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, + 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4, + 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, + 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 852 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7, + 0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106, + 0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A, + 0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E, + 0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A, + 0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE, + 0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580, + 0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161, + 0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4, + 0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8, + 0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 855 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */ + 0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404, + 0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408, + 0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C, + 0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A, + 0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414, + 0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438, + 0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E, + 0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580, + 0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443, + 0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116, + 0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D, + 0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 857 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, + 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, + 0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F, + 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, + 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE, + 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580, + 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000, + 0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4, + 0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, + 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 858 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP858(0x80-0xFF) to Unicode conversion table */ + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, + 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, + 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, + 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, + 0x00A9, 0x2563, 0x2551, 0x2557, 0x2550, 0x00A2, 0x00A5, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, + 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x20AC, 0x00CD, 0x00CE, + 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00C6, 0x00CC, 0x2580, + 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, + 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4, + 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, + 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 862 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */ + 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, + 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, + 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, + 0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, + 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, + 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, + 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, + 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 866 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */ + 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, + 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, + 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, + 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, + 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, + 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, + 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, + 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, + 0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E, + 0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0 +}; + +#elif _CODE_PAGE == 874 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP874(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x2026, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07, + 0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F, + 0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17, + 0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F, + 0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27, + 0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F, + 0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37, + 0x0E38, 0x0E39, 0x0E3A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0E3F, + 0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47, + 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F, + 0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57, + 0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0x0000, 0x0000, 0x0000, 0x0000 +}; + +#elif _CODE_PAGE == 1250 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1250(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021, + 0x0000, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x0000, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A, + 0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7, + 0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B, + 0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7, + 0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C, + 0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7, + 0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E, + 0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7, + 0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF, + 0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7, + 0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, + 0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, + 0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9 +}; + +#elif _CODE_PAGE == 1251 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */ + 0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021, + 0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F, + 0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x0000, 0x2111, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F, + 0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7, + 0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407, + 0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7, + 0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457, + 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, + 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, + 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, + 0x0428, 0x0429, 0x042A, 0x042D, 0x042C, 0x042D, 0x042E, 0x042F, + 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, + 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, + 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, + 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F +}; + +#elif _CODE_PAGE == 1252 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1252(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, + 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178, + 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, + 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, + 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, + 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, + 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, + 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, + 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, + 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, + 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, + 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, + 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, + 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF +}; + +#elif _CODE_PAGE == 1253 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1253(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, + 0x0000, 0x2030, 0x0000, 0x2039, 0x000C, 0x0000, 0x0000, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, + 0x00A8, 0x00A9, 0x0000, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015, + 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7, + 0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F, + 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, + 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, + 0x03A0, 0x03A1, 0x0000, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, + 0x03A8, 0x03A9, 0x03AA, 0x03AD, 0x03AC, 0x03AD, 0x03AE, 0x03AF, + 0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, + 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, + 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7, + 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0000 +}; + +#elif _CODE_PAGE == 1254 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1254(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x0000, 0x210A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, + 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178, + 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, + 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, + 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, + 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, + 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, + 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, + 0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, + 0x00D8, 0x00D9, 0x00DA, 0x00BD, 0x00DC, 0x0130, 0x015E, 0x00DF, + 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, + 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, + 0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, + 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF +}; + +#elif _CODE_PAGE == 1255 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1255(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, + 0x02C6, 0x2030, 0x0000, 0x2039, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x02DC, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, + 0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, + 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, + 0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, + 0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7, + 0x05B8, 0x05B9, 0x0000, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF, + 0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3, + 0x05F4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, + 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, + 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, + 0x05E8, 0x05E9, 0x05EA, 0x0000, 0x0000, 0x200E, 0x200F, 0x0000 +}; + +#elif _CODE_PAGE == 1256 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, + 0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688, + 0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA, + 0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, + 0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, + 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, + 0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F, + 0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, + 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F, + 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7, + 0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0640, 0x0642, 0x0643, + 0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7, + 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF, + 0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7, + 0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2 +} + +#elif _CODE_PAGE == 1257 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1257(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021, + 0x0000, 0x2030, 0x0000, 0x2039, 0x0000, 0x00A8, 0x02C7, 0x00B8, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x00AF, 0x02DB, 0x0000, + 0x00A0, 0x0000, 0x00A2, 0x00A3, 0x00A4, 0x0000, 0x00A6, 0x00A7, + 0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, + 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, + 0x00B8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6, + 0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112, + 0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B, + 0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7, + 0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF, + 0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113, + 0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C, + 0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7, + 0x0173, 0x014E, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9 +}; + +#elif _CODE_PAGE == 1258 +#define _TBLDEF 1 +static +const WCHAR Tbl[] = { /* CP1258(0x80-0xFF) to Unicode conversion table */ + 0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, + 0x02C6, 0x2030, 0x0000, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x02DC, 0x2122, 0x0000, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178, + 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, + 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, + 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, + 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, + 0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7, + 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF, + 0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7, + 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF, + 0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7, + 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF, + 0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7, + 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF +}; + +#endif + + +#if !_TBLDEF || !_USE_LFN +#error This file is not needed in current configuration. Remove from the project. +#endif + + +WCHAR ff_convert ( /* Converted character, Returns zero on error */ + WCHAR src, /* Character code to be converted */ + UINT dir /* 0: Unicode to OEMCP, 1: OEMCP to Unicode */ +) +{ + WCHAR c; + + + if (src < 0x80) { /* ASCII */ + c = src; + + } else { + if (dir) { /* OEMCP to Unicode */ + c = (src >= 0x100) ? 0 : Tbl[src - 0x80]; + + } else { /* Unicode to OEMCP */ + for (c = 0; c < 0x80; c++) { + if (src == Tbl[c]) break; + } + c = (c + 0x80) & 0xFF; + } + } + + return c; +} + + +WCHAR ff_wtoupper ( /* Upper converted character */ + WCHAR chr /* Input character */ +) +{ + static const WCHAR tbl_lower[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0xA1, 0x00A2, 0x00A3, 0x00A5, 0x00AC, 0x00AF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x0FF, 0x101, 0x103, 0x105, 0x107, 0x109, 0x10B, 0x10D, 0x10F, 0x111, 0x113, 0x115, 0x117, 0x119, 0x11B, 0x11D, 0x11F, 0x121, 0x123, 0x125, 0x127, 0x129, 0x12B, 0x12D, 0x12F, 0x131, 0x133, 0x135, 0x137, 0x13A, 0x13C, 0x13E, 0x140, 0x142, 0x144, 0x146, 0x148, 0x14B, 0x14D, 0x14F, 0x151, 0x153, 0x155, 0x157, 0x159, 0x15B, 0x15D, 0x15F, 0x161, 0x163, 0x165, 0x167, 0x169, 0x16B, 0x16D, 0x16F, 0x171, 0x173, 0x175, 0x177, 0x17A, 0x17C, 0x17E, 0x192, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x45E, 0x45F, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179, 0x217A, 0x217B, 0x217C, 0x217D, 0x217E, 0x217F, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0 }; + static const WCHAR tbl_upper[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x21, 0xFFE0, 0xFFE1, 0xFFE5, 0xFFE2, 0xFFE3, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x178, 0x100, 0x102, 0x104, 0x106, 0x108, 0x10A, 0x10C, 0x10E, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11A, 0x11C, 0x11E, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12A, 0x12C, 0x12E, 0x130, 0x132, 0x134, 0x136, 0x139, 0x13B, 0x13D, 0x13F, 0x141, 0x143, 0x145, 0x147, 0x14A, 0x14C, 0x14E, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15A, 0x15C, 0x15E, 0x160, 0x162, 0x164, 0x166, 0x168, 0x16A, 0x16C, 0x16E, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17B, 0x17D, 0x191, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x40E, 0x40F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0 }; + int i; + + + for (i = 0; tbl_lower[i] && chr != tbl_lower[i]; i++) ; + + return tbl_lower[i] ? tbl_upper[i] : chr; +} diff --git a/macusbfb/drivers/fatfs/diskio.h b/macusbfb/drivers/fatfs/diskio.h new file mode 100644 index 0000000..c891a32 --- /dev/null +++ b/macusbfb/drivers/fatfs/diskio.h @@ -0,0 +1,81 @@ +/*----------------------------------------------------------------------- +/ Low level disk interface modlue include file R0.05 (C)ChaN, 2007 +/-----------------------------------------------------------------------*/ + +#ifndef _DISKIO + +#define _READONLY 0 /* 1: Read-only mode */ +#define _USE_IOCTL 1 + +#include "integer.h" + + +/* Status of Disk Functions */ +typedef BYTE DSTATUS; + +/* Results of Disk Functions */ +typedef enum { + RES_OK = 0, /* 0: Successful */ + RES_ERROR, /* 1: R/W Error */ + RES_WRPRT, /* 2: Write Protected */ + RES_NOTRDY, /* 3: Not Ready */ + RES_PARERR /* 4: Invalid Parameter */ +} DRESULT; + + +/*---------------------------------------*/ +/* Prototypes for disk control functions */ + +DSTATUS disk_initialize (BYTE); +DSTATUS disk_status (BYTE); +DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); +#if _READONLY == 0 +DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); +#endif +DRESULT disk_ioctl (BYTE, BYTE, void*); +void disk_timerproc (void); + + + + +/* Disk Status Bits (DSTATUS) */ + +#define STA_NOINIT 0x01 /* Drive not initialized */ +#define STA_NODISK 0x02 /* No medium in the drive */ +#define STA_PROTECT 0x04 /* Write protected */ + + + +/* Command code for disk_ioctrl() */ + +/* Generic command */ +#define CTRL_SYNC 0 /* Mandatory for write functions */ +#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */ +#define GET_SECTOR_SIZE 2 +#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */ +#define CTRL_POWER 4 +#define CTRL_LOCK 5 +#define CTRL_EJECT 6 +/* MMC/SDC command */ +#define MMC_GET_TYPE 10 +#define MMC_GET_CSD 11 +#define MMC_GET_CID 12 +#define MMC_GET_OCR 13 +#define MMC_GET_SDSTAT 14 +/* ATA/CF command */ +#define ATA_GET_REV 20 +#define ATA_GET_MODEL 21 +#define ATA_GET_SN 22 + + + +/* Card type flags (CardType) */ +#define CT_MMC 0x01 /* MMC ver 3 */ +#define CT_SD1 0x02 /* SD ver 1 */ +#define CT_SD2 0x04 /* SD ver 2 */ +#define CT_SDC (CT_SD1|CT_SD2) /* SD */ +#define CT_BLOCK 0x08 /* Block addressing */ + + +#define _DISKIO +#endif diff --git a/macusbfb/drivers/fatfs/ff.c b/macusbfb/drivers/fatfs/ff.c new file mode 100644 index 0000000..4747019 --- /dev/null +++ b/macusbfb/drivers/fatfs/ff.c @@ -0,0 +1,3154 @@ +/*----------------------------------------------------------------------------/ +/ FatFs - FAT file system module R0.07e (C)ChaN, 2009 +/-----------------------------------------------------------------------------/ +/ FatFs module is a generic FAT file system module for small embedded systems. +/ This is a free software that opened for education, research and commercial +/ developments under license policy of following trems. +/ +/ Copyright (C) 2009, ChaN, all right reserved. +/ +/ * The FatFs module is a free software and there is NO WARRANTY. +/ * No restriction on use. You can use, modify and redistribute it for +/ personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY. +/ * Redistributions of source code must retain the above copyright notice. +/ +/-----------------------------------------------------------------------------/ +/ Feb 26,'06 R0.00 Prototype. +/ +/ Apr 29,'06 R0.01 First stable version. +/ +/ Jun 01,'06 R0.02 Added FAT12 support. +/ Removed unbuffered mode. +/ Fixed a problem on small (<32M) patition. +/ Jun 10,'06 R0.02a Added a configuration option (_FS_MINIMUM). +/ +/ Sep 22,'06 R0.03 Added f_rename(). +/ Changed option _FS_MINIMUM to _FS_MINIMIZE. +/ Dec 11,'06 R0.03a Improved cluster scan algolithm to write files fast. +/ Fixed f_mkdir() creates incorrect directory on FAT32. +/ +/ Feb 04,'07 R0.04 Supported multiple drive system. +/ Changed some interfaces for multiple drive system. +/ Changed f_mountdrv() to f_mount(). +/ Added f_mkfs(). +/ Apr 01,'07 R0.04a Supported multiple partitions on a plysical drive. +/ Added a capability of extending file size to f_lseek(). +/ Added minimization level 3. +/ Fixed an endian sensitive code in f_mkfs(). +/ May 05,'07 R0.04b Added a configuration option _USE_NTFLAG. +/ Added FSInfo support. +/ Fixed DBCS name can result FR_INVALID_NAME. +/ Fixed short seek (<= csize) collapses the file object. +/ +/ Aug 25,'07 R0.05 Changed arguments of f_read(), f_write() and f_mkfs(). +/ Fixed f_mkfs() on FAT32 creates incorrect FSInfo. +/ Fixed f_mkdir() on FAT32 creates incorrect directory. +/ Feb 03,'08 R0.05a Added f_truncate() and f_utime(). +/ Fixed off by one error at FAT sub-type determination. +/ Fixed btr in f_read() can be mistruncated. +/ Fixed cached sector is not flushed when create and close +/ without write. +/ +/ Apr 01,'08 R0.06 Added fputc(), fputs(), fprintf() and fgets(). +/ Improved performance of f_lseek() on moving to the same +/ or following cluster. +/ +/ Apr 01,'09 R0.07 Merged Tiny-FatFs as a buffer configuration option. +/ Added long file name support. +/ Added multiple code page support. +/ Added re-entrancy for multitask operation. +/ Added auto cluster size selection to f_mkfs(). +/ Added rewind option to f_readdir(). +/ Changed result code of critical errors. +/ Renamed string functions to avoid name collision. +/ Apr 14,'09 R0.07a Separated out OS dependent code on reentrant cfg. +/ Added multiple sector size support. +/ Jun 21,'09 R0.07c Fixed f_unlink() can return FR_OK on error. +/ Fixed wrong cache control in f_lseek(). +/ Added relative path feature. +/ Added f_chdir() and f_chdrive(). +/ Added proper case conversion to extended char. +/ Nov 03,'09 R0.07e Separated out configuration options from ff.h to ffconf.h. +/ Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH. +/ Fixed name matching error on the 13 char boundary. +/ Added a configuration option, _LFN_UNICODE. +/ Changed f_readdir() to return the SFN with always upper +/ case on non-LFN cfg. +/---------------------------------------------------------------------------*/ + +#include "projectconfig.h" +#include "ff.h" /* FatFs configurations and declarations */ +#include "diskio.h" /* Declarations of low level disk I/O functions */ + +/*-------------------------------------------------------------------------- + + Module Private Definitions + +---------------------------------------------------------------------------*/ + +#if _FATFS != 0x007E +#error Wrong include file (ff.h). +#endif + +#if _FS_REENTRANT +#if _USE_LFN == 1 +#error Static LFN work area must not be used in re-entrant configuration. +#endif +#define ENTER_FF(fs) { if (!lock_fs(fs)) return FR_TIMEOUT; } +#define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; } + +#else +#define ENTER_FF(fs) +#define LEAVE_FF(fs, res) return res + +#endif + +#define ABORT(fs, res) { fp->flag |= FA__ERROR; LEAVE_FF(fs, res); } + +#ifndef NULL +#define NULL 0 +#endif + +/* Name status flags */ +#define NS 11 /* Offset of name status byte */ +#define NS_LOSS 0x01 /* Out of 8.3 format */ +#define NS_LFN 0x02 /* Force to create LFN entry */ +#define NS_LAST 0x04 /* Last segment */ +#define NS_BODY 0x08 /* Lower case flag (body) */ +#define NS_EXT 0x10 /* Lower case flag (ext) */ +#define NS_DOT 0x20 /* Dot entry */ + + + + +/*-------------------------------------------------------------------------- + + Private Work Area + +---------------------------------------------------------------------------*/ + +#if _DRIVES < 1 || _DRIVES > 9 +#error Number of drives must be 1-9. +#endif +static +FATFS *FatFs[_DRIVES]; /* Pointer to the file system objects (logical drives) */ + +static +WORD Fsid; /* File system mount ID */ + +#if _FS_RPATH +static +BYTE Drive; /* Current drive */ +#endif + + +#if _USE_LFN == 1 /* LFN with static LFN working buffer */ +static +WCHAR LfnBuf[_MAX_LFN + 1]; +#define NAMEBUF(sp,lp) BYTE sp[12]; WCHAR *lp = LfnBuf +#define INITBUF(dj,sp,lp) dj.fn = sp; dj.lfn = lp + +#elif _USE_LFN > 1 /* LFN with dynamic LFN working buffer */ +#define NAMEBUF(sp,lp) BYTE sp[12]; WCHAR lbuf[_MAX_LFN + 1], *lp = lbuf +#define INITBUF(dj,sp,lp) dj.fn = sp; dj.lfn = lp + +#else /* No LFN */ +#define NAMEBUF(sp,lp) BYTE sp[12] +#define INITBUF(dj,sp,lp) dj.fn = sp + +#endif + + + + +/*-------------------------------------------------------------------------- + + Module Private Functions + +---------------------------------------------------------------------------*/ + + +/*-----------------------------------------------------------------------*/ +/* String functions */ +/*-----------------------------------------------------------------------*/ + +/* Copy memory to memory */ +static +void mem_cpy (void* dst, const void* src, int cnt) { + char *d = (char*)dst; + const char *s = (const char *)src; + while (cnt--) *d++ = *s++; +} + +/* Fill memory */ +static +void mem_set (void* dst, int val, int cnt) { + char *d = (char*)dst; + while (cnt--) *d++ = (char)val; +} + +/* Compare memory to memory */ +static +int mem_cmp (const void* dst, const void* src, int cnt) { + const char *d = (const char *)dst, *s = (const char *)src; + int r = 0; + while (cnt-- && (r = *d++ - *s++) == 0) ; + return r; +} + +/* Check if chr is contained in the string */ +static +int chk_chr (const char* str, int chr) { + while (*str && *str != chr) str++; + return *str; +} + + + +/*-----------------------------------------------------------------------*/ +/* Request/Release grant to access the volume */ +/*-----------------------------------------------------------------------*/ +#if _FS_REENTRANT + +static +BOOL lock_fs ( + FATFS *fs /* File system object */ +) +{ + return ff_req_grant(fs->sobj); +} + + +static +void unlock_fs ( + FATFS *fs, /* File system object */ + FRESULT res /* Result code to be returned */ +) +{ + if (res != FR_NOT_ENABLED && + res != FR_INVALID_DRIVE && + res != FR_INVALID_OBJECT && + res != FR_TIMEOUT) { + ff_rel_grant(fs->sobj); + } +} +#endif + + + +/*-----------------------------------------------------------------------*/ +/* Change window offset */ +/*-----------------------------------------------------------------------*/ + +static +FRESULT move_window ( + FATFS *fs, /* File system object */ + DWORD sector /* Sector number to make apperance in the fs->win[] */ +) /* Move to zero only writes back dirty window */ +{ + DWORD wsect; + + + wsect = fs->winsect; + if (wsect != sector) { /* Changed current window */ +#if !_FS_READONLY + if (fs->wflag) { /* Write back dirty window if needed */ + if (disk_write(fs->drive, fs->win, wsect, 1) != RES_OK) + return FR_DISK_ERR; + fs->wflag = 0; + if (wsect < (fs->fatbase + fs->sects_fat)) { /* In FAT area */ + BYTE nf; + for (nf = fs->n_fats; nf > 1; nf--) { /* Refrect the change to all FAT copies */ + wsect += fs->sects_fat; + disk_write(fs->drive, fs->win, wsect, 1); + } + } + } +#endif + if (sector) { + if (disk_read(fs->drive, fs->win, sector, 1) != RES_OK) + return FR_DISK_ERR; + fs->winsect = sector; + } + } + + return FR_OK; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Clean-up cached data */ +/*-----------------------------------------------------------------------*/ +#if !_FS_READONLY +static +FRESULT sync ( /* FR_OK: successful, FR_DISK_ERR: failed */ + FATFS *fs /* File system object */ +) +{ + FRESULT res; + + + res = move_window(fs, 0); + if (res == FR_OK) { + /* Update FSInfo sector if needed */ + if (fs->fs_type == FS_FAT32 && fs->fsi_flag) { + fs->winsect = 0; + mem_set(fs->win, 0, 512); + ST_WORD(fs->win+BS_55AA, 0xAA55); + ST_DWORD(fs->win+FSI_LeadSig, 0x41615252); + ST_DWORD(fs->win+FSI_StrucSig, 0x61417272); + ST_DWORD(fs->win+FSI_Free_Count, fs->free_clust); + ST_DWORD(fs->win+FSI_Nxt_Free, fs->last_clust); + disk_write(fs->drive, fs->win, fs->fsi_sector, 1); + fs->fsi_flag = 0; + } + /* Make sure that no pending write process in the physical drive */ + if (disk_ioctl(fs->drive, CTRL_SYNC, (void*)NULL) != RES_OK) + res = FR_DISK_ERR; + } + + return res; +} +#endif + + + + +/*-----------------------------------------------------------------------*/ +/* FAT access - Read value of a FAT entry */ +/*-----------------------------------------------------------------------*/ + + +DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Interal error, Else:Cluster status */ + FATFS *fs, /* File system object */ + DWORD clst /* Cluster# to get the link information */ +) +{ + UINT wc, bc; + DWORD fsect; + + + if (clst < 2 || clst >= fs->max_clust) /* Range check */ + return 1; + + fsect = fs->fatbase; + switch (fs->fs_type) { + case FS_FAT12 : + bc = clst; bc += bc / 2; + if (move_window(fs, fsect + (bc / SS(fs)))) break; + wc = fs->win[bc & (SS(fs) - 1)]; bc++; + if (move_window(fs, fsect + (bc / SS(fs)))) break; + wc |= (WORD)fs->win[bc & (SS(fs) - 1)] << 8; + return (clst & 1) ? (wc >> 4) : (wc & 0xFFF); + + case FS_FAT16 : + if (move_window(fs, fsect + (clst / (SS(fs) / 2)))) break; + return LD_WORD(&fs->win[((WORD)clst * 2) & (SS(fs) - 1)]); + + case FS_FAT32 : + if (move_window(fs, fsect + (clst / (SS(fs) / 4)))) break; + return LD_DWORD(&fs->win[((WORD)clst * 4) & (SS(fs) - 1)]) & 0x0FFFFFFF; + } + + return 0xFFFFFFFF; /* An error occured at the disk I/O layer */ +} + + + + +/*-----------------------------------------------------------------------*/ +/* FAT access - Change value of a FAT entry */ +/*-----------------------------------------------------------------------*/ +#if !_FS_READONLY + +FRESULT put_fat ( + FATFS *fs, /* File system object */ + DWORD clst, /* Cluster# to be changed in range of 2 to fs->max_clust - 1 */ + DWORD val /* New value to mark the cluster */ +) +{ + UINT bc; + BYTE *p; + DWORD fsect; + FRESULT res; + + + if (clst < 2 || clst >= fs->max_clust) { /* Range check */ + res = FR_INT_ERR; + + } else { + fsect = fs->fatbase; + switch (fs->fs_type) { + case FS_FAT12 : + bc = clst; bc += bc / 2; + res = move_window(fs, fsect + (bc / SS(fs))); + if (res != FR_OK) break; + p = &fs->win[bc & (SS(fs) - 1)]; + *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; + bc++; + fs->wflag = 1; + res = move_window(fs, fsect + (bc / SS(fs))); + if (res != FR_OK) break; + p = &fs->win[bc & (SS(fs) - 1)]; + *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); + break; + + case FS_FAT16 : + res = move_window(fs, fsect + (clst / (SS(fs) / 2))); + if (res != FR_OK) break; + ST_WORD(&fs->win[((WORD)clst * 2) & (SS(fs) - 1)], (WORD)val); + break; + + case FS_FAT32 : + res = move_window(fs, fsect + (clst / (SS(fs) / 4))); + if (res != FR_OK) break; + ST_DWORD(&fs->win[((WORD)clst * 4) & (SS(fs) - 1)], val); + break; + + default : + res = FR_INT_ERR; + } + fs->wflag = 1; + } + + return res; +} +#endif /* !_FS_READONLY */ + + + + +/*-----------------------------------------------------------------------*/ +/* FAT handling - Remove a cluster chain */ +/*-----------------------------------------------------------------------*/ +#if !_FS_READONLY +static +FRESULT remove_chain ( + FATFS *fs, /* File system object */ + DWORD clst /* Cluster# to remove a chain from */ +) +{ + FRESULT res; + DWORD nxt; + + + if (clst < 2 || clst >= fs->max_clust) { /* Check the range of cluster# */ + res = FR_INT_ERR; + + } else { + res = FR_OK; + while (clst < fs->max_clust) { /* Not a last link? */ + nxt = get_fat(fs, clst); /* Get cluster status */ + if (nxt == 0) break; /* Empty cluster? */ + if (nxt == 1) { res = FR_INT_ERR; break; } /* Internal error? */ + if (nxt == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } /* Disk error? */ + res = put_fat(fs, clst, 0); /* Mark the cluster "empty" */ + if (res != FR_OK) break; + if (fs->free_clust != 0xFFFFFFFF) { /* Update FSInfo */ + fs->free_clust++; + fs->fsi_flag = 1; + } + clst = nxt; /* Next cluster */ + } + } + + return res; +} +#endif + + + + +/*-----------------------------------------------------------------------*/ +/* FAT handling - Stretch or Create a cluster chain */ +/*-----------------------------------------------------------------------*/ +#if !_FS_READONLY +static +DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */ + FATFS *fs, /* File system object */ + DWORD clst /* Cluster# to stretch. 0 means create a new chain. */ +) +{ + DWORD cs, ncl, scl, mcl; + + + mcl = fs->max_clust; + if (clst == 0) { /* Create new chain */ + scl = fs->last_clust; /* Get suggested start point */ + if (scl == 0 || scl >= mcl) scl = 1; + } + else { /* Stretch existing chain */ + cs = get_fat(fs, clst); /* Check the cluster status */ + if (cs < 2) return 1; /* It is an invalid cluster */ + if (cs < mcl) return cs; /* It is already followed by next cluster */ + scl = clst; + } + + ncl = scl; /* Start cluster */ + for (;;) { + ncl++; /* Next cluster */ + if (ncl >= mcl) { /* Wrap around */ + ncl = 2; + if (ncl > scl) return 0; /* No free custer */ + } + cs = get_fat(fs, ncl); /* Get the cluster status */ + if (cs == 0) break; /* Found a free cluster */ + if (cs == 0xFFFFFFFF || cs == 1)/* An error occured */ + return cs; + if (ncl == scl) return 0; /* No free custer */ + } + + if (put_fat(fs, ncl, 0x0FFFFFFF)) /* Mark the new cluster "in use" */ + return 0xFFFFFFFF; + if (clst != 0) { /* Link it to the previous one if needed */ + if (put_fat(fs, clst, ncl)) + return 0xFFFFFFFF; + } + + fs->last_clust = ncl; /* Update FSINFO */ + if (fs->free_clust != 0xFFFFFFFF) { + fs->free_clust--; + fs->fsi_flag = 1; + } + + return ncl; /* Return new cluster number */ +} +#endif /* !_FS_READONLY */ + + + + +/*-----------------------------------------------------------------------*/ +/* Get sector# from cluster# */ +/*-----------------------------------------------------------------------*/ + + +DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */ + FATFS *fs, /* File system object */ + DWORD clst /* Cluster# to be converted */ +) +{ + clst -= 2; + if (clst >= (fs->max_clust - 2)) return 0; /* Invalid cluster# */ + return clst * fs->csize + fs->database; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Directory handling - Seek directory index */ +/*-----------------------------------------------------------------------*/ + +static +FRESULT dir_seek ( + DIR *dj, /* Pointer to directory object */ + WORD idx /* Directory index number */ +) +{ + DWORD clst; + WORD ic; + + + dj->index = idx; + clst = dj->sclust; + if (clst == 1 || clst >= dj->fs->max_clust) /* Check start cluster range */ + return FR_INT_ERR; + if (!clst && dj->fs->fs_type == FS_FAT32) /* Replace cluster# 0 with root cluster# if in FAT32 */ + clst = dj->fs->dirbase; + + if (clst == 0) { /* Static table */ + dj->clust = clst; + if (idx >= dj->fs->n_rootdir) /* Index is out of range */ + return FR_INT_ERR; + dj->sect = dj->fs->dirbase + idx / (SS(dj->fs) / 32); /* Sector# */ + } + else { /* Dynamic table */ + ic = SS(dj->fs) / 32 * dj->fs->csize; /* Entries per cluster */ + while (idx >= ic) { /* Follow cluster chain */ + clst = get_fat(dj->fs, clst); /* Get next cluster */ + if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */ + if (clst < 2 || clst >= dj->fs->max_clust) /* Reached to end of table or int error */ + return FR_INT_ERR; + idx -= ic; + } + dj->clust = clst; + dj->sect = clust2sect(dj->fs, clst) + idx / (SS(dj->fs) / 32); /* Sector# */ + } + + dj->dir = dj->fs->win + (idx % (SS(dj->fs) / 32)) * 32; /* Ptr to the entry in the sector */ + + return FR_OK; /* Seek succeeded */ +} + + + + +/*-----------------------------------------------------------------------*/ +/* Directory handling - Move directory index next */ +/*-----------------------------------------------------------------------*/ + +static +FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:EOT and could not streach */ + DIR *dj, /* Pointer to directory object */ + BOOL streach /* FALSE: Do not streach table, TRUE: Streach table if needed */ +) +{ + DWORD clst; + WORD i; + + + i = dj->index + 1; + if (!i || !dj->sect) /* Report EOT when index has reached 65535 */ + return FR_NO_FILE; + + if (!(i % (SS(dj->fs) / 32))) { /* Sector changed? */ + dj->sect++; /* Next sector */ + + if (dj->clust == 0) { /* Static table */ + if (i >= dj->fs->n_rootdir) /* Report EOT when end of table */ + return FR_NO_FILE; + } + else { /* Dynamic table */ + if (((i / (SS(dj->fs) / 32)) & (dj->fs->csize - 1)) == 0) { /* Cluster changed? */ + clst = get_fat(dj->fs, dj->clust); /* Get next cluster */ + if (clst <= 1) return FR_INT_ERR; + if (clst == 0xFFFFFFFF) return FR_DISK_ERR; + if (clst >= dj->fs->max_clust) { /* When it reached end of dynamic table */ +#if !_FS_READONLY + BYTE c; + if (!streach) return FR_NO_FILE; /* When do not streach, report EOT */ + clst = create_chain(dj->fs, dj->clust); /* Streach cluster chain */ + if (clst == 0) return FR_DENIED; /* No free cluster */ + if (clst == 1) return FR_INT_ERR; + if (clst == 0xFFFFFFFF) return FR_DISK_ERR; + /* Clean-up streached table */ + if (move_window(dj->fs, 0)) return FR_DISK_ERR; /* Flush active window */ + mem_set(dj->fs->win, 0, SS(dj->fs)); /* Clear window buffer */ + dj->fs->winsect = clust2sect(dj->fs, clst); /* Cluster start sector */ + for (c = 0; c < dj->fs->csize; c++) { /* Fill the new cluster with 0 */ + dj->fs->wflag = 1; + if (move_window(dj->fs, 0)) return FR_DISK_ERR; + dj->fs->winsect++; + } + dj->fs->winsect -= c; /* Rewind window address */ +#else + return FR_NO_FILE; /* Report EOT */ +#endif + } + dj->clust = clst; /* Initialize data for new cluster */ + dj->sect = clust2sect(dj->fs, clst); + } + } + } + + dj->index = i; + dj->dir = dj->fs->win + (i % (SS(dj->fs) / 32)) * 32; + + return FR_OK; +} + + + + +/*-----------------------------------------------------------------------*/ +/* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry */ +/*-----------------------------------------------------------------------*/ +#if _USE_LFN +static +const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* Offset of LFN chars in the directory entry */ + + +static +BOOL cmp_lfn ( /* TRUE:Matched, FALSE:Not matched */ + WCHAR *lfnbuf, /* Pointer to the LFN to be compared */ + BYTE *dir /* Pointer to the directory entry containing a part of LFN */ +) +{ + int i, s; + WCHAR wc, uc; + + + i = ((dir[LDIR_Ord] & 0xBF) - 1) * 13; /* Get offset in the LFN buffer */ + s = 0; wc = 1; + do { + uc = LD_WORD(dir+LfnOfs[s]); /* Pick an LFN character from the entry */ + if (wc) { /* Last char has not been processed */ + wc = ff_wtoupper(uc); /* Convert it to upper case */ + if (i >= _MAX_LFN || wc != ff_wtoupper(lfnbuf[i++])) /* Compare it */ + return FALSE; /* Not matched */ + } else { + if (uc != 0xFFFF) return FALSE; /* Check filler */ + } + } while (++s < 13); /* Repeat until all chars in the entry are checked */ + + if ((dir[LDIR_Ord] & 0x40) && wc && lfnbuf[i]) /* Last segment matched but different length */ + return FALSE; + + return TRUE; /* The part of LFN matched */ +} + + + +static +BOOL pick_lfn ( /* TRUE:Succeeded, FALSE:Buffer overflow */ + WCHAR *lfnbuf, /* Pointer to the Unicode-LFN buffer */ + BYTE *dir /* Pointer to the directory entry */ +) +{ + int i, s; + WCHAR wc, uc; + + + i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the LFN buffer */ + + s = 0; wc = 1; + do { + uc = LD_WORD(dir+LfnOfs[s]); /* Pick an LFN character from the entry */ + if (wc) { /* Last char has not been processed */ + if (i >= _MAX_LFN) return FALSE; /* Buffer overflow? */ + lfnbuf[i++] = wc = uc; /* Store it */ + } else { + if (uc != 0xFFFF) return FALSE; /* Check filler */ + } + } while (++s < 13); /* Read all character in the entry */ + + if (dir[LDIR_Ord] & 0x40) { /* Put terminator if it is the last LFN part */ + if (i >= _MAX_LFN) return FALSE; /* Buffer overflow? */ + lfnbuf[i] = 0; + } + + return TRUE; +} + + +#if !_FS_READONLY +static +void fit_lfn ( + const WCHAR *lfnbuf, /* Pointer to the LFN buffer */ + BYTE *dir, /* Pointer to the directory entry */ + BYTE ord, /* LFN order (1-20) */ + BYTE sum /* SFN sum */ +) +{ + int i, s; + WCHAR wc; + + + dir[LDIR_Chksum] = sum; /* Set check sum */ + dir[LDIR_Attr] = AM_LFN; /* Set attribute. LFN entry */ + dir[LDIR_Type] = 0; + ST_WORD(dir+LDIR_FstClusLO, 0); + + i = (ord - 1) * 13; /* Get offset in the LFN buffer */ + s = wc = 0; + do { + if (wc != 0xFFFF) wc = lfnbuf[i++]; /* Get an effective char */ + ST_WORD(dir+LfnOfs[s], wc); /* Put it */ + if (!wc) wc = 0xFFFF; /* Padding chars following last char */ + } while (++s < 13); + if (wc == 0xFFFF || !lfnbuf[i]) ord |= 0x40; /* Bottom LFN part is the start of LFN sequence */ + dir[LDIR_Ord] = ord; /* Set the LFN order */ +} + +#endif +#endif + + + +/*-----------------------------------------------------------------------*/ +/* Create numbered name */ +/*-----------------------------------------------------------------------*/ +#if _USE_LFN +void gen_numname ( + BYTE *dst, /* Pointer to genartated SFN */ + const BYTE *src, /* Pointer to source SFN to be modified */ + const WCHAR *lfn, /* Pointer to LFN */ + WORD num /* Sequense number */ +) +{ + char ns[8]; + int i, j; + + + mem_cpy(dst, src, 11); + + if (num > 5) { /* On many collisions, generate a hash number instead of sequencial number */ + do num = (num >> 1) + (num << 15) + (WORD)*lfn++; while (*lfn); + } + + /* itoa */ + i = 7; + do { + ns[i--] = (num % 10) + '0'; + num /= 10; + } while (num); + ns[i] = '~'; + + /* Append the number */ + for (j = 0; j < i && dst[j] != ' '; j++) { + if (IsDBCS1(dst[j])) { + if (j == i - 1) break; + j++; + } + } + do { + dst[j++] = (i < 8) ? ns[i++] : ' '; + } while (j < 8); +} +#endif + + + + +/*-----------------------------------------------------------------------*/ +/* Calculate sum of an SFN */ +/*-----------------------------------------------------------------------*/ +#if _USE_LFN +static +BYTE sum_sfn ( + const BYTE *dir /* Ptr to directory entry */ +) +{ + BYTE sum = 0; + int n = 11; + + do sum = (sum >> 1) + (sum << 7) + *dir++; while (--n); + return sum; +} +#endif + + + + +/*-----------------------------------------------------------------------*/ +/* Directory handling - Find an object in the directory */ +/*-----------------------------------------------------------------------*/ + +static +FRESULT dir_find ( + DIR *dj /* Pointer to the directory object linked to the file name */ +) +{ + FRESULT res; + BYTE c, *dir; +#if _USE_LFN + BYTE a, ord, sum; +#endif + + res = dir_seek(dj, 0); /* Rewind directory object */ + if (res != FR_OK) return res; + +#if _USE_LFN + ord = sum = 0xFF; +#endif + do { + res = move_window(dj->fs, dj->sect); + if (res != FR_OK) break; + dir = dj->dir; /* Ptr to the directory entry of current index */ + c = dir[DIR_Name]; + if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ +#if _USE_LFN /* LFN configuration */ + a = dir[DIR_Attr] & AM_MASK; + if (c == 0xE5 || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ + ord = 0xFF; + } else { + if (a == AM_LFN) { /* An LFN entry is found */ + if (dj->lfn) { + if (c & 0x40) { /* Is it start of LFN sequence? */ + sum = dir[LDIR_Chksum]; + c &= 0xBF; ord = c; /* LFN start order */ + dj->lfn_idx = dj->index; + } + /* Check validity of the LFN entry and compare it with given name */ + ord = (c == ord && sum == dir[LDIR_Chksum] && cmp_lfn(dj->lfn, dir)) ? ord - 1 : 0xFF; + } + } else { /* An SFN entry is found */ + if (!ord && sum == sum_sfn(dir)) break; /* LFN matched? */ + ord = 0xFF; dj->lfn_idx = 0xFFFF; /* Reset LFN sequence */ + if (!(dj->fn[NS] & NS_LOSS) && !mem_cmp(dir, dj->fn, 11)) break; /* SFN matched? */ + } + } +#else /* Non LFN configuration */ + if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dj->fn, 11)) /* Is it a valid entry? */ + break; +#endif + res = dir_next(dj, FALSE); /* Next entry */ + } while (res == FR_OK); + + return res; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Read an object from the directory */ +/*-----------------------------------------------------------------------*/ +#if _FS_MINIMIZE <= 1 +static +FRESULT dir_read ( + DIR *dj /* Pointer to the directory object that pointing the entry to be read */ +) +{ + FRESULT res; + BYTE c, *dir; +#if _USE_LFN + BYTE a, ord = 0xFF, sum = 0xFF; +#endif + + res = FR_NO_FILE; + while (dj->sect) { + res = move_window(dj->fs, dj->sect); + if (res != FR_OK) break; + dir = dj->dir; /* Ptr to the directory entry of current index */ + c = dir[DIR_Name]; + if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ +#if _USE_LFN /* LFN configuration */ + a = dir[DIR_Attr] & AM_MASK; + if (c == 0xE5 || (!_FS_RPATH && c == '.') || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ + ord = 0xFF; + } else { + if (a == AM_LFN) { /* An LFN entry is found */ + if (c & 0x40) { /* Is it start of LFN sequence? */ + sum = dir[LDIR_Chksum]; + c &= 0xBF; ord = c; + dj->lfn_idx = dj->index; + } + /* Check LFN validity and capture it */ + ord = (c == ord && sum == dir[LDIR_Chksum] && pick_lfn(dj->lfn, dir)) ? ord - 1 : 0xFF; + } else { /* An SFN entry is found */ + if (ord || sum != sum_sfn(dir)) /* Is there a valid LFN? */ + dj->lfn_idx = 0xFFFF; /* It has no LFN. */ + break; + } + } +#else /* Non LFN configuration */ + if (c != 0xE5 && (_FS_RPATH || c != '.') && !(dir[DIR_Attr] & AM_VOL)) /* Is it a valid entry? */ + break; +#endif + res = dir_next(dj, FALSE); /* Next entry */ + if (res != FR_OK) break; + } + + if (res != FR_OK) dj->sect = 0; + + return res; +} +#endif + + + +/*-----------------------------------------------------------------------*/ +/* Register an object to the directory */ +/*-----------------------------------------------------------------------*/ +#if !_FS_READONLY +static +FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many SFN collision, FR_DISK_ERR:Disk error */ + DIR *dj /* Target directory with object name to be created */ +) +{ + FRESULT res; + BYTE c, *dir; +#if _USE_LFN /* LFN configuration */ + WORD n, ne, is; + BYTE sn[12], *fn, sum; + WCHAR *lfn; + + + fn = dj->fn; lfn = dj->lfn; + mem_cpy(sn, fn, 12); + + if (_FS_RPATH && (sn[NS] & NS_DOT)) return FR_INVALID_NAME; /* Cannot create dot entry */ + + if (sn[NS] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */ + fn[NS] = 0; dj->lfn = NULL; /* Find only SFN */ + for (n = 1; n < 100; n++) { + gen_numname(fn, sn, lfn, n); /* Generate a numbered name */ + res = dir_find(dj); /* Check if the name collides with existing SFN */ + if (res != FR_OK) break; + } + if (n == 100) return FR_DENIED; /* Abort if too many collisions */ + if (res != FR_NO_FILE) return res; /* Abort if the result is other than 'not collided' */ + fn[NS] = sn[NS]; dj->lfn = lfn; + } + + if (sn[NS] & NS_LFN) { /* When LFN is to be created, reserve reserve an SFN + LFN entries. */ + for (ne = 0; lfn[ne]; ne++) ; + ne = (ne + 25) / 13; + } else { /* Otherwise reserve only an SFN entry. */ + ne = 1; + } + + /* Reserve contiguous entries */ + res = dir_seek(dj, 0); + if (res != FR_OK) return res; + n = is = 0; + do { + res = move_window(dj->fs, dj->sect); + if (res != FR_OK) break; + c = *dj->dir; /* Check the entry status */ + if (c == 0xE5 || c == 0) { /* Is it a blank entry? */ + if (n == 0) is = dj->index; /* First index of the contigulus entry */ + if (++n == ne) break; /* A contiguous entry that requiered count is found */ + } else { + n = 0; /* Not a blank entry. Restart to search */ + } + res = dir_next(dj, TRUE); /* Next entry with table streach */ + } while (res == FR_OK); + + if (res == FR_OK && ne > 1) { /* Initialize LFN entry if needed */ + res = dir_seek(dj, is); + if (res == FR_OK) { + sum = sum_sfn(dj->fn); /* Sum of the SFN tied to the LFN */ + ne--; + do { /* Store LFN entries in bottom first */ + res = move_window(dj->fs, dj->sect); + if (res != FR_OK) break; + fit_lfn(dj->lfn, dj->dir, (BYTE)ne, sum); + dj->fs->wflag = 1; + res = dir_next(dj, FALSE); /* Next entry */ + } while (res == FR_OK && --ne); + } + } + +#else /* Non LFN configuration */ + res = dir_seek(dj, 0); + if (res == FR_OK) { + do { /* Find a blank entry for the SFN */ + res = move_window(dj->fs, dj->sect); + if (res != FR_OK) break; + c = *dj->dir; + if (c == 0xE5 || c == 0) break; /* Is it a blank entry? */ + res = dir_next(dj, TRUE); /* Next entry with table streach */ + } while (res == FR_OK); + } +#endif + + if (res == FR_OK) { /* Initialize the SFN entry */ + res = move_window(dj->fs, dj->sect); + if (res == FR_OK) { + dir = dj->dir; + mem_set(dir, 0, 32); /* Clean the entry */ + mem_cpy(dir, dj->fn, 11); /* Put SFN */ + dir[DIR_NTres] = *(dj->fn+NS) & (NS_BODY | NS_EXT); /* Put NT flag */ + dj->fs->wflag = 1; + } + } + + return res; +} +#endif /* !_FS_READONLY */ + + + + +/*-----------------------------------------------------------------------*/ +/* Remove an object from the directory */ +/*-----------------------------------------------------------------------*/ +#if !_FS_READONLY && !_FS_MINIMIZE +static +FRESULT dir_remove ( /* FR_OK: Successful, FR_DISK_ERR: A disk error */ + DIR *dj /* Directory object pointing the entry to be removed */ +) +{ + FRESULT res; +#if _USE_LFN /* LFN configuration */ + WORD i; + + i = dj->index; /* SFN index */ + res = dir_seek(dj, (WORD)((dj->lfn_idx == 0xFFFF) ? i : dj->lfn_idx)); /* Goto the SFN or top of the LFN entries */ + if (res == FR_OK) { + do { + res = move_window(dj->fs, dj->sect); + if (res != FR_OK) break; + *dj->dir = 0xE5; /* Mark the entry "deleted" */ + dj->fs->wflag = 1; + if (dj->index >= i) break; /* When reached SFN, all entries of the object has been deleted. */ + res = dir_next(dj, FALSE); /* Next entry */ + } while (res == FR_OK); + if (res == FR_NO_FILE) res = FR_INT_ERR; + } + +#else /* Non LFN configuration */ + res = dir_seek(dj, dj->index); + if (res == FR_OK) { + res = move_window(dj->fs, dj->sect); + if (res == FR_OK) { + *dj->dir = 0xE5; /* Mark the entry "deleted" */ + dj->fs->wflag = 1; + } + } +#endif + + return res; +} +#endif /* !_FS_READONLY */ + + + + +/*-----------------------------------------------------------------------*/ +/* Pick a segment and create the object name in directory form */ +/*-----------------------------------------------------------------------*/ + +static +FRESULT create_name ( + DIR *dj, /* Pointer to the directory object */ + const XCHAR **path /* Pointer to pointer to the segment in the path string */ +) +{ +#ifdef _EXCVT + static const BYTE cvt[] = _EXCVT; +#endif + +#if _USE_LFN /* LFN configuration */ + BYTE b, cf; + WCHAR w, *lfn; + int i, ni, si, di; + const XCHAR *p; + + /* Create LFN in Unicode */ + si = di = 0; + p = *path; + lfn = dj->lfn; + for (;;) { + w = p[si++]; /* Get a character */ + if (w < ' ' || w == '/' || w == '\\') break; /* Break on end of segment */ + if (di >= _MAX_LFN) /* Reject too long name */ + return FR_INVALID_NAME; +#if !_LFN_UNICODE + w &= 0xFF; + if (IsDBCS1(w)) { /* If it is a DBC 1st byte */ + b = p[si++]; /* Get 2nd byte */ + if (!IsDBCS2(b)) /* Reject invalid code for DBC */ + return FR_INVALID_NAME; + w = (w << 8) + b; + } + w = ff_convert(w, 1); /* Convert OEM to Unicode */ + if (!w) return FR_INVALID_NAME; /* Reject invalid code */ +#endif + if (w < 0x80 && chk_chr("\"*:<>\?|\x7F", w)) /* Reject illegal chars for LFN */ + return FR_INVALID_NAME; + lfn[di++] = w; /* Store the Unicode char */ + } + *path = &p[si]; /* Rerurn pointer to the next segment */ + cf = (w < ' ') ? NS_LAST : 0; /* Set last segment flag if end of path */ +#if _FS_RPATH + if ((di == 1 && lfn[di - 1] == '.') || /* Is this a dot entry? */ + (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { + lfn[di] = 0; + for (i = 0; i < 11; i++) + dj->fn[i] = (i < di) ? '.' : ' '; + dj->fn[i] = cf | NS_DOT; /* This is a dot entry */ + return FR_OK; + } +#endif + while (di) { /* Strip trailing spaces and dots */ + w = lfn[di - 1]; + if (w != ' ' && w != '.') break; + di--; + } + if (!di) return FR_INVALID_NAME; /* Reject null string */ + + lfn[di] = 0; /* LFN is created */ + + /* Create SFN in directory form */ + mem_set(dj->fn, ' ', 11); + for (si = 0; lfn[si] == ' ' || lfn[si] == '.'; si++) ; /* Strip leading spaces and dots */ + if (si) cf |= NS_LOSS | NS_LFN; + while (di && lfn[di - 1] != '.') di--; /* Find extension (di<=si: no extension) */ + + b = i = 0; ni = 8; + for (;;) { + w = lfn[si++]; /* Get an LFN char */ + if (!w) break; /* Break on enf of the LFN */ + if (w == ' ' || (w == '.' && si != di)) { /* Remove spaces and dots */ + cf |= NS_LOSS | NS_LFN; continue; + } + + if (i >= ni || si == di) { /* Extension or end of SFN */ + if (ni == 11) { /* Long extension */ + cf |= NS_LOSS | NS_LFN; break; + } + if (si != di) cf |= NS_LOSS | NS_LFN; /* Out of 8.3 format */ + if (si > di) break; /* No extension */ + si = di; i = 8; ni = 11; /* Enter extension section */ + b <<= 2; continue; + } + + if (w >= 0x80) { /* Non ASCII char */ +#ifdef _EXCVT + w = ff_convert(w, 0); /* Unicode -> OEM code */ + if (w) w = cvt[w - 0x80]; /* Convert extended char to upper (SBCS) */ +#else + w = ff_convert(ff_wtoupper(w), 0); /* Upper converted Unicode -> OEM code */ +#endif + cf |= NS_LFN; /* Force create LFN entry */ + } + + if (_DF1S && w >= 0x100) { /* Double byte char */ + if (i >= ni - 1) { + cf |= NS_LOSS | NS_LFN; i = ni; continue; + } + dj->fn[i++] = (BYTE)(w >> 8); + } else { /* Single byte char */ + if (!w || chk_chr("+,;[=]", w)) { /* Replace illegal chars for SFN */ + w = '_'; cf |= NS_LOSS | NS_LFN; /* Lossy conversion */ + } else { + if (IsUpper(w)) { /* ASCII large capital */ + b |= 2; + } else { + if (IsLower(w)) { /* ASCII small capital */ + b |= 1; w -= 0x20; + } + } + } + } + dj->fn[i++] = (BYTE)w; + } + + if (dj->fn[0] == 0xE5) dj->fn[0] = 0x05; /* If the first char collides with deleted mark, replace it with 0x05 */ + + if (ni == 8) b <<= 2; + if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03) /* Create LFN entry when there are composite capitals */ + cf |= NS_LFN; + if (!(cf & NS_LFN)) { /* When LFN is in 8.3 format without extended char, NT flags are created */ + if ((b & 0x03) == 0x01) cf |= NS_EXT; /* NT flag (Extension has only small capital) */ + if ((b & 0x0C) == 0x04) cf |= NS_BODY; /* NT flag (Filename has only small capital) */ + } + + dj->fn[NS] = cf; /* SFN is created */ + + return FR_OK; + + +#else /* Non-LFN configuration */ + BYTE b, c, d, *sfn; + int ni, si, i; + const char *p; + + /* Create file name in directory form */ + sfn = dj->fn; + mem_set(sfn, ' ', 11); + si = i = b = 0; ni = 8; + p = *path; +#if _FS_RPATH + if (p[si] == '.') { /* Is this a dot entry? */ + for (;;) { + c = p[si++]; + if (c != '.' || si >= 3) break; + sfn[i++] = c; + } + if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME; + *path = &p[si]; /* Rerurn pointer to the next segment */ + sfn[NS] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of path */ + return FR_OK; + } +#endif + for (;;) { + c = p[si++]; + if (c <= ' ' || c == '/' || c == '\\') break; /* Break on end of segment */ + if (c == '.' || i >= ni) { + if (ni != 8 || c != '.') return FR_INVALID_NAME; + i = 8; ni = 11; + b <<= 2; continue; + } + if (c >= 0x80) { /* Extended char */ +#ifdef _EXCVT + c = cvt[c - 0x80]; /* Convert extend char (SBCS) */ +#else + b |= 3; /* Eliminate NT flag if ext char is exist */ +#if !_DF1S /* ASCII only cfg */ + return FR_INVALID_NAME; +#endif +#endif + } + if (IsDBCS1(c)) { /* DBC 1st byte? */ + d = p[si++]; /* Get 2nd byte */ + if (!IsDBCS2(d) || i >= ni - 1) /* Reject invalid DBC */ + return FR_INVALID_NAME; + sfn[i++] = c; + sfn[i++] = d; + } else { /* Single byte code */ + if (chk_chr(" \"*+,[=]|\x7F", c)) /* Reject illegal chrs for SFN */ + return FR_INVALID_NAME; + if (IsUpper(c)) { /* ASCII large capital? */ + b |= 2; + } else { + if (IsLower(c)) { /* ASCII small capital? */ + b |= 1; c -= 0x20; + } + } + sfn[i++] = c; + } + } + *path = &p[si]; /* Rerurn pointer to the next segment */ + c = (c <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of path */ + + if (!i) return FR_INVALID_NAME; /* Reject null string */ + if (sfn[0] == 0xE5) sfn[0] = 0x05; /* When first char collides with 0xE5, replace it with 0x05 */ + + if (ni == 8) b <<= 2; + if ((b & 0x03) == 0x01) c |= NS_EXT; /* NT flag (Extension has only small capital) */ + if ((b & 0x0C) == 0x04) c |= NS_BODY; /* NT flag (Filename has only small capital) */ + + sfn[NS] = c; /* Store NT flag, File name is created */ + + return FR_OK; +#endif +} + + + + +/*-----------------------------------------------------------------------*/ +/* Get file information from directory entry */ +/*-----------------------------------------------------------------------*/ +#if _FS_MINIMIZE <= 1 +static +void get_fileinfo ( /* No return code */ + DIR *dj, /* Pointer to the directory object */ + FILINFO *fno /* Pointer to the file information to be filled */ +) +{ + int i; + BYTE c, nt, *dir; + char *p; + + + p = fno->fname; + if (dj->sect) { + dir = dj->dir; + nt = dir[DIR_NTres]; /* NT flag */ + for (i = 0; i < 8; i++) { /* Copy name body */ + c = dir[i]; + if (c == ' ') break; + if (c == 0x05) c = 0xE5; + if (_USE_LFN && (nt & NS_BODY) && IsUpper(c)) c += 0x20; + *p++ = c; + } + if (dir[8] != ' ') { /* Copy name extension */ + *p++ = '.'; + for (i = 8; i < 11; i++) { + c = dir[i]; + if (c == ' ') break; + if (_USE_LFN && (nt & NS_EXT) && IsUpper(c)) c += 0x20; + *p++ = c; + } + } + fno->fattrib = dir[DIR_Attr]; /* Attribute */ + fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */ + fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */ + fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */ + } + *p = 0; + +#if _USE_LFN + if (fno->lfname) { + XCHAR *tp = fno->lfname; + WCHAR w, *lfn; + + i = 0; + if (dj->sect && dj->lfn_idx != 0xFFFF) {/* Get LFN if available */ + lfn = dj->lfn; + while ((w = *lfn++) != 0) { /* Get an LFN char */ +#if !_LFN_UNICODE + w = ff_convert(w, 0); /* Unicode -> OEM conversion */ + if (!w) { i = 0; break; } /* Could not convert, no LFN */ + if (_DF1S && w >= 0x100) /* Put 1st byte if it is a DBC */ + tp[i++] = (XCHAR)(w >> 8); +#endif + if (i >= fno->lfsize - 1) { i = 0; break; } /* Buffer overrun, no LFN */ + tp[i++] = (XCHAR)w; + } + } + tp[i] = 0; /* Terminator */ + } +#endif +} +#endif /* _FS_MINIMIZE <= 1 */ + + + + +/*-----------------------------------------------------------------------*/ +/* Follow a file path */ +/*-----------------------------------------------------------------------*/ + +static +FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ + DIR *dj, /* Directory object to return last directory and found object */ + const XCHAR *path /* Full-path string to find a file or directory */ +) +{ + FRESULT res; + BYTE *dir, last; + + + while (!_USE_LFN && *path == ' ') path++; /* Skip leading spaces */ +#if _FS_RPATH + if (*path == '/' || *path == '\\') { /* There is a heading separator */ + path++; dj->sclust = 0; /* Strip it and start from the root dir */ + } else { /* No heading saparator */ + dj->sclust = dj->fs->cdir; /* Start from the current dir */ + } +#else + if (*path == '/' || *path == '\\') /* Strip heading separator if exist */ + path++; + dj->sclust = 0; /* Start from the root dir */ +#endif + + if ((UINT)*path < ' ') { /* Null path means the start directory itself */ + res = dir_seek(dj, 0); + dj->dir = NULL; + + } else { /* Follow path */ + for (;;) { + res = create_name(dj, &path); /* Get a segment */ + if (res != FR_OK) break; + res = dir_find(dj); /* Find it */ + last = *(dj->fn+NS) & NS_LAST; + if (res != FR_OK) { /* Could not find the object */ + if (res == FR_NO_FILE && !last) + res = FR_NO_PATH; + break; + } + if (last) break; /* Last segment match. Function completed. */ + dir = dj->dir; /* There is next segment. Follow the sub directory */ + if (!(dir[DIR_Attr] & AM_DIR)) { /* Cannot follow because it is a file */ + res = FR_NO_PATH; break; + } + dj->sclust = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO); + } + } + + return res; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Load boot record and check if it is an FAT boot record */ +/*-----------------------------------------------------------------------*/ + +static +BYTE check_fs ( /* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record, 3:Error */ + FATFS *fs, /* File system object */ + DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */ +) +{ + if (disk_read(fs->drive, fs->win, sect, 1) != RES_OK) /* Load boot record */ + return 3; + if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature (always placed at offset 510 even if the sector size is >512) */ + return 2; + + if ((LD_DWORD(&fs->win[BS_FilSysType]) & 0xFFFFFF) == 0x544146) /* Check "FAT" string */ + return 0; + if ((LD_DWORD(&fs->win[BS_FilSysType32]) & 0xFFFFFF) == 0x544146) + return 0; + + return 1; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Make sure that the file system is valid */ +/*-----------------------------------------------------------------------*/ + + +FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occured */ + const XCHAR **path, /* Pointer to pointer to the path name (drive number) */ + FATFS **rfs, /* Pointer to pointer to the found file system object */ + BYTE chk_wp /* !=0: Check media write protection for write access */ +) +{ + BYTE fmt, *tbl; + UINT vol; + DSTATUS stat; + DWORD bsect, fsize, tsect, mclst; + const XCHAR *p = *path; + FATFS *fs; + + /* Get logical drive number from the path name */ + vol = p[0] - '0'; /* Is there a drive number? */ + if (vol <= 9 && p[1] == ':') { /* Found a drive number, get and strip it */ + p += 2; *path = p; /* Return pointer to the path name */ + } else { /* No drive number is given */ +#if _FS_RPATH + vol = Drive; /* Use current drive */ +#else + vol = 0; /* Use drive 0 */ +#endif + } + + /* Check if the logical drive is valid or not */ + if (vol >= _DRIVES) /* Is the drive number valid? */ + return FR_INVALID_DRIVE; + *rfs = fs = FatFs[vol]; /* Returen pointer to the corresponding file system object */ + if (!fs) return FR_NOT_ENABLED; /* Is the file system object available? */ + + ENTER_FF(fs); /* Lock file system */ + + if (fs->fs_type) { /* If the logical drive has been mounted */ + stat = disk_status(fs->drive); + if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized (has not been changed), */ +#if !_FS_READONLY + if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */ + return FR_WRITE_PROTECTED; +#endif + return FR_OK; /* The file system object is valid */ + } + } + + /* The logical drive must be mounted. Following code attempts to mount the volume */ + + fs->fs_type = 0; /* Clear the file system object */ + fs->drive = (BYTE)LD2PD(vol); /* Bind the logical drive and a physical drive */ + stat = disk_initialize(fs->drive); /* Initialize low level disk I/O layer */ + if (stat & STA_NOINIT) /* Check if the drive is ready */ + return FR_NOT_READY; +#if _MAX_SS != 512 /* Get disk sector size if needed */ + if (disk_ioctl(fs->drive, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS) + return FR_NO_FILESYSTEM; +#endif +#if !_FS_READONLY + if (chk_wp && (stat & STA_PROTECT)) /* Check disk write protection if needed */ + return FR_WRITE_PROTECTED; +#endif + /* Search FAT partition on the drive */ + fmt = check_fs(fs, bsect = 0); /* Check sector 0 as an SFD format */ + if (fmt == 1) { /* Not an FAT boot record, it may be patitioned */ + /* Check a partition listed in top of the partition table */ + tbl = &fs->win[MBR_Table + LD2PT(vol) * 16]; /* Partition table */ + if (tbl[4]) { /* Is the partition existing? */ + bsect = LD_DWORD(&tbl[8]); /* Partition offset in LBA */ + fmt = check_fs(fs, bsect); /* Check the partition */ + } + } + if (fmt == 3) return FR_DISK_ERR; + if (fmt || LD_WORD(fs->win+BPB_BytsPerSec) != SS(fs)) /* No valid FAT patition is found */ + return FR_NO_FILESYSTEM; + + /* Initialize the file system object */ + fsize = LD_WORD(fs->win+BPB_FATSz16); /* Number of sectors per FAT */ + if (!fsize) fsize = LD_DWORD(fs->win+BPB_FATSz32); + fs->sects_fat = fsize; + fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FAT copies */ + fsize *= fs->n_fats; /* (Number of sectors in FAT area) */ + fs->fatbase = bsect + LD_WORD(fs->win+BPB_RsvdSecCnt); /* FAT start sector (lba) */ + fs->csize = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */ + fs->n_rootdir = LD_WORD(fs->win+BPB_RootEntCnt); /* Nmuber of root directory entries */ + tsect = LD_WORD(fs->win+BPB_TotSec16); /* Number of sectors on the volume */ + if (!tsect) tsect = LD_DWORD(fs->win+BPB_TotSec32); + fs->max_clust = mclst = (tsect /* Last cluster# + 1 (Number of clusters + 2) */ + - LD_WORD(fs->win+BPB_RsvdSecCnt) - fsize - fs->n_rootdir / (SS(fs)/32) + ) / fs->csize + 2; + + fmt = FS_FAT12; /* Determine the FAT sub type */ + if (mclst >= 0xFF7) fmt = FS_FAT16; /* Number of clusters >= 0xFF5 */ + if (mclst >= 0xFFF7) fmt = FS_FAT32; /* Number of clusters >= 0xFFF5 */ + + if (fmt == FS_FAT32) + fs->dirbase = LD_DWORD(fs->win+BPB_RootClus); /* Root directory start cluster */ + else + fs->dirbase = fs->fatbase + fsize; /* Root directory start sector (lba) */ + fs->database = fs->fatbase + fsize + fs->n_rootdir / (SS(fs)/32); /* Data start sector (lba) */ + +#if !_FS_READONLY + /* Initialize allocation information */ + fs->free_clust = 0xFFFFFFFF; + fs->wflag = 0; + /* Get fsinfo if needed */ + if (fmt == FS_FAT32) { + fs->fsi_flag = 0; + fs->fsi_sector = bsect + LD_WORD(fs->win+BPB_FSInfo); + if (disk_read(fs->drive, fs->win, fs->fsi_sector, 1) == RES_OK && + LD_WORD(fs->win+BS_55AA) == 0xAA55 && + LD_DWORD(fs->win+FSI_LeadSig) == 0x41615252 && + LD_DWORD(fs->win+FSI_StrucSig) == 0x61417272) { + fs->last_clust = LD_DWORD(fs->win+FSI_Nxt_Free); + fs->free_clust = LD_DWORD(fs->win+FSI_Free_Count); + } + } +#endif + fs->fs_type = fmt; /* FAT sub-type */ + fs->winsect = 0; /* Invalidate sector cache */ +#if _FS_RPATH + fs->cdir = 0; /* Current directory (root dir) */ +#endif + fs->id = ++Fsid; /* File system mount ID */ + + return FR_OK; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Check if the file/dir object is valid or not */ +/*-----------------------------------------------------------------------*/ + +static +FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */ + FATFS *fs, /* Pointer to the file system object */ + WORD id /* Member id of the target object to be checked */ +) +{ + if (!fs || !fs->fs_type || fs->id != id) + return FR_INVALID_OBJECT; + + ENTER_FF(fs); /* Lock file system */ + + if (disk_status(fs->drive) & STA_NOINIT) + return FR_NOT_READY; + + return FR_OK; +} + + + + +/*-------------------------------------------------------------------------- + + Public Functions + +--------------------------------------------------------------------------*/ + + + +/*-----------------------------------------------------------------------*/ +/* Mount/Unmount a Locical Drive */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_mount ( + BYTE vol, /* Logical drive number to be mounted/unmounted */ + FATFS *fs /* Pointer to new file system object (NULL for unmount)*/ +) +{ + FATFS *rfs; + + + if (vol >= _DRIVES) /* Check if the drive number is valid */ + return FR_INVALID_DRIVE; + rfs = FatFs[vol]; /* Get current fs object */ + + if (rfs) { +#if _FS_REENTRANT /* Discard sync object of the current volume */ + if (!ff_del_syncobj(rfs->sobj)) return FR_INT_ERR; +#endif + rfs->fs_type = 0; /* Clear old fs object */ + } + + if (fs) { + fs->fs_type = 0; /* Clear new fs object */ +#if _FS_REENTRANT /* Create sync object for the new volume */ + if (!ff_cre_syncobj(vol, &fs->sobj)) return FR_INT_ERR; +#endif + } + FatFs[vol] = fs; /* Register new fs object */ + + return FR_OK; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Open or Create a File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_open ( + FIL *fp, /* Pointer to the blank file object */ + const XCHAR *path, /* Pointer to the file name */ + BYTE mode /* Access mode and file open mode flags */ +) +{ + FRESULT res; + DIR dj; + NAMEBUF(sfn, lfn); + BYTE *dir; + + + fp->fs = NULL; /* Clear file object */ +#if !_FS_READONLY + mode &= (FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW); + res = chk_mounted(&path, &dj.fs, (BYTE)(mode & (FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW))); +#else + mode &= FA_READ; + res = chk_mounted(&path, &dj.fs, 0); +#endif + if (res != FR_OK) LEAVE_FF(dj.fs, res); + INITBUF(dj, sfn, lfn); + res = follow_path(&dj, path); /* Follow the file path */ + +#if !_FS_READONLY + /* Create or Open a file */ + if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) { + DWORD ps, cl; + + if (res != FR_OK) { /* No file, create new */ + if (res == FR_NO_FILE) /* There is no file to open, create a new entry */ + res = dir_register(&dj); + if (res != FR_OK) LEAVE_FF(dj.fs, res); + mode |= FA_CREATE_ALWAYS; + dir = dj.dir; /* Created entry (SFN entry) */ + } + else { /* Any object is already existing */ + if (mode & FA_CREATE_NEW) /* Cannot create new */ + LEAVE_FF(dj.fs, FR_EXIST); + dir = dj.dir; + if (!dir || (dir[DIR_Attr] & (AM_RDO | AM_DIR))) /* Cannot overwrite it (R/O or DIR) */ + LEAVE_FF(dj.fs, FR_DENIED); + if (mode & FA_CREATE_ALWAYS) { /* Resize it to zero on over write mode */ + cl = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO); /* Get start cluster */ + ST_WORD(dir+DIR_FstClusHI, 0); /* cluster = 0 */ + ST_WORD(dir+DIR_FstClusLO, 0); + ST_DWORD(dir+DIR_FileSize, 0); /* size = 0 */ + dj.fs->wflag = 1; + ps = dj.fs->winsect; /* Remove the cluster chain */ + if (cl) { + res = remove_chain(dj.fs, cl); + if (res) LEAVE_FF(dj.fs, res); + dj.fs->last_clust = cl - 1; /* Reuse the cluster hole */ + } + res = move_window(dj.fs, ps); + if (res != FR_OK) LEAVE_FF(dj.fs, res); + } + } + if (mode & FA_CREATE_ALWAYS) { + dir[DIR_Attr] = 0; /* Reset attribute */ + ps = get_fattime(); + ST_DWORD(dir+DIR_CrtTime, ps); /* Created time */ + dj.fs->wflag = 1; + mode |= FA__WRITTEN; /* Set file changed flag */ + } + } + /* Open an existing file */ + else { +#endif /* !_FS_READONLY */ + if (res != FR_OK) LEAVE_FF(dj.fs, res); /* Follow failed */ + dir = dj.dir; + if (!dir || (dir[DIR_Attr] & AM_DIR)) /* It is a directory */ + LEAVE_FF(dj.fs, FR_NO_FILE); +#if !_FS_READONLY + if ((mode & FA_WRITE) && (dir[DIR_Attr] & AM_RDO)) /* R/O violation */ + LEAVE_FF(dj.fs, FR_DENIED); + } + fp->dir_sect = dj.fs->winsect; /* Pointer to the directory entry */ + fp->dir_ptr = dj.dir; +#endif + fp->flag = mode; /* File access mode */ + fp->org_clust = /* File start cluster */ + ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO); + fp->fsize = LD_DWORD(dir+DIR_FileSize); /* File size */ + fp->fptr = 0; fp->csect = 255; /* File pointer */ + fp->dsect = 0; + fp->fs = dj.fs; fp->id = dj.fs->id; /* Owner file system object of the file */ + + LEAVE_FF(dj.fs, FR_OK); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Read File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_read ( + FIL *fp, /* Pointer to the file object */ + void *buff, /* Pointer to data buffer */ + UINT btr, /* Number of bytes to read */ + UINT *br /* Pointer to number of bytes read */ +) +{ + FRESULT res; + DWORD clst, sect, remain; + UINT rcnt, cc; + BYTE *rbuff = buff; + + + *br = 0; /* Initialize bytes read */ + + res = validate(fp->fs, fp->id); /* Check validity of the object */ + if (res != FR_OK) LEAVE_FF(fp->fs, res); + if (fp->flag & FA__ERROR) /* Check abort flag */ + LEAVE_FF(fp->fs, FR_INT_ERR); + if (!(fp->flag & FA_READ)) /* Check access mode */ + LEAVE_FF(fp->fs, FR_DENIED); + remain = fp->fsize - fp->fptr; + if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ + + for ( ; btr; /* Repeat until all data transferred */ + rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) { + if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ + if (fp->csect >= fp->fs->csize) { /* On the cluster boundary? */ + clst = (fp->fptr == 0) ? /* On the top of the file? */ + fp->org_clust : get_fat(fp->fs, fp->curr_clust); + if (clst <= 1) ABORT(fp->fs, FR_INT_ERR); + if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); + fp->curr_clust = clst; /* Update current cluster */ + fp->csect = 0; /* Reset sector offset in the cluster */ + } + sect = clust2sect(fp->fs, fp->curr_clust); /* Get current sector */ + if (!sect) ABORT(fp->fs, FR_INT_ERR); + sect += fp->csect; + cc = btr / SS(fp->fs); /* When remaining bytes >= sector size, */ + if (cc) { /* Read maximum contiguous sectors directly */ + if (fp->csect + cc > fp->fs->csize) /* Clip at cluster boundary */ + cc = fp->fs->csize - fp->csect; + if (disk_read(fp->fs->drive, rbuff, sect, (BYTE)cc) != RES_OK) + ABORT(fp->fs, FR_DISK_ERR); +#if !_FS_READONLY && _FS_MINIMIZE <= 2 +#if _FS_TINY + if (fp->fs->wflag && fp->fs->winsect - sect < cc) /* Replace one of the read sectors with cached data if it contains a dirty sector */ + mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs)); +#else + if ((fp->flag & FA__DIRTY) && fp->dsect - sect < cc) /* Replace one of the read sectors with cached data if it contains a dirty sector */ + mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs)); +#endif +#endif + fp->csect += (BYTE)cc; /* Next sector address in the cluster */ + rcnt = SS(fp->fs) * cc; /* Number of bytes transferred */ + continue; + } +#if !_FS_TINY +#if !_FS_READONLY + if (fp->flag & FA__DIRTY) { /* Write sector I/O buffer if needed */ + if (disk_write(fp->fs->drive, fp->buf, fp->dsect, 1) != RES_OK) + ABORT(fp->fs, FR_DISK_ERR); + fp->flag &= ~FA__DIRTY; + } +#endif + if (fp->dsect != sect) { /* Fill sector buffer with file data */ + if (disk_read(fp->fs->drive, fp->buf, sect, 1) != RES_OK) + ABORT(fp->fs, FR_DISK_ERR); + } +#endif + fp->dsect = sect; + fp->csect++; /* Next sector address in the cluster */ + } + rcnt = SS(fp->fs) - (fp->fptr % SS(fp->fs)); /* Get partial sector data from sector buffer */ + if (rcnt > btr) rcnt = btr; +#if _FS_TINY + if (move_window(fp->fs, fp->dsect)) /* Move sector window */ + ABORT(fp->fs, FR_DISK_ERR); + mem_cpy(rbuff, &fp->fs->win[fp->fptr % SS(fp->fs)], rcnt); /* Pick partial sector */ +#else + mem_cpy(rbuff, &fp->buf[fp->fptr % SS(fp->fs)], rcnt); /* Pick partial sector */ +#endif + } + + LEAVE_FF(fp->fs, FR_OK); +} + + + + +#if !_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Write File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_write ( + FIL *fp, /* Pointer to the file object */ + const void *buff, /* Pointer to the data to be written */ + UINT btw, /* Number of bytes to write */ + UINT *bw /* Pointer to number of bytes written */ +) +{ + FRESULT res; + DWORD clst, sect; + UINT wcnt, cc; + const BYTE *wbuff = buff; + + + *bw = 0; /* Initialize bytes written */ + + res = validate(fp->fs, fp->id); /* Check validity of the object */ + if (res != FR_OK) LEAVE_FF(fp->fs, res); + if (fp->flag & FA__ERROR) /* Check abort flag */ + LEAVE_FF(fp->fs, FR_INT_ERR); + if (!(fp->flag & FA_WRITE)) /* Check access mode */ + LEAVE_FF(fp->fs, FR_DENIED); + if (fp->fsize + btw < fp->fsize) btw = 0; /* File size cannot reach 4GB */ + + for ( ; btw; /* Repeat until all data transferred */ + wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) { + if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ + if (fp->csect >= fp->fs->csize) { /* On the cluster boundary? */ + if (fp->fptr == 0) { /* On the top of the file? */ + clst = fp->org_clust; /* Follow from the origin */ + if (clst == 0) /* When there is no cluster chain, */ + fp->org_clust = clst = create_chain(fp->fs, 0); /* Create a new cluster chain */ + } else { /* Middle or end of the file */ + clst = create_chain(fp->fs, fp->curr_clust); /* Follow or streach cluster chain */ + } + if (clst == 0) break; /* Could not allocate a new cluster (disk full) */ + if (clst == 1) ABORT(fp->fs, FR_INT_ERR); + if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); + fp->curr_clust = clst; /* Update current cluster */ + fp->csect = 0; /* Reset sector address in the cluster */ + } +#if _FS_TINY + if (fp->fs->winsect == fp->dsect && move_window(fp->fs, 0)) /* Write back data buffer prior to following direct transfer */ + ABORT(fp->fs, FR_DISK_ERR); +#else + if (fp->flag & FA__DIRTY) { /* Write back data buffer prior to following direct transfer */ + if (disk_write(fp->fs->drive, fp->buf, fp->dsect, 1) != RES_OK) + ABORT(fp->fs, FR_DISK_ERR); + fp->flag &= ~FA__DIRTY; + } +#endif + sect = clust2sect(fp->fs, fp->curr_clust); /* Get current sector */ + if (!sect) ABORT(fp->fs, FR_INT_ERR); + sect += fp->csect; + cc = btw / SS(fp->fs); /* When remaining bytes >= sector size, */ + if (cc) { /* Write maximum contiguous sectors directly */ + if (fp->csect + cc > fp->fs->csize) /* Clip at cluster boundary */ + cc = fp->fs->csize - fp->csect; + if (disk_write(fp->fs->drive, wbuff, sect, (BYTE)cc) != RES_OK) + ABORT(fp->fs, FR_DISK_ERR); +#if _FS_TINY + if (fp->fs->winsect - sect < cc) { /* Refill sector cache if it gets dirty by the direct write */ + mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs)); + fp->fs->wflag = 0; + } +#else + if (fp->dsect - sect < cc) { /* Refill sector cache if it gets dirty by the direct write */ + mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs)); + fp->flag &= ~FA__DIRTY; + } +#endif + fp->csect += (BYTE)cc; /* Next sector address in the cluster */ + wcnt = SS(fp->fs) * cc; /* Number of bytes transferred */ + continue; + } +#if _FS_TINY + if (fp->fptr >= fp->fsize) { /* Avoid silly buffer filling at growing edge */ + if (move_window(fp->fs, 0)) ABORT(fp->fs, FR_DISK_ERR); + fp->fs->winsect = sect; + } +#else + if (fp->dsect != sect) { /* Fill sector buffer with file data */ + if (fp->fptr < fp->fsize && + disk_read(fp->fs->drive, fp->buf, sect, 1) != RES_OK) + ABORT(fp->fs, FR_DISK_ERR); + } +#endif + fp->dsect = sect; + fp->csect++; /* Next sector address in the cluster */ + } + wcnt = SS(fp->fs) - (fp->fptr % SS(fp->fs)); /* Put partial sector into file I/O buffer */ + if (wcnt > btw) wcnt = btw; +#if _FS_TINY + if (move_window(fp->fs, fp->dsect)) /* Move sector window */ + ABORT(fp->fs, FR_DISK_ERR); + mem_cpy(&fp->fs->win[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */ + fp->fs->wflag = 1; +#else + mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */ + fp->flag |= FA__DIRTY; +#endif + } + + if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */ + fp->flag |= FA__WRITTEN; /* Set file changed flag */ + + LEAVE_FF(fp->fs, FR_OK); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Synchronize the File Object */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_sync ( + FIL *fp /* Pointer to the file object */ +) +{ + FRESULT res; + DWORD tim; + BYTE *dir; + + + res = validate(fp->fs, fp->id); /* Check validity of the object */ + if (res == FR_OK) { + if (fp->flag & FA__WRITTEN) { /* Has the file been written? */ +#if !_FS_TINY /* Write-back dirty buffer */ + if (fp->flag & FA__DIRTY) { + if (disk_write(fp->fs->drive, fp->buf, fp->dsect, 1) != RES_OK) + LEAVE_FF(fp->fs, FR_DISK_ERR); + fp->flag &= ~FA__DIRTY; + } +#endif + /* Update the directory entry */ + res = move_window(fp->fs, fp->dir_sect); + if (res == FR_OK) { + dir = fp->dir_ptr; + dir[DIR_Attr] |= AM_ARC; /* Set archive bit */ + ST_DWORD(dir+DIR_FileSize, fp->fsize); /* Update file size */ + ST_WORD(dir+DIR_FstClusLO, fp->org_clust); /* Update start cluster */ + ST_WORD(dir+DIR_FstClusHI, fp->org_clust >> 16); + tim = get_fattime(); /* Updated time */ + ST_DWORD(dir+DIR_WrtTime, tim); + fp->flag &= ~FA__WRITTEN; + fp->fs->wflag = 1; + res = sync(fp->fs); + } + } + } + + LEAVE_FF(fp->fs, res); +} + +#endif /* !_FS_READONLY */ + + + + +/*-----------------------------------------------------------------------*/ +/* Close File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_close ( + FIL *fp /* Pointer to the file object to be closed */ +) +{ + FRESULT res; + + +#if _FS_READONLY + res = validate(fp->fs, fp->id); + if (res == FR_OK) fp->fs = NULL; + LEAVE_FF(fp->fs, res); +#else + res = f_sync(fp); + if (res == FR_OK) fp->fs = NULL; + return res; +#endif +} + + + + +/*-----------------------------------------------------------------------*/ +/* Change Current Drive/Directory */ +/*-----------------------------------------------------------------------*/ + +#if _FS_RPATH + +FRESULT f_chdrive ( + BYTE drv /* Drive number */ +) +{ + if (drv >= _DRIVES) return FR_INVALID_DRIVE; + + Drive = drv; + + return FR_OK; +} + + + + +FRESULT f_chdir ( + const XCHAR *path /* Pointer to the directory path */ +) +{ + FRESULT res; + DIR dj; + NAMEBUF(sfn, lfn); + BYTE *dir; + + + res = chk_mounted(&path, &dj.fs, 0); + if (res == FR_OK) { + INITBUF(dj, sfn, lfn); + res = follow_path(&dj, path); /* Follow the file path */ + if (res == FR_OK) { /* Follow completed */ + dir = dj.dir; /* Pointer to the entry */ + if (!dir) { + dj.fs->cdir = 0; /* No entry (root dir) */ + } else { + if (dir[DIR_Attr] & AM_DIR) /* Reached to the dir */ + dj.fs->cdir = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO); + else + res = FR_NO_PATH; /* Could not reach the dir (it is a file) */ + } + } + if (res == FR_NO_FILE) res = FR_NO_PATH; + } + + LEAVE_FF(dj.fs, res); +} + +#endif + + + +#if _FS_MINIMIZE <= 2 +/*-----------------------------------------------------------------------*/ +/* Seek File R/W Pointer */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_lseek ( + FIL *fp, /* Pointer to the file object */ + DWORD ofs /* File pointer from top of file */ +) +{ + FRESULT res; + DWORD clst, bcs, nsect, ifptr; + + + res = validate(fp->fs, fp->id); /* Check validity of the object */ + if (res != FR_OK) LEAVE_FF(fp->fs, res); + if (fp->flag & FA__ERROR) /* Check abort flag */ + LEAVE_FF(fp->fs, FR_INT_ERR); + if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */ +#if !_FS_READONLY + && !(fp->flag & FA_WRITE) +#endif + ) ofs = fp->fsize; + + ifptr = fp->fptr; + fp->fptr = nsect = 0; fp->csect = 255; + if (ofs > 0) { + bcs = (DWORD)fp->fs->csize * SS(fp->fs); /* Cluster size (byte) */ + if (ifptr > 0 && + (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */ + fp->fptr = (ifptr - 1) & ~(bcs - 1); /* start from the current cluster */ + ofs -= fp->fptr; + clst = fp->curr_clust; + } else { /* When seek to back cluster, */ + clst = fp->org_clust; /* start from the first cluster */ +#if !_FS_READONLY + if (clst == 0) { /* If no cluster chain, create a new chain */ + clst = create_chain(fp->fs, 0); + if (clst == 1) ABORT(fp->fs, FR_INT_ERR); + if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); + fp->org_clust = clst; + } +#endif + fp->curr_clust = clst; + } + if (clst != 0) { + while (ofs > bcs) { /* Cluster following loop */ +#if !_FS_READONLY + if (fp->flag & FA_WRITE) { /* Check if in write mode or not */ + clst = create_chain(fp->fs, clst); /* Force streached if in write mode */ + if (clst == 0) { /* When disk gets full, clip file size */ + ofs = bcs; break; + } + } else +#endif + clst = get_fat(fp->fs, clst); /* Follow cluster chain if not in write mode */ + if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); + if (clst <= 1 || clst >= fp->fs->max_clust) ABORT(fp->fs, FR_INT_ERR); + fp->curr_clust = clst; + fp->fptr += bcs; + ofs -= bcs; + } + fp->fptr += ofs; + fp->csect = (BYTE)(ofs / SS(fp->fs)); /* Sector offset in the cluster */ + if (ofs % SS(fp->fs)) { + nsect = clust2sect(fp->fs, clst); /* Current sector */ + if (!nsect) ABORT(fp->fs, FR_INT_ERR); + nsect += fp->csect; + fp->csect++; + } + } + } + if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) { +#if !_FS_TINY +#if !_FS_READONLY + if (fp->flag & FA__DIRTY) { /* Write-back dirty buffer if needed */ + if (disk_write(fp->fs->drive, fp->buf, fp->dsect, 1) != RES_OK) + ABORT(fp->fs, FR_DISK_ERR); + fp->flag &= ~FA__DIRTY; + } +#endif + if (disk_read(fp->fs->drive, fp->buf, nsect, 1) != RES_OK) + ABORT(fp->fs, FR_DISK_ERR); +#endif + fp->dsect = nsect; + } +#if !_FS_READONLY + if (fp->fptr > fp->fsize) { /* Set changed flag if the file size is extended */ + fp->fsize = fp->fptr; + fp->flag |= FA__WRITTEN; + } +#endif + + LEAVE_FF(fp->fs, res); +} + + + + +#if _FS_MINIMIZE <= 1 +/*-----------------------------------------------------------------------*/ +/* Create a Directroy Object */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_opendir ( + DIR *dj, /* Pointer to directory object to create */ + const XCHAR *path /* Pointer to the directory path */ +) +{ + FRESULT res; + NAMEBUF(sfn, lfn); + BYTE *dir; + + + res = chk_mounted(&path, &dj->fs, 0); + if (res == FR_OK) { + INITBUF((*dj), sfn, lfn); + res = follow_path(dj, path); /* Follow the path to the directory */ + if (res == FR_OK) { /* Follow completed */ + dir = dj->dir; + if (dir) { /* It is not the root dir */ + if (dir[DIR_Attr] & AM_DIR) { /* The object is a directory */ + dj->sclust = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO); + } else { /* The object is not a directory */ + res = FR_NO_PATH; + } + } + if (res == FR_OK) { + dj->id = dj->fs->id; + res = dir_seek(dj, 0); /* Rewind dir */ + } + } + if (res == FR_NO_FILE) res = FR_NO_PATH; + } + + LEAVE_FF(dj->fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Read Directory Entry in Sequense */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_readdir ( + DIR *dj, /* Pointer to the open directory object */ + FILINFO *fno /* Pointer to file information to return */ +) +{ + FRESULT res; + NAMEBUF(sfn, lfn); + + + res = validate(dj->fs, dj->id); /* Check validity of the object */ + if (res == FR_OK) { + INITBUF((*dj), sfn, lfn); + if (!fno) { + res = dir_seek(dj, 0); + } else { + res = dir_read(dj); + if (res == FR_NO_FILE) { + dj->sect = 0; + res = FR_OK; + } + if (res == FR_OK) { /* A valid entry is found */ + get_fileinfo(dj, fno); /* Get the object information */ + res = dir_next(dj, FALSE); /* Increment index for next */ + if (res == FR_NO_FILE) { + dj->sect = 0; + res = FR_OK; + } + } + } + } + + LEAVE_FF(dj->fs, res); +} + + + +#if _FS_MINIMIZE == 0 +/*-----------------------------------------------------------------------*/ +/* Get File Status */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_stat ( + const XCHAR *path, /* Pointer to the file path */ + FILINFO *fno /* Pointer to file information to return */ +) +{ + FRESULT res; + DIR dj; + NAMEBUF(sfn, lfn); + + + res = chk_mounted(&path, &dj.fs, 0); + if (res == FR_OK) { + INITBUF(dj, sfn, lfn); + res = follow_path(&dj, path); /* Follow the file path */ + if (res == FR_OK) { /* Follwo completed */ + if (dj.dir) /* Found an object */ + get_fileinfo(&dj, fno); + else /* It is root dir */ + res = FR_INVALID_NAME; + } + } + + LEAVE_FF(dj.fs, res); +} + + + +#if !_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Get Number of Free Clusters */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_getfree ( + const XCHAR *path, /* Pointer to the logical drive number (root dir) */ + DWORD *nclst, /* Pointer to the variable to return number of free clusters */ + FATFS **fatfs /* Pointer to pointer to corresponding file system object to return */ +) +{ + FRESULT res; + DWORD n, clst, sect, stat; + UINT i; + BYTE fat, *p; + + + /* Get drive number */ + res = chk_mounted(&path, fatfs, 0); + if (res != FR_OK) LEAVE_FF(*fatfs, res); + + /* If number of free cluster is valid, return it without cluster scan. */ + if ((*fatfs)->free_clust <= (*fatfs)->max_clust - 2) { + *nclst = (*fatfs)->free_clust; + LEAVE_FF(*fatfs, FR_OK); + } + + /* Get number of free clusters */ + fat = (*fatfs)->fs_type; + n = 0; + if (fat == FS_FAT12) { + clst = 2; + do { + stat = get_fat(*fatfs, clst); + if (stat == 0xFFFFFFFF) LEAVE_FF(*fatfs, FR_DISK_ERR); + if (stat == 1) LEAVE_FF(*fatfs, FR_INT_ERR); + if (stat == 0) n++; + } while (++clst < (*fatfs)->max_clust); + } else { + clst = (*fatfs)->max_clust; + sect = (*fatfs)->fatbase; + i = 0; p = 0; + do { + if (!i) { + res = move_window(*fatfs, sect++); + if (res != FR_OK) + LEAVE_FF(*fatfs, res); + p = (*fatfs)->win; + i = SS(*fatfs); + } + if (fat == FS_FAT16) { + if (LD_WORD(p) == 0) n++; + p += 2; i -= 2; + } else { + if ((LD_DWORD(p) & 0x0FFFFFFF) == 0) n++; + p += 4; i -= 4; + } + } while (--clst); + } + (*fatfs)->free_clust = n; + if (fat == FS_FAT32) (*fatfs)->fsi_flag = 1; + *nclst = n; + + LEAVE_FF(*fatfs, FR_OK); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Truncate File */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_truncate ( + FIL *fp /* Pointer to the file object */ +) +{ + FRESULT res; + DWORD ncl; + + + res = validate(fp->fs, fp->id); /* Check validity of the object */ + if (res != FR_OK) LEAVE_FF(fp->fs, res); + if (fp->flag & FA__ERROR) /* Check abort flag */ + LEAVE_FF(fp->fs, FR_INT_ERR); + if (!(fp->flag & FA_WRITE)) /* Check access mode */ + LEAVE_FF(fp->fs, FR_DENIED); + + if (fp->fsize > fp->fptr) { + fp->fsize = fp->fptr; /* Set file size to current R/W point */ + fp->flag |= FA__WRITTEN; + if (fp->fptr == 0) { /* When set file size to zero, remove entire cluster chain */ + res = remove_chain(fp->fs, fp->org_clust); + fp->org_clust = 0; + } else { /* When truncate a part of the file, remove remaining clusters */ + ncl = get_fat(fp->fs, fp->curr_clust); + res = FR_OK; + if (ncl == 0xFFFFFFFF) res = FR_DISK_ERR; + if (ncl == 1) res = FR_INT_ERR; + if (res == FR_OK && ncl < fp->fs->max_clust) { + res = put_fat(fp->fs, fp->curr_clust, 0x0FFFFFFF); + if (res == FR_OK) res = remove_chain(fp->fs, ncl); + } + } + } + if (res != FR_OK) fp->flag |= FA__ERROR; + + LEAVE_FF(fp->fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Delete a File or Directory */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_unlink ( + const XCHAR *path /* Pointer to the file or directory path */ +) +{ + FRESULT res; + DIR dj, sdj; + NAMEBUF(sfn, lfn); + BYTE *dir; + DWORD dclst; + + + res = chk_mounted(&path, &dj.fs, 1); + if (res != FR_OK) LEAVE_FF(dj.fs, res); + + INITBUF(dj, sfn, lfn); + res = follow_path(&dj, path); /* Follow the file path */ + if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT)) + res = FR_INVALID_NAME; + if (res != FR_OK) LEAVE_FF(dj.fs, res); /* Follow failed */ + + dir = dj.dir; + if (!dir) /* Is it the root directory? */ + LEAVE_FF(dj.fs, FR_INVALID_NAME); + if (dir[DIR_Attr] & AM_RDO) /* Is it a R/O object? */ + LEAVE_FF(dj.fs, FR_DENIED); + dclst = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16) | LD_WORD(dir+DIR_FstClusLO); + + if (dir[DIR_Attr] & AM_DIR) { /* It is a sub-directory */ + if (dclst < 2) LEAVE_FF(dj.fs, FR_INT_ERR); + mem_cpy(&sdj, &dj, sizeof(DIR)); /* Check if the sub-dir is empty or not */ + sdj.sclust = dclst; + res = dir_seek(&sdj, 2); + if (res != FR_OK) LEAVE_FF(dj.fs, res); + res = dir_read(&sdj); + if (res == FR_OK) res = FR_DENIED; /* Not empty sub-dir */ + if (res != FR_NO_FILE) LEAVE_FF(dj.fs, res); + } + + res = dir_remove(&dj); /* Remove directory entry */ + if (res == FR_OK) { + if (dclst) + res = remove_chain(dj.fs, dclst); /* Remove the cluster chain */ + if (res == FR_OK) res = sync(dj.fs); + } + + LEAVE_FF(dj.fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Create a Directory */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_mkdir ( + const XCHAR *path /* Pointer to the directory path */ +) +{ + FRESULT res; + DIR dj; + NAMEBUF(sfn, lfn); + BYTE *dir, n; + DWORD dsect, dclst, pclst, tim; + + + res = chk_mounted(&path, &dj.fs, 1); + if (res != FR_OK) LEAVE_FF(dj.fs, res); + + INITBUF(dj, sfn, lfn); + res = follow_path(&dj, path); /* Follow the file path */ + if (res == FR_OK) res = FR_EXIST; /* Any file or directory is already existing */ + if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NS] & NS_DOT)) + res = FR_INVALID_NAME; + if (res != FR_NO_FILE) /* Any error occured */ + LEAVE_FF(dj.fs, res); + + dclst = create_chain(dj.fs, 0); /* Allocate a new cluster for new directory table */ + res = FR_OK; + if (dclst == 0) res = FR_DENIED; + if (dclst == 1) res = FR_INT_ERR; + if (dclst == 0xFFFFFFFF) res = FR_DISK_ERR; + if (res == FR_OK) + res = move_window(dj.fs, 0); + if (res != FR_OK) LEAVE_FF(dj.fs, res); + dsect = clust2sect(dj.fs, dclst); + + dir = dj.fs->win; /* Initialize the new directory table */ + mem_set(dir, 0, SS(dj.fs)); + mem_set(dir+DIR_Name, ' ', 8+3); /* Create "." entry */ + dir[DIR_Name] = '.'; + dir[DIR_Attr] = AM_DIR; + tim = get_fattime(); + ST_DWORD(dir+DIR_WrtTime, tim); + ST_WORD(dir+DIR_FstClusLO, dclst); + ST_WORD(dir+DIR_FstClusHI, dclst >> 16); + mem_cpy(dir+32, dir, 32); /* Create ".." entry */ + dir[33] = '.'; + pclst = dj.sclust; + if (dj.fs->fs_type == FS_FAT32 && pclst == dj.fs->dirbase) + pclst = 0; + ST_WORD(dir+32+DIR_FstClusLO, pclst); + ST_WORD(dir+32+DIR_FstClusHI, pclst >> 16); + for (n = 0; n < dj.fs->csize; n++) { /* Write dot entries and clear left sectors */ + dj.fs->winsect = dsect++; + dj.fs->wflag = 1; + res = move_window(dj.fs, 0); + if (res) LEAVE_FF(dj.fs, res); + mem_set(dir, 0, SS(dj.fs)); + } + + res = dir_register(&dj); + if (res != FR_OK) { + remove_chain(dj.fs, dclst); + } else { + dir = dj.dir; + dir[DIR_Attr] = AM_DIR; /* Attribute */ + ST_DWORD(dir+DIR_WrtTime, tim); /* Crated time */ + ST_WORD(dir+DIR_FstClusLO, dclst); /* Table start cluster */ + ST_WORD(dir+DIR_FstClusHI, dclst >> 16); + dj.fs->wflag = 1; + res = sync(dj.fs); + } + + LEAVE_FF(dj.fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Change File Attribute */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_chmod ( + const XCHAR *path, /* Pointer to the file path */ + BYTE value, /* Attribute bits */ + BYTE mask /* Attribute mask to change */ +) +{ + FRESULT res; + DIR dj; + NAMEBUF(sfn, lfn); + BYTE *dir; + + + res = chk_mounted(&path, &dj.fs, 1); + if (res == FR_OK) { + INITBUF(dj, sfn, lfn); + res = follow_path(&dj, path); /* Follow the file path */ + if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT)) + res = FR_INVALID_NAME; + if (res == FR_OK) { + dir = dj.dir; + if (!dir) { /* Is it a root directory? */ + res = FR_INVALID_NAME; + } else { /* File or sub directory */ + mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */ + dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */ + dj.fs->wflag = 1; + res = sync(dj.fs); + } + } + } + + LEAVE_FF(dj.fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Change Timestamp */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_utime ( + const XCHAR *path, /* Pointer to the file/directory name */ + const FILINFO *fno /* Pointer to the timestamp to be set */ +) +{ + FRESULT res; + DIR dj; + NAMEBUF(sfn, lfn); + BYTE *dir; + + + res = chk_mounted(&path, &dj.fs, 1); + if (res == FR_OK) { + INITBUF(dj, sfn, lfn); + res = follow_path(&dj, path); /* Follow the file path */ + if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT)) + res = FR_INVALID_NAME; + if (res == FR_OK) { + dir = dj.dir; + if (!dir) { /* Root directory */ + res = FR_INVALID_NAME; + } else { /* File or sub-directory */ + ST_WORD(dir+DIR_WrtTime, fno->ftime); + ST_WORD(dir+DIR_WrtDate, fno->fdate); + dj.fs->wflag = 1; + res = sync(dj.fs); + } + } + } + + LEAVE_FF(dj.fs, res); +} + + + + +/*-----------------------------------------------------------------------*/ +/* Rename File/Directory */ +/*-----------------------------------------------------------------------*/ + +FRESULT f_rename ( + const XCHAR *path_old, /* Pointer to the old name */ + const XCHAR *path_new /* Pointer to the new name */ +) +{ + FRESULT res; + DIR dj_old, dj_new; + NAMEBUF(sfn, lfn); + BYTE buf[21], *dir; + DWORD dw; + + + INITBUF(dj_old, sfn, lfn); + res = chk_mounted(&path_old, &dj_old.fs, 1); + if (res == FR_OK) { + dj_new.fs = dj_old.fs; + res = follow_path(&dj_old, path_old); /* Check old object */ + if (_FS_RPATH && res == FR_OK && (dj_old.fn[NS] & NS_DOT)) + res = FR_INVALID_NAME; + } + if (res != FR_OK) LEAVE_FF(dj_old.fs, res); /* The old object is not found */ + + if (!dj_old.dir) LEAVE_FF(dj_old.fs, FR_NO_FILE); /* Is root dir? */ + mem_cpy(buf, dj_old.dir+DIR_Attr, 21); /* Save the object information */ + + mem_cpy(&dj_new, &dj_old, sizeof(DIR)); + res = follow_path(&dj_new, path_new); /* Check new object */ + if (res == FR_OK) res = FR_EXIST; /* The new object name is already existing */ + if (res == FR_NO_FILE) { /* Is it a valid path and no name collision? */ + res = dir_register(&dj_new); /* Register the new object */ + if (res == FR_OK) { + dir = dj_new.dir; /* Copy object information into new entry */ + mem_cpy(dir+13, buf+2, 19); + dir[DIR_Attr] = buf[0] | AM_ARC; + dj_old.fs->wflag = 1; + if (dir[DIR_Attr] & AM_DIR) { /* Update .. entry in the directory if needed */ + dw = clust2sect(dj_new.fs, (DWORD)LD_WORD(dir+DIR_FstClusHI) | LD_WORD(dir+DIR_FstClusLO)); + if (!dw) { + res = FR_INT_ERR; + } else { + res = move_window(dj_new.fs, dw); + dir = dj_new.fs->win+32; + if (res == FR_OK && dir[1] == '.') { + dw = (dj_new.fs->fs_type == FS_FAT32 && dj_new.sclust == dj_new.fs->dirbase) ? 0 : dj_new.sclust; + ST_WORD(dir+DIR_FstClusLO, dw); + ST_WORD(dir+DIR_FstClusHI, dw >> 16); + dj_new.fs->wflag = 1; + } + } + } + if (res == FR_OK) { + res = dir_remove(&dj_old); /* Remove old entry */ + if (res == FR_OK) + res = sync(dj_old.fs); + } + } + } + + LEAVE_FF(dj_old.fs, res); +} + +#endif /* !_FS_READONLY */ +#endif /* _FS_MINIMIZE == 0 */ +#endif /* _FS_MINIMIZE <= 1 */ +#endif /* _FS_MINIMIZE <= 2 */ + + + +/*-----------------------------------------------------------------------*/ +/* Forward data to the stream directly (Available on only _FS_TINY cfg) */ +/*-----------------------------------------------------------------------*/ +#if _USE_FORWARD && _FS_TINY + +FRESULT f_forward ( + FIL *fp, /* Pointer to the file object */ + UINT (*func)(const BYTE*,UINT), /* Pointer to the streaming function */ + UINT btr, /* Number of bytes to forward */ + UINT *bf /* Pointer to number of bytes forwarded */ +) +{ + FRESULT res; + DWORD remain, clst, sect; + UINT rcnt; + + + *bf = 0; + + res = validate(fp->fs, fp->id); /* Check validity of the object */ + if (res != FR_OK) LEAVE_FF(fp->fs, res); + if (fp->flag & FA__ERROR) /* Check error flag */ + LEAVE_FF(fp->fs, FR_INT_ERR); + if (!(fp->flag & FA_READ)) /* Check access mode */ + LEAVE_FF(fp->fs, FR_DENIED); + + remain = fp->fsize - fp->fptr; + if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ + + for ( ; btr && (*func)(NULL, 0); /* Repeat until all data transferred or stream becomes busy */ + fp->fptr += rcnt, *bf += rcnt, btr -= rcnt) { + if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ + if (fp->csect >= fp->fs->csize) { /* On the cluster boundary? */ + clst = (fp->fptr == 0) ? /* On the top of the file? */ + fp->org_clust : get_fat(fp->fs, fp->curr_clust); + if (clst <= 1) ABORT(fp->fs, FR_INT_ERR); + if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); + fp->curr_clust = clst; /* Update current cluster */ + fp->csect = 0; /* Reset sector address in the cluster */ + } + fp->csect++; /* Next sector address in the cluster */ + } + sect = clust2sect(fp->fs, fp->curr_clust); /* Get current data sector */ + if (!sect) ABORT(fp->fs, FR_INT_ERR); + sect += fp->csect - 1; + if (move_window(fp->fs, sect)) /* Move sector window */ + ABORT(fp->fs, FR_DISK_ERR); + fp->dsect = sect; + rcnt = SS(fp->fs) - (WORD)(fp->fptr % SS(fp->fs)); /* Forward data from sector window */ + if (rcnt > btr) rcnt = btr; + rcnt = (*func)(&fp->fs->win[(WORD)fp->fptr % SS(fp->fs)], rcnt); + if (!rcnt) ABORT(fp->fs, FR_INT_ERR); + } + + LEAVE_FF(fp->fs, FR_OK); +} +#endif /* _USE_FORWARD */ + + + +#if _USE_MKFS && !_FS_READONLY +/*-----------------------------------------------------------------------*/ +/* Create File System on the Drive */ +/*-----------------------------------------------------------------------*/ +#define N_ROOTDIR 512 /* Multiple of 32 and <= 2048 */ +#define N_FATS 1 /* 1 or 2 */ +#define MAX_SECTOR 131072000UL /* Maximum partition size */ +#define MIN_SECTOR 2000UL /* Minimum partition size */ + + +FRESULT f_mkfs ( + BYTE drv, /* Logical drive number */ + BYTE partition, /* Partitioning rule 0:FDISK, 1:SFD */ + WORD allocsize /* Allocation unit size [bytes] */ +) +{ + static const DWORD sstbl[] = { 2048000, 1024000, 512000, 256000, 128000, 64000, 32000, 16000, 8000, 4000, 0 }; + static const WORD cstbl[] = { 32768, 16384, 8192, 4096, 2048, 16384, 8192, 4096, 2048, 1024, 512 }; + BYTE fmt, m, *tbl; + DWORD b_part, b_fat, b_dir, b_data; /* Area offset (LBA) */ + DWORD n_part, n_rsv, n_fat, n_dir; /* Area size */ + DWORD n_clst, d, n; + WORD as; + FATFS *fs; + DSTATUS stat; + + + /* Check validity of the parameters */ + if (drv >= _DRIVES) return FR_INVALID_DRIVE; + if (partition >= 2) return FR_MKFS_ABORTED; + + /* Check mounted drive and clear work area */ + fs = FatFs[drv]; + if (!fs) return FR_NOT_ENABLED; + fs->fs_type = 0; + drv = LD2PD(drv); + + /* Get disk statics */ + stat = disk_initialize(drv); + if (stat & STA_NOINIT) return FR_NOT_READY; + if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; +#if _MAX_SS != 512 /* Get disk sector size */ + if (disk_ioctl(drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK + || SS(fs) > _MAX_SS) + return FR_MKFS_ABORTED; +#endif + if (disk_ioctl(drv, GET_SECTOR_COUNT, &n_part) != RES_OK || n_part < MIN_SECTOR) + return FR_MKFS_ABORTED; + if (n_part > MAX_SECTOR) n_part = MAX_SECTOR; + b_part = (!partition) ? 63 : 0; /* Boot sector */ + n_part -= b_part; + for (d = 512; d <= 32768U && d != allocsize; d <<= 1) ; /* Check validity of the allocation unit size */ + if (d != allocsize) allocsize = 0; + if (!allocsize) { /* Auto selection of cluster size */ + d = n_part; + for (as = SS(fs); as > 512U; as >>= 1) d >>= 1; + for (n = 0; d < sstbl[n]; n++) ; + allocsize = cstbl[n]; + } + if (allocsize < SS(fs)) allocsize = SS(fs); + + allocsize /= SS(fs); /* Number of sectors per cluster */ + + /* Pre-compute number of clusters and FAT type */ + n_clst = n_part / allocsize; + fmt = FS_FAT12; + if (n_clst >= 0xFF5) fmt = FS_FAT16; + if (n_clst >= 0xFFF5) fmt = FS_FAT32; + + /* Determine offset and size of FAT structure */ + switch (fmt) { + case FS_FAT12: + n_fat = ((n_clst * 3 + 1) / 2 + 3 + SS(fs) - 1) / SS(fs); + n_rsv = 1 + partition; + n_dir = N_ROOTDIR * 32 / SS(fs); + break; + case FS_FAT16: + n_fat = ((n_clst * 2) + 4 + SS(fs) - 1) / SS(fs); + n_rsv = 1 + partition; + n_dir = N_ROOTDIR * 32 / SS(fs); + break; + default: + n_fat = ((n_clst * 4) + 8 + SS(fs) - 1) / SS(fs); + n_rsv = 33 - partition; + n_dir = 0; + } + b_fat = b_part + n_rsv; /* FATs start sector */ + b_dir = b_fat + n_fat * N_FATS; /* Directory start sector */ + b_data = b_dir + n_dir; /* Data start sector */ + + /* Align data start sector to erase block boundary (for flash memory media) */ + if (disk_ioctl(drv, GET_BLOCK_SIZE, &n) != RES_OK) return FR_MKFS_ABORTED; + n = (b_data + n - 1) & ~(n - 1); + n_fat += (n - b_data) / N_FATS; + /* b_dir and b_data are no longer used below */ + + /* Determine number of cluster and final check of validity of the FAT type */ + n_clst = (n_part - n_rsv - n_fat * N_FATS - n_dir) / allocsize; + if ( (fmt == FS_FAT16 && n_clst < 0xFF5) + || (fmt == FS_FAT32 && n_clst < 0xFFF5)) + return FR_MKFS_ABORTED; + + /* Create partition table if needed */ + if (!partition) { + DWORD n_disk = b_part + n_part; + + mem_set(fs->win, 0, SS(fs)); + tbl = fs->win+MBR_Table; + ST_DWORD(tbl, 0x00010180); /* Partition start in CHS */ + if (n_disk < 63UL * 255 * 1024) { /* Partition end in CHS */ + n_disk = n_disk / 63 / 255; + tbl[7] = (BYTE)n_disk; + tbl[6] = (BYTE)((n_disk >> 2) | 63); + } else { + ST_WORD(&tbl[6], 0xFFFF); + } + tbl[5] = 254; + if (fmt != FS_FAT32) /* System ID */ + tbl[4] = (n_part < 0x10000) ? 0x04 : 0x06; + else + tbl[4] = 0x0c; + ST_DWORD(tbl+8, 63); /* Partition start in LBA */ + ST_DWORD(tbl+12, n_part); /* Partition size in LBA */ + ST_WORD(tbl+64, 0xAA55); /* Signature */ + if (disk_write(drv, fs->win, 0, 1) != RES_OK) + return FR_DISK_ERR; + partition = 0xF8; + } else { + partition = 0xF0; + } + + /* Create boot record */ + tbl = fs->win; /* Clear buffer */ + mem_set(tbl, 0, SS(fs)); + ST_DWORD(tbl+BS_jmpBoot, 0x90FEEB); /* Boot code (jmp $, nop) */ + ST_WORD(tbl+BPB_BytsPerSec, SS(fs)); /* Sector size */ + tbl[BPB_SecPerClus] = (BYTE)allocsize; /* Sectors per cluster */ + ST_WORD(tbl+BPB_RsvdSecCnt, n_rsv); /* Reserved sectors */ + tbl[BPB_NumFATs] = N_FATS; /* Number of FATs */ + ST_WORD(tbl+BPB_RootEntCnt, SS(fs) / 32 * n_dir); /* Number of rootdir entries */ + if (n_part < 0x10000) { /* Number of total sectors */ + ST_WORD(tbl+BPB_TotSec16, n_part); + } else { + ST_DWORD(tbl+BPB_TotSec32, n_part); + } + tbl[BPB_Media] = partition; /* Media descripter */ + ST_WORD(tbl+BPB_SecPerTrk, 63); /* Number of sectors per track */ + ST_WORD(tbl+BPB_NumHeads, 255); /* Number of heads */ + ST_DWORD(tbl+BPB_HiddSec, b_part); /* Hidden sectors */ + n = get_fattime(); /* Use current time as a VSN */ + if (fmt != FS_FAT32) { + ST_DWORD(tbl+BS_VolID, n); /* Volume serial number */ + ST_WORD(tbl+BPB_FATSz16, n_fat); /* Number of secters per FAT */ + tbl[BS_DrvNum] = 0x80; /* Drive number */ + tbl[BS_BootSig] = 0x29; /* Extended boot signature */ + mem_cpy(tbl+BS_VolLab, "NO NAME FAT ", 19); /* Volume lavel, FAT signature */ + } else { + ST_DWORD(tbl+BS_VolID32, n); /* Volume serial number */ + ST_DWORD(tbl+BPB_FATSz32, n_fat); /* Number of secters per FAT */ + ST_DWORD(tbl+BPB_RootClus, 2); /* Root directory cluster (2) */ + ST_WORD(tbl+BPB_FSInfo, 1); /* FSInfo record offset (bs+1) */ + ST_WORD(tbl+BPB_BkBootSec, 6); /* Backup boot record offset (bs+6) */ + tbl[BS_DrvNum32] = 0x80; /* Drive number */ + tbl[BS_BootSig32] = 0x29; /* Extended boot signature */ + mem_cpy(tbl+BS_VolLab32, "NO NAME FAT32 ", 19); /* Volume lavel, FAT signature */ + } + ST_WORD(tbl+BS_55AA, 0xAA55); /* Signature */ + if (SS(fs) > 512U) { + ST_WORD(tbl+SS(fs)-2, 0xAA55); + } + if (disk_write(drv, tbl, b_part+0, 1) != RES_OK) + return FR_DISK_ERR; + if (fmt == FS_FAT32) + disk_write(drv, tbl, b_part+6, 1); + + /* Initialize FAT area */ + for (m = 0; m < N_FATS; m++) { + mem_set(tbl, 0, SS(fs)); /* 1st sector of the FAT */ + if (fmt != FS_FAT32) { + n = (fmt == FS_FAT12) ? 0x00FFFF00 : 0xFFFFFF00; + n |= partition; + ST_DWORD(tbl, n); /* Reserve cluster #0-1 (FAT12/16) */ + } else { + ST_DWORD(tbl+0, 0xFFFFFFF8); /* Reserve cluster #0-1 (FAT32) */ + ST_DWORD(tbl+4, 0xFFFFFFFF); + ST_DWORD(tbl+8, 0x0FFFFFFF); /* Reserve cluster #2 for root dir */ + } + if (disk_write(drv, tbl, b_fat++, 1) != RES_OK) + return FR_DISK_ERR; + mem_set(tbl, 0, SS(fs)); /* Following FAT entries are filled by zero */ + for (n = 1; n < n_fat; n++) { + if (disk_write(drv, tbl, b_fat++, 1) != RES_OK) + return FR_DISK_ERR; + } + } + + /* Initialize Root directory */ + m = (BYTE)((fmt == FS_FAT32) ? allocsize : n_dir); + do { + if (disk_write(drv, tbl, b_fat++, 1) != RES_OK) + return FR_DISK_ERR; + } while (--m); + + /* Create FSInfo record if needed */ + if (fmt == FS_FAT32) { + ST_WORD(tbl+BS_55AA, 0xAA55); + ST_DWORD(tbl+FSI_LeadSig, 0x41615252); + ST_DWORD(tbl+FSI_StrucSig, 0x61417272); + ST_DWORD(tbl+FSI_Free_Count, n_clst - 1); + ST_DWORD(tbl+FSI_Nxt_Free, 0xFFFFFFFF); + disk_write(drv, tbl, b_part+1, 1); + disk_write(drv, tbl, b_part+7, 1); + } + + return (disk_ioctl(drv, CTRL_SYNC, (void*)NULL) == RES_OK) ? FR_OK : FR_DISK_ERR; +} + +#endif /* _USE_MKFS && !_FS_READONLY */ + + + + +#if _USE_STRFUNC +/*-----------------------------------------------------------------------*/ +/* Get a string from the file */ +/*-----------------------------------------------------------------------*/ +char* f_gets ( + char* buff, /* Pointer to the string buffer to read */ + int len, /* Size of string buffer */ + FIL* fil /* Pointer to the file object */ +) +{ + int i = 0; + char *p = buff; + UINT rc; + + + while (i < len - 1) { /* Read bytes until buffer gets filled */ + f_read(fil, p, 1, &rc); + if (rc != 1) break; /* Break when no data to read */ +#if _USE_STRFUNC >= 2 + if (*p == '\r') continue; /* Strip '\r' */ +#endif + i++; + if (*p++ == '\n') break; /* Break when reached end of line */ + } + *p = 0; + return i ? buff : NULL; /* When no data read (eof or error), return with error. */ +} + + + +#if !_FS_READONLY +#include +/*-----------------------------------------------------------------------*/ +/* Put a character to the file */ +/*-----------------------------------------------------------------------*/ +int f_putc ( + int chr, /* A character to be output */ + FIL* fil /* Ponter to the file object */ +) +{ + UINT bw; + char c; + + +#if _USE_STRFUNC >= 2 + if (chr == '\n') f_putc ('\r', fil); /* LF -> CRLF conversion */ +#endif + if (!fil) { /* Special value may be used to switch the destination to any other device */ + /* put_console(chr); */ + return chr; + } + c = (char)chr; + f_write(fil, &c, 1, &bw); /* Write a byte to the file */ + return bw ? chr : EOF; /* Return the result */ +} + + + + +/*-----------------------------------------------------------------------*/ +/* Put a string to the file */ +/*-----------------------------------------------------------------------*/ +int f_puts ( + const char* str, /* Pointer to the string to be output */ + FIL* fil /* Pointer to the file object */ +) +{ + int n; + + + for (n = 0; *str; str++, n++) { + if (f_putc(*str, fil) == EOF) return EOF; + } + return n; +} + + + + +/*-----------------------------------------------------------------------*/ +/* Put a formatted string to the file */ +/*-----------------------------------------------------------------------*/ +int f_printf ( + FIL* fil, /* Pointer to the file object */ + const char* str, /* Pointer to the format string */ + ... /* Optional arguments... */ +) +{ + va_list arp; + UCHAR c, f, r; + ULONG val; + char s[16]; + int i, w, res, cc; + + + va_start(arp, str); + + for (cc = res = 0; cc != EOF; res += cc) { + c = *str++; + if (c == 0) break; /* End of string */ + if (c != '%') { /* Non escape cahracter */ + cc = f_putc(c, fil); + if (cc != EOF) cc = 1; + continue; + } + w = f = 0; + c = *str++; + if (c == '0') { /* Flag: '0' padding */ + f = 1; c = *str++; + } + while (c >= '0' && c <= '9') { /* Precision */ + w = w * 10 + (c - '0'); + c = *str++; + } + if (c == 'l') { /* Prefix: Size is long int */ + f |= 2; c = *str++; + } + if (c == 's') { /* Type is string */ + cc = f_puts(va_arg(arp, char*), fil); + continue; + } + if (c == 'c') { /* Type is character */ + cc = f_putc(va_arg(arp, int), fil); + if (cc != EOF) cc = 1; + continue; + } + r = 0; + if (c == 'd') r = 10; /* Type is signed decimal */ + if (c == 'u') r = 10; /* Type is unsigned decimal */ + if (c == 'X') r = 16; /* Type is unsigned hexdecimal */ + if (r == 0) break; /* Unknown type */ + if (f & 2) { /* Get the value */ + val = (ULONG)va_arg(arp, long); + } else { + val = (c == 'd') ? (ULONG)(long)va_arg(arp, int) : (ULONG)va_arg(arp, unsigned int); + } + /* Put numeral string */ + if (c == 'd') { + if (val & 0x80000000) { + val = 0 - val; + f |= 4; + } + } + i = sizeof(s) - 1; s[i] = 0; + do { + c = (UCHAR)(val % r + '0'); + if (c > '9') c += 7; + s[--i] = c; + val /= r; + } while (i && val); + if (i && (f & 4)) s[--i] = '-'; + w = sizeof(s) - 1 - w; + while (i && i > w) s[--i] = (f & 1) ? '0' : ' '; + cc = f_puts(&s[i], fil); + } + + va_end(arp); + return (cc == EOF) ? cc : res; +} + +#endif /* !_FS_READONLY */ +#endif /* _USE_STRFUNC */ diff --git a/macusbfb/drivers/fatfs/ff.h b/macusbfb/drivers/fatfs/ff.h new file mode 100644 index 0000000..c24d6c7 --- /dev/null +++ b/macusbfb/drivers/fatfs/ff.h @@ -0,0 +1,596 @@ +/*---------------------------------------------------------------------------/ +/ FatFs - FAT file system module include file R0.07e (C)ChaN, 2009 +/----------------------------------------------------------------------------/ +/ FatFs module is a generic FAT file system module for small embedded systems. +/ This is a free software that opened for education, research and commercial +/ developments under license policy of following trems. +/ +/ Copyright (C) 2009, ChaN, all right reserved. +/ +/ * The FatFs module is a free software and there is NO WARRANTY. +/ * No restriction on use. You can use, modify and redistribute it for +/ personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY. +/ * Redistributions of source code must retain the above copyright notice. +/----------------------------------------------------------------------------*/ + +#ifndef _FATFS +#define _FATFS 0x007E + +#include "integer.h" /* Basic integer types */ +#include "ffconf.h" /* FatFs configuration options */ + +#if _FATFS != _FFCONFIG +#error Wrong configuration file (ffconf.h). +#endif + + +/* DBCS code ranges and SBCS extend char conversion table */ + +#if _CODE_PAGE == 932 /* Japanese Shift-JIS */ +#define _DF1S 0x81 /* DBC 1st byte range 1 start */ +#define _DF1E 0x9F /* DBC 1st byte range 1 end */ +#define _DF2S 0xE0 /* DBC 1st byte range 2 start */ +#define _DF2E 0xFC /* DBC 1st byte range 2 end */ +#define _DS1S 0x40 /* DBC 2nd byte range 1 start */ +#define _DS1E 0x7E /* DBC 2nd byte range 1 end */ +#define _DS2S 0x80 /* DBC 2nd byte range 2 start */ +#define _DS2E 0xFC /* DBC 2nd byte range 2 end */ + +#elif _CODE_PAGE == 936 /* Simplified Chinese GBK */ +#define _DF1S 0x81 +#define _DF1E 0xFE +#define _DS1S 0x40 +#define _DS1E 0x7E +#define _DS2S 0x80 +#define _DS2E 0xFE + +#elif _CODE_PAGE == 949 /* Korean */ +#define _DF1S 0x81 +#define _DF1E 0xFE +#define _DS1S 0x41 +#define _DS1E 0x5A +#define _DS2S 0x61 +#define _DS2E 0x7A +#define _DS3S 0x81 +#define _DS3E 0xFE + +#elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */ +#define _DF1S 0x81 +#define _DF1E 0xFE +#define _DS1S 0x40 +#define _DS1E 0x7E +#define _DS2S 0xA1 +#define _DS2E 0xFE + +#elif _CODE_PAGE == 437 /* U.S. (OEM) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F,0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ + 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB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0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} + +#elif _CODE_PAGE == 737 /* Greek (OEM) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \ + 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ + 0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xE7,0xE8,0xF1,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} + +#elif _CODE_PAGE == 775 /* Baltic (OEM) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \ + 0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0x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0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} + +#elif _CODE_PAGE == 858 /* Multilingual Latin 1 + Euro (OEM) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0xDE,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x59,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \ + 0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ + 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE7,0xE9,0xEA,0xEB,0xED,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} + +#elif _CODE_PAGE == 862 /* Hebrew (OEM) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ + 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,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,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} + +#elif _CODE_PAGE == 874 /* Thai (OEM, Windows) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ + 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ + 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} + +#elif _CODE_PAGE == 1250 /* Central Europe (Windows) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x8D,0x8E,0x8F, \ + 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC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E,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF} + +#elif _CODE_PAGE == 1252 /* Latin 1 (Windows) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0xAd,0x9B,0x8C,0x9D,0xAE,0x9F, \ + 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F} + +#elif _CODE_PAGE == 1253 /* Greek (Windows) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ + 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,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CD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F} + +#elif _CODE_PAGE == 1255 /* Hebrew (Windows) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ + 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ + 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} + +#elif _CODE_PAGE == 1256 /* Arabic (Windows) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x8C,0x9D,0x9E,0x9F, \ + 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,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,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xFF} + +#elif _CODE_PAGE == 1258 /* Vietnam (OEM, Windows) */ +#define _DF1S 0 +#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0xAC,0x9D,0x9E,0x9F, \ + 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xEC,0xCD,0xCE,0xCF,0xD0,0xD1,0xF2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xFE,0x9F} + +#elif _CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */ +#define _DF1S 0 + +#else +#error Unknown code page + +#endif + + + +/* Character code support macros */ + +#define IsUpper(c) (((c)>='A')&&((c)<='Z')) +#define IsLower(c) (((c)>='a')&&((c)<='z')) + +#if _DF1S /* DBCS configuration */ + +#ifdef _DF2S /* Two 1st byte areas */ +#define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E)) +#else /* One 1st byte area */ +#define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) +#endif + +#ifdef _DS3S /* Three 2nd byte areas */ +#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E)) +#else /* Two 2nd byte areas */ +#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E)) +#endif + +#else /* SBCS configuration */ + +#define IsDBCS1(c) 0 +#define IsDBCS2(c) 0 + +#endif /* _DF1S */ + + + +/* Definitions corresponds to multi partition */ + +#if _MULTI_PARTITION /* Multiple partition configuration */ + +typedef struct _PARTITION { + BYTE pd; /* Physical drive# */ + BYTE pt; /* Partition # (0-3) */ +} PARTITION; + +extern +const PARTITION Drives[]; /* Logical drive# to physical location conversion table */ +#define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */ +#define LD2PT(drv) (Drives[drv].pt) /* Get partition# */ + +#else /* Single partition configuration */ + +#define LD2PD(drv) (drv) /* Physical drive# is equal to the logical drive# */ +#define LD2PT(drv) 0 /* Always mounts the 1st partition */ + +#endif + + + +/* Definitions corresponds to multiple sector size */ + +#if _MAX_SS == 512 /* Single sector size */ +#define SS(fs) 512U + +#elif _MAX_SS == 1024 || _MAX_SS == 2048 || _MAX_SS == 4096 /* Multiple sector size */ +#define SS(fs) ((fs)->s_size) + +#else +#error Sector size must be 512, 1024, 2048 or 4096. + +#endif + + + +/* Type of file name on FatFs API */ + +#if _LFN_UNICODE && _USE_LFN +typedef WCHAR XCHAR; /* Unicode */ +#else +typedef char XCHAR; /* SBCS, DBCS */ +#endif + + + +/* File system object structure */ + +typedef struct _FATFS_ { + BYTE fs_type; /* FAT sub type */ + BYTE drive; /* Physical drive number */ + BYTE csize; /* Number of sectors per cluster */ + BYTE n_fats; /* Number of FAT copies */ + BYTE wflag; /* win[] dirty flag (1:must be written back) */ + BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ + WORD id; /* File system mount ID */ + WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */ +#if _FS_REENTRANT + _SYNC_t sobj; /* Identifier of sync object */ +#endif +#if _MAX_SS != 512 + WORD s_size; /* Sector size */ +#endif +#if !_FS_READONLY + DWORD last_clust; /* Last allocated cluster */ + DWORD free_clust; /* Number of free clusters */ + DWORD fsi_sector; /* fsinfo sector */ +#endif +#if _FS_RPATH + DWORD cdir; /* Current directory (0:root)*/ +#endif + DWORD sects_fat; /* Sectors per fat */ + DWORD max_clust; /* Maximum cluster# + 1. Number of clusters is max_clust - 2 */ + DWORD fatbase; /* FAT start sector */ + DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */ + DWORD database; /* Data start sector */ + DWORD winsect; /* Current sector appearing in the win[] */ + BYTE win[_MAX_SS];/* Disk access window for Directory/FAT */ +} FATFS; + + + +/* Directory object structure */ + +typedef struct _DIR_ { + FATFS* fs; /* Pointer to the owner file system object */ + WORD id; /* Owner file system mount ID */ + WORD index; /* Current read/write index number */ + DWORD sclust; /* Table start cluster (0:Static table) */ + DWORD clust; /* Current cluster */ + DWORD sect; /* Current sector */ + BYTE* dir; /* Pointer to the current SFN entry in the win[] */ + BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ +#if _USE_LFN + WCHAR* lfn; /* Pointer to the LFN working buffer */ + WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */ +#endif +} DIR; + + + +/* File object structure */ + +typedef struct _FIL_ { + FATFS* fs; /* Pointer to the owner file system object */ + WORD id; /* Owner file system mount ID */ + BYTE flag; /* File status flags */ + BYTE csect; /* Sector address in the cluster */ + DWORD fptr; /* File R/W pointer */ + DWORD fsize; /* File size */ + DWORD org_clust; /* File start cluster */ + DWORD curr_clust; /* Current cluster */ + DWORD dsect; /* Current data sector */ +#if !_FS_READONLY + DWORD dir_sect; /* Sector containing the directory entry */ + BYTE* dir_ptr; /* Ponter to the directory entry in the window */ +#endif +#if !_FS_TINY + BYTE buf[_MAX_SS];/* File R/W buffer */ +#endif +} FIL; + + + +/* File status structure */ + +typedef struct _FILINFO_ { + DWORD fsize; /* File size */ + WORD fdate; /* Last modified date */ + WORD ftime; /* Last modified time */ + BYTE fattrib; /* Attribute */ + char fname[13]; /* Short file name (8.3 format) */ +#if _USE_LFN + XCHAR* lfname; /* Pointer to the LFN buffer */ + int lfsize; /* Size of LFN buffer [chrs] */ +#endif +} FILINFO; + + + +/* File function return code (FRESULT) */ + +typedef enum { + FR_OK = 0, /* 0 */ + FR_DISK_ERR, /* 1 */ + FR_INT_ERR, /* 2 */ + FR_NOT_READY, /* 3 */ + FR_NO_FILE, /* 4 */ + FR_NO_PATH, /* 5 */ + FR_INVALID_NAME, /* 6 */ + FR_DENIED, /* 7 */ + FR_EXIST, /* 8 */ + FR_INVALID_OBJECT, /* 9 */ + FR_WRITE_PROTECTED, /* 10 */ + FR_INVALID_DRIVE, /* 11 */ + FR_NOT_ENABLED, /* 12 */ + FR_NO_FILESYSTEM, /* 13 */ + FR_MKFS_ABORTED, /* 14 */ + FR_TIMEOUT /* 15 */ +} FRESULT; + + + +/*--------------------------------------------------------------*/ +/* FatFs module application interface */ + +FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ +FRESULT f_open (FIL*, const XCHAR*, BYTE); /* Open or create a file */ +FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ +FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ +FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ +FRESULT f_close (FIL*); /* Close an open file object */ +FRESULT f_opendir (DIR*, const XCHAR*); /* Open an existing directory */ +FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */ +FRESULT f_stat (const XCHAR*, FILINFO*); /* Get file status */ +FRESULT f_getfree (const XCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ +FRESULT f_truncate (FIL*); /* Truncate file */ +FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ +FRESULT f_unlink (const XCHAR*); /* Delete an existing file or directory */ +FRESULT f_mkdir (const XCHAR*); /* Create a new directory */ +FRESULT f_chmod (const XCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */ +FRESULT f_utime (const XCHAR*, const FILINFO*); /* Change timestamp of the file/dir */ +FRESULT f_rename (const XCHAR*, const XCHAR*); /* Rename/Move a file or directory */ +FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ +FRESULT f_mkfs (BYTE, BYTE, WORD); /* Create a file system on the drive */ +FRESULT f_chdir (const XCHAR*); /* Change current directory */ +FRESULT f_chdrive (BYTE); /* Change current drive */ + +#if _USE_STRFUNC +int f_putc (int, FIL*); /* Put a character to the file */ +int f_puts (const char*, FIL*); /* Put a string to the file */ +int f_printf (FIL*, const char*, ...); /* Put a formatted string to the file */ +char* f_gets (char*, int, FIL*); /* Get a string from the file */ +#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0) +#define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0) +#ifndef EOF +#define EOF -1 +#endif +#endif + + + +/*--------------------------------------------------------------*/ +/* User defined functions */ + +/* Real time clock */ +#if !_FS_READONLY +DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */ + /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ +#endif + +/* Unicode - OEM code conversion */ +#if _USE_LFN +WCHAR ff_convert (WCHAR, UINT); +WCHAR ff_wtoupper (WCHAR); +#endif + +/* Sync functions */ +#if _FS_REENTRANT +BOOL ff_cre_syncobj(BYTE, _SYNC_t*); +BOOL ff_del_syncobj(_SYNC_t); +BOOL ff_req_grant(_SYNC_t); +void ff_rel_grant(_SYNC_t); +#endif + + + +/*--------------------------------------------------------------*/ +/* Flags and offset address */ + + +/* File access control and file status flags (FIL.flag) */ + +#define FA_READ 0x01 +#define FA_OPEN_EXISTING 0x00 +#if _FS_READONLY == 0 +#define FA_WRITE 0x02 +#define FA_CREATE_NEW 0x04 +#define FA_CREATE_ALWAYS 0x08 +#define FA_OPEN_ALWAYS 0x10 +#define FA__WRITTEN 0x20 +#define FA__DIRTY 0x40 +#endif +#define FA__ERROR 0x80 + + +/* FAT sub type (FATFS.fs_type) */ + +#define FS_FAT12 1 +#define FS_FAT16 2 +#define FS_FAT32 3 + + +/* File attribute bits for directory entry */ + +#define AM_RDO 0x01 /* Read only */ +#define AM_HID 0x02 /* Hidden */ +#define AM_SYS 0x04 /* System */ +#define AM_VOL 0x08 /* Volume label */ +#define AM_LFN 0x0F /* LFN entry */ +#define AM_DIR 0x10 /* Directory */ +#define AM_ARC 0x20 /* Archive */ +#define AM_MASK 0x3F /* Mask of defined bits */ + + +/* FatFs refers the members in the FAT structures with byte offset instead +/ of structure member because there are incompatibility of the packing option +/ between various compilers. */ + +#define BS_jmpBoot 0 +#define BS_OEMName 3 +#define BPB_BytsPerSec 11 +#define BPB_SecPerClus 13 +#define BPB_RsvdSecCnt 14 +#define BPB_NumFATs 16 +#define BPB_RootEntCnt 17 +#define BPB_TotSec16 19 +#define BPB_Media 21 +#define BPB_FATSz16 22 +#define BPB_SecPerTrk 24 +#define BPB_NumHeads 26 +#define BPB_HiddSec 28 +#define BPB_TotSec32 32 +#define BS_55AA 510 + +#define BS_DrvNum 36 +#define BS_BootSig 38 +#define BS_VolID 39 +#define BS_VolLab 43 +#define BS_FilSysType 54 + +#define BPB_FATSz32 36 +#define BPB_ExtFlags 40 +#define BPB_FSVer 42 +#define BPB_RootClus 44 +#define BPB_FSInfo 48 +#define BPB_BkBootSec 50 +#define BS_DrvNum32 64 +#define BS_BootSig32 66 +#define BS_VolID32 67 +#define BS_VolLab32 71 +#define BS_FilSysType32 82 + +#define FSI_LeadSig 0 +#define FSI_StrucSig 484 +#define FSI_Free_Count 488 +#define FSI_Nxt_Free 492 + +#define MBR_Table 446 + +#define DIR_Name 0 +#define DIR_Attr 11 +#define DIR_NTres 12 +#define DIR_CrtTime 14 +#define DIR_CrtDate 16 +#define DIR_FstClusHI 20 +#define DIR_WrtTime 22 +#define DIR_WrtDate 24 +#define DIR_FstClusLO 26 +#define DIR_FileSize 28 +#define LDIR_Ord 0 +#define LDIR_Attr 11 +#define LDIR_Type 12 +#define LDIR_Chksum 13 +#define LDIR_FstClusLO 26 + + + +/*--------------------------------*/ +/* Multi-byte word access macros */ + +#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */ +#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) +#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) +#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) +#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) +#else /* Use byte-by-byte access to the FAT structure */ +#define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) +#define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr)) +#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8) +#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24) +#endif + + +#endif /* _FATFS */ diff --git a/macusbfb/drivers/fatfs/ffconf.h b/macusbfb/drivers/fatfs/ffconf.h new file mode 100644 index 0000000..c543fc4 --- /dev/null +++ b/macusbfb/drivers/fatfs/ffconf.h @@ -0,0 +1,166 @@ +/*---------------------------------------------------------------------------/ +/ FatFs - FAT file system module configuration file R0.07e (C)ChaN, 2009 +/----------------------------------------------------------------------------/ +/ +/ CAUTION! Do not forget to make clean the project after any changes to +/ the configuration options. +/ +/----------------------------------------------------------------------------*/ +#ifndef _FFCONFIG +#define _FFCONFIG 0x007E + + +/*---------------------------------------------------------------------------/ +/ Function and Buffer Configurations +/----------------------------------------------------------------------------*/ + +#define _FS_TINY 1 /* 0 or 1 */ +/* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system +/ object instead of the sector buffer in the individual file object for file +/ data transfer. This reduces memory consumption 512 bytes each file object. */ + + +#define _FS_READONLY 0 /* 0 or 1 */ +/* Setting _FS_READONLY to 1 defines read only configuration. This removes +/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename, +/ f_truncate and useless f_getfree. */ + + +#define _FS_MINIMIZE 1 /* 0, 1, 2 or 3 */ +/* The _FS_MINIMIZE option defines minimization level to remove some functions. +/ +/ 0: Full function. +/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename +/ are removed. +/ 2: f_opendir and f_readdir are removed in addition to level 1. +/ 3: f_lseek is removed in addition to level 2. */ + + +#define _USE_STRFUNC 0 /* 0, 1 or 2 */ +/* To enable string functions, set _USE_STRFUNC to 1 or 2. */ + + +#define _USE_MKFS 0 /* 0 or 1 */ +/* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */ + + +#define _USE_FORWARD 0 /* 0 or 1 */ +/* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */ + + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/----------------------------------------------------------------------------*/ + +#define _CODE_PAGE 858 +/* The _CODE_PAGE specifies the OEM code page to be used on the target system. +/ Incorrect setting of the code page can cause a file open failure. +/ +/ 932 - Japanese Shift-JIS (DBCS, OEM, Windows) +/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows) +/ 949 - Korean (DBCS, OEM, Windows) +/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows) +/ 1250 - Central Europe (Windows) +/ 1251 - Cyrillic (Windows) +/ 1252 - Latin 1 (Windows) +/ 1253 - Greek (Windows) +/ 1254 - Turkish (Windows) +/ 1255 - Hebrew (Windows) +/ 1256 - Arabic (Windows) +/ 1257 - Baltic (Windows) +/ 1258 - Vietnam (OEM, Windows) +/ 437 - U.S. (OEM) +/ 720 - Arabic (OEM) +/ 737 - Greek (OEM) +/ 775 - Baltic (OEM) +/ 850 - Multilingual Latin 1 (OEM) +/ 858 - Multilingual Latin 1 + Euro (OEM) +/ 852 - Latin 2 (OEM) +/ 855 - Cyrillic (OEM) +/ 866 - Russian (OEM) +/ 857 - Turkish (OEM) +/ 862 - Hebrew (OEM) +/ 874 - Thai (OEM, Windows) +/ 1 - ASCII only (Valid for non LFN cfg.) +*/ + + +#define _USE_LFN 0 /* 0, 1 or 2 */ +#define _MAX_LFN 64 /* Maximum LFN length to handle (12 to 255) */ +/* The _USE_LFN option switches the LFN support. +/ +/ 0: Disable LFN. _MAX_LFN and _LFN_UNICODE have no effect. +/ 1: Enable LFN with static working buffer on the bss. NOT REENTRANT. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ +/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When enable LFN, +/ two Unicode handling functions ff_convert() and ff_wtoupper() must be added +/ to the project. */ + + +#define _LFN_UNICODE 0 /* 0 or 1 */ +/* To switch the character code set on FatFs API to Unicode, +/ enable LFN feature and set _LFN_UNICODE to 1. +*/ + + +#define _FS_RPATH 0 /* 0 or 1 */ +/* When _FS_RPATH is set to 1, relative path feature is enabled and f_chdir, +/ f_chdrive function are available. +/ Note that output of the f_readdir fnction is affected by this option. */ + + + +/*---------------------------------------------------------------------------/ +/ Physical Drive Configurations +/----------------------------------------------------------------------------*/ + +#define _DRIVES 2 +/* Number of volumes (logical drives) to be used. */ + + +#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */ +/* Maximum sector size to be handled. +/ Always set 512 for memory card and hard disk but a larger value may be +/ required for floppy disk (512/1024) and optical disk (512/2048). +/ When _MAX_SS is larger than 512, GET_SECTOR_SIZE command must be implememted +/ to the disk_ioctl function. */ + + +#define _MULTI_PARTITION 0 /* 0 or 1 */ +/* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical +/ drive number and can mount only first primaly partition. When it is set to 1, +/ each volume is tied to the partitions listed in Drives[]. */ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/----------------------------------------------------------------------------*/ + +#define _WORD_ACCESS 0 /* 0 or 1 */ +/* The _WORD_ACCESS option defines which access method is used to the word +/ data on the FAT volume. +/ +/ 0: Byte-by-byte access. Always compatible with all platforms. +/ 1: Word access. Do not choose this unless following condition is met. +/ +/ When the byte order on the memory is big-endian or address miss-aligned +/ word access results incorrect behavior, the _WORD_ACCESS must be set to 0. +/ If it is not the case, the value can also be set to 1 to improve the +/ performance and code size. */ + + +#define _FS_REENTRANT 0 /* 0 or 1 */ +#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ +#define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */ +/* The _FS_REENTRANT option switches the reentrancy of the FatFs module. +/ +/ 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect. +/ 1: Enable reentrancy. Also user provided synchronization handlers, +/ ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj +/ function must be added to the project. */ + + +#endif /* _FFCONFIG */ diff --git a/macusbfb/drivers/fatfs/integer.h b/macusbfb/drivers/fatfs/integer.h new file mode 100644 index 0000000..3b39dfb --- /dev/null +++ b/macusbfb/drivers/fatfs/integer.h @@ -0,0 +1,34 @@ +/*-------------------------------------------*/ +/* Integer type definitions for FatFs module */ +/*-------------------------------------------*/ + +#ifndef _INTEGER + +#if 0 +#include +#else + +/* These types must be 16-bit, 32-bit or larger integer */ +typedef int INT; +typedef unsigned int UINT; + +/* These types must be 8-bit integer */ +typedef signed char CHAR; +typedef unsigned char UCHAR; +typedef unsigned char BYTE; + +/* These types must be 16-bit integer */ +typedef short SHORT; +typedef unsigned short USHORT; +typedef unsigned short WORD; +typedef unsigned short WCHAR; + +/* These types must be 32-bit integer */ +typedef long LONG; +typedef unsigned long ULONG; +typedef unsigned long DWORD; + +#endif + +#define _INTEGER +#endif diff --git a/macusbfb/drivers/fatfs/mmc.c b/macusbfb/drivers/fatfs/mmc.c new file mode 100644 index 0000000..936b00f --- /dev/null +++ b/macusbfb/drivers/fatfs/mmc.c @@ -0,0 +1,669 @@ +/*-----------------------------------------------------------------------*/ +/* MMCv3/SDv1/SDv2 (in SPI mode) control module (C)ChaN, 2007 */ +/*-----------------------------------------------------------------------*/ +/* Only rcvr_spi(), xmit_spi(), disk_timerproc() and some macros */ +/* are platform dependent. */ +/*-----------------------------------------------------------------------*/ + + +#include "projectconfig.h" +#include "diskio.h" +#include "core/gpio/gpio.h" +#include "core/ssp/ssp.h" +#include "core/systick/systick.h" + + +/* Definitions for MMC/SDC command */ +#define CMD0 (0x40+0) /* GO_IDLE_STATE */ +#define CMD1 (0x40+1) /* SEND_OP_COND (MMC) */ +#define ACMD41 (0xC0+41) /* SEND_OP_COND (SDC) */ +#define CMD8 (0x40+8) /* SEND_IF_COND */ +#define CMD9 (0x40+9) /* SEND_CSD */ +#define CMD10 (0x40+10) /* SEND_CID */ +#define CMD12 (0x40+12) /* STOP_TRANSMISSION */ +#define ACMD13 (0xC0+13) /* SD_STATUS (SDC) */ +#define CMD16 (0x40+16) /* SET_BLOCKLEN */ +#define CMD17 (0x40+17) /* READ_SINGLE_BLOCK */ +#define CMD18 (0x40+18) /* READ_MULTIPLE_BLOCK */ +#define CMD23 (0x40+23) /* SET_BLOCK_COUNT (MMC) */ +#define ACMD23 (0xC0+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */ +#define CMD24 (0x40+24) /* WRITE_BLOCK */ +#define CMD25 (0x40+25) /* WRITE_MULTIPLE_BLOCK */ +#define CMD55 (0x40+55) /* APP_CMD */ +#define CMD58 (0x40+58) /* READ_OCR */ + + +/* Port Controls (Platform dependent) */ +#define CS_LOW() gpioSetValue(SSP0_CSPORT, SSP0_CSPIN, 0) +#define CS_HIGH() gpioSetValue(SSP0_CSPORT, SSP0_CSPIN, 1) + +// #define FCLK_SLOW() /* Set slow clock (100k-400k) */ +// #define FCLK_FAST() /* Set fast clock (depends on the CSD) */ + +#define FDELAY(ms) systickDelay(ms) // Assumes delay = 1ms, ugly + +/*-------------------------------------------------------------------------- + + Module Private Functions + +---------------------------------------------------------------------------*/ + +static volatile +DSTATUS Stat = STA_NOINIT; /* Disk status */ + +static volatile +BYTE Timer1, Timer2; /* 100Hz decrement timer */ + +static +BYTE CardType; /* Card type flags */ + +/**************************************************************************/ +/*! + Set SSP clock to slow (400 KHz) +*/ +/**************************************************************************/ +static void FCLK_SLOW() +{ + /* Divide by 10 (SSPCLKDIV also enables to SSP CLK) */ + SCB_SSP0CLKDIV = SCB_SSP0CLKDIV_DIV10; + + /* (PCLK / (CPSDVSR × [SCR+1])) = (7,200,000 / (2 x [8 + 1])) = 400 KHz */ + uint32_t configReg = ( SSP_SSP0CR0_DSS_8BIT // Data size = 8-bit + | SSP_SSP0CR0_FRF_SPI // Frame format = SPI + | SSP_SSP0CR0_SCR_8); // Serial clock rate = 8 + + // Set clock polarity + configReg &= ~SSP_SSP0CR0_CPOL_MASK; // Clock polarity = Low between frames + + // Set edge transition + configReg &= ~SSP_SSP0CR0_CPHA_MASK; // Clock out phase = Leading edge clock transition + + // Assign config values to SSP0CR0 + SSP_SSP0CR0 = configReg; + + /* Clock prescale register must be even and at least 2 in master mode */ + SSP_SSP0CPSR = SSP_SSP0CPSR_CPSDVSR_DIV2; +} + +/**************************************************************************/ +/*! + Set SSP clock to fast (4.0 MHz) +*/ +/**************************************************************************/ +static void FCLK_FAST() +{ + /* Divide by 1 (SSPCLKDIV also enables to SSP CLK) */ + SCB_SSP0CLKDIV = SCB_SSP0CLKDIV_DIV1; + + /* (PCLK / (CPSDVSR × [SCR+1])) = (72,000,000 / (2 x [8 + 1])) = 4.0 MHz */ + uint32_t configReg = ( SSP_SSP0CR0_DSS_8BIT // Data size = 8-bit + | SSP_SSP0CR0_FRF_SPI // Frame format = SPI + | SSP_SSP0CR0_SCR_8); // Serial clock rate = 8 + + // Set clock polarity + configReg &= ~SSP_SSP0CR0_CPOL_MASK; // Clock polarity = Low between frames + + // Set edge transition + configReg &= ~SSP_SSP0CR0_CPHA_MASK; // Clock out phase = Leading edge clock transition + + // Assign config values to SSP0CR0 + SSP_SSP0CR0 = configReg; + + /* Clock prescale register must be even and at least 2 in master mode */ + SSP_SSP0CPSR = SSP_SSP0CPSR_CPSDVSR_DIV2; +} + +/*-----------------------------------------------------------------------*/ +/* Transmit a byte to MMC via SPI (Platform dependent) */ +/*-----------------------------------------------------------------------*/ + +//#define xmit_spi(dat) (SSPSend((uint8_t*)&(dat), 1)) +static void xmit_spi(BYTE dat) +{ + sspSend(0, (uint8_t*) &dat, 1); +} + + +/*-----------------------------------------------------------------------*/ +/* Receive a byte from MMC via SPI (Platform dependent) */ +/*-----------------------------------------------------------------------*/ + +static +BYTE rcvr_spi (void) +{ + BYTE data = 0; + + sspReceive(0, &data, 1); + + return data; +} + +/* Alternative macro to receive data fast */ + +#define rcvr_spi_m(dst) \ + do { \ + sspReceive(0, (uint8_t*)(dst), 1); \ + } while(0) + + + + +/*-----------------------------------------------------------------------*/ +/* Wait for card ready */ +/*-----------------------------------------------------------------------*/ + +static +BYTE wait_ready (void) +{ + BYTE res; + + + Timer2 = 50; /* Wait for ready in timeout of 500ms */ + rcvr_spi(); + do + res = rcvr_spi(); + while ((res != 0xFF) && Timer2); + + return res; +} + + + +/*-----------------------------------------------------------------------*/ +/* Deselect the card and release SPI bus */ +/*-----------------------------------------------------------------------*/ + +static +void deselect (void) +{ + CS_HIGH(); + rcvr_spi(); +} + + + +/*-----------------------------------------------------------------------*/ +/* Select the card and wait ready */ +/*-----------------------------------------------------------------------*/ + +static +BOOL select (void) /* TRUE:Successful, FALSE:Timeout */ +{ + CS_LOW(); + if (wait_ready() != 0xFF) { + deselect(); + return FALSE; + } + return TRUE; +} + + + +/*-----------------------------------------------------------------------*/ +/* Power Control (Platform dependent) */ +/*-----------------------------------------------------------------------*/ +/* When the target system does not support socket power control, there */ +/* is nothing to do in these functions and chk_power always returns 1. */ + +static +void power_on (void) +{ +} + +static +void power_off (void) +{ +} + +static +int chk_power(void) /* Socket power state: 0=off, 1=on */ +{ + return 1; +} + + + +/*-----------------------------------------------------------------------*/ +/* Receive a data packet from MMC */ +/*-----------------------------------------------------------------------*/ + +static +BOOL rcvr_datablock ( + BYTE *buff, /* Data buffer to store received data */ + UINT btr /* Byte count (must be multiple of 4) */ +) +{ + BYTE token; + + + Timer1 = 20; + do { /* Wait for data packet in timeout of 200ms */ + token = rcvr_spi(); + } while ((token == 0xFF) && Timer1); + if(token != 0xFE) return FALSE; /* If not valid data token, retutn with error */ + + do { /* Receive the data block into buffer */ + rcvr_spi_m(buff++); + rcvr_spi_m(buff++); + rcvr_spi_m(buff++); + rcvr_spi_m(buff++); + } while (btr -= 4); + rcvr_spi(); /* Discard CRC */ + rcvr_spi(); + + return TRUE; /* Return with success */ +} + + + +/*-----------------------------------------------------------------------*/ +/* Send a data packet to MMC */ +/*-----------------------------------------------------------------------*/ + +#if _READONLY == 0 +static +BOOL xmit_datablock ( + const BYTE *buff, /* 512 byte data block to be transmitted */ + BYTE token /* Data/Stop token */ +) +{ + BYTE resp, wc; + + + if (wait_ready() != 0xFF) return FALSE; + + xmit_spi(token); /* Xmit data token */ + if (token != 0xFD) { /* Is data token */ + wc = 0; + do { /* Xmit the 512 byte data block to MMC */ + xmit_spi(*buff++); + xmit_spi(*buff++); + } while (--wc); + xmit_spi(0xFF); /* CRC (Dummy) */ + xmit_spi(0xFF); + resp = rcvr_spi(); /* Reveive data response */ + if ((resp & 0x1F) != 0x05) /* If not accepted, return with error */ + return FALSE; + } + + return TRUE; +} +#endif /* _READONLY */ + + + +/*-----------------------------------------------------------------------*/ +/* Send a command packet to MMC */ +/*-----------------------------------------------------------------------*/ + +static +BYTE send_cmd ( + BYTE cmd, /* Command byte */ + DWORD arg /* Argument */ +) +{ + BYTE n, res; + + + if (cmd & 0x80) { /* ACMD is the command sequense of CMD55-CMD */ + cmd &= 0x7F; + res = send_cmd(CMD55, 0); + if (res > 1) return res; + } + + /* Select the card and wait for ready */ + deselect(); + if (!select()) return 0xFF; + + /* Send command packet */ + xmit_spi(cmd); /* Start + Command index */ + xmit_spi((BYTE)(arg >> 24)); /* Argument[31..24] */ + xmit_spi((BYTE)(arg >> 16)); /* Argument[23..16] */ + xmit_spi((BYTE)(arg >> 8)); /* Argument[15..8] */ + xmit_spi((BYTE)arg); /* Argument[7..0] */ + n = 0x01; /* Dummy CRC + Stop */ + if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */ + if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */ + xmit_spi(n); + + /* Receive command response */ + if (cmd == CMD12) rcvr_spi(); /* Skip a stuff byte when stop reading */ + n = 10; /* Wait for a valid response in timeout of 10 attempts */ + do + res = rcvr_spi(); + while ((res & 0x80) && --n); + + return res; /* Return with the response value */ +} + + + +/*-------------------------------------------------------------------------- + + Public Functions + +---------------------------------------------------------------------------*/ + + +/*-----------------------------------------------------------------------*/ +/* Initialize Disk Drive */ +/*-----------------------------------------------------------------------*/ + +DSTATUS disk_initialize ( + BYTE drv /* Physical drive nmuber (0) */ +) +{ + BYTE n, cmd, ty, ocr[4]; + + gpioSetDir( SSP0_CSPORT, SSP0_CSPIN, 1 ); /* CS */ + gpioSetDir( CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN, 0 ); /* Card Detect */ + + if (drv) return STA_NOINIT; /* Supports only single drive */ + if (Stat & STA_NODISK) return Stat; /* No card in the socket */ + + power_on(); /* Force socket power on */ + FCLK_SLOW(); + for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */ + + ty = 0; + if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */ + Timer1 = 100; /* Initialization timeout of 1000 msec */ + if (send_cmd(CMD8, 0x1AA) == 1) { /* SDHC */ + for (n = 0; n < 4; n++) ocr[n] = rcvr_spi(); /* Get trailing return value of R7 resp */ + if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */ + while (Timer1 && send_cmd(ACMD41, 1UL << 30)); /* Wait for leaving idle state (ACMD41 with HCS bit) */ + if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */ + for (n = 0; n < 4; n++) ocr[n] = rcvr_spi(); + ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 */ + } + } + } else { /* SDSC or MMC */ + if (send_cmd(ACMD41, 0) <= 1) { + ty = CT_SD1; cmd = ACMD41; /* SDv1 */ + } else { + ty = CT_MMC; cmd = CMD1; /* MMCv3 */ + } + while (Timer1 && send_cmd(cmd, 0)); /* Wait for leaving idle state */ + if (!Timer1 || send_cmd(CMD16, 512) != 0) /* Set R/W block length to 512 */ + ty = 0; + } + } + CardType = ty; + deselect(); + + if (ty) { /* Initialization succeded */ + Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */ + FCLK_FAST(); + } else { /* Initialization failed */ + power_off(); + } + + return Stat; +} + + + +/*-----------------------------------------------------------------------*/ +/* Get Disk Status */ +/*-----------------------------------------------------------------------*/ + +DSTATUS disk_status ( + BYTE drv /* Physical drive nmuber (0) */ +) +{ + if (drv) return STA_NOINIT; /* Supports only single drive */ + return Stat; +} + + + +/*-----------------------------------------------------------------------*/ +/* Read Sector(s) */ +/*-----------------------------------------------------------------------*/ + +DRESULT disk_read ( + BYTE drv, /* Physical drive nmuber (0) */ + BYTE *buff, /* Pointer to the data buffer to store read data */ + DWORD sector, /* Start sector number (LBA) */ + BYTE count /* Sector count (1..255) */ +) +{ + if (drv || !count) return RES_PARERR; + if (Stat & STA_NOINIT) return RES_NOTRDY; + + if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */ + + if (count == 1) { /* Single block read */ + if ((send_cmd(CMD17, sector) == 0) /* READ_SINGLE_BLOCK */ + && rcvr_datablock(buff, 512)) + count = 0; + } + else { /* Multiple block read */ + if (send_cmd(CMD18, sector) == 0) { /* READ_MULTIPLE_BLOCK */ + do { + if (!rcvr_datablock(buff, 512)) break; + buff += 512; + } while (--count); + send_cmd(CMD12, 0); /* STOP_TRANSMISSION */ + } + } + deselect(); + + return count ? RES_ERROR : RES_OK; +} + + + +/*-----------------------------------------------------------------------*/ +/* Write Sector(s) */ +/*-----------------------------------------------------------------------*/ + +#if _READONLY == 0 +DRESULT disk_write ( + BYTE drv, /* Physical drive nmuber (0) */ + const BYTE *buff, /* Pointer to the data to be written */ + DWORD sector, /* Start sector number (LBA) */ + BYTE count /* Sector count (1..255) */ +) +{ + if (drv || !count) return RES_PARERR; + if (Stat & STA_NOINIT) return RES_NOTRDY; + if (Stat & STA_PROTECT) return RES_WRPRT; + + if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */ + + if (count == 1) { /* Single block write */ + if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */ + && xmit_datablock(buff, 0xFE)) + count = 0; + } + else { /* Multiple block write */ + if (CardType & CT_SDC) send_cmd(ACMD23, count); + if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */ + do { + if (!xmit_datablock(buff, 0xFC)) break; + buff += 512; + } while (--count); + if (!xmit_datablock(0, 0xFD)) /* STOP_TRAN token */ + count = 1; + } + } + deselect(); + + return count ? RES_ERROR : RES_OK; +} +#endif /* _READONLY == 0 */ + + + +/*-----------------------------------------------------------------------*/ +/* Miscellaneous Functions */ +/*-----------------------------------------------------------------------*/ + +#if _USE_IOCTL != 0 +DRESULT disk_ioctl ( + BYTE drv, /* Physical drive nmuber (0) */ + BYTE ctrl, /* Control code */ + void *buff /* Buffer to send/receive control data */ +) +{ + DRESULT res; + BYTE n, csd[16], *ptr = buff; + WORD csize; + + + if (drv) return RES_PARERR; + + res = RES_ERROR; + + if (ctrl == CTRL_POWER) { + switch (*ptr) { + case 0: /* Sub control code == 0 (POWER_OFF) */ + if (chk_power()) + power_off(); /* Power off */ + res = RES_OK; + break; + case 1: /* Sub control code == 1 (POWER_ON) */ + power_on(); /* Power on */ + res = RES_OK; + break; + case 2: /* Sub control code == 2 (POWER_GET) */ + *(ptr+1) = (BYTE)chk_power(); + res = RES_OK; + break; + default : + res = RES_PARERR; + } + } + else { + if (Stat & STA_NOINIT) return RES_NOTRDY; + + switch (ctrl) { + case CTRL_SYNC : /* Make sure that no pending write process. Do not remove this or written sector might not left updated. */ + if (select()) { + res = RES_OK; + deselect(); + } + break; + + case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */ + if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) { + if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */ + csize = csd[9] + ((WORD)csd[8] << 8) + 1; + *(DWORD*)buff = (DWORD)csize << 10; + } else { /* SDC ver 1.XX or MMC*/ + n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2; + csize = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1; + *(DWORD*)buff = (DWORD)csize << (n - 9); + } + res = RES_OK; + } + break; + + case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */ + *(WORD*)buff = 512; + res = RES_OK; + break; + + case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */ + if (CardType & CT_SD2) { /* SDC ver 2.00 */ + if (send_cmd(ACMD13, 0) == 0) { /* Read SD status */ + rcvr_spi(); + if (rcvr_datablock(csd, 16)) { /* Read partial block */ + for (n = 64 - 16; n; n--) rcvr_spi(); /* Purge trailing data */ + *(DWORD*)buff = 16UL << (csd[10] >> 4); + res = RES_OK; + } + } + } else { /* SDC ver 1.XX or MMC */ + if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) { /* Read CSD */ + if (CardType & CT_SD1) { /* SDC ver 1.XX */ + *(DWORD*)buff = (((csd[10] & 63) << 1) + ((WORD)(csd[11] & 128) >> 7) + 1) << ((csd[13] >> 6) - 1); + } else { /* MMC */ + *(DWORD*)buff = ((WORD)((csd[10] & 124) >> 2) + 1) * (((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1); + } + res = RES_OK; + } + } + break; + + case MMC_GET_TYPE : /* Get card type flags (1 byte) */ + *ptr = CardType; + res = RES_OK; + break; + + case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */ + if (send_cmd(CMD9, 0) == 0 /* READ_CSD */ + && rcvr_datablock(ptr, 16)) + res = RES_OK; + break; + + case MMC_GET_CID : /* Receive CID as a data block (16 bytes) */ + if (send_cmd(CMD10, 0) == 0 /* READ_CID */ + && rcvr_datablock(ptr, 16)) + res = RES_OK; + break; + + case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */ + if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */ + for (n = 4; n; n--) *ptr++ = rcvr_spi(); + res = RES_OK; + } + break; + + case MMC_GET_SDSTAT : /* Receive SD statsu as a data block (64 bytes) */ + if (send_cmd(ACMD13, 0) == 0) { /* SD_STATUS */ + rcvr_spi(); + if (rcvr_datablock(ptr, 64)) + res = RES_OK; + } + break; + + default: + res = RES_PARERR; + } + + deselect(); + } + + return res; +} +#endif /* _USE_IOCTL != 0 */ + + +/*-----------------------------------------------------------------------*/ +/* Device Timer Interrupt Procedure (Platform dependent) */ +/*-----------------------------------------------------------------------*/ +/* This function must be called in period of 10ms */ + +void disk_timerproc (void) +{ + static BYTE pv; + BYTE n, s; + + + n = Timer1; /* 100Hz decrement timer */ + if (n) Timer1 = --n; + n = Timer2; + if (n) Timer2 = --n; + + n = pv; + // pv = SOCKPORT & (SOCKWP | SOCKINS); /* Sample socket switch */ + pv = 0; // gpioGetValue( 0, 1 ); + +// if (n == pv) { /* Have contacts stabled? */ +// s = Stat; +// +// /* write protect NOT supported */ +// +// /* check card detect */ +// if (pv) /* (Socket empty) */ +// s |= (STA_NODISK | STA_NOINIT); +// else /* (Card inserted) */ +// s &= ~STA_NODISK; +// +// Stat = s; +// } +} + + diff --git a/macusbfb/drivers/lcd/drawing.c b/macusbfb/drivers/lcd/drawing.c new file mode 100644 index 0000000..089fd7e --- /dev/null +++ b/macusbfb/drivers/lcd/drawing.c @@ -0,0 +1,688 @@ +/**************************************************************************/ +/*! + @file drawing.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + drawLine and drawCircle adapted from a tutorial by Leonard McMillan: + http://www.cs.unc.edu/~mcmillan/ + + drawString based on an example from Eran Duchan: + http://www.pavius.net/downloads/tools/53-the-dot-factory + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include + +#include "drawing.h" + +/**************************************************************************/ +/* */ +/* ----------------------- Private Methods ------------------------------ */ +/* */ +/**************************************************************************/ + +/**************************************************************************/ +/*! + @brief Draws a single bitmap character +*/ +/**************************************************************************/ +static void drawCharBitmap(const uint16_t xPixel, const uint16_t yPixel, uint16_t color, const uint8_t *glyph, uint8_t glyphHeightPages, uint8_t glyphWidthBits) +{ + uint16_t verticalPage, horizBit, currentY, currentX; + uint16_t indexIntoGlyph; + + // set initial current y + currentY = yPixel; + currentX = xPixel; + + // for each page of the glyph + for (verticalPage = glyphHeightPages; verticalPage > 0; --verticalPage) + { + // for each horizontol bit + for (horizBit = 0; horizBit < glyphWidthBits; ++horizBit) + { + // next byte + indexIntoGlyph = (glyphHeightPages * horizBit) + verticalPage - 1; + + currentX = xPixel + (horizBit); + // send the data byte + if (glyph[indexIntoGlyph] & (0X80)) drawPixel(currentX, currentY, color); + if (glyph[indexIntoGlyph] & (0X40)) drawPixel(currentX, currentY - 1, color); + if (glyph[indexIntoGlyph] & (0X20)) drawPixel(currentX, currentY - 2, color); + if (glyph[indexIntoGlyph] & (0X10)) drawPixel(currentX, currentY - 3, color); + if (glyph[indexIntoGlyph] & (0X08)) drawPixel(currentX, currentY - 4, color); + if (glyph[indexIntoGlyph] & (0X04)) drawPixel(currentX, currentY - 5, color); + if (glyph[indexIntoGlyph] & (0X02)) drawPixel(currentX, currentY - 6, color); + if (glyph[indexIntoGlyph] & (0X01)) drawPixel(currentX, currentY - 7, color); + } + // next line of pages + currentY += 8; + } +} + +#if defined CFG_LCD_INCLUDESMALLFONTS & CFG_LCD_INCLUDESMALLFONTS == 1 +/**************************************************************************/ +/*! + @brief Draws a single smallfont character +*/ +/**************************************************************************/ +static void drawCharSmall(uint16_t x, uint16_t y, uint16_t color, uint8_t c, struct FONT_DEF font) +{ + uint8_t col, column[font.u8Width]; + + // Check if the requested character is available + if ((c >= font.u8FirstChar) && (c <= font.u8LastChar)) + { + // Retrieve appropriate columns from font data + for (col = 0; col < font.u8Width; col++) + { + column[col] = font.au8FontTable[((c - 32) * font.u8Width) + col]; // Get first column of appropriate character + } + } + else + { + // Requested character is not available in this font ... send a space instead + for (col = 0; col < font.u8Width; col++) + { + column[col] = 0xFF; // Send solid space + } + } + + // Render each column + uint16_t xoffset, yoffset; + for (xoffset = 0; xoffset < font.u8Width; xoffset++) + { + for (yoffset = 0; yoffset < (font.u8Height + 1); yoffset++) + { + uint8_t bit = 0x00; + bit = (column[xoffset] << (8 - (yoffset + 1))); // Shift current row bit left + bit = (bit >> 7); // Shift current row but right (results in 0x01 for black, and 0x00 for white) + if (bit) + { + drawPixel(x + xoffset, y + yoffset, color); + } + } + } +} +#endif + +/**************************************************************************/ +/*! + @brief Helper method to accurately draw individual circle points +*/ +/**************************************************************************/ +static void drawCirclePoints(int cx, int cy, int x, int y, uint16_t color) +{ + if (x == 0) + { + drawPixel(cx, cy + y, color); + drawPixel(cx, cy - y, color); + drawPixel(cx + y, cy, color); + drawPixel(cx - y, cy, color); + } + else if (x == y) + { + drawPixel(cx + x, cy + y, color); + drawPixel(cx - x, cy + y, color); + drawPixel(cx + x, cy - y, color); + drawPixel(cx - x, cy - y, color); + } + else if (x < y) + { + drawPixel(cx + x, cy + y, color); + drawPixel(cx - x, cy + y, color); + drawPixel(cx + x, cy - y, color); + drawPixel(cx - x, cy - y, color); + drawPixel(cx + y, cy + x, color); + drawPixel(cx - y, cy + x, color); + drawPixel(cx + y, cy - x, color); + drawPixel(cx - y, cy - x, color); + } +} + +/**************************************************************************/ +/* */ +/* ----------------------- Public Methods ------------------------------- */ +/* */ +/**************************************************************************/ + +/**************************************************************************/ +/*! + @brief Draws a single pixel at the specified location + + @param[in] x + Horizontal position + @param[in] y + Vertical position + @param[in] color + Color used when drawing +*/ +/**************************************************************************/ +void drawPixel(uint16_t x, uint16_t y, uint16_t color) +{ + // Redirect to LCD + lcdDrawPixel(x, y, color); +} + +/**************************************************************************/ +/*! + @brief Fills the screen with the specified color + + @param[in] color + Color used when drawing +*/ +/**************************************************************************/ +void drawFill(uint16_t color) +{ + lcdFillRGB(color); +} + +/**************************************************************************/ +/*! + @brief Draws a simple color test pattern +*/ +/**************************************************************************/ +void drawTestPattern(void) +{ + lcdTest(); +} + +#if defined CFG_LCD_INCLUDESMALLFONTS & CFG_LCD_INCLUDESMALLFONTS == 1 +/**************************************************************************/ +/*! + @brief Draws a string using a small font (6 of 8 pixels high). + + @param[in] x + Starting x co-ordinate + @param[in] y + Starting y co-ordinate + @param[in] color + Color to use when rendering the font + @param[in] text + The string to render + @param[in] font + Pointer to the FONT_DEF to use when drawing the string + + @section Example + + @code + + #include "drivers/lcd/fonts/smallfonts.h" + + drawStringSmall(1, 210, WHITE, "5x8 System (Max 40 Characters)", Font_System5x8); + drawStringSmall(1, 220, WHITE, "7x8 System (Max 30 Characters)", Font_System7x8); + + @endcode +*/ +/**************************************************************************/ +void drawStringSmall(uint16_t x, uint16_t y, uint16_t color, char* text, struct FONT_DEF font) +{ + uint8_t l; + for (l = 0; l < strlen(text); l++) + { + drawCharSmall(x + (l * (font.u8Width + 1)), y, color, text[l], font); + } +} +#endif + +/**************************************************************************/ +/*! + @brief Draws a string using the supplied font + + @param[in] x + Starting x co-ordinate + @param[in] y + Starting y co-ordinate + @param[in] color + Color to use when rendering the font + @param[in] fontInfo + Pointer to the FONT_INFO to use when drawing the string + @param[in] str + The string to render + + @section Example + + @code + + #include "drivers/lcd/fonts/consolas9.h" + + drawString(1, 90, GREEN, &consolas9ptFontInfo, "Consolas 9 (38 chars wide)"); + drawString(1, 105, GREEN, &consolas9ptFontInfo, "12345678901234567890123456789012345678"); + + @endcode +*/ +/**************************************************************************/ +void drawString(uint16_t x, uint16_t y, uint16_t color, const FONT_INFO *fontInfo, char *str) +{ + uint16_t currentX, charWidth, characterToOutput; + const FONT_CHAR_INFO *charInfo; + uint16_t charOffset; + + // set current x, y to that of requested + currentX = x; + + // while not NULL + while (*str != 0) + { + // get character to output + characterToOutput = *str; + + // get char info + charInfo = fontInfo->charInfo; + + // some fonts have character descriptors, some don't + if (charInfo != NULL) + { + // get correct char offset + charInfo += (characterToOutput - fontInfo->startChar); + + // get width from char info + charWidth = charInfo->widthBits; + + // get offset from char info + charOffset = charInfo->offset; + } + else + { + // if no char info, char width is always 5 + charWidth = 5; + + // char offset - assume 5 * letter offset + charOffset = (characterToOutput - fontInfo->startChar) * 5; + } + + // Send individual characters + drawCharBitmap(currentX, y, color, &fontInfo->data[charOffset], fontInfo->heightPages, charWidth); + + // next char X + currentX += charWidth + 1; + + // next char + str++; + } +} + +/**************************************************************************/ +/*! + @brief Returns the width in pixels of a string when it is rendered + + This method can be used to determine whether a string will fit + inside a specific area, or if it needs to be broken up into multiple + lines to be properly rendered on the screen. + + This function only applied to bitmap fonts (which can have variable + widths). All smallfonts (if available) are fixed width and can + easily have their width calculated without costly functions like + this one. + + @param[in] fontInfo + Pointer to the FONT_INFO for the font that will be used + @param[in] str + The string that will be rendered +*/ +/**************************************************************************/ +uint32_t drawGetStringWidth(const FONT_INFO *fontInfo, char *str) +{ + uint32_t currChar, width = 0; + uint32_t startChar = fontInfo->startChar; + + // until termination + for (currChar = *str; currChar; currChar = *(++str)) + { + // if char info exists for the font, use width from there + if (fontInfo->charInfo != NULL) + { + width += fontInfo->charInfo[currChar - startChar].widthBits + 1; + } + else + { + width += 5 + 1; + } + } + + /* return the wdith */ + return width; +} + +/**************************************************************************/ +/*! + @brief Draws a Bresenham line + + Based on: http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html + + @param[in] x0 + Starting x co-ordinate + @param[in] y0 + Starting y co-ordinate + @param[in] x1 + Ending x co-ordinate + @param[in] y1 + Ending y co-ordinate + @param[in] color + Color used when drawing +*/ +/**************************************************************************/ +void drawLine ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color ) +{ + // Check if we can used the optimised horizontal line method + if (y0 == y1) + { + lcdDrawHLine(x0, x1, y0, color); + return; + } + + // Draw non horizontal line + int dy = y1 - y0; + int dx = x1 - x0; + int stepx, stepy; + + if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; } + if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } + dy <<= 1; // dy is now 2*dy + dx <<= 1; // dx is now 2*dx + + drawPixel(x0, y0, color); + if (dx > dy) + { + int fraction = dy - (dx >> 1); // same as 2*dy - dx + while (x0 != x1) + { + if (fraction >= 0) + { + y0 += stepy; + fraction -= dx; // same as fraction -= 2*dx + } + x0 += stepx; + fraction += dy; // same as fraction -= 2*dy + drawPixel(x0, y0, color); + } + } + else + { + int fraction = dx - (dy >> 1); + while (y0 != y1) + { + if (fraction >= 0) + { + x0 += stepx; + fraction -= dy; + } + y0 += stepy; + fraction += dx; + drawPixel(x0, y0, color); + } + } +} + +/**************************************************************************/ +/*! + @brief Draws a circle + + Based on: http://www.cs.unc.edu/~mcmillan/comp136/Lecture7/circle.html + + @param[in] xCenter + The horizontal center of the circle + @param[in] yCenter + The vertical center of the circle + @param[in] radius + The circle's radius in pixels + @param[in] color + Color used when drawing +*/ +/**************************************************************************/ +void drawCircle (uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint16_t color) +{ + int x = 0; + int y = radius; + int p = (5 - radius*4)/4; + + drawCirclePoints(xCenter, yCenter, x, y, color); + while (x < y) + { + x++; + if (p < 0) + { + p += 2*x+1; + } + else + { + y--; + p += 2*(x-y)+1; + } + drawCirclePoints(xCenter, yCenter, x, y, color); + } +} + +/**************************************************************************/ +/*! + @brief Draws a simple (empty) rectangle + + @param[in] x0 + Starting x co-ordinate + @param[in] y0 + Starting y co-ordinate + @param[in] x1 + Ending x co-ordinate + @param[in] y1 + Ending y co-ordinate + @param[in] color + Color used when drawing +*/ +/**************************************************************************/ +void drawRectangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) +{ + uint16_t x, y; + + if (y1 < y0) + { + // Swich y1 and y0 + y = y1; + y1 = y0; + y0 = y; + } + + if (x1 < x0) + { + // Swich x1 and x0 + x = x1; + x1 = x0; + x0 = x; + } + + drawLine (x0, y0, x1, y0, color); + drawLine (x1, y0, x1, y1, color); + drawLine (x1, y1, x0, y1, color); + drawLine (x0, y1, x0, y0, color); +} + +/**************************************************************************/ +/*! + @brief Draws a filled rectangle + + @param[in] x0 + Starting x co-ordinate + @param[in] y0 + Starting y co-ordinate + @param[in] x1 + Ending x co-ordinate + @param[in] y1 + Ending y co-ordinate + @param[in] color + Color used when drawing +*/ +/**************************************************************************/ +void drawRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) +{ + int height; + uint16_t x, y; + + if (y1 < y0) + { + // Swich y1 and y0 + y = y1; + y1 = y0; + y0 = y; + } + + if (x1 < x0) + { + // Swich x1 and x0 + x = x1; + x1 = x0; + x0 = x; + } + + height = y1 - y0; + for (height = y0; y1 > height - 1; ++height) + { + drawLine(x0, height, x1, height, color); + } +} + +/**************************************************************************/ +/*! + @brief Converts a 24-bit RGB color to an equivalent 16-bit RGB565 value + + @param[in] r + 8-bit red + @param[in] g + 8-bit green + @param[in] b + 8-bit blue + + @section Example + + @code + + // Get 16-bit equivalent of 24-bit color + uint16_t gray = drawRGB24toRGB565(0x33, 0x33, 0x33); + + @endcode +*/ +/**************************************************************************/ +uint16_t drawRGB24toRGB565(uint8_t r, uint8_t g, uint8_t b) +{ + return ((r / 8) << 11) | ((g / 4) << 5) | (b / 8); +} + +/**************************************************************************/ +/*! + @brief Draws a progress bar with rounded corners + + @param[in] x + Starting x location + @param[in] y + Starting y location + @param[in] width + Total width of the progress bar in pixels + @param[in] borderColor + 16-bit color for the outer border + @param[in] fillColor + 16-bit color for the outer border fill + @param[in] barBorderColor + 16-bit color for the inner bar's border + @param[in] barFillColor + 16-bit color for the inner bar's fill + @param[in] progress + Progress percentage (between 0 and 100) + + @section Example + + @code + + // Get 16-bit equivalent of 24-bit color + uint16_t gray = drawRGB24toRGB565(0x33, 0x33, 0x33); + + // Draw a the progress bar + drawProgressBar(10, 200, 100, 20, WHITE, gray, WHITE, BLUE, 90); + + @endcode +*/ +/**************************************************************************/ +void drawProgressBar ( uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t borderColor, uint16_t fillColor, uint16_t barBorderColor, uint16_t barFillColor, uint8_t progress ) +{ + // Draw border with rounded corners + drawLine(x+2, y, x + width - 2, y, borderColor); + drawLine(x + width, y + 2, x + width, y + height - 2, borderColor); + drawLine(x + width - 2, y + height, x + 2, y + height, borderColor); + drawLine(x, y + height - 2, x, y + 2, borderColor); + drawPixel(x + 1, y + 1, borderColor); + drawPixel(x + width - 1, y + 1, borderColor); + drawPixel(x + 1, y + height - 1, borderColor); + drawPixel(x + width - 1, y + height - 1, borderColor); + + // Fill outer container + drawLine(x+1, y+2, x+1, y+height-2, fillColor); + drawLine(x+2, y+height-1, x+width-2, y+height-1, fillColor); + drawLine(x+width-1, y+height-2, x+width-1, y+2, fillColor); + drawLine(x+width-2, y+1, x+2, y+1, fillColor); + drawRectangleFilled(x+2, y+2, x+width-2, y+height-2, fillColor); + + // Progress bar + if (progress > 0 && progress <= 100) + { + // Calculate bar size + uint16_t bw; + bw = (width - 6); // bar at 100% + if (progress != 100) + { + bw = (bw * progress) / 100; + } + drawRectangle(x + 3, y + 3, bw + x + 3, y + height - 3, barBorderColor); + drawRectangleFilled(x + 4, y + 4, bw + x + 3 - 1, y + height - 4, barFillColor); + } +} + +#ifdef CFG_SDCARD +/**************************************************************************/ +/*! + @brief Loads an image from an SD card and renders it +*/ +/**************************************************************************/ +void drawImageFromFile(uint16_t x, uint16_t y, char *filename) +{ + lcdDrawImageFromFile(x, y, filename); +} +#endif + +/**************************************************************************/ +/*! + @brief Renders a bitmap image +*/ +/**************************************************************************/ +void drawImage(uint16_t x, uint16_t y, uint16_t *data) +{ + lcdDrawImage(x, y, data); +} + + diff --git a/macusbfb/drivers/lcd/drawing.h b/macusbfb/drivers/lcd/drawing.h new file mode 100644 index 0000000..f318583 --- /dev/null +++ b/macusbfb/drivers/lcd/drawing.h @@ -0,0 +1,70 @@ +/**************************************************************************/ +/*! + @file drawing.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __DRAWING_H__ +#define __DRAWING_H__ + +#include "projectconfig.h" +#include "lcd.h" +#include "drivers/lcd/fonts/bitmapfonts.h" + +#if defined CFG_LCD_INCLUDESMALLFONTS & CFG_LCD_INCLUDESMALLFONTS == 1 + #include "drivers/lcd/fonts/smallfonts.h" +#endif + +void drawTestPattern ( void ); +void drawPixel ( uint16_t x, uint16_t y, uint16_t color ); +void drawFill ( uint16_t color ); +void drawString ( uint16_t x, uint16_t y, uint16_t color, const FONT_INFO *fontInfo, char *str ); +void drawLine ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color ); +void drawCircle ( uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint16_t color ); +void drawRectangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); +void drawRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); +void drawImage ( uint16_t x, uint16_t y, uint16_t *data ); +void drawProgressBar ( uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t borderColor, uint16_t fillColor, uint16_t barBorderColor, uint16_t barFillColor, uint8_t progress ); +uint32_t drawGetStringWidth ( const FONT_INFO *fontInfo, char *str ); +uint16_t drawRGB24toRGB565 ( uint8_t r, uint8_t g, uint8_t b ); + +#if defined CFG_LCD_INCLUDESMALLFONTS & CFG_LCD_INCLUDESMALLFONTS == 1 +void drawStringSmall ( uint16_t x, uint16_t y, uint16_t color, char* text, struct FONT_DEF font ); +#endif + +#if defined CFG_SDCARD +void drawImageFromFile ( uint16_t x, uint16_t y, char *filename ); +#endif + +#endif diff --git a/macusbfb/drivers/lcd/fonts/DotFactorySettings.png b/macusbfb/drivers/lcd/fonts/DotFactorySettings.png new file mode 100644 index 0000000..f0d87c5 Binary files /dev/null and b/macusbfb/drivers/lcd/fonts/DotFactorySettings.png differ diff --git a/macusbfb/drivers/lcd/fonts/bitmapfonts.h b/macusbfb/drivers/lcd/fonts/bitmapfonts.h new file mode 100644 index 0000000..fd6a328 --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/bitmapfonts.h @@ -0,0 +1,68 @@ +/**************************************************************************/ +/*! + @file bitmapfonts.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __BITMAPFONTS_H__ +#define __BITMAPFONTS_H__ + +#include "projectconfig.h" + +/**************************************************************************/ +/*! + @brief Describes a single character's display information +*/ +/**************************************************************************/ +typedef struct +{ + const uint8_t widthBits; // width, in bits (or pixels), of the character + const uint16_t offset; // offset of the character's bitmap, in bytes, into the the FONT_INFO's data array +} FONT_CHAR_INFO; + +/**************************************************************************/ +/*! + @brief Describes a single font +*/ +/**************************************************************************/ +typedef struct +{ + const uint8_t heightPages; // height, in pages (8 pixels), of the font's characters + const uint8_t startChar; // the first character in the font (e.g. in charInfo and data) + const FONT_CHAR_INFO* charInfo; // pointer to array of char information + const uint8_t* data; // pointer to generated array of character visual representation +} FONT_INFO; + +#endif + diff --git a/macusbfb/drivers/lcd/fonts/consolas11.c b/macusbfb/drivers/lcd/fonts/consolas11.c new file mode 100644 index 0000000..ac588d7 --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/consolas11.c @@ -0,0 +1,895 @@ +/**************************************************************************/ +/*! + @file consolas11.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include "consolas11.h" + +/* +** Font data for Consolas 11pt +*/ + +/* Character bitmaps for Consolas 11pt */ +const uint8_t consolas11ptCharBitmaps[] = +{ + /* @0 ' ' (2 pixels wide) */ + 0x00, 0x00, /* */ + 0x00, 0x00, /* */ + + /* @4 '!' (2 pixels wide) */ + 0x1B, 0xF8, /* ## ####### */ + 0x18, 0x00, /* ## */ + + /* @8 '"' (5 pixels wide) */ + 0x00, 0x38, /* ### */ + 0x00, 0x38, /* ### */ + 0x00, 0x00, /* */ + 0x00, 0x38, /* ### */ + 0x00, 0x38, /* ### */ + + /* @18 '#' (8 pixels wide) */ + 0x02, 0x40, /* # # */ + 0x1F, 0x40, /* ##### # */ + 0x02, 0xF8, /* # ##### */ + 0x02, 0x40, /* # # */ + 0x02, 0x40, /* # # */ + 0x1F, 0x40, /* ##### # */ + 0x02, 0xF8, /* # ##### */ + 0x02, 0x40, /* # # */ + + /* @34 '$' (6 pixels wide) */ + 0x10, 0x70, /* # ### */ + 0x10, 0x88, /* # # # */ + 0x7F, 0xC8, /* ######### # */ + 0x11, 0x3C, /* # # #### */ + 0x19, 0x08, /* ## # # */ + 0x0E, 0x00, /* ### */ + + /* @46 '%' (8 pixels wide) */ + 0x10, 0x30, /* # ## */ + 0x18, 0x48, /* ## # # */ + 0x06, 0x48, /* ## # # */ + 0x03, 0x30, /* ## ## */ + 0x0C, 0x80, /* ## # */ + 0x12, 0x60, /* # # ## */ + 0x12, 0x10, /* # # # */ + 0x0C, 0x08, /* ## # */ + + /* @62 '&' (8 pixels wide) */ + 0x0E, 0x00, /* ### */ + 0x19, 0x70, /* ## # ### */ + 0x10, 0xC8, /* # ## # */ + 0x11, 0x88, /* # ## # */ + 0x16, 0x48, /* # ## # # */ + 0x0C, 0x70, /* ## ### */ + 0x1F, 0x00, /* ##### */ + 0x10, 0x00, /* # */ + + /* @78 ''' (2 pixels wide) */ + 0x00, 0x38, /* ### */ + 0x00, 0x38, /* ### */ + + /* @82 '(' (4 pixels wide) */ + 0x0F, 0xC0, /* ###### */ + 0x30, 0x30, /* ## ## */ + 0x40, 0x08, /* # # */ + 0x80, 0x04, /* # # */ + + /* @90 ')' (4 pixels wide) */ + 0x80, 0x04, /* # # */ + 0x40, 0x08, /* # # */ + 0x30, 0x30, /* ## ## */ + 0x0F, 0xC0, /* ###### */ + + /* @98 '*' (5 pixels wide) */ + 0x00, 0x90, /* # # */ + 0x00, 0x60, /* ## */ + 0x01, 0xF8, /* ###### */ + 0x00, 0x60, /* ## */ + 0x00, 0x90, /* # # */ + + /* @108 '+' (7 pixels wide) */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x1F, 0xC0, /* ####### */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + + /* @122 ',' (3 pixels wide) */ + 0x80, 0x00, /* # */ + 0xD8, 0x00, /* ## ## */ + 0x78, 0x00, /* #### */ + + /* @128 '-' (4 pixels wide) */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + + /* @136 '.' (2 pixels wide) */ + 0x18, 0x00, /* ## */ + 0x18, 0x00, /* ## */ + + /* @140 '/' (6 pixels wide) */ + 0x40, 0x00, /* # */ + 0x38, 0x00, /* ### */ + 0x0E, 0x00, /* ### */ + 0x03, 0x80, /* ### */ + 0x00, 0x70, /* ### */ + 0x00, 0x18, /* ## */ + + /* @152 '0' (7 pixels wide) */ + 0x07, 0xE0, /* ###### */ + 0x0A, 0x10, /* # # # */ + 0x11, 0x08, /* # # # */ + 0x11, 0x88, /* # ## # */ + 0x10, 0x88, /* # # # */ + 0x08, 0x50, /* # # # */ + 0x07, 0xE0, /* ###### */ + + /* @166 '1' (6 pixels wide) */ + 0x10, 0x20, /* # # */ + 0x10, 0x10, /* # # */ + 0x1F, 0xF8, /* ########## */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + + /* @178 '2' (6 pixels wide) */ + 0x10, 0x10, /* # # */ + 0x18, 0x08, /* ## # */ + 0x14, 0x08, /* # # # */ + 0x12, 0x08, /* # # # */ + 0x11, 0x18, /* # # ## */ + 0x10, 0xF0, /* # #### */ + + /* @190 '3' (6 pixels wide) */ + 0x10, 0x08, /* # # */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x09, 0xC8, /* # ### # */ + 0x07, 0x70, /* ### ### */ + + /* @202 '4' (8 pixels wide) */ + 0x06, 0x00, /* ## */ + 0x07, 0x00, /* ### */ + 0x04, 0xC0, /* # ## */ + 0x04, 0x60, /* # ## */ + 0x04, 0x18, /* # ## */ + 0x1F, 0xF8, /* ########## */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + + /* @218 '5' (5 pixels wide) */ + 0x10, 0xF8, /* # ##### */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x09, 0x88, /* # ## # */ + 0x0F, 0x08, /* #### # */ + + /* @228 '6' (6 pixels wide) */ + 0x07, 0xE0, /* ###### */ + 0x19, 0x10, /* ## # # */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x18, 0x88, /* ## # # */ + 0x0F, 0x00, /* #### */ + + /* @240 '7' (6 pixels wide) */ + 0x00, 0x08, /* # */ + 0x18, 0x08, /* ## # */ + 0x0E, 0x08, /* ### # */ + 0x03, 0x88, /* ### # */ + 0x00, 0xF8, /* ##### */ + 0x00, 0x18, /* ## */ + + /* @252 '8' (6 pixels wide) */ + 0x0E, 0x70, /* ### ### */ + 0x19, 0x48, /* ## # # # */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x11, 0x48, /* # # # # */ + 0x0E, 0x70, /* ### ### */ + + /* @264 '9' (6 pixels wide) */ + 0x00, 0xF0, /* #### */ + 0x11, 0x18, /* # # ## */ + 0x11, 0x08, /* # # # */ + 0x11, 0x08, /* # # # */ + 0x08, 0x98, /* # # ## */ + 0x07, 0xE0, /* ###### */ + + /* @276 ':' (2 pixels wide) */ + 0x18, 0xC0, /* ## ## */ + 0x18, 0xC0, /* ## ## */ + + /* @280 ';' (3 pixels wide) */ + 0x80, 0x00, /* # */ + 0xD8, 0xC0, /* ## ## ## */ + 0x78, 0xC0, /* #### ## */ + + /* @286 '<' (5 pixels wide) */ + 0x03, 0x00, /* ## */ + 0x07, 0x80, /* #### */ + 0x0C, 0xC0, /* ## ## */ + 0x08, 0x40, /* # # */ + 0x10, 0x20, /* # # */ + + /* @296 '=' (6 pixels wide) */ + 0x02, 0x80, /* # # */ + 0x02, 0x80, /* # # */ + 0x02, 0x80, /* # # */ + 0x02, 0x80, /* # # */ + 0x02, 0x80, /* # # */ + 0x02, 0x80, /* # # */ + + /* @308 '>' (5 pixels wide) */ + 0x10, 0x20, /* # # */ + 0x08, 0x40, /* # # */ + 0x0C, 0xC0, /* ## ## */ + 0x07, 0x80, /* #### */ + 0x03, 0x00, /* ## */ + + /* @318 '?' (4 pixels wide) */ + 0x1B, 0x08, /* ## ## # */ + 0x19, 0x08, /* ## # # */ + 0x01, 0x10, /* # # */ + 0x00, 0xE0, /* ### */ + + /* @326 '@' (8 pixels wide) */ + 0x3F, 0x80, /* ####### */ + 0x40, 0x60, /* # ## */ + 0x9F, 0x10, /* # ##### # */ + 0x91, 0x88, /* # # ## # */ + 0x90, 0x88, /* # # # # */ + 0xDF, 0x88, /* ## ###### # */ + 0x10, 0x10, /* # # */ + 0x0F, 0xE0, /* ####### */ + + /* @342 'A' (7 pixels wide) */ + 0x1C, 0x00, /* ### */ + 0x07, 0x80, /* #### */ + 0x04, 0x78, /* # #### */ + 0x04, 0x08, /* # # */ + 0x04, 0x78, /* # #### */ + 0x07, 0xC0, /* ##### */ + 0x1C, 0x00, /* ### */ + + /* @356 'B' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x19, 0xC8, /* ## ### # */ + 0x0F, 0x70, /* #### ### */ + + /* @368 'C' (6 pixels wide) */ + 0x07, 0xE0, /* ###### */ + 0x08, 0x10, /* # # */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x08, 0x10, /* # # */ + + /* @380 'D' (7 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x18, 0x08, /* ## # */ + 0x0C, 0x10, /* ## # */ + 0x07, 0xE0, /* ###### */ + + /* @394 'E' (5 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + + /* @404 'F' (5 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x01, 0x08, /* # # */ + 0x01, 0x08, /* # # */ + 0x01, 0x08, /* # # */ + 0x01, 0x08, /* # # */ + + /* @414 'G' (7 pixels wide) */ + 0x07, 0xC0, /* ##### */ + 0x0C, 0x30, /* ## ## */ + 0x18, 0x18, /* ## ## */ + 0x10, 0x08, /* # # */ + 0x11, 0x08, /* # # # */ + 0x11, 0x08, /* # # # */ + 0x1F, 0x10, /* ##### # */ + + /* @428 'H' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x00, 0x80, /* # */ + 0x00, 0x80, /* # */ + 0x00, 0x80, /* # */ + 0x00, 0x80, /* # */ + 0x1F, 0xF8, /* ########## */ + + /* @440 'I' (5 pixels wide) */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x1F, 0xF8, /* ########## */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + + /* @450 'J' (5 pixels wide) */ + 0x08, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x0F, 0xF8, /* ######### */ + + /* @460 'K' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x01, 0x80, /* ## */ + 0x03, 0xC0, /* #### */ + 0x06, 0x60, /* ## ## */ + 0x08, 0x10, /* # # */ + 0x10, 0x08, /* # # */ + + /* @472 'L' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + + /* @484 'M' (7 pixels wide) */ + 0x1F, 0xF0, /* ######### */ + 0x00, 0x18, /* ## */ + 0x03, 0xE0, /* ##### */ + 0x03, 0x80, /* ### */ + 0x00, 0x70, /* ### */ + 0x00, 0x08, /* # */ + 0x1F, 0xF8, /* ########## */ + + /* @498 'N' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x00, 0x38, /* ### */ + 0x00, 0xC0, /* ## */ + 0x07, 0x00, /* ### */ + 0x18, 0x00, /* ## */ + 0x1F, 0xF8, /* ########## */ + + /* @510 'O' (8 pixels wide) */ + 0x07, 0xE0, /* ###### */ + 0x08, 0x30, /* # ## */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x0C, 0x10, /* ## # */ + 0x07, 0xE0, /* ###### */ + + /* @526 'P' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x01, 0x08, /* # # */ + 0x01, 0x08, /* # # */ + 0x01, 0x08, /* # # */ + 0x00, 0x98, /* # ## */ + 0x00, 0xF0, /* #### */ + + /* @538 'Q' (7 pixels wide) */ + 0x07, 0xE0, /* ###### */ + 0x08, 0x10, /* # # */ + 0x10, 0x08, /* # # */ + 0x70, 0x08, /* ### # */ + 0x90, 0x08, /* # # # */ + 0x88, 0x10, /* # # # */ + 0xC7, 0xE0, /* ## ###### */ + + /* @552 'R' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x00, 0x88, /* # # */ + 0x01, 0x88, /* ## # */ + 0x07, 0x88, /* #### # */ + 0x1C, 0x70, /* ### ### */ + 0x10, 0x00, /* # */ + + /* @564 'S' (6 pixels wide) */ + 0x10, 0x70, /* # ### */ + 0x10, 0x88, /* # # # */ + 0x10, 0x88, /* # # # */ + 0x11, 0x88, /* # ## # */ + 0x11, 0x08, /* # # # */ + 0x0E, 0x00, /* ### */ + + /* @576 'T' (7 pixels wide) */ + 0x00, 0x08, /* # */ + 0x00, 0x08, /* # */ + 0x00, 0x08, /* # */ + 0x1F, 0xF8, /* ########## */ + 0x00, 0x08, /* # */ + 0x00, 0x08, /* # */ + 0x00, 0x08, /* # */ + + /* @590 'U' (6 pixels wide) */ + 0x0F, 0xF8, /* ######### */ + 0x18, 0x00, /* ## */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x18, 0x00, /* ## */ + 0x0F, 0xF8, /* ######### */ + + /* @602 'V' (7 pixels wide) */ + 0x00, 0x38, /* ### */ + 0x03, 0xE0, /* ##### */ + 0x1F, 0x00, /* ##### */ + 0x10, 0x00, /* # */ + 0x0F, 0x00, /* #### */ + 0x01, 0xE0, /* #### */ + 0x00, 0x38, /* ### */ + + /* @616 'W' (8 pixels wide) */ + 0x00, 0xF8, /* ##### */ + 0x1F, 0x80, /* ###### */ + 0x18, 0x00, /* ## */ + 0x07, 0x80, /* #### */ + 0x03, 0xC0, /* #### */ + 0x1C, 0x00, /* ### */ + 0x1F, 0x80, /* ###### */ + 0x00, 0xF8, /* ##### */ + + /* @632 'X' (8 pixels wide) */ + 0x10, 0x08, /* # # */ + 0x18, 0x18, /* ## ## */ + 0x0E, 0x60, /* ### ## */ + 0x03, 0xC0, /* #### */ + 0x03, 0xC0, /* #### */ + 0x0E, 0x60, /* ### ## */ + 0x18, 0x18, /* ## ## */ + 0x10, 0x08, /* # # */ + + /* @648 'Y' (7 pixels wide) */ + 0x00, 0x08, /* # */ + 0x00, 0x30, /* ## */ + 0x00, 0xC0, /* ## */ + 0x1F, 0x00, /* ##### */ + 0x00, 0xC0, /* ## */ + 0x00, 0x30, /* ## */ + 0x00, 0x08, /* # */ + + /* @662 'Z' (7 pixels wide) */ + 0x10, 0x08, /* # # */ + 0x1C, 0x08, /* ### # */ + 0x16, 0x08, /* # ## # */ + 0x11, 0x88, /* # ## # */ + 0x10, 0x68, /* # ## # */ + 0x10, 0x38, /* # ### */ + 0x00, 0x08, /* # */ + + /* @676 '[' (3 pixels wide) */ + 0xFF, 0xFC, /* ############## */ + 0x80, 0x04, /* # # */ + 0x80, 0x04, /* # # */ + + /* @682 '\' (6 pixels wide) */ + 0x00, 0x08, /* # */ + 0x00, 0x70, /* ### */ + 0x01, 0xC0, /* ### */ + 0x07, 0x00, /* ### */ + 0x38, 0x00, /* ### */ + 0x60, 0x00, /* ## */ + + /* @694 ']' (3 pixels wide) */ + 0x80, 0x04, /* # # */ + 0x80, 0x04, /* # # */ + 0xFF, 0xFC, /* ############## */ + + /* @700 '^' (5 pixels wide) */ + 0x00, 0xC0, /* ## */ + 0x00, 0x30, /* ## */ + 0x00, 0x08, /* # */ + 0x00, 0x30, /* ## */ + 0x00, 0xC0, /* ## */ + + /* @710 '_' (8 pixels wide) */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + + /* @726 '`' (3 pixels wide) */ + 0x00, 0x08, /* # */ + 0x00, 0x18, /* ## */ + 0x00, 0x10, /* # */ + + /* @732 'a' (6 pixels wide) */ + 0x0C, 0x00, /* ## */ + 0x12, 0x80, /* # # # */ + 0x12, 0x40, /* # # # */ + 0x12, 0x40, /* # # # */ + 0x0A, 0x40, /* # # # */ + 0x1F, 0x80, /* ###### */ + + /* @744 'b' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x10, 0x80, /* # # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x08, 0xC0, /* # ## */ + 0x07, 0x80, /* #### */ + + /* @756 'c' (6 pixels wide) */ + 0x0F, 0x00, /* #### */ + 0x08, 0x80, /* # # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + + /* @768 'd' (6 pixels wide) */ + 0x0F, 0x00, /* #### */ + 0x18, 0x80, /* ## # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x08, 0x40, /* # # */ + 0x1F, 0xF8, /* ########## */ + + /* @780 'e' (6 pixels wide) */ + 0x0F, 0x80, /* ##### */ + 0x1A, 0xC0, /* ## # ## */ + 0x12, 0x40, /* # # # */ + 0x12, 0x40, /* # # # */ + 0x12, 0xC0, /* # # ## */ + 0x13, 0x80, /* # ### */ + + /* @792 'f' (6 pixels wide) */ + 0x00, 0x80, /* # */ + 0x00, 0x80, /* # */ + 0x1F, 0xF0, /* ######### */ + 0x00, 0x88, /* # # */ + 0x00, 0x88, /* # # */ + 0x00, 0x08, /* # */ + + /* @804 'g' (7 pixels wide) */ + 0x7F, 0x80, /* ######## */ + 0x94, 0x40, /* # # # # */ + 0x94, 0x40, /* # # # # */ + 0x94, 0x40, /* # # # # */ + 0x94, 0x40, /* # # # # */ + 0x93, 0xC0, /* # # #### */ + 0x60, 0x40, /* ## # */ + + /* @818 'h' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x00, 0x80, /* # */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + 0x1F, 0x80, /* ###### */ + + /* @830 'i' (6 pixels wide) */ + 0x10, 0x40, /* # # */ + 0x10, 0x58, /* # # ## */ + 0x1F, 0xD8, /* ####### ## */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + + /* @842 'j' (5 pixels wide) */ + 0x40, 0x40, /* # # */ + 0x80, 0x40, /* # # */ + 0x80, 0x40, /* # # */ + 0xC0, 0x58, /* ## # ## */ + 0x7F, 0xD8, /* ######### ## */ + + /* @852 'k' (6 pixels wide) */ + 0x1F, 0xF8, /* ########## */ + 0x02, 0x00, /* # */ + 0x05, 0x00, /* # # */ + 0x0C, 0x80, /* ## # */ + 0x18, 0xC0, /* ## ## */ + 0x10, 0x40, /* # # */ + + /* @864 'l' (6 pixels wide) */ + 0x10, 0x08, /* # # */ + 0x10, 0x08, /* # # */ + 0x1F, 0xF8, /* ########## */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + + /* @876 'm' (7 pixels wide) */ + 0x1F, 0xC0, /* ####### */ + 0x00, 0xC0, /* ## */ + 0x00, 0x40, /* # */ + 0x1F, 0xC0, /* ####### */ + 0x00, 0xC0, /* ## */ + 0x00, 0x40, /* # */ + 0x1F, 0xC0, /* ####### */ + + /* @890 'n' (6 pixels wide) */ + 0x1F, 0xC0, /* ####### */ + 0x00, 0x80, /* # */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + 0x1F, 0x80, /* ###### */ + + /* @902 'o' (7 pixels wide) */ + 0x0F, 0x00, /* #### */ + 0x18, 0x80, /* ## # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x08, 0xC0, /* # ## */ + 0x07, 0x80, /* #### */ + + /* @916 'p' (6 pixels wide) */ + 0xFF, 0xC0, /* ########## */ + 0x10, 0x80, /* # # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x08, 0xC0, /* # ## */ + 0x07, 0x80, /* #### */ + + /* @928 'q' (6 pixels wide) */ + 0x0F, 0x00, /* #### */ + 0x18, 0x80, /* ## # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x08, 0x40, /* # # */ + 0xFF, 0xC0, /* ########## */ + + /* @940 'r' (6 pixels wide) */ + 0x1F, 0xC0, /* ####### */ + 0x00, 0x80, /* # */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + 0x01, 0x80, /* ## */ + + /* @952 's' (5 pixels wide) */ + 0x11, 0x80, /* # ## */ + 0x12, 0x40, /* # # # */ + 0x12, 0x40, /* # # # */ + 0x12, 0x40, /* # # # */ + 0x0C, 0x40, /* ## # */ + + /* @962 't' (7 pixels wide) */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + 0x0F, 0xF0, /* ######## */ + 0x18, 0x40, /* ## # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + 0x10, 0x40, /* # # */ + + /* @976 'u' (6 pixels wide) */ + 0x0F, 0xC0, /* ###### */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x10, 0x00, /* # */ + 0x08, 0x00, /* # */ + 0x1F, 0xC0, /* ####### */ + + /* @988 'v' (7 pixels wide) */ + 0x00, 0xC0, /* ## */ + 0x03, 0x80, /* ### */ + 0x1C, 0x00, /* ### */ + 0x10, 0x00, /* # */ + 0x0C, 0x00, /* ## */ + 0x03, 0x80, /* ### */ + 0x00, 0xC0, /* ## */ + + /* @1002 'w' (7 pixels wide) */ + 0x1F, 0xC0, /* ####### */ + 0x10, 0x00, /* # */ + 0x0E, 0x00, /* ### */ + 0x01, 0x00, /* # */ + 0x0E, 0x00, /* ### */ + 0x10, 0x00, /* # */ + 0x0F, 0xC0, /* ###### */ + + /* @1016 'x' (7 pixels wide) */ + 0x10, 0x40, /* # # */ + 0x18, 0xC0, /* ## ## */ + 0x0D, 0x80, /* ## ## */ + 0x02, 0x00, /* # */ + 0x0D, 0x80, /* ## ## */ + 0x18, 0xC0, /* ## ## */ + 0x10, 0x40, /* # # */ + + /* @1030 'y' (8 pixels wide) */ + 0x80, 0x00, /* # */ + 0x80, 0xC0, /* # ## */ + 0x83, 0x80, /* # ### */ + 0x6C, 0x00, /* ## ## */ + 0x30, 0x00, /* ## */ + 0x0C, 0x00, /* ## */ + 0x03, 0x80, /* ### */ + 0x00, 0xC0, /* ## */ + + /* @1046 'z' (6 pixels wide) */ + 0x10, 0x40, /* # # */ + 0x18, 0x40, /* ## # */ + 0x16, 0x40, /* # ## # */ + 0x13, 0x40, /* # ## # */ + 0x10, 0xC0, /* # ## */ + 0x10, 0x40, /* # # */ + + /* @1058 '{' (5 pixels wide) */ + 0x01, 0x00, /* # */ + 0x01, 0x00, /* # */ + 0x7E, 0xF8, /* ###### ##### */ + 0x80, 0x04, /* # # */ + 0x80, 0x04, /* # # */ + + /* @1068 '|' (1 pixels wide) */ + 0xFF, 0xFE, /* ############### */ + + /* @1070 '}' (5 pixels wide) */ + 0x80, 0x04, /* # # */ + 0x80, 0x04, /* # # */ + 0x7E, 0xF8, /* ###### ##### */ + 0x01, 0x00, /* # */ + 0x01, 0x00, /* # */ + + /* @1080 '~' (7 pixels wide) */ + 0x03, 0x00, /* ## */ + 0x00, 0x80, /* # */ + 0x00, 0x80, /* # */ + 0x01, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x01, 0x80, /* ## */ +}; + +/* Character descriptors for Consolas 11pt */ +/* { [Char width in bits], [Offset into consolas11ptCharBitmaps in bytes] } */ +const FONT_CHAR_INFO consolas11ptCharDescriptors[] = +{ + {2, 0}, /* */ + {2, 4}, /* ! */ + {5, 8}, /* " */ + {8, 18}, /* # */ + {6, 34}, /* $ */ + {8, 46}, /* % */ + {8, 62}, /* & */ + {2, 78}, /* ' */ + {4, 82}, /* ( */ + {4, 90}, /* ) */ + {5, 98}, /* * */ + {7, 108}, /* + */ + {3, 122}, /* , */ + {4, 128}, /* - */ + {2, 136}, /* . */ + {6, 140}, /* / */ + {7, 152}, /* 0 */ + {6, 166}, /* 1 */ + {6, 178}, /* 2 */ + {6, 190}, /* 3 */ + {8, 202}, /* 4 */ + {5, 218}, /* 5 */ + {6, 228}, /* 6 */ + {6, 240}, /* 7 */ + {6, 252}, /* 8 */ + {6, 264}, /* 9 */ + {2, 276}, /* : */ + {3, 280}, /* ; */ + {5, 286}, /* < */ + {6, 296}, /* = */ + {5, 308}, /* > */ + {4, 318}, /* ? */ + {8, 326}, /* @ */ + {7, 342}, /* A */ + {6, 356}, /* B */ + {6, 368}, /* C */ + {7, 380}, /* D */ + {5, 394}, /* E */ + {5, 404}, /* F */ + {7, 414}, /* G */ + {6, 428}, /* H */ + {5, 440}, /* I */ + {5, 450}, /* J */ + {6, 460}, /* K */ + {6, 472}, /* L */ + {7, 484}, /* M */ + {6, 498}, /* N */ + {8, 510}, /* O */ + {6, 526}, /* P */ + {7, 538}, /* Q */ + {6, 552}, /* R */ + {6, 564}, /* S */ + {7, 576}, /* T */ + {6, 590}, /* U */ + {7, 602}, /* V */ + {8, 616}, /* W */ + {8, 632}, /* X */ + {7, 648}, /* Y */ + {7, 662}, /* Z */ + {3, 676}, /* [ */ + {6, 682}, /* \ */ + {3, 694}, /* ] */ + {5, 700}, /* ^ */ + {8, 710}, /* _ */ + {3, 726}, /* ` */ + {6, 732}, /* a */ + {6, 744}, /* b */ + {6, 756}, /* c */ + {6, 768}, /* d */ + {6, 780}, /* e */ + {6, 792}, /* f */ + {7, 804}, /* g */ + {6, 818}, /* h */ + {6, 830}, /* i */ + {5, 842}, /* j */ + {6, 852}, /* k */ + {6, 864}, /* l */ + {7, 876}, /* m */ + {6, 890}, /* n */ + {7, 902}, /* o */ + {6, 916}, /* p */ + {6, 928}, /* q */ + {6, 940}, /* r */ + {5, 952}, /* s */ + {7, 962}, /* t */ + {6, 976}, /* u */ + {7, 988}, /* v */ + {7, 1002}, /* w */ + {7, 1016}, /* x */ + {8, 1030}, /* y */ + {6, 1046}, /* z */ + {5, 1058}, /* { */ + {1, 1068}, /* | */ + {5, 1070}, /* } */ + {7, 1080}, /* ~ */ +}; + +/* Font information for Consolas 11pt */ +const FONT_INFO consolas11ptFontInfo = +{ + 2, /* Character height */ + ' ', /* Start character */ + consolas11ptCharDescriptors, /* Character decriptor array */ + consolas11ptCharBitmaps, /* Character bitmap array */ +}; + + diff --git a/macusbfb/drivers/lcd/fonts/consolas11.h b/macusbfb/drivers/lcd/fonts/consolas11.h new file mode 100644 index 0000000..30a551f --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/consolas11.h @@ -0,0 +1,6 @@ +#include "bitmapfonts.h" + +/* Font data for Consolas 11pt */ +extern const uint8_t consolas11ptCharBitmaps[]; +extern const FONT_CHAR_INFO consolas11ptCharDescriptors[]; +extern const FONT_INFO consolas11ptFontInfo; diff --git a/macusbfb/drivers/lcd/fonts/consolas16.c b/macusbfb/drivers/lcd/fonts/consolas16.c new file mode 100644 index 0000000..01d8bf6 --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/consolas16.c @@ -0,0 +1,1199 @@ +/**************************************************************************/ +/*! + @file consolas11.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include "consolas16.h" + +/* +** Font data for Consolas 16pt +*/ + +/* Character bitmaps for Consolas 16pt */ +const uint8_t consolas16ptCharBitmaps[] = +{ + /* @0 ' ' (2 pixels wide) */ + 0x00, 0x00, 0x00, /* */ + 0x00, 0x00, 0x00, /* */ + + /* @6 '!' (3 pixels wide) */ + 0x0E, 0xFF, 0xC0, /* ### ########## */ + 0x0E, 0xFF, 0xC0, /* ### ########## */ + 0x0E, 0xFF, 0xC0, /* ### ########## */ + + /* @15 '"' (8 pixels wide) */ + 0x00, 0x07, 0xC0, /* ##### */ + 0x00, 0x07, 0xC0, /* ##### */ + 0x00, 0x07, 0xC0, /* ##### */ + 0x00, 0x00, 0x00, /* */ + 0x00, 0x00, 0x00, /* */ + 0x00, 0x07, 0xC0, /* ##### */ + 0x00, 0x07, 0xC0, /* ##### */ + 0x00, 0x07, 0xC0, /* ##### */ + + /* @39 '#' (11 pixels wide) */ + 0x01, 0x80, 0x00, /* ## */ + 0x0F, 0xCC, 0x00, /* ###### ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x01, 0xBF, 0x80, /* ## ####### */ + 0x01, 0x8C, 0x00, /* ## ## */ + 0x01, 0x8C, 0x00, /* ## ## */ + 0x0F, 0xCC, 0x00, /* ###### ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x01, 0xBF, 0x80, /* ## ####### */ + 0x01, 0x8C, 0x00, /* ## ## */ + 0x00, 0x0C, 0x00, /* ## */ + + /* @72 '$' (10 pixels wide) */ + 0x06, 0x0E, 0x00, /* ## ### */ + 0x0C, 0x1F, 0x00, /* ## ##### */ + 0x7C, 0x3F, 0x80, /* ##### ####### */ + 0x7F, 0xF9, 0x80, /* ############ ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x7F, 0xE0, /* ## ########## */ + 0x0E, 0x61, 0xE0, /* ### ## #### */ + 0x07, 0xE1, 0x80, /* ###### ## */ + 0x07, 0xE3, 0x00, /* ###### ## */ + 0x03, 0xC0, 0x00, /* #### */ + + /* @102 '%' (12 pixels wide) */ + 0x08, 0x07, 0x80, /* # #### */ + 0x0C, 0x08, 0x40, /* ## # # */ + 0x07, 0x08, 0x40, /* ### # # */ + 0x03, 0x88, 0x40, /* ### # # */ + 0x01, 0xC7, 0x80, /* ### #### */ + 0x00, 0x70, 0x00, /* ### */ + 0x07, 0xB8, 0x00, /* #### ### */ + 0x08, 0x4E, 0x00, /* # # ### */ + 0x08, 0x47, 0x00, /* # # ### */ + 0x08, 0x43, 0x80, /* # # ### */ + 0x07, 0x80, 0xC0, /* #### ## */ + 0x00, 0x00, 0x40, /* # */ + + /* @138 '&' (12 pixels wide) */ + 0x03, 0xC0, 0x00, /* #### */ + 0x07, 0xE7, 0x00, /* ###### ### */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0E, 0x3F, 0xC0, /* ### ######## */ + 0x0C, 0x78, 0xC0, /* ## #### ## */ + 0x0C, 0xF8, 0xC0, /* ## ##### ## */ + 0x0D, 0xEF, 0xC0, /* ## #### ###### */ + 0x07, 0xCF, 0x80, /* ##### ##### */ + 0x07, 0xE7, 0x80, /* ###### #### */ + 0x0F, 0xE0, 0x00, /* ####### */ + 0x0C, 0xE0, 0x00, /* ## ### */ + 0x08, 0x00, 0x00, /* # */ + + /* @174 ''' (3 pixels wide) */ + 0x00, 0x07, 0xC0, /* ##### */ + 0x00, 0x07, 0xC0, /* ##### */ + 0x00, 0x07, 0xC0, /* ##### */ + + /* @183 '(' (6 pixels wide) */ + 0x03, 0xF8, 0x00, /* ####### */ + 0x0F, 0xFE, 0x00, /* ########### */ + 0x3F, 0xFF, 0x00, /* ############## */ + 0x7C, 0x07, 0xC0, /* ##### ##### */ + 0xF0, 0x01, 0xE0, /* #### #### */ + 0x40, 0x00, 0x40, /* # # */ + + /* @201 ')' (6 pixels wide) */ + 0x40, 0x00, 0x40, /* # # */ + 0xF0, 0x01, 0xE0, /* #### #### */ + 0x7C, 0x07, 0xC0, /* ##### ##### */ + 0x1F, 0xFF, 0x80, /* ############## */ + 0x0F, 0xFE, 0x00, /* ########### */ + 0x03, 0xF8, 0x00, /* ####### */ + + /* @219 '*' (9 pixels wide) */ + 0x00, 0x11, 0x00, /* # # */ + 0x00, 0x3B, 0x80, /* ### ### */ + 0x00, 0x1B, 0x00, /* ## ## */ + 0x00, 0x7F, 0xC0, /* ######### */ + 0x00, 0x7F, 0xC0, /* ######### */ + 0x00, 0x7F, 0xC0, /* ######### */ + 0x00, 0x1B, 0x00, /* ## ## */ + 0x00, 0x1B, 0x00, /* ## ## */ + 0x00, 0x11, 0x00, /* # # */ + + /* @246 '+' (11 pixels wide) */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0x60, 0x00, /* ## */ + 0x07, 0xFE, 0x00, /* ########## */ + 0x07, 0xFE, 0x00, /* ########## */ + 0x07, 0xFE, 0x00, /* ########## */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0x60, 0x00, /* ## */ + + /* @279 ',' (6 pixels wide) */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC6, 0x00, 0x00, /* ## ## */ + 0x7E, 0x00, 0x00, /* ###### */ + 0x7E, 0x00, 0x00, /* ###### */ + 0x3C, 0x00, 0x00, /* #### */ + + /* @297 '-' (6 pixels wide) */ + 0x00, 0xC0, 0x00, /* ## */ + 0x00, 0xC0, 0x00, /* ## */ + 0x00, 0xC0, 0x00, /* ## */ + 0x00, 0xC0, 0x00, /* ## */ + 0x00, 0xC0, 0x00, /* ## */ + 0x00, 0xC0, 0x00, /* ## */ + + /* @315 '.' (4 pixels wide) */ + 0x06, 0x00, 0x00, /* ## */ + 0x0F, 0x00, 0x00, /* #### */ + 0x0F, 0x00, 0x00, /* #### */ + 0x06, 0x00, 0x00, /* ## */ + + /* @327 '/' (9 pixels wide) */ + 0x20, 0x00, 0x00, /* # */ + 0x38, 0x00, 0x00, /* ### */ + 0x3F, 0x00, 0x00, /* ###### */ + 0x0F, 0xC0, 0x00, /* ###### */ + 0x01, 0xF0, 0x00, /* ##### */ + 0x00, 0x7E, 0x00, /* ###### */ + 0x00, 0x1F, 0x80, /* ###### */ + 0x00, 0x03, 0xC0, /* #### */ + 0x00, 0x00, 0xC0, /* ## */ + + /* @354 '0' (11 pixels wide) */ + 0x01, 0xFC, 0x00, /* ####### */ + 0x03, 0xFE, 0x00, /* ######### */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x0F, 0xC7, 0x80, /* ###### #### */ + 0x0C, 0x61, 0x80, /* ## ## ## */ + 0x0C, 0x71, 0x80, /* ## ### ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0F, 0x1F, 0x80, /* #### ###### */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x03, 0xFF, 0x00, /* ########## */ + 0x01, 0xFC, 0x00, /* ####### */ + + /* @387 '1' (9 pixels wide) */ + 0x0C, 0x06, 0x00, /* ## ## */ + 0x0C, 0x03, 0x00, /* ## ## */ + 0x0C, 0x03, 0x00, /* ## ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + + /* @414 '2' (9 pixels wide) */ + 0x0C, 0x01, 0x00, /* ## # */ + 0x0E, 0x03, 0x00, /* ### ## */ + 0x0F, 0x01, 0x80, /* #### ## */ + 0x0F, 0x81, 0x80, /* ##### ## */ + 0x0D, 0xC1, 0x80, /* ## ### ## */ + 0x0C, 0xE3, 0x80, /* ## ### ### */ + 0x0C, 0x7F, 0x80, /* ## ######## */ + 0x0C, 0x3F, 0x00, /* ## ###### */ + 0x0C, 0x1E, 0x00, /* ## #### */ + + /* @441 '3' (9 pixels wide) */ + 0x06, 0x03, 0x00, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0E, 0x7F, 0x80, /* ### ######## */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x07, 0xEF, 0x00, /* ###### #### */ + 0x03, 0xC0, 0x00, /* #### */ + + /* @468 '4' (11 pixels wide) */ + 0x01, 0xC0, 0x00, /* ### */ + 0x01, 0xE0, 0x00, /* #### */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x01, 0x9E, 0x00, /* ## #### */ + 0x01, 0x8F, 0x00, /* ## #### */ + 0x01, 0x83, 0x80, /* ## ### */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x01, 0x80, 0x00, /* ## */ + 0x01, 0x80, 0x00, /* ## */ + + /* @501 '5' (9 pixels wide) */ + 0x0C, 0x3F, 0x80, /* ## ####### */ + 0x0C, 0x3F, 0x80, /* ## ####### */ + 0x0C, 0x3F, 0x80, /* ## ####### */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0E, 0x71, 0x80, /* ### ### ## */ + 0x07, 0xF1, 0x80, /* ####### ## */ + 0x07, 0xE1, 0x80, /* ###### ## */ + 0x03, 0xC0, 0x00, /* #### */ + + /* @528 '6' (10 pixels wide) */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x07, 0xFE, 0x00, /* ########## */ + 0x0F, 0xFF, 0x00, /* ############ */ + 0x0E, 0x67, 0x00, /* ### ## ### */ + 0x0C, 0x33, 0x80, /* ## ## ### */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0E, 0x31, 0x80, /* ### ## ## */ + 0x0F, 0xF1, 0x80, /* ######## ## */ + 0x07, 0xE1, 0x80, /* ###### ## */ + 0x03, 0xC0, 0x00, /* #### */ + + /* @558 '7' (9 pixels wide) */ + 0x00, 0x01, 0x80, /* ## */ + 0x08, 0x01, 0x80, /* # ## */ + 0x0E, 0x01, 0x80, /* ### ## */ + 0x0F, 0x81, 0x80, /* ##### ## */ + 0x07, 0xE1, 0x80, /* ###### ## */ + 0x01, 0xFD, 0x80, /* ####### ## */ + 0x00, 0x3F, 0x80, /* ####### */ + 0x00, 0x0F, 0x80, /* ##### */ + 0x00, 0x03, 0x80, /* ### */ + + /* @585 '8' (10 pixels wide) */ + 0x03, 0x8E, 0x00, /* ### ### */ + 0x07, 0xDF, 0x00, /* ##### ##### */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x79, 0x80, /* ## #### ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x71, 0x80, /* ## ### ## */ + 0x0C, 0x79, 0x80, /* ## #### ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x07, 0xDF, 0x00, /* ##### ##### */ + 0x03, 0x8F, 0x00, /* ### #### */ + + /* @615 '9' (10 pixels wide) */ + 0x00, 0x1E, 0x00, /* #### */ + 0x0C, 0x3F, 0x00, /* ## ###### */ + 0x0C, 0x7F, 0x80, /* ## ######## */ + 0x0C, 0x63, 0x80, /* ## ## ### */ + 0x0C, 0x61, 0x80, /* ## ## ## */ + 0x0E, 0x61, 0x80, /* ### ## ## */ + 0x07, 0x23, 0x80, /* ### # ### */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x03, 0xFF, 0x00, /* ########## */ + 0x00, 0xFC, 0x00, /* ###### */ + + /* @645 ':' (4 pixels wide) */ + 0x06, 0x18, 0x00, /* ## ## */ + 0x0F, 0x3C, 0x00, /* #### #### */ + 0x0F, 0x3C, 0x00, /* #### #### */ + 0x06, 0x18, 0x00, /* ## ## */ + + /* @657 ';' (6 pixels wide) */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC6, 0x18, 0x00, /* ## ## ## */ + 0x7E, 0x3C, 0x00, /* ###### #### */ + 0x7E, 0x3C, 0x00, /* ###### #### */ + 0x3C, 0x18, 0x00, /* #### ## */ + + /* @675 '<' (8 pixels wide) */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0xF0, 0x00, /* #### */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x03, 0x9C, 0x00, /* ### ### */ + 0x07, 0x0E, 0x00, /* ### ### */ + 0x06, 0x06, 0x00, /* ## ## */ + 0x0E, 0x07, 0x00, /* ### ### */ + 0x04, 0x02, 0x00, /* # # */ + + /* @699 '=' (9 pixels wide) */ + 0x01, 0x98, 0x00, /* ## ## */ + 0x01, 0x98, 0x00, /* ## ## */ + 0x01, 0x98, 0x00, /* ## ## */ + 0x01, 0x98, 0x00, /* ## ## */ + 0x01, 0x98, 0x00, /* ## ## */ + 0x01, 0x98, 0x00, /* ## ## */ + 0x01, 0x98, 0x00, /* ## ## */ + 0x01, 0x98, 0x00, /* ## ## */ + 0x01, 0x98, 0x00, /* ## ## */ + + /* @726 '>' (8 pixels wide) */ + 0x04, 0x02, 0x00, /* # # */ + 0x0E, 0x07, 0x00, /* ### ### */ + 0x06, 0x06, 0x00, /* ## ## */ + 0x07, 0x0E, 0x00, /* ### ### */ + 0x03, 0x9C, 0x00, /* ### ### */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x00, 0xF0, 0x00, /* #### */ + 0x00, 0x60, 0x00, /* ## */ + + /* @750 '?' (7 pixels wide) */ + 0x0E, 0xF0, 0xC0, /* ### #### ## */ + 0x0E, 0xF0, 0xC0, /* ### #### ## */ + 0x0E, 0xF0, 0xC0, /* ### #### ## */ + 0x00, 0x39, 0xC0, /* ### ### */ + 0x00, 0x3F, 0x80, /* ####### */ + 0x00, 0x1F, 0x80, /* ###### */ + 0x00, 0x0F, 0x00, /* #### */ + + /* @771 '@' (11 pixels wide) */ + 0x0F, 0xF0, 0x00, /* ######## */ + 0x3F, 0xFC, 0x00, /* ############ */ + 0x70, 0x1F, 0x00, /* ### ##### */ + 0xE3, 0xE3, 0x80, /* ### ##### ### */ + 0xC7, 0xF9, 0xC0, /* ## ######## ### */ + 0xC7, 0x98, 0xC0, /* ## #### ## ## */ + 0xC3, 0xF8, 0xC0, /* ## ####### ## */ + 0xC6, 0x78, 0xC0, /* ## ## #### ## */ + 0x67, 0x03, 0x80, /* ## ### ### */ + 0x07, 0xFF, 0x80, /* ############ */ + 0x01, 0xFE, 0x00, /* ######## */ + + /* @804 'A' (11 pixels wide) */ + 0x0E, 0x00, 0x00, /* ### */ + 0x0F, 0xC0, 0x00, /* ###### */ + 0x03, 0xF8, 0x00, /* ####### */ + 0x01, 0xFF, 0x00, /* ######### */ + 0x01, 0x8F, 0x80, /* ## ##### */ + 0x01, 0x81, 0x80, /* ## ## */ + 0x01, 0x8F, 0x80, /* ## ##### */ + 0x01, 0xFF, 0x80, /* ########## */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0F, 0xC0, 0x00, /* ###### */ + 0x0E, 0x00, 0x00, /* ### */ + + /* @837 'B' (10 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0E, 0x7F, 0x80, /* ### ######## */ + 0x0F, 0xFF, 0x00, /* ############ */ + 0x07, 0xEF, 0x00, /* ###### #### */ + 0x03, 0xC0, 0x00, /* #### */ + + /* @867 'C' (9 pixels wide) */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x03, 0xFE, 0x00, /* ######### */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x0F, 0x07, 0x80, /* #### #### */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x06, 0x03, 0x00, /* ## ## */ + + /* @894 'D' (10 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x07, 0x03, 0x80, /* ### ### */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x03, 0xFE, 0x00, /* ######### */ + 0x00, 0xFC, 0x00, /* ###### */ + + /* @924 'E' (8 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + + /* @948 'F' (8 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x00, 0x61, 0x80, /* ## ## */ + 0x00, 0x61, 0x80, /* ## ## */ + 0x00, 0x61, 0x80, /* ## ## */ + 0x00, 0x61, 0x80, /* ## ## */ + 0x00, 0x61, 0x80, /* ## ## */ + + /* @972 'G' (11 pixels wide) */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x03, 0xFE, 0x00, /* ######### */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x07, 0x07, 0x00, /* ### ### */ + 0x0E, 0x03, 0x80, /* ### ### */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0C, 0x31, 0x80, /* ## ## ## */ + 0x0F, 0xF1, 0x80, /* ######## ## */ + 0x0F, 0xF1, 0x80, /* ######## ## */ + 0x07, 0xF3, 0x00, /* ####### ## */ + + /* @1005 'H' (10 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x00, 0x30, 0x00, /* ## */ + 0x00, 0x30, 0x00, /* ## */ + 0x00, 0x30, 0x00, /* ## */ + 0x00, 0x30, 0x00, /* ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + + /* @1035 'I' (9 pixels wide) */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + + /* @1062 'J' (8 pixels wide) */ + 0x06, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0E, 0x01, 0x80, /* ### ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x07, 0xFF, 0x80, /* ############ */ + 0x03, 0xFF, 0x80, /* ########### */ + + /* @1086 'K' (10 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0xF8, 0x00, /* ##### */ + 0x03, 0xFE, 0x00, /* ######### */ + 0x07, 0x8F, 0x00, /* #### #### */ + 0x0F, 0x07, 0x80, /* #### #### */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x08, 0x00, 0x80, /* # # */ + + /* @1116 'L' (8 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + + /* @1140 'M' (9 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x00, 0x0F, 0x80, /* ##### */ + 0x00, 0xFE, 0x00, /* ####### */ + 0x00, 0xE0, 0x00, /* ### */ + 0x00, 0x7E, 0x00, /* ###### */ + 0x00, 0x07, 0x80, /* #### */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + + /* @1167 'N' (10 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x00, 0x0F, 0x80, /* ##### */ + 0x00, 0x7E, 0x00, /* ###### */ + 0x03, 0xF0, 0x00, /* ###### */ + 0x0F, 0x80, 0x00, /* ##### */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + + /* @1197 'O' (11 pixels wide) */ + 0x01, 0xFC, 0x00, /* ####### */ + 0x07, 0xFE, 0x00, /* ########## */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x0E, 0x03, 0x80, /* ### ### */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0E, 0x03, 0x80, /* ### ### */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x03, 0xFF, 0x00, /* ########## */ + 0x01, 0xFC, 0x00, /* ####### */ + + /* @1230 'P' (10 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x00, 0xC1, 0x80, /* ## ## */ + 0x00, 0xC1, 0x80, /* ## ## */ + 0x00, 0xC1, 0x80, /* ## ## */ + 0x00, 0xE3, 0x80, /* ### ### */ + 0x00, 0x7F, 0x00, /* ####### */ + 0x00, 0x7F, 0x00, /* ####### */ + 0x00, 0x1E, 0x00, /* #### */ + + /* @1260 'Q' (11 pixels wide) */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x07, 0xFE, 0x00, /* ########## */ + 0x07, 0xFF, 0x00, /* ########### */ + 0x0E, 0x03, 0x80, /* ### ### */ + 0x3C, 0x01, 0x80, /* #### ## */ + 0x7C, 0x01, 0x80, /* ##### ## */ + 0xFC, 0x01, 0x80, /* ###### ## */ + 0xEE, 0x03, 0x80, /* ### ### ### */ + 0xC7, 0xFF, 0x00, /* ## ########### */ + 0xC3, 0xFF, 0x00, /* ## ########## */ + 0x41, 0xFC, 0x00, /* # ####### */ + + /* @1293 'R' (10 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x00, 0x61, 0x80, /* ## ## */ + 0x00, 0x61, 0x80, /* ## ## */ + 0x01, 0xF1, 0x80, /* ##### ## */ + 0x07, 0xFF, 0x80, /* ############ */ + 0x0F, 0xBF, 0x00, /* ##### ###### */ + 0x0E, 0x1E, 0x00, /* ### #### */ + 0x08, 0x00, 0x00, /* # */ + + /* @1323 'S' (10 pixels wide) */ + 0x06, 0x0E, 0x00, /* ## ### */ + 0x0C, 0x1F, 0x00, /* ## ##### */ + 0x0C, 0x3F, 0x80, /* ## ####### */ + 0x0C, 0x39, 0x80, /* ## ### ## */ + 0x0C, 0x71, 0x80, /* ## ### ## */ + 0x0C, 0x71, 0x80, /* ## ### ## */ + 0x0E, 0x71, 0x80, /* ### ### ## */ + 0x07, 0xE1, 0x80, /* ###### ## */ + 0x07, 0xE3, 0x00, /* ###### ## */ + 0x03, 0xC0, 0x00, /* #### */ + + /* @1353 'T' (11 pixels wide) */ + 0x00, 0x01, 0x80, /* ## */ + 0x00, 0x01, 0x80, /* ## */ + 0x00, 0x01, 0x80, /* ## */ + 0x00, 0x01, 0x80, /* ## */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x00, 0x01, 0x80, /* ## */ + 0x00, 0x01, 0x80, /* ## */ + 0x00, 0x01, 0x80, /* ## */ + 0x00, 0x01, 0x80, /* ## */ + + /* @1386 'U' (10 pixels wide) */ + 0x03, 0xFF, 0x80, /* ########### */ + 0x07, 0xFF, 0x80, /* ############ */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0E, 0x00, 0x00, /* ### */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0E, 0x00, 0x00, /* ### */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x07, 0xFF, 0x80, /* ############ */ + 0x03, 0xFF, 0x80, /* ########### */ + + /* @1416 'V' (11 pixels wide) */ + 0x00, 0x03, 0x80, /* ### */ + 0x00, 0x1F, 0x80, /* ###### */ + 0x00, 0xFF, 0x80, /* ######### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0F, 0xC0, 0x00, /* ###### */ + 0x0E, 0x00, 0x00, /* ### */ + 0x0F, 0xC0, 0x00, /* ###### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x00, 0xFF, 0x00, /* ######## */ + 0x00, 0x1F, 0x80, /* ###### */ + 0x00, 0x03, 0x80, /* ### */ + + /* @1449 'W' (10 pixels wide) */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0x00, 0x00, /* #### */ + 0x01, 0xF0, 0x00, /* ##### */ + 0x00, 0x18, 0x00, /* ## */ + 0x00, 0xF8, 0x00, /* ##### */ + 0x07, 0xC0, 0x00, /* ##### */ + 0x0F, 0x00, 0x00, /* #### */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + + /* @1479 'X' (11 pixels wide) */ + 0x08, 0x00, 0x80, /* # # */ + 0x0E, 0x01, 0x80, /* ### ## */ + 0x0F, 0x07, 0x80, /* #### #### */ + 0x07, 0xCF, 0x00, /* ##### #### */ + 0x01, 0xFF, 0x00, /* ######### */ + 0x00, 0x7E, 0x00, /* ###### */ + 0x01, 0xFE, 0x00, /* ######## */ + 0x03, 0xCF, 0x00, /* #### #### */ + 0x0F, 0x87, 0x80, /* ##### #### */ + 0x0E, 0x01, 0x80, /* ### ## */ + 0x0C, 0x00, 0x80, /* ## # */ + + /* @1512 'Y' (11 pixels wide) */ + 0x00, 0x00, 0x80, /* # */ + 0x00, 0x03, 0x80, /* ### */ + 0x00, 0x0F, 0x80, /* ##### */ + 0x00, 0x3F, 0x00, /* ###### */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xE0, 0x00, /* ####### */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x00, 0x3F, 0x00, /* ###### */ + 0x00, 0x0F, 0x80, /* ##### */ + 0x00, 0x03, 0x80, /* ### */ + 0x00, 0x00, 0x80, /* # */ + + /* @1545 'Z' (9 pixels wide) */ + 0x0C, 0x01, 0x80, /* ## ## */ + 0x0F, 0x01, 0x80, /* #### ## */ + 0x0F, 0x81, 0x80, /* ##### ## */ + 0x0D, 0xE1, 0x80, /* ## #### ## */ + 0x0C, 0xF9, 0x80, /* ## ##### ## */ + 0x0C, 0x3D, 0x80, /* ## #### ## */ + 0x0C, 0x0F, 0x80, /* ## ##### */ + 0x0C, 0x07, 0x80, /* ## #### */ + 0x0C, 0x01, 0x80, /* ## ## */ + + /* @1572 '[' (6 pixels wide) */ + 0xFF, 0xFF, 0xE0, /* ################### */ + 0xFF, 0xFF, 0xE0, /* ################### */ + 0xFF, 0xFF, 0xE0, /* ################### */ + 0xC0, 0x00, 0x60, /* ## ## */ + 0xC0, 0x00, 0x60, /* ## ## */ + 0xC0, 0x00, 0x60, /* ## ## */ + + /* @1590 '\' (10 pixels wide) */ + 0x00, 0x00, 0x40, /* # */ + 0x00, 0x01, 0xC0, /* ### */ + 0x00, 0x07, 0xC0, /* ##### */ + 0x00, 0x1F, 0x00, /* ##### */ + 0x00, 0xFC, 0x00, /* ###### */ + 0x03, 0xF0, 0x00, /* ###### */ + 0x0F, 0x80, 0x00, /* ##### */ + 0x3E, 0x00, 0x00, /* ##### */ + 0x38, 0x00, 0x00, /* ### */ + 0x20, 0x00, 0x00, /* # */ + + /* @1620 ']' (6 pixels wide) */ + 0xC0, 0x00, 0x60, /* ## ## */ + 0xC0, 0x00, 0x60, /* ## ## */ + 0xC0, 0x00, 0x60, /* ## ## */ + 0xFF, 0xFF, 0xE0, /* ################### */ + 0xFF, 0xFF, 0xE0, /* ################### */ + 0xFF, 0xFF, 0xE0, /* ################### */ + + /* @1638 '^' (9 pixels wide) */ + 0x00, 0x30, 0x00, /* ## */ + 0x00, 0x3C, 0x00, /* #### */ + 0x00, 0x3E, 0x00, /* ##### */ + 0x00, 0x07, 0x80, /* #### */ + 0x00, 0x01, 0x80, /* ## */ + 0x00, 0x07, 0x80, /* #### */ + 0x00, 0x3E, 0x00, /* ##### */ + 0x00, 0x38, 0x00, /* ### */ + 0x00, 0x30, 0x00, /* ## */ + + /* @1665 '_' (12 pixels wide) */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + 0xC0, 0x00, 0x00, /* ## */ + + /* @1701 '`' (5 pixels wide) */ + 0x00, 0x00, 0x40, /* # */ + 0x00, 0x00, 0xC0, /* ## */ + 0x00, 0x01, 0xC0, /* ### */ + 0x00, 0x01, 0x80, /* ## */ + 0x00, 0x01, 0x00, /* # */ + + /* @1716 'a' (9 pixels wide) */ + 0x07, 0x00, 0x00, /* ### */ + 0x0F, 0x98, 0x00, /* ##### ## */ + 0x0F, 0xCC, 0x00, /* ###### ## */ + 0x0C, 0xCC, 0x00, /* ## ## ## */ + 0x0C, 0xCC, 0x00, /* ## ## ## */ + 0x06, 0xCC, 0x00, /* ## ## ## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xF8, 0x00, /* ######### */ + 0x0F, 0xF8, 0x00, /* ######### */ + + /* @1743 'b' (10 pixels wide) */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0C, 0x18, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x07, 0xFC, 0x00, /* ######### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x01, 0xF0, 0x00, /* ##### */ + + /* @1773 'c' (8 pixels wide) */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0F, 0xF8, 0x00, /* ######### */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x06, 0x18, 0x00, /* ## ## */ + + /* @1797 'd' (10 pixels wide) */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0F, 0xF8, 0x00, /* ######### */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x06, 0x0C, 0x00, /* ## ## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + + /* @1827 'e' (10 pixels wide) */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0F, 0xF8, 0x00, /* ######### */ + 0x0E, 0xDC, 0x00, /* ### ## ### */ + 0x0C, 0xCC, 0x00, /* ## ## ## */ + 0x0C, 0xCC, 0x00, /* ## ## ## */ + 0x0C, 0xDC, 0x00, /* ## ## ### */ + 0x0C, 0xFC, 0x00, /* ## ###### */ + 0x06, 0xF8, 0x00, /* ## ##### */ + 0x00, 0xF0, 0x00, /* #### */ + + /* @1857 'f' (10 pixels wide) */ + 0x00, 0x18, 0x00, /* ## */ + 0x00, 0x18, 0x00, /* ## */ + 0x00, 0x18, 0x00, /* ## */ + 0x0F, 0xFF, 0x00, /* ############ */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x00, 0x18, 0xC0, /* ## ## */ + 0x00, 0x18, 0xC0, /* ## ## */ + 0x00, 0x18, 0xC0, /* ## ## */ + 0x00, 0x00, 0xC0, /* ## */ + + /* @1887 'g' (10 pixels wide) */ + 0x76, 0x00, 0x00, /* ### ## */ + 0x77, 0x70, 0x00, /* ### ### ### */ + 0xFF, 0xF8, 0x00, /* ############# */ + 0xCD, 0xFC, 0x00, /* ## ## ####### */ + 0xCD, 0x8C, 0x00, /* ## ## ## ## */ + 0xCD, 0x8C, 0x00, /* ## ## ## ## */ + 0xCD, 0xFC, 0x00, /* ## ## ####### */ + 0xFC, 0xFC, 0x00, /* ###### ###### */ + 0x7C, 0x7C, 0x00, /* ##### ##### */ + 0x38, 0x0C, 0x00, /* ### ## */ + + /* @1917 'h' (9 pixels wide) */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x00, 0x18, 0x00, /* ## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xF8, 0x00, /* ######### */ + + /* @1944 'i' (9 pixels wide) */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0F, 0xFD, 0xC0, /* ########## ### */ + 0x0F, 0xFD, 0xC0, /* ########## ### */ + 0x0F, 0xFD, 0xC0, /* ########## ### */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + + /* @1971 'j' (8 pixels wide) */ + 0x60, 0x0C, 0x00, /* ## ## */ + 0xC0, 0x0C, 0x00, /* ## ## */ + 0xC0, 0x0C, 0x00, /* ## ## */ + 0xC0, 0x0C, 0x00, /* ## ## */ + 0xE0, 0x0C, 0x00, /* ### ## */ + 0xFF, 0xFD, 0xC0, /* ############## ### */ + 0x7F, 0xFD, 0xC0, /* ############# ### */ + 0x3F, 0xFD, 0xC0, /* ############ ### */ + + /* @1995 'k' (9 pixels wide) */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x00, 0xE0, 0x00, /* ### */ + 0x01, 0xF0, 0x00, /* ##### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x0C, 0x04, 0x00, /* ## # */ + + /* @2022 'l' (9 pixels wide) */ + 0x0C, 0x00, 0xC0, /* ## ## */ + 0x0C, 0x00, 0xC0, /* ## ## */ + 0x0C, 0x00, 0xC0, /* ## ## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0F, 0xFF, 0xC0, /* ############## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + + /* @2049 'm' (11 pixels wide) */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xF8, 0x00, /* ######### */ + 0x00, 0x0C, 0x00, /* ## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xF8, 0x00, /* ######### */ + + /* @2082 'n' (9 pixels wide) */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x00, 0x18, 0x00, /* ## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xF8, 0x00, /* ######### */ + + /* @2109 'o' (10 pixels wide) */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0F, 0xF8, 0x00, /* ######### */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x07, 0xFC, 0x00, /* ######### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x01, 0xF0, 0x00, /* ##### */ + + /* @2139 'p' (10 pixels wide) */ + 0xFF, 0xFC, 0x00, /* ############## */ + 0xFF, 0xFC, 0x00, /* ############## */ + 0xFF, 0xFC, 0x00, /* ############## */ + 0x0C, 0x18, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x07, 0xFC, 0x00, /* ######### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x01, 0xF0, 0x00, /* ##### */ + + /* @2169 'q' (10 pixels wide) */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0F, 0xF8, 0x00, /* ######### */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x06, 0x0C, 0x00, /* ## ## */ + 0xFF, 0xFC, 0x00, /* ############## */ + 0xFF, 0xFC, 0x00, /* ############## */ + 0xFF, 0xFC, 0x00, /* ############## */ + + /* @2199 'r' (9 pixels wide) */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x00, 0x18, 0x00, /* ## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x00, 0x3C, 0x00, /* #### */ + 0x00, 0x3C, 0x00, /* #### */ + 0x00, 0x38, 0x00, /* ### */ + + /* @2226 's' (9 pixels wide) */ + 0x06, 0x38, 0x00, /* ## ### */ + 0x0C, 0x78, 0x00, /* ## #### */ + 0x0C, 0xFC, 0x00, /* ## ###### */ + 0x0C, 0xEC, 0x00, /* ## ### ## */ + 0x0C, 0xCC, 0x00, /* ## ## ## */ + 0x0C, 0xCC, 0x00, /* ## ## ## */ + 0x0F, 0xCC, 0x00, /* ###### ## */ + 0x07, 0x98, 0x00, /* #### ## */ + 0x03, 0x80, 0x00, /* ### */ + + /* @2253 't' (10 pixels wide) */ + 0x00, 0x0C, 0x00, /* ## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x00, 0x0C, 0x00, /* ## */ + 0x07, 0xFF, 0x80, /* ############ */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0F, 0xFF, 0x80, /* ############# */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0C, 0x0C, 0x00, /* ## ## */ + + /* @2283 'u' (9 pixels wide) */ + 0x07, 0xFC, 0x00, /* ######### */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0C, 0x00, 0x00, /* ## */ + 0x06, 0x00, 0x00, /* ## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0xFC, 0x00, /* ########## */ + + /* @2310 'v' (11 pixels wide) */ + 0x00, 0x0C, 0x00, /* ## */ + 0x00, 0x3C, 0x00, /* #### */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x07, 0xE0, 0x00, /* ###### */ + 0x0F, 0x00, 0x00, /* #### */ + 0x0C, 0x00, 0x00, /* ## */ + 0x0F, 0x00, 0x00, /* #### */ + 0x07, 0xE0, 0x00, /* ###### */ + 0x01, 0xF8, 0x00, /* ###### */ + 0x00, 0x3C, 0x00, /* #### */ + 0x00, 0x0C, 0x00, /* ## */ + + /* @2343 'w' (11 pixels wide) */ + 0x01, 0xFC, 0x00, /* ####### */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x0F, 0x00, 0x00, /* #### */ + 0x0F, 0x00, 0x00, /* #### */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x00, 0x60, 0x00, /* ## */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x0F, 0x00, 0x00, /* #### */ + 0x0E, 0x00, 0x00, /* ### */ + 0x0F, 0xFC, 0x00, /* ########## */ + 0x01, 0xFC, 0x00, /* ####### */ + + /* @2376 'x' (10 pixels wide) */ + 0x08, 0x04, 0x00, /* # # */ + 0x0E, 0x0C, 0x00, /* ### ## */ + 0x0F, 0x3C, 0x00, /* #### #### */ + 0x03, 0xF8, 0x00, /* ####### */ + 0x00, 0xE0, 0x00, /* ### */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x07, 0xF8, 0x00, /* ######## */ + 0x0E, 0x1C, 0x00, /* ### ### */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x08, 0x04, 0x00, /* # # */ + + /* @2406 'y' (11 pixels wide) */ + 0xC0, 0x0C, 0x00, /* ## ## */ + 0xC0, 0x3C, 0x00, /* ## #### */ + 0xC1, 0xF8, 0x00, /* ## ###### */ + 0xE7, 0xE0, 0x00, /* ### ###### */ + 0x7F, 0x00, 0x00, /* ####### */ + 0x3E, 0x00, 0x00, /* ##### */ + 0x0F, 0x80, 0x00, /* ##### */ + 0x03, 0xE0, 0x00, /* ##### */ + 0x00, 0xF8, 0x00, /* ##### */ + 0x00, 0x3C, 0x00, /* #### */ + 0x00, 0x0C, 0x00, /* ## */ + + /* @2439 'z' (8 pixels wide) */ + 0x0C, 0x0C, 0x00, /* ## ## */ + 0x0E, 0x0C, 0x00, /* ### ## */ + 0x0F, 0x8C, 0x00, /* ##### ## */ + 0x0F, 0xCC, 0x00, /* ###### ## */ + 0x0C, 0xFC, 0x00, /* ## ###### */ + 0x0C, 0x7C, 0x00, /* ## ##### */ + 0x0C, 0x1C, 0x00, /* ## ### */ + 0x0C, 0x0C, 0x00, /* ## ## */ + + /* @2463 '{' (9 pixels wide) */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0xE0, 0x00, /* ### */ + 0x3F, 0xFF, 0x80, /* ############### */ + 0x7F, 0xFF, 0xC0, /* ################# */ + 0xFF, 0x9F, 0xE0, /* ######### ######## */ + 0xE0, 0x00, 0xE0, /* ### ### */ + 0xC0, 0x00, 0x60, /* ## ## */ + 0xC0, 0x00, 0x60, /* ## ## */ + + /* @2490 '|' (3 pixels wide) */ + 0xFF, 0xFF, 0xF8, /* ##################### */ + 0xFF, 0xFF, 0xF8, /* ##################### */ + 0xFF, 0xFF, 0xF8, /* ##################### */ + + /* @2499 '}' (9 pixels wide) */ + 0xC0, 0x00, 0x60, /* ## ## */ + 0xC0, 0x00, 0x60, /* ## ## */ + 0xE0, 0x00, 0xE0, /* ### ### */ + 0xFF, 0x9F, 0xE0, /* ######### ######## */ + 0x7F, 0xFF, 0xC0, /* ################# */ + 0x3F, 0xFF, 0x80, /* ############### */ + 0x00, 0x70, 0x00, /* ### */ + 0x00, 0x60, 0x00, /* ## */ + 0x00, 0x60, 0x00, /* ## */ + + /* @2526 '~' (11 pixels wide) */ + 0x00, 0xC0, 0x00, /* ## */ + 0x00, 0xF0, 0x00, /* #### */ + 0x00, 0x30, 0x00, /* ## */ + 0x00, 0x30, 0x00, /* ## */ + 0x00, 0x70, 0x00, /* ### */ + 0x00, 0xE0, 0x00, /* ### */ + 0x01, 0xC0, 0x00, /* ### */ + 0x01, 0x80, 0x00, /* ## */ + 0x01, 0x80, 0x00, /* ## */ + 0x01, 0xE0, 0x00, /* #### */ + 0x00, 0x60, 0x00, /* ## */ +}; + +/* Character descriptors for Consolas 16pt */ +/* { [Char width in bits], [Offset into consolas16ptCharBitmaps in bytes] } */ +const FONT_CHAR_INFO consolas16ptCharDescriptors[] = +{ + {2, 0}, /* */ + {3, 6}, /* ! */ + {8, 15}, /* " */ + {11, 39}, /* # */ + {10, 72}, /* $ */ + {12, 102}, /* % */ + {12, 138}, /* & */ + {3, 174}, /* ' */ + {6, 183}, /* ( */ + {6, 201}, /* ) */ + {9, 219}, /* * */ + {11, 246}, /* + */ + {6, 279}, /* , */ + {6, 297}, /* - */ + {4, 315}, /* . */ + {9, 327}, /* / */ + {11, 354}, /* 0 */ + {9, 387}, /* 1 */ + {9, 414}, /* 2 */ + {9, 441}, /* 3 */ + {11, 468}, /* 4 */ + {9, 501}, /* 5 */ + {10, 528}, /* 6 */ + {9, 558}, /* 7 */ + {10, 585}, /* 8 */ + {10, 615}, /* 9 */ + {4, 645}, /* : */ + {6, 657}, /* ; */ + {8, 675}, /* < */ + {9, 699}, /* = */ + {8, 726}, /* > */ + {7, 750}, /* ? */ + {11, 771}, /* @ */ + {11, 804}, /* A */ + {10, 837}, /* B */ + {9, 867}, /* C */ + {10, 894}, /* D */ + {8, 924}, /* E */ + {8, 948}, /* F */ + {11, 972}, /* G */ + {10, 1005}, /* H */ + {9, 1035}, /* I */ + {8, 1062}, /* J */ + {10, 1086}, /* K */ + {8, 1116}, /* L */ + {9, 1140}, /* M */ + {10, 1167}, /* N */ + {11, 1197}, /* O */ + {10, 1230}, /* P */ + {11, 1260}, /* Q */ + {10, 1293}, /* R */ + {10, 1323}, /* S */ + {11, 1353}, /* T */ + {10, 1386}, /* U */ + {11, 1416}, /* V */ + {10, 1449}, /* W */ + {11, 1479}, /* X */ + {11, 1512}, /* Y */ + {9, 1545}, /* Z */ + {6, 1572}, /* [ */ + {10, 1590}, /* \ */ + {6, 1620}, /* ] */ + {9, 1638}, /* ^ */ + {12, 1665}, /* _ */ + {5, 1701}, /* ` */ + {9, 1716}, /* a */ + {10, 1743}, /* b */ + {8, 1773}, /* c */ + {10, 1797}, /* d */ + {10, 1827}, /* e */ + {10, 1857}, /* f */ + {10, 1887}, /* g */ + {9, 1917}, /* h */ + {9, 1944}, /* i */ + {8, 1971}, /* j */ + {9, 1995}, /* k */ + {9, 2022}, /* l */ + {11, 2049}, /* m */ + {9, 2082}, /* n */ + {10, 2109}, /* o */ + {10, 2139}, /* p */ + {10, 2169}, /* q */ + {9, 2199}, /* r */ + {9, 2226}, /* s */ + {10, 2253}, /* t */ + {9, 2283}, /* u */ + {11, 2310}, /* v */ + {11, 2343}, /* w */ + {10, 2376}, /* x */ + {11, 2406}, /* y */ + {8, 2439}, /* z */ + {9, 2463}, /* { */ + {3, 2490}, /* | */ + {9, 2499}, /* } */ + {11, 2526}, /* ~ */ +}; + +/* Font information for Consolas 16pt */ +const FONT_INFO consolas16ptFontInfo = +{ + 3, /* Character height */ + ' ', /* Start character */ + consolas16ptCharDescriptors, /* Character decriptor array */ + consolas16ptCharBitmaps, /* Character bitmap array */ +}; diff --git a/macusbfb/drivers/lcd/fonts/consolas16.h b/macusbfb/drivers/lcd/fonts/consolas16.h new file mode 100644 index 0000000..7b65a05 --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/consolas16.h @@ -0,0 +1,6 @@ +#include "bitmapfonts.h" + +/* Font data for Consolas 16pt bold */ +extern const uint8_t consolas16ptCharBitmaps[]; +extern const FONT_CHAR_INFO consolas16ptCharDescriptors[]; +extern const FONT_INFO consolas16ptFontInfo; diff --git a/macusbfb/drivers/lcd/fonts/consolas9.c b/macusbfb/drivers/lcd/fonts/consolas9.c new file mode 100644 index 0000000..feda405 --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/consolas9.c @@ -0,0 +1,804 @@ +/**************************************************************************/ +/*! + @file consolas11.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include "consolas9.h" + +/* +** Font data for Consolas 9pt +*/ + +/* Character bitmaps for Consolas 9pt */ +const uint8_t consolas9ptCharBitmaps[] = +{ + /* @0 ' ' (2 pixels wide) */ + 0x00, 0x00, /* */ + 0x00, 0x00, /* */ + + /* @4 '!' (2 pixels wide) */ + 0x37, 0xC0, /* ## ##### */ + 0x30, 0x00, /* ## */ + + /* @8 '"' (3 pixels wide) */ + 0x01, 0xC0, /* ### */ + 0x00, 0x00, /* */ + 0x01, 0xC0, /* ### */ + + /* @14 '#' (6 pixels wide) */ + 0x09, 0x00, /* # # */ + 0x3D, 0x00, /* #### # */ + 0x0B, 0xC0, /* # #### */ + 0x3D, 0x00, /* #### # */ + 0x0B, 0xC0, /* # #### */ + 0x09, 0x00, /* # # */ + + /* @26 '$' (5 pixels wide) */ + 0x21, 0x80, /* # ## */ + 0x72, 0x40, /* ### # # */ + 0x2F, 0xE0, /* # ####### */ + 0x24, 0x40, /* # # # */ + 0x18, 0x00, /* ## */ + + /* @36 '%' (7 pixels wide) */ + 0x23, 0xC0, /* # #### */ + 0x12, 0x40, /* # # # */ + 0x0B, 0xC0, /* # #### */ + 0x3E, 0x00, /* ##### */ + 0x25, 0x00, /* # # # */ + 0x3C, 0x80, /* #### # */ + 0x00, 0x40, /* # */ + + /* @50 '&' (7 pixels wide) */ + 0x18, 0x00, /* ## */ + 0x25, 0x80, /* # # ## */ + 0x22, 0x40, /* # # # */ + 0x2E, 0x40, /* # ### # */ + 0x39, 0xC0, /* ### ### */ + 0x3C, 0x00, /* #### */ + 0x20, 0x00, /* # */ + + /* @64 ''' (1 pixels wide) */ + 0x01, 0xC0, /* ### */ + + /* @66 '(' (3 pixels wide) */ + 0x1F, 0x00, /* ##### */ + 0x60, 0xC0, /* ## ## */ + 0x80, 0x20, /* # # */ + + /* @72 ')' (3 pixels wide) */ + 0x80, 0x20, /* # # */ + 0x60, 0xC0, /* ## ## */ + 0x1F, 0x00, /* ##### */ + + /* @78 '*' (5 pixels wide) */ + 0x02, 0x80, /* # # */ + 0x01, 0x00, /* # */ + 0x07, 0xC0, /* ##### */ + 0x01, 0x00, /* # */ + 0x02, 0x80, /* # # */ + + /* @88 '+' (5 pixels wide) */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + 0x1F, 0x00, /* ##### */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + + /* @98 ',' (3 pixels wide) */ + 0x80, 0x00, /* # */ + 0xF0, 0x00, /* #### */ + 0x70, 0x00, /* ### */ + + /* @104 '-' (4 pixels wide) */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + + /* @112 '.' (2 pixels wide) */ + 0x30, 0x00, /* ## */ + 0x30, 0x00, /* ## */ + + /* @116 '/' (5 pixels wide) */ + 0x40, 0x00, /* # */ + 0x30, 0x00, /* ## */ + 0x0E, 0x00, /* ### */ + 0x01, 0x80, /* ## */ + 0x00, 0x40, /* # */ + + /* @126 '0' (6 pixels wide) */ + 0x1F, 0x00, /* ##### */ + 0x38, 0xC0, /* ### ## */ + 0x24, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x31, 0xC0, /* ## ### */ + 0x0F, 0x80, /* ##### */ + + /* @138 '1' (5 pixels wide) */ + 0x20, 0x80, /* # # */ + 0x20, 0x40, /* # # */ + 0x3F, 0xC0, /* ######## */ + 0x20, 0x00, /* # */ + 0x20, 0x00, /* # */ + + /* @148 '2' (5 pixels wide) */ + 0x20, 0x80, /* # # */ + 0x30, 0x40, /* ## # */ + 0x28, 0x40, /* # # # */ + 0x24, 0x40, /* # # # */ + 0x23, 0x80, /* # ### */ + + /* @158 '3' (5 pixels wide) */ + 0x20, 0x40, /* # # */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x1D, 0x80, /* ### ## */ + + /* @168 '4' (6 pixels wide) */ + 0x0C, 0x00, /* ## */ + 0x0A, 0x00, /* # # */ + 0x09, 0x00, /* # # */ + 0x08, 0xC0, /* # ## */ + 0x3F, 0xC0, /* ######## */ + 0x08, 0x00, /* # */ + + /* @180 '5' (5 pixels wide) */ + 0x23, 0xC0, /* # #### */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x32, 0x40, /* ## # # */ + 0x1C, 0x40, /* ### # */ + + /* @190 '6' (5 pixels wide) */ + 0x1F, 0x00, /* ##### */ + 0x22, 0xC0, /* # # ## */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x1C, 0x00, /* ### */ + + /* @200 '7' (5 pixels wide) */ + 0x00, 0x40, /* # */ + 0x30, 0x40, /* ## # */ + 0x1C, 0x40, /* ### # */ + 0x03, 0x40, /* ## # */ + 0x00, 0xC0, /* ## */ + + /* @210 '8' (5 pixels wide) */ + 0x1D, 0x80, /* ### ## */ + 0x27, 0x40, /* # ### # */ + 0x22, 0x40, /* # # # */ + 0x26, 0x40, /* # ## # */ + 0x1D, 0x80, /* ### ## */ + + /* @220 '9' (5 pixels wide) */ + 0x23, 0x80, /* # ### */ + 0x24, 0x40, /* # # # */ + 0x24, 0x40, /* # # # */ + 0x14, 0x40, /* # # # */ + 0x0F, 0x80, /* ##### */ + + /* @230 ':' (2 pixels wide) */ + 0x33, 0x00, /* ## ## */ + 0x33, 0x00, /* ## ## */ + + /* @234 ';' (3 pixels wide) */ + 0x80, 0x00, /* # */ + 0xF3, 0x00, /* #### ## */ + 0x73, 0x00, /* ### ## */ + + /* @240 '<' (5 pixels wide) */ + 0x04, 0x00, /* # */ + 0x0A, 0x00, /* # # */ + 0x11, 0x00, /* # # */ + 0x11, 0x00, /* # # */ + 0x20, 0x80, /* # # */ + + /* @250 '=' (5 pixels wide) */ + 0x0A, 0x00, /* # # */ + 0x0A, 0x00, /* # # */ + 0x0A, 0x00, /* # # */ + 0x0A, 0x00, /* # # */ + 0x0A, 0x00, /* # # */ + + /* @260 '>' (5 pixels wide) */ + 0x20, 0x80, /* # # */ + 0x11, 0x00, /* # # */ + 0x11, 0x00, /* # # */ + 0x0A, 0x00, /* # # */ + 0x04, 0x00, /* # */ + + /* @270 '?' (4 pixels wide) */ + 0x34, 0x40, /* ## # # */ + 0x34, 0x40, /* ## # # */ + 0x04, 0x80, /* # # */ + 0x03, 0x80, /* ### */ + + /* @278 '@' (7 pixels wide) */ + 0x3E, 0x00, /* ##### */ + 0xC1, 0x80, /* ## ## */ + 0x9C, 0xC0, /* # ### ## */ + 0x92, 0x40, /* # # # # */ + 0x9E, 0x40, /* # #### # */ + 0x10, 0xC0, /* # ## */ + 0x0F, 0x80, /* ##### */ + + /* @292 'A' (5 pixels wide) */ + 0x3C, 0x00, /* #### */ + 0x0B, 0x80, /* # ### */ + 0x08, 0x40, /* # # */ + 0x0B, 0x80, /* # ### */ + 0x3C, 0x00, /* #### */ + + /* @302 'B' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x1D, 0x80, /* ### ## */ + + /* @312 'C' (5 pixels wide) */ + 0x1F, 0x00, /* ##### */ + 0x30, 0x80, /* ## # */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + + /* @322 'D' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + 0x30, 0xC0, /* ## ## */ + 0x0F, 0x80, /* ##### */ + + /* @332 'E' (4 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + + /* @340 'F' (4 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x02, 0x40, /* # # */ + 0x02, 0x40, /* # # */ + 0x02, 0x40, /* # # */ + + /* @348 'G' (6 pixels wide) */ + 0x0F, 0x00, /* #### */ + 0x10, 0x80, /* # # */ + 0x20, 0x40, /* # # */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x3E, 0x40, /* ##### # */ + + /* @360 'H' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x3F, 0xC0, /* ######## */ + + /* @370 'I' (5 pixels wide) */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + 0x3F, 0xC0, /* ######## */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + + /* @380 'J' (4 pixels wide) */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + 0x1F, 0xC0, /* ####### */ + + /* @388 'K' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x06, 0x00, /* ## */ + 0x09, 0x00, /* # # */ + 0x10, 0x80, /* # # */ + 0x20, 0x40, /* # # */ + + /* @398 'L' (4 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x20, 0x00, /* # */ + 0x20, 0x00, /* # */ + 0x20, 0x00, /* # */ + + /* @406 'M' (6 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x03, 0x00, /* ## */ + 0x04, 0x00, /* # */ + 0x03, 0x00, /* ## */ + 0x3F, 0xC0, /* ######## */ + 0x20, 0x00, /* # */ + + /* @418 'N' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x01, 0xC0, /* ### */ + 0x06, 0x00, /* ## */ + 0x38, 0x00, /* ### */ + 0x3F, 0xC0, /* ######## */ + + /* @428 'O' (6 pixels wide) */ + 0x1F, 0x00, /* ##### */ + 0x30, 0xC0, /* ## ## */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + 0x30, 0xC0, /* ## ## */ + 0x0F, 0x80, /* ##### */ + + /* @440 'P' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x04, 0x40, /* # # */ + 0x04, 0x40, /* # # */ + 0x04, 0x40, /* # # */ + 0x03, 0x80, /* ### */ + + /* @450 'Q' (6 pixels wide) */ + 0x1F, 0x00, /* ##### */ + 0x30, 0xC0, /* ## ## */ + 0x60, 0x40, /* ## # */ + 0xA0, 0x40, /* # # # */ + 0xB0, 0xC0, /* # ## ## */ + 0x8F, 0x80, /* # ##### */ + + /* @462 'R' (6 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x04, 0x40, /* # # */ + 0x04, 0x40, /* # # */ + 0x0C, 0x40, /* ## # */ + 0x3B, 0x80, /* ### ### */ + 0x20, 0x00, /* # */ + + /* @474 'S' (5 pixels wide) */ + 0x21, 0x80, /* # ## */ + 0x22, 0x40, /* # # # */ + 0x22, 0x40, /* # # # */ + 0x24, 0x40, /* # # # */ + 0x18, 0x40, /* ## # */ + + /* @484 'T' (5 pixels wide) */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + 0x3F, 0xC0, /* ######## */ + 0x00, 0x40, /* # */ + 0x00, 0x40, /* # */ + + /* @494 'U' (5 pixels wide) */ + 0x1F, 0xC0, /* ####### */ + 0x20, 0x00, /* # */ + 0x20, 0x00, /* # */ + 0x20, 0x00, /* # */ + 0x1F, 0xC0, /* ####### */ + + /* @504 'V' (5 pixels wide) */ + 0x03, 0xC0, /* #### */ + 0x1E, 0x00, /* #### */ + 0x20, 0x00, /* # */ + 0x1E, 0x00, /* #### */ + 0x01, 0xC0, /* ### */ + + /* @514 'W' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x1C, 0x00, /* ### */ + 0x02, 0x00, /* # */ + 0x1C, 0x00, /* ### */ + 0x3F, 0xC0, /* ######## */ + + /* @524 'X' (7 pixels wide) */ + 0x20, 0x40, /* # # */ + 0x30, 0xC0, /* ## ## */ + 0x0F, 0x00, /* #### */ + 0x07, 0x00, /* ### */ + 0x09, 0xC0, /* # ### */ + 0x30, 0x40, /* ## # */ + 0x20, 0x00, /* # */ + + /* @538 'Y' (7 pixels wide) */ + 0x00, 0x40, /* # */ + 0x01, 0x80, /* ## */ + 0x03, 0x00, /* ## */ + 0x3C, 0x00, /* #### */ + 0x03, 0x00, /* ## */ + 0x01, 0x80, /* ## */ + 0x00, 0x40, /* # */ + + /* @552 'Z' (5 pixels wide) */ + 0x20, 0x40, /* # # */ + 0x38, 0x40, /* ### # */ + 0x26, 0x40, /* # ## # */ + 0x21, 0xC0, /* # ### */ + 0x20, 0x40, /* # # */ + + /* @562 '[' (3 pixels wide) */ + 0xFF, 0xC0, /* ########## */ + 0x80, 0x40, /* # # */ + 0x80, 0x40, /* # # */ + + /* @568 '\' (5 pixels wide) */ + 0x00, 0x40, /* # */ + 0x01, 0x80, /* ## */ + 0x0E, 0x00, /* ### */ + 0x30, 0x00, /* ## */ + 0x40, 0x00, /* # */ + + /* @578 ']' (3 pixels wide) */ + 0x80, 0x40, /* # # */ + 0x80, 0x40, /* # # */ + 0xFF, 0xC0, /* ########## */ + + /* @584 '^' (5 pixels wide) */ + 0x03, 0x00, /* ## */ + 0x00, 0x80, /* # */ + 0x00, 0x40, /* # */ + 0x00, 0x80, /* # */ + 0x03, 0x00, /* ## */ + + /* @594 '_' (7 pixels wide) */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + 0x80, 0x00, /* # */ + + /* @608 '`' (3 pixels wide) */ + 0x00, 0x20, /* # */ + 0x00, 0x60, /* ## */ + 0x00, 0x40, /* # */ + + /* @614 'a' (5 pixels wide) */ + 0x18, 0x00, /* ## */ + 0x25, 0x00, /* # # # */ + 0x25, 0x00, /* # # # */ + 0x35, 0x00, /* ## # # */ + 0x3E, 0x00, /* ##### */ + + /* @624 'b' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x23, 0x00, /* # ## */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + 0x1E, 0x00, /* #### */ + + /* @634 'c' (5 pixels wide) */ + 0x1E, 0x00, /* #### */ + 0x33, 0x00, /* ## ## */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + + /* @644 'd' (5 pixels wide) */ + 0x1E, 0x00, /* #### */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + 0x11, 0x00, /* # # */ + 0x3F, 0xC0, /* ######## */ + + /* @654 'e' (5 pixels wide) */ + 0x1E, 0x00, /* #### */ + 0x35, 0x00, /* ## # # */ + 0x25, 0x00, /* # # # */ + 0x25, 0x00, /* # # # */ + 0x26, 0x00, /* # ## */ + + /* @664 'f' (7 pixels wide) */ + 0x02, 0x00, /* # */ + 0x02, 0x00, /* # */ + 0x3F, 0x80, /* ####### */ + 0x02, 0x40, /* # # */ + 0x02, 0x40, /* # # */ + 0x02, 0x40, /* # # */ + 0x00, 0x40, /* # */ + + /* @678 'g' (6 pixels wide) */ + 0xFE, 0x00, /* ####### */ + 0xA9, 0x00, /* # # # # */ + 0xA9, 0x00, /* # # # # */ + 0xA9, 0x00, /* # # # # */ + 0x67, 0x00, /* ## ### */ + 0x01, 0x00, /* # */ + + /* @690 'h' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x02, 0x00, /* # */ + 0x01, 0x00, /* # */ + 0x01, 0x00, /* # */ + 0x3E, 0x00, /* ##### */ + + /* @700 'i' (5 pixels wide) */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + 0x3F, 0x60, /* ###### ## */ + 0x20, 0x60, /* # ## */ + 0x20, 0x00, /* # */ + + /* @710 'j' (4 pixels wide) */ + 0x81, 0x00, /* # # */ + 0x81, 0x00, /* # # */ + 0x81, 0x60, /* # # ## */ + 0x7F, 0x60, /* ####### ## */ + + /* @718 'k' (5 pixels wide) */ + 0x3F, 0xC0, /* ######## */ + 0x04, 0x00, /* # */ + 0x0A, 0x00, /* # # */ + 0x11, 0x00, /* # # */ + 0x20, 0x00, /* # */ + + /* @728 'l' (5 pixels wide) */ + 0x20, 0x40, /* # # */ + 0x20, 0x40, /* # # */ + 0x3F, 0xC0, /* ######## */ + 0x20, 0x00, /* # */ + 0x20, 0x00, /* # */ + + /* @738 'm' (5 pixels wide) */ + 0x3F, 0x00, /* ###### */ + 0x01, 0x00, /* # */ + 0x3F, 0x00, /* ###### */ + 0x01, 0x00, /* # */ + 0x3F, 0x00, /* ###### */ + + /* @748 'n' (5 pixels wide) */ + 0x3F, 0x00, /* ###### */ + 0x03, 0x00, /* ## */ + 0x01, 0x00, /* # */ + 0x01, 0x00, /* # */ + 0x3E, 0x00, /* ##### */ + + /* @758 'o' (5 pixels wide) */ + 0x1E, 0x00, /* #### */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + 0x1E, 0x00, /* #### */ + + /* @768 'p' (5 pixels wide) */ + 0xFF, 0x00, /* ######## */ + 0x23, 0x00, /* # ## */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + 0x1E, 0x00, /* #### */ + + /* @778 'q' (5 pixels wide) */ + 0x1E, 0x00, /* #### */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + 0x11, 0x00, /* # # */ + 0xFF, 0x00, /* ######## */ + + /* @788 'r' (5 pixels wide) */ + 0x3F, 0x00, /* ###### */ + 0x02, 0x00, /* # */ + 0x01, 0x00, /* # */ + 0x01, 0x00, /* # */ + 0x03, 0x00, /* ## */ + + /* @798 's' (4 pixels wide) */ + 0x26, 0x00, /* # ## */ + 0x25, 0x00, /* # # # */ + 0x29, 0x00, /* # # # */ + 0x19, 0x00, /* ## # */ + + /* @806 't' (5 pixels wide) */ + 0x01, 0x00, /* # */ + 0x01, 0x00, /* # */ + 0x3F, 0xC0, /* ######## */ + 0x21, 0x00, /* # # */ + 0x21, 0x00, /* # # */ + + /* @816 'u' (5 pixels wide) */ + 0x1F, 0x00, /* ##### */ + 0x20, 0x00, /* # */ + 0x20, 0x00, /* # */ + 0x30, 0x00, /* ## */ + 0x3F, 0x00, /* ###### */ + + /* @826 'v' (5 pixels wide) */ + 0x07, 0x00, /* ### */ + 0x18, 0x00, /* ## */ + 0x20, 0x00, /* # */ + 0x18, 0x00, /* ## */ + 0x07, 0x00, /* ### */ + + /* @836 'w' (5 pixels wide) */ + 0x1F, 0x00, /* ##### */ + 0x30, 0x00, /* ## */ + 0x0E, 0x00, /* ### */ + 0x18, 0x00, /* ## */ + 0x3F, 0x00, /* ###### */ + + /* @846 'x' (7 pixels wide) */ + 0x20, 0x00, /* # */ + 0x31, 0x00, /* ## # */ + 0x0B, 0x00, /* # ## */ + 0x04, 0x00, /* # */ + 0x0B, 0x00, /* # ## */ + 0x31, 0x00, /* ## # */ + 0x20, 0x00, /* # */ + + /* @860 'y' (6 pixels wide) */ + 0x80, 0x00, /* # */ + 0x83, 0x00, /* # ## */ + 0xDC, 0x00, /* ## ### */ + 0x30, 0x00, /* ## */ + 0x0C, 0x00, /* ## */ + 0x03, 0x00, /* ## */ + + /* @872 'z' (5 pixels wide) */ + 0x21, 0x00, /* # # */ + 0x31, 0x00, /* ## # */ + 0x2D, 0x00, /* # ## # */ + 0x23, 0x00, /* # ## */ + 0x21, 0x00, /* # # */ + + /* @882 '{' (5 pixels wide) */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + 0x7B, 0x80, /* #### ### */ + 0x80, 0x40, /* # # */ + 0x80, 0x40, /* # # */ + + /* @892 '|' (1 pixels wide) */ + 0xFF, 0xF0, /* ############ */ + + /* @894 '}' (5 pixels wide) */ + 0x80, 0x40, /* # # */ + 0x80, 0x40, /* # # */ + 0x7B, 0x80, /* #### ### */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + + /* @904 '~' (6 pixels wide) */ + 0x0C, 0x00, /* ## */ + 0x04, 0x00, /* # */ + 0x04, 0x00, /* # */ + 0x08, 0x00, /* # */ + 0x08, 0x00, /* # */ + 0x0C, 0x00, /* ## */ +}; + +/* Character descriptors for Consolas 9pt */ +/* { [Char width in bits], [Offset into consolas9ptCharBitmaps in bytes] } */ +const FONT_CHAR_INFO consolas9ptCharDescriptors[] = +{ + {2, 0}, /* */ + {2, 4}, /* ! */ + {3, 8}, /* " */ + {6, 14}, /* # */ + {5, 26}, /* $ */ + {7, 36}, /* % */ + {7, 50}, /* & */ + {1, 64}, /* ' */ + {3, 66}, /* ( */ + {3, 72}, /* ) */ + {5, 78}, /* * */ + {5, 88}, /* + */ + {3, 98}, /* , */ + {4, 104}, /* - */ + {2, 112}, /* . */ + {5, 116}, /* / */ + {6, 126}, /* 0 */ + {5, 138}, /* 1 */ + {5, 148}, /* 2 */ + {5, 158}, /* 3 */ + {6, 168}, /* 4 */ + {5, 180}, /* 5 */ + {5, 190}, /* 6 */ + {5, 200}, /* 7 */ + {5, 210}, /* 8 */ + {5, 220}, /* 9 */ + {2, 230}, /* : */ + {3, 234}, /* ; */ + {5, 240}, /* < */ + {5, 250}, /* = */ + {5, 260}, /* > */ + {4, 270}, /* ? */ + {7, 278}, /* @ */ + {5, 292}, /* A */ + {5, 302}, /* B */ + {5, 312}, /* C */ + {5, 322}, /* D */ + {4, 332}, /* E */ + {4, 340}, /* F */ + {6, 348}, /* G */ + {5, 360}, /* H */ + {5, 370}, /* I */ + {4, 380}, /* J */ + {5, 388}, /* K */ + {4, 398}, /* L */ + {6, 406}, /* M */ + {5, 418}, /* N */ + {6, 428}, /* O */ + {5, 440}, /* P */ + {6, 450}, /* Q */ + {6, 462}, /* R */ + {5, 474}, /* S */ + {5, 484}, /* T */ + {5, 494}, /* U */ + {5, 504}, /* V */ + {5, 514}, /* W */ + {7, 524}, /* X */ + {7, 538}, /* Y */ + {5, 552}, /* Z */ + {3, 562}, /* [ */ + {5, 568}, /* \ */ + {3, 578}, /* ] */ + {5, 584}, /* ^ */ + {7, 594}, /* _ */ + {3, 608}, /* ` */ + {5, 614}, /* a */ + {5, 624}, /* b */ + {5, 634}, /* c */ + {5, 644}, /* d */ + {5, 654}, /* e */ + {7, 664}, /* f */ + {6, 678}, /* g */ + {5, 690}, /* h */ + {5, 700}, /* i */ + {4, 710}, /* j */ + {5, 718}, /* k */ + {5, 728}, /* l */ + {5, 738}, /* m */ + {5, 748}, /* n */ + {5, 758}, /* o */ + {5, 768}, /* p */ + {5, 778}, /* q */ + {5, 788}, /* r */ + {4, 798}, /* s */ + {5, 806}, /* t */ + {5, 816}, /* u */ + {5, 826}, /* v */ + {5, 836}, /* w */ + {7, 846}, /* x */ + {6, 860}, /* y */ + {5, 872}, /* z */ + {5, 882}, /* { */ + {1, 892}, /* | */ + {5, 894}, /* } */ + {6, 904}, /* ~ */ +}; + +/* Font information for Consolas 9pt */ +const FONT_INFO consolas9ptFontInfo = +{ + 2, /* Character height */ + ' ', /* Start character */ + consolas9ptCharDescriptors, /* Character decriptor array */ + consolas9ptCharBitmaps, /* Character bitmap array */ +}; diff --git a/macusbfb/drivers/lcd/fonts/consolas9.h b/macusbfb/drivers/lcd/fonts/consolas9.h new file mode 100644 index 0000000..483880d --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/consolas9.h @@ -0,0 +1,6 @@ +#include "bitmapfonts.h" + +/* Font data for Consolas 9pt */ +extern const uint8_t consolas9ptCharBitmaps[]; +extern const FONT_CHAR_INFO consolas9ptCharDescriptors[]; +extern const FONT_INFO consolas9ptFontInfo; diff --git a/macusbfb/drivers/lcd/fonts/smallfonts.c b/macusbfb/drivers/lcd/fonts/smallfonts.c new file mode 100644 index 0000000..925f122 --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/smallfonts.c @@ -0,0 +1,561 @@ +/* Partially based on original code for the KS0108 by Stephane Rey */ +/* Current version by Kevin Townsend */ + +/**************************************************************************/ +/*! + @file smallfonts.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include "sysdefs.h" +#include "smallfonts.h" + +#if defined CFG_LCD_INCLUDESMALLFONTS & CFG_LCD_INCLUDESMALLFONTS == 1 + +/* Global variables */ +const struct FONT_DEF Font_System3x6 = {3, 6, 32, 96, au8FontSystem3x6}; +const struct FONT_DEF Font_System5x8 = {5, 8, 32, 128, au8FontSystem5x8}; +const struct FONT_DEF Font_System7x8 = {7, 8, 32, 128, au8FontSystem7x8}; +const struct FONT_DEF Font_8x8 = {8, 8, 32, 128, au8Font8x8}; +const struct FONT_DEF Font_8x8Thin = {8, 8, 32, 128, au8Font8x8Thin}; + +/* System 3x6 - UPPER CASE ONLY */ +const uint8_t au8FontSystem3x6[]= { + 0x00,0x00,0x00, /* Space */ + 0x00,0x5C,0x00, /* ! */ + 0x0C,0x00,0x0C, /* " */ + 0x7C,0x28,0x7C, /* # */ + 0x7C,0x44,0x7C, /* 0x */ + 0x24,0x10,0x48, /* % */ + 0x28,0x54,0x08, /* & */ + 0x00,0x0C,0x00, /* ' */ + 0x38,0x44,0x00, /* ( */ + 0x44,0x38,0x00, /* ) */ + 0x20,0x10,0x08, /* // */ + 0x10,0x38,0x10, /* + */ + 0x80,0x40,0x00, /* , */ + 0x10,0x10,0x10, /* - */ + 0x00,0x40,0x00, /* . */ + 0x20,0x10,0x08, /* / */ + 0x38,0x44,0x38, /* 0 */ + 0x00,0x7C,0x00, /* 1 */ + 0x64,0x54,0x48, /* 2 */ + 0x44,0x54,0x28, /* 3 */ + 0x1C,0x10,0x7C, /* 4 */ + 0x4C,0x54,0x24, /* 5 */ + 0x38,0x54,0x20, /* 6 */ + 0x04,0x74,0x0C, /* 7 */ + 0x28,0x54,0x28, /* 8 */ + 0x08,0x54,0x38, /* 9 */ + 0x00,0x50,0x00, /* : */ + 0x80,0x50,0x00, /* ; */ + 0x10,0x28,0x44, /* < */ + 0x28,0x28,0x28, /* = */ + 0x44,0x28,0x10, /* > */ + 0x04,0x54,0x08, /* ? */ + 0x38,0x4C,0x5C, /* @ */ + 0x78,0x14,0x78, /* A */ + 0x7C,0x54,0x28, /* B */ + 0x38,0x44,0x44, /* C */ + 0x7C,0x44,0x38, /* D */ + 0x7C,0x54,0x44, /* E */ + 0x7C,0x14,0x04, /* F */ + 0x38,0x44,0x34, /* G */ + 0x7C,0x10,0x7C, /* H */ + 0x00,0x7C,0x00, /* I */ + 0x20,0x40,0x3C, /* J */ + 0x7C,0x10,0x6C, /* K */ + 0x7C,0x40,0x40, /* L */ + 0x7C,0x08,0x7C, /* M */ + 0x7C,0x04,0x7C, /* N */ + 0x7C,0x44,0x7C, /* O */ + 0x7C,0x14,0x08, /* P */ + 0x38,0x44,0x78, /* Q */ + 0x7C,0x14,0x68, /* R */ + 0x48,0x54,0x24, /* S */ + 0x04,0x7C,0x04, /* T */ + 0x7C,0x40,0x7C, /* U */ + 0x3C,0x40,0x3C, /* V */ + 0x7C,0x20,0x7C, /* W */ + 0x6C,0x10,0x6C, /* X */ + 0x1C,0x60,0x1C, /* Y */ + 0x64,0x54,0x4C, /* Z */ + 0x7C,0x44,0x00, /* [ */ + 0x08,0x10,0x20, /* \ */ + 0x44,0x7C,0x00, /* ] */ + 0x08,0x04,0x08, /* ^ */ + 0x80,0x80,0x80, /* _ */ + 0x04,0x08,0x00 /* ` */ +}; + +/* System 5x8 */ +const uint8_t au8FontSystem5x8[]= +{ + 0x00,0x00,0x00,0x00,0x00, /* Space */ + 0x00,0x00,0x4f,0x00,0x00, /* ! */ + 0x00,0x07,0x00,0x07,0x00, /* " */ + 0x14,0x7f,0x14,0x7f,0x14, /* # */ + 0x24,0x2a,0x7f,0x2a,0x12, /* 0x */ + 0x23,0x13,0x08,0x64,0x62, /* % */ + 0x36,0x49,0x55,0x22,0x20, /* & */ + 0x00,0x05,0x03,0x00,0x00, /* ' */ + 0x00,0x1c,0x22,0x41,0x00, /* ( */ + 0x00,0x41,0x22,0x1c,0x00, /* ) */ + 0x14,0x08,0x3e,0x08,0x14, /* // */ + 0x08,0x08,0x3e,0x08,0x08, /* + */ + 0x50,0x30,0x00,0x00,0x00, /* , */ + 0x08,0x08,0x08,0x08,0x08, /* - */ + 0x00,0x60,0x60,0x00,0x00, /* . */ + 0x20,0x10,0x08,0x04,0x02, /* / */ + 0x3e,0x51,0x49,0x45,0x3e, /* 0 */ + 0x00,0x42,0x7f,0x40,0x00, /* 1 */ + 0x42,0x61,0x51,0x49,0x46, /* 2 */ + 0x21,0x41,0x45,0x4b,0x31, /* 3 */ + 0x18,0x14,0x12,0x7f,0x10, /* 4 */ + 0x27,0x45,0x45,0x45,0x39, /* 5 */ + 0x3c,0x4a,0x49,0x49,0x30, /* 6 */ + 0x01,0x71,0x09,0x05,0x03, /* 7 */ + 0x36,0x49,0x49,0x49,0x36, /* 8 */ + 0x06,0x49,0x49,0x29,0x1e, /* 9 */ + 0x00,0x36,0x36,0x00,0x00, /* : */ + 0x00,0x56,0x36,0x00,0x00, /* ; */ + 0x08,0x14,0x22,0x41,0x00, /* < */ + 0x14,0x14,0x14,0x14,0x14, /* = */ + 0x00,0x41,0x22,0x14,0x08, /* > */ + 0x02,0x01,0x51,0x09,0x06, /* ? */ + 0x3e,0x41,0x5d,0x55,0x1e, /* @ */ + 0x7e,0x11,0x11,0x11,0x7e, /* A */ + 0x7f,0x49,0x49,0x49,0x36, /* B */ + 0x3e,0x41,0x41,0x41,0x22, /* C */ + 0x7f,0x41,0x41,0x22,0x1c, /* D */ + 0x7f,0x49,0x49,0x49,0x41, /* E */ + 0x7f,0x09,0x09,0x09,0x01, /* F */ + 0x3e,0x41,0x49,0x49,0x7a, /* G */ + 0x7f,0x08,0x08,0x08,0x7f, /* H */ + 0x00,0x41,0x7f,0x41,0x00, /* I */ + 0x20,0x40,0x41,0x3f,0x01, /* J */ + 0x7f,0x08,0x14,0x22,0x41, /* K */ + 0x7f,0x40,0x40,0x40,0x40, /* L */ + 0x7f,0x02,0x0c,0x02,0x7f, /* M */ + 0x7f,0x04,0x08,0x10,0x7f, /* N */ + 0x3e,0x41,0x41,0x41,0x3e, /* O */ + 0x7f,0x09,0x09,0x09,0x06, /* P */ + 0x3e,0x41,0x51,0x21,0x5e, /* Q */ + 0x7f,0x09,0x19,0x29,0x46, /* R */ + 0x26,0x49,0x49,0x49,0x32, /* S */ + 0x01,0x01,0x7f,0x01,0x01, /* T */ + 0x3f,0x40,0x40,0x40,0x3f, /* U */ + 0x1f,0x20,0x40,0x20,0x1f, /* V */ + 0x3f,0x40,0x38,0x40,0x3f, /* W */ + 0x63,0x14,0x08,0x14,0x63, /* X */ + 0x07,0x08,0x70,0x08,0x07, /* Y */ + 0x61,0x51,0x49,0x45,0x43, /* Z */ + 0x00,0x7f,0x41,0x41,0x00, /* [ */ + 0x02,0x04,0x08,0x10,0x20, /* \ */ + 0x00,0x41,0x41,0x7f,0x00, /* ] */ + 0x04,0x02,0x01,0x02,0x04, /* ^ */ + 0x40,0x40,0x40,0x40,0x40, /* _ */ + 0x00,0x00,0x03,0x05,0x00, /* ` */ + 0x20,0x54,0x54,0x54,0x78, /* a */ + 0x7F,0x44,0x44,0x44,0x38, /* b */ + 0x38,0x44,0x44,0x44,0x44, /* c */ + 0x38,0x44,0x44,0x44,0x7f, /* d */ + 0x38,0x54,0x54,0x54,0x18, /* e */ + 0x04,0x04,0x7e,0x05,0x05, /* f */ + 0x08,0x54,0x54,0x54,0x3c, /* g */ + 0x7f,0x08,0x04,0x04,0x78, /* h */ + 0x00,0x44,0x7d,0x40,0x00, /* i */ + 0x20,0x40,0x44,0x3d,0x00, /* j */ + 0x7f,0x10,0x28,0x44,0x00, /* k */ + 0x00,0x41,0x7f,0x40,0x00, /* l */ + 0x7c,0x04,0x7c,0x04,0x78, /* m */ + 0x7c,0x08,0x04,0x04,0x78, /* n */ + 0x38,0x44,0x44,0x44,0x38, /* o */ + 0x7c,0x14,0x14,0x14,0x08, /* p */ + 0x08,0x14,0x14,0x14,0x7c, /* q */ + 0x7c,0x08,0x04,0x04,0x00, /* r */ + 0x48,0x54,0x54,0x54,0x24, /* s */ + 0x04,0x04,0x3f,0x44,0x44, /* t */ + 0x3c,0x40,0x40,0x20,0x7c, /* u */ + 0x1c,0x20,0x40,0x20,0x1c, /* v */ + 0x3c,0x40,0x30,0x40,0x3c, /* w */ + 0x44,0x28,0x10,0x28,0x44, /* x */ + 0x0c,0x50,0x50,0x50,0x3c, /* y */ + 0x44,0x64,0x54,0x4c,0x44, /* z */ + 0x08,0x36,0x41,0x41,0x00, /* { */ + 0x00,0x00,0x77,0x00,0x00, /* | */ + 0x00,0x41,0x41,0x36,0x08, /* } */ + 0x08,0x08,0x2a,0x1c,0x08, /* <- */ + 0x08,0x1c,0x2a,0x08,0x08, /* -> */ + 0xff,0xff,0xff,0xff,0xff, /*  */ +}; + +/* System 7x8 */ +const uint8_t au8FontSystem7x8[]= +{ + 0, 0, 0, 0, 0, 0, 0, //' ' + 0, 6, 95, 95, 6, 0, 0, //'!' + 0, 7, 7, 0, 7, 7, 0, //'"' + 20, 127, 127, 20, 127, 127, 20, //'#' + 36, 46, 107, 107, 58, 18, 0, //'$' + 70, 102, 48, 24, 12, 102, 98, //'%' + 48, 122, 79, 93, 55, 122, 72, //'&' + 4, 7, 3, 0, 0, 0, 0, //''' + 0, 28, 62, 99, 65, 0, 0, //'(' + 0, 65, 99, 62, 28, 0, 0, //')' + 8, 42, 62, 28, 28, 62, 42, //'*' + 8, 8, 62, 62, 8, 8, 0, //'+' + 0, 128, 224, 96, 0, 0, 0, //',' + 8, 8, 8, 8, 8, 8, 0, //'-' + 0, 0, 96, 96, 0, 0, 0, //'.' + 96, 48, 24, 12, 6, 3, 1, //'/' + 62, 127, 113, 89, 77, 127, 62, //'0' + 64, 66, 127, 127, 64, 64, 0, //'1' + 98, 115, 89, 73, 111, 102, 0, //'2' + 34, 99, 73, 73, 127, 54, 0, //'3' + 24, 28, 22, 83, 127, 127, 80, //'4' + 39, 103, 69, 69, 125, 57, 0, //'5' + 60, 126, 75, 73, 121, 48, 0, //'6' + 3, 3, 113, 121, 15, 7, 0, //'7' + 54, 127, 73, 73, 127, 54, 0, //'8' + 6, 79, 73, 105, 63, 30, 0, //'9' + 0, 0, 102, 102, 0, 0, 0, //':' + 0, 128, 230, 102, 0, 0, 0, //';' + 8, 28, 54, 99, 65, 0, 0, //'<' + 36, 36, 36, 36, 36, 36, 0, //'=' + 0, 65, 99, 54, 28, 8, 0, //'>' + 2, 3, 81, 89, 15, 6, 0, //'?' + 62, 127, 65, 93, 93, 31, 30, //'@' + 124,126, 19, 19, 126, 124, 0, //'A' + 65, 127, 127, 73, 73, 127, 54, //'B' + 28, 62, 99, 65, 65, 99, 34, //'C' + 65, 127, 127, 65, 99, 62, 28, //'D' + 65, 127, 127, 73, 93, 65, 99, //'E' + 65, 127, 127, 73, 29, 1, 3, //'F' + 28, 62, 99, 65, 81, 115, 114, //'G' + 127,127, 8, 8, 127, 127, 0, //'H' + 0, 65, 127, 127, 65, 0, 0, //'I' + 48, 112, 64, 65, 127, 63, 1, //'J' + 65, 127, 127, 8, 28, 119, 99, //'K' + 65, 127, 127, 65, 64, 96, 112, //'L' + 127,127, 14, 28, 14, 127, 127, //'M' + 127,127, 6, 12, 24, 127, 127, //'N' + 28, 62, 99, 65, 99, 62, 28, //'O' + 65, 127, 127, 73, 9, 15, 6, //'P' + 30, 63, 33, 113, 127, 94, 0, //'Q' + 65, 127, 127, 9, 25, 127, 102, //'R' + 38, 111, 77, 89, 115, 50, 0, //'S' + 3, 65, 127, 127, 65, 3, 0, //'T' + 127,127, 64, 64, 127, 127, 0, //'U' + 31, 63, 96, 96, 63, 31, 0, //'V' + 127,127, 48, 24, 48, 127, 127, //'W' + 67, 103, 60, 24, 60, 103, 67, //'X' + 7, 79, 120, 120, 79, 7, 0, //'Y' + 71, 99, 113, 89, 77, 103, 115, //'Z' + 0, 127, 127, 65, 65, 0, 0, //'[' + 1, 3, 6, 12, 24, 48, 96, //'\' + 0, 65, 65, 127, 127, 0, 0, //']' + 8, 12, 6, 3, 6, 12, 8, //'^' + 128,128, 128, 128, 128, 128, 128, //'_' + 0, 0, 3, 7, 4, 0, 0, //'`' + 32, 116, 84, 84, 60, 120, 64, //'a' + 65, 127, 63, 72, 72, 120, 48, //'b' + 56, 124, 68, 68, 108, 40, 0, //'c' + 48, 120, 72, 73, 63, 127, 64, //'d' + 56, 124, 84, 84, 92, 24, 0, //'e' + 72, 126, 127, 73, 3, 2, 0, //'f' + 56, 188, 164, 164, 252, 120, 0, //'g' + 65, 127, 127, 8, 4, 124, 120, //'h' + 0, 68, 125, 125, 64, 0, 0, //'i' + 96, 224, 128, 128, 253, 125, 0, //'j' + 65, 127, 127, 16, 56, 108, 68, //'k' + 0, 65, 127, 127, 64, 0, 0, //'l' + 120,124, 28, 56, 28, 124, 120, //'m' + 124,124, 4, 4, 124, 120, 0, //'n' + 56, 124, 68, 68, 124, 56, 0, //'o' + 0, 252, 252, 164, 36, 60, 24, //'p' + 24, 60, 36, 164, 248, 252, 132, //'q' + 68, 124, 120, 76, 4, 28, 24, //'r' + 72, 92, 84, 84, 116, 36, 0, //'s' + 0, 4, 62, 127, 68, 36, 0, //'t' + 60, 124, 64, 64, 60, 124, 64, //'u' + 28, 60, 96, 96, 60, 28, 0, //'v' + 60, 124, 112, 56, 112, 124, 60, //'w' + 68, 108, 56, 16, 56, 108, 68, //'x' + 60, 188, 160, 160, 252, 124, 0, //'y' + 76, 100, 116, 92, 76, 100, 0, //'z' + 8, 8, 62, 119, 65, 65, 0, //'{' + 0, 0, 0, 119, 119, 0, 0, //'|' + 65, 65, 119, 62, 8, 8, 0, //'}' + 2, 3, 1, 3, 2, 3, 1, //'~' + 255,129, 129, 129, 129, 129, 255, //'' + 14, 159, 145, 177, 251, 74, 0 //'Á' +}; + +/* 8x8 Normal */ +const uint8_t au8Font8x8[]= { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ASCII - 32 + 0x00,0x00,0x00,0x5F,0x5F,0x00,0x00,0x00, // ASCII - 33 + 0x00,0x00,0x03,0x07,0x00,0x07,0x03,0x00, // ASCII - 34 + 0x00,0x10,0x74,0x1C,0x77,0x1C,0x17,0x04, // ASCII - 35 + 0x00,0x24,0x2E,0x2A,0x7F,0x2A,0x3A,0x10, // ASCII - 36 + 0x00,0x4C,0x6A,0x76,0x1A,0x6A,0x56,0x33, // ASCII - 37 + 0x00,0x30,0x7A,0x4F,0x5D,0x37,0x7A,0x48, // ASCII - 38 + 0x00,0x00,0x04,0x07,0x03,0x00,0x00,0x00, // ASCII - 39 + 0x00,0x00,0x00,0x1C,0x3E,0x63,0x41,0x00, // ASCII - 40 + 0x00,0x00,0x41,0x63,0x3E,0x1C,0x00,0x00, // ASCII - 41 + 0x00,0x08,0x2A,0x3E,0x1C,0x3E,0x2A,0x08, // ASCII - 42 + 0x00,0x08,0x08,0x3E,0x3E,0x08,0x08,0x00, // ASCII - 43 + 0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00, // ASCII - 44 + 0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00, // ASCII - 45 + 0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00, // ASCII - 46 + 0x00,0x60,0x30,0x18,0x0C,0x06,0x03,0x01, // ASCII - 47 + 0x00,0x1C,0x3E,0x61,0x43,0x3E,0x1C,0x00, // ASCII - 48 + 0x00,0x00,0x44,0x7F,0x7F,0x40,0x00,0x00, // ASCII - 49 + 0x00,0x46,0x67,0x71,0x59,0x4F,0x66,0x00, // ASCII - 50 + 0x00,0x22,0x63,0x49,0x4D,0x7F,0x32,0x00, // ASCII - 51 + 0x00,0x18,0x1C,0x52,0x7F,0x7F,0x50,0x00, // ASCII - 52 + 0x00,0x2F,0x6F,0x45,0x45,0x7D,0x39,0x00, // ASCII - 53 + 0x00,0x3C,0x7E,0x4B,0x49,0x79,0x30,0x00, // ASCII - 54 + 0x00,0x07,0x43,0x71,0x7D,0x0F,0x03,0x00, // ASCII - 55 + 0x00,0x36,0x7F,0x4D,0x59,0x7F,0x36,0x00, // ASCII - 56 + 0x00,0x06,0x4F,0x49,0x69,0x3F,0x1E,0x00, // ASCII - 57 + 0x00,0x00,0x00,0x66,0x66,0x00,0x00,0x00, // ASCII - 58 + 0x00,0x00,0x00,0x66,0x66,0x00,0x00,0x00, // ASCII - 59 + 0x00,0x00,0x08,0x1C,0x36,0x63,0x41,0x00, // ASCII - 60 + 0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00, // ASCII - 61 + 0x00,0x00,0x41,0x63,0x36,0x1C,0x08,0x00, // ASCII - 62 + 0x00,0x02,0x07,0x51,0x59,0x0F,0x06,0x00, // ASCII - 63 + 0x00,0x3E,0x41,0x5D,0x55,0x5D,0x51,0x1E, // ASCII - 64 + 0x00,0x40,0x70,0x1D,0x17,0x1F,0x78,0x60, // ASCII - 65 + 0x00,0x41,0x7F,0x7F,0x49,0x4F,0x7E,0x30, // ASCII - 66 + 0x00,0x1C,0x3E,0x63,0x41,0x41,0x42,0x27, // ASCII - 67 + 0x00,0x41,0x7F,0x7F,0x41,0x63,0x3E,0x1C, // ASCII - 68 + 0x00,0x41,0x7F,0x7F,0x49,0x5D,0x41,0x63, // ASCII - 69 + 0x00,0x41,0x7F,0x7F,0x49,0x1D,0x01,0x03, // ASCII - 70 + 0x00,0x1C,0x3E,0x63,0x41,0x51,0x72,0x77, // ASCII - 71 + 0x00,0x7F,0x7F,0x08,0x08,0x7F,0x7F,0x00, // ASCII - 72 + 0x00,0x00,0x41,0x7F,0x7F,0x41,0x00,0x00, // ASCII - 73 + 0x00,0x30,0x70,0x41,0x41,0x7F,0x3F,0x01, // ASCII - 74 + 0x00,0x7F,0x7F,0x08,0x1C,0x77,0x63,0x41, // ASCII - 75 + 0x00,0x41,0x7F,0x7F,0x41,0x40,0x60,0x70, // ASCII - 76 + 0x00,0x7F,0x7E,0x0C,0x18,0x0C,0x7E,0x7F, // ASCII - 77 + 0x00,0x7F,0x7E,0x0C,0x18,0x30,0x7F,0x7F, // ASCII - 78 + 0x00,0x1C,0x3E,0x63,0x41,0x63,0x3E,0x1C, // ASCII - 79 + 0x00,0x41,0x7F,0x7F,0x49,0x09,0x0F,0x06, // ASCII - 80 + 0x00,0x1C,0x3E,0x63,0x51,0x63,0x3E,0x1C, // ASCII - 81 + 0x00,0x7F,0x7F,0x09,0x19,0x7F,0x66,0x40, // ASCII - 82 + 0x00,0x66,0x6F,0x4D,0x59,0x7B,0x33,0x00, // ASCII - 83 + 0x00,0x03,0x41,0x7F,0x7F,0x41,0x03,0x00, // ASCII - 84 + 0x00,0x3F,0x7F,0x40,0x40,0x40,0x7F,0x3F, // ASCII - 85 + 0x00,0x03,0x0F,0x3D,0x70,0x1D,0x07,0x01, // ASCII - 86 + 0x00,0x0F,0x7F,0x30,0x1C,0x30,0x7F,0x0F, // ASCII - 87 + 0x00,0x63,0x77,0x1C,0x1C,0x77,0x63,0x00, // ASCII - 88 + 0x01,0x03,0x47,0x7C,0x78,0x47,0x03,0x01, // ASCII - 89 + 0x00,0x67,0x73,0x59,0x4D,0x67,0x73,0x00, // ASCII - 90 + 0x00,0x00,0x00,0x7F,0x7F,0x41,0x41,0x00, // ASCII - 91 + 0x00,0x01,0x03,0x06,0x0C,0x18,0x30,0x60, // ASCII - 92 + 0x00,0x00,0x41,0x41,0x7F,0x7F,0x00,0x00, // ASCII - 93 + 0x00,0x00,0x04,0x06,0x03,0x06,0x04,0x00, // ASCII - 94 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ASCII - 95 + 0x00,0x00,0x01,0x03,0x06,0x04,0x00,0x00, // ASCII - 96 + 0x00,0x68,0x6C,0x54,0x54,0x3C,0x78,0x40, // ASCII - 97 + 0x00,0x41,0x7F,0x3F,0x6C,0x44,0x7C,0x38, // ASCII - 98 + 0x00,0x38,0x7C,0x44,0x44,0x6C,0x2C,0x00, // ASCII - 99 + 0x00,0x38,0x7C,0x44,0x49,0x3F,0x7F,0x40, // ASCII - 100 + 0x00,0x38,0x7C,0x54,0x54,0x5C,0x58,0x00, // ASCII - 101 + 0x00,0x00,0x48,0x7E,0x7F,0x49,0x0B,0x02, // ASCII - 102 + 0x00,0x48,0x7C,0x34,0x34,0x2C,0x68,0x44, // ASCII - 103 + 0x00,0x41,0x7F,0x7F,0x08,0x04,0x7C,0x78, // ASCII - 104 + 0x00,0x00,0x44,0x7D,0x7D,0x40,0x00,0x00, // ASCII - 105 + 0x00,0x60,0x60,0x04,0x7D,0x7D,0x00,0x00, // ASCII - 106 + 0x00,0x41,0x7F,0x7F,0x10,0x78,0x6C,0x44, // ASCII - 107 + 0x00,0x00,0x41,0x7F,0x7F,0x40,0x00,0x00, // ASCII - 108 + 0x00,0x7C,0x7C,0x0C,0x78,0x0C,0x7C,0x78, // ASCII - 109 + 0x00,0x44,0x7C,0x7C,0x08,0x04,0x7C,0x78, // ASCII - 110 + 0x00,0x38,0x7C,0x44,0x44,0x7C,0x38,0x00, // ASCII - 111 + 0x00,0x04,0x7C,0x78,0x24,0x24,0x3C,0x18, // ASCII - 112 + 0x00,0x18,0x3C,0x24,0x24,0x78,0x7C,0x00, // ASCII - 113 + 0x00,0x44,0x7C,0x78,0x4C,0x04,0x1C,0x18, // ASCII - 114 + 0x00,0x48,0x5C,0x5C,0x74,0x74,0x24,0x00, // ASCII - 115 + 0x00,0x00,0x04,0x3E,0x7F,0x44,0x24,0x00, // ASCII - 116 + 0x00,0x3C,0x7C,0x40,0x40,0x3C,0x7C,0x40, // ASCII - 117 + 0x00,0x04,0x1C,0x3C,0x60,0x30,0x1C,0x04, // ASCII - 118 + 0x00,0x1C,0x7C,0x30,0x1C,0x30,0x7C,0x1C, // ASCII - 119 + 0x00,0x44,0x6C,0x3C,0x10,0x78,0x6C,0x44, // ASCII - 120 + 0x00,0x44,0x4C,0x1C,0x70,0x64,0x1C,0x0C, // ASCII - 121 + 0x00,0x4C,0x64,0x74,0x5C,0x4C,0x64,0x00, // ASCII - 122 + 0x00,0x08,0x08,0x3E,0x77,0x41,0x41,0x00, // ASCII - 123 + 0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00, // ASCII - 124 + 0x00,0x41,0x41,0x77,0x3E,0x08,0x08,0x00, // ASCII - 125 + 0x00,0x02,0x01,0x01,0x03,0x02,0x02,0x01, // ASCII - 126 + 0x00,0x60,0x78,0x4E,0x47,0x5E,0x78,0x60, // ASCII - 127 + 0x00,0x1C,0x3E,0x23,0x41,0x41,0x42,0x27, // ASCII - 128 + 0x00,0x3D,0x7D,0x40,0x41,0x3D,0x7C,0x40, // ASCII - 129 +}; + +/* 8x8 Thin */ +const uint8_t au8Font8x8Thin[]= { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00, + 0x00,0x00,0x07,0x00,0x00,0x07,0x00,0x00, + 0x00,0x14,0x7F,0x14,0x14,0x7F,0x14,0x00, + 0x00,0x24,0x2A,0x6B,0x6B,0x2A,0x12,0x00, + 0x00,0x46,0x26,0x10,0x08,0x64,0x62,0x00, + 0x30,0x4A,0x45,0x4D,0x32,0x48,0x48,0x00, + 0x00,0x00,0x04,0x03,0x00,0x00,0x00,0x00, + 0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00, + 0x00,0x00,0x41,0x22,0x1C,0x00,0x00,0x00, + 0x08,0x2A,0x1C,0x1C,0x1C,0x2A,0x08,0x00, + 0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00, + 0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00, + 0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00, + 0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00, + 0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x00, + 0x00,0x3E,0x61,0x51,0x49,0x45,0x3E,0x00, + 0x00,0x44,0x42,0x7F,0x40,0x40,0x00,0x00, + 0x00,0x62,0x51,0x51,0x49,0x49,0x66,0x00, + 0x00,0x22,0x41,0x49,0x49,0x49,0x36,0x00, + 0x10,0x18,0x14,0x52,0x7F,0x50,0x10,0x00, + 0x00,0x27,0x45,0x45,0x45,0x45,0x39,0x00, + 0x00,0x3C,0x4A,0x49,0x49,0x49,0x30,0x00, + 0x00,0x03,0x01,0x71,0x09,0x05,0x03,0x00, + 0x00,0x36,0x49,0x49,0x49,0x49,0x36,0x00, + 0x00,0x06,0x49,0x49,0x49,0x29,0x1E,0x00, + 0x00,0x00,0x00,0x66,0x00,0x00,0x00,0x00, + 0x00,0x00,0x80,0x66,0x00,0x00,0x00,0x00, + 0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00, + 0x00,0x24,0x24,0x24,0x24,0x24,0x24,0x00, + 0x00,0x00,0x00,0x41,0x22,0x14,0x08,0x00, + 0x00,0x02,0x01,0x01,0x51,0x09,0x06,0x00, + 0x00,0x3E,0x41,0x5D,0x55,0x55,0x1E,0x00, + 0x00,0x7C,0x12,0x11,0x11,0x12,0x7C,0x00, + 0x00,0x41,0x7F,0x49,0x49,0x49,0x36,0x00, + 0x00,0x1C,0x22,0x41,0x41,0x41,0x22,0x00, + 0x00,0x41,0x7F,0x41,0x41,0x22,0x1C,0x00, + 0x00,0x41,0x7F,0x49,0x5D,0x41,0x63,0x00, + 0x00,0x41,0x7F,0x49,0x1D,0x01,0x03,0x00, + 0x00,0x1C,0x22,0x41,0x51,0x51,0x72,0x00, + 0x00,0x7F,0x08,0x08,0x08,0x08,0x7F,0x00, + 0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00, + 0x00,0x30,0x40,0x40,0x41,0x3F,0x01,0x00, + 0x00,0x41,0x7F,0x08,0x14,0x22,0x41,0x40, + 0x00,0x41,0x7F,0x41,0x40,0x40,0x60,0x00, + 0x00,0x7F,0x01,0x02,0x04,0x02,0x01,0x7F, + 0x00,0x7F,0x01,0x02,0x04,0x08,0x7F,0x00, + 0x00,0x3E,0x41,0x41,0x41,0x41,0x3E,0x00, + 0x00,0x41,0x7F,0x49,0x09,0x09,0x06,0x00, + 0x00,0x1E,0x21,0x21,0x31,0x21,0x5E,0x40, + 0x00,0x41,0x7F,0x49,0x19,0x29,0x46,0x00, + 0x00,0x26,0x49,0x49,0x49,0x49,0x32,0x00, + 0x00,0x03,0x01,0x41,0x7F,0x41,0x01,0x03, + 0x00,0x3F,0x40,0x40,0x40,0x40,0x3F,0x00, + 0x00,0x0F,0x10,0x20,0x40,0x20,0x10,0x0F, + 0x00,0x3F,0x40,0x40,0x38,0x40,0x40,0x3F, + 0x00,0x41,0x22,0x14,0x08,0x14,0x22,0x41, + 0x00,0x01,0x02,0x44,0x78,0x44,0x02,0x01, + 0x00,0x43,0x61,0x51,0x49,0x45,0x43,0x61, + 0x00,0x7F,0x41,0x41,0x41,0x00,0x00,0x00, + 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x00, + 0x00,0x41,0x41,0x41,0x7F,0x00,0x00,0x00, + 0x08,0x04,0x02,0x01,0x02,0x04,0x08,0x00, + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, + 0x00,0x00,0x00,0x03,0x04,0x00,0x00,0x00, + 0x00,0x20,0x54,0x54,0x54,0x54,0x78,0x40, + 0x00,0x01,0x7F,0x30,0x48,0x48,0x48,0x30, + 0x00,0x38,0x44,0x44,0x44,0x44,0x28,0x00, + 0x00,0x30,0x48,0x48,0x48,0x31,0x7F,0x40, + 0x00,0x38,0x54,0x54,0x54,0x54,0x18,0x00, + 0x00,0x00,0x48,0x7E,0x49,0x01,0x02,0x00, + 0x00,0x98,0xA4,0xA4,0xA4,0xA4,0x78,0x04, + 0x00,0x41,0x7F,0x08,0x04,0x04,0x78,0x00, + 0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00, + 0x00,0x60,0x80,0x80,0x80,0x84,0x7D,0x00, + 0x00,0x01,0x7F,0x10,0x28,0x44,0x40,0x00, + 0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00, + 0x00,0x7C,0x04,0x04,0x78,0x04,0x04,0x78, + 0x00,0x7C,0x08,0x04,0x04,0x04,0x78,0x00, + 0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x00, + 0x00,0x84,0xFC,0x98,0x24,0x24,0x18,0x00, + 0x00,0x18,0x24,0x24,0x98,0xFC,0x84,0x00, + 0x00,0x44,0x7C,0x48,0x04,0x04,0x18,0x00, + 0x00,0x48,0x54,0x54,0x54,0x54,0x24,0x00, + 0x00,0x04,0x04,0x3F,0x44,0x44,0x20,0x00, + 0x00,0x3C,0x40,0x40,0x40,0x20,0x7C,0x00, + 0x00,0x0C,0x10,0x20,0x40,0x20,0x10,0x0C, + 0x00,0x3C,0x40,0x40,0x38,0x40,0x40,0x3C, + 0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00, + 0x00,0x9C,0xA0,0xA0,0xA0,0xA0,0x7C,0x00, + 0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00, + 0x00,0x08,0x08,0x36,0x41,0x41,0x00,0x00, + 0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00, + 0x00,0x00,0x41,0x41,0x36,0x08,0x08,0x00, + 0x00,0x02,0x01,0x01,0x02,0x02,0x01,0x00, + 0x00,0x70,0x48,0x44,0x42,0x44,0x48,0x70, + 0x00,0x0E,0x91,0x91,0xB1,0xB1,0x4A,0x00, + 0x00,0x3A,0x40,0x40,0x40,0x7A,0x40,0x00, + 0x00,0x38,0x54,0x54,0x55,0x55,0x18,0x00, + 0x00,0x22,0x55,0x55,0x55,0x79,0x42,0x00, + 0x00,0x21,0x54,0x54,0x54,0x78,0x41,0x00, + 0x00,0x20,0x55,0x55,0x54,0x78,0x40,0x00, + 0x00,0x20,0x54,0x55,0x54,0x78,0x40,0x00, + 0x00,0x18,0x24,0xA4,0xA4,0xE4,0x40,0x00, + 0x00,0x3A,0x55,0x55,0x55,0x55,0x1A,0x00, + 0x00,0x39,0x54,0x54,0x54,0x54,0x19,0x00, + 0x00,0x38,0x55,0x55,0x54,0x54,0x18,0x00, + 0x00,0x00,0x01,0x44,0x7C,0x41,0x00,0x00, + 0x02,0x01,0x45,0x7D,0x41,0x01,0x02,0x00, + 0x00,0x00,0x01,0x45,0x7C,0x40,0x00,0x00, + 0x00,0x79,0x14,0x12,0x12,0x14,0x79,0x00, + 0x00,0x70,0x28,0x2B,0x2B,0x28,0x70,0x00, + 0x00,0x44,0x7C,0x54,0x55,0x45,0x00,0x00, + 0x00,0x20,0x54,0x54,0x58,0x38,0x54,0x54, + 0x00,0x7C,0x0A,0x09,0x09,0x7F,0x49,0x49, + 0x00,0x30,0x4A,0x49,0x49,0x4A,0x30,0x00, + 0x00,0x32,0x48,0x48,0x48,0x48,0x32,0x00, + 0x00,0x30,0x49,0x4A,0x48,0x48,0x30,0x00, + 0x00,0x38,0x42,0x41,0x41,0x42,0x38,0x00, + 0x00,0x38,0x41,0x42,0x40,0x40,0x38,0x00, + 0x00,0x1A,0xA0,0xA0,0xA0,0xA0,0x7A,0x00, + 0x00,0x19,0x24,0x42,0x42,0x24,0x19,0x00, + 0x00,0x3D,0x40,0x40,0x40,0x40,0x3D,0x00, + 0x00,0x18,0x24,0x24,0xE7,0x24,0x24,0x00, + 0x00,0x68,0x5E,0x49,0x41,0x42,0x20,0x00, + 0x00,0x15,0x16,0x7C,0x16,0x15,0x00,0x00, + 0x81,0xFF,0x85,0x05,0x17,0xFA,0x90,0x50, + 0x40,0x88,0x88,0x7F,0x09,0x09,0x02,0x00, + 0x00,0x20,0x54,0x54,0x55,0x79,0x40,0x00, +}; + +#endif \ No newline at end of file diff --git a/macusbfb/drivers/lcd/fonts/smallfonts.h b/macusbfb/drivers/lcd/fonts/smallfonts.h new file mode 100644 index 0000000..99ad045 --- /dev/null +++ b/macusbfb/drivers/lcd/fonts/smallfonts.h @@ -0,0 +1,72 @@ +/**************************************************************************/ +/*! + @file smallfonts.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __SMALLFONTS_H_ +#define __SMALLFONTS_H_ + +/* Partially based on original code for the KS0108 by Stephane Rey */ +/* Current version by Kevin Townsend */ +/* Last Updated: 12 May 2009 */ + +#include "projectconfig.h" + +#if defined CFG_LCD_INCLUDESMALLFONTS & CFG_LCD_INCLUDESMALLFONTS == 1 + +struct FONT_DEF +{ + uint8_t u8Width; /* Character width for storage */ + uint8_t u8Height; /* Character height for storage */ + uint8_t u8FirstChar; /* The first character available */ + uint8_t u8LastChar; /* The last character available */ + uint8_t *au8FontTable; /* Font table start address in memory */ +}; + +extern const struct FONT_DEF Font_System3x6; +extern const struct FONT_DEF Font_System5x8; +extern const struct FONT_DEF Font_System7x8; +extern const struct FONT_DEF Font_8x8; +extern const struct FONT_DEF Font_8x8Thin; + +extern const uint8_t au8FontSystem3x6[]; +extern const uint8_t au8FontSystem5x8[]; +extern const uint8_t au8FontSystem7x8[]; +extern const uint8_t au8Font8x8[]; +extern const uint8_t au8Font8x8Thin[]; + +#endif + +#endif diff --git a/macusbfb/drivers/lcd/hw/ILI9325.c b/macusbfb/drivers/lcd/hw/ILI9325.c new file mode 100644 index 0000000..781da20 --- /dev/null +++ b/macusbfb/drivers/lcd/hw/ILI9325.c @@ -0,0 +1,362 @@ +/**************************************************************************/ +/*! + @file ILI9325.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include "ILI9325.h" + +/*************************************************/ +/* Private Methods */ +/*************************************************/ + +/*************************************************/ +void ili9325Delay(unsigned int t) +{ + unsigned char t1; + while(t--) + for ( t1=10; t1 > 0; t1-- ) + { + __asm("nop"); + } +} + +/*************************************************/ +void ili9325WriteCmd(uint16_t command) +{ + CLR_CS_CD; // Saves 7 commands compared to "CLR_CS; CLR_CD;" + SET_RD_WR; // Saves 7 commands compared to "SET_RD; SET_WR;" + ILI9325_GPIO2DATA_DATA = (command >> (8 - ILI9325_DATA_OFFSET)); + CLR_WR; + SET_WR; + ILI9325_GPIO2DATA_DATA = command << ILI9325_DATA_OFFSET; + CLR_WR; + SET_WR_CS; // Saves 7 commands compared to "SET_WR; SET_CS;" +} + +/*************************************************/ +void ili9325WriteData(uint16_t data) +{ + CLR_CS; + SET_CD_RD_WR; // Saves 14 commands compared to "SET_CD; SET_RD; SET_WR" + ILI9325_GPIO2DATA_DATA = (data >> (8 - ILI9325_DATA_OFFSET)); + CLR_WR; + SET_WR; + ILI9325_GPIO2DATA_DATA = data << ILI9325_DATA_OFFSET; + CLR_WR; + SET_WR_CS; // Saves 7 commands compared to "SET_WR, SET_CS;" +} + +/*************************************************/ +void ili9325Command(uint16_t command, uint16_t data) +{ + // Provided for convenience sake ... shouldn't be used + // in critical sections since it adds an extra + // branch, etc. + ili9325WriteCmd(command); + ili9325WriteData(data); +} + +uint16_t ili9325BGR2RGB(uint16_t color) +{ + uint16_t r, g, b; + + b = (color>>0) & 0x1f; + g = (color>>5) & 0x3f; + r = (color>>11) & 0x1f; + + return( (b<<11) + (g<<5) + (r<<0) ); +} + +/*********************************************************** + Read pixel from LCD controller at current position +***********************************************************/ +uint16_t ili9325Read(void) +{ + // ToDo + + return 0; +} + +/*************************************************/ +void ili9325SetCursor(uint16_t x, uint16_t y) +{ + ili9325Command(0x0020, x-1); // GRAM Address Set (Horizontal Address) (R20h) + ili9325Command(0x0021, y-1); // GRAM Address Set (Vertical Address) (R21h) +} + +/*************************************************/ +static void ili9325InitDisplay(void) +{ + // Clear data line + GPIO_GPIO2DATA &= ~ILI9325_DATA_MASK; + + SET_RD; + SET_WR; + SET_CS; + SET_CD; + + // Reset display + CLR_RESET; + ili9325Delay(10000); + SET_RESET; + ili9325Delay(500); + + ili9325Command(0x00FF, 0x0001); + ili9325Command(0x00F3, 0x0008); + ili9325WriteCmd(0x00F3); + + ili9325Command(0x0001, 0x0100); // Driver Output Control Register (R01h) + ili9325Command(0x0002, 0x0700); // LCD Driving Waveform Control (R02h) + ili9325Command(0x0003, 0x1030); // Entry Mode (R03h) + ili9325Command(0x0008, 0x0302); + ili9325Command(0x0009, 0x0000); + ili9325Command(0x0010, 0x0000); // Power Control 1 (R10h) + ili9325Command(0x0011, 0x0007); // Power Control 2 (R11h) + ili9325Command(0x0012, 0x0000); // Power Control 3 (R12h) + ili9325Command(0x0013, 0x0000); // Power Control 4 (R13h) + ili9325Delay(1000); + ili9325Command(0x0010, 0x14B0); // Power Control 1 (R10h) + ili9325Delay(500); + ili9325Command(0x0011, 0x0007); // Power Control 2 (R11h) + ili9325Delay(500); + ili9325Command(0x0012, 0x008E); // Power Control 3 (R12h) + ili9325Command(0x0013, 0x0C00); // Power Control 4 (R13h) + ili9325Command(0x0029, 0x0015); // NVM read data 2 (R29h) + ili9325Delay(500); + ili9325Command(0x0030, 0x0000); // Gamma Control 1 + ili9325Command(0x0031, 0x0107); // Gamma Control 2 + ili9325Command(0x0032, 0x0000); // Gamma Control 3 + ili9325Command(0x0035, 0x0203); // Gamma Control 6 + ili9325Command(0x0036, 0x0402); // Gamma Control 7 + ili9325Command(0x0037, 0x0000); // Gamma Control 8 + ili9325Command(0x0038, 0x0207); // Gamma Control 9 + ili9325Command(0x0039, 0x0000); // Gamma Control 10 + ili9325Command(0x003C, 0x0203); // Gamma Control 13 + ili9325Command(0x003D, 0x0403); // Gamma Control 14 + ili9325Command(0x0050, 0x0000); // Window Horizontal RAM Address Start (R50h) + ili9325Command(0x0051, 0x00EF); // Window Horizontal RAM Address End (R51h) + ili9325Command(0x0052, 0X0000); // Window Vertical RAM Address Start (R52h) + ili9325Command(0x0053, 0x013F); // Window Vertical RAM Address End (R53h) + ili9325Command(0x0060, 0xa700); // Driver Output Control (R60h) + ili9325Command(0x0061, 0x0001); // Driver Output Control (R61h) + ili9325Command(0x0090, 0X0029); // Panel Interface Control 1 (R90h) + + // Display On + ili9325Command(0x0007, 0x0133); // Display Control (R07h) + ili9325Delay(500); + ili9325WriteCmd(0x0022); +} + +/*************************************************/ +void ili9325Home(void) +{ + ili9325Command(0x0020, 0X0000); // GRAM Address Set (Horizontal Address) (R20h) + ili9325Command(0x0021, 0X0000); // GRAM Address Set (Vertical Address) (R21h) + ili9325WriteCmd(0x0022); // Write Data to GRAM (R22h) +} + +/*************************************************/ +void ili9325SetWindow(uint16_t x, uint16_t y, uint16_t x1, uint16_t y1) +{ + ili9325Command(0x0050, x-1); // Window Horizontal RAM Address Start (R50h) + ili9325Command(0x0051, x1-1); // Window Horizontal RAM Address End (R51h) + ili9325Command(0x0052, y-1); // Window Vertical RAM Address Start (R52h) ) + ili9325Command(0x0053, y1-1); // Window Vertical RAM Address End (R53h) +} + +/*************************************************/ +/* Public Methods */ +/*************************************************/ + +/*************************************************/ +void lcdInit(void) +{ + // Set control line pins to output + gpioSetDir(ILI9325_CS_PORT, ILI9325_CS_PIN, 1); + gpioSetDir(ILI9325_CD_PORT, ILI9325_CD_PIN, 1); + gpioSetDir(ILI9325_WR_PORT, ILI9325_WR_PIN, 1); + gpioSetDir(ILI9325_RD_PORT, ILI9325_RD_PIN, 1); + + // Set data port pins to output + ILI9325_GPIO2DATA_SETOUTPUT; + + // Disable pullups + gpioSetPullup(&IOCON_PIO2_1, gpioPullupMode_Inactive); + gpioSetPullup(&IOCON_PIO2_2, gpioPullupMode_Inactive); + gpioSetPullup(&IOCON_PIO2_3, gpioPullupMode_Inactive); + gpioSetPullup(&IOCON_PIO2_4, gpioPullupMode_Inactive); + gpioSetPullup(&IOCON_PIO2_5, gpioPullupMode_Inactive); + gpioSetPullup(&IOCON_PIO2_6, gpioPullupMode_Inactive); + gpioSetPullup(&IOCON_PIO2_7, gpioPullupMode_Inactive); + gpioSetPullup(&IOCON_PIO2_8, gpioPullupMode_Inactive); + + // Set backlight + gpioSetDir(ILI9325_BL_PORT, ILI9325_BL_PIN, 1); // set to output + gpioSetValue(ILI9325_BL_PORT, ILI9325_BL_PIN, 0); // turn on + + // Initialize the display + ili9325InitDisplay(); + + // Fill black + lcdFillRGB(BLACK); +} + +/*************************************************/ +void lcdTest(void) +{ + uint32_t i,j; + ili9325Home(); + + for(i=0;i<320;i++) + { + for(j=0;j<240;j++) + { + if(i>279)ili9325WriteData(WHITE); + else if(i>239)ili9325WriteData(BLUE); + else if(i>199)ili9325WriteData(GREEN); + else if(i>159)ili9325WriteData(CYAN); + else if(i>119)ili9325WriteData(RED); + else if(i>79)ili9325WriteData(MAGENTA); + else if(i>39)ili9325WriteData(YELLOW); + else ili9325WriteData(BLACK); + } + } +} + +/*************************************************/ +void lcdFillRGB(uint16_t data) +{ + unsigned int i; + ili9325Home(); + + uint32_t pixels = 320*240; + for ( i=0; i < pixels; i++ ) + { + ili9325WriteData(data); + } +} + +/*************************************************/ +void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) +{ + ili9325WriteCmd(0x0020); // GRAM Address Set (Horizontal Address) (R20h) + ili9325WriteData(x-1); + ili9325WriteCmd(0x0021); // GRAM Address Set (Vertical Address) (R21h) + ili9325WriteData(y-1); + ili9325WriteCmd(0x0022); // Write Data to GRAM (R22h) + ili9325WriteData(color); +} + +/*************************************************/ +void lcdDrawHLine(uint16_t x0, uint16_t x1, uint16_t y, uint16_t color) +{ + // Allows for slightly better performance than setting individual pixels + uint16_t x, pixels; + + if (x1 < x0) + { + // Switch x1 and x0 + x = x1; + x1 = x0; + x0 = x; + } + + ili9325WriteCmd(0x0020); // GRAM Address Set (Horizontal Address) (R20h) + ili9325WriteData(x0-1); + ili9325WriteCmd(0x0021); // GRAM Address Set (Vertical Address) (R21h) + ili9325WriteData(y-1); + ili9325WriteCmd(0x0022); // Write Data to GRAM (R22h) + for (pixels = 0; pixels < x1 - x0 + 1; pixels++) + { + ili9325WriteData(color); + } +} + +#ifdef CFG_SDCARD +/**************************************************************************/ +/*! + @brief Loads an image from an SD card and renders it +*/ +/**************************************************************************/ +void lcdDrawImageFromFile(uint16_t x, uint16_t y, char *filename) +{ +} +#endif + +/**************************************************************************/ +/*! + @brief Renders a bitmap image +*/ +/**************************************************************************/ +void lcdDrawImage(uint16_t x, uint16_t y, const uint16_t *data) +{ + // data[0] = Width + // data[1] = height + // data[2] = Compression + // data[3] = Compression Window + // data[4] = Pixel Data ... + + uint16_t line, width; + uint32_t currentPixel, totalPixels; + + width = 0; + + // Calculate total pixels (width * height) + totalPixels = data[0] * data[1]; + currentPixel = 0; + + // Draw individual pixels + for (line = 0; line < data[1]; line++) + { + // Set cursor to starting x, y position + ili9325SetCursor(x, y + line); + // Prepare to write data to GRAM + ili9325WriteCmd(0x0022); // Write Data to GRAM (R22h) + do + { + ili9325WriteData(data[currentPixel]); + currentPixel++; + } while (--width); + width = data[0]; // Reset width counter + } +} + +/*************************************************/ +uint16_t lcdGetPixel(uint16_t x, uint16_t y) +{ + ili9325SetCursor(x, y); + ili9325WriteCmd(0x0022); + return (ili9325Read()); +} diff --git a/macusbfb/drivers/lcd/hw/ILI9325.h b/macusbfb/drivers/lcd/hw/ILI9325.h new file mode 100644 index 0000000..f457d3f --- /dev/null +++ b/macusbfb/drivers/lcd/hw/ILI9325.h @@ -0,0 +1,119 @@ +/**************************************************************************/ +/*! + @file ILI9325.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __ILI9325_H__ +#define __ILI9325_H__ + +#include "projectconfig.h" + +#include "drivers/lcd/lcd.h" +#include "core/gpio/gpio.h" + +// Control pins +#define ILI9325_CS_PORT 1 // CS (LCD Pin 7) +#define ILI9325_CS_PIN 8 +#define ILI9325_CD_PORT 1 // CS/RS (LCD Pin 8) +#define ILI9325_CD_PIN 9 +#define ILI9325_WR_PORT 1 // WR (LCD Pin 9) +#define ILI9325_WR_PIN 10 +#define ILI9325_RD_PORT 1 // RD (LCD Pin 10) +#define ILI9325_RD_PIN 11 + +// These combined pin definitions are for optimisation purposes. +// If the pin values above are modified the bit equivalents +// below will also need to be updated +#define ILI9325_CS_CD_PINS 0x300 // 8 + 9 +#define ILI9325_RD_WR_PINS 0xC00 // 11 + 10 +#define ILI9325_WR_CS_PINS 0x500 // 10 + 8 +#define ILI9325_CD_RD_WR_PINS 0xE00 // 9 + 11 + 10 + +// Backlight and Reset pins +#define ILI9325_RES_PORT 3 // LCD Reset (LCD Pin 31) +#define ILI9325_RES_PIN 3 +#define ILI9325_BL_PORT 2 // Backlight Enable (LCD Pin 16) +#define ILI9325_BL_PIN 9 + +// Data pins +// Note: data pins must be consecutive and on the same port +#define ILI9325_DATA_PORT 2 // 8-Pin Data Port +#define ILI9325_DATA_PIN1 1 +#define ILI9325_DATA_PIN2 2 +#define ILI9325_DATA_PIN3 3 +#define ILI9325_DATA_PIN4 4 +#define ILI9325_DATA_PIN5 5 +#define ILI9325_DATA_PIN6 6 +#define ILI9325_DATA_PIN7 7 +#define ILI9325_DATA_PIN8 8 +#define ILI9325_DATA_MASK 0x000001FE +#define ILI9325_DATA_OFFSET 1 // Offset = PIN1 + +// These registers allow fast single operation clear+set of bits (see section 8.5.1 of LPC1343 UM) +#define ILI9325_GPIO2DATA_DATA (*(pREG32 (GPIO_GPIO2_BASE + (ILI9325_DATA_MASK << 2)))) +#define ILI9325_GPIO1DATA_WR (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ILI9325_WR_PIN) << 2)))) +#define ILI9325_GPIO1DATA_CD (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ILI9325_CD_PIN) << 2)))) +#define ILI9325_GPIO1DATA_CS (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ILI9325_CS_PIN) << 2)))) +#define ILI9325_GPIO1DATA_RD (*(pREG32 (GPIO_GPIO1_BASE + ((1 << ILI9325_RD_PIN) << 2)))) +#define ILI9325_GPIO3DATA_RES (*(pREG32 (GPIO_GPIO3_BASE + ((1 << ILI9325_RES_PIN) << 2)))) +#define ILI9325_GPIO1DATA_CS_CD (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9325_CS_CD_PINS) << 2)))) +#define ILI9325_GPIO1DATA_RD_WR (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9325_RD_WR_PINS) << 2)))) +#define ILI9325_GPIO1DATA_WR_CS (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9325_WR_CS_PINS) << 2)))) +#define ILI9325_GPIO1DATA_CD_RD_WR (*(pREG32 (GPIO_GPIO1_BASE + ((ILI9325_CD_RD_WR_PINS) << 2)))) + +// Macros to set data bus direction to input/output +#define ILI9325_GPIO2DATA_SETINPUT GPIO_GPIO2DIR &= ~ILI9325_DATA_MASK +#define ILI9325_GPIO2DATA_SETOUTPUT GPIO_GPIO2DIR |= ILI9325_DATA_MASK + +// Macros for control line state +#define CLR_CD ILI9325_GPIO1DATA_CD = (0) +#define SET_CD ILI9325_GPIO1DATA_CD = (1 << ILI9325_CD_PIN) +#define CLR_CS ILI9325_GPIO1DATA_CS = (0) +#define SET_CS ILI9325_GPIO1DATA_CS = (1 << ILI9325_CS_PIN) +#define CLR_WR ILI9325_GPIO1DATA_WR = (0) +#define SET_WR ILI9325_GPIO1DATA_WR = (1 << ILI9325_WR_PIN) +#define CLR_RD ILI9325_GPIO1DATA_RD = (0) +#define SET_RD ILI9325_GPIO1DATA_RD = (1 << ILI9325_RD_PIN) +#define CLR_RESET ILI9325_GPIO3DATA_RES = (0) +#define SET_RESET ILI9325_GPIO3DATA_RES = (1 << ILI9325_RES_PIN) + +// These 'combined' macros are defined to improve code performance by +// reducing the number of instructions in heavily used functions +#define CLR_CS_CD ILI9325_GPIO1DATA_CS_CD = (0); +#define SET_RD_WR ILI9325_GPIO1DATA_RD_WR = (ILI9325_RD_WR_PINS); +#define SET_WR_CS ILI9325_GPIO1DATA_WR_CS = (ILI9325_WR_CS_PINS); +#define SET_CD_RD_WR ILI9325_GPIO1DATA_CD_RD_WR = (ILI9325_CD_RD_WR_PINS); + +#endif diff --git a/macusbfb/drivers/lcd/lcd.h b/macusbfb/drivers/lcd/lcd.h new file mode 100644 index 0000000..26cfdb4 --- /dev/null +++ b/macusbfb/drivers/lcd/lcd.h @@ -0,0 +1,71 @@ +/**************************************************************************/ +/*! + @file lcd.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __LCD_H__ +#define __LCD_H__ + +#include "projectconfig.h" + +// Color definitions +#define BLACK 0x0000 +#define BLUE 0x001F +#define RED 0xF800 +#define GREEN 0x07E0 +#define CYAN 0x07FF +#define MAGENTA 0xF81F +#define YELLOW 0xFFE0 +#define WHITE 0xFFFF + +// Method prototypes + +// Any LCD needs to implement these common methods, which allow the low-level +// initialisation and pixel-setting details to be abstracted away from the +// higher level drawing and graphics code. + +extern void lcdInit(void); +extern void lcdFillRGB(uint16_t data); +extern void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color); +extern void lcdDrawHLine(uint16_t x0, uint16_t x1, uint16_t y, uint16_t color); +extern void lcdTest(void); +extern void lcdDrawImage(uint16_t x, uint16_t y, const uint16_t *data); +extern uint16_t lcdGetPixel(uint16_t x, uint16_t y); + +#ifdef CFG_SDCARD +extern void lcdDrawImageFromFile(uint16_t x, uint16_t y, char *filename); +#endif + +#endif diff --git a/macusbfb/drivers/sensors/lm75b/lm75b.c b/macusbfb/drivers/sensors/lm75b/lm75b.c new file mode 100644 index 0000000..18cd6ca --- /dev/null +++ b/macusbfb/drivers/sensors/lm75b/lm75b.c @@ -0,0 +1,190 @@ +/**************************************************************************/ +/*! + @file lm75b.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section DESCRIPTION + + Driver for NXP's LM75B I2C temperature sensor. This temperature + sensor has an accuracy of 0.125°C, and returns a temperature value + in degrees celsius where each unit is equal to 0.125°C. For example, + if the temperature reading is 198, it means that the temperature in + degree celsius is: 198 / 8 = 24.75°C. + + @section Example + + @code + #include "core/cpu/cpu.h" + #include "drivers/sensors/lm75b/lm75b.h" + + int main(void) + { + cpuInit(); + + int32_t temp = 0; + + // Initialise the LM75B + lm75bInit(); + + while (1) + { + // Get the current temperature (in 0.125°C units) + lm75bGetTemperature(&temp); + + // Multiply value by 125 for fixed-point math (0.125°C per unit) + temp *= 125; + + // Use modulus operator to display decimal value + printf("Current Temperature: %d.%d C\n", temp / 1000, temp % 1000); + + // Alternatively, you could also use floating point math, though + // this will result in larger compiled code if you add in floating + // point support for printf, etc. + // + // float tempFloat = 0.0F; + // lm75bGetTemperature(&temp); + // tempFloat = (float)temp / 8.0F; + } + } + @endcode + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "lm75b.h" + +extern volatile uint8_t I2CMasterBuffer[I2C_BUFSIZE]; +extern volatile uint8_t I2CSlaveBuffer[I2C_BUFSIZE]; +extern volatile uint32_t I2CReadLength, I2CWriteLength; + +uint32_t i; + +static lm75bError_e lm75bWrite8 (uint8_t reg, uint32_t value) +{ + // Clear write buffers + for ( i = 0; i < I2C_BUFSIZE; i++ ) + { + I2CMasterBuffer[i] = 0x00; + } + + I2CWriteLength = 3; + I2CReadLength = 0; + I2CMasterBuffer[0] = LM75B_ADDRESS; // I2C device address + I2CMasterBuffer[1] = reg; // Command register + I2CMasterBuffer[2] = (value & 0xFF); // Value to write + i2cEngine(); + return LM75B_ERROR_OK; +} + +static lm75bError_e lm75bRead16(uint8_t reg, int32_t *value) +{ + // Clear write buffers + for ( i = 0; i < I2C_BUFSIZE; i++ ) + { + I2CMasterBuffer[i] = 0x00; + } + + I2CWriteLength = 2; + I2CReadLength = 2; + I2CMasterBuffer[0] = LM75B_ADDRESS; // I2C device address + I2CMasterBuffer[1] = reg; // Command register + // Append address w/read bit + I2CMasterBuffer[2] = LM75B_ADDRESS | LM75B_READBIT; + i2cEngine(); + + // Shift values to create properly formed integer + *value = ((I2CSlaveBuffer[0] << 8) | I2CSlaveBuffer[1]) >> 5; + + // Sign extend negative numbers + if (I2CSlaveBuffer[0] & 0x80) + { + // Negative number + *value |= 0xFFFFFC00; + } + return LM75B_ERROR_OK; +} + +/**************************************************************************/ +/*! + @brief Initialises the I2C block +*/ +/**************************************************************************/ +lm75bError_e lm75bInit(void) +{ + // Initialise I2C + if (i2cInit(I2CMODE_MASTER) == FALSE) + { + return LM75B_ERROR_I2CINIT; /* Fatal error */ + } + + return LM75B_ERROR_OK; + + // Set device to shutdown mode by default (saves power) + // return lm75bConfigWrite (LM75B_CONFIG_SHUTDOWN_SHUTDOWN); +} + +/**************************************************************************/ +/*! + @brief Reads the current temperature from the LM75B + + @note This method will assign a signed 32-bit value (int32) to 'temp', + where each unit represents +/- 0.125°C. To convert the numeric + value to degrees celsius, you must divide the value of 'temp' + by 8. This conversion is not done automatically, since you may + or may not want to use floating point math for the calculations. +*/ +/**************************************************************************/ +lm75bError_e lm75bGetTemperature (int32_t *temp) +{ + // Turn device on + // lm75bConfigWrite (LM75B_CONFIG_SHUTDOWN_POWERON); + + // Read temperature + lm75bError_e error = LM75B_ERROR_OK; + error = lm75bRead16 (LM75B_REGISTER_TEMPERATURE, temp); + + // Shut device back down + // lm75bConfigWrite (LM75B_CONFIG_SHUTDOWN_SHUTDOWN); + + return error; +} + +/**************************************************************************/ +/*! + @brief Writes the supplied 8-bit value to the LM75B config register +*/ +/**************************************************************************/ +lm75bError_e lm75bConfigWrite (uint8_t configValue) +{ + return lm75bWrite8 (LM75B_REGISTER_CONFIGURATION, configValue); +} diff --git a/macusbfb/drivers/sensors/lm75b/lm75b.h b/macusbfb/drivers/sensors/lm75b/lm75b.h new file mode 100644 index 0000000..b159dbe --- /dev/null +++ b/macusbfb/drivers/sensors/lm75b/lm75b.h @@ -0,0 +1,70 @@ +/**************************************************************************/ +/*! + @file lm75b.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _LM75B_H_ +#define _LM75B_H_ + +#include "projectconfig.h" +#include "core/i2c/i2c.h" + +#define LM75B_ADDRESS (0x90) // 100 1000 shifted left 1 bit = 0x90 +#define LM75B_READBIT (0x01) + +#define LM75B_REGISTER_TEMPERATURE (0x00) +#define LM75B_REGISTER_CONFIGURATION (0x01) + +#define LM75B_CONFIG_SHUTDOWN_MASK (0x01) +#define LM75B_CONFIG_SHUTDOWN_POWERON (0x00) +#define LM75B_CONFIG_SHUTDOWN_SHUTDOWN (0x01) + +typedef enum +{ + LM75B_ERROR_OK = 0, // Everything executed normally + LM75B_ERROR_I2CINIT, // Unable to initialise I2C + LM75B_ERROR_I2CBUSY, // I2C already in use + LM75B_ERROR_LAST +} +lm75bError_e; + +lm75bError_e lm75bInit(void); +lm75bError_e lm75bGetTemperature (int32_t *temp); +lm75bError_e lm75bConfigWrite (uint8_t configValue); + +#endif + + diff --git a/macusbfb/font_8x8.c b/macusbfb/font_8x8.c new file mode 100644 index 0000000..54d6c21 --- /dev/null +++ b/macusbfb/font_8x8.c @@ -0,0 +1,2571 @@ +/**********************************************/ +/* */ +/* Font file generated by cpi2fnt */ +/* */ +/**********************************************/ + +#define FONTDATAMAX 2048 + +const unsigned char fontdata_8x8[FONTDATAMAX] = { + + /* 0 0x00 '^@' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 1 0x01 '^A' */ + 0x7e, /* 01111110 */ + 0x81, /* 10000001 */ + 0xa5, /* 10100101 */ + 0x81, /* 10000001 */ + 0xbd, /* 10111101 */ + 0x99, /* 10011001 */ + 0x81, /* 10000001 */ + 0x7e, /* 01111110 */ + + /* 2 0x02 '^B' */ + 0x7e, /* 01111110 */ + 0xff, /* 11111111 */ + 0xdb, /* 11011011 */ + 0xff, /* 11111111 */ + 0xc3, /* 11000011 */ + 0xe7, /* 11100111 */ + 0xff, /* 11111111 */ + 0x7e, /* 01111110 */ + + /* 3 0x03 '^C' */ + 0x6c, /* 01101100 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0x7c, /* 01111100 */ + 0x38, /* 00111000 */ + 0x10, /* 00010000 */ + 0x00, /* 00000000 */ + + /* 4 0x04 '^D' */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + 0x7c, /* 01111100 */ + 0xfe, /* 11111110 */ + 0x7c, /* 01111100 */ + 0x38, /* 00111000 */ + 0x10, /* 00010000 */ + 0x00, /* 00000000 */ + + /* 5 0x05 '^E' */ + 0x38, /* 00111000 */ + 0x7c, /* 01111100 */ + 0x38, /* 00111000 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0xd6, /* 11010110 */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + + /* 6 0x06 '^F' */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + 0x7c, /* 01111100 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0x7c, /* 01111100 */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + + /* 7 0x07 '^G' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 8 0x08 '^H' */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xe7, /* 11100111 */ + 0xc3, /* 11000011 */ + 0xc3, /* 11000011 */ + 0xe7, /* 11100111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + + /* 9 0x09 '^I' */ + 0x00, /* 00000000 */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x42, /* 01000010 */ + 0x42, /* 01000010 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 10 0x0a '^J' */ + 0xff, /* 11111111 */ + 0xc3, /* 11000011 */ + 0x99, /* 10011001 */ + 0xbd, /* 10111101 */ + 0xbd, /* 10111101 */ + 0x99, /* 10011001 */ + 0xc3, /* 11000011 */ + 0xff, /* 11111111 */ + + /* 11 0x0b '^K' */ + 0x0f, /* 00001111 */ + 0x07, /* 00000111 */ + 0x0f, /* 00001111 */ + 0x7d, /* 01111101 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x78, /* 01111000 */ + + /* 12 0x0c '^L' */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + + /* 13 0x0d '^M' */ + 0x3f, /* 00111111 */ + 0x33, /* 00110011 */ + 0x3f, /* 00111111 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x70, /* 01110000 */ + 0xf0, /* 11110000 */ + 0xe0, /* 11100000 */ + + /* 14 0x0e '^N' */ + 0x7f, /* 01111111 */ + 0x63, /* 01100011 */ + 0x7f, /* 01111111 */ + 0x63, /* 01100011 */ + 0x63, /* 01100011 */ + 0x67, /* 01100111 */ + 0xe6, /* 11100110 */ + 0xc0, /* 11000000 */ + + /* 15 0x0f '^O' */ + 0x18, /* 00011000 */ + 0xdb, /* 11011011 */ + 0x3c, /* 00111100 */ + 0xe7, /* 11100111 */ + 0xe7, /* 11100111 */ + 0x3c, /* 00111100 */ + 0xdb, /* 11011011 */ + 0x18, /* 00011000 */ + + /* 16 0x10 '^P' */ + 0x80, /* 10000000 */ + 0xe0, /* 11100000 */ + 0xf8, /* 11111000 */ + 0xfe, /* 11111110 */ + 0xf8, /* 11111000 */ + 0xe0, /* 11100000 */ + 0x80, /* 10000000 */ + 0x00, /* 00000000 */ + + /* 17 0x11 '^Q' */ + 0x02, /* 00000010 */ + 0x0e, /* 00001110 */ + 0x3e, /* 00111110 */ + 0xfe, /* 11111110 */ + 0x3e, /* 00111110 */ + 0x0e, /* 00001110 */ + 0x02, /* 00000010 */ + 0x00, /* 00000000 */ + + /* 18 0x12 '^R' */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + + /* 19 0x13 '^S' */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + + /* 20 0x14 '^T' */ + 0x7f, /* 01111111 */ + 0xdb, /* 11011011 */ + 0xdb, /* 11011011 */ + 0x7b, /* 01111011 */ + 0x1b, /* 00011011 */ + 0x1b, /* 00011011 */ + 0x1b, /* 00011011 */ + 0x00, /* 00000000 */ + + /* 21 0x15 '^U' */ + 0x3e, /* 00111110 */ + 0x61, /* 01100001 */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x86, /* 10000110 */ + 0x7c, /* 01111100 */ + + /* 22 0x16 '^V' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x7e, /* 01111110 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* 23 0x17 '^W' */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + + /* 24 0x18 '^X' */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 25 0x19 '^Y' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 26 0x1a '^Z' */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0xfe, /* 11111110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 27 0x1b '^[' */ + 0x00, /* 00000000 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0xfe, /* 11111110 */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 28 0x1c '^\' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 29 0x1d '^]' */ + 0x00, /* 00000000 */ + 0x24, /* 00100100 */ + 0x66, /* 01100110 */ + 0xff, /* 11111111 */ + 0x66, /* 01100110 */ + 0x24, /* 00100100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 30 0x1e '^^' */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 31 0x1f '^_' */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0x7e, /* 01111110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 32 0x20 ' ' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 33 0x21 '!' */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 34 0x22 '"' */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x24, /* 00100100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 35 0x23 '#' */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x00, /* 00000000 */ + + /* 36 0x24 '$' */ + 0x18, /* 00011000 */ + 0x3e, /* 00111110 */ + 0x60, /* 01100000 */ + 0x3c, /* 00111100 */ + 0x06, /* 00000110 */ + 0x7c, /* 01111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 37 0x25 '%' */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xcc, /* 11001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x66, /* 01100110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 38 0x26 '&' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 39 0x27 ''' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 40 0x28 '(' */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x00, /* 00000000 */ + + /* 41 0x29 ')' */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + + /* 42 0x2a '*' */ + 0x00, /* 00000000 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0xff, /* 11111111 */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 43 0x2b '+' */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 44 0x2c ',' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + + /* 45 0x2d '-' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 46 0x2e '.' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 47 0x2f '/' */ + 0x06, /* 00000110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0xc0, /* 11000000 */ + 0x80, /* 10000000 */ + 0x00, /* 00000000 */ + + /* 48 0x30 '0' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xd6, /* 11010110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* 49 0x31 '1' */ + 0x18, /* 00011000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* 50 0x32 '2' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0x06, /* 00000110 */ + 0x1c, /* 00011100 */ + 0x30, /* 00110000 */ + 0x66, /* 01100110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* 51 0x33 '3' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0x06, /* 00000110 */ + 0x3c, /* 00111100 */ + 0x06, /* 00000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 52 0x34 '4' */ + 0x1c, /* 00011100 */ + 0x3c, /* 00111100 */ + 0x6c, /* 01101100 */ + 0xcc, /* 11001100 */ + 0xfe, /* 11111110 */ + 0x0c, /* 00001100 */ + 0x1e, /* 00011110 */ + 0x00, /* 00000000 */ + + /* 53 0x35 '5' */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xfc, /* 11111100 */ + 0x06, /* 00000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 54 0x36 '6' */ + 0x38, /* 00111000 */ + 0x60, /* 01100000 */ + 0xc0, /* 11000000 */ + 0xfc, /* 11111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 55 0x37 '7' */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + + /* 56 0x38 '8' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 57 0x39 '9' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7e, /* 01111110 */ + 0x06, /* 00000110 */ + 0x0c, /* 00001100 */ + 0x78, /* 01111000 */ + 0x00, /* 00000000 */ + + /* 58 0x3a ':' */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 59 0x3b ';' */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + + /* 60 0x3c '<' */ + 0x06, /* 00000110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x06, /* 00000110 */ + 0x00, /* 00000000 */ + + /* 61 0x3d '=' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 62 0x3e '>' */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0x00, /* 00000000 */ + + /* 63 0x3f '?' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 64 0x40 '@' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xde, /* 11011110 */ + 0xde, /* 11011110 */ + 0xde, /* 11011110 */ + 0xc0, /* 11000000 */ + 0x78, /* 01111000 */ + 0x00, /* 00000000 */ + + /* 65 0x41 'A' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 66 0x42 'B' */ + 0xfc, /* 11111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0xfc, /* 11111100 */ + 0x00, /* 00000000 */ + + /* 67 0x43 'C' */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 68 0x44 'D' */ + 0xf8, /* 11111000 */ + 0x6c, /* 01101100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x6c, /* 01101100 */ + 0xf8, /* 11111000 */ + 0x00, /* 00000000 */ + + /* 69 0x45 'E' */ + 0xfe, /* 11111110 */ + 0x62, /* 01100010 */ + 0x68, /* 01101000 */ + 0x78, /* 01111000 */ + 0x68, /* 01101000 */ + 0x62, /* 01100010 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* 70 0x46 'F' */ + 0xfe, /* 11111110 */ + 0x62, /* 01100010 */ + 0x68, /* 01101000 */ + 0x78, /* 01111000 */ + 0x68, /* 01101000 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + 0x00, /* 00000000 */ + + /* 71 0x47 'G' */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xce, /* 11001110 */ + 0x66, /* 01100110 */ + 0x3a, /* 00111010 */ + 0x00, /* 00000000 */ + + /* 72 0x48 'H' */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 73 0x49 'I' */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 74 0x4a 'J' */ + 0x1e, /* 00011110 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x78, /* 01111000 */ + 0x00, /* 00000000 */ + + /* 75 0x4b 'K' */ + 0xe6, /* 11100110 */ + 0x66, /* 01100110 */ + 0x6c, /* 01101100 */ + 0x78, /* 01111000 */ + 0x6c, /* 01101100 */ + 0x66, /* 01100110 */ + 0xe6, /* 11100110 */ + 0x00, /* 00000000 */ + + /* 76 0x4c 'L' */ + 0xf0, /* 11110000 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0x62, /* 01100010 */ + 0x66, /* 01100110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* 77 0x4d 'M' */ + 0xc6, /* 11000110 */ + 0xee, /* 11101110 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0xd6, /* 11010110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 78 0x4e 'N' */ + 0xc6, /* 11000110 */ + 0xe6, /* 11100110 */ + 0xf6, /* 11110110 */ + 0xde, /* 11011110 */ + 0xce, /* 11001110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 79 0x4f 'O' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 80 0x50 'P' */ + 0xfc, /* 11111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + 0x00, /* 00000000 */ + + /* 81 0x51 'Q' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xce, /* 11001110 */ + 0x7c, /* 01111100 */ + 0x0e, /* 00001110 */ + + /* 82 0x52 'R' */ + 0xfc, /* 11111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0x6c, /* 01101100 */ + 0x66, /* 01100110 */ + 0xe6, /* 11100110 */ + 0x00, /* 00000000 */ + + /* 83 0x53 'S' */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 84 0x54 'T' */ + 0x7e, /* 01111110 */ + 0x7e, /* 01111110 */ + 0x5a, /* 01011010 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 85 0x55 'U' */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 86 0x56 'V' */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* 87 0x57 'W' */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xd6, /* 11010110 */ + 0xd6, /* 11010110 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0x00, /* 00000000 */ + + /* 88 0x58 'X' */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 89 0x59 'Y' */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 90 0x5a 'Z' */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0x8c, /* 10001100 */ + 0x18, /* 00011000 */ + 0x32, /* 00110010 */ + 0x66, /* 01100110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* 91 0x5b '[' */ + 0x3c, /* 00111100 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 92 0x5c '\' */ + 0xc0, /* 11000000 */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x06, /* 00000110 */ + 0x02, /* 00000010 */ + 0x00, /* 00000000 */ + + /* 93 0x5d ']' */ + 0x3c, /* 00111100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 94 0x5e '^' */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 95 0x5f '_' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + + /* 96 0x60 '`' */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 97 0x61 'a' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 98 0x62 'b' */ + 0xe0, /* 11100000 */ + 0x60, /* 01100000 */ + 0x7c, /* 01111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + + /* 99 0x63 'c' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc0, /* 11000000 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 100 0x64 'd' */ + 0x1c, /* 00011100 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 101 0x65 'e' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 102 0x66 'f' */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x60, /* 01100000 */ + 0xf8, /* 11111000 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + 0x00, /* 00000000 */ + + /* 103 0x67 'g' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x7c, /* 01111100 */ + 0x0c, /* 00001100 */ + 0xf8, /* 11111000 */ + + /* 104 0x68 'h' */ + 0xe0, /* 11100000 */ + 0x60, /* 01100000 */ + 0x6c, /* 01101100 */ + 0x76, /* 01110110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0xe6, /* 11100110 */ + 0x00, /* 00000000 */ + + /* 105 0x69 'i' */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 106 0x6a 'j' */ + 0x06, /* 00000110 */ + 0x00, /* 00000000 */ + 0x06, /* 00000110 */ + 0x06, /* 00000110 */ + 0x06, /* 00000110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + + /* 107 0x6b 'k' */ + 0xe0, /* 11100000 */ + 0x60, /* 01100000 */ + 0x66, /* 01100110 */ + 0x6c, /* 01101100 */ + 0x78, /* 01111000 */ + 0x6c, /* 01101100 */ + 0xe6, /* 11100110 */ + 0x00, /* 00000000 */ + + /* 108 0x6c 'l' */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 109 0x6d 'm' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xec, /* 11101100 */ + 0xfe, /* 11111110 */ + 0xd6, /* 11010110 */ + 0xd6, /* 11010110 */ + 0xd6, /* 11010110 */ + 0x00, /* 00000000 */ + + /* 110 0x6e 'n' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xdc, /* 11011100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + + /* 111 0x6f 'o' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 112 0x70 'p' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xdc, /* 11011100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + + /* 113 0x71 'q' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x7c, /* 01111100 */ + 0x0c, /* 00001100 */ + 0x1e, /* 00011110 */ + + /* 114 0x72 'r' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xdc, /* 11011100 */ + 0x76, /* 01110110 */ + 0x60, /* 01100000 */ + 0x60, /* 01100000 */ + 0xf0, /* 11110000 */ + 0x00, /* 00000000 */ + + /* 115 0x73 's' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x06, /* 00000110 */ + 0xfc, /* 11111100 */ + 0x00, /* 00000000 */ + + /* 116 0x74 't' */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0xfc, /* 11111100 */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x36, /* 00110110 */ + 0x1c, /* 00011100 */ + 0x00, /* 00000000 */ + + /* 117 0x75 'u' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 118 0x76 'v' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* 119 0x77 'w' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xd6, /* 11010110 */ + 0xd6, /* 11010110 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0x00, /* 00000000 */ + + /* 120 0x78 'x' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 121 0x79 'y' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7e, /* 01111110 */ + 0x06, /* 00000110 */ + 0xfc, /* 11111100 */ + + /* 122 0x7a 'z' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x4c, /* 01001100 */ + 0x18, /* 00011000 */ + 0x32, /* 00110010 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* 123 0x7b '{' */ + 0x0e, /* 00001110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x70, /* 01110000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x0e, /* 00001110 */ + 0x00, /* 00000000 */ + + /* 124 0x7c '|' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 125 0x7d '}' */ + 0x70, /* 01110000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x0e, /* 00001110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x70, /* 01110000 */ + 0x00, /* 00000000 */ + + /* 126 0x7e '~' */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 127 0x7f '' */ + 0x00, /* 00000000 */ + 0x10, /* 00010000 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* 128 0x80 '€' */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x0c, /* 00001100 */ + 0x78, /* 01111000 */ + + /* 129 0x81 '' */ + 0xcc, /* 11001100 */ + 0x00, /* 00000000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 130 0x82 '‚' */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 131 0x83 'ƒ' */ + 0x7c, /* 01111100 */ + 0x82, /* 10000010 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 132 0x84 '„' */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 133 0x85 '…' */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 134 0x86 '†' */ + 0x30, /* 00110000 */ + 0x30, /* 00110000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 135 0x87 '‡' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x7e, /* 01111110 */ + 0x0c, /* 00001100 */ + 0x38, /* 00111000 */ + + /* 136 0x88 'ˆ' */ + 0x7c, /* 01111100 */ + 0x82, /* 10000010 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 137 0x89 '‰' */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 138 0x8a 'Š' */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 139 0x8b '‹' */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 140 0x8c 'Œ' */ + 0x7c, /* 01111100 */ + 0x82, /* 10000010 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 141 0x8d '' */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 142 0x8e 'Ž' */ + 0xc6, /* 11000110 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 143 0x8f '' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 144 0x90 '' */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0xf8, /* 11111000 */ + 0xc0, /* 11000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* 145 0x91 '‘' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0xd8, /* 11011000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* 146 0x92 '’' */ + 0x3e, /* 00111110 */ + 0x6c, /* 01101100 */ + 0xcc, /* 11001100 */ + 0xfe, /* 11111110 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xce, /* 11001110 */ + 0x00, /* 00000000 */ + + /* 147 0x93 '“' */ + 0x7c, /* 01111100 */ + 0x82, /* 10000010 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 148 0x94 '”' */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 149 0x95 '•' */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 150 0x96 '–' */ + 0x78, /* 01111000 */ + 0x84, /* 10000100 */ + 0x00, /* 00000000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 151 0x97 '—' */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 152 0x98 '˜' */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7e, /* 01111110 */ + 0x06, /* 00000110 */ + 0xfc, /* 11111100 */ + + /* 153 0x99 '™' */ + 0xc6, /* 11000110 */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* 154 0x9a 'š' */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 155 0x9b '›' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 156 0x9c 'œ' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x64, /* 01100100 */ + 0xf0, /* 11110000 */ + 0x60, /* 01100000 */ + 0x66, /* 01100110 */ + 0xfc, /* 11111100 */ + 0x00, /* 00000000 */ + + /* 157 0x9d '' */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 158 0x9e 'ž' */ + 0xf8, /* 11111000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xfa, /* 11111010 */ + 0xc6, /* 11000110 */ + 0xcf, /* 11001111 */ + 0xc6, /* 11000110 */ + 0xc7, /* 11000111 */ + + /* 159 0x9f 'Ÿ' */ + 0x0e, /* 00001110 */ + 0x1b, /* 00011011 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0xd8, /* 11011000 */ + 0x70, /* 01110000 */ + 0x00, /* 00000000 */ + + /* 160 0xa0 ' ' */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x7c, /* 01111100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 161 0xa1 '¡' */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x38, /* 00111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 162 0xa2 '¢' */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + + /* 163 0xa3 '£' */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 164 0xa4 '¤' */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0xdc, /* 11011100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x00, /* 00000000 */ + + /* 165 0xa5 '¥' */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0xe6, /* 11100110 */ + 0xf6, /* 11110110 */ + 0xde, /* 11011110 */ + 0xce, /* 11001110 */ + 0x00, /* 00000000 */ + + /* 166 0xa6 '¦' */ + 0x3c, /* 00111100 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x3e, /* 00111110 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 167 0xa7 '§' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 168 0xa8 '¨' */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x63, /* 01100011 */ + 0x3e, /* 00111110 */ + 0x00, /* 00000000 */ + + /* 169 0xa9 '©' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 170 0xaa 'ª' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x06, /* 00000110 */ + 0x06, /* 00000110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 171 0xab '«' */ + 0x63, /* 01100011 */ + 0xe6, /* 11100110 */ + 0x6c, /* 01101100 */ + 0x7e, /* 01111110 */ + 0x33, /* 00110011 */ + 0x66, /* 01100110 */ + 0xcc, /* 11001100 */ + 0x0f, /* 00001111 */ + + /* 172 0xac '¬' */ + 0x63, /* 01100011 */ + 0xe6, /* 11100110 */ + 0x6c, /* 01101100 */ + 0x7a, /* 01111010 */ + 0x36, /* 00110110 */ + 0x6a, /* 01101010 */ + 0xdf, /* 11011111 */ + 0x06, /* 00000110 */ + + /* 173 0xad '­' */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 174 0xae '®' */ + 0x00, /* 00000000 */ + 0x33, /* 00110011 */ + 0x66, /* 01100110 */ + 0xcc, /* 11001100 */ + 0x66, /* 01100110 */ + 0x33, /* 00110011 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 175 0xaf '¯' */ + 0x00, /* 00000000 */ + 0xcc, /* 11001100 */ + 0x66, /* 01100110 */ + 0x33, /* 00110011 */ + 0x66, /* 01100110 */ + 0xcc, /* 11001100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 176 0xb0 '°' */ + 0x22, /* 00100010 */ + 0x88, /* 10001000 */ + 0x22, /* 00100010 */ + 0x88, /* 10001000 */ + 0x22, /* 00100010 */ + 0x88, /* 10001000 */ + 0x22, /* 00100010 */ + 0x88, /* 10001000 */ + + /* 177 0xb1 '±' */ + 0x55, /* 01010101 */ + 0xaa, /* 10101010 */ + 0x55, /* 01010101 */ + 0xaa, /* 10101010 */ + 0x55, /* 01010101 */ + 0xaa, /* 10101010 */ + 0x55, /* 01010101 */ + 0xaa, /* 10101010 */ + + /* 178 0xb2 '²' */ + 0x77, /* 01110111 */ + 0xdd, /* 11011101 */ + 0x77, /* 01110111 */ + 0xdd, /* 11011101 */ + 0x77, /* 01110111 */ + 0xdd, /* 11011101 */ + 0x77, /* 01110111 */ + 0xdd, /* 11011101 */ + + /* 179 0xb3 '³' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 180 0xb4 '´' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 181 0xb5 'µ' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 182 0xb6 '¶' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf6, /* 11110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 183 0xb7 '·' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 184 0xb8 '¸' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 185 0xb9 '¹' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf6, /* 11110110 */ + 0x06, /* 00000110 */ + 0xf6, /* 11110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 186 0xba 'º' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 187 0xbb '»' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x06, /* 00000110 */ + 0xf6, /* 11110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 188 0xbc '¼' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf6, /* 11110110 */ + 0x06, /* 00000110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 189 0xbd '½' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 190 0xbe '¾' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 191 0xbf '¿' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xf8, /* 11111000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 192 0xc0 'À' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 193 0xc1 'Á' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 194 0xc2 'Â' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 195 0xc3 'Ã' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 196 0xc4 'Ä' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 197 0xc5 'Å' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 198 0xc6 'Æ' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 199 0xc7 'Ç' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x37, /* 00110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 200 0xc8 'È' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x37, /* 00110111 */ + 0x30, /* 00110000 */ + 0x3f, /* 00111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 201 0xc9 'É' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x3f, /* 00111111 */ + 0x30, /* 00110000 */ + 0x37, /* 00110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 202 0xca 'Ê' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf7, /* 11110111 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 203 0xcb 'Ë' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0xf7, /* 11110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 204 0xcc 'Ì' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x37, /* 00110111 */ + 0x30, /* 00110000 */ + 0x37, /* 00110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 205 0xcd 'Í' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 206 0xce 'Î' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xf7, /* 11110111 */ + 0x00, /* 00000000 */ + 0xf7, /* 11110111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 207 0xcf 'Ï' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 208 0xd0 'Ð' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 209 0xd1 'Ñ' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 210 0xd2 'Ò' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 211 0xd3 'Ó' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x3f, /* 00111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 212 0xd4 'Ô' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 213 0xd5 'Õ' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 214 0xd6 'Ö' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x3f, /* 00111111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 215 0xd7 '×' */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0xff, /* 11111111 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + + /* 216 0xd8 'Ø' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0xff, /* 11111111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 217 0xd9 'Ù' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xf8, /* 11111000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 218 0xda 'Ú' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x1f, /* 00011111 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 219 0xdb 'Û' */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + + /* 220 0xdc 'Ü' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + + /* 221 0xdd 'Ý' */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + 0xf0, /* 11110000 */ + + /* 222 0xde 'Þ' */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + 0x0f, /* 00001111 */ + + /* 223 0xdf 'ß' */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0xff, /* 11111111 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 224 0xe0 'à' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0xc8, /* 11001000 */ + 0xdc, /* 11011100 */ + 0x76, /* 01110110 */ + 0x00, /* 00000000 */ + + /* 225 0xe1 'á' */ + 0x78, /* 01111000 */ + 0xcc, /* 11001100 */ + 0xcc, /* 11001100 */ + 0xd8, /* 11011000 */ + 0xcc, /* 11001100 */ + 0xc6, /* 11000110 */ + 0xcc, /* 11001100 */ + 0x00, /* 00000000 */ + + /* 226 0xe2 'â' */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0xc0, /* 11000000 */ + 0x00, /* 00000000 */ + + /* 227 0xe3 'ã' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x00, /* 00000000 */ + + /* 228 0xe4 'ä' */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + + /* 229 0xe5 'å' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0xd8, /* 11011000 */ + 0xd8, /* 11011000 */ + 0xd8, /* 11011000 */ + 0x70, /* 01110000 */ + 0x00, /* 00000000 */ + + /* 230 0xe6 'æ' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x7c, /* 01111100 */ + 0xc0, /* 11000000 */ + + /* 231 0xe7 'ç' */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + + /* 232 0xe8 'è' */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x3c, /* 00111100 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + + /* 233 0xe9 'é' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xfe, /* 11111110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + + /* 234 0xea 'ê' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0xee, /* 11101110 */ + 0x00, /* 00000000 */ + + /* 235 0xeb 'ë' */ + 0x0e, /* 00001110 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x3e, /* 00111110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + + /* 236 0xec 'ì' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0xdb, /* 11011011 */ + 0xdb, /* 11011011 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 237 0xed 'í' */ + 0x06, /* 00000110 */ + 0x0c, /* 00001100 */ + 0x7e, /* 01111110 */ + 0xdb, /* 11011011 */ + 0xdb, /* 11011011 */ + 0x7e, /* 01111110 */ + 0x60, /* 01100000 */ + 0xc0, /* 11000000 */ + + /* 238 0xee 'î' */ + 0x1e, /* 00011110 */ + 0x30, /* 00110000 */ + 0x60, /* 01100000 */ + 0x7e, /* 01111110 */ + 0x60, /* 01100000 */ + 0x30, /* 00110000 */ + 0x1e, /* 00011110 */ + 0x00, /* 00000000 */ + + /* 239 0xef 'ï' */ + 0x00, /* 00000000 */ + 0x7c, /* 01111100 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + + /* 240 0xf0 'ð' */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0xfe, /* 11111110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 241 0xf1 'ñ' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x7e, /* 01111110 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* 242 0xf2 'ò' */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* 243 0xf3 'ó' */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x18, /* 00011000 */ + 0x0c, /* 00001100 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + + /* 244 0xf4 'ô' */ + 0x0e, /* 00001110 */ + 0x1b, /* 00011011 */ + 0x1b, /* 00011011 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + + /* 245 0xf5 'õ' */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0xd8, /* 11011000 */ + 0xd8, /* 11011000 */ + 0x70, /* 01110000 */ + + /* 246 0xf6 'ö' */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x7e, /* 01111110 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 247 0xf7 '÷' */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0x76, /* 01110110 */ + 0xdc, /* 11011100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 248 0xf8 'ø' */ + 0x38, /* 00111000 */ + 0x6c, /* 01101100 */ + 0x6c, /* 01101100 */ + 0x38, /* 00111000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 249 0xf9 'ù' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 250 0xfa 'ú' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x18, /* 00011000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 251 0xfb 'û' */ + 0x0f, /* 00001111 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0x0c, /* 00001100 */ + 0xec, /* 11101100 */ + 0x6c, /* 01101100 */ + 0x3c, /* 00111100 */ + 0x1c, /* 00011100 */ + + /* 252 0xfc 'ü' */ + 0x6c, /* 01101100 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x36, /* 00110110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 253 0xfd 'ý' */ + 0x78, /* 01111000 */ + 0x0c, /* 00001100 */ + 0x18, /* 00011000 */ + 0x30, /* 00110000 */ + 0x7c, /* 01111100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 254 0xfe 'þ' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x3c, /* 00111100 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + + /* 255 0xff 'ÿ' */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + +}; diff --git a/macusbfb/gpio.h b/macusbfb/gpio.h new file mode 100644 index 0000000..157eba0 --- /dev/null +++ b/macusbfb/gpio.h @@ -0,0 +1,5 @@ +//Macros to quickly modify gpio values + +#define GPIOMOD(port, mask, bits) (* (pREG32 (0x50000000+(0x10000*port)+(mask<<2))))=bits +#define GPIOSET(port, bits) GPIOMOD(port, (1< V, the + hysteresis of the WAKEUP input pin has to be disabled in order for the chip to wake up + from Deep power-down mode. */ + +#define PMU_GPREG4_GPDATA_MASK ((unsigned int) 0xFFFFF800) +#define PMU_GPREG4_WAKEUPHYS_MASK ((unsigned int) 0x00000400) +#define PMU_GPREG4_WAKEUPHYS_HYSTERESISENABLED ((unsigned int) 0x00000400) +#define PMU_GPREG4_WAKEUPHYS_HYSTERESISDISABLED ((unsigned int) 0x00000000) +#define PMU_GPREG4_GPDATA_MASK ((unsigned int) 0xFFFFF800) + +/*############################################################################## +## I/O Control (IOCON) +##############################################################################*/ + +#define IOCON_BASE_ADDRESS (0x40044000) + +/* Values that should be common to all pins, though they are also defined + on the individual pin level in case they change with a pin on any future + device */ + +#define IOCON_COMMON_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_COMMON_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_COMMON_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_COMMON_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_COMMON_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_COMMON_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_COMMON_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_COMMON_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_COMMON_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_6 (*(pREG32 (0x40044000))) +#define IOCON_PIO2_6_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_6_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_6_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_6_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_6_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_6_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_6_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_6_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_6_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_6_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_0 (*(pREG32 (0x40044008))) +#define IOCON_PIO2_0_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_0_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_0_FUNC_DTR ((unsigned int) 0x00000001) +#define IOCON_PIO2_0_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_0_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_0_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_0_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_0_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_0_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_0_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_0_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_nRESET_PIO0_0 (*(pREG32 (0x4004400C))) +#define IOCON_nRESET_PIO0_0_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_nRESET_PIO0_0_FUNC_RESET ((unsigned int) 0x00000000) +#define IOCON_nRESET_PIO0_0_FUNC_GPIO ((unsigned int) 0x00000001) +#define IOCON_nRESET_PIO0_0_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_nRESET_PIO0_0_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_nRESET_PIO0_0_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_nRESET_PIO0_0_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_nRESET_PIO0_0_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_nRESET_PIO0_0_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_nRESET_PIO0_0_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_nRESET_PIO0_0_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO0_1 (*(pREG32 (0x40044010))) +#define IOCON_PIO0_1_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_1_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_1_FUNC_CLKOUT ((unsigned int) 0x00000001) +#define IOCON_PIO0_1_FUNC_CT32B0_MAT2 ((unsigned int) 0x00000002) +#define IOCON_PIO0_1_FUNC_USB_FTOGGLE ((unsigned int) 0x00000003) +#define IOCON_PIO0_1_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO0_1_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO0_1_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO0_1_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO0_1_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO0_1_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO0_1_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO0_1_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO1_8 (*(pREG32 (0x40044014))) +#define IOCON_PIO1_8_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO1_8_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO1_8_FUNC_CT16B1_CAP0 ((unsigned int) 0x00000001) +#define IOCON_PIO1_8_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO1_8_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO1_8_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO1_8_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO1_8_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO1_8_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO1_8_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO1_8_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO0_2 (*(pREG32 (0x4004401C))) +#define IOCON_PIO0_2_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_2_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_2_FUNC_SSEL ((unsigned int) 0x00000001) +#define IOCON_PIO0_2_FUNC_CT16B0_CAP0 ((unsigned int) 0x00000002) +#define IOCON_PIO0_2_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO0_2_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO0_2_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO0_2_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO0_2_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO0_2_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO0_2_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO0_2_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_7 (*(pREG32 (0x40044020))) +#define IOCON_PIO2_7_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_7_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_7_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_7_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_7_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_7_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_7_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_7_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_7_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_7_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_8 (*(pREG32 (0x40044024))) +#define IOCON_PIO2_8_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_8_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_8_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_8_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_8_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_8_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_8_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_8_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_8_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_8_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_1 (*(pREG32 (0x40044028))) +#define IOCON_PIO2_1_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_1_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_1_FUNC_DSR ((unsigned int) 0x00000001) +#define IOCON_PIO2_1_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_1_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_1_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_1_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_1_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_1_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_1_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_1_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO0_3 (*(pREG32 (0x4004402C))) +#define IOCON_PIO0_3_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_3_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_3_FUNC_USB_VBUS ((unsigned int) 0x00000001) +#define IOCON_PIO0_3_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO0_3_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO0_3_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO0_3_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO0_3_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO0_3_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO0_3_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO0_3_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO0_4 (*(pREG32 (0x40044030))) +#define IOCON_PIO0_4_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_4_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_4_FUNC_I2CSCL ((unsigned int) 0x00000001) +#define IOCON_PIO0_4_I2CMODE_MASK ((unsigned int) 0x00000300) +#define IOCON_PIO0_4_I2CMODE_STANDARDI2C ((unsigned int) 0x00000000) +#define IOCON_PIO0_4_I2CMODE_STANDARDIO ((unsigned int) 0x00000100) +#define IOCON_PIO0_4_I2CMODE_FASTPLUSI2C ((unsigned int) 0x00000200) + +#define IOCON_PIO0_5 (*(pREG32 (0x40044034))) +#define IOCON_PIO0_5_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_5_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_5_FUNC_I2CSDA ((unsigned int) 0x00000001) +#define IOCON_PIO0_5_I2CMODE_MASK ((unsigned int) 0x00000300) +#define IOCON_PIO0_5_I2CMODE_STANDARDI2C ((unsigned int) 0x00000000) +#define IOCON_PIO0_5_I2CMODE_STANDARDIO ((unsigned int) 0x00000100) +#define IOCON_PIO0_5_I2CMODE_FASTPLUSI2C ((unsigned int) 0x00000200) + +#define IOCON_PIO1_9 (*(pREG32 (0x40044038))) +#define IOCON_PIO1_9_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO1_9_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO1_9_FUNC_CT16B1_MAT0 ((unsigned int) 0x00000001) +#define IOCON_PIO1_9_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO1_9_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO1_9_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO1_9_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO1_9_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO1_9_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO1_9_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO1_9_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO3_4 (*(pREG32 (0x4004403C))) +#define IOCON_PIO3_4_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO3_4_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO3_4_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO3_4_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO3_4_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO3_4_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO3_4_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO3_4_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO3_4_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO3_4_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_4 (*(pREG32 (0x40044040))) +#define IOCON_PIO2_4_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_4_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_4_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_4_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_4_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_4_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_4_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_4_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_4_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_4_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_5 (*(pREG32 (0x40044044))) +#define IOCON_PIO2_5_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_5_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_5_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_5_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_5_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_5_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_5_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_5_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_5_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_5_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO3_5 (*(pREG32 (0x40044048))) +#define IOCON_PIO3_5_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO3_5_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO3_5_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO3_5_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO3_5_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO3_5_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO3_5_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO3_5_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO3_5_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO3_5_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO0_6 (*(pREG32 (0x4004404C))) +#define IOCON_PIO0_6_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_6_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_6_FUNC_USB_CONNECT ((unsigned int) 0x00000001) +#define IOCON_PIO0_6_FUNC_SCK ((unsigned int) 0x00000002) +#define IOCON_PIO0_6_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO0_6_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO0_6_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO0_6_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO0_6_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO0_6_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO0_6_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO0_6_HYS_ENABLE ((unsigned int) 0x00000020) + + +#define IOCON_PIO0_7 (*(pREG32 (0x40044050))) +#define IOCON_PIO0_7_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_7_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_7_FUNC_CTS ((unsigned int) 0x00000001) +#define IOCON_PIO0_7_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO0_7_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO0_7_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO0_7_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO0_7_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO0_7_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO0_7_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO0_7_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_9 (*(pREG32 (0x40044054))) +#define IOCON_PIO2_9_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_9_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_9_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_9_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_9_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_9_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_9_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_9_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_9_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_9_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_10 (*(pREG32 (0x40044058))) +#define IOCON_PIO2_10_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_10_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_10_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_10_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_10_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_10_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_10_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_10_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_10_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_10_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_2 (*(pREG32 (0x4004405C))) +#define IOCON_PIO2_2_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_2_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_2_FUNC_DCD ((unsigned int) 0x00000001) +#define IOCON_PIO2_2_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_2_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_2_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_2_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_2_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_2_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_2_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_2_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO0_8 (*(pREG32 (0x40044060))) +#define IOCON_PIO0_8_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_8_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_8_FUNC_MISO0 ((unsigned int) 0x00000001) +#define IOCON_PIO0_8_FUNC_CT16B0_MAT0 ((unsigned int) 0x00000002) +#define IOCON_PIO0_8_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO0_8_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO0_8_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO0_8_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO0_8_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO0_8_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO0_8_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO0_8_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO0_9 (*(pREG32 (0x40044064))) +#define IOCON_PIO0_9_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO0_9_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO0_9_FUNC_MOSI0 ((unsigned int) 0x00000001) +#define IOCON_PIO0_9_FUNC_CT16B0_MAT1 ((unsigned int) 0x00000002) +#define IOCON_PIO0_9_FUNC_SWO ((unsigned int) 0x00000003) +#define IOCON_PIO0_9_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO0_9_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO0_9_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO0_9_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO0_9_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO0_9_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO0_9_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO0_9_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_JTAG_TCK_PIO0_10 (*(pREG32 (0x40044068))) +#define IOCON_JTAG_TCK_PIO0_10_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_JTAG_TCK_PIO0_10_FUNC_SWCLK ((unsigned int) 0x00000000) +#define IOCON_JTAG_TCK_PIO0_10_FUNC_GPIO ((unsigned int) 0x00000001) +#define IOCON_JTAG_TCK_PIO0_10_FUNC_SCK ((unsigned int) 0x00000002) +#define IOCON_JTAG_TCK_PIO0_10_FUNC_CT16B0_MAT2 ((unsigned int) 0x00000003) +#define IOCON_JTAG_TCK_PIO0_10_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_JTAG_TCK_PIO0_10_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_JTAG_TCK_PIO0_10_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_JTAG_TCK_PIO0_10_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_JTAG_TCK_PIO0_10_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_JTAG_TCK_PIO0_10_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_JTAG_TCK_PIO0_10_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_JTAG_TCK_PIO0_10_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO1_10 (*(pREG32 (0x4004406C))) +#define IOCON_PIO1_10_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO1_10_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO1_10_FUNC_AD6 ((unsigned int) 0x00000001) +#define IOCON_PIO1_10_FUNC_CT16B1_MAT1 ((unsigned int) 0x00000002) +#define IOCON_PIO1_10_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO1_10_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO1_10_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO1_10_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO1_10_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO1_10_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO1_10_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO1_10_HYS_ENABLE ((unsigned int) 0x00000020) +#define IOCON_PIO1_10_ADMODE_MASK ((unsigned int) 0x00000080) +#define IOCON_PIO1_10_ADMODE_ANALOG ((unsigned int) 0x00000000) +#define IOCON_PIO1_10_ADMODE_DIGITAL ((unsigned int) 0x00000080) + +#define IOCON_PIO2_11 (*(pREG32 (0x40044070))) +#define IOCON_PIO2_11_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO2_11_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO2_11_FUNC_SCK0 ((unsigned int) 0x00000001) +#define IOCON_PIO2_11_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO2_11_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO2_11_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO2_11_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO2_11_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO2_11_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO2_11_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO2_11_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_JTAG_TDI_PIO0_11 (*(pREG32 (0x40044074))) +#define IOCON_JTAG_TDI_PIO0_11_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_JTAG_TDI_PIO0_11_FUNC_TDI ((unsigned int) 0x00000000) +#define IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO ((unsigned int) 0x00000001) +#define IOCON_JTAG_TDI_PIO0_11_FUNC_AD0 ((unsigned int) 0x00000002) +#define IOCON_JTAG_TDI_PIO0_11_FUNC_CT32B0_MAT3 ((unsigned int) 0x00000003) +#define IOCON_JTAG_TDI_PIO0_11_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_JTAG_TDI_PIO0_11_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_JTAG_TDI_PIO0_11_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_JTAG_TDI_PIO0_11_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_JTAG_TDI_PIO0_11_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_JTAG_TDI_PIO0_11_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_JTAG_TDI_PIO0_11_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_JTAG_TDI_PIO0_11_HYS_ENABLE ((unsigned int) 0x00000020) +#define IOCON_JTAG_TDI_PIO0_11_ADMODE_MASK ((unsigned int) 0x00000080) +#define IOCON_JTAG_TDI_PIO0_11_ADMODE_ANALOG ((unsigned int) 0x00000000) +#define IOCON_JTAG_TDI_PIO0_11_ADMODE_DIGITAL ((unsigned int) 0x00000080) + +#define IOCON_JTAG_TMS_PIO1_0 (*(pREG32 (0x40044078))) +#define IOCON_JTAG_TMS_PIO1_0_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_JTAG_TMS_PIO1_0_FUNC_TMS ((unsigned int) 0x00000000) +#define IOCON_JTAG_TMS_PIO1_0_FUNC_GPIO ((unsigned int) 0x00000001) +#define IOCON_JTAG_TMS_PIO1_0_FUNC_AD1 ((unsigned int) 0x00000002) +#define IOCON_JTAG_TMS_PIO1_0_FUNC_CT32B1_CAP0 ((unsigned int) 0x00000003) +#define IOCON_JTAG_TMS_PIO1_0_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_JTAG_TMS_PIO1_0_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_JTAG_TMS_PIO1_0_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_JTAG_TMS_PIO1_0_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_JTAG_TMS_PIO1_0_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_JTAG_TMS_PIO1_0_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_JTAG_TMS_PIO1_0_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_JTAG_TMS_PIO1_0_HYS_ENABLE ((unsigned int) 0x00000020) +#define IOCON_JTAG_TMS_PIO1_0_ADMODE_MASK ((unsigned int) 0x00000080) +#define IOCON_JTAG_TMS_PIO1_0_ADMODE_ANALOG ((unsigned int) 0x00000000) +#define IOCON_JTAG_TMS_PIO1_0_ADMODE_DIGITAL ((unsigned int) 0x00000080) + +#define IOCON_JTAG_TDO_PIO1_1 (*(pREG32 (0x4004407C))) +#define IOCON_JTAG_TDO_PIO1_1_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_JTAG_TDO_PIO1_1_FUNC_TDO ((unsigned int) 0x00000000) +#define IOCON_JTAG_TDO_PIO1_1_FUNC_GPIO ((unsigned int) 0x00000001) +#define IOCON_JTAG_TDO_PIO1_1_FUNC_AD2 ((unsigned int) 0x00000002) +#define IOCON_JTAG_TDO_PIO1_1_FUNC_CT32B1_MAT0 ((unsigned int) 0x00000003) +#define IOCON_JTAG_TDO_PIO1_1_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_JTAG_TDO_PIO1_1_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_JTAG_TDO_PIO1_1_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_JTAG_TDO_PIO1_1_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_JTAG_TDO_PIO1_1_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_JTAG_TDO_PIO1_1_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_JTAG_TDO_PIO1_1_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_JTAG_TDO_PIO1_1_HYS_ENABLE ((unsigned int) 0x00000020) +#define IOCON_JTAG_TDO_PIO1_1_ADMODE_MASK ((unsigned int) 0x00000080) +#define IOCON_JTAG_TDO_PIO1_1_ADMODE_ANALOG ((unsigned int) 0x00000000) +#define IOCON_JTAG_TDO_PIO1_1_ADMODE_DIGITAL ((unsigned int) 0x00000080) + +#define IOCON_JTAG_nTRST_PIO1_2 (*(pREG32 (0x40044080))) +#define IOCON_JTAG_nTRST_PIO1_2_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_JTAG_nTRST_PIO1_2_FUNC_TRST ((unsigned int) 0x00000000) +#define IOCON_JTAG_nTRST_PIO1_2_FUNC_GPIO ((unsigned int) 0x00000001) +#define IOCON_JTAG_nTRST_PIO1_2_FUNC_AD3 ((unsigned int) 0x00000002) +#define IOCON_JTAG_nTRST_PIO1_2_FUNC_CT32B1_MAT1 ((unsigned int) 0x00000003) +#define IOCON_JTAG_nTRST_PIO1_2_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_JTAG_nTRST_PIO1_2_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_JTAG_nTRST_PIO1_2_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_JTAG_nTRST_PIO1_2_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_JTAG_nTRST_PIO1_2_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_JTAG_nTRST_PIO1_2_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_JTAG_nTRST_PIO1_2_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_JTAG_nTRST_PIO1_2_HYS_ENABLE ((unsigned int) 0x00000020) +#define IOCON_JTAG_nTRST_PIO1_2_ADMODE_MASK ((unsigned int) 0x00000080) +#define IOCON_JTAG_nTRST_PIO1_2_ADMODE_ANALOG ((unsigned int) 0x00000000) +#define IOCON_JTAG_nTRST_PIO1_2_ADMODE_DIGITAL ((unsigned int) 0x00000080) + +#define IOCON_PIO3_0 (*(pREG32 (0x40044084))) +#define IOCON_PIO3_0_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO3_0_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO3_0_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO3_0_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO3_0_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO3_0_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO3_0_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO3_0_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO3_0_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO3_0_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO3_1 (*(pREG32 (0x40044088))) +#define IOCON_PIO3_1_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO3_1_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO3_1_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO3_1_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO3_1_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO3_1_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO3_1_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO3_1_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO3_1_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO3_1_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO2_3 (*(pREG32 (0x4004408C))) +#define IOCON_PIO2_3_FUNC_MASK 0x7 +#define IOCON_PIO2_3_MODE_MASK 0x18 +#define IOCON_PIO2_3_HYS_MASK 0x20 +#define IOCON_PIO2_3_HYS 0x20 + +#define IOCON_SWDIO_PIO1_3 (*(pREG32 (0x40044090))) +#define IOCON_SWDIO_PIO1_3_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_SWDIO_PIO1_3_FUNC_SWDIO ((unsigned int) 0x00000000) +#define IOCON_SWDIO_PIO1_3_FUNC_GPIO ((unsigned int) 0x00000001) +#define IOCON_SWDIO_PIO1_3_FUNC_AD4 ((unsigned int) 0x00000002) +#define IOCON_SWDIO_PIO1_3_FUNC_CT32B1_MAT2 ((unsigned int) 0x00000004) +#define IOCON_SWDIO_PIO1_3_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_SWDIO_PIO1_3_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_SWDIO_PIO1_3_HYS_ENABLE ((unsigned int) 0x00000020) +#define IOCON_SWDIO_PIO1_3_ADMODE_MASK ((unsigned int) 0x00000080) +#define IOCON_SWDIO_PIO1_3_ADMODE_ANALOG ((unsigned int) 0x00000000) +#define IOCON_SWDIO_PIO1_3_ADMODE_DIGITAL ((unsigned int) 0x00000080) + +#define IOCON_PIO1_4 (*(pREG32 (0x40044094))) +#define IOCON_PIO1_4_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO1_4_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO1_4_FUNC_AD5 ((unsigned int) 0x00000001) +#define IOCON_PIO1_4_FUNC_CT32B1_MAT3 ((unsigned int) 0x00000002) +#define IOCON_PIO1_4_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO1_4_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO1_4_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO1_4_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO1_4_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO1_4_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO1_4_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO1_4_HYS_ENABLE ((unsigned int) 0x00000020) +#define IOCON_PIO1_4_ADMODE_MASK ((unsigned int) 0x00000080) +#define IOCON_PIO1_4_ADMODE_ANALOG ((unsigned int) 0x00000000) +#define IOCON_PIO1_4_ADMODE_DIGITAL ((unsigned int) 0x00000080) + +#define IOCON_PIO1_11 (*(pREG32 (0x40044098))) +#define IOCON_PIO1_11_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO1_11_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO1_11_FUNC_AD7 ((unsigned int) 0x00000001) +#define IOCON_PIO1_11_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO1_11_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO1_11_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO1_11_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO1_11_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO1_11_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO1_11_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO1_11_HYS_ENABLE ((unsigned int) 0x00000020) +#define IOCON_PIO1_11_ADMODE_MASK ((unsigned int) 0x00000080) +#define IOCON_PIO1_11_ADMODE_ANALOG ((unsigned int) 0x00000000) +#define IOCON_PIO1_11_ADMODE_DIGITAL ((unsigned int) 0x00000080) + +#define IOCON_PIO3_2 (*(pREG32 (0x4004409C))) +#define IOCON_PIO3_2_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO3_2_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO3_2_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO3_2_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO3_2_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO3_2_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO3_2_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO3_2_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO3_2_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO3_2_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO1_5 (*(pREG32 (0x400440A0))) +#define IOCON_PIO1_5_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO1_5_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO1_5_FUNC_RTS ((unsigned int) 0x00000001) +#define IOCON_PIO1_5_FUNC_CT32B0_CAP0 ((unsigned int) 0x00000002) +#define IOCON_PIO1_5_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO1_5_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO1_5_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO1_5_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO1_5_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO1_5_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO1_5_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO1_5_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO1_6 (*(pREG32 (0x400440A4))) +#define IOCON_PIO1_6_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO1_6_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO1_6_FUNC_UART_RXD ((unsigned int) 0x00000001) +#define IOCON_PIO1_6_FUNC_CT32B0_MAT0 ((unsigned int) 0x00000002) +#define IOCON_PIO1_6_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO1_6_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO1_6_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO1_6_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO1_6_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO1_6_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO1_6_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO1_6_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO1_7 (*(pREG32 (0x400440A8))) +#define IOCON_PIO1_7_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO1_7_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO1_7_FUNC_UART_TXD ((unsigned int) 0x00000001) +#define IOCON_PIO1_7_FUNC_CT32B0_MAT1 ((unsigned int) 0x00000002) +#define IOCON_PIO1_7_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO1_7_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO1_7_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO1_7_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO1_7_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO1_7_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO1_7_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO1_7_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_PIO3_3 (*(pREG32 (0x400440AC))) +#define IOCON_PIO3_3_FUNC_MASK ((unsigned int) 0x00000007) +#define IOCON_PIO3_3_FUNC_GPIO ((unsigned int) 0x00000000) +#define IOCON_PIO3_3_MODE_MASK ((unsigned int) 0x00000018) +#define IOCON_PIO3_3_MODE_INACTIVE ((unsigned int) 0x00000000) +#define IOCON_PIO3_3_MODE_PULLDOWN ((unsigned int) 0x00000008) +#define IOCON_PIO3_3_MODE_PULLUP ((unsigned int) 0x00000010) +#define IOCON_PIO3_3_MODE_REPEATER ((unsigned int) 0x00000018) +#define IOCON_PIO3_3_HYS_MASK ((unsigned int) 0x00000020) +#define IOCON_PIO3_3_HYS_DISABLE ((unsigned int) 0x00000000) +#define IOCON_PIO3_3_HYS_ENABLE ((unsigned int) 0x00000020) + +#define IOCON_SCKLOC (*(pREG32 (0x400440B0))) +#define IOCON_SCKLOC_SCKPIN_MASK ((unsigned int) 0x00000003) +#define IOCON_SCKLOC_SCKPIN_PIO0_10 ((unsigned int) 0x00000000) // Set SCK function to pin 0.10 +#define IOCON_SCKLOC_SCKPIN_PIO2_11 ((unsigned int) 0x00000001) // Set SCK function to pin 2.11 +#define IOCON_SCKLOC_SCKPIN_PIO0_6 ((unsigned int) 0x00000003) // Set SCK function to pin 0.6 + +/*############################################################################## +## Nested Vectored Interrupt Controller +##############################################################################*/ + +#define NVIC_BASE_ADDRESS (0xE000E100) + +typedef struct +{ + volatile uint32_t ISER[8]; /*!< Offset: 0x000 Interrupt Set Enable Register */ + uint32_t RESERVED0[24]; + volatile uint32_t ICER[8]; /*!< Offset: 0x080 Interrupt Clear Enable Register */ + uint32_t RSERVED1[24]; + volatile uint32_t ISPR[8]; /*!< Offset: 0x100 Interrupt Set Pending Register */ + uint32_t RESERVED2[24]; + volatile uint32_t ICPR[8]; /*!< Offset: 0x180 Interrupt Clear Pending Register */ + uint32_t RESERVED3[24]; + volatile uint32_t IABR[8]; /*!< Offset: 0x200 Interrupt Active bit Register */ + uint32_t RESERVED4[56]; + volatile uint8_t IP[240]; /*!< Offset: 0x300 Interrupt Priority Register (8Bit wide) */ + uint32_t RESERVED5[644]; + volatile uint32_t STIR; /*!< Offset: 0xE00 Software Trigger Interrupt Register */ +} NVIC_Type; + +#define NVIC ((NVIC_Type *) NVIC_BASE_ADDRESS) + +static inline void __enable_irq() { __asm volatile ("cpsie i"); } +static inline void __disable_irq() { __asm volatile ("cpsid i"); } + +typedef enum IRQn +{ +/****** Cortex-M3 Processor Exceptions Numbers ***************************************************/ + NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ + MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */ + BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */ + UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */ + SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */ + DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */ + PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */ + SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */ + +/****** LPC13xx Specific Interrupt Numbers *******************************************************/ + WAKEUP0_IRQn = 0, /*!< All I/O pins can be used as wakeup source. */ + WAKEUP1_IRQn = 1, /*!< There are 40 pins in total for LPC17xx */ + WAKEUP2_IRQn = 2, + WAKEUP3_IRQn = 3, + WAKEUP4_IRQn = 4, + WAKEUP5_IRQn = 5, + WAKEUP6_IRQn = 6, + WAKEUP7_IRQn = 7, + WAKEUP8_IRQn = 8, + WAKEUP9_IRQn = 9, + WAKEUP10_IRQn = 10, + WAKEUP11_IRQn = 11, + WAKEUP12_IRQn = 12, + WAKEUP13_IRQn = 13, + WAKEUP14_IRQn = 14, + WAKEUP15_IRQn = 15, + WAKEUP16_IRQn = 16, + WAKEUP17_IRQn = 17, + WAKEUP18_IRQn = 18, + WAKEUP19_IRQn = 19, + WAKEUP20_IRQn = 20, + WAKEUP21_IRQn = 21, + WAKEUP22_IRQn = 22, + WAKEUP23_IRQn = 23, + WAKEUP24_IRQn = 24, + WAKEUP25_IRQn = 25, + WAKEUP26_IRQn = 26, + WAKEUP27_IRQn = 27, + WAKEUP28_IRQn = 28, + WAKEUP29_IRQn = 29, + WAKEUP30_IRQn = 30, + WAKEUP31_IRQn = 31, + WAKEUP32_IRQn = 32, + WAKEUP33_IRQn = 33, + WAKEUP34_IRQn = 34, + WAKEUP35_IRQn = 35, + WAKEUP36_IRQn = 36, + WAKEUP37_IRQn = 37, + WAKEUP38_IRQn = 38, + WAKEUP39_IRQn = 39, + I2C_IRQn = 40, /*!< I2C Interrupt */ + TIMER_16_0_IRQn = 41, /*!< 16-bit Timer0 Interrupt */ + TIMER_16_1_IRQn = 42, /*!< 16-bit Timer1 Interrupt */ + TIMER_32_0_IRQn = 43, /*!< 32-bit Timer0 Interrupt */ + TIMER_32_1_IRQn = 44, /*!< 32-bit Timer1 Interrupt */ + SSP_IRQn = 45, /*!< SSP Interrupt */ + UART_IRQn = 46, /*!< UART Interrupt */ + USB_IRQn = 47, /*!< USB Regular Interrupt */ + USB_FIQn = 48, /*!< USB Fast Interrupt */ + ADC_IRQn = 49, /*!< A/D Converter Interrupt */ + WDT_IRQn = 50, /*!< Watchdog timer Interrupt */ + BOD_IRQn = 51, /*!< Brown Out Detect(BOD) Interrupt */ + EINT3_IRQn = 53, /*!< External Interrupt 3 Interrupt */ + EINT2_IRQn = 54, /*!< External Interrupt 2 Interrupt */ + EINT1_IRQn = 55, /*!< External Interrupt 1 Interrupt */ + EINT0_IRQn = 56, /*!< External Interrupt 0 Interrupt */ +} IRQn_t; + +static inline void NVIC_EnableIRQ(IRQn_t IRQn) +{ + NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); +} + +static inline void NVIC_DisableIRQ(IRQn_t IRQn) +{ + NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); +} + +/*############################################################################## +## GPIO - General Purpose I/O +##############################################################################*/ + +#define GPIO_GPIO0_BASE (0x50000000) +#define GPIO_GPIO1_BASE (0x50010000) +#define GPIO_GPIO2_BASE (0x50020000) +#define GPIO_GPIO3_BASE (0x50030000) + +#define GPIO_GPIO0DATA (*(pREG32 (0x50003FFC))) // Port data register +#define GPIO_GPIO0DIR (*(pREG32 (0x50008000))) // Data direction register +#define GPIO_GPIO0IS (*(pREG32 (0x50008004))) // Interrupt sense register +#define GPIO_GPIO0IBE (*(pREG32 (0x50008008))) // Interrupt both edges register +#define GPIO_GPIO0IEV (*(pREG32 (0x5000800C))) // Interrupt event register +#define GPIO_GPIO0IE (*(pREG32 (0x50008010))) // Interrupt mask register +#define GPIO_GPIO0RIS (*(pREG32 (0x50008014))) // Raw interrupt status register +#define GPIO_GPIO0MIS (*(pREG32 (0x50008018))) // Masked interrupt status register +#define GPIO_GPIO0IC (*(pREG32 (0x5000801C))) // Interrupt clear register + +#define GPIO_GPIO1DATA (*(pREG32 (0x50013FFC))) // Port data register +#define GPIO_GPIO1DIR (*(pREG32 (0x50018000))) // Data direction register +#define GPIO_GPIO1IS (*(pREG32 (0x50018004))) // Interrupt sense register +#define GPIO_GPIO1IBE (*(pREG32 (0x50018008))) // Interrupt both edges register +#define GPIO_GPIO1IEV (*(pREG32 (0x5001800C))) // Interrupt event register +#define GPIO_GPIO1IE (*(pREG32 (0x50018010))) // Interrupt mask register +#define GPIO_GPIO1RIS (*(pREG32 (0x50018014))) // Raw interrupt status register +#define GPIO_GPIO1MIS (*(pREG32 (0x50018018))) // Masked interrupt status register +#define GPIO_GPIO1IC (*(pREG32 (0x5001801C))) // Interrupt clear register + +#define GPIO_GPIO2DATA (*(pREG32 (0x50023FFC))) // Port data register +#define GPIO_GPIO2DIR (*(pREG32 (0x50028000))) // Data direction register +#define GPIO_GPIO2IS (*(pREG32 (0x50028004))) // Interrupt sense register +#define GPIO_GPIO2IBE (*(pREG32 (0x50028008))) // Interrupt both edges register +#define GPIO_GPIO2IEV (*(pREG32 (0x5002800C))) // Interrupt event register +#define GPIO_GPIO2IE (*(pREG32 (0x50028010))) // Interrupt mask register +#define GPIO_GPIO2RIS (*(pREG32 (0x50028014))) // Raw interrupt status register +#define GPIO_GPIO2MIS (*(pREG32 (0x50028018))) // Masked interrupt status register +#define GPIO_GPIO2IC (*(pREG32 (0x5002801C))) // Interrupt clear register + +#define GPIO_GPIO3DATA (*(pREG32 (0x50033FFC))) // Port data register +#define GPIO_GPIO3DIR (*(pREG32 (0x50038000))) // Data direction register +#define GPIO_GPIO3IS (*(pREG32 (0x50038004))) // Interrupt sense register +#define GPIO_GPIO3IBE (*(pREG32 (0x50038008))) // Interrupt both edges register +#define GPIO_GPIO3IEV (*(pREG32 (0x5003800C))) // Interrupt event register +#define GPIO_GPIO3IE (*(pREG32 (0x50038010))) // Interrupt mask register +#define GPIO_GPIO3RIS (*(pREG32 (0x50038014))) // Raw interrupt status register +#define GPIO_GPIO3MIS (*(pREG32 (0x50038018))) // Masked interrupt status register +#define GPIO_GPIO3IC (*(pREG32 (0x5003801C))) // Interrupt clear register + +#define GPIO_IO_P0 ((unsigned int) 0x00000001) +#define GPIO_IO_P1 ((unsigned int) 0x00000002) +#define GPIO_IO_P2 ((unsigned int) 0x00000004) +#define GPIO_IO_P3 ((unsigned int) 0x00000008) +#define GPIO_IO_P4 ((unsigned int) 0x00000010) +#define GPIO_IO_P5 ((unsigned int) 0x00000020) +#define GPIO_IO_P6 ((unsigned int) 0x00000040) +#define GPIO_IO_P7 ((unsigned int) 0x00000080) +#define GPIO_IO_P8 ((unsigned int) 0x00000100) +#define GPIO_IO_P9 ((unsigned int) 0x00000200) +#define GPIO_IO_P10 ((unsigned int) 0x00000400) +#define GPIO_IO_P11 ((unsigned int) 0x00000800) +#define GPIO_IO_ALL ((unsigned int) 0x00000FFF) + +/*############################################################################## +## USB +##############################################################################*/ + +/* USB registers are defined in USB code */ +#define USB_BASE_ADDRESS (0x40020000) + +/* USB Device Interrupt Status Register */ +#define USB_DEVINTST (*(pREG32 (0x40020000))) +#define USB_DEVINTST_FRAME_MASK ((unsigned int) 0x00000001) +#define USB_DEVINTST_FRAME ((unsigned int) 0x00000001) // Frame interrupt +#define USB_DEVINTST_EP0_MASK ((unsigned int) 0x00000002) +#define USB_DEVINTST_EP0 ((unsigned int) 0x00000002) // USB core interrupt for EP0 +#define USB_DEVINTST_EP1_MASK ((unsigned int) 0x00000004) +#define USB_DEVINTST_EP1 ((unsigned int) 0x00000004) // USB core interrupt for EP1 +#define USB_DEVINTST_EP2_MASK ((unsigned int) 0x00000008) +#define USB_DEVINTST_EP2 ((unsigned int) 0x00000008) // USB core interrupt for EP2 +#define USB_DEVINTST_EP3_MASK ((unsigned int) 0x00000010) +#define USB_DEVINTST_EP3 ((unsigned int) 0x00000010) // USB core interrupt for EP3 +#define USB_DEVINTST_EP4_MASK ((unsigned int) 0x00000020) +#define USB_DEVINTST_EP4 ((unsigned int) 0x00000020) // USB core interrupt for EP4 +#define USB_DEVINTST_EP5_MASK ((unsigned int) 0x00000040) +#define USB_DEVINTST_EP5 ((unsigned int) 0x00000040) // USB core interrupt for EP5 +#define USB_DEVINTST_EP6_MASK ((unsigned int) 0x00000080) +#define USB_DEVINTST_EP6 ((unsigned int) 0x00000080) // USB core interrupt for EP6 +#define USB_DEVINTST_EP7_MASK ((unsigned int) 0x00000100) +#define USB_DEVINTST_EP7 ((unsigned int) 0x00000100) // USB core interrupt for EP7 +#define USB_DEVINTST_DEV_START_MASK ((unsigned int) 0x00000200) +#define USB_DEVINTST_DEV_START ((unsigned int) 0x00000200) +#define USB_DEVINTST_CC_EMPTY_MASK ((unsigned int) 0x00000400) +#define USB_DEVINTST_CC_EMPTY ((unsigned int) 0x00000400) +#define USB_DEVINTST_CD_FULL_MASK ((unsigned int) 0x00000800) +#define USB_DEVINTST_CD_FULL ((unsigned int) 0x00000800) +#define USB_DEVINTST_RxENDPKT_MASK ((unsigned int) 0x00001000) +#define USB_DEVINTST_RxENDPKT ((unsigned int) 0x00001000) +#define USB_DEVINTST_TxENDPKT_MASK ((unsigned int) 0x00002000) +#define USB_DEVINTST_TxENDPKT ((unsigned int) 0x00002000) + +/* USB Device Interrupt Enable Register */ +#define USB_DEVINTEN (*(pREG32 (0x40020004))) +#define USB_DEVINTEN_FRAME_MASK ((unsigned int) 0x00000001) +#define USB_DEVINTEN_FRAME ((unsigned int) 0x00000001) +#define USB_DEVINTEN_EP0_MASK ((unsigned int) 0x00000002) +#define USB_DEVINTEN_EP0 ((unsigned int) 0x00000002) +#define USB_DEVINTEN_EP1_MASK ((unsigned int) 0x00000004) +#define USB_DEVINTEN_EP1 ((unsigned int) 0x00000004) +#define USB_DEVINTEN_EP2_MASK ((unsigned int) 0x00000008) +#define USB_DEVINTEN_EP2 ((unsigned int) 0x00000008) +#define USB_DEVINTEN_EP3_MASK ((unsigned int) 0x00000010) +#define USB_DEVINTEN_EP3 ((unsigned int) 0x00000010) +#define USB_DEVINTEN_EP4_MASK ((unsigned int) 0x00000020) +#define USB_DEVINTEN_EP4 ((unsigned int) 0x00000020) +#define USB_DEVINTEN_EP5_MASK ((unsigned int) 0x00000040) +#define USB_DEVINTEN_EP5 ((unsigned int) 0x00000040) +#define USB_DEVINTEN_EP6_MASK ((unsigned int) 0x00000080) +#define USB_DEVINTEN_EP6 ((unsigned int) 0x00000080) +#define USB_DEVINTEN_EP7_MASK ((unsigned int) 0x00000100) +#define USB_DEVINTEN_EP7 ((unsigned int) 0x00000100) +#define USB_DEVINTEN_DEV_START_MASK ((unsigned int) 0x00000200) +#define USB_DEVINTEN_DEV_START ((unsigned int) 0x00000200) +#define USB_DEVINTEN_CC_EMPTY_MASK ((unsigned int) 0x00000400) +#define USB_DEVINTEN_CC_EMPTY ((unsigned int) 0x00000400) +#define USB_DEVINTEN_CD_FULL_MASK ((unsigned int) 0x00000800) +#define USB_DEVINTEN_CD_FULL ((unsigned int) 0x00000800) +#define USB_DEVINTEN_RxENDPKT_MASK ((unsigned int) 0x00001000) +#define USB_DEVINTEN_RxENDPKT ((unsigned int) 0x00001000) +#define USB_DEVINTEN_TxENDPKT_MASK ((unsigned int) 0x00002000) +#define USB_DEVINTEN_TxENDPKT ((unsigned int) 0x00002000) + +/* USB Device Interrupt Clear Register */ +#define USB_DEVINTCLR (*(pREG32 (0x40020008))) +#define USB_DEVINTCLR_FRAME_MASK ((unsigned int) 0x00000001) +#define USB_DEVINTCLR_FRAME ((unsigned int) 0x00000001) +#define USB_DEVINTCLR_EP0_MASK ((unsigned int) 0x00000002) +#define USB_DEVINTCLR_EP0 ((unsigned int) 0x00000002) +#define USB_DEVINTCLR_EP1_MASK ((unsigned int) 0x00000004) +#define USB_DEVINTCLR_EP1 ((unsigned int) 0x00000004) +#define USB_DEVINTCLR_EP2_MASK ((unsigned int) 0x00000008) +#define USB_DEVINTCLR_EP2 ((unsigned int) 0x00000008) +#define USB_DEVINTCLR_EP3_MASK ((unsigned int) 0x00000010) +#define USB_DEVINTCLR_EP3 ((unsigned int) 0x00000010) +#define USB_DEVINTCLR_EP4_MASK ((unsigned int) 0x00000020) +#define USB_DEVINTCLR_EP4 ((unsigned int) 0x00000020) +#define USB_DEVINTCLR_EP5_MASK ((unsigned int) 0x00000040) +#define USB_DEVINTCLR_EP5 ((unsigned int) 0x00000040) +#define USB_DEVINTCLR_EP6_MASK ((unsigned int) 0x00000080) +#define USB_DEVINTCLR_EP6 ((unsigned int) 0x00000080) +#define USB_DEVINTCLR_EP7_MASK ((unsigned int) 0x00000100) +#define USB_DEVINTCLR_EP7 ((unsigned int) 0x00000100) +#define USB_DEVINTCLR_DEV_START_MASK ((unsigned int) 0x00000200) +#define USB_DEVINTCLR_DEV_START ((unsigned int) 0x00000200) +#define USB_DEVINTCLR_CC_EMPTY_MASK ((unsigned int) 0x00000400) +#define USB_DEVINTCLR_CC_EMPTY ((unsigned int) 0x00000400) +#define USB_DEVINTCLR_CD_FULL_MASK ((unsigned int) 0x00000800) +#define USB_DEVINTCLR_CD_FULL ((unsigned int) 0x00000800) +#define USB_DEVINTCLR_RxENDPKT_MASK ((unsigned int) 0x00001000) +#define USB_DEVINTCLR_RxENDPKT ((unsigned int) 0x00001000) +#define USB_DEVINTCLR_TxENDPKT_MASK ((unsigned int) 0x00002000) +#define USB_DEVINTCLR_TxENDPKT ((unsigned int) 0x00002000) + +/* USB Device Interrupt Set Register */ +#define USB_DEVINTSET (*(pREG32 (0x4002000C))) +#define USB_DEVINTSET_FRAME_MASK ((unsigned int) 0x00000001) +#define USB_DEVINTSET_FRAME ((unsigned int) 0x00000001) +#define USB_DEVINTSET_EP0_MASK ((unsigned int) 0x00000002) +#define USB_DEVINTSET_EP0 ((unsigned int) 0x00000002) +#define USB_DEVINTSET_EP1_MASK ((unsigned int) 0x00000004) +#define USB_DEVINTSET_EP1 ((unsigned int) 0x00000004) +#define USB_DEVINTSET_EP2_MASK ((unsigned int) 0x00000008) +#define USB_DEVINTSET_EP2 ((unsigned int) 0x00000008) +#define USB_DEVINTSET_EP3_MASK ((unsigned int) 0x00000010) +#define USB_DEVINTSET_EP3 ((unsigned int) 0x00000010) +#define USB_DEVINTSET_EP4_MASK ((unsigned int) 0x00000020) +#define USB_DEVINTSET_EP4 ((unsigned int) 0x00000020) +#define USB_DEVINTSET_EP5_MASK ((unsigned int) 0x00000040) +#define USB_DEVINTSET_EP5 ((unsigned int) 0x00000040) +#define USB_DEVINTSET_EP6_MASK ((unsigned int) 0x00000080) +#define USB_DEVINTSET_EP6 ((unsigned int) 0x00000080) +#define USB_DEVINTSET_EP7_MASK ((unsigned int) 0x00000100) +#define USB_DEVINTSET_EP7 ((unsigned int) 0x00000100) +#define USB_DEVINTSET_DEV_START_MASK ((unsigned int) 0x00000200) +#define USB_DEVINTSET_DEV_START ((unsigned int) 0x00000200) +#define USB_DEVINTSET_CC_EMPTY_MASK ((unsigned int) 0x00000400) +#define USB_DEVINTSET_CC_EMPTY ((unsigned int) 0x00000400) +#define USB_DEVINTSET_CD_FULL_MASK ((unsigned int) 0x00000800) +#define USB_DEVINTSET_CD_FULL ((unsigned int) 0x00000800) +#define USB_DEVINTSET_RxENDPKT_MASK ((unsigned int) 0x00001000) +#define USB_DEVINTSET_RxENDPKT ((unsigned int) 0x00001000) +#define USB_DEVINTSET_TxENDPKT_MASK ((unsigned int) 0x00002000) +#define USB_DEVINTSET_TxENDPKT ((unsigned int) 0x00002000) + +/* USB Command Code Register */ +#define USB_CMDCODE (*(pREG32 (0x40020010))) +#define USB_CMDCODE_CMD_PHASE_READ ((unsigned int) 0x00000100) +#define USB_CMDCODE_CMD_PHASE_WRITE ((unsigned int) 0x00000200) +#define USB_CMDCODE_CMD_PHASE_COMMAND ((unsigned int) 0x00000500) +#define USB_CMDCODE_CMD_PHASE_MASK ((unsigned int) 0x0000FF00) +#define USB_CMDCODE_CMD_CODE_MASK ((unsigned int) 0x00FF0000) +#define USB_CMDCODE_CMD_WDATA_MASK ((unsigned int) 0x00FF0000) + +/* USB Command Data Register */ +#define USB_CMDDATA (*(pREG32 (0x40020014))) +#define USB_CMDDATA_CMD_RDATA_MASK ((unsigned int) 0x000000FF) + +/* USB Receive Data Register */ +#define USB_RXDATA (*(pREG32 (0x40020018))) + +/* USB Transmit Data Register */ +#define USB_TXDATA (*(pREG32 (0x4002001C))) + +/* USB Receive Packet Length Register */ +#define USB_RXPLEN (*(pREG32 (0x40020020))) +#define USB_RXPLEN_PKT_LNGTH_MASK ((unsigned int) 0x000003FF) +#define USB_RXPLEN_DV_MASK ((unsigned int) 0x00000400) +#define USB_RXPLEN_DV ((unsigned int) 0x00000400) + +/* USB Transmit Packet Length Register */ +#define USB_TXPLEN (*(pREG32 (0x40020024))) +#define USB_TXPLEN_PKT_LNGTH_MASK 0x3FF + +/* USB Control Register */ +#define USB_CTRL (*(pREG32 (0x40020028))) +#define USB_CTRL_RD_EN_MASK ((unsigned int) 0x00000001) +#define USB_CTRL_RD_EN ((unsigned int) 0x00000001) +#define USB_CTRL_WR_EN_MASK ((unsigned int) 0x00000002) +#define USB_CTRL_WR_EN ((unsigned int) 0x00000002) +#define USB_CTRL_LOG_ENDPOINT_MASK ((unsigned int) 0x0000003C) + +/* USB Device FIQ Select Register */ +#define USB_DEVFIQSEL (*(pREG32 (0x4002002C))) +#define USB_DEVFIQSEL_FRAME_MASK ((unsigned int) 0x00000001) +#define USB_DEVFIQSEL_FRAME ((unsigned int) 0x00000001) +#define USB_DEVFIQSEL_BULKOUT_MASK ((unsigned int) 0x00000002) +#define USB_DEVFIQSEL_BULKOUT ((unsigned int) 0x00000002) +#define USB_DEVFIQSEL_BULKIN_MASK ((unsigned int) 0x00000004) +#define USB_DEVFIQSEL_BULKIN ((unsigned int) 0x00000004) + +/*############################################################################## +## UART +##############################################################################*/ + +#define UART_BASE_ADDRESS (0x40008000) + +#define UART_U0RBR (*(pREG32 (0x40008000))) // Receive buffer +#define UART_U0THR (*(pREG32 (0x40008000))) // Transmitter holding register +#define UART_U0DLL (*(pREG32 (0x40008000))) // Divisor latch LSB +#define UART_U0DLM (*(pREG32 (0x40008004))) // Divisor latch MSB +#define UART_U0IER (*(pREG32 (0x40008004))) // Interrupt enable +#define UART_U0IIR (*(pREG32 (0x40008008))) // Interrupt identification +#define UART_U0FCR (*(pREG32 (0x40008008))) // FIFO control +#define UART_U0MCR (*(pREG32 (0x40008010))) // Modem control +#define UART_U0LCR (*(pREG32 (0x4000800C))) // Line control +#define UART_U0LSR (*(pREG32 (0x40008014))) // Line status +#define UART_U0MSR (*(pREG32 (0x40008018))) // Modem status +#define UART_U0SCR (*(pREG32 (0x4000801C))) // Scratch pad +#define UART_U0ACR (*(pREG32 (0x40008020))) // Auto-baud control +#define UART_U0FDR (*(pREG32 (0x40008028))) // Fractional divider +#define UART_U0TER (*(pREG32 (0x40008030))) // Transmit enable +#define UART_U0RS485CTRL (*(pREG32 (0x4000804C))) // RS485 control register +#define UART_U0RS485ADRMATCH (*(pREG32 (0x40008050))) // RS485 address match +#define UART_U0RS485DLY (*(pREG32 (0x40008054))) // RS485 Delay value +#define UART_U0FIFOLVL (*(pREG32 (0x40008058))) // UART FIFO level + +#define UART_U0RBR_MASK ((unsigned int) 0x000000FF) + +#define UART_U0IER_RBR_Interrupt_MASK ((unsigned int) 0x00000001) // Enables the received data available interrupt +#define UART_U0IER_RBR_Interrupt_Enabled ((unsigned int) 0x00000001) +#define UART_U0IER_RBR_Interrupt_Disabled ((unsigned int) 0x00000000) +#define UART_U0IER_THRE_Interrupt_MASK ((unsigned int) 0x00000002) // Enables the THRE interrupt +#define UART_U0IER_THRE_Interrupt_Enabled ((unsigned int) 0x00000002) +#define UART_U0IER_THRE_Interrupt_Disabled ((unsigned int) 0x00000000) +#define UART_U0IER_RLS_Interrupt_MASK ((unsigned int) 0x00000004) // Enables the Rx line status interrupt +#define UART_U0IER_RLS_Interrupt_Enabled ((unsigned int) 0x00000004) +#define UART_U0IER_RLS_Interrupt_Disabled ((unsigned int) 0x00000000) +#define UART_U0IER_ABEOIntEn_MASK ((unsigned int) 0x00000100) // End of auto-baud interrupt +#define UART_U0IER_ABEOIntEn_Enabled ((unsigned int) 0x00000100) +#define UART_U0IER_ABEOIntEn_Disabled ((unsigned int) 0x00000000) +#define UART_U0IER_ABTOIntEn_MASK ((unsigned int) 0x00000200) // Auto-baud timeout interrupt +#define UART_U0IER_ABTOIntEn_Enabled ((unsigned int) 0x00000200) +#define UART_U0IER_ABTOIntEn_Disabled ((unsigned int) 0x00000000) + +#define UART_U0IIR_IntStatus_MASK ((unsigned int) 0x00000001) // Interrupt status +#define UART_U0IIR_IntStatus_InterruptPending ((unsigned int) 0x00000001) +#define UART_U0IIR_IntStatus_NoInterruptPending ((unsigned int) 0x00000000) +#define UART_U0IIR_IntId_MASK ((unsigned int) 0x0000000E) // Interrupt identification +#define UART_U0IIR_IntId_RLS ((unsigned int) 0x00000006) // Receive line status +#define UART_U0IIR_IntId_RDA ((unsigned int) 0x00000004) // Receive data available +#define UART_U0IIR_IntId_CTI ((unsigned int) 0x0000000C) // Character time-out indicator +#define UART_U0IIR_IntId_THRE ((unsigned int) 0x00000002) // THRE interrupt +#define UART_U0IIR_IntId_MODEM ((unsigned int) 0x00000000) // Modem interrupt +#define UART_U0IIR_FIFO_Enable_MASK ((unsigned int) 0x000000C0) +#define UART_U0IIR_ABEOInt_MASK ((unsigned int) 0x00000100) // End of auto-baud interrupt +#define UART_U0IIR_ABEOInt ((unsigned int) 0x00000100) +#define UART_U0IIR_ABTOInt_MASK ((unsigned int) 0x00000200) // Auto-baud time-out interrupt +#define UART_U0IIR_ABTOInt ((unsigned int) 0x00000200) + +#define UART_U0FCR_FIFO_Enable_MASK ((unsigned int) 0x00000001) // UART FIFOs enabled/disabled +#define UART_U0FCR_FIFO_Enabled ((unsigned int) 0x00000001) +#define UART_U0FCR_FIFO_Disabled ((unsigned int) 0x00000000) +#define UART_U0FCR_Rx_FIFO_Reset_MASK ((unsigned int) 0x00000002) +#define UART_U0FCR_Rx_FIFO_Reset ((unsigned int) 0x00000002) // Clear Rx FIFO +#define UART_U0FCR_Tx_FIFO_Reset_MASK ((unsigned int) 0x00000004) +#define UART_U0FCR_Tx_FIFO_Reset ((unsigned int) 0x00000004) // Clear Tx FIFO +#define UART_U0FCR_Rx_Trigger_Level_Select_MASK ((unsigned int) 0x000000C0) // Chars written before before interrupt +#define UART_U0FCR_Rx_Trigger_Level_Select_1Char ((unsigned int) 0x00000000) +#define UART_U0FCR_Rx_Trigger_Level_Select_4Char ((unsigned int) 0x00000040) +#define UART_U0FCR_Rx_Trigger_Level_Select_8Char ((unsigned int) 0x00000080) +#define UART_U0FCR_Rx_Trigger_Level_Select_12Char ((unsigned int) 0x000000C0) + +#define UART_U0MCR_DTR_Control_MASK ((unsigned int) 0x00000001) // Source for modem output pin DTR +#define UART_U0MCR_DTR_Control ((unsigned int) 0x00000001) +#define UART_U0MCR_RTS_Control_MASK ((unsigned int) 0x00000002) // Source for modem output pin RTS +#define UART_U0MCR_RTS_Control ((unsigned int) 0x00000002) +#define UART_U0MCR_Loopback_Mode_Select_MASK ((unsigned int) 0x00000010) // Diagnostic loopback mode +#define UART_U0MCR_Loopback_Mode_Select_Enabled ((unsigned int) 0x00000010) +#define UART_U0MCR_Loopback_Mode_Select_Disabled ((unsigned int) 0x00000000) +#define UART_U0MCR_RTSen_MASK ((unsigned int) 0x00000040) // Disable auto-rts flow control +#define UART_U0MCR_RTSen_Enabled ((unsigned int) 0x00000040) +#define UART_U0MCR_RTSen_Disabled ((unsigned int) 0x00000000) +#define UART_U0MCR_CTSen_MASK ((unsigned int) 0x00000080) // Disable auto-cts flow control +#define UART_U0MCR_CTSen_Enabled ((unsigned int) 0x00000080) +#define UART_U0MCR_CTSen_Disabled ((unsigned int) 0x00000000) + +#define UART_U0LCR_Word_Length_Select_MASK ((unsigned int) 0x00000003) // Word Length Selector +#define UART_U0LCR_Word_Length_Select_5Chars ((unsigned int) 0x00000000) +#define UART_U0LCR_Word_Length_Select_6Chars ((unsigned int) 0x00000001) +#define UART_U0LCR_Word_Length_Select_7Chars ((unsigned int) 0x00000002) +#define UART_U0LCR_Word_Length_Select_8Chars ((unsigned int) 0x00000003) +#define UART_U0LCR_Stop_Bit_Select_MASK ((unsigned int) 0x00000004) // Stop bit select +#define UART_U0LCR_Stop_Bit_Select_1Bits ((unsigned int) 0x00000000) +#define UART_U0LCR_Stop_Bit_Select_2Bits ((unsigned int) 0x00000004) +#define UART_U0LCR_Parity_Enable_MASK ((unsigned int) 0x00000008) // Parity enable +#define UART_U0LCR_Parity_Enabled ((unsigned int) 0x00000008) +#define UART_U0LCR_Parity_Disabled ((unsigned int) 0x00000000) +#define UART_U0LCR_Parity_Select_MASK ((unsigned int) 0x00000030) // Parity select +#define UART_U0LCR_Parity_Select_OddParity ((unsigned int) 0x00000000) +#define UART_U0LCR_Parity_Select_EvenParity ((unsigned int) 0x00000010) +#define UART_U0LCR_Parity_Select_Forced1 ((unsigned int) 0x00000020) +#define UART_U0LCR_Parity_Select_Forced0 ((unsigned int) 0x00000030) +#define UART_U0LCR_Break_Control_MASK ((unsigned int) 0x00000040) // Break transmission control +#define UART_U0LCR_Break_Control_Enabled ((unsigned int) 0x00000040) +#define UART_U0LCR_Break_Control_Disabled ((unsigned int) 0x00000000) +#define UART_U0LCR_Divisor_Latch_Access_MASK ((unsigned int) 0x00000080) // Divisor latch access +#define UART_U0LCR_Divisor_Latch_Access_Enabled ((unsigned int) 0x00000080) +#define UART_U0LCR_Divisor_Latch_Access_Disabled ((unsigned int) 0x00000000) + +#define UART_U0LSR_RDR_MASK ((unsigned int) 0x00000001) // Receiver data ready +#define UART_U0LSR_RDR_EMPTY ((unsigned int) 0x00000000) // U0RBR is empty +#define UART_U0LSR_RDR_DATA ((unsigned int) 0x00000001) // U0RBR contains valid data +#define UART_U0LSR_OE_MASK ((unsigned int) 0x00000002) // Overrun error +#define UART_U0LSR_OE ((unsigned int) 0x00000002) +#define UART_U0LSR_PE_MASK ((unsigned int) 0x00000004) // Parity error +#define UART_U0LSR_PE ((unsigned int) 0x00000004) +#define UART_U0LSR_FE_MASK ((unsigned int) 0x00000008) // Framing error +#define UART_U0LSR_FE ((unsigned int) 0x00000008) +#define UART_U0LSR_BI_MASK ((unsigned int) 0x00000010) // Break interrupt +#define UART_U0LSR_BI ((unsigned int) 0x00000010) +#define UART_U0LSR_THRE_MASK ((unsigned int) 0x00000020) // Transmitter holding register empty +#define UART_U0LSR_THRE ((unsigned int) 0x00000020) +#define UART_U0LSR_TEMT_MASK ((unsigned int) 0x00000040) // Transmitter empty +#define UART_U0LSR_TEMT ((unsigned int) 0x00000040) +#define UART_U0LSR_RXFE_MASK ((unsigned int) 0x00000080) // Error in Rx FIFO +#define UART_U0LSR_RXFE ((unsigned int) 0x00000080) + +#define UART_U0MSR_Delta_CTS_MASK ((unsigned int) 0x00000001) // State change of input CTS +#define UART_U0MSR_Delta_CTS ((unsigned int) 0x00000001) +#define UART_U0MSR_Delta_DSR_MASK ((unsigned int) 0x00000002) // State change of input DSR +#define UART_U0MSR_Delta_DSR ((unsigned int) 0x00000002) +#define UART_U0MSR_Trailing_Edge_RI_MASK ((unsigned int) 0x00000004) // Low to high transition of input RI +#define UART_U0MSR_Trailing_Edge_RI ((unsigned int) 0x00000004) +#define UART_U0MSR_Delta_DCD_MASK ((unsigned int) 0x00000008) // State change of input DCD +#define UART_U0MSR_Delta_DCD ((unsigned int) 0x00000008) +#define UART_U0MSR_CTS_MASK ((unsigned int) 0x00000010) // Clear to send state +#define UART_U0MSR_CTS ((unsigned int) 0x00000010) +#define UART_U0MSR_DSR_MASK ((unsigned int) 0x00000020) // Data set ready state +#define UART_U0MSR_DSR ((unsigned int) 0x00000020) +#define UART_U0MSR_RI_MASK ((unsigned int) 0x00000040) // Ring indicator state +#define UART_U0MSR_RI ((unsigned int) 0x00000040) +#define UART_U0MSR_DCD_MASK ((unsigned int) 0x00000080) // Data carrier detect state +#define UART_U0MSR_DCD ((unsigned int) 0x00000080) + +#define UART_U0ACR_Start_MASK ((unsigned int) 0x00000001) // Auto-baud start/stop +#define UART_U0ACR_Start ((unsigned int) 0x00000001) +#define UART_U0ACR_Stop ((unsigned int) 0x00000000) +#define UART_U0ACR_Mode_MASK ((unsigned int) 0x00000002) // Auto-baud mode select +#define UART_U0ACR_Mode_Mode1 ((unsigned int) 0x00000000) +#define UART_U0ACR_Mode_Mode2 ((unsigned int) 0x00000002) +#define UART_U0ACR_AutoRestart_MASK ((unsigned int) 0x00000004) +#define UART_U0ACR_AutoRestart_NoRestart ((unsigned int) 0x00000000) +#define UART_U0ACR_AutoRestart_Restart ((unsigned int) 0x00000004) // Restart in case of time-out +#define UART_U0ACR_ABEOIntClr_MASK ((unsigned int) 0x00000100) // End of auto-baud interrupt clear bit +#define UART_U0ACR_ABEOIntClr ((unsigned int) 0x00000100) +#define UART_U0ACR_ABTOIntClr_MASK ((unsigned int) 0x00000200) // Auto-baud timeout interrupt clear bit +#define UART_U0ACR_ABTOIntClr ((unsigned int) 0x00000200) + +#define UART_U0FDR_DIVADDVAL_MASK ((unsigned int) 0x0000000F) // Fractional divider: prescaler register +#define UART_U0FDR_MULVAL_MASK ((unsigned int) 0x000000F0) // Fractional divider: prescaler multiplier + +#define UART_U0TER_TXEN_MASK ((unsigned int) 0x00000080) // UART transmit enable +#define UART_U0TER_TXEN_Enabled ((unsigned int) 0x00000080) +#define UART_U0TER_TXEN_Disabled ((unsigned int) 0x00000000) + +#define UART_U0RS485CTRL_NMMEN_MASK ((unsigned int) 0x00000001) // Normal multi-drop mode +#define UART_U0RS485CTRL_NMMEN ((unsigned int) 0x00000001) +#define UART_U0RS485CTRL_RXDIS_MASK ((unsigned int) 0x00000002) // Receiver +#define UART_U0RS485CTRL_RXDIS ((unsigned int) 0x00000002) +#define UART_U0RS485CTRL_AADEN_MASK ((unsigned int) 0x00000004) // Auto-address detect +#define UART_U0RS485CTRL_AADEN ((unsigned int) 0x00000004) +#define UART_U0RS485CTRL_SEL_MASK ((unsigned int) 0x00000008) +#define UART_U0RS485CTRL_SEL_RTS ((unsigned int) 0x00000000) // Use RTS for direction control +#define UART_U0RS485CTRL_SEL_DTS ((unsigned int) 0x00000008) // Use DTS for direction control +#define UART_U0RS485CTRL_DCTRL_MASK ((unsigned int) 0x00000010) // Enable/Disable auto-direction control +#define UART_U0RS485CTRL_DCTRL_Disabled ((unsigned int) 0x00000000) +#define UART_U0RS485CTRL_DCTRL_Enabled ((unsigned int) 0x00000010) +#define UART_U0RS485CTRL_OINV_MASK ((unsigned int) 0x00000020) // Reverse polarity of direction control signal on RTS/DTR pin +#define UART_U0RS485CTRL_OINV_Normal ((unsigned int) 0x00000000) +#define UART_U0RS485CTRL_OINV_Inverted ((unsigned int) 0x00000020) + +#define UART_U0FIFOLVL_RXFIFOLVL_MASK ((unsigned int) 0x0000000F) +#define UART_U0FIFOLVL_RXFIFOLVL_Empty ((unsigned int) 0x00000000) +#define UART_U0FIFOLVL_RXFIFOLVL_Full ((unsigned int) 0x0000000F) +#define UART_U0FIFOLVL_TXFIFOLVL_MASK ((unsigned int) 0x00000F00) +#define UART_U0FIFOLVL_TXFIFOLVL_Empty ((unsigned int) 0x00000000) +#define UART_U0FIFOLVL_TXFIFOLVL_Full ((unsigned int) 0x00000F00) + +/*############################################################################## +## SSP - Synchronous Serial Port +##############################################################################*/ + +#define SSP_SSP0_BASE_ADDRESS (0x40040000) + +#define SSP_SSP0CR0 (*(pREG32 (0x40040000))) // Control register 0 +#define SSP_SSP0CR1 (*(pREG32 (0x40040004))) // Control register 1 +#define SSP_SSP0DR (*(pREG32 (0x40040008))) // Data register +#define SSP_SSP0SR (*(pREG32 (0x4004000C))) // Status register +#define SSP_SSP0CPSR (*(pREG32 (0x40040010))) // Clock prescale register +#define SSP_SSP0IMSC (*(pREG32 (0x40040014))) // Interrupt mask set/clear register +#define SSP_SSP0RIS (*(pREG32 (0x40040018))) // Raw interrupt status register +#define SSP_SSP0MIS (*(pREG32 (0x4004001C))) // Masked interrupt status register +#define SSP_SSP0ICR (*(pREG32 (0x40040020))) // SSPICR interrupt clear register + +/* SSP0CR0 (SSP0 Control Register 0) + This register controls the basic operation of the SSP controller. */ + +#define SSP_SSP0CR0_DSS_MASK ((unsigned int) 0x0000000F) // Data size select +#define SSP_SSP0CR0_DSS_4BIT ((unsigned int) 0x00000003) +#define SSP_SSP0CR0_DSS_5BIT ((unsigned int) 0x00000004) +#define SSP_SSP0CR0_DSS_6BIT ((unsigned int) 0x00000005) +#define SSP_SSP0CR0_DSS_7BIT ((unsigned int) 0x00000006) +#define SSP_SSP0CR0_DSS_8BIT ((unsigned int) 0x00000007) +#define SSP_SSP0CR0_DSS_9BIT ((unsigned int) 0x00000008) +#define SSP_SSP0CR0_DSS_10BIT ((unsigned int) 0x00000009) +#define SSP_SSP0CR0_DSS_11BIT ((unsigned int) 0x0000000A) +#define SSP_SSP0CR0_DSS_12BIT ((unsigned int) 0x0000000B) +#define SSP_SSP0CR0_DSS_13BIT ((unsigned int) 0x0000000C) +#define SSP_SSP0CR0_DSS_14BIT ((unsigned int) 0x0000000D) +#define SSP_SSP0CR0_DSS_15BIT ((unsigned int) 0x0000000E) +#define SSP_SSP0CR0_DSS_16BIT ((unsigned int) 0x0000000F) +#define SSP_SSP0CR0_FRF_MASK ((unsigned int) 0x00000030) // Frame format +#define SSP_SSP0CR0_FRF_SPI ((unsigned int) 0x00000000) +#define SSP_SSP0CR0_FRF_TI ((unsigned int) 0x00000010) +#define SSP_SSP0CR0_FRF_MWIRE ((unsigned int) 0x00000020) +#define SSP_SSP0CR0_CPOL_MASK ((unsigned int) 0x00000040) // Clock out polarity +#define SSP_SSP0CR0_CPOL_LOW ((unsigned int) 0x00000000) +#define SSP_SSP0CR0_CPOL_HIGH ((unsigned int) 0x00000040) +#define SSP_SSP0CR0_CPHA_MASK ((unsigned int) 0x00000080) // Clock out phase +#define SSP_SSP0CR0_CPHA_FIRST ((unsigned int) 0x00000000) +#define SSP_SSP0CR0_CPHA_SECOND ((unsigned int) 0x00000080) + +/* Serial Clock Rate. The number of prescaler-output clocks per + bit on the bus, minus one. Given that CPSDVSR is the + prescale divider, and the APB clock PCLK clocks the + prescaler, the bit frequency is PCLK / (CPSDVSR × [SCR+1]). */ + +#define SSP_SSP0CR0_SCR_MASK ((unsigned int) 0x0000FF00) // Serial clock rate +#define SSP_SSP0CR0_SCR_1 ((unsigned int) 0x00000100) +#define SSP_SSP0CR0_SCR_2 ((unsigned int) 0x00000200) +#define SSP_SSP0CR0_SCR_3 ((unsigned int) 0x00000300) +#define SSP_SSP0CR0_SCR_4 ((unsigned int) 0x00000400) +#define SSP_SSP0CR0_SCR_5 ((unsigned int) 0x00000500) +#define SSP_SSP0CR0_SCR_6 ((unsigned int) 0x00000600) +#define SSP_SSP0CR0_SCR_7 ((unsigned int) 0x00000700) +#define SSP_SSP0CR0_SCR_8 ((unsigned int) 0x00000800) +#define SSP_SSP0CR0_SCR_9 ((unsigned int) 0x00000900) +#define SSP_SSP0CR0_SCR_10 ((unsigned int) 0x00000A00) +#define SSP_SSP0CR0_SCR_11 ((unsigned int) 0x00000B00) +#define SSP_SSP0CR0_SCR_12 ((unsigned int) 0x00000C00) +#define SSP_SSP0CR0_SCR_13 ((unsigned int) 0x00000D00) +#define SSP_SSP0CR0_SCR_14 ((unsigned int) 0x00000E00) +#define SSP_SSP0CR0_SCR_15 ((unsigned int) 0x00000F00) +#define SSP_SSP0CR0_SCR_16 ((unsigned int) 0x00001000) + +/* SSP0CR1 (SSP0 Control Register 1) + This register controls certain aspects of the operation of the SSP controller. */ + +#define SSP_SSP0CR1_LBM_MASK ((unsigned int) 0x00000001) // Loop back mode +#define SSP_SSP0CR1_LBM_NORMAL ((unsigned int) 0x00000000) +#define SSP_SSP0CR1_LBM_INVERTED ((unsigned int) 0x00000001) // MISO/MOSI are reversed +#define SSP_SSP0CR1_SSE_MASK ((unsigned int) 0x00000002) // SSP enable +#define SSP_SSP0CR1_SSE_DISABLED ((unsigned int) 0x00000000) +#define SSP_SSP0CR1_SSE_ENABLED ((unsigned int) 0x00000002) +#define SSP_SSP0CR1_MS_MASK ((unsigned int) 0x00000004) // Master/Slave Mode +#define SSP_SSP0CR1_MS_MASTER ((unsigned int) 0x00000000) +#define SSP_SSP0CR1_MS_SLAVE ((unsigned int) 0x00000004) +#define SSP_SSP0CR1_SOD_MASK ((unsigned int) 0x00000008) // Slave output disable + +/* SSP0DR (SSP0 Data Register) + Software can write data to be transmitted to this register, and read data that has been + received. */ + +#define SSP_SSP0DR_MASK ((unsigned int) 0x0000FFFF) // Data + +/* SSP0SR (SSP0 Status Register) + This read-only register reflects the current status of the SSP controller. */ + +#define SSP_SSP0SR_TFE_MASK ((unsigned int) 0x00000001) // Transmit FIFO empty +#define SSP_SSP0SR_TFE_EMPTY ((unsigned int) 0x00000001) +#define SSP_SSP0SR_TFE_NOTEMPTY ((unsigned int) 0x00000000) +#define SSP_SSP0SR_TNF_MASK ((unsigned int) 0x00000002) // Transmit FIFO not full +#define SSP_SSP0SR_TNF_NOTFULL ((unsigned int) 0x00000002) +#define SSP_SSP0SR_TNF_FULL ((unsigned int) 0x00000000) +#define SSP_SSP0SR_RNE_MASK ((unsigned int) 0x00000004) // Receive FIFO not empty +#define SSP_SSP0SR_RNE_NOTEMPTY ((unsigned int) 0x00000004) +#define SSP_SSP0SR_RNE_EMPTY ((unsigned int) 0x00000000) +#define SSP_SSP0SR_RFF_MASK ((unsigned int) 0x00000008) // Receive FIFO full +#define SSP_SSP0SR_RFF_FULL ((unsigned int) 0x00000008) +#define SSP_SSP0SR_RFF_NOTFULL ((unsigned int) 0x00000000) +#define SSP_SSP0SR_BSY_MASK ((unsigned int) 0x00000010) // Busy Flag +#define SSP_SSP0SR_BSY_IDLE ((unsigned int) 0x00000000) +#define SSP_SSP0SR_BSY_BUSY ((unsigned int) 0x00000010) + +/* SSP0CPSR (SSP0 Clock Prescale Register) + This register controls the factor by which the Prescaler divides the SSP peripheral clock + SSP_PCLK to yield the prescaler clock that is, in turn, divided by the SCR factor in + SSP0CR0, to determine the bit clock. */ + +#define SSP_SSP0CPSR_CPSDVSR_MASK ((unsigned int) 0x000000FF) +#define SSP_SSP0CPSR_CPSDVSR_DIV2 ((unsigned int) 0x00000002) +#define SSP_SSP0CPSR_CPSDVSR_DIV4 ((unsigned int) 0x00000004) +#define SSP_SSP0CPSR_CPSDVSR_DIV10 ((unsigned int) 0x0000000A) +#define SSP_SSP0CPSR_CPSDVSR_DIV12 ((unsigned int) 0x0000000C) +#define SSP_SSP0CPSR_CPSDVSR_DIV16 ((unsigned int) 0x00000010) +#define SSP_SSP0CPSR_CPSDVSR_DIV20 ((unsigned int) 0x00000014) + +/* SSP0IMSC (SSP0 Interrupt Mask Set/Clear Register) + This register controls whether each of the four possible interrupt conditions in the SSP + controller are enabled. Note that ARM uses the word “masked” in the opposite sense from + classic computer terminology, in which “masked” meant “disabled”. ARM uses the word + “masked” to mean “enabled”. To avoid confusion we will not use the word “masked”. */ + +#define SSP_SSP0IMSC_RORIM_MASK ((unsigned int) 0x00000001) // Receive overrun interrupt +#define SSP_SSP0IMSC_RORIM_ENBL ((unsigned int) 0x00000001) +#define SSP_SSP0IMSC_RORIM_DSBL ((unsigned int) 0x00000000) +#define SSP_SSP0IMSC_RTIM_MASK ((unsigned int) 0x00000002) // Receive timeout interrupt +#define SSP_SSP0IMSC_RTIM_ENBL ((unsigned int) 0x00000002) +#define SSP_SSP0IMSC_RTIM_DSBL ((unsigned int) 0x00000000) +#define SSP_SSP0IMSC_RXIM_MASK ((unsigned int) 0x00000004) // Rx FIFO >= 1/2 full interrupt +#define SSP_SSP0IMSC_RXIM_ENBL ((unsigned int) 0x00000004) +#define SSP_SSP0IMSC_RXIM_DSBL ((unsigned int) 0x00000000) +#define SSP_SSP0IMSC_TXIM_MASK ((unsigned int) 0x00000008) // Tx FIFO >= 1/2 empty interrupt +#define SSP_SSP0IMSC_TXIM_ENBL ((unsigned int) 0x00000008) +#define SSP_SSP0IMSC_TXIM_DSBL ((unsigned int) 0x00000000) + +/* SSP0RIS (SSP0 Raw Interrupt Status Register) + This read-only register contains a 1 for each interrupt condition that is asserted, + regardless of whether or not the interrupt is enabled in the SSP0IMSC. */ + +#define SSP_SSP0RIS_RORRIS_MASK ((unsigned int) 0x00000001) // Frame received while Rx FIFO full +#define SSP_SSP0RIS_RORRIS_RCVD ((unsigned int) 0x00000001) +#define SSP_SSP0RIS_RTRIS_MASK ((unsigned int) 0x00000002) // Rx FIFO not empty no read within timeout +#define SSP_SSP0RIS_RTRIS_NOTEMPTY ((unsigned int) 0x00000002) +#define SSP_SSP0RIS_RXRIS_MASK ((unsigned int) 0x00000004) // Rx FIFO >= half full +#define SSP_SSP0RIS_RXRIS_HALFFULL ((unsigned int) 0x00000004) +#define SSP_SSP0RIS_TXRIS_MASK ((unsigned int) 0x00000008) // Tx FIF0 >= half-empty +#define SSP_SSP0RIS_TXRIS_HALFEMPTY ((unsigned int) 0x00000008) + +/* SSP0MIS (SSP0 Masked Interrupt Status Register) + This read-only register contains a 1 for each interrupt condition that is asserted and + enabled in the SSP0IMSC. When an SSP interrupt occurs, the interrupt service routine + should read this register to determine the cause(s) of the interrupt. */ + +#define SSP_SSP0MIS_RORMIS_MASK ((unsigned int) 0x00000001) // Frame received while Rx FIFO full +#define SSP_SSP0MIS_RORMIS_FRMRCVD ((unsigned int) 0x00000001) +#define SSP_SSP0MIS_RTMIS_MASK ((unsigned int) 0x00000002) // Rx FIFO not empty no read withing timeout +#define SSP_SSP0MIS_RTMIS_NOTEMPTY ((unsigned int) 0x00000002) +#define SSP_SSP0MIS_RXMIS_MASK ((unsigned int) 0x00000004) // Rx FIFO >= half full +#define SSP_SSP0MIS_RXMIS_HALFFULL ((unsigned int) 0x00000004) +#define SSP_SSP0MIS_TXMIS_MASK ((unsigned int) 0x00000008) // Tx FIFO >= half-empty +#define SSP_SSP0MIS_TXMIS_HALFEMPTY ((unsigned int) 0x00000008) + +/* SSP0ICR (SSP0 Interrupt Clear Register) + Software can write one or more one(s) to this write-only register, to clear the + corresponding interrupt condition(s) in the SSP controller. Note that the other two interrupt + conditions can be cleared by writing or reading the appropriate FIFO, or disabled by + clearing the corresponding bit in SSP0IMSC. */ + +#define SSP_SSP0ICR_RORIC_MASK ((unsigned int) 0x00000001) // Clears RORIC interrupt flag +#define SSP_SSP0ICR_RORIC_CLEAR ((unsigned int) 0x00000001) +#define SSP_SSP0ICR_RTIC_MASK ((unsigned int) 0x00000002) // Clear Rx FIFO not empty/no read flag +#define SSP_SSP0ICR_RTIC_CLEAR ((unsigned int) 0x00000002) + +/*############################################################################## +## I2C +##############################################################################*/ + +#define I2C_BASE_ADDRESS (0x40000000) + +#define I2C_I2CCONSET (*(pREG32 (0x40000000))) // I2C control set register +#define I2C_I2CSTAT (*(pREG32 (0x40000004))) // I2C status register +#define I2C_I2CDAT (*(pREG32 (0x40000008))) // I2C data register +#define I2C_I2CADR0 (*(pREG32 (0x4000000C))) // I2C slave address register +#define I2C_I2CSCLH (*(pREG32 (0x40000010))) // I2C SCL HIGH/LOW duty cycle register +#define I2C_I2CSCLL (*(pREG32 (0x40000014))) +#define I2C_I2CCONCLR (*(pREG32 (0x40000018))) // I2C control clear register +#define I2C_I2CMMCTRL (*(pREG32 (0x4000001C))) // I2C monitor control register +#define I2C_I2CADR1 (*(pREG32 (0x40000020))) // I2C slave address register 1 +#define I2C_I2CADR2 (*(pREG32 (0x40000024))) // I2C slave address register 2 +#define I2C_I2CADR3 (*(pREG32 (0x40000028))) // I2C slave address register 3 +#define I2C_I2CDATA_BUFFER (*(pREG32 (0x4000002C))) // I2C data buffer register +#define I2C_I2CMASK0 (*(pREG32 (0x40000030))) // I2C mask register 0 +#define I2C_I2CMASK1 (*(pREG32 (0x40000034))) // I2C mask register 1 +#define I2C_I2CMASK2 (*(pREG32 (0x40000038))) // I2C mask register 2 +#define I2C_I2CMASK3 (*(pREG32 (0x4000003C))) // I2C mask register 3 + +/* I2CCONSET (I2C Control Set register) + The I2CONSET registers control setting of bits in the I2CON register that controls + operation of the I2C interface. Writing a one to a bit of this register causes the + corresponding bit in the I2C control register to be set. Writing a zero has no effect. */ + +#define I2C_I2CCONSET_AA_MASK ((unsigned int) 0x00000004) +#define I2C_I2CCONSET_AA ((unsigned int) 0x00000004) // Asset acknowlegde flag +#define I2C_I2CCONSET_SI_MASK ((unsigned int) 0x00000008) +#define I2C_I2CCONSET_SI ((unsigned int) 0x00000008) // I2C interrupt flag +#define I2C_I2CCONSET_STO_MASK ((unsigned int) 0x00000010) +#define I2C_I2CCONSET_STO ((unsigned int) 0x00000010) // Stop flag +#define I2C_I2CCONSET_STA_MASK ((unsigned int) 0x00000020) +#define I2C_I2CCONSET_STA ((unsigned int) 0x00000020) // Start flag +#define I2C_I2CCONSET_I2EN_MASK ((unsigned int) 0x00000040) +#define I2C_I2CCONSET_I2EN ((unsigned int) 0x00000040) // I2C interface enable + +/* I2CSTAT (I2C Status register) + Each I2C Status register reflects the condition of the corresponding I2C interface. The I2C + Status register is Read-Only. */ + +#define I2C_I2CSTAT_Status_MASK ((unsigned int) 0x000000F8) // Status information + +/* I2CADR0 (I2C Slave Address register) + These registers are readable and writable and are only used when an I2C interface is set + to slave mode. */ + +#define I2C_I2CADR0_GC_MASK ((unsigned int) 0x00000001) +#define I2C_I2CADR0_GC ((unsigned int) 0x00000001) // General call enable bit +#define I2C_I2CADR0_Address_MASK ((unsigned int) 0x000000FE) // I2C device address for slave mode + +/* I2CCONCLR (I2C Control Clear register) + The I2CONCLR registers control clearing of bits in the I2CON register that controls + operation of the I2C interface. Writing a one to a bit of this register causes the + corresponding bit in the I2C control register to be cleared. Writing a zero has no effect. */ + +#define I2C_I2CCONCLR_AAC_MASK ((unsigned int) 0x00000004) // Assert acknowledge clear bit +#define I2C_I2CCONCLR_AAC ((unsigned int) 0x00000004) +#define I2C_I2CCONCLR_SIC_MASK ((unsigned int) 0x00000008) // I2C interrupt clear bit +#define I2C_I2CCONCLR_SIC ((unsigned int) 0x00000008) +#define I2C_I2CCONCLR_STAC_MASK ((unsigned int) 0x00000020) // Start flag clear bit +#define I2C_I2CCONCLR_STAC ((unsigned int) 0x00000020) +#define I2C_I2CCONCLR_I2ENC_MASK ((unsigned int) 0x00000040) // I2C interface disable bit +#define I2C_I2CCONCLR_I2ENC ((unsigned int) 0x00000040) + +/* I2CMMCTRL (I2C Monitor mode control register) + This register controls the Monitor mode which allows the I2C module to monitor traffic on + the I2C bus without actually participating in traffic or interfering with the I2C bus. */ + +#define I2C_I2CMMCTRL_MM_ENA_MASK ((unsigned int) 0x00000001) // Monitor mode enable +#define I2C_I2CMMCTRL_MM_ENA_ENABLED ((unsigned int) 0x00000001) +#define I2C_I2CMMCTRL_MM_ENA_DISABLED ((unsigned int) 0x00000000) +#define I2C_I2CMMCTRL_ENA_SCL_MASK ((unsigned int) 0x00000002) // SCL output enable +#define I2C_I2CMMCTRL_ENA_SCL_HOLDLOW ((unsigned int) 0x00000002) +#define I2C_I2CMMCTRL_ENA_SCL_FORCEHIGH ((unsigned int) 0x00000000) +#define I2C_I2CMMCTRL_MATCH_ALL_MASK ((unsigned int) 0x00000008) // Select interrupt register match +#define I2C_I2CMMCTRL_MATCH_ALL_NORMAL ((unsigned int) 0x00000000) +#define I2C_I2CMMCTRL_MATCH_ALL_ANYADDRESS ((unsigned int) 0x00000008) + +/* I2CADR1..3 (I2C Slave Address registers) + These registers are readable and writable and are only used when an I2C interface is set + to slave mode. In master mode, this register has no effect. The LSB of I2ADR is the + General Call bit. When this bit is set, the General Call address (0x00) is recognized. */ + +#define I2C_I2CADR1_GC_MASK ((unsigned int) 0x00000001) // General call enable bit +#define I2C_I2CADR1_GC ((unsigned int) 0x00000001) +#define I2C_I2CADR1_Address_MASK ((unsigned int) 0x000000FE) + +#define I2C_I2CADR2_GC_MASK ((unsigned int) 0x00000001) // General call enable bit +#define I2C_I2CADR2_GC ((unsigned int) 0x00000001) +#define I2C_I2CADR2_Address_MASK ((unsigned int) 0x000000FE) + +#define I2C_I2CADR3_GC_MASK ((unsigned int) 0x00000001) // General call enable bit +#define I2C_I2CADR3_GC ((unsigned int) 0x00000001) +#define I2C_I2CADR3_Address_MASK ((unsigned int) 0x000000FE) + +/* I2CMASK0..3 (I2C Mask registers) */ + +#define I2C_I2CMASK0_MASK_MASK ((unsigned int) 0x000000FE) + +#define I2C_I2CMASK1_MASK_MASK ((unsigned int) 0x000000FE) + +#define I2C_I2CMASK2_MASK_MASK ((unsigned int) 0x000000FE) + +#define I2C_I2CMASK3_MASK_MASK ((unsigned int) 0x000000FE) + +/*############################################################################## +## 16-Bit Timers (CT16B0/1) +##############################################################################*/ + +#define TMR_CT16B0_BASE_ADDRESS (0x4000C000) + +#define TMR_TMR16B0IR (*(pREG32 (0x4000C000))) // Interrupt register +#define TMR_TMR16B0TCR (*(pREG32 (0x4000C004))) // Timer control register +#define TMR_TMR16B0TC (*(pREG32 (0x4000C008))) // Timer counter +#define TMR_TMR16B0PR (*(pREG32 (0x4000C00C))) // Prescale register +#define TMR_TMR16B0PC (*(pREG32 (0x4000C010))) // Prescale counter register +#define TMR_TMR16B0MCR (*(pREG32 (0x4000C014))) // Match control register +#define TMR_TMR16B0MR0 (*(pREG32 (0x4000C018))) // Match register 0 +#define TMR_TMR16B0MR1 (*(pREG32 (0x4000C01C))) // Match register 1 +#define TMR_TMR16B0MR2 (*(pREG32 (0x4000C020))) // Match register 2 +#define TMR_TMR16B0MR3 (*(pREG32 (0x4000C024))) // Match register 3 +#define TMR_TMR16B0CCR (*(pREG32 (0x4000C028))) // Capture control register +#define TMR_TMR16B0CR0 (*(pREG32 (0x4000C02C))) // Capture register +#define TMR_TMR16B0EMR (*(pREG32 (0x4000C03C))) // External match register +#define TMR_TMR16B0CTCR (*(pREG32 (0x4000C070))) // Count control register +#define TMR_TMR16B0PWMC (*(pREG32 (0x4000C074))) // PWM control register + +#define TMR_TMR16B0IR_MR0_MASK ((unsigned int) 0x00000001) // Interrupt flag for match channel 0 +#define TMR_TMR16B0IR_MR0 ((unsigned int) 0x00000001) +#define TMR_TMR16B0IR_MR1_MASK ((unsigned int) 0x00000002) // Interrupt flag for match channel 1 +#define TMR_TMR16B0IR_MR1 ((unsigned int) 0x00000002) +#define TMR_TMR16B0IR_MR2_MASK ((unsigned int) 0x00000004) // Interrupt flag for match channel 2 +#define TMR_TMR16B0IR_MR2 ((unsigned int) 0x00000004) +#define TMR_TMR16B0IR_MR3_MASK ((unsigned int) 0x00000008) // Interrupt flag for match channel 3 +#define TMR_TMR16B0IR_MR3 ((unsigned int) 0x00000008) +#define TMR_TMR16B0IR_CR0_MASK ((unsigned int) 0x00000010) // Interrupt flag for capture channel 0 event +#define TMR_TMR16B0IR_CR0 ((unsigned int) 0x00000010) +#define TMR_TMR16B0IR_MASK_ALL ((unsigned int) 0x0000001F) + +#define TMR_TMR16B0TCR_COUNTERENABLE_MASK ((unsigned int) 0x00000001) // Counter enable +#define TMR_TMR16B0TCR_COUNTERENABLE_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR16B0TCR_COUNTERENABLE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0TCR_COUNTERRESET_MASK ((unsigned int) 0x00000002) +#define TMR_TMR16B0TCR_COUNTERRESET_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR16B0TCR_COUNTERRESET_DISABLED ((unsigned int) 0x00000002) + +#define TMR_TMR16B0MCR_MR0_INT_MASK ((unsigned int) 0x00000001) // Interrupt on MRO +#define TMR_TMR16B0MCR_MR0_INT_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR16B0MCR_MR0_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR0_RESET_MASK ((unsigned int) 0x00000002) // Reset on MR0 +#define TMR_TMR16B0MCR_MR0_RESET_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR16B0MCR_MR0_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR0_STOP_MASK ((unsigned int) 0x00000004) // Stop on MR0 +#define TMR_TMR16B0MCR_MR0_STOP_ENABLED ((unsigned int) 0x00000004) +#define TMR_TMR16B0MCR_MR0_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR1_INT_MASK ((unsigned int) 0x00000008) // Interrupt on MR1 +#define TMR_TMR16B0MCR_MR1_INT_ENABLED ((unsigned int) 0x00000008) +#define TMR_TMR16B0MCR_MR1_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR1_RESET_MASK ((unsigned int) 0x00000010) // Reset on MR1 +#define TMR_TMR16B0MCR_MR1_RESET_ENABLED ((unsigned int) 0x00000010) +#define TMR_TMR16B0MCR_MR1_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR1_STOP_MASK ((unsigned int) 0x00000020) // Stop on MR1 +#define TMR_TMR16B0MCR_MR1_STOP_ENABLED ((unsigned int) 0x00000020) +#define TMR_TMR16B0MCR_MR1_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR2_INT_MASK ((unsigned int) 0x00000040) // Interrupt on MR2 +#define TMR_TMR16B0MCR_MR2_INT_ENABLED ((unsigned int) 0x00000040) +#define TMR_TMR16B0MCR_MR2_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR2_RESET_MASK ((unsigned int) 0x00000080) // Reset on MR2 +#define TMR_TMR16B0MCR_MR2_RESET_ENABLED ((unsigned int) 0x00000080) +#define TMR_TMR16B0MCR_MR2_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR2_STOP_MASK ((unsigned int) 0x00000100) // Stop on MR2 +#define TMR_TMR16B0MCR_MR2_STOP_ENABLED ((unsigned int) 0x00000100) +#define TMR_TMR16B0MCR_MR2_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR3_INT_MASK ((unsigned int) 0x00000200) // Interrupt on MR3 +#define TMR_TMR16B0MCR_MR3_INT_ENABLED ((unsigned int) 0x00000200) +#define TMR_TMR16B0MCR_MR3_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR3_RESET_MASK ((unsigned int) 0x00000400) // Reset on MR3 +#define TMR_TMR16B0MCR_MR3_RESET_ENABLED ((unsigned int) 0x00000400) +#define TMR_TMR16B0MCR_MR3_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0MCR_MR3_STOP_MASK ((unsigned int) 0x00000800) // Stop on MR3 +#define TMR_TMR16B0MCR_MR3_STOP_ENABLED ((unsigned int) 0x00000800) +#define TMR_TMR16B0MCR_MR3_STOP_DISABLED ((unsigned int) 0x00000000) + +#define TMR_TMR16B0CCR_CAP0RE_MASK ((unsigned int) 0x00000001) // Capture on rising edge +#define TMR_TMR16B0CCR_CAP0RE_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR16B0CCR_CAP0RE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0CCR_CAP0FE_MASK ((unsigned int) 0x00000002) // Capture on falling edge +#define TMR_TMR16B0CCR_CAP0FE_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR16B0CCR_CAP0FE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0CCR_CAP0I_MASK ((unsigned int) 0x00000004) // Interrupt on CAP0 event +#define TMR_TMR16B0CCR_CAP0I_ENABLED ((unsigned int) 0x00000004) +#define TMR_TMR16B0CCR_CAP0I_DISABLED ((unsigned int) 0x00000000) + +#define TMR_TMR16B0EMR_EM0_MASK ((unsigned int) 0x00000001) // External match 0 +#define TMR_TMR16B0EMR_EM0 ((unsigned int) 0x00000001) +#define TMR_TMR16B0EMR_EMC0_MASK ((unsigned int) 0x00000030) +#define TMR_TMR16B0EMR_EMC0_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR16B0EMR_EMC0_LOW ((unsigned int) 0x00000010) +#define TMR_TMR16B0EMR_EMC0_HIGH ((unsigned int) 0x00000020) +#define TMR_TMR16B0EMR_EMC0_TOGGLE ((unsigned int) 0x00000030) +#define TMR_TMR16B0EMR_EM1_MASK ((unsigned int) 0x00000002) // External match 1 +#define TMR_TMR16B0EMR_EM1 ((unsigned int) 0x00000002) +#define TMR_TMR16B0EMR_EMC1_MASK ((unsigned int) 0x000000C0) +#define TMR_TMR16B0EMR_EMC1_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR16B0EMR_EMC1_LOW ((unsigned int) 0x00000040) +#define TMR_TMR16B0EMR_EMC1_HIGH ((unsigned int) 0x00000080) +#define TMR_TMR16B0EMR_EMC1_TOGGLE ((unsigned int) 0x000000C0) +#define TMR_TMR16B0EMR_EM2_MASK ((unsigned int) 0x00000004) // External match 2 +#define TMR_TMR16B0EMR_EM2 ((unsigned int) 0x00000004) +#define TMR_TMR16B0EMR_EMC2_MASK ((unsigned int) 0x00000300) +#define TMR_TMR16B0EMR_EMC2_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR16B0EMR_EMC2_LOW ((unsigned int) 0x00000100) +#define TMR_TMR16B0EMR_EMC2_HIGH ((unsigned int) 0x00000200) +#define TMR_TMR16B0EMR_EMC2_TOGGLE ((unsigned int) 0x00000300) +#define TMR_TMR16B0EMR_EM3_MASK ((unsigned int) 0x00000008) // External match 3 +#define TMR_TMR16B0EMR_EM3 ((unsigned int) 0x00000008) +#define TMR_TMR16B0EMR_EMC3_MASK ((unsigned int) 0x00000C00) +#define TMR_TMR16B0EMR_EMC3_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR16B0EMR_EMC3_LOW ((unsigned int) 0x00000400) +#define TMR_TMR16B0EMR_EMC3_HIGH ((unsigned int) 0x00000800) +#define TMR_TMR16B0EMR_EMC3_TOGGLE ((unsigned int) 0x00000C00) + +#define TMR_TMR16B0CTCR_CTMODE_MASK ((unsigned int) 0x00000003) // Counter/Timer mode +#define TMR_TMR16B0CTCR_CTMODE_TIMER ((unsigned int) 0x00000000) // Timer Mode: Every rising PCLK edge +#define TMR_TMR16B0CTCR_CTMODE_COUNTERRISING ((unsigned int) 0x00000001) // Counter: TC increments on rising edge of input +#define TMR_TMR16B0CTCR_CTMODE_COUNTERFALLING ((unsigned int) 0x00000002) // Counter: TC increments on falling edge of input +#define TMR_TMR16B0CTCR_CTMODE_COUNTERBOTH ((unsigned int) 0x00000003) // Counter: TC increments on both edges of input +#define TMR_TMR16B0CTCR_CINPUTSELECT_MASK ((unsigned int) 0x0000000C) +#define TMR_TMR16B0CTCR_CINPUTSELECT ((unsigned int) 0x00000000) // CINPUTSELECT must be set to 00 + +#define TMR_TMR16B0PWMC_PWM0_MASK ((unsigned int) 0x00000001) +#define TMR_TMR16B0PWMC_PWM0_ENABLED ((unsigned int) 0x00000001) // PWM mode is enabled for CT16Bn_MAT0 +#define TMR_TMR16B0PWMC_PWM0_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0PWMC_PWM1_MASK ((unsigned int) 0x00000002) +#define TMR_TMR16B0PWMC_PWM1_ENABLED ((unsigned int) 0x00000002) // PWM mode is enabled for CT16Bn_MAT1 +#define TMR_TMR16B0PWMC_PWM1_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0PWMC_PWM2_MASK ((unsigned int) 0x00000004) +#define TMR_TMR16B0PWMC_PWM2_ENABLED ((unsigned int) 0x00000004) // PWM mode is enabled for CT16Bn_MAT2 +#define TMR_TMR16B0PWMC_PWM2_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B0PWMC_PWM3_MASK ((unsigned int) 0x00000008) +#define TMR_TMR16B0PWMC_PWM3_ENABLED ((unsigned int) 0x00000008) +#define TMR_TMR16B0PWMC_PWM3_DISABLED ((unsigned int) 0x00000000) + +#define TMR_CT16B1_BASE_ADDRESS (0x40010000) + +#define TMR_TMR16B1IR (*(pREG32 (0x40010000))) // Interrupt register +#define TMR_TMR16B1TCR (*(pREG32 (0x40010004))) // Timer control register +#define TMR_TMR16B1TC (*(pREG32 (0x40010008))) // Timer counter +#define TMR_TMR16B1PR (*(pREG32 (0x4001000C))) // Prescale register +#define TMR_TMR16B1PC (*(pREG32 (0x40010010))) // Prescale counter register +#define TMR_TMR16B1MCR (*(pREG32 (0x40010014))) // Match control register +#define TMR_TMR16B1MR0 (*(pREG32 (0x40010018))) // Match register 0 +#define TMR_TMR16B1MR1 (*(pREG32 (0x4001001C))) // Match register 1 +#define TMR_TMR16B1MR2 (*(pREG32 (0x40010020))) // Match register 2 +#define TMR_TMR16B1MR3 (*(pREG32 (0x40010024))) // Match register 3 +#define TMR_TMR16B1CCR (*(pREG32 (0x40010028))) // Capture control register +#define TMR_TMR16B1CR0 (*(pREG32 (0x4001002C))) // Capture register +#define TMR_TMR16B1EMR (*(pREG32 (0x4001003C))) // External match register +#define TMR_TMR16B1CTCR (*(pREG32 (0x40010070))) // Count control register +#define TMR_TMR16B1PWMC (*(pREG32 (0x40010074))) // PWM control register + +#define TMR_TMR16B1IR_MR0_MASK ((unsigned int) 0x00000001) // Interrupt flag for match channel 0 +#define TMR_TMR16B1IR_MR0 ((unsigned int) 0x00000001) +#define TMR_TMR16B1IR_MR1_MASK ((unsigned int) 0x00000002) // Interrupt flag for match channel 1 +#define TMR_TMR16B1IR_MR1 ((unsigned int) 0x00000002) +#define TMR_TMR16B1IR_MR2_MASK ((unsigned int) 0x00000004) // Interrupt flag for match channel 2 +#define TMR_TMR16B1IR_MR2 ((unsigned int) 0x00000004) +#define TMR_TMR16B1IR_MR3_MASK ((unsigned int) 0x00000008) // Interrupt flag for match channel 3 +#define TMR_TMR16B1IR_MR3 ((unsigned int) 0x00000008) +#define TMR_TMR16B1IR_CR0_MASK ((unsigned int) 0x00000010) // Interrupt flag for capture channel 0 event +#define TMR_TMR16B1IR_CR0 ((unsigned int) 0x00000010) +#define TMR_TMR16B1IR_MASK_ALL ((unsigned int) 0x0000001F) + +#define TMR_TMR16B1TCR_COUNTERENABLE_MASK ((unsigned int) 0x00000001) // Counter enable +#define TMR_TMR16B1TCR_COUNTERENABLE_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR16B1TCR_COUNTERENABLE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1TCR_COUNTERRESET_MASK ((unsigned int) 0x00000002) +#define TMR_TMR16B1TCR_COUNTERRESET_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR16B1TCR_COUNTERRESET_DISABLED ((unsigned int) 0x00000002) + +#define TMR_TMR16B1MCR_MR0_INT_MASK ((unsigned int) 0x00000001) // Interrupt on MRO +#define TMR_TMR16B1MCR_MR0_INT_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR16B1MCR_MR0_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR0_RESET_MASK ((unsigned int) 0x00000002) // Reset on MR0 +#define TMR_TMR16B1MCR_MR0_RESET_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR16B1MCR_MR0_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR0_STOP_MASK ((unsigned int) 0x00000004) // Stop on MR0 +#define TMR_TMR16B1MCR_MR0_STOP_ENABLED ((unsigned int) 0x00000004) +#define TMR_TMR16B1MCR_MR0_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR1_INT_MASK ((unsigned int) 0x00000008) // Interrupt on MR1 +#define TMR_TMR16B1MCR_MR1_INT_ENABLED ((unsigned int) 0x00000008) +#define TMR_TMR16B1MCR_MR1_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR1_RESET_MASK ((unsigned int) 0x00000010) // Reset on MR1 +#define TMR_TMR16B1MCR_MR1_RESET_ENABLED ((unsigned int) 0x00000010) +#define TMR_TMR16B1MCR_MR1_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR1_STOP_MASK ((unsigned int) 0x00000020) // Stop on MR1 +#define TMR_TMR16B1MCR_MR1_STOP_ENABLED ((unsigned int) 0x00000020) +#define TMR_TMR16B1MCR_MR1_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR2_INT_MASK ((unsigned int) 0x00000040) // Interrupt on MR2 +#define TMR_TMR16B1MCR_MR2_INT_ENABLED ((unsigned int) 0x00000040) +#define TMR_TMR16B1MCR_MR2_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR2_RESET_MASK ((unsigned int) 0x00000080) // Reset on MR2 +#define TMR_TMR16B1MCR_MR2_RESET_ENABLED ((unsigned int) 0x00000080) +#define TMR_TMR16B1MCR_MR2_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR2_STOP_MASK ((unsigned int) 0x00000100) // Stop on MR2 +#define TMR_TMR16B1MCR_MR2_STOP_ENABLED ((unsigned int) 0x00000100) +#define TMR_TMR16B1MCR_MR2_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR3_INT_MASK ((unsigned int) 0x00000200) // Interrupt on MR3 +#define TMR_TMR16B1MCR_MR3_INT_ENABLED ((unsigned int) 0x00000200) +#define TMR_TMR16B1MCR_MR3_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR3_RESET_MASK ((unsigned int) 0x00000400) // Reset on MR3 +#define TMR_TMR16B1MCR_MR3_RESET_ENABLED ((unsigned int) 0x00000400) +#define TMR_TMR16B1MCR_MR3_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1MCR_MR3_STOP_MASK ((unsigned int) 0x00000800) // Stop on MR3 +#define TMR_TMR16B1MCR_MR3_STOP_ENABLED ((unsigned int) 0x00000800) +#define TMR_TMR16B1MCR_MR3_STOP_DISABLED ((unsigned int) 0x00000000) + +#define TMR_TMR16B1CCR_CAP0RE_MASK ((unsigned int) 0x00000001) // Capture on rising edge +#define TMR_TMR16B1CCR_CAP0RE_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR16B1CCR_CAP0RE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1CCR_CAP0FE_MASK ((unsigned int) 0x00000002) // Capture on falling edge +#define TMR_TMR16B1CCR_CAP0FE_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR16B1CCR_CAP0FE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1CCR_CAP0I_MASK ((unsigned int) 0x00000004) // Interrupt on CAP0 event +#define TMR_TMR16B1CCR_CAP0I_ENABLED ((unsigned int) 0x00000004) +#define TMR_TMR16B1CCR_CAP0I_DISABLED ((unsigned int) 0x00000000) + +#define TMR_TMR16B1EMR_EM0_MASK ((unsigned int) 0x00000001) // External match 0 +#define TMR_TMR16B1EMR_EM0 ((unsigned int) 0x00000001) +#define TMR_TMR16B1EMR_EMC0_MASK ((unsigned int) 0x00000030) +#define TMR_TMR16B1EMR_EMC0_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR16B1EMR_EMC0_LOW ((unsigned int) 0x00000010) +#define TMR_TMR16B1EMR_EMC0_HIGH ((unsigned int) 0x00000020) +#define TMR_TMR16B1EMR_EMC0_TOGGLE ((unsigned int) 0x00000030) +#define TMR_TMR16B1EMR_EM1_MASK ((unsigned int) 0x00000002) // External match 1 +#define TMR_TMR16B1EMR_EM1 ((unsigned int) 0x00000002) +#define TMR_TMR16B1EMR_EMC1_MASK ((unsigned int) 0x000000C0) +#define TMR_TMR16B1EMR_EMC1_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR16B1EMR_EMC1_LOW ((unsigned int) 0x00000040) +#define TMR_TMR16B1EMR_EMC1_HIGH ((unsigned int) 0x00000080) +#define TMR_TMR16B1EMR_EMC1_TOGGLE ((unsigned int) 0x000000C0) +#define TMR_TMR16B1EMR_EM2_MASK ((unsigned int) 0x00000004) // External match 2 +#define TMR_TMR16B1EMR_EM2 ((unsigned int) 0x00000004) +#define TMR_TMR16B1EMR_EMC2_MASK ((unsigned int) 0x00000300) +#define TMR_TMR16B1EMR_EMC2_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR16B1EMR_EMC2_LOW ((unsigned int) 0x00000100) +#define TMR_TMR16B1EMR_EMC2_HIGH ((unsigned int) 0x00000200) +#define TMR_TMR16B1EMR_EMC2_TOGGLE ((unsigned int) 0x00000300) +#define TMR_TMR16B1EMR_EM3_MASK ((unsigned int) 0x00000008) // External match 3 +#define TMR_TMR16B1EMR_EM3 ((unsigned int) 0x00000008) +#define TMR_TMR16B1EMR_EMC3_MASK ((unsigned int) 0x00000C00) +#define TMR_TMR16B1EMR_EMC3_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR16B1EMR_EMC3_LOW ((unsigned int) 0x00000400) +#define TMR_TMR16B1EMR_EMC3_HIGH ((unsigned int) 0x00000800) +#define TMR_TMR16B1EMR_EMC3_TOGGLE ((unsigned int) 0x00000C00) + +#define TMR_TMR16B1CTCR_CTMODE_MASK ((unsigned int) 0x00000003) // Counter/Timer mode +#define TMR_TMR16B1CTCR_CTMODE_TIMER ((unsigned int) 0x00000000) // Timer Mode: Every rising PCLK edge +#define TMR_TMR16B1CTCR_CTMODE_COUNTERRISING ((unsigned int) 0x00000001) // Counter: TC increments on rising edge of input +#define TMR_TMR16B1CTCR_CTMODE_COUNTERFALLING ((unsigned int) 0x00000002) // Counter: TC increments on falling edge of input +#define TMR_TMR16B1CTCR_CTMODE_COUNTERBOTH ((unsigned int) 0x00000003) // Counter: TC increments on both edges of input +#define TMR_TMR16B1CTCR_CINPUTSELECT_MASK ((unsigned int) 0x0000000C) +#define TMR_TMR16B1CTCR_CINPUTSELECT ((unsigned int) 0x00000000) // CINPUTSELECT must be set to 00 + +#define TMR_TMR16B1PWMC_PWM0_MASK ((unsigned int) 0x00000001) +#define TMR_TMR16B1PWMC_PWM0_ENABLED ((unsigned int) 0x00000001) // PWM mode is enabled for CT16Bn_MAT0 +#define TMR_TMR16B1PWMC_PWM0_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1PWMC_PWM1_MASK ((unsigned int) 0x00000002) +#define TMR_TMR16B1PWMC_PWM1_ENABLED ((unsigned int) 0x00000002) // PWM mode is enabled for CT16Bn_MAT1 +#define TMR_TMR16B1PWMC_PWM1_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1PWMC_PWM2_MASK ((unsigned int) 0x00000004) +#define TMR_TMR16B1PWMC_PWM2_ENABLED ((unsigned int) 0x00000004) // PWM mode is enabled for CT16Bn_MAT2 +#define TMR_TMR16B1PWMC_PWM2_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR16B1PWMC_PWM3_MASK ((unsigned int) 0x00000008) +#define TMR_TMR16B1PWMC_PWM3_ENABLED ((unsigned int) 0x00000008) +#define TMR_TMR16B1PWMC_PWM3_DISABLED ((unsigned int) 0x00000000) + +/*############################################################################## +## 32-Bit Timers (CT32B0/1) +##############################################################################*/ + +#define TMR_CT32B0_BASE_ADDRESS (0x40014000) + +#define TMR_TMR32B0IR (*(pREG32 (0x40014000))) // Interrupt register +#define TMR_TMR32B0TCR (*(pREG32 (0x40014004))) // Timer control register +#define TMR_TMR32B0TC (*(pREG32 (0x40014008))) // Timer counter +#define TMR_TMR32B0PR (*(pREG32 (0x4001400C))) // Prescale register +#define TMR_TMR32B0PC (*(pREG32 (0x40014010))) // Prescale counter register +#define TMR_TMR32B0MCR (*(pREG32 (0x40014014))) // Match control register +#define TMR_TMR32B0MR0 (*(pREG32 (0x40014018))) // Match register 0 +#define TMR_TMR32B0MR1 (*(pREG32 (0x4001401C))) // Match register 1 +#define TMR_TMR32B0MR2 (*(pREG32 (0x40014020))) // Match register 2 +#define TMR_TMR32B0MR3 (*(pREG32 (0x40014024))) // Match register 3 +#define TMR_TMR32B0CCR (*(pREG32 (0x40014028))) // Capture control register +#define TMR_TMR32B0CR0 (*(pREG32 (0x4001402C))) // Capture register +#define TMR_TMR32B0EMR (*(pREG32 (0x4001403C))) // External match register +#define TMR_TMR32B0CTCR (*(pREG32 (0x40014070))) // Count control register +#define TMR_TMR32B0PWMC (*(pREG32 (0x40014074))) // PWM control register + +#define TMR_TMR32B0IR_MR0_MASK ((unsigned int) 0x00000001) // Interrupt flag for match channel 0 +#define TMR_TMR32B0IR_MR0 ((unsigned int) 0x00000001) +#define TMR_TMR32B0IR_MR1_MASK ((unsigned int) 0x00000002) // Interrupt flag for match channel 1 +#define TMR_TMR32B0IR_MR1 ((unsigned int) 0x00000002) +#define TMR_TMR32B0IR_MR2_MASK ((unsigned int) 0x00000004) // Interrupt flag for match channel 2 +#define TMR_TMR32B0IR_MR2 ((unsigned int) 0x00000004) +#define TMR_TMR32B0IR_MR3_MASK ((unsigned int) 0x00000008) // Interrupt flag for match channel 3 +#define TMR_TMR32B0IR_MR3 ((unsigned int) 0x00000008) +#define TMR_TMR32B0IR_CR0_MASK ((unsigned int) 0x00000010) // Interrupt flag for capture channel 0 event +#define TMR_TMR32B0IR_CR0 ((unsigned int) 0x00000010) +#define TMR_TMR32B0IR_MASK_ALL ((unsigned int) 0x0000001F) + +#define TMR_TMR32B0TCR_COUNTERENABLE_MASK ((unsigned int) 0x00000001) // Counter enable +#define TMR_TMR32B0TCR_COUNTERENABLE_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR32B0TCR_COUNTERENABLE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0TCR_COUNTERRESET_MASK ((unsigned int) 0x00000002) +#define TMR_TMR32B0TCR_COUNTERRESET_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR32B0TCR_COUNTERRESET_DISABLED ((unsigned int) 0x00000002) + +#define TMR_TMR32B0MCR_MR0_INT_MASK ((unsigned int) 0x00000001) // Interrupt on MRO +#define TMR_TMR32B0MCR_MR0_INT_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR32B0MCR_MR0_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR0_RESET_MASK ((unsigned int) 0x00000002) // Reset on MR0 +#define TMR_TMR32B0MCR_MR0_RESET_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR32B0MCR_MR0_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR0_STOP_MASK ((unsigned int) 0x00000004) // Stop on MR0 +#define TMR_TMR32B0MCR_MR0_STOP_ENABLED ((unsigned int) 0x00000004) +#define TMR_TMR32B0MCR_MR0_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR1_INT_MASK ((unsigned int) 0x00000008) // Interrupt on MR1 +#define TMR_TMR32B0MCR_MR1_INT_ENABLED ((unsigned int) 0x00000008) +#define TMR_TMR32B0MCR_MR1_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR1_RESET_MASK ((unsigned int) 0x00000010) // Reset on MR1 +#define TMR_TMR32B0MCR_MR1_RESET_ENABLED ((unsigned int) 0x00000010) +#define TMR_TMR32B0MCR_MR1_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR1_STOP_MASK ((unsigned int) 0x00000020) // Stop on MR1 +#define TMR_TMR32B0MCR_MR1_STOP_ENABLED ((unsigned int) 0x00000020) +#define TMR_TMR32B0MCR_MR1_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR2_INT_MASK ((unsigned int) 0x00000040) // Interrupt on MR2 +#define TMR_TMR32B0MCR_MR2_INT_ENABLED ((unsigned int) 0x00000040) +#define TMR_TMR32B0MCR_MR2_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR2_RESET_MASK ((unsigned int) 0x00000080) // Reset on MR2 +#define TMR_TMR32B0MCR_MR2_RESET_ENABLED ((unsigned int) 0x00000080) +#define TMR_TMR32B0MCR_MR2_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR2_STOP_MASK ((unsigned int) 0x00000100) // Stop on MR2 +#define TMR_TMR32B0MCR_MR2_STOP_ENABLED ((unsigned int) 0x00000100) +#define TMR_TMR32B0MCR_MR2_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR3_INT_MASK ((unsigned int) 0x00000200) // Interrupt on MR3 +#define TMR_TMR32B0MCR_MR3_INT_ENABLED ((unsigned int) 0x00000200) +#define TMR_TMR32B0MCR_MR3_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR3_RESET_MASK ((unsigned int) 0x00000400) // Reset on MR3 +#define TMR_TMR32B0MCR_MR3_RESET_ENABLED ((unsigned int) 0x00000400) +#define TMR_TMR32B0MCR_MR3_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0MCR_MR3_STOP_MASK ((unsigned int) 0x00000800) // Stop on MR3 +#define TMR_TMR32B0MCR_MR3_STOP_ENABLED ((unsigned int) 0x00000800) +#define TMR_TMR32B0MCR_MR3_STOP_DISABLED ((unsigned int) 0x00000000) + +#define TMR_TMR32B0CCR_CAP0RE_MASK ((unsigned int) 0x00000001) // Capture on rising edge +#define TMR_TMR32B0CCR_CAP0RE_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR32B0CCR_CAP0RE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0CCR_CAP0FE_MASK ((unsigned int) 0x00000002) // Capture on falling edge +#define TMR_TMR32B0CCR_CAP0FE_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR32B0CCR_CAP0FE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0CCR_CAP0I_MASK ((unsigned int) 0x00000004) // Interrupt on CAP0 event +#define TMR_TMR32B0CCR_CAP0I_ENABLED ((unsigned int) 0x00000004) +#define TMR_TMR32B0CCR_CAP0I_DISABLED ((unsigned int) 0x00000000) + +#define TMR_TMR32B0EMR_EM0_MASK ((unsigned int) 0x00000001) // External match 0 +#define TMR_TMR32B0EMR_EM0 ((unsigned int) 0x00000001) +#define TMR_TMR32B0EMR_EMC0_MASK ((unsigned int) 0x00000030) +#define TMR_TMR32B0EMR_EMC0_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR32B0EMR_EMC0_LOW ((unsigned int) 0x00000010) +#define TMR_TMR32B0EMR_EMC0_HIGH ((unsigned int) 0x00000020) +#define TMR_TMR32B0EMR_EMC0_TOGGLE ((unsigned int) 0x00000030) +#define TMR_TMR32B0EMR_EM1_MASK ((unsigned int) 0x00000002) // External match 1 +#define TMR_TMR32B0EMR_EM1 ((unsigned int) 0x00000002) +#define TMR_TMR32B0EMR_EMC1_MASK ((unsigned int) 0x000000C0) +#define TMR_TMR32B0EMR_EMC1_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR32B0EMR_EMC1_LOW ((unsigned int) 0x00000040) +#define TMR_TMR32B0EMR_EMC1_HIGH ((unsigned int) 0x00000080) +#define TMR_TMR32B0EMR_EMC1_TOGGLE ((unsigned int) 0x000000C0) +#define TMR_TMR32B0EMR_EM2_MASK ((unsigned int) 0x00000004) // External match 2 +#define TMR_TMR32B0EMR_EM2 ((unsigned int) 0x00000004) +#define TMR_TMR32B0EMR_EMC2_MASK ((unsigned int) 0x00000300) +#define TMR_TMR32B0EMR_EMC2_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR32B0EMR_EMC2_LOW ((unsigned int) 0x00000100) +#define TMR_TMR32B0EMR_EMC2_HIGH ((unsigned int) 0x00000200) +#define TMR_TMR32B0EMR_EMC2_TOGGLE ((unsigned int) 0x00000300) +#define TMR_TMR32B0EMR_EM3_MASK ((unsigned int) 0x00000008) // External match 3 +#define TMR_TMR32B0EMR_EM3 ((unsigned int) 0x00000008) +#define TMR_TMR32B0EMR_EMC3_MASK ((unsigned int) 0x00000C00) +#define TMR_TMR32B0EMR_EMC3_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR32B0EMR_EMC3_LOW ((unsigned int) 0x00000400) +#define TMR_TMR32B0EMR_EMC3_HIGH ((unsigned int) 0x00000800) +#define TMR_TMR32B0EMR_EMC3_TOGGLE ((unsigned int) 0x00000C00) + +#define TMR_TMR32B0CTCR_CTMODE_MASK ((unsigned int) 0x00000003) // Counter/Timer mode +#define TMR_TMR32B0CTCR_CTMODE_TIMER ((unsigned int) 0x00000000) // Timer Mode: Every rising PCLK edge +#define TMR_TMR32B0CTCR_CTMODE_COUNTERRISING ((unsigned int) 0x00000001) // Counter: TC increments on rising edge of input +#define TMR_TMR32B0CTCR_CTMODE_COUNTERFALLING ((unsigned int) 0x00000002) // Counter: TC increments on falling edge of input +#define TMR_TMR32B0CTCR_CTMODE_COUNTERBOTH ((unsigned int) 0x00000003) // Counter: TC increments on both edges of input +#define TMR_TMR32B0CTCR_CINPUTSELECT_MASK ((unsigned int) 0x0000000C) +#define TMR_TMR32B0CTCR_CINPUTSELECT ((unsigned int) 0x00000000) // CINPUTSELECT must be set to 00 + +#define TMR_TMR32B0PWMC_PWM0_MASK ((unsigned int) 0x00000001) +#define TMR_TMR32B0PWMC_PWM0_ENABLED ((unsigned int) 0x00000001) // PWM mode is enabled for CT32Bn_MAT0 +#define TMR_TMR32B0PWMC_PWM0_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0PWMC_PWM1_MASK ((unsigned int) 0x00000002) +#define TMR_TMR32B0PWMC_PWM1_ENABLED ((unsigned int) 0x00000002) // PWM mode is enabled for CT32Bn_MAT1 +#define TMR_TMR32B0PWMC_PWM1_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0PWMC_PWM2_MASK ((unsigned int) 0x00000004) +#define TMR_TMR32B0PWMC_PWM2_ENABLED ((unsigned int) 0x00000004) // PWM mode is enabled for CT32Bn_MAT2 +#define TMR_TMR32B0PWMC_PWM2_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B0PWMC_PWM3_MASK ((unsigned int) 0x00000008) +#define TMR_TMR32B0PWMC_PWM3_ENABLED ((unsigned int) 0x00000008) // PWM mode is enabled for CT32Bn_MAT3 +#define TMR_TMR32B0PWMC_PWM3_DISABLED ((unsigned int) 0x00000000) + +#define TMR_CT32B1_BASE_ADDRESS (0x40018000) + +#define TMR_TMR32B1IR (*(pREG32 (0x40018000))) // Interrupt register +#define TMR_TMR32B1TCR (*(pREG32 (0x40018004))) // Timer control register +#define TMR_TMR32B1TC (*(pREG32 (0x40018008))) // Timer counter +#define TMR_TMR32B1PR (*(pREG32 (0x4001800C))) // Prescale register +#define TMR_TMR32B1PC (*(pREG32 (0x40018010))) // Prescale counter register +#define TMR_TMR32B1MCR (*(pREG32 (0x40018014))) // Match control register +#define TMR_TMR32B1MR0 (*(pREG32 (0x40018018))) // Match register 0 +#define TMR_TMR32B1MR1 (*(pREG32 (0x4001801C))) // Match register 1 +#define TMR_TMR32B1MR2 (*(pREG32 (0x40018020))) // Match register 2 +#define TMR_TMR32B1MR3 (*(pREG32 (0x40018024))) // Match register 3 +#define TMR_TMR32B1CCR (*(pREG32 (0x40018028))) // Capture control register +#define TMR_TMR32B1CR0 (*(pREG32 (0x4001802C))) // Capture register +#define TMR_TMR32B1EMR (*(pREG32 (0x4001803C))) // External match register +#define TMR_TMR32B1CTCR (*(pREG32 (0x40018070))) // Count control register +#define TMR_TMR32B1PWMC (*(pREG32 (0x40018074))) // PWM control register + +#define TMR_TMR32B1IR_MR0_MASK ((unsigned int) 0x00000001) // Interrupt flag for match channel 0 +#define TMR_TMR32B1IR_MR0 ((unsigned int) 0x00000001) +#define TMR_TMR32B1IR_MR1_MASK ((unsigned int) 0x00000002) // Interrupt flag for match channel 1 +#define TMR_TMR32B1IR_MR1 ((unsigned int) 0x00000002) +#define TMR_TMR32B1IR_MR2_MASK ((unsigned int) 0x00000004) // Interrupt flag for match channel 2 +#define TMR_TMR32B1IR_MR2 ((unsigned int) 0x00000004) +#define TMR_TMR32B1IR_MR3_MASK ((unsigned int) 0x00000008) // Interrupt flag for match channel 3 +#define TMR_TMR32B1IR_MR3 ((unsigned int) 0x00000008) +#define TMR_TMR32B1IR_CR0_MASK ((unsigned int) 0x00000010) // Interrupt flag for capture channel 0 event +#define TMR_TMR32B1IR_CR0 ((unsigned int) 0x00000010) +#define TMR_TMR32B1IR_MASK_ALL ((unsigned int) 0x0000001F) + +#define TMR_TMR32B1TCR_COUNTERENABLE_MASK ((unsigned int) 0x00000001) // Counter enable +#define TMR_TMR32B1TCR_COUNTERENABLE_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR32B1TCR_COUNTERENABLE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1TCR_COUNTERRESET_MASK ((unsigned int) 0x00000002) +#define TMR_TMR32B1TCR_COUNTERRESET_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR32B1TCR_COUNTERRESET_DISABLED ((unsigned int) 0x00000002) + +#define TMR_TMR32B1MCR_MR0_INT_MASK ((unsigned int) 0x00000001) // Interrupt on MRO +#define TMR_TMR32B1MCR_MR0_INT_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR32B1MCR_MR0_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR0_RESET_MASK ((unsigned int) 0x00000002) // Reset on MR0 +#define TMR_TMR32B1MCR_MR0_RESET_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR32B1MCR_MR0_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR0_STOP_MASK ((unsigned int) 0x00000004) // Stop on MR0 +#define TMR_TMR32B1MCR_MR0_STOP_ENABLED ((unsigned int) 0x00000004) +#define TMR_TMR32B1MCR_MR0_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR1_INT_MASK ((unsigned int) 0x00000008) // Interrupt on MR1 +#define TMR_TMR32B1MCR_MR1_INT_ENABLED ((unsigned int) 0x00000008) +#define TMR_TMR32B1MCR_MR1_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR1_RESET_MASK ((unsigned int) 0x00000010) // Reset on MR1 +#define TMR_TMR32B1MCR_MR1_RESET_ENABLED ((unsigned int) 0x00000010) +#define TMR_TMR32B1MCR_MR1_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR1_STOP_MASK ((unsigned int) 0x00000020) // Stop on MR1 +#define TMR_TMR32B1MCR_MR1_STOP_ENABLED ((unsigned int) 0x00000020) +#define TMR_TMR32B1MCR_MR1_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR2_INT_MASK ((unsigned int) 0x00000040) // Interrupt on MR2 +#define TMR_TMR32B1MCR_MR2_INT_ENABLED ((unsigned int) 0x00000040) +#define TMR_TMR32B1MCR_MR2_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR2_RESET_MASK ((unsigned int) 0x00000080) // Reset on MR2 +#define TMR_TMR32B1MCR_MR2_RESET_ENABLED ((unsigned int) 0x00000080) +#define TMR_TMR32B1MCR_MR2_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR2_STOP_MASK ((unsigned int) 0x00000100) // Stop on MR2 +#define TMR_TMR32B1MCR_MR2_STOP_ENABLED ((unsigned int) 0x00000100) +#define TMR_TMR32B1MCR_MR2_STOP_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR3_INT_MASK ((unsigned int) 0x00000200) // Interrupt on MR3 +#define TMR_TMR32B1MCR_MR3_INT_ENABLED ((unsigned int) 0x00000200) +#define TMR_TMR32B1MCR_MR3_INT_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR3_RESET_MASK ((unsigned int) 0x00000400) // Reset on MR3 +#define TMR_TMR32B1MCR_MR3_RESET_ENABLED ((unsigned int) 0x00000400) +#define TMR_TMR32B1MCR_MR3_RESET_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1MCR_MR3_STOP_MASK ((unsigned int) 0x00000800) // Stop on MR3 +#define TMR_TMR32B1MCR_MR3_STOP_ENABLED ((unsigned int) 0x00000800) +#define TMR_TMR32B1MCR_MR3_STOP_DISABLED ((unsigned int) 0x00000000) + +#define TMR_TMR32B1CCR_CAP0RE_MASK ((unsigned int) 0x00000001) // Capture on rising edge +#define TMR_TMR32B1CCR_CAP0RE_ENABLED ((unsigned int) 0x00000001) +#define TMR_TMR32B1CCR_CAP0RE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1CCR_CAP0FE_MASK ((unsigned int) 0x00000002) // Capture on falling edge +#define TMR_TMR32B1CCR_CAP0FE_ENABLED ((unsigned int) 0x00000002) +#define TMR_TMR32B1CCR_CAP0FE_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1CCR_CAP0I_MASK ((unsigned int) 0x00000004) // Interrupt on CAP0 event +#define TMR_TMR32B1CCR_CAP0I_ENABLED ((unsigned int) 0x00000004) +#define TMR_TMR32B1CCR_CAP0I_DISABLED ((unsigned int) 0x00000000) + +#define TMR_TMR32B1EMR_EM0_MASK ((unsigned int) 0x00000001) // External match 0 +#define TMR_TMR32B1EMR_EM0 ((unsigned int) 0x00000001) +#define TMR_TMR32B1EMR_EMC0_MASK ((unsigned int) 0x00000030) +#define TMR_TMR32B1EMR_EMC0_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR32B1EMR_EMC0_LOW ((unsigned int) 0x00000010) +#define TMR_TMR32B1EMR_EMC0_HIGH ((unsigned int) 0x00000020) +#define TMR_TMR32B1EMR_EMC0_TOGGLE ((unsigned int) 0x00000030) +#define TMR_TMR32B1EMR_EM1_MASK ((unsigned int) 0x00000002) // External match 1 +#define TMR_TMR32B1EMR_EM1 ((unsigned int) 0x00000002) +#define TMR_TMR32B1EMR_EMC1_MASK ((unsigned int) 0x000000C0) +#define TMR_TMR32B1EMR_EMC1_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR32B1EMR_EMC1_LOW ((unsigned int) 0x00000040) +#define TMR_TMR32B1EMR_EMC1_HIGH ((unsigned int) 0x00000080) +#define TMR_TMR32B1EMR_EMC1_TOGGLE ((unsigned int) 0x000000C0) +#define TMR_TMR32B1EMR_EM2_MASK ((unsigned int) 0x00000004) // External match 2 +#define TMR_TMR32B1EMR_EM2 ((unsigned int) 0x00000004) +#define TMR_TMR32B1EMR_EMC2_MASK ((unsigned int) 0x00000300) +#define TMR_TMR32B1EMR_EMC2_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR32B1EMR_EMC2_LOW ((unsigned int) 0x00000100) +#define TMR_TMR32B1EMR_EMC2_HIGH ((unsigned int) 0x00000200) +#define TMR_TMR32B1EMR_EMC2_TOGGLE ((unsigned int) 0x00000300) +#define TMR_TMR32B1EMR_EM3_MASK ((unsigned int) 0x00000008) // External match 3 +#define TMR_TMR32B1EMR_EM3 ((unsigned int) 0x00000008) +#define TMR_TMR32B1EMR_EMC3_MASK ((unsigned int) 0x00000C00) +#define TMR_TMR32B1EMR_EMC3_DONOTHING ((unsigned int) 0x00000000) +#define TMR_TMR32B1EMR_EMC3_LOW ((unsigned int) 0x00000400) +#define TMR_TMR32B1EMR_EMC3_HIGH ((unsigned int) 0x00000800) +#define TMR_TMR32B1EMR_EMC3_TOGGLE ((unsigned int) 0x00000C00) + +#define TMR_TMR32B1CTCR_CTMODE_MASK ((unsigned int) 0x00000003) // Counter/Timer mode +#define TMR_TMR32B1CTCR_CTMODE_TIMER ((unsigned int) 0x00000000) // Timer Mode: Every rising PCLK edge +#define TMR_TMR32B1CTCR_CTMODE_COUNTERRISING ((unsigned int) 0x00000001) // Counter: TC increments on rising edge of input +#define TMR_TMR32B1CTCR_CTMODE_COUNTERFALLING ((unsigned int) 0x00000002) // Counter: TC increments on falling edge of input +#define TMR_TMR32B1CTCR_CTMODE_COUNTERBOTH ((unsigned int) 0x00000003) // Counter: TC increments on both edges of input +#define TMR_TMR32B1CTCR_CINPUTSELECT_MASK ((unsigned int) 0x0000000C) +#define TMR_TMR32B1CTCR_CINPUTSELECT ((unsigned int) 0x00000000) // CINPUTSELECT must be set to 00 + +#define TMR_TMR32B1PWMC_PWM0_MASK ((unsigned int) 0x00000001) +#define TMR_TMR32B1PWMC_PWM0_ENABLED ((unsigned int) 0x00000001) // PWM mode is enabled for CT32Bn_MAT0 +#define TMR_TMR32B1PWMC_PWM0_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1PWMC_PWM1_MASK ((unsigned int) 0x00000002) +#define TMR_TMR32B1PWMC_PWM1_ENABLED ((unsigned int) 0x00000002) // PWM mode is enabled for CT32Bn_MAT1 +#define TMR_TMR32B1PWMC_PWM1_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1PWMC_PWM2_MASK ((unsigned int) 0x00000004) +#define TMR_TMR32B1PWMC_PWM2_ENABLED ((unsigned int) 0x00000004) // PWM mode is enabled for CT32Bn_MAT2 +#define TMR_TMR32B1PWMC_PWM2_DISABLED ((unsigned int) 0x00000000) +#define TMR_TMR32B1PWMC_PWM3_MASK ((unsigned int) 0x00000008) +#define TMR_TMR32B1PWMC_PWM3_ENABLED ((unsigned int) 0x00000008) // PWM mode is enabled for CT32Bn_MAT3 +#define TMR_TMR32B1PWMC_PWM3_DISABLED ((unsigned int) 0x00000000) + +/*############################################################################## +## System Tick Timer +##############################################################################*/ + +#define SYSTICK_BASE_ADDRESS (0xE000E000) + +#define SYSTICK_STCTRL (*(pREG32 (0xE000E010))) // System tick control +#define SYSTICK_STRELOAD (*(pREG32 (0xE000E014))) // System timer reload +#define SYSTICK_STCURR (*(pREG32 (0xE000E018))) // System timer current +#define SYSTICK_STCALIB (*(pREG32 (0xE000E01C))) // System timer calibration + +/* STCTRL (System Timer Control and status register) + The STCTRL register contains control information for the System Tick Timer, and provides + a status flag. */ + +#define SYSTICK_STCTRL_ENABLE (0x00000001) // System tick counter enable +#define SYSTICK_STCTRL_TICKINT (0x00000002) // System tick interrupt enable +#define SYSTICK_STCTRL_CLKSOURCE (0x00000004) // NOTE: This isn't documented but is based on NXP examples +#define SYSTICK_STCTRL_COUNTFLAG (0x00010000) // System tick counter flag + +/* STRELOAD (System Timer Reload value register) + The STRELOAD register is set to the value that will be loaded into the System Tick Timer + whenever it counts down to zero. This register is loaded by software as part of timer + initialization. The STCALIB register may be read and used as the value for STRELOAD if + the CPU or external clock is running at the frequency intended for use with the STCALIB + value. */ + +#define SYSTICK_STRELOAD_MASK (0x00FFFFFF) + +/* STCURR (System Timer Current value register) + The STCURR register returns the current count from the System Tick counter when it is + read by software. */ + +#define SYSTICK_STCURR_MASK (0x00FFFFFF) + +/* STCALIB (System Timer Calibration value register) */ + +#define SYSTICK_STCALIB_TENMS_MASK (0x00FFFFFF) +#define SYSTICK_STCALIB_SKEW_MASK (0x40000000) +#define SYSTICK_STCALIB_NOREF_MASK (0x80000000) + +/*############################################################################## +## ADC +##############################################################################*/ + +#define ADC_AD0_BASE_ADDRESS (0x4001C000) + +#define ADC_AD0CR (*(pREG32 (0x4001C000))) // ADC Control Register +#define ADC_AD0GDR ((unsigned int) 0x4001C004) // ADC Global Data Register +#define ADC_AD0INTEN ((unsigned int) 0x4001C00C) // ADC Interrupt Enable Register +#define ADC_AD0DR0 ((unsigned int) 0x4001C010) // ADC Data Register 0 +#define ADC_AD0DR1 ((unsigned int) 0x4001C014) // ADC Data Register 1 +#define ADC_AD0DR2 ((unsigned int) 0x4001C018) // ADC Data Register 2 +#define ADC_AD0DR3 ((unsigned int) 0x4001C01C) // ADC Data Register 3 +#define ADC_AD0DR4 ((unsigned int) 0x4001C020) // ADC Data Register 4 +#define ADC_AD0DR5 ((unsigned int) 0x4001C024) // ADC Data Register 5 +#define ADC_AD0DR6 ((unsigned int) 0x4001C028) // ADC Data Register 6 +#define ADC_AD0DR7 ((unsigned int) 0x4001C02C) // ADC Data Register 7 +#define ADC_AD0STAT ((unsigned int) 0x4001C030) // ADC Status Register + +#define ADC_AD0CR_SEL_MASK (0x000000FF) +#define ADC_AD0CR_SEL_AD0 (0x00000001) +#define ADC_AD0CR_SEL_AD1 (0x00000002) +#define ADC_AD0CR_SEL_AD2 (0x00000004) +#define ADC_AD0CR_SEL_AD3 (0x00000008) +#define ADC_AD0CR_SEL_AD4 (0x00000010) +#define ADC_AD0CR_SEL_AD5 (0x00000020) +#define ADC_AD0CR_SEL_AD6 (0x00000040) +#define ADC_AD0CR_SEL_AD7 (0x00000080) +#define ADC_AD0CR_CLKDIV_MASK (0x0000FF00) +#define ADC_AD0CR_BURST_MASK (0x00010000) +#define ADC_AD0CR_BURST_SWMODE (0x00000000) +#define ADC_AD0CR_BURST_HWSCANMODE (0x00010000) +#define ADC_AD0CR_CLKS_MASK (0x000E0000) +#define ADC_AD0CR_CLKS_10BITS (0x00000000) +#define ADC_AD0CR_CLKS_9BITS (0x00020000) +#define ADC_AD0CR_CLKS_8BITS (0x00040000) +#define ADC_AD0CR_CLKS_7BITS (0x00060000) +#define ADC_AD0CR_CLKS_6BITS (0x00080000) +#define ADC_AD0CR_CLKS_5BITS (0x000A0000) +#define ADC_AD0CR_CLKS_4BITS (0x000C0000) +#define ADC_AD0CR_CLKS_3BITS (0x000E0000) +#define ADC_AD0CR_START_MASK (0x07000000) +#define ADC_AD0CR_START_NOSTART (0x00000000) +#define ADC_AD0CR_START_STARTNOW (0x01000000) +#define ADC_AD0CR_EDGE_MASK (0x08000000) +#define ADC_AD0CR_EDGE_FALLING (0x08000000) +#define ADC_AD0CR_EDGE_RISING (0x00000000) + +/* AD9GDR (A/D Global Data Register) + The A/D Global Data Register contains the result of the most recent A/D conversion. This + includes the data, DONE, and Overrun flags, and the number of the A/D channel to which + the data relates. */ + +#define ADC_AD0GDR_RESULT_MASK (0x0000FFC0) +#define ADC_AD0GDR_CHN_MASK (0x07000000) // Channel from which the results were converted +#define ADC_AD0GDR_OVERUN_MASK (0x40000000) +#define ADC_AD0GDR_OVERUN (0x40000000) +#define ADC_AD0GDR_DONE_MASK (0x80000000) +#define ADC_AD0GDR_DONE (0x80000000) + +/* AD0STAT (A/D Status Register) + The A/D Status register allows checking the status of all A/D channels simultaneously. + The DONE and OVERRUN flags appearing in the ADDRn register for each A/D channel + are mirrored in ADSTAT. The interrupt flag (the logical OR of all DONE flags) is also found + in ADSTAT. */ + +#define ADC_AD0STAT_DONE0_MASK (0x00000001) +#define ADC_AD0STAT_DONE0 (0x00000001) +#define ADC_AD0STAT_DONE1_MASK (0x00000002) +#define ADC_AD0STAT_DONE1 (0x00000002) +#define ADC_AD0STAT_DONE2_MASK (0x00000004) +#define ADC_AD0STAT_DONE2 (0x00000004) +#define ADC_AD0STAT_DONE3_MASK (0x00000008) +#define ADC_AD0STAT_DONE3 (0x00000008) +#define ADC_AD0STAT_DONE4_MASK (0x00000010) +#define ADC_AD0STAT_DONE4 (0x00000010) +#define ADC_AD0STAT_DONE5_MASK (0x00000020) +#define ADC_AD0STAT_DONE5 (0x00000020) +#define ADC_AD0STAT_DONE6_MASK (0x00000040) +#define ADC_AD0STAT_DONE6 (0x00000040) +#define ADC_AD0STAT_DONE7_MASK (0x00000080) +#define ADC_AD0STAT_DONE7 (0x00000080) +#define ADC_AD0STAT_OVERRUN0_MASK (0x00000100) +#define ADC_AD0STAT_OVERRUN0 (0x00000100) +#define ADC_AD0STAT_OVERRUN1_MASK (0x00000200) +#define ADC_AD0STAT_OVERRUN1 (0x00000200) +#define ADC_AD0STAT_OVERRUN2_MASK (0x00000400) +#define ADC_AD0STAT_OVERRUN2 (0x00000400) +#define ADC_AD0STAT_OVERRUN3_MASK (0x00000800) +#define ADC_AD0STAT_OVERRUN3 (0x00000800) +#define ADC_AD0STAT_OVERRUN4_MASK (0x00001000) +#define ADC_AD0STAT_OVERRUN4 (0x00001000) +#define ADC_AD0STAT_OVERRUN5_MASK (0x00002000) +#define ADC_AD0STAT_OVERRUN5 (0x00002000) +#define ADC_AD0STAT_OVERRUN6_MASK (0x00004000) +#define ADC_AD0STAT_OVERRUN6 (0x00004000) +#define ADC_AD0STAT_OVERRUN7_MASK (0x00008000) +#define ADC_AD0STAT_OVERRUN7 (0x00008000) +#define ADC_AD0STAT_ADINT_MASK (0x00010000) +#define ADC_AD0STAT_ADINT (0x00010000) + +/* ADINTEN0 (A/D Interrupt Enable Register) + This register allows control over which A/D channels generate an interrupt when a + conversion is complete. For example, it may be desirable to use some A/D channels to + monitor sensors by continuously performing conversions on them. The most recent + results are read by the application program whenever they are needed. In this case, an + interrupt is not desirable at the end of each conversion for some A/D channels. */ + +#define ADC_AD0INTEN_ADINTEN0_MASK (0x00000001) +#define ADC_AD0INTEN_ADINTEN0 (0x00000001) +#define ADC_AD0INTEN_ADINTEN1_MASK (0x00000002) +#define ADC_AD0INTEN_ADINTEN1 (0x00000002) +#define ADC_AD0INTEN_ADINTEN2_MASK (0x00000004) +#define ADC_AD0INTEN_ADINTEN2 (0x00000004) +#define ADC_AD0INTEN_ADINTEN3_MASK (0x00000008) +#define ADC_AD0INTEN_ADINTEN3 (0x00000008) +#define ADC_AD0INTEN_ADINTEN4_MASK (0x00000010) +#define ADC_AD0INTEN_ADINTEN4 (0x00000010) +#define ADC_AD0INTEN_ADINTEN5_MASK (0x00000020) +#define ADC_AD0INTEN_ADINTEN5 (0x00000020) +#define ADC_AD0INTEN_ADINTEN6_MASK (0x00000040) +#define ADC_AD0INTEN_ADINTEN6 (0x00000040) +#define ADC_AD0INTEN_ADINTEN7_MASK (0x00000080) +#define ADC_AD0INTEN_ADINTEN7 (0x00000080) +#define ADC_AD0INTEN_ADGINTEN_MASK (0x00000100) +#define ADC_AD0INTEN_ADGINTEN_ENABLE (0x00000100) +#define ADC_AD0INTEN_ADGINTEN_DISABLE (0x00000000) + +/* AD0DR0..7 (A/D Data Registers) + The A/D Data Register hold the result when an A/D conversion is complete, and also + include the flags that indicate when a conversion has been completed and when a + conversion overrun has occurred. */ + +#define ADC_DR_V_MASK (0x0000FFC0) +#define ADC_DR_OVERRUN_MASK (0x40000000) +#define ADC_DR_OVERRUN (0x40000000) +#define ADC_DR_DONE_MASK (0x80000000) +#define ADC_DR_DONE (0x80000000) + +/*############################################################################## +## WDT - Watchdog Timer +##############################################################################*/ + +#define WDT_BASE_ADDRESS (0x40004000) + +#define WDT_WDMOD (*(pREG32 (0x40004000))) // Watchdog mode register +#define WDT_WDTC (*(pREG32 (0x40004004))) // Watchdog timer constant register +#define WDT_WDFEED (*(pREG32 (0x40004008))) // Watchdog feed sequence register +#define WDT_WDTV (*(pREG32 (0x4000400C))) // Watchdog timer value register + +/* WDMOD (Watchdog Mode register) + The WDMOD register controls the operation of the Watchdog through the combination of + WDEN and RESET bits. Note that a watchdog feed must be performed before any + changes to the WDMOD register take effect. */ + +#define WDT_WDMOD_WDEN_DISABLED (0x00000000) // Watchdog enable bit +#define WDT_WDMOD_WDEN_ENABLED (0x00000001) +#define WDT_WDMOD_WDEN_MASK (0x00000001) +#define WDT_WDMOD_WDRESET_DISABLED (0x00000000) // Watchdog reset enable bit +#define WDT_WDMOD_WDRESET_ENABLED (0x00000002) +#define WDT_WDMOD_WDRESET_MASK (0x00000002) +#define WDT_WDMOD_WDTOF (0x00000004) // Watchdog time-out interrupt flag +#define WDT_WDMOD_WDTOF_MASK (0x00000004) // Set when the watchdog times out +#define WDT_WDMOD_WDINT (0x00000008) // Watchdog timer interrupt flag +#define WDT_WDMOD_WDINT_MASK (0x00000008) + +/* WDFEED (Watchdog Feed register) + Writing 0xAA followed by 0x55 to this register will reload the Watchdog timer with the + WDTC value. This operation will also start the Watchdog if it is enabled via the WDMOD + register. Setting the WDEN bit in the WDMOD register is not sufficient to enable the + Watchdog. A valid feed sequence must be completed after setting WDEN before the + Watchdog is capable of generating a reset. Until then, the Watchdog will ignore feed + errors. After writing 0xAA to WDFEED, access to any Watchdog register other than writing + 0x55 to WDFEED causes an immediate reset/interrupt when the Watchdog is enabled. + The reset will be generated during the second PCLK following an incorrect access to a + Watchdog register during a feed sequence. + Interrupts should be disabled during the feed sequence. An abort condition will occur if an + interrupt happens during the feed sequence. */ + +#define WDT_WDFEED_FEED1 (0x000000AA) +#define WDT_WDFEED_FEED2 (0x00000055) + +#endif \ No newline at end of file diff --git a/macusbfb/lpc1xxx/LPC11xx_handlers.c b/macusbfb/lpc1xxx/LPC11xx_handlers.c new file mode 100644 index 0000000..9d0d131 --- /dev/null +++ b/macusbfb/lpc1xxx/LPC11xx_handlers.c @@ -0,0 +1,170 @@ +/* + * Software License Agreement (BSD License) + * + * Copyright (c) 2010, Roel Verdult + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// The GCC compiler defines the current architecture derived from the -mcpu argument. +// When target cpu is the cortex-m0, it automatically defines __ARM_ARCH_6M__ +#ifndef __ARM_ARCH_6M__ + #error "The target ARM cpu must be Cortex-M0 compatible (-mcpu=cortex-m0)" +#endif + +// Declare a weak alias macro as described in the GCC manual[1][2] +#define WEAK_ALIAS(f) __attribute__ ((weak, alias (#f))); +#define SECTION(s) __attribute__ ((section(s))) + +/****************************************************************************** + * Forward undefined IRQ handlers to an infinite loop function. The Handlers + * are weakly aliased which means that (re)definitions will overide these. + *****************************************************************************/ + +void irq_undefined() { + // Do nothing when occured interrupt is not defined, just keep looping + while(1); +} + +void CAN_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void SSP1_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void I2C_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void TIMER16_0_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void TIMER16_1_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void TIMER32_0_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void TIMER32_1_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void SSP0_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void UART_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void USB_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void USB_FIQHandler(void) WEAK_ALIAS(irq_undefined); +void ADC_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void WDT_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void BOD_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void FMC_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void PIOINT3_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void PIOINT2_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void PIOINT1_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void PIOINT0_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void WAKEUP_IRQHandler(void) WEAK_ALIAS(irq_undefined); + +/***************************************************************************** + * Forward undefined fault handlers to an infinite loop function. The Handlers + * are weakly aliased which means that (re)definitions will overide these. + ****************************************************************************/ + +void fault_undefined() { + // Do nothing when occured interrupt is not defined, just keep looping + while(1); +} + +void NMI_Handler(void) WEAK_ALIAS(fault_undefined); +void HardFault_Handler(void) WEAK_ALIAS(fault_undefined); +void MemManage_Handler(void) WEAK_ALIAS(fault_undefined); +void BusFault_Handler(void) WEAK_ALIAS(fault_undefined); +void UsageFault_Handler(void) WEAK_ALIAS(fault_undefined); +void SVCall_Handler(void) WEAK_ALIAS(fault_undefined); +void DebugMon_Handler(void) WEAK_ALIAS(fault_undefined); +void PendSV_Handler(void) WEAK_ALIAS(fault_undefined); +void SysTick_Handler(void) WEAK_ALIAS(fault_undefined); + +/****************************************************************************** + * Forward undefined IRQ handlers to an infinite loop function. The Handlers + * are weakly aliased which means that (re)definitions will overide these. + *****************************************************************************/ + +// Prototype the entry values, which are handled by the linker script +extern void stack_entry; +extern void boot_entry(void); + +// Defined irq vectors using simple c code following the description in a white +// paper from ARM[3] and code example from Simonsson Fun Technologies[4]. +// These vectors are placed at the memory location defined in the linker script +const void *vectors[] SECTION(".irq_vectors") = +{ + // Stack and program reset entry point + (void*)&stack_entry, // The initial stack pointer + boot_entry, // The reset handler + + // Various fault handlers + NMI_Handler, // The NMI handler + HardFault_Handler, // The hard fault handler + MemManage_Handler, // MemManage_Handler + BusFault_Handler, // BusFault_Handler + UsageFault_Handler, // UsageFault_Handler + 0, // Reserved + 0, // Reserved + 0, // Reserved + 0, // Reserved + SVCall_Handler, // SVCall handler + DebugMon_Handler, // DebugMon_Handler + 0, // Reserved + PendSV_Handler, // The PendSV handler + SysTick_Handler, // The SysTick handler + + // Wakeup I/O pins handlers + WAKEUP_IRQHandler, // PIO0_0 Wakeup + WAKEUP_IRQHandler, // PIO0_1 Wakeup + WAKEUP_IRQHandler, // PIO0_2 Wakeup + WAKEUP_IRQHandler, // PIO0_3 Wakeup + WAKEUP_IRQHandler, // PIO0_4 Wakeup + WAKEUP_IRQHandler, // PIO0_5 Wakeup + WAKEUP_IRQHandler, // PIO0_6 Wakeup + WAKEUP_IRQHandler, // PIO0_7 Wakeup + WAKEUP_IRQHandler, // PIO0_8 Wakeup + WAKEUP_IRQHandler, // PIO0_9 Wakeup + WAKEUP_IRQHandler, // PIO0_10 Wakeup + WAKEUP_IRQHandler, // PIO0_11 Wakeup + WAKEUP_IRQHandler, // PIO1_0 Wakeup + + // Specific peripheral irq handlers + CAN_IRQHandler, // CAN + SSP1_IRQHandler, // SSP1 + I2C_IRQHandler, // I2C0 + TIMER16_0_IRQHandler, // CT16B0 (16-bit Timer 0) + TIMER16_1_IRQHandler, // CT16B1 (16-bit Timer 1) + TIMER32_0_IRQHandler, // CT32B0 (32-bit Timer 0) + TIMER32_1_IRQHandler, // CT32B1 (32-bit Timer 1) + SSP0_IRQHandler, // SSP0 + UART_IRQHandler, // UART0 + USB_IRQHandler, // USB IRQ + USB_FIQHandler, // USB FIQ + ADC_IRQHandler, // ADC (A/D Converter) + WDT_IRQHandler, // WDT (Watchdog Timer) + BOD_IRQHandler, // BOD (Brownout Detect) + FMC_IRQHandler, // Flash (IP2111 Flash Memory Controller) + PIOINT3_IRQHandler, // PIO INT3 + PIOINT2_IRQHandler, // PIO INT2 + PIOINT1_IRQHandler, // PIO INT1 + PIOINT0_IRQHandler, // PIO INT0 +}; + +/****************************************************************************** + * References + * [1] http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html + * [2] http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html + * [3] http://www.arm.com/files/pdf/Cortex-M3_programming_for_ARM7_developers.pdf + * [4] http://fun-tech.se/stm32/OlimexBlinky/mini.php + *****************************************************************************/ + diff --git a/macusbfb/lpc1xxx/LPC13xx_handlers.c b/macusbfb/lpc1xxx/LPC13xx_handlers.c new file mode 100644 index 0000000..7fe40c4 --- /dev/null +++ b/macusbfb/lpc1xxx/LPC13xx_handlers.c @@ -0,0 +1,193 @@ +/* + * Software License Agreement (BSD License) + * + * Copyright (c) 2010, Roel Verdult + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// The GCC compiler defines the current architecture derived from the -mcpu argument. +// When target cpu is the cortex-m3, it automatically defines __ARM_ARCH_7M__ +#ifndef __ARM_ARCH_7M__ + #error "The target ARM cpu must be Cortex-M3 compatible (-mcpu=cortex-m3)" +#endif + +// Declare a weak alias macro as described in the GCC manual[1][2] +#define WEAK_ALIAS(f) __attribute__ ((weak, alias (#f))); +#define SECTION(s) __attribute__ ((section(s))) + +/****************************************************************************** + * Forward undefined IRQ handlers to an infinite loop function. The Handlers + * are weakly aliased which means that (re)definitions will overide these. + *****************************************************************************/ + +void irq_undefined() { + // Do nothing when occured interrupt is not defined, just keep looping + while(1); +} + +void I2C_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void TIMER16_0_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void TIMER16_1_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void TIMER32_0_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void TIMER32_1_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void SSP_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void UART_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void USB_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void USB_FIQHandler(void) WEAK_ALIAS(irq_undefined); +void ADC_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void WDT_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void BOD_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void FMC_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void PIOINT3_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void PIOINT2_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void PIOINT1_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void PIOINT0_IRQHandler(void) WEAK_ALIAS(irq_undefined); +void WAKEUP_IRQHandler(void) WEAK_ALIAS(irq_undefined); + +/***************************************************************************** + * Forward undefined fault handlers to an infinite loop function. The Handlers + * are weakly aliased which means that (re)definitions will overide these. + ****************************************************************************/ + +void fault_undefined() { + // Do nothing when occured interrupt is not defined, just keep looping + while(1); +} + +void NMI_Handler(void) WEAK_ALIAS(fault_undefined); +void HardFault_Handler(void) WEAK_ALIAS(fault_undefined); +void MemManage_Handler(void) WEAK_ALIAS(fault_undefined); +void BusFault_Handler(void) WEAK_ALIAS(fault_undefined); +void UsageFault_Handler(void) WEAK_ALIAS(fault_undefined); +void SVCall_Handler(void) WEAK_ALIAS(fault_undefined); +void DebugMon_Handler(void) WEAK_ALIAS(fault_undefined); +void PendSV_Handler(void) WEAK_ALIAS(fault_undefined); +void SysTick_Handler(void) WEAK_ALIAS(fault_undefined); + +/****************************************************************************** + * Forward undefined IRQ handlers to an infinite loop function. The Handlers + * are weakly aliased which means that (re)definitions will overide these. + *****************************************************************************/ + +// Prototype the entry values, which are handled by the linker script +extern void* stack_entry; +extern void boot_entry(void); + +// Defined irq vectors using simple c code following the description in a white +// paper from ARM[3] and code example from Simonsson Fun Technologies[4]. +// These vectors are placed at the memory location defined in the linker script +const void *vectors[] SECTION(".irq_vectors") = +{ + // Stack and program reset entry point + &stack_entry, // The initial stack pointer + boot_entry, // The reset handler + + // Various fault handlers + NMI_Handler, // The NMI handler + HardFault_Handler, // The hard fault handler + MemManage_Handler, // The MPU fault handler + BusFault_Handler, // The bus fault handler + UsageFault_Handler, // The usage fault handler + 0, // Reserved + 0, // Reserved + 0, // Reserved + 0, // Reserved + SVCall_Handler, // SVCall handler + DebugMon_Handler, // Debug monitor handler + 0, // Reserved + PendSV_Handler, // The PendSV handler + SysTick_Handler, // The SysTick handler + + // Wakeup I/O pins handlers + WAKEUP_IRQHandler, // PIO0_0 Wakeup + WAKEUP_IRQHandler, // PIO0_1 Wakeup + WAKEUP_IRQHandler, // PIO0_2 Wakeup + WAKEUP_IRQHandler, // PIO0_3 Wakeup + WAKEUP_IRQHandler, // PIO0_4 Wakeup + WAKEUP_IRQHandler, // PIO0_5 Wakeup + WAKEUP_IRQHandler, // PIO0_6 Wakeup + WAKEUP_IRQHandler, // PIO0_7 Wakeup + WAKEUP_IRQHandler, // PIO0_8 Wakeup + WAKEUP_IRQHandler, // PIO0_9 Wakeup + WAKEUP_IRQHandler, // PIO0_10 Wakeup + WAKEUP_IRQHandler, // PIO0_11 Wakeup + WAKEUP_IRQHandler, // PIO1_0 Wakeup + WAKEUP_IRQHandler, // PIO1_1 Wakeup + WAKEUP_IRQHandler, // PIO1_2 Wakeup + WAKEUP_IRQHandler, // PIO1_3 Wakeup + WAKEUP_IRQHandler, // PIO1_4 Wakeup + WAKEUP_IRQHandler, // PIO1_5 Wakeup + WAKEUP_IRQHandler, // PIO1_6 Wakeup + WAKEUP_IRQHandler, // PIO1_7 Wakeup + WAKEUP_IRQHandler, // PIO1_8 Wakeup + WAKEUP_IRQHandler, // PIO1_9 Wakeup + WAKEUP_IRQHandler, // PIO1_10 Wakeup + WAKEUP_IRQHandler, // PIO1_11 Wakeup + WAKEUP_IRQHandler, // PIO2_0 Wakeup + WAKEUP_IRQHandler, // PIO2_1 Wakeup + WAKEUP_IRQHandler, // PIO2_2 Wakeup + WAKEUP_IRQHandler, // PIO2_3 Wakeup + WAKEUP_IRQHandler, // PIO2_4 Wakeup + WAKEUP_IRQHandler, // PIO2_5 Wakeup + WAKEUP_IRQHandler, // PIO2_6 Wakeup + WAKEUP_IRQHandler, // PIO2_7 Wakeup + WAKEUP_IRQHandler, // PIO2_8 Wakeup + WAKEUP_IRQHandler, // PIO2_9 Wakeup + WAKEUP_IRQHandler, // PIO2_10 Wakeup + WAKEUP_IRQHandler, // PIO2_11 Wakeup + WAKEUP_IRQHandler, // PIO3_0 Wakeup + WAKEUP_IRQHandler, // PIO3_1 Wakeup + WAKEUP_IRQHandler, // PIO3_2 Wakeup + WAKEUP_IRQHandler, // PIO3_3 Wakeup + + // Specific peripheral irq handlers + I2C_IRQHandler, // I2C0 + TIMER16_0_IRQHandler, // CT16B0 (16-bit Timer 0) + TIMER16_1_IRQHandler, // CT16B1 (16-bit Timer 1) + TIMER32_0_IRQHandler, // CT32B0 (32-bit Timer 0) + TIMER32_1_IRQHandler, // CT32B1 (32-bit Timer 1) + SSP_IRQHandler, // SSP0 + UART_IRQHandler, // UART0 + USB_IRQHandler, // USB IRQ + USB_FIQHandler, // USB FIQ + ADC_IRQHandler, // ADC (A/D Converter) + WDT_IRQHandler, // WDT (Watchdog Timer) + BOD_IRQHandler, // BOD (Brownout Detect) + FMC_IRQHandler, // Flash (IP2111 Flash Memory Controller) + PIOINT3_IRQHandler, // PIO INT3 + PIOINT2_IRQHandler, // PIO INT2 + PIOINT1_IRQHandler, // PIO INT1 + PIOINT0_IRQHandler, // PIO INT0 +}; + +/****************************************************************************** + * References + * [1] http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html + * [2] http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html + * [3] http://www.arm.com/files/pdf/Cortex-M3_programming_for_ARM7_developers.pdf + * [4] http://fun-tech.se/stm32/OlimexBlinky/mini.php + *****************************************************************************/ + diff --git a/macusbfb/lpc1xxx/LPC1xxx_startup.c b/macusbfb/lpc1xxx/LPC1xxx_startup.c new file mode 100644 index 0000000..db54ec3 --- /dev/null +++ b/macusbfb/lpc1xxx/LPC1xxx_startup.c @@ -0,0 +1,65 @@ +/* + * Software License Agreement (BSD License) + * + * Copyright (c) 2010, Roel Verdult + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// These are defined and created by the linker, locating them in memory +extern unsigned char _etext; +extern unsigned char _data; +extern unsigned char _edata; +extern unsigned char _bss; +extern unsigned char _ebss; + +// Prototype the required startup functions +extern void main(void); + +// The entry point of the application, prepare segments, +// initialize the cpu and execute main() +void boot_entry(void) +{ + register unsigned char *src, *dst; + + // Get physical data address and copy it to sram + src = &_etext; + dst = &_data; + while(dst < &_edata) { + *dst++ = *src++; + } + + // Clear the bss segment + dst = &_bss; + while(dst < &_ebss) { + *dst++ = 0; + } + + // Execute the code at the program entry point + main(); + + // Do nothing when returned from main, just keep looping + while(1); +} diff --git a/macusbfb/lpc1xxx/linkscript.ld b/macusbfb/lpc1xxx/linkscript.ld new file mode 100644 index 0000000..f3e5059 --- /dev/null +++ b/macusbfb/lpc1xxx/linkscript.ld @@ -0,0 +1,77 @@ +/* + * Software License Agreement (BSD License) + * + * Copyright (c) 2010, Roel Verdult + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +sram_top = ORIGIN(sram) + LENGTH(sram); +ENTRY(boot_entry) + +SECTIONS +{ + .text : + { + KEEP(*(.irq_vectors)) + *(.text*) + *(.rodata*) + } > flash + + /* + * More information about Special Section Indexes is available in the + * free "ELF for the ARM Architecture" document from ARM Limited + * http://simplemachines.it/doc/aaelf.pdf + * + */ + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > flash + __exidx_start = .; + .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } > flash + __exidx_end = .; + + _etext = .; + + .data : AT (__exidx_end) + { + _data = .; + *(vtable) + *(.data*) + _edata = .; + } > sram + + /* zero initialized data */ + .bss : + { + _bss = .; + *(.bss*) + *(COMMON) + _ebss = .; + } > sram + + end = .; + + /* For GDB compatibility we decrease the top with 16 bytes */ + stack_entry = sram_top - 16; +} diff --git a/macusbfb/main.c b/macusbfb/main.c new file mode 100644 index 0000000..c1f9a62 --- /dev/null +++ b/macusbfb/main.c @@ -0,0 +1,454 @@ +/* +Firmware for a Macintosh display adapter connected over USB +Copyright (C) 2010 Jeroen Domburg + +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 . +*/ +#include "sysinit.h" +#include "lpc134x.h" +#include +#include "usb.h" +#include "gpio.h" + +//Mac display = 512x342 +//Pixel clock = 15.6672MHz + +//Refresh freq = 60.15 +//Scan rate: 22KHz (?) +//Vbl = 28 scan lines +//Hbl = 192 pixels +// Total: 714x370 'pixels' +//1 line = 64 bytes aan data + +//Ok, the HBL is really funky and actually a HDrive... +//More info: http://members.optusnet.com.au/eviltim/macmp3/macmp3.htm + + +/* +Timings: +Per line: 512 pixels, 202 non-visible 'pixels' +SPI FIFO buffer is 128 pixels -> 384 pixels in which we have to keep pushing the buffer, 330 in which we don't. + +*/ + + +#define NOP() __asm volatile ("NOP") + + +#define LEDPORT 2 +#define LEDBIT 6 +#define HSYNCPORT 0 +#define HSYNCBIT 10 //=CT16B0_MAT2 +#define VSYNCPORT 0 +#define VSYNCBIT 7 +#define VIDEOPORT 0 +#define VIDEOBIT 9 + +#define DRAMDPORT 1 +#define DRAMAPORT 1 +//DRAM D pins: P1_8 - P1_11 +//DRAM A pins: P1_0 - P1-7 +#define DRAMDMASK 0x0F00 +#define DRAMDSHIFT 8 +#define DRAMAMASK 0x00FF +#define DRAMASHIFT 0 +#define DRAMWPORT 3 +#define DRAMWBIT 1 +#define DRAMRASPORT 3 +#define DRAMRASBIT 0 +#define DRAMCASPORT 3 +#define DRAMCASBIT 3 +#define DRAMGPORT 2 +#define DRAMGBIT 11 + +#define GPIOFANPORT 2 +#define GPIOFANBIT 4 +#define GPIOMONPORT 2 +#define GPIOMONBIT 2 +#define GPIOEJECTPORT 2 +#define GPIOEJECTBIT 10 +#define GPIOHDLEDPORT 3 +#define GPIOHDLEDBIT 2 + +#define SENDLINE_BUFFER 1 +#define SENDLINE_FREETIME 2 + +volatile int linePos; +volatile int wordPos; +volatile int dramRow=0; +volatile int doSendLine; +char usbData[64]; +int usbDataLen; +int usbDataProcessed; + +struct GpioPins_t { + int port; + int bit; +}; + +const struct GpioPins_t gpioPins[]={ + {GPIOFANPORT, GPIOFANBIT}, //Fan enable + {GPIOMONPORT, GPIOMONBIT}, //Monitor enable + {GPIOEJECTPORT, GPIOEJECTBIT}, //Floppy eject + {GPIOHDLEDPORT, GPIOHDLEDBIT}, //HD led +}; + + +void gpioSet(int gpio, int val) { + if (gpio>=4) return; + if (val) { + GPIOSET(gpioPins[gpio].port, gpioPins[gpio].bit); + } else { + GPIOCLEAR(gpioPins[gpio].port, gpioPins[gpio].bit); + } +} + + +//Timing note: One NOP is 13ns. + +//Takes a while to set up the line, so this should be called a bit before the real data has to be sent. +void sendLine(int line) { + int dramCol; + + GPIOCLEAR(LEDPORT, LEDBIT); + + GPIOMOD(DRAMAPORT, DRAMAMASK, line<>DRAMDSHIFT); \ + GPIOSET(DRAMCASPORT, DRAMCASBIT); + + int from=0; int to=128; + if (line>=256) { + from=128; + to=256; + } + for (dramCol=from; dramCol32) state=stSync; + //Pre-calc row and col. + row=(pos>>6); + if (pos<16384) { + col=(pos&0x3f)<<1; + } else { + col=((pos&0x3f)|0x40)<<1; + } + state=stRunningFirst; + break; + case stRunning: + case stRunningFirst: + if (state==stRunningFirst || (firstlast&1)) { + GPIO_GPIO1DIR=DRAMDMASK|DRAMAMASK; + GPIOMOD(DRAMAPORT, DRAMAMASK, row<>4)<=256?128:0))<>4)&0xf; + GPIOMOD(DRAMDPORT, DRAMDMASK, i<=256?128:0))<=VIDEOLINESTART && linePos>=4; + i=inv[i&0xf]; +*/ + if ((dramRow)&1) i=0xa; else i=0x5; + GPIOMOD(DRAMDPORT, DRAMDMASK, i<0) { + int x; + int firstlast; + int credits; +#define STARTCREDS 1 + firstlast=1; + credits=STARTCREDS; + while (firstlast!=2) { + if (credits<0) firstlast|=2; + if ((usbDataProcessed+1)==usbDataLen) firstlast|=2; + credits-=processByte(usbData[usbDataProcessed++], firstlast); + if (usbDataProcessed==usbDataLen) { + firstlast=2; + usbDataLen=0; + usbDataProcessed=0; + } + firstlast&=(~1); + } + } else { + usbHandle(); + } + } +} diff --git a/macusbfb/projectconfig.h b/macusbfb/projectconfig.h new file mode 100644 index 0000000..b62ddb1 --- /dev/null +++ b/macusbfb/projectconfig.h @@ -0,0 +1,53 @@ +/**************************************************************************/ +/*! + @file projectconfig.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef _PROJECTCONFIG_H_ +#define _PROJECTCONFIG_H_ + +#include "lpc134x.h" +#include "sysdefs.h" +//#include "drivers/chibi/chb_drvr.h" + +/* Core CPU Settings (reference only) */ +#define CFG_CPU_CCLK (72000000) // Ref. only. Clock speed actually set in "core/cpu/cpu.c" + +/* Systick Timer Settings */ +#define CFG_SYSTICK_DELAY_IN_MS (1) // The number of milliseconds between each tick of the systick timer + + +#endif diff --git a/macusbfb/sysdefs.h b/macusbfb/sysdefs.h new file mode 100644 index 0000000..625d24f --- /dev/null +++ b/macusbfb/sysdefs.h @@ -0,0 +1,64 @@ +/**************************************************************************/ +/*! + @file sysdefs.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include + +#ifndef _SYSDEFS_H_ +#define _SYSDEFS_H_ + +#ifndef TRUE +#define TRUE (1) +#endif +#ifndef FALSE +#define FALSE (0) +#endif + +typedef volatile uint8_t REG8; +typedef volatile uint16_t REG16; +typedef volatile uint32_t REG32; +typedef unsigned int BOOL; + +#define pREG8 (REG8 *) +#define pREG16 (REG16 *) +#define pREG32 (REG32 *) + +#ifndef NULL +#define NULL ((void *) 0) +#endif + +#endif diff --git a/macusbfb/sysinit.c b/macusbfb/sysinit.c new file mode 100644 index 0000000..9cfb9ac --- /dev/null +++ b/macusbfb/sysinit.c @@ -0,0 +1,156 @@ +/**************************************************************************/ +/*! + @file sysinit.c + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include +#include + +#include "sysinit.h" + +#include "core/cpu/cpu.h" +#include "core/pmu/pmu.h" + +#ifdef CFG_PRINTF_UART + #include "core/uart/uart.h" +#endif + +#ifdef CFG_INTERFACE + #include "core/cmd/cmd.h" +#endif + +#ifdef CFG_CHIBI + #include "drivers/chibi/chb.h" + static chb_rx_data_t rx_data; +#endif + +#ifdef CFG_USBHID + #include "core/usbhid-rom/usbhid.h" +#endif + +#ifdef CFG_USBCDC + #include "core/usbcdc/usb.h" + #include "core/usbcdc/usbcore.h" + #include "core/usbcdc/usbhw.h" + #include "core/usbcdc/cdcuser.h" +#endif + +#ifdef CFG_LCD + #include "drivers/lcd/lcd.h" + #include "drivers/lcd/drawing.h" + #include "drivers/lcd/fonts/consolas9.h" + #include "drivers/lcd/fonts/consolas11.h" + #include "drivers/lcd/fonts/consolas16.h" + #include "drivers/lcd/fonts/smallfonts.h" +#endif + +#ifdef CFG_I2CEEPROM + #include "drivers/eeprom/mcp24aa/mcp24aa.h" +#endif + +#ifdef CFG_SDCARD + #include "core/ssp/ssp.h" + #include "drivers/fatfs/diskio.h" + #include "drivers/fatfs/ff.h" + static FILINFO Finfo; + static FATFS Fatfs[1]; + static uint8_t buf[64]; +#endif + +/**************************************************************************/ +/*! + Configures the core system clock and sets up any mandatory + peripherals like the systick timer, UART for printf, etc. + + This function should set the HW to the default state you wish to be + in coming out of reset/startup, such as disabling or enabling LEDs, + setting specific pin states, etc. +*/ +/**************************************************************************/ +void systemInit() +{ + // Setup the cpu and core clock + cpuInit(); + + // Initialise the systick timer (delay set in projectconfig.h) +// systickInit(CFG_SYSTICK_DELAY_IN_MS); + + /* Enable AHB clock to the GPIO domain. */ + SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_GPIO); + +} + + +#if 0 +/**************************************************************************/ +/*! + @brief Sends a single byte to a pre-determined peripheral (UART, etc.). + + @param[in] byte + Byte value to send +*/ +/**************************************************************************/ +void __putchar(const char c) +{ + #ifdef CFG_PRINTF_UART + // Send output to UART + uartSendByte(c); + #endif + + #ifdef CFG_PRINTF_USBCDC + usbcdcSendByte(c); + #endif + + #if defined CFG_PRINTF_NONE + // Ignore output + #endif +} + +/**************************************************************************/ +/*! + @brief Sends a string to a pre-determined end point (UART, etc.). + + @param[in] str + Text to send +*/ +/**************************************************************************/ +int puts(const char * str) +{ + while(*str) __putchar(*str++); + return 0; +} + +#endif \ No newline at end of file diff --git a/macusbfb/sysinit.h b/macusbfb/sysinit.h new file mode 100644 index 0000000..f7beabd --- /dev/null +++ b/macusbfb/sysinit.h @@ -0,0 +1,50 @@ +/**************************************************************************/ +/*! + @file sysinit.h + @author K. Townsend (microBuilder.eu) + @date 22 March 2010 + @version 0.10 + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#ifndef __SYSINIT_H__ +#define __SYSINIT_H__ + +#include "projectconfig.h" + +#include "core/gpio/gpio.h" +#include "core/systick/systick.h" + +// Function prototypes +void systemInit(); + +#endif \ No newline at end of file diff --git a/macusbfb/usb.c b/macusbfb/usb.c new file mode 100644 index 0000000..753f968 --- /dev/null +++ b/macusbfb/usb.c @@ -0,0 +1,319 @@ +/* +Firmware for a Macintosh display adapter connected over USB +Copyright (C) 2010 Jeroen Domburg + +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 . +*/ +//Implement a simple USB interface thingy which can receive bulk packets. +//No interrupts are used because of timing issues in the main code. + +#include "lpc134x.h" +#include + +#define NOP() __asm volatile ("NOP") +#define PACKED __attribute__((__packed__)) + +//Comment out to get debugging stuff on the monitor. +#define printf(bla, ...) {} + +extern void gpioSet(int gpio, int val); + +typedef struct { + unsigned char bmRequestType; + unsigned char bRequest; + unsigned short wValue; + unsigned short wIndex; + unsigned short wLength; +} PACKED setupPacketTp; + +//Descriptor ref: +//http://www.usbmadesimple.co.uk/ums_4.htm + +char myDevDescriptor[]={ + 18, //length (18?) + 1, //descriptor type + 0x02,0x00, //usb ver + 0xff, //class + 0, //subclass + 0, //protocol + 64, //max packet size + 0x34,0x12, //vendor id + 0xAA,0x55, //product id + 0x00,0x01, //device release + 0x00, //manuf str index + 0x00, //prod str index + 0x00, //serial str index + 0x01 //no of possible configs +}; + +char myConfDescriptor[]={ + //main config descriptor + 9, //length of this descr + 02, //type (config descr) + 32,0, //total length + 01, //no of interfaces + 01, //select config no 1 to use this + 00, //string descr of this config + 0x80, //attributes + 100, //max current drawn in 2ma steps + //iface1 condfig descriptor + 9, //len + 4, //type (iface descr) + 0, //iface number this descr describes + 0, //alternate setting for this iface + 2, //number of endpoints + 0xff, //iface class + 0, //Iface subclass + 0, //Iface protocol + 0, //String descr of this iface + //Endpoint descriptor + 7, //len + 5, //type (endpoint descr) + 0x3, //address. IN iface = +0x80 + 0x2, //attributes + 32,0, //max packet size + 10, //Interval to poll for data, in ms + //Endpoint descriptor + 7, //len + 5, //type (endpoint descr) + 0x83, //address. IN iface = +0x80 + 0x2, //attributes + 32,0, //max packet size + 10, //Interval to poll for data, in ms +}; + +static int myAddr=0; + +static void dumpHex(unsigned char *buf, int len) { + int x; + if (len==0) return; + for (x=0; x0) dumpHex((unsigned char* )data, len); +} + +int readFromEp(int ep, unsigned int *data, int maxlen) { + int x, dummy; + USB_CTRL=((ep&0xF)<<2)|(1<<0); + NOP(); NOP(); NOP(); + int plen; + do { + plen=USB_RXPLEN; + } while ((plen&0x400)==0); + plen&=0x3ff; + + if (plen!=maxlen) printf("Ep %x: recv %i bufflen=%i!\n", ep, plen, maxlen); + for (x=0; x<(plen); x+=4) { + if (xmaxlen?maxlen:plen; +} + +inline short swap16(unsigned short word) { + return ((word&0xff)<<8)|(word>>8); +} + +static inline void handleSetupPacket(setupPacketTp *p) { +//A printf("Setup packet, type=%i, req=%i, val=%i, idx=%i\n", p->bmRequestType, p->bRequest, p->wValue, p->wIndex); +// dumpHex((unsigned char* )p, 8); + if (p->bmRequestType==0x80 && p->bRequest==6) { + //Get descriptor. + int index=swap16(p->wIndex); + int len=p->wLength; + if (swap16(p->wValue)==1) { + //Dev descriptor. Write to ep. + writeToEp(0, (unsigned int *)myDevDescriptor, myDevDescriptor[0]); + printf("Dev desc written.\n"); + } else if (swap16(p->wValue)==2) { + int resplen=myConfDescriptor[2]+(myConfDescriptor[3]<<8); + if (resplen>len) resplen=len; + writeToEp(0, (unsigned int *)myConfDescriptor, len); + printf("Conf desc written.\n"); + } else { + printf("EEK! Unhandled descriptor request!\n"); + } + } else if (p->bmRequestType==00 && p->bRequest==5) { + //Set address + //First send Ack with our old addresss 0 + writeToEp(0, NULL, 0); + //Then set new address. + myAddr=(p->wValue&0x7F); + + wrCmd(0xD0); + wrData(myAddr|0x80); + wrCmd(0xD0); + wrData(myAddr|0x80); + printf("Set addr to %i.\n",myAddr); + } else if (p->bmRequestType==00 && p->bRequest==9) { + //Set configuration. + //Just allow, there's only one of them anyway. + writeToEp(0, NULL, 0); + //Ok, other stuff can come in now. + wrCmd(0xD8); + wrData(1); + printf("Enabled other endpoints!\n"); + } else if (p->bmRequestType==0x40 && p->bRequest==1) { //vendor specific, gpio control, host->dev + //Modify output wIndex to wValue + gpioSet(p->wIndex, p->wValue); + } else { + printf("EEK! Unhandled setup packet!\n"); + } +} + +extern char usbData[64]; +extern int usbDataLen; + + +void usbHandle() { + //Handle all the USB stuff by looking at any interrupts that would have been triggered. + int ints=USB_DEVINTST; + USB_DEVINTCLR=ints; +// if ((ints&0x1fe)!=0) printf("Int status %x\n", ints); + if (ints&(1<<7)) { + int epstatus=rdCmd(0x46); + printf("Ep3 int, status=%x\n", epstatus); + usbDataLen=readFromEp(3, usbData, 64); + return; + } + if (ints&(1<<8)) { + int epstatus=rdCmd(0x47); + printf("Ep3.1 int, status=%x\n", epstatus); + } + + if (ints&(1<<1)) { + //Endpoint0 int + int epstatus=rdCmd(0x40); +// printf("Ep0 int, status=%x\n", epstatus); + if (epstatus&(1<<2)) { + //Setup-packet. + unsigned char setupPacket[8]; + readFromEp(0, (unsigned int *)setupPacket, 8); + handleSetupPacket((setupPacketTp*) setupPacket); + } + } + if (ints&(1<<9)) { + //Device status change + int status=rdCmd(0xfe); +// printf("Dev status is now %x\n",status); + if (!(status&1)) { + //Reconnect, damn you! +/* + wrCmd(0xFE); + wrData(0x1); + myAddr=0; +*/ + } + } +} diff --git a/macusbfb/usb.h b/macusbfb/usb.h new file mode 100644 index 0000000..a2a35c3 --- /dev/null +++ b/macusbfb/usb.h @@ -0,0 +1,3 @@ +void usbInit(); +void usbHandle(); +void usbConnect(); diff --git a/macusbfb/usbgpio.c b/macusbfb/usbgpio.c new file mode 100644 index 0000000..2ff6bd2 --- /dev/null +++ b/macusbfb/usbgpio.c @@ -0,0 +1,48 @@ +/* +Firmware for a Macintosh display adapter connected over USB +Copyright (C) 2010 Jeroen Domburg + +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 . +*/ +#include "gpio.h" +#include "usbgpio.h" + +//Handler for the USB-exposed GPIO pins + +struct GpioPins_t { + int port; + int bit; +}; + +const struct GpioPins_t gpioPins[]={ + {0, 11}, //Fan enable, can be pwmmed too + {2, 2}, //Monitor enable + {2, 10}, //Floppy eject + {3, 2}, //HD led +} + + +void gpioSet(int gpio, int val) { + if (gpio>4) return; + if (val) { + GPIOSET(gpioPins[gpio].port, gpioPins[gpio].bit); + } else { + GPIOCLEAR(gpioPins[gpio].port, gpioPins[gpio].bit); + } +} + +int gpioGet(int gpio) { + //Not implemented (yet) +} + diff --git a/macusbfb/usbgpio.h b/macusbfb/usbgpio.h new file mode 100644 index 0000000..eb4ecf3 --- /dev/null +++ b/macusbfb/usbgpio.h @@ -0,0 +1,2 @@ +void gpioSet(int gpio, int val); +int gpioGet(int gpio);