summaryrefslogtreecommitdiffstats
path: root/contrib/cp210x-program
diff options
context:
space:
mode:
authorJames McKenzie <git@madingley.org>2014-12-15 12:05:41 +0000
committerJames McKenzie <git@madingley.org>2014-12-15 12:05:41 +0000
commit373bb32332b117236720af0ff971769fc5930ba6 (patch)
treec1a1e58218a9ce1fed33b7e5330069f856c209cc /contrib/cp210x-program
downloadvalve-373bb32332b117236720af0ff971769fc5930ba6.tar.gz
valve-373bb32332b117236720af0ff971769fc5930ba6.tar.bz2
valve-373bb32332b117236720af0ff971769fc5930ba6.zip
Diffstat (limited to 'contrib/cp210x-program')
-rw-r--r--contrib/cp210x-program/LICENSE510
-rw-r--r--contrib/cp210x-program/MANIFEST.in4
-rw-r--r--contrib/cp210x-program/README92
-rw-r--r--contrib/cp210x-program/build/lib/cp210x/__init__.py4
-rw-r--r--contrib/cp210x-program/build/lib/cp210x/cp210x.py398
-rw-r--r--contrib/cp210x-program/build/lib/cp210x/eeprom.py180
-rw-r--r--contrib/cp210x-program/build/lib/cp210x/usb.py274
-rw-r--r--contrib/cp210x-program/build/lib/cp210x/valuefile.py234
-rwxr-xr-xcontrib/cp210x-program/build/scripts-2.6/cp210x-program266
-rwxr-xr-xcontrib/cp210x-program/cp210x-program266
-rw-r--r--contrib/cp210x-program/cp210x-program.doap83
-rw-r--r--contrib/cp210x-program/cp210x/__init__.py4
-rw-r--r--contrib/cp210x-program/cp210x/__init__.pycbin0 -> 259 bytes
-rw-r--r--contrib/cp210x-program/cp210x/cp210x.py398
-rw-r--r--contrib/cp210x-program/cp210x/cp210x.pycbin0 -> 17366 bytes
-rw-r--r--contrib/cp210x-program/cp210x/eeprom.py180
-rw-r--r--contrib/cp210x-program/cp210x/eeprom.pycbin0 -> 9905 bytes
-rw-r--r--contrib/cp210x-program/cp210x/usb.py274
-rw-r--r--contrib/cp210x-program/cp210x/usb.pycbin0 -> 9059 bytes
-rw-r--r--contrib/cp210x-program/cp210x/valuefile.py234
-rw-r--r--contrib/cp210x-program/cp210x/valuefile.pycbin0 -> 8339 bytes
-rw-r--r--contrib/cp210x-program/doc/45-cp210x-programming.rules9
-rw-r--r--contrib/cp210x-program/doc/cp210x.txt107
-rw-r--r--contrib/cp210x-program/doc/index.html129
-rwxr-xr-xcontrib/cp210x-program/setup.py48
25 files changed, 3694 insertions, 0 deletions
diff --git a/contrib/cp210x-program/LICENSE b/contrib/cp210x-program/LICENSE
new file mode 100644
index 0000000..2d2d780
--- /dev/null
+++ b/contrib/cp210x-program/LICENSE
@@ -0,0 +1,510 @@
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+ When we speak of free software, we are referring to freedom of use,
+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 and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes a de-facto standard. To achieve this, non-free programs must
+be allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, 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 library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete 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 distribute a copy of this License along with the
+Library.
+
+ 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 Library or any portion
+of it, thus forming a work based on the Library, 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) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+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 Library, 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 Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you 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.
+
+ If distribution of 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 satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at least
+ three years, to give the same user the materials specified in
+ Subsection 6a, above, for a charge no more than the cost of
+ performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be 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.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library 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.
+
+ 9. 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 Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+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 with
+this License.
+
+ 11. 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 Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library 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 Library.
+
+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.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library 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.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+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 Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+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
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "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
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. 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 LIBRARY 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
+LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), 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 Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library.
+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.
+
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or
+your school, if any, to sign a "copyright disclaimer" for the library,
+if necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James
+ Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/contrib/cp210x-program/MANIFEST.in b/contrib/cp210x-program/MANIFEST.in
new file mode 100644
index 0000000..519311e
--- /dev/null
+++ b/contrib/cp210x-program/MANIFEST.in
@@ -0,0 +1,4 @@
+include doc/*.txt
+include doc/*.rules
+include LICENSE
+include cp210x-program.doap
diff --git a/contrib/cp210x-program/README b/contrib/cp210x-program/README
new file mode 100644
index 0000000..2ac42a1
--- /dev/null
+++ b/contrib/cp210x-program/README
@@ -0,0 +1,92 @@
+
+ cp210x-program
+ ==============
+
+ATTENTION: THIS VERSION OF cp210x-program IS NOT FULLY TESTED. IT MAY RENDER
+ YOUR CP210x USELESS OR DESTROY IT.
+
+Be aware that the current version is only tested on CP2102.
+
+The goal of this library is to provide access to the EEPROM of an Silabs CP210x
+under Linux.
+
+The CP210x is an USB-to-serial chip used in a lot of USB devices (similar to
+FTDIs and PL2303). The CP210x has a EEPROM on the chip which can be programmed
+via USB. Silabs provides already a library and gui programm to program this
+EEPROM, but only for windows.
+
+This project uses results from monitoring the USB bus when the windows library
+programms an CP210x. The windows library was not disassembled for this protocol
+analysis.
+
+When the programm is finished, a later goal would be to provide a library which
+can be used to access further functions of the CP210x like the general IO pins
+of the CP2103. The goal is not to provide an tty driver, such driver exists
+already for linux and BSD.
+
+Version: 0.1
+Author: Johannes Hölzl <johannes.hoelzl@gmx.de>
+
+Dependencies
+------------
+
+ * Python >= 2.4
+ * ctypes >= 0.9 (only when Python 2.4 is used)
+ * libusb 0.1
+
+Since libusb is available on most Linux, Mac OS X and FreeBSD cp210x-program
+should run flawlessly on these platforms. Currently it is only tested on
+Linux 2.6 (Ubuntu).
+
+If cp210x-program should run as non-root user, add the udev rule found in
+doc/45-cp210x-programming.rules to /etc/udev/rules.d. When devices with already
+programmed IDs are reprogrammed at this IDs to 45-cp210x-programming.rules.
+
+Usage
+-----
+
+Read EEPROM content into hexfile:
+$ cp210x-program --read-cp210x -F eeprom-content.hex
+
+Show EEPROM content from device 002 on bus 001:
+$ cp210x-program --read-cp210x -m 001/002
+
+Write some data to device with vendor id 0x10C4 and product id 0xEA62:
+$ cp210x-program --write-cp210x -m 10C4:EA62 \
+ --set-product-string="Product String" \
+ --set-max-power=100 \
+ --set-bus-powered=no
+
+TODO
+----
+
+ * Test on other than CP2102
+
+ * Implement CP2103 GIOP settings
+
+ * Implement GUI
+
+Links
+-----
+
+ * CP210x Product page on Silicon Labs:
+ http://www.silabs.com/tgwWebApp/public/web_content/products/Microcontrollers/Interface/en/interface.htm
+
+ * AN114 Customization Guide:
+ http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an144.pdf
+ http://www.silabs.com/public/documents/software_doc/othersoftware/Microcontrollers/Interface/en/an144sw.zip
+
+ * AN205 CP210x Baudrate Guide:
+ http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an205.pdf
+ http://www.silabs.com/public/documents/software_doc/othersoftware/Microcontrollers/en/AN205SW.zip
+
+ * AN223 Port Configuration and GPIO for CP210x
+ http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an223.pdf
+ http://www.silabs.com/public/documents/software_doc/othersoftware/Microcontrollers/Interface/en/AN223SW.zip
+
+License
+-------
+
+The python package 'cp210x' and the python script 'cp210x-program' are provided
+under the terms of the GNU LGPL. See LICENSE.
+
diff --git a/contrib/cp210x-program/build/lib/cp210x/__init__.py b/contrib/cp210x-program/build/lib/cp210x/__init__.py
new file mode 100644
index 0000000..b761032
--- /dev/null
+++ b/contrib/cp210x-program/build/lib/cp210x/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+
+__author__ = "Johannes Hölzl <johannes.hoelzl@gmx.de>"
+__license__ = "GNU LGPL"
diff --git a/contrib/cp210x-program/build/lib/cp210x/cp210x.py b/contrib/cp210x-program/build/lib/cp210x/cp210x.py
new file mode 100644
index 0000000..c51cb35
--- /dev/null
+++ b/contrib/cp210x-program/build/lib/cp210x/cp210x.py
@@ -0,0 +1,398 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2007 Johannes Hölzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+"""Provides access to the EEPROM of Silabs CP210x devices
+
+The following classes are available:
+
+class Cp210xProgrammer:
+ Provides direct access to the CP2101, can be used to write single data
+ directly or via an EEPROM image.
+
+class EEPROM:
+ Can be used to read or write a hex file containing the EEPROM content
+ of an CP2101. Provides also access to the single fields in the EEPROM.
+"""
+
+import ctypes
+import usb
+
+__all__ = ['Cp210xProgrammer', 'Cp210xError']
+
+CP2101_UART = 0x00
+CP2101_CONFIG = 0xFF
+
+CP2101_UART_ENABLE = 0x0001
+CP2101_UART_DISABLE = 0x0000
+
+REG_VENDOR_ID = 0x3701
+REG_PRODUCT_ID = 0x3702
+REG_PRODUCT_STRING = 0x3703
+REG_SERIAL_NUMBER = 0x3704
+REG_CFG_ATTRIBUTES = 0x3705
+REG_MAX_POWER = 0x3706
+REG_VERSION = 0x3707
+REG_UNKNOWN = 0x3708
+REG_EEPROM = 0x3709
+REG_LOCK_VALUE = 0x370A
+REG_PART_NUMBER = 0x370B
+
+SIZE_EEPROM = 0x0400
+SIZE_PRODUCT_STRING = 0x007D
+SIZE_SERIAL_NUMBER = 0x003F
+SIZE_BAUDRATES = 32
+SIZE_BAUDRATE_CFG = 10
+SIZE_BAUDRATE_TABLE = SIZE_BAUDRATES * SIZE_BAUDRATE_CFG
+SIZE_VENDOR_STRING = 24
+
+LCK_LOCKED = 0x00
+LCK_UNLOCKED = 0xFF
+
+VID_SILABS = 0x10C4
+PID_CP210x = 0xEA60
+
+VALUES = [
+ ('product_string', 'string'),
+ ('serial_number', 'string'),
+ ('product_id', 'id'),
+ ('vendor_id', 'id'),
+ ('version', 'version'),
+ ('bus_powered', 'boolean'),
+ ('max_power', 'int'),
+ ('locked', 'boolean'),
+ ('part_number', 'int'),
+ ('vendor_string', 'string'),
+ ('baudrate_table', 'list'),
+]
+
+def iif(v, a, b):
+ if v:
+ return a
+ else:
+ return b
+
+def to_div2(p):
+ value = int(p / 2)
+ if (value * 2) < p:
+ value += 1
+ return value
+
+def to_bcd(i):
+ assert i >= 0 and i <= 99
+ return (i // 10) << 4 | (i % 10)
+
+def to_bcd2( (i, j) ):
+ return to_bcd(i) << 8 | to_bcd(j)
+
+def from_bcd(num):
+ return num & 0x0F + (num >> 4) * 10
+
+def from_bcd2(data):
+ return (from_bcd(data >> 8), from_bcd(data & 0xFF))
+
+def from_binary(data, le=True):
+ value = 0
+ if le:
+ data = data[::-1]
+ for byte in data:
+ value = value << 8 | ord(byte)
+ return value
+
+def to_binary(value, size=2, le=True):
+ data = ''
+ for i in range(size):
+ data += chr(value & 0xFF)
+ value >>= 8
+ if le:
+ return data
+ else:
+ return data[::-1]
+
+def parse_baudrate_cfg(data):
+ return (from_binary(data[0:2], le=False),
+ from_binary(data[2:4], le=False),
+ from_binary(data[4:5]),
+ from_binary(data[6:10]))
+
+def build_baudrate_cfg(baudgen, timer0reload, prescaler, baudrate):
+ return (to_binary(baudgen, le=False) + to_binary(timer0reload, le=False) +
+ to_binary(prescaler, 1) + '\x00' + to_binary(baudrate, 4))
+
+class Cp210xError(IOError):
+ pass
+
+class DeviceLocked(Cp210xError):
+ pass
+
+class Cp210xProgrammer(object):
+ """Program an Silabs CP2101, CP2102 or CP2103
+
+ This modul provides access to Silabs CP210x devices to set some USB
+ descriptor fields and some USB descriptor strings.
+
+ The following fields can be set:
+
+ * Vendor ID
+ * Product ID
+ * Product String
+ * Serial Number
+ * Device Version
+ * Bus Powered
+ * max. Power consumption
+
+ Either use libusb to find a device, and provide the device description
+ to the constructor, or use Cp210xProgrammer.list_device() to list all
+ devices matching certain pattern.
+
+ To progamm the device open() it, set the data, and close() it. To have the
+ changed fields reread call reset() before closing it.
+ """
+
+ TIMEOUT = 300 #ms
+
+ @classmethod
+ def list_devices(self, patterns=[{ 'idVendor': VID_SILABS,
+ 'idProduct': PID_CP210x }]):
+ """Yields a list of devices matching certain patterns.
+
+ param patterns: This must be a list of dictionaries or pairs of string.
+ Each device in the usb tree is matched against all pattern in the
+ list.
+
+ When an item is a dictionary all fields of the descriptors
+ are compared against the corresponding values in the dictionary. If
+ each value is equal, the device is yielded.
+
+ When an item is a pair of strings. The first string must be the
+ dirname of the bus and the second string the filename of the device.
+
+ For example:
+
+ >> list(Cp210xProgrammer.list_device([{ 'idVendor': VID_SILABS,
+ 'idProduct': PID_CP210x }]))
+ [device(...)]
+
+ """
+
+ usb.find_busses()
+ usb.find_devices()
+
+ bus = usb.get_busses()
+ while bus:
+ dev = bus.contents.devices
+ while dev:
+ for pattern in patterns:
+ if isinstance(pattern, dict):
+ for name, value in pattern.items():
+ if getattr(dev.contents.descriptor, name) != value:
+ break
+ else:
+ yield self(dev)
+ break
+ elif isinstance(pattern, tuple):
+ if (bus.contents.dirname == pattern[0] and
+ dev.contents.filename == pattern[1]):
+ yield self(dev)
+ break
+ dev = dev.contents.next
+ bus = bus.contents.next
+
+ def __init__(self, dev_info):
+ self.dev_info = dev_info
+ self.handle = None
+ self._locked = None
+
+ def open(self):
+ """Opens the device.
+
+ Only after an successful call to open() data can be read from and
+ written to the device.
+
+ Claims all resources associated with this device.
+ """
+ self.handle = usb.open(self.dev_info)
+ if self.handle == 0:
+ self.handle = None
+ raise Cp210xError("Can't open device.")
+ usb.set_configuration(self.handle, 1)
+ usb.claim_interface(self.handle, 0)
+
+ def reset(self):
+ """Force the USB stack to reset the device.
+
+ Resets the device through an hard reset over the port to which the
+ device is connected. After that happend the EEPROM content in the device
+ is reread and the device's descriptors are the one written to it.
+ """
+ assert self.handle is not None
+ usb.reset(self.handle)
+
+ def close(self):
+ """Closes the device.
+
+ Releases all resources associated with this device.
+ """
+ assert self.handle is not None
+ usb.release_interface(self.handle, 0)
+ usb.close(self.handle)
+ self.handle = None
+
+ def __del__(self):
+ if self.handle is not None:
+ self.close()
+
+ def _set_config(self, value, index=0, data=None, request=CP2101_CONFIG):
+ assert self.handle is not None
+ if self.get_locked():
+ raise DeviceLocked()
+
+ if data is not None:
+ data_length = len(data)
+ else:
+ data_length = 0
+ res = usb.control_msg(self.handle, usb.ENDPOINT_OUT | usb.TYPE_VENDOR,
+ request, value, index, data, data_length,
+ self.TIMEOUT)
+ if res < 0:
+ raise Cp210xError("Unable to send request %04X result=%d"
+ % (value, res))
+
+ def _set_config_string(self, value, content, max_length):
+ assert isinstance(content, basestring)
+ encoded = content.encode('utf-16-le')
+ assert len(encoded) <= max_length
+ self._set_config(value, data=chr(len(encoded) + 2) + "\x03" + encoded)
+
+ def _get_config(self, value, length, index=0, request=CP2101_CONFIG):
+ assert self.handle is not None
+ data = ctypes.create_string_buffer(length)
+ res = usb.control_msg(self.handle, usb.ENDPOINT_IN | usb.TYPE_VENDOR,
+ request, value, index, data, length,
+ self.TIMEOUT)
+ if res < 0:
+ raise Cp210xError("Unable to send request, %04X result=%d"
+ % (value, res))
+ return data.raw[:res]
+
+ def _get_int8_config(self, value, index=0, request=CP2101_CONFIG):
+ return ord(self._get_config(value, 1, index=index, request=request))
+
+ def _get_int16_config(self, value, index=0, request=CP2101_CONFIG):
+ data = self._get_config(value, 2, index=index, request=request)
+ return ord(data[0]) << 8 | ord(data[1])
+
+ def get_eeprom_content(self):
+ """Reads the entire EEPROM content as one big 1024-byte blob.
+ """
+ return self._get_config(REG_EEPROM, SIZE_EEPROM)
+
+ def get_baudrate_content(self):
+ """Return the baudrate table as binary data.
+ """
+ return self._get_config(REG_EEPROM, SIZE_BAUDRATE_TABLE)
+
+ def get_baudrate_table(self):
+ """Returns the baudrate table.
+
+ A list containing 4-tuples are returnes.
+ Each tuple containes the following data:
+
+ * BaudGen: Value used to generate the real baudrate.
+ * Time0Reset: Value used to generate the usb timeout.
+ * Prescaler: Used to generate the real baudrate.
+ * Baudrate: The baudrate which activates this entry.
+ """
+ data = self.get_baudrate_content()
+ return [parse_baudrate_cfg(data[pos:pos+SIZE_BAUDRATE_CFG])
+ for pos in range(0, SIZE_BAUDRATE_TABLE, SIZE_BAUDRATE_CFG)]
+
+ def set_baudrate_table(self, baudrates):
+ """Writes the baudrate table.
+
+ See get_baudrate_table() for the structure of the table.
+ """
+ assert len(baudrates) == SIZE_BAUDRATES
+ self.set_baudrate_content(data=''.join(build_baudrate_cfg(*cfg)
+ for cfg in baudrates))
+ baudrate_table = property(get_baudrate_table, set_baudrate_table)
+
+ def get_part_number(self):
+ """ The part number of the device.
+
+ Returns: 1 for an CP2101
+ 2 for an CP2102
+ 3 for an CP2103
+ """
+ return self._get_int8_config(REG_PART_NUMBER)
+
+ def get_locked(self):
+ """ The lock value of the device.
+
+ When True is returnes no data can be written to the device.
+ """
+ if self._locked is None:
+ self._locked = self._get_int8_config(REG_LOCK_VALUE) == LCK_LOCKED
+ return self._locked
+
+ def set_eeprom_content(self, content):
+ """Writes an 1024-byte blob to the EEPROM
+ """
+ assert len(content) == SIZE_EEPROM, ("EEPROM data must be %i bytes."
+ % SIZE_EEPROM)
+ assert isinstance(content, str), "EEPROM data must be string."
+ self._set_config(REG_EEPROM, data=content)
+
+ def set_product_id(self, pid):
+ """Sets the Product ID
+ """
+ assert pid > 0x0000 and pid < 0xFFFF
+ self._set_config(REG_PRODUCT_ID, pid)
+
+ def set_vendor_id(self, vid):
+ """Sets the Vendor ID
+ """
+ assert vid > 0x0000 and vid < 0xFFFF
+ self._set_config(REG_VENDOR_ID, vid)
+
+ def set_product_string(self, product_string):
+ """Sets the product string.
+
+ Be aware that the string will be stored as UTF-16 encoded and should not
+ exceed SIZE_PRODUCT_STRING
+ """
+ self._set_config_string(REG_PRODUCT_STRING, product_string,
+ SIZE_PRODUCT_STRING)
+
+ def set_serial_number(self, serial_number):
+ self._set_config_string(REG_SERIAL_NUMBER, serial_number,
+ SIZE_SERIAL_NUMBER)
+
+ def set_max_power(self, max_power):
+ assert max_power >= 0 and max_power <= 500
+ self._set_config(REG_MAX_POWER, to_div2(max_power))
+
+ def set_bus_powered(self, bus_powered):
+ if bus_powered:
+ self._set_config(REG_CFG_ATTRIBUTES, 0xC0)
+ else:
+ self._set_config(REG_CFG_ATTRIBUTES, 0x80)
+
+ def set_version(self, version):
+ self._set_config(REG_VERSION, to_bcd2(version))
+
+ def set_locked(self, locked):
+ """ The lock value of the device.
+
+ When True is returnes no data can be written to the device.
+ """
+ if locked:
+ self._set_config(REG_LOCK_VALUE, LCK_LOCKED)
+ else:
+ self._set_config(REG_LOCK_VALUE, LCK_UNLOCKED)
+
+ def set_values(self, values):
+ for name, value in values.items():
+ if name not in ['part_number', 'vendor_string']:
+ getattr(self, "set_" + name) (value)
+
diff --git a/contrib/cp210x-program/build/lib/cp210x/eeprom.py b/contrib/cp210x-program/build/lib/cp210x/eeprom.py
new file mode 100644
index 0000000..25f0372
--- /dev/null
+++ b/contrib/cp210x-program/build/lib/cp210x/eeprom.py
@@ -0,0 +1,180 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2007 Johannes Hölzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+
+import cp210x
+from cp210x import from_binary, to_binary, iif, VALUES
+
+__all__ = ['EEPROM', 'HexFileError']
+
+POS_BAUDRATE_TABLE = 0x0000
+POS_PART_NUMBER = 0x01FF
+POS_PRODUCT_STRING = 0x0208
+POS_SERIAL_NUMBER = 0x0307
+POS_PRODUCT_ID = 0x0390
+POS_VENDOR_ID = 0x0392
+POS_VERSION = 0x0394
+POS_CFG_ATTRIBUTES = 0x03A1
+POS_MAX_POWER = 0x03A2
+POS_VENDOR_STRING = 0x03C3
+POS_LOCK_VALUE = 0x03FF
+
+class HexFileError(StandardError):
+ pass
+
+def checksum(line):
+ return sum(ord(c) for c in line) & 0xFF
+
+def _int_value(position, size, read=lambda x:x, write=lambda x:x):
+ def get(self):
+ return read(from_binary(self.get(position, size)))
+ def set(self, value):
+ self.set(position, to_binary(write(value), size))
+ return property(get, set)
+
+def _str_value(position, max_size):
+ def get(self):
+ size = from_binary(self.get(position, 1))
+ assert size <= (max_size + 2) and size >= 2
+ assert self.get(position + 1, 1) == '\x03', "Missing 0x03 at %04X" % (position + 1)
+ return self.get(position + 2, size - 2).decode('utf-16-le')
+
+ def set(self, value):
+ encoded = value.encode('utf-16-le')
+ assert len(encoded) <= max_size
+ self.set(position, chr(len(encoded) + 2) + '\x03' + encoded)
+
+ return property(get, set)
+
+class EEPROM(object):
+ START_ADDRESS = 0x3600
+ def __init__(self, content=None):
+ if isinstance(content, str) or content is None:
+ assert content is None or len(content) == cp210x.SIZE_EEPROM
+ self.content = content
+ elif isinstance(content, cp210x.Cp210xProgrammer):
+ self.content = content.get_eeprom_content()
+ else:
+ self.parse_hex_file(content.read())
+
+ def write_to_cp210x(self, cp210xDevice):
+ cp210xDevice.set_eeprom_content(self.content)
+
+ def parse_hex_file(self, hex_content):
+ self.content = ''
+ address = self.START_ADDRESS
+ for tag in hex_content.split('\n'):
+ if not tag.startswith(':'):
+ raise HexFileError("Line doesn't start with ':'")
+
+ try:
+ content = tag[1:].decode('hex')
+ except TypeError:
+ raise HexFileError("Hex data expected")
+
+ if len(content) < 5:
+ raise HexFileError("Line to short")
+
+ if checksum(content) != 0:
+ raise HexFileError("Checksum error")
+
+ size = from_binary(content[0])
+ tag_address = from_binary(content[1:3], le=False)
+ tag_type = from_binary(content[3:4])
+ line = content[4:-1]
+
+ if tag_type == 0x00:
+ if tag_address != address:
+ raise HexFileError("Expected address %04X but found %04X"
+ % (address, tag_address))
+ self.content += line
+ address += len(line)
+ elif tag_type == 0x01:
+ if size != 0 or len(line) != 0:
+ raise HexFileError("Defekt end tag")
+ break
+
+ else:
+ raise HexFileError("Unknown tag type %02X" % tag_type)
+
+ def build_hex_file(self):
+ for tag_start in range(0, len(self.content), 0x10):
+ line = self.content[tag_start:tag_start+0x10]
+ address = self.START_ADDRESS + tag_start
+ tag = (to_binary(len(line), 1) +
+ to_binary(address, le=False) +
+ '\x00' +
+ line)
+ cs = checksum(tag)
+ if cs == 0:
+ tag += '\x00'
+ else:
+ tag += chr(0x100 - cs)
+ yield ":%s\n" % tag.encode('hex')
+ yield ":00000001FF\n"
+
+ def write_hex_file(self, f):
+ if isinstance(f, str):
+ f = file(f, 'wb')
+ do_close = True
+ else:
+ do_close = False
+ for line in self.build_hex_file():
+ f.write(line)
+ if do_close:
+ f.close()
+
+ def read_hex_file(self, f):
+ if isinstance(f, str):
+ f = file(f, 'rb')
+ do_close = True
+ else:
+ do_close = False
+ self.parse_hex_file(f.read())
+ if do_close:
+ f.close()
+
+ def get(self, pos, length):
+ return self.content[pos:pos+length]
+
+ def set(self, pos, data):
+ self.content = (self.content[:pos] +
+ data +
+ self.content[pos + len(data):])
+
+ def _get_baudrate_table(self):
+ dat = self.get(POS_BAUDRATE_TABLE, cp210x.SIZE_BAUDRATE_TABLE)
+ return [cp210x.parse_baudrate_cfg(dat[pos:pos+cp210x.SIZE_BAUDRATE_CFG])
+ for pos in range(0, cp210x.SIZE_BAUDRATE_TABLE,
+ cp210x.SIZE_BAUDRATE_CFG)]
+ def _set_baudrate_table(self, baudrates):
+ assert len(baudrates) == cp210x.SIZE_BAUDRATES
+ self.set(POS_BAUDRATE_TABLE,
+ ''.join(cp210x.build_baudrate_cfg(*cfg) for cfg in baudrates))
+ baudrate_table = property(_get_baudrate_table, _set_baudrate_table)
+ product_string = _str_value(POS_PRODUCT_STRING, cp210x.SIZE_PRODUCT_STRING)
+ serial_number = _str_value(POS_SERIAL_NUMBER, cp210x.SIZE_SERIAL_NUMBER)
+ part_number = _int_value(POS_PART_NUMBER, 1)
+ product_id = _int_value(POS_PRODUCT_ID, 2)
+ vendor_id = _int_value(POS_VENDOR_ID, 2)
+ version = _int_value(POS_VERSION, 2,
+ cp210x.from_bcd2, cp210x.to_bcd2)
+ bus_powered = _int_value(POS_CFG_ATTRIBUTES, 1,
+ lambda a: bool(a & 0x40),
+ lambda a: iif(a, 0xC0, 0x80))
+ max_power = _int_value(POS_MAX_POWER, 1, lambda p: p*2, cp210x.to_div2)
+ vendor_string = _str_value(POS_VENDOR_STRING, cp210x.SIZE_VENDOR_STRING)
+ locked = _int_value(POS_LOCK_VALUE, 1,
+ lambda l: l == cp210x.LCK_LOCKED,
+ lambda b: iif(b, cp210x.LCK_LOCKED,
+ cp210x.LCK_UNLOCKED))
+
+ def get_values(self):
+ return dict((name, getattr(self, name)) for name, type in VALUES)
+
+ def set_values(self, values):
+ for name, value in values.items():
+ setattr(self, name, value)
+
+
diff --git a/contrib/cp210x-program/build/lib/cp210x/usb.py b/contrib/cp210x-program/build/lib/cp210x/usb.py
new file mode 100644
index 0000000..be70f82
--- /dev/null
+++ b/contrib/cp210x-program/build/lib/cp210x/usb.py
@@ -0,0 +1,274 @@
+# Python interface for "usb.h" version 0.1.4.4.4
+#
+# Copyright (c) 2005 Robert Hoelzl <robert.hoelzl@gmx.de>
+# Copyright (c) 2007 Johannes Hoelzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+
+from ctypes import *
+import sys
+
+class LibUsbNotInstalled(OSError):
+ pass
+
+try:
+ if sys.platform == 'darwin':
+ PATH_MAX = 1024
+ dll=cdll.LoadLibrary("libusb.dylib")
+ elif sys.platform == 'linux2':
+ PATH_MAX = 4096
+ dll=cdll.LoadLibrary("libusb.so")
+ else:
+ raise NotImplementedError("Platform %s not supported by usb.py" % sys.platform)
+except OSError:
+ raise LibUsbNotInstalled()
+
+
+# helper functions
+def func(f, *args, **retval):
+ f.restype = retval.get('retval', None)
+ f.argtypes = args
+ if retval.has_key('rename'): globals()[retval['rename']] = f
+ else: globals()[f.__name__[4:]] = f
+
+# constants
+CLASS_PER_INTERFACE = 0
+USB_CLASS_AUDIO = 1
+CLASS_COMM = 2
+CLASS_HID = 3
+CLASS_PRINTER = 7
+CLASS_PTP = 6
+CLASS_MASS_STORAGE = 8
+CLASS_HUB = 9
+CLASS_DATA = 10
+CLASS_VENDOR_SPEC = 0xff
+
+DT_DEVICE = 0x01
+DT_CONFIG = 0x02
+DT_STRING = 0x03
+DT_INTERFACE = 0x04
+DT_ENDPOINT = 0x05
+
+DT_HID = 0x21
+DT_REPORT = 0x22
+DT_PHYSICAL = 0x23
+DT_HUB = 0x29
+
+DT_DEVICE_SIZE = 18
+DT_CONFIG_SIZE = 9
+DT_INTERFACE_SIZE = 9
+DT_ENDPOINT_SIZE = 7
+DT_ENDPOINT_AUDIO_SIZE = 9 # Audio extension
+DT_HUB_NONVAR_SIZE = 7
+
+
+class descriptor_header(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8) ]
+
+
+class string_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("wData", c_uint*1) ]
+
+class hid_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("bcdHID", c_uint16),
+ ("bCountryCode", c_uint8),
+ ("bNumDescriptors", c_uint8) ]
+
+MAXENDPOINTS = 32
+class endpoint_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("bEndpointAddress", c_uint8),
+ ("bmAttributes", c_uint8),
+ ("wMaxPacketSize", c_uint16),
+ ("bInterval", c_uint8),
+ ("bRefresh", c_uint8),
+ ("bSynchAddress", c_uint8),
+
+ ("extra", POINTER(c_uint8)),
+ ("extralen", c_int) ]
+
+
+ENDPOINT_ADDRESS_MASK = 0x0f # in bEndpointAddress
+ENDPOINT_DIR_MASK = 0x80
+
+ENDPOINT_TYPE_MASK = 0x03 # in bmAttributes
+ENDPOINT_TYPE_CONTROL = 0
+ENDPOINT_TYPE_ISOCHRONOUS = 1
+ENDPOINT_TYPE_BULK = 2
+ENDPOINT_TYPE_INTERRUPT = 3
+
+MAXINTERFACES = 32
+class interface_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("bInterfaceNumber", c_uint8),
+ ("bAlternateSetting", c_uint8),
+ ("bNumEndpoints", c_uint8),
+ ("bInterfaceClass", c_uint8),
+ ("bInterfaceSubClass", c_uint8),
+ ("bInterfaceProtocol", c_uint8),
+ ("iInterface", c_uint8),
+
+ ("endpoint", POINTER(endpoint_descriptor)),
+
+ ("extra", POINTER(c_uint8)),
+ ("extralen", c_int) ]
+
+MAXALTSETTING = 128 # Hard limit
+class interface(Structure): _fields_ = [
+ ("altsetting", POINTER(interface_descriptor)),
+
+ ("num_altsetting", c_int) ]
+
+MAXCONFIG = 8
+class config_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("wTotalLength", c_uint16),
+ ("bNumInterfaces", c_uint8),
+ ("bConfigurationValue", c_uint8),
+ ("iConfiguration", c_uint16),
+ ("bmAttributes", c_uint8),
+ ("MaxPower", c_uint8),
+
+ ("interface", POINTER(interface)),
+
+ ("extra", POINTER(c_uint8)), # Extra descriptors
+ ("extralen", c_int) ]
+
+class device_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("bcdUSB", c_uint16),
+ ("bDeviceClass", c_uint8),
+ ("bDeviceSubClass", c_uint8),
+ ("bDeviceProtocol", c_uint8),
+ ("bMaxPacketSize0", c_uint8),
+ ("idVendor", c_uint16),
+ ("idProduct", c_uint16),
+ ("bcdDevice", c_uint16),
+ ("iManufacturer", c_uint8),
+ ("iProduct", c_uint8),
+ ("iSerialNumber", c_uint8),
+ ("bNumConfigurations", c_uint8) ]
+
+class ctrl_setup(Structure): _fields_ = [
+ ("bRequestType", c_uint8),
+ ("bRequest", c_uint8),
+ ("wValue", c_uint16),
+ ("wIndex", c_uint16),
+ ("wLength", c_uint16) ]
+
+
+REQ_GET_STATUS = 0x00
+REQ_CLEAR_FEATURE = 0x01
+# 0x02 is reserved
+REQ_SET_FEATURE = 0x03
+# 0x04 is reserved
+REQ_SET_ADDRESS = 0x05
+REQ_GET_DESCRIPTOR = 0x06
+REQ_SET_DESCRIPTOR = 0x07
+REQ_GET_CONFIGURATION = 0x08
+REQ_SET_CONFIGURATION = 0x09
+REQ_GET_INTERFACE = 0x0A
+REQ_SET_INTERFACE = 0x0B
+REQ_SYNCH_FRAME = 0x0C
+
+TYPE_STANDARD = (0x00 << 5)
+TYPE_CLASS = (0x01 << 5)
+TYPE_VENDOR = (0x02 << 5)
+TYPE_RESERVED = (0x03 << 5)
+
+RECIP_DEVICE = 0x00
+RECIP_INTERFACE = 0x01
+RECIP_ENDPOINT = 0x02
+RECIP_OTHER = 0x03
+
+ENDPOINT_IN = 0x80
+ENDPOINT_OUT = 0x00
+
+# Error codes
+ERROR_BEGIN = 500000
+
+#if 1
+#define USB_LE16_TO_CPU(x) do { x = ((x & 0xff) << 8) | ((x & 0xff00) >> 8); } while(0)
+#else
+#define USB_LE16_TO_CPU(x)
+#endif
+
+device_p = POINTER("device")
+bus_p = POINTER("bus")
+
+class device(Structure): _fields_ = [
+ ("next", device_p),
+ ("prev", device_p),
+ ("filename", c_char*(PATH_MAX + 1)),
+
+ ("bus", bus_p),
+ ("descriptor", device_descriptor),
+ ("config", POINTER(config_descriptor)),
+
+ ("dev", c_void_p), # Darwin support
+
+ ("devnum", c_char),
+
+ ("num_children", c_uint8),
+ ("children", POINTER(device_p)) ]
+SetPointerType(device_p, device)
+
+class bus(Structure): _fields_ = [
+ ("next", bus_p),
+ ("prev", bus_p),
+
+ ("dirname", c_char*(PATH_MAX + 1)),
+
+ ("devices", device_p),
+ ("location", c_uint),
+
+ ("root_dev", device_p) ]
+SetPointerType(bus_p, bus)
+
+
+dev_handle_p = c_void_p
+
+
+func(dll.usb_open, device_p, retval=dev_handle_p, rename="_open")
+func(dll.usb_close, dev_handle_p, retval=c_int)
+func(dll.usb_get_string, dev_handle_p, c_int, c_int, c_char_p, c_int, retval=c_int)
+func(dll.usb_get_string_simple, dev_handle_p, c_int, c_char_p, c_int, retval=c_int)
+func(dll.usb_get_descriptor_by_endpoint, dev_handle_p, c_int, c_uint8, c_uint8, c_void_p, c_int, retval=c_int)
+func(dll.usb_get_descriptor, dev_handle_p, c_uint8, c_uint8, c_void_p, c_int, retval=c_int)
+
+func(dll.usb_bulk_write, dev_handle_p, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_bulk_read, dev_handle_p, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_interrupt_write, dev_handle_p, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_interrupt_read, dev_handle_p, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_control_msg, dev_handle_p, c_int, c_int, c_int, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_set_configuration, dev_handle_p, c_int, retval=c_int)
+func(dll.usb_claim_interface, dev_handle_p, c_int, retval=c_int)
+func(dll.usb_release_interface, dev_handle_p, c_int, retval=c_int)
+func(dll.usb_set_altinterface, dev_handle_p, c_int, retval=c_int)
+func(dll.usb_resetep, dev_handle_p, c_uint16, retval=c_int)
+func(dll.usb_clear_halt, dev_handle_p, c_uint16, retval=c_int)
+func(dll.usb_reset, dev_handle_p, retval=c_int)
+
+func(dll.usb_strerror, retval=c_char_p)
+
+func(dll.usb_init)
+func(dll.usb_set_debug, c_int)
+func(dll.usb_find_busses, retval=c_int)
+func(dll.usb_find_devices, retval=c_int)
+func(dll.usb_device, dev_handle_p, retval=device_p, rename="get_device")
+func(dll.usb_get_busses, retval=bus_p)
+
+func(dll.usb_detach_kernel_driver_np, dev_handle_p, c_int, retval=c_int)
+
+# workaround for bug in ctypes 0.9.6 (cannot create functions with c_void_p as retval)
+def open(dev):
+ return cast(_open(dev), dev_handle_p)
diff --git a/contrib/cp210x-program/build/lib/cp210x/valuefile.py b/contrib/cp210x-program/build/lib/cp210x/valuefile.py
new file mode 100644
index 0000000..ae665d2
--- /dev/null
+++ b/contrib/cp210x-program/build/lib/cp210x/valuefile.py
@@ -0,0 +1,234 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2007 Johannes Hölzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+
+# For documentation of the baudrate table see:
+#
+# [AN205] Silicon Labs Application Note 205 Rev. 0.3
+# http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an205.pdf
+
+import re
+from ConfigParser import ConfigParser
+
+import cp210x
+from cp210x import VALUES, SIZE_BAUDRATES
+
+__all__ = ['read_file', 'write_file', 'update_values', 'PrescalerIsZero',
+ 'ValuesFileError']
+
+class ValuesError(StandardError):
+ pass
+
+class PrescalerIsZero(ValuesError):
+ pass
+
+class ValuesFileError(ValuesError):
+ pass
+
+version_pattern = re.compile(r'^\s*(\d\d?)\.(\d\d?)\s*$')
+def read_version(s):
+ match = version_pattern.match(s)
+ if match is None:
+ raise ValueError("Version does not match 'xx.yy'")
+ return (int(match.group(1)), int(match.group(2)))
+def write_version(v):
+ return "%d.%02d" % v
+
+def read_hex(s):
+ return int(s.strip(), 16)
+
+def write_hex(num):
+ return "%04X" % num
+
+def write_bool(b):
+ if b:
+ return 'yes'
+ else:
+ return 'no'
+
+def read_bool(s):
+ s = s.strip().lower()
+ if s not in ['true', 'yes', 'false', 'no']:
+ raise ValueError("Boolean must be either 'true', 'yes', 'false' or 'no'.")
+ return s in ['true', 'yes']
+
+def read_baudrate_info(s):
+ values = s.split(',')
+ if len(values) != 3:
+ raise ValueError("Baudrate info must be three comma-separated items")
+ try:
+ baudgen = read_hex(values[0])
+ except ValueError:
+ raise ValueError("The first baudrate info must be a hex-value")
+ try:
+ timer0 = read_hex(values[1])
+ except ValueError:
+ raise ValueError("The second baudrate info must be a hex-value")
+ try:
+ prescale = int(values[2])
+ except ValueError:
+ raise ValueError("The thirdbaudrate info must be a number")
+ return (baudgen, timer0, prescale)
+
+TYPES = {
+ 'boolean': (read_bool, write_bool),
+ 'int': (int, str),
+ 'id': (read_hex, write_hex),
+ 'string': (str, str),
+ 'version': (read_version, write_version),
+}
+
+def read_file(fp):
+ cp = ConfigParser()
+ if isinstance(fp, str):
+ cp.read([fp])
+ else:
+ cp.readfp(fp)
+
+ values = {}
+
+ for name, type in VALUES:
+ if name is 'baudrate_table':
+ continue
+ reader, _ = TYPES[type]
+ if cp.has_option('usb device', name):
+ try:
+ values[name] = reader(cp.get('usb device', name))
+ except ValueError, err:
+ raise ValuesFileError("Key '%s': %s" % (name, str(err)))
+
+ if cp.has_section('baudrate table'):
+ baudrate_table = []
+ for name, value in cp.items('baudrate table'):
+ try:
+ baudrate = int(name)
+ except ValueError:
+ raise ValuesFileError("Key names in 'baudrate table' must be"
+ " baudrate numbers.")
+ try:
+ baudrate_table.append(read_baudrate_info(value) + (baudrate, ))
+ except ValueError, err:
+ raise ValuesFileError("Wrong baudrate info %i: %s"
+ % (baudrate, str(err)))
+ baudrate_table.sort(key=(lambda i: i[3]), reverse=True)
+
+ values['baudrate_table'] = baudrate_table
+ return values
+
+def write_file(fp, values):
+ fp.write("[usb device]\n")
+
+ for name, type in VALUES:
+ if name == 'baudrate_table':
+ continue
+ _, writer = TYPES[type]
+ if name in values:
+ fp.write("%s = %s\n" % (name, writer(values[name])))
+
+ if 'baudrate_table' in values:
+ fp.write("\n")
+ fp.write("[baudrate table]\n")
+ for (baudgen, timegen, prescaler,
+ baudrate) in sorted(values['baudrate_table'], key=(lambda i: i[3]),
+ reverse=True):
+ fp.write("%7d = %04X, %04X, %d # %s\n"
+ % (baudrate, baudgen, timegen, prescaler,
+ show_baudrate(baudgen, timegen, prescaler)))
+
+def calc_baudrate(baudgen, timegen, prescaler):
+ # This formulas are from AN205 page 5.
+ if prescaler == 0:
+ raise PrescalerIsZero("Prescaler is 0")
+ baudrate = (24000000. / prescaler) / (0x10000 - baudgen)
+ return (baudrate, (0x10000 - timegen) * 2)
+
+def show_baudrate(baudgen, timegen, prescaler):
+ try:
+ baudrate, timeout = calc_baudrate(baudgen, timegen, prescaler)
+ except PrescalerIsZero:
+ return "Wrong data, Prescaler is 0."
+ if timeout >= 1000:
+ timeout = "%1.3f ms" % (float(timeout) / 1000)
+ else:
+ timeout = "%d us" % timeout
+ if baudrate is None:
+ return ", %s" % (baudrate, timeout)
+ else:
+ return "%7.0f Baud, %s" % (baudrate, timeout)
+
+def update_values(v, new, dev):
+ old_baudrate_table = v.get('baudrate_table')
+ new_baudrate_table = new.get('baudrate_table')
+
+ v.update(new)
+
+ # update baudrate table
+ # it is needed, that the baudrate table has 32 entries when it is written
+ # to the eeprom or device.
+ if ((old_baudrate_table is not None or new_baudrate_table is not None) and
+ (new_baudrate_table is None or
+ len(new_baudrate_table) < SIZE_BAUDRATES)):
+
+ if old_baudrate_table is not None:
+ if len(old_baudrate_table) < SIZE_BAUDRATES:
+ baudrate_table = old_baudrate_table
+ else:
+ baudrate_table = list(merge_baudrate_table(dev.baudrate_table,
+ old_baudrate_table))
+ else:
+ baudrate_table = dev.baudrate_table
+
+ if new_baudrate_table:
+ baudrate_table = list(merge_baudrate_table(baudrate_table,
+ new_baudrate_table))
+ v['baudrate_table'] = baudrate_table
+
+
+
+def merge_baudrate_table(old, new):
+ for (old_info, (start, stop)) in zip(old, REQUEST_BAUDRATE_RANGES):
+ for baudgen, timer, prescaler, baudrate in new:
+ if ((start is None or baudrate <= start) and
+ baudrate >= stop):
+ yield (baudgen, timer, prescaler, baudrate)
+ break
+ else:
+ yield old_info
+
+REQUEST_BAUDRATE_RANGES = [
+# The table data is from AN205 Table 1 on page 1.
+# Start End Default Baudrate
+ (None, 2457601), # Undefined
+ (2457600, 1474561), # Undefined
+ (1474560, 1053258), # Undefined
+ (1053257, 670255), # 921600
+ ( 670254, 567139), # 576000
+ ( 567138, 491521), # 500000
+ ( 491520, 273067), # 460800
+ ( 273066, 254235), # 256000
+ ( 254234, 237833), # 250000
+ ( 237832, 156869), # 230400
+ ( 156868, 129348), # 153600
+ ( 129347, 117029), # 128000
+ ( 117028, 77609), # 115200
+ ( 77608, 64112), # 76800
+ ( 64111, 58054), # 64000
+ ( 58053, 56281), # 57600
+ ( 56280, 51559), # 56000
+ ( 51558, 38602), # 51200
+ ( 38601, 28913), # 38400
+ ( 28912, 19251), # 28800
+ ( 19250, 16063), # 19200
+ ( 16062, 14429), # 16000
+ ( 14428, 9613), # 14400
+ ( 9612, 7208), # 9600
+ ( 7207, 4804), # 7200
+ ( 4803, 4001), # 4800
+ ( 4000, 2401), # 4000
+ ( 2400, 1801), # 2400
+ ( 1800, 1201), # 1800
+ ( 1200, 601), # 1200
+ ( 600, 301), # 600
+ ( 300, 57), # 300
+]
diff --git a/contrib/cp210x-program/build/scripts-2.6/cp210x-program b/contrib/cp210x-program/build/scripts-2.6/cp210x-program
new file mode 100755
index 0000000..524a123
--- /dev/null
+++ b/contrib/cp210x-program/build/scripts-2.6/cp210x-program
@@ -0,0 +1,266 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Copyright (c) 2007 Johannes Hölzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+"""\
+Provides access to the EEPROM in an Silabs CP210x. The data can be directly to
+the device read or written.
+"""
+__author__ = "Johannes Hölzl <johannes.hoelzl@gmx.de>"
+__license__ = "GNU LGPL"
+__version__ = "0.2"
+
+import sys
+import re
+import string
+import traceback
+import optparse
+
+from cp210x import usb, valuefile, cp210x
+from cp210x.eeprom import EEPROM, HexFileError
+from cp210x.valuefile import read_baudrate_info, update_values, ValuesFileError
+TRANS_UNDERSCORE = string.maketrans('_', '-')
+
+ERR_OK = 0
+ERR_WRONG_INPUT = -1
+ERR_INTERNAL = -2
+ERR_DEVICE_LOCKED = -3
+ERR_DEVICE_NOT_FOUND = -4
+ERR_DEVICE_ERROR = -5
+
+def error(message, retval=-1):
+ sys.stderr.write(message + "\n")
+ sys.exit(retval)
+
+class Option(optparse.Option):
+ TYPES = list(optparse.Option.TYPES)
+ TYPE_CHECKER = dict(optparse.Option.TYPE_CHECKER)
+ for type, (reader, _) in valuefile.TYPES.items():
+ if type in TYPES:
+ continue
+ TYPES.append(type)
+ def checker(self, name, value, reader=reader):
+ try:
+ return reader(value)
+ except ValueError, err:
+ raise optparse.OptionValueError("option %s: %s" % (name,
+ str(err)))
+ TYPE_CHECKER[type] = checker
+
+class OptionParser(optparse.OptionParser):
+ def error(self, msg):
+ error(msg, ERR_WRONG_INPUT)
+
+ def __init__(self, *args, **kwargs):
+ if 'option_class' not in kwargs:
+ kwargs['option_class'] = Option
+ optparse.OptionParser.__init__(self, *args, **kwargs)
+
+def input_file(arg):
+ if arg is None or arg == '-':
+ return sys.stdin
+ else:
+ return file(arg, 'rb')
+
+def output_file(arg):
+ if arg is None or arg == '-':
+ return sys.stdout
+ else:
+ return file(arg, 'wb')
+
+def options_to_values(options):
+ values = {}
+ for name, type in cp210x.VALUES:
+ if name == "baudrate_table":
+ continue
+ value = getattr(options, name)
+ if value is not None:
+ values[name] = value
+
+ if options.baudrate_table:
+ baudrate_table = []
+ for s in options.baudrate_table:
+ try:
+ baudrate, info = s.split(':')
+ except TypeError:
+ error("option --set-baudrate: need two parts separated by ':'",
+ ERR_WRONG_INPUT)
+ try:
+ baudrate_table.append(read_baudrate_info(info) +
+ (int(baudrate), ))
+ except ValueError, err:
+ error("option --set-baudrate: %s" % str(err),
+ ERR_WRONG_INPUT)
+
+ values['baudrate_table'] = baudrate_table
+ return values
+
+def find_device(patterns):
+ usb_patterns = []
+ for pattern in patterns:
+ if ':' in pattern:
+ try:
+ vidString, pidString = pattern.split(':')
+ vid = int(vidString, 16)
+ pid = int(pidString, 16)
+
+ except (TypeError, ValueError):
+ error("Match be either 'ddd/ddd' or 'hhhh:hhhh'.",
+ ERR_WRONG_INPUT)
+
+ usb_patterns.append(dict(idVendor=vid, idProduct=pid))
+ elif '/' in pattern:
+ try:
+ bus, device = pattern.split('/')
+ usb_patterns.append( (bus, device) )
+ except (TypeError, ValueError):
+ error("Match be either 'ddd/ddd' or 'hhhh:hhhh'.",
+ ERR_WRONG_INPUT)
+ else:
+ error("Match be either 'ddd/ddd' or 'hhhh:hhhh'.",
+ ERR_WRONG_INPUT)
+
+ for dev in cp210x.Cp210xProgrammer.list_devices(usb_patterns):
+ return dev
+
+ error("No devices found", ERR_DEVICE_NOT_FOUND)
+
+def read_cp210x(options):
+ dev = find_device(options.match)
+ dev.open()
+ try:
+ eeprom = EEPROM(dev)
+ finally:
+ dev.close()
+
+ if options.hex_output:
+ eeprom.write_hex_file(output_file(options.hex_output))
+ if options.ini_output or not options.hex_output:
+ valuefile.write_file(output_file(options.ini_output), eeprom.get_values())
+
+def write_cp210x(options):
+ dev = find_device(options.match)
+ dev.open()
+ try:
+ if options.hex_input or options.force_eeprom:
+
+ if options.hex_input:
+ eeprom = EEPROM(input_file(options.hex_input))
+ else:
+ eeprom = EEPROM(dev)
+
+ values = eeprom.get_values()
+ if options.ini_input:
+ values = valuefile.read_file(input_file(options.ini_input))
+ update_values(values, options_to_values(options), eeprom)
+
+ eeprom.set_values(values)
+
+ eeprom.write_to_cp210x(dev)
+ if options.reset_device:
+ dev.reset()
+
+ else:
+ if options.ini_input:
+ values = valuefile.read_file(input_file(options.ini_input))
+ else:
+ values = {}
+ update_values(values, options_to_values(options), dev)
+ dev.set_values(values)
+
+ if options.reset_device:
+ dev.reset()
+ finally:
+ dev.close()
+
+def change_hexfile(options):
+ eeprom = EEPROM(input_file(options.hex_input))
+ values = {}
+ if options.ini_input:
+ update_values(values,
+ valuefile.read_file(input_file(options.ini_input)),
+ eeprom)
+ update_values(values, options_to_values(options), eeprom)
+ eeprom.set_values(values)
+ if options.ini_output:
+ valuefile.write_file(output_file(options.ini_output),
+ eeprom.get_values())
+ eeprom.write_hex_file(output_file(options.hex_output))
+
+def parse_hexfile(options):
+ eeprom = EEPROM(input_file(options.hex_input))
+ valuefile.write_file(output_file(options.ini_output), eeprom.get_values())
+
+parser = OptionParser(version=__version__, description=__doc__)
+parser.add_option("-r", "--read-cp210x", const=read_cp210x,
+ dest="action", action="store_const")
+parser.add_option("-w", "--write-cp210x", const=write_cp210x,
+ dest="action", action="store_const")
+parser.add_option("-c", "--change-hexfile", const=change_hexfile,
+ dest="action", action="store_const")
+parser.add_option("-p", "--parse-hexfile", const=parse_hexfile,
+ dest="action", action="store_const")
+parser.add_option("-F", "--hex-input", metavar="FILE")
+parser.add_option("-f", "--hex-output", metavar="FILE")
+parser.add_option("-I", "--ini-input", metavar="FILE")
+parser.add_option("-i", "--ini-output", metavar="FILE")
+for name, type in cp210x.VALUES:
+ if name == 'baudrate_table':
+ continue
+ parser.add_option("--set-" + name.translate(TRANS_UNDERSCORE),
+ dest=name, metavar=name.upper(), type=type)
+parser.add_option("--set-baudrate", action="append", dest="baudrate_table")
+parser.add_option("-m", "--match", action="append", metavar="PATTERN")
+parser.add_option("--reset-device", action="store_true")
+parser.add_option("--force-eeprom", action="store_true")
+
+parser.set_defaults(
+ action=read_cp210x,
+ hex_input=None,
+ hex_output=None,
+ ini_input=None,
+ ini_output=None,
+ match=[],
+ baudrate_table=[],
+ reset_device=False,
+ force_eeprom=False,
+)
+
+def main():
+ (options, _) = parser.parse_args()
+ if not options.match:
+ options.match = ['10C4:EA60', '10C4:EA61']
+ options.action(options)
+
+if __name__ == '__main__':
+ try:
+ usb.init()
+ main()
+
+ except cp210x.DeviceLocked:
+ error("Can not write data to device. Device is locked.",
+ ERR_DEVICE_LOCKED)
+
+ except cp210x.Cp210xError, err:
+ error(str(err), ERR_DEVICE_ERROR)
+
+ except IOError, err:
+ error(str(err), ERR_OTHER)
+
+ except HexFileError, err:
+ error(str(err), ERR_OTHER)
+
+ except ValuesFileError, err:
+ error(str(err), ERR_OTHER)
+
+ except usb.LibUsbNotInstalled:
+ error("Package 'libusb' not installed.")
+
+ except SystemExit, err:
+ raise
+
+ except:
+ traceback.print_exc()
+ sys.exit(ERR_INTERNAL)
+
diff --git a/contrib/cp210x-program/cp210x-program b/contrib/cp210x-program/cp210x-program
new file mode 100755
index 0000000..be97be8
--- /dev/null
+++ b/contrib/cp210x-program/cp210x-program
@@ -0,0 +1,266 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (c) 2007 Johannes Hölzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+"""\
+Provides access to the EEPROM in an Silabs CP210x. The data can be directly to
+the device read or written.
+"""
+__author__ = "Johannes Hölzl <johannes.hoelzl@gmx.de>"
+__license__ = "GNU LGPL"
+__version__ = "0.2"
+
+import sys
+import re
+import string
+import traceback
+import optparse
+
+from cp210x import usb, valuefile, cp210x
+from cp210x.eeprom import EEPROM, HexFileError
+from cp210x.valuefile import read_baudrate_info, update_values, ValuesFileError
+TRANS_UNDERSCORE = string.maketrans('_', '-')
+
+ERR_OK = 0
+ERR_WRONG_INPUT = -1
+ERR_INTERNAL = -2
+ERR_DEVICE_LOCKED = -3
+ERR_DEVICE_NOT_FOUND = -4
+ERR_DEVICE_ERROR = -5
+
+def error(message, retval=-1):
+ sys.stderr.write(message + "\n")
+ sys.exit(retval)
+
+class Option(optparse.Option):
+ TYPES = list(optparse.Option.TYPES)
+ TYPE_CHECKER = dict(optparse.Option.TYPE_CHECKER)
+ for type, (reader, _) in valuefile.TYPES.items():
+ if type in TYPES:
+ continue
+ TYPES.append(type)
+ def checker(self, name, value, reader=reader):
+ try:
+ return reader(value)
+ except ValueError, err:
+ raise optparse.OptionValueError("option %s: %s" % (name,
+ str(err)))
+ TYPE_CHECKER[type] = checker
+
+class OptionParser(optparse.OptionParser):
+ def error(self, msg):
+ error(msg, ERR_WRONG_INPUT)
+
+ def __init__(self, *args, **kwargs):
+ if 'option_class' not in kwargs:
+ kwargs['option_class'] = Option
+ optparse.OptionParser.__init__(self, *args, **kwargs)
+
+def input_file(arg):
+ if arg is None or arg == '-':
+ return sys.stdin
+ else:
+ return file(arg, 'rb')
+
+def output_file(arg):
+ if arg is None or arg == '-':
+ return sys.stdout
+ else:
+ return file(arg, 'wb')
+
+def options_to_values(options):
+ values = {}
+ for name, type in cp210x.VALUES:
+ if name == "baudrate_table":
+ continue
+ value = getattr(options, name)
+ if value is not None:
+ values[name] = value
+
+ if options.baudrate_table:
+ baudrate_table = []
+ for s in options.baudrate_table:
+ try:
+ baudrate, info = s.split(':')
+ except TypeError:
+ error("option --set-baudrate: need two parts separated by ':'",
+ ERR_WRONG_INPUT)
+ try:
+ baudrate_table.append(read_baudrate_info(info) +
+ (int(baudrate), ))
+ except ValueError, err:
+ error("option --set-baudrate: %s" % str(err),
+ ERR_WRONG_INPUT)
+
+ values['baudrate_table'] = baudrate_table
+ return values
+
+def find_device(patterns):
+ usb_patterns = []
+ for pattern in patterns:
+ if ':' in pattern:
+ try:
+ vidString, pidString = pattern.split(':')
+ vid = int(vidString, 16)
+ pid = int(pidString, 16)
+
+ except (TypeError, ValueError):
+ error("Match be either 'ddd/ddd' or 'hhhh:hhhh'.",
+ ERR_WRONG_INPUT)
+
+ usb_patterns.append(dict(idVendor=vid, idProduct=pid))
+ elif '/' in pattern:
+ try:
+ bus, device = pattern.split('/')
+ usb_patterns.append( (bus, device) )
+ except (TypeError, ValueError):
+ error("Match be either 'ddd/ddd' or 'hhhh:hhhh'.",
+ ERR_WRONG_INPUT)
+ else:
+ error("Match be either 'ddd/ddd' or 'hhhh:hhhh'.",
+ ERR_WRONG_INPUT)
+
+ for dev in cp210x.Cp210xProgrammer.list_devices(usb_patterns):
+ return dev
+
+ error("No devices found", ERR_DEVICE_NOT_FOUND)
+
+def read_cp210x(options):
+ dev = find_device(options.match)
+ dev.open()
+ try:
+ eeprom = EEPROM(dev)
+ finally:
+ dev.close()
+
+ if options.hex_output:
+ eeprom.write_hex_file(output_file(options.hex_output))
+ if options.ini_output or not options.hex_output:
+ valuefile.write_file(output_file(options.ini_output), eeprom.get_values())
+
+def write_cp210x(options):
+ dev = find_device(options.match)
+ dev.open()
+ try:
+ if options.hex_input or options.force_eeprom:
+
+ if options.hex_input:
+ eeprom = EEPROM(input_file(options.hex_input))
+ else:
+ eeprom = EEPROM(dev)
+
+ values = eeprom.get_values()
+ if options.ini_input:
+ values = valuefile.read_file(input_file(options.ini_input))
+ update_values(values, options_to_values(options), eeprom)
+
+ eeprom.set_values(values)
+
+ eeprom.write_to_cp210x(dev)
+ if options.reset_device:
+ dev.reset()
+
+ else:
+ if options.ini_input:
+ values = valuefile.read_file(input_file(options.ini_input))
+ else:
+ values = {}
+ update_values(values, options_to_values(options), dev)
+ dev.set_values(values)
+
+ if options.reset_device:
+ dev.reset()
+ finally:
+ dev.close()
+
+def change_hexfile(options):
+ eeprom = EEPROM(input_file(options.hex_input))
+ values = {}
+ if options.ini_input:
+ update_values(values,
+ valuefile.read_file(input_file(options.ini_input)),
+ eeprom)
+ update_values(values, options_to_values(options), eeprom)
+ eeprom.set_values(values)
+ if options.ini_output:
+ valuefile.write_file(output_file(options.ini_output),
+ eeprom.get_values())
+ eeprom.write_hex_file(output_file(options.hex_output))
+
+def parse_hexfile(options):
+ eeprom = EEPROM(input_file(options.hex_input))
+ valuefile.write_file(output_file(options.ini_output), eeprom.get_values())
+
+parser = OptionParser(version=__version__, description=__doc__)
+parser.add_option("-r", "--read-cp210x", const=read_cp210x,
+ dest="action", action="store_const")
+parser.add_option("-w", "--write-cp210x", const=write_cp210x,
+ dest="action", action="store_const")
+parser.add_option("-c", "--change-hexfile", const=change_hexfile,
+ dest="action", action="store_const")
+parser.add_option("-p", "--parse-hexfile", const=parse_hexfile,
+ dest="action", action="store_const")
+parser.add_option("-F", "--hex-input", metavar="FILE")
+parser.add_option("-f", "--hex-output", metavar="FILE")
+parser.add_option("-I", "--ini-input", metavar="FILE")
+parser.add_option("-i", "--ini-output", metavar="FILE")
+for name, type in cp210x.VALUES:
+ if name == 'baudrate_table':
+ continue
+ parser.add_option("--set-" + name.translate(TRANS_UNDERSCORE),
+ dest=name, metavar=name.upper(), type=type)
+parser.add_option("--set-baudrate", action="append", dest="baudrate_table")
+parser.add_option("-m", "--match", action="append", metavar="PATTERN")
+parser.add_option("--reset-device", action="store_true")
+parser.add_option("--force-eeprom", action="store_true")
+
+parser.set_defaults(
+ action=read_cp210x,
+ hex_input=None,
+ hex_output=None,
+ ini_input=None,
+ ini_output=None,
+ match=[],
+ baudrate_table=[],
+ reset_device=False,
+ force_eeprom=False,
+)
+
+def main():
+ (options, _) = parser.parse_args()
+ if not options.match:
+ options.match = ['10C4:EA60', '10C4:EA61','413C:9500' ]
+ options.action(options)
+
+if __name__ == '__main__':
+ try:
+ usb.init()
+ main()
+
+ except cp210x.DeviceLocked:
+ error("Can not write data to device. Device is locked.",
+ ERR_DEVICE_LOCKED)
+
+ except cp210x.Cp210xError, err:
+ error(str(err), ERR_DEVICE_ERROR)
+
+ except IOError, err:
+ error(str(err), ERR_OTHER)
+
+ except HexFileError, err:
+ error(str(err), ERR_OTHER)
+
+ except ValuesFileError, err:
+ error(str(err), ERR_OTHER)
+
+ except usb.LibUsbNotInstalled:
+ error("Package 'libusb' not installed.")
+
+ except SystemExit, err:
+ raise
+
+ except:
+ traceback.print_exc()
+ sys.exit(ERR_INTERNAL)
+
diff --git a/contrib/cp210x-program/cp210x-program.doap b/contrib/cp210x-program/cp210x-program.doap
new file mode 100644
index 0000000..2e84f2e
--- /dev/null
+++ b/contrib/cp210x-program/cp210x-program.doap
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Project
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns="http://usefulinc.com/ns/doap#"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
+ >
+
+ <name>CP210x Programmer</name>
+ <shortname>cp210x-program</shortname>
+
+ <homepage rdf:resource="http://cp210x-program.sourceforge.net/" />
+ <created>2007-04-02</created>
+
+ <shortdesc xml:lang="en">
+ Provides access to the EEPROM in an Silabs CP210x
+ </shortdesc>
+
+ <bug-database rdf:resource="http://sourceforge.net/tracker/?group_id=193093" />
+ <download-page rdf:resource="http://sourceforge.net/project/showfiles.php?group_id=193093" />
+
+ <description xml:lang="en">
+The goal of this library is to provide access to the EEPROM of an Silabs CP210x
+under Linux.
+
+The CP210x is an USB-to-serial chip used in a lot of USB devices (similar to
+FTDIs and PL2303). The CP210x has a EEPROM on the chip which can be programmed
+via USB. Silabs provides already a library and gui programm to program this
+EEPROM, but only for windows.
+
+For more information see:
+* http://www.silabs.com/tgwWebApp/public/web_content/products/Microcontrollers/Interface/en/interface.htm
+* http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an144.pdf
+
+Requires:
+* libusb: http://libusb.sourceforge.net/
+* ctypes: http://starship.python.net/crew/theller/ctypes/
+ </description>
+
+<!-- <mailing-list rdf:resource="http://" /> -->
+
+ <maintainer>
+ <foaf:Person>
+ <foaf:name>Johannes Hölzl</foaf:name>
+ <foaf:homepage rdf:resource="http://hoelzl-bros.de/~johannes/" />
+ </foaf:Person>
+ </maintainer>
+
+ <repository>
+ <SVNRepository>
+ <location rdf:resource="http://cp210x-program.svn.sourceforge.net/" />
+ </SVNRepository>
+ </repository>
+
+ <license rdf:resource="http://usefulinc.com/doap/licenses/lgpl" />
+
+ <programming-language>
+ Python
+ </programming-language>
+
+ <os>
+ Linux
+ </os>
+
+ <os>
+ FreeBSD
+ </os>
+
+ <os>
+ Mac OS X
+ </os>
+
+<!-- <bug-database rdf:resource="http://bugzilla.gnome.org/" /> -->
+
+ <release>
+ <Version>
+ <name>unstable</name>
+ <created>2007-04-05</created>
+ <revision>0.1</revision>
+ </Version>
+ </release>
+
+</Project>
diff --git a/contrib/cp210x-program/cp210x/__init__.py b/contrib/cp210x-program/cp210x/__init__.py
new file mode 100644
index 0000000..b761032
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+
+__author__ = "Johannes Hölzl <johannes.hoelzl@gmx.de>"
+__license__ = "GNU LGPL"
diff --git a/contrib/cp210x-program/cp210x/__init__.pyc b/contrib/cp210x-program/cp210x/__init__.pyc
new file mode 100644
index 0000000..70aea84
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/__init__.pyc
Binary files differ
diff --git a/contrib/cp210x-program/cp210x/cp210x.py b/contrib/cp210x-program/cp210x/cp210x.py
new file mode 100644
index 0000000..c51cb35
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/cp210x.py
@@ -0,0 +1,398 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2007 Johannes Hölzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+"""Provides access to the EEPROM of Silabs CP210x devices
+
+The following classes are available:
+
+class Cp210xProgrammer:
+ Provides direct access to the CP2101, can be used to write single data
+ directly or via an EEPROM image.
+
+class EEPROM:
+ Can be used to read or write a hex file containing the EEPROM content
+ of an CP2101. Provides also access to the single fields in the EEPROM.
+"""
+
+import ctypes
+import usb
+
+__all__ = ['Cp210xProgrammer', 'Cp210xError']
+
+CP2101_UART = 0x00
+CP2101_CONFIG = 0xFF
+
+CP2101_UART_ENABLE = 0x0001
+CP2101_UART_DISABLE = 0x0000
+
+REG_VENDOR_ID = 0x3701
+REG_PRODUCT_ID = 0x3702
+REG_PRODUCT_STRING = 0x3703
+REG_SERIAL_NUMBER = 0x3704
+REG_CFG_ATTRIBUTES = 0x3705
+REG_MAX_POWER = 0x3706
+REG_VERSION = 0x3707
+REG_UNKNOWN = 0x3708
+REG_EEPROM = 0x3709
+REG_LOCK_VALUE = 0x370A
+REG_PART_NUMBER = 0x370B
+
+SIZE_EEPROM = 0x0400
+SIZE_PRODUCT_STRING = 0x007D
+SIZE_SERIAL_NUMBER = 0x003F
+SIZE_BAUDRATES = 32
+SIZE_BAUDRATE_CFG = 10
+SIZE_BAUDRATE_TABLE = SIZE_BAUDRATES * SIZE_BAUDRATE_CFG
+SIZE_VENDOR_STRING = 24
+
+LCK_LOCKED = 0x00
+LCK_UNLOCKED = 0xFF
+
+VID_SILABS = 0x10C4
+PID_CP210x = 0xEA60
+
+VALUES = [
+ ('product_string', 'string'),
+ ('serial_number', 'string'),
+ ('product_id', 'id'),
+ ('vendor_id', 'id'),
+ ('version', 'version'),
+ ('bus_powered', 'boolean'),
+ ('max_power', 'int'),
+ ('locked', 'boolean'),
+ ('part_number', 'int'),
+ ('vendor_string', 'string'),
+ ('baudrate_table', 'list'),
+]
+
+def iif(v, a, b):
+ if v:
+ return a
+ else:
+ return b
+
+def to_div2(p):
+ value = int(p / 2)
+ if (value * 2) < p:
+ value += 1
+ return value
+
+def to_bcd(i):
+ assert i >= 0 and i <= 99
+ return (i // 10) << 4 | (i % 10)
+
+def to_bcd2( (i, j) ):
+ return to_bcd(i) << 8 | to_bcd(j)
+
+def from_bcd(num):
+ return num & 0x0F + (num >> 4) * 10
+
+def from_bcd2(data):
+ return (from_bcd(data >> 8), from_bcd(data & 0xFF))
+
+def from_binary(data, le=True):
+ value = 0
+ if le:
+ data = data[::-1]
+ for byte in data:
+ value = value << 8 | ord(byte)
+ return value
+
+def to_binary(value, size=2, le=True):
+ data = ''
+ for i in range(size):
+ data += chr(value & 0xFF)
+ value >>= 8
+ if le:
+ return data
+ else:
+ return data[::-1]
+
+def parse_baudrate_cfg(data):
+ return (from_binary(data[0:2], le=False),
+ from_binary(data[2:4], le=False),
+ from_binary(data[4:5]),
+ from_binary(data[6:10]))
+
+def build_baudrate_cfg(baudgen, timer0reload, prescaler, baudrate):
+ return (to_binary(baudgen, le=False) + to_binary(timer0reload, le=False) +
+ to_binary(prescaler, 1) + '\x00' + to_binary(baudrate, 4))
+
+class Cp210xError(IOError):
+ pass
+
+class DeviceLocked(Cp210xError):
+ pass
+
+class Cp210xProgrammer(object):
+ """Program an Silabs CP2101, CP2102 or CP2103
+
+ This modul provides access to Silabs CP210x devices to set some USB
+ descriptor fields and some USB descriptor strings.
+
+ The following fields can be set:
+
+ * Vendor ID
+ * Product ID
+ * Product String
+ * Serial Number
+ * Device Version
+ * Bus Powered
+ * max. Power consumption
+
+ Either use libusb to find a device, and provide the device description
+ to the constructor, or use Cp210xProgrammer.list_device() to list all
+ devices matching certain pattern.
+
+ To progamm the device open() it, set the data, and close() it. To have the
+ changed fields reread call reset() before closing it.
+ """
+
+ TIMEOUT = 300 #ms
+
+ @classmethod
+ def list_devices(self, patterns=[{ 'idVendor': VID_SILABS,
+ 'idProduct': PID_CP210x }]):
+ """Yields a list of devices matching certain patterns.
+
+ param patterns: This must be a list of dictionaries or pairs of string.
+ Each device in the usb tree is matched against all pattern in the
+ list.
+
+ When an item is a dictionary all fields of the descriptors
+ are compared against the corresponding values in the dictionary. If
+ each value is equal, the device is yielded.
+
+ When an item is a pair of strings. The first string must be the
+ dirname of the bus and the second string the filename of the device.
+
+ For example:
+
+ >> list(Cp210xProgrammer.list_device([{ 'idVendor': VID_SILABS,
+ 'idProduct': PID_CP210x }]))
+ [device(...)]
+
+ """
+
+ usb.find_busses()
+ usb.find_devices()
+
+ bus = usb.get_busses()
+ while bus:
+ dev = bus.contents.devices
+ while dev:
+ for pattern in patterns:
+ if isinstance(pattern, dict):
+ for name, value in pattern.items():
+ if getattr(dev.contents.descriptor, name) != value:
+ break
+ else:
+ yield self(dev)
+ break
+ elif isinstance(pattern, tuple):
+ if (bus.contents.dirname == pattern[0] and
+ dev.contents.filename == pattern[1]):
+ yield self(dev)
+ break
+ dev = dev.contents.next
+ bus = bus.contents.next
+
+ def __init__(self, dev_info):
+ self.dev_info = dev_info
+ self.handle = None
+ self._locked = None
+
+ def open(self):
+ """Opens the device.
+
+ Only after an successful call to open() data can be read from and
+ written to the device.
+
+ Claims all resources associated with this device.
+ """
+ self.handle = usb.open(self.dev_info)
+ if self.handle == 0:
+ self.handle = None
+ raise Cp210xError("Can't open device.")
+ usb.set_configuration(self.handle, 1)
+ usb.claim_interface(self.handle, 0)
+
+ def reset(self):
+ """Force the USB stack to reset the device.
+
+ Resets the device through an hard reset over the port to which the
+ device is connected. After that happend the EEPROM content in the device
+ is reread and the device's descriptors are the one written to it.
+ """
+ assert self.handle is not None
+ usb.reset(self.handle)
+
+ def close(self):
+ """Closes the device.
+
+ Releases all resources associated with this device.
+ """
+ assert self.handle is not None
+ usb.release_interface(self.handle, 0)
+ usb.close(self.handle)
+ self.handle = None
+
+ def __del__(self):
+ if self.handle is not None:
+ self.close()
+
+ def _set_config(self, value, index=0, data=None, request=CP2101_CONFIG):
+ assert self.handle is not None
+ if self.get_locked():
+ raise DeviceLocked()
+
+ if data is not None:
+ data_length = len(data)
+ else:
+ data_length = 0
+ res = usb.control_msg(self.handle, usb.ENDPOINT_OUT | usb.TYPE_VENDOR,
+ request, value, index, data, data_length,
+ self.TIMEOUT)
+ if res < 0:
+ raise Cp210xError("Unable to send request %04X result=%d"
+ % (value, res))
+
+ def _set_config_string(self, value, content, max_length):
+ assert isinstance(content, basestring)
+ encoded = content.encode('utf-16-le')
+ assert len(encoded) <= max_length
+ self._set_config(value, data=chr(len(encoded) + 2) + "\x03" + encoded)
+
+ def _get_config(self, value, length, index=0, request=CP2101_CONFIG):
+ assert self.handle is not None
+ data = ctypes.create_string_buffer(length)
+ res = usb.control_msg(self.handle, usb.ENDPOINT_IN | usb.TYPE_VENDOR,
+ request, value, index, data, length,
+ self.TIMEOUT)
+ if res < 0:
+ raise Cp210xError("Unable to send request, %04X result=%d"
+ % (value, res))
+ return data.raw[:res]
+
+ def _get_int8_config(self, value, index=0, request=CP2101_CONFIG):
+ return ord(self._get_config(value, 1, index=index, request=request))
+
+ def _get_int16_config(self, value, index=0, request=CP2101_CONFIG):
+ data = self._get_config(value, 2, index=index, request=request)
+ return ord(data[0]) << 8 | ord(data[1])
+
+ def get_eeprom_content(self):
+ """Reads the entire EEPROM content as one big 1024-byte blob.
+ """
+ return self._get_config(REG_EEPROM, SIZE_EEPROM)
+
+ def get_baudrate_content(self):
+ """Return the baudrate table as binary data.
+ """
+ return self._get_config(REG_EEPROM, SIZE_BAUDRATE_TABLE)
+
+ def get_baudrate_table(self):
+ """Returns the baudrate table.
+
+ A list containing 4-tuples are returnes.
+ Each tuple containes the following data:
+
+ * BaudGen: Value used to generate the real baudrate.
+ * Time0Reset: Value used to generate the usb timeout.
+ * Prescaler: Used to generate the real baudrate.
+ * Baudrate: The baudrate which activates this entry.
+ """
+ data = self.get_baudrate_content()
+ return [parse_baudrate_cfg(data[pos:pos+SIZE_BAUDRATE_CFG])
+ for pos in range(0, SIZE_BAUDRATE_TABLE, SIZE_BAUDRATE_CFG)]
+
+ def set_baudrate_table(self, baudrates):
+ """Writes the baudrate table.
+
+ See get_baudrate_table() for the structure of the table.
+ """
+ assert len(baudrates) == SIZE_BAUDRATES
+ self.set_baudrate_content(data=''.join(build_baudrate_cfg(*cfg)
+ for cfg in baudrates))
+ baudrate_table = property(get_baudrate_table, set_baudrate_table)
+
+ def get_part_number(self):
+ """ The part number of the device.
+
+ Returns: 1 for an CP2101
+ 2 for an CP2102
+ 3 for an CP2103
+ """
+ return self._get_int8_config(REG_PART_NUMBER)
+
+ def get_locked(self):
+ """ The lock value of the device.
+
+ When True is returnes no data can be written to the device.
+ """
+ if self._locked is None:
+ self._locked = self._get_int8_config(REG_LOCK_VALUE) == LCK_LOCKED
+ return self._locked
+
+ def set_eeprom_content(self, content):
+ """Writes an 1024-byte blob to the EEPROM
+ """
+ assert len(content) == SIZE_EEPROM, ("EEPROM data must be %i bytes."
+ % SIZE_EEPROM)
+ assert isinstance(content, str), "EEPROM data must be string."
+ self._set_config(REG_EEPROM, data=content)
+
+ def set_product_id(self, pid):
+ """Sets the Product ID
+ """
+ assert pid > 0x0000 and pid < 0xFFFF
+ self._set_config(REG_PRODUCT_ID, pid)
+
+ def set_vendor_id(self, vid):
+ """Sets the Vendor ID
+ """
+ assert vid > 0x0000 and vid < 0xFFFF
+ self._set_config(REG_VENDOR_ID, vid)
+
+ def set_product_string(self, product_string):
+ """Sets the product string.
+
+ Be aware that the string will be stored as UTF-16 encoded and should not
+ exceed SIZE_PRODUCT_STRING
+ """
+ self._set_config_string(REG_PRODUCT_STRING, product_string,
+ SIZE_PRODUCT_STRING)
+
+ def set_serial_number(self, serial_number):
+ self._set_config_string(REG_SERIAL_NUMBER, serial_number,
+ SIZE_SERIAL_NUMBER)
+
+ def set_max_power(self, max_power):
+ assert max_power >= 0 and max_power <= 500
+ self._set_config(REG_MAX_POWER, to_div2(max_power))
+
+ def set_bus_powered(self, bus_powered):
+ if bus_powered:
+ self._set_config(REG_CFG_ATTRIBUTES, 0xC0)
+ else:
+ self._set_config(REG_CFG_ATTRIBUTES, 0x80)
+
+ def set_version(self, version):
+ self._set_config(REG_VERSION, to_bcd2(version))
+
+ def set_locked(self, locked):
+ """ The lock value of the device.
+
+ When True is returnes no data can be written to the device.
+ """
+ if locked:
+ self._set_config(REG_LOCK_VALUE, LCK_LOCKED)
+ else:
+ self._set_config(REG_LOCK_VALUE, LCK_UNLOCKED)
+
+ def set_values(self, values):
+ for name, value in values.items():
+ if name not in ['part_number', 'vendor_string']:
+ getattr(self, "set_" + name) (value)
+
diff --git a/contrib/cp210x-program/cp210x/cp210x.pyc b/contrib/cp210x-program/cp210x/cp210x.pyc
new file mode 100644
index 0000000..912a046
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/cp210x.pyc
Binary files differ
diff --git a/contrib/cp210x-program/cp210x/eeprom.py b/contrib/cp210x-program/cp210x/eeprom.py
new file mode 100644
index 0000000..25f0372
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/eeprom.py
@@ -0,0 +1,180 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2007 Johannes Hölzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+
+import cp210x
+from cp210x import from_binary, to_binary, iif, VALUES
+
+__all__ = ['EEPROM', 'HexFileError']
+
+POS_BAUDRATE_TABLE = 0x0000
+POS_PART_NUMBER = 0x01FF
+POS_PRODUCT_STRING = 0x0208
+POS_SERIAL_NUMBER = 0x0307
+POS_PRODUCT_ID = 0x0390
+POS_VENDOR_ID = 0x0392
+POS_VERSION = 0x0394
+POS_CFG_ATTRIBUTES = 0x03A1
+POS_MAX_POWER = 0x03A2
+POS_VENDOR_STRING = 0x03C3
+POS_LOCK_VALUE = 0x03FF
+
+class HexFileError(StandardError):
+ pass
+
+def checksum(line):
+ return sum(ord(c) for c in line) & 0xFF
+
+def _int_value(position, size, read=lambda x:x, write=lambda x:x):
+ def get(self):
+ return read(from_binary(self.get(position, size)))
+ def set(self, value):
+ self.set(position, to_binary(write(value), size))
+ return property(get, set)
+
+def _str_value(position, max_size):
+ def get(self):
+ size = from_binary(self.get(position, 1))
+ assert size <= (max_size + 2) and size >= 2
+ assert self.get(position + 1, 1) == '\x03', "Missing 0x03 at %04X" % (position + 1)
+ return self.get(position + 2, size - 2).decode('utf-16-le')
+
+ def set(self, value):
+ encoded = value.encode('utf-16-le')
+ assert len(encoded) <= max_size
+ self.set(position, chr(len(encoded) + 2) + '\x03' + encoded)
+
+ return property(get, set)
+
+class EEPROM(object):
+ START_ADDRESS = 0x3600
+ def __init__(self, content=None):
+ if isinstance(content, str) or content is None:
+ assert content is None or len(content) == cp210x.SIZE_EEPROM
+ self.content = content
+ elif isinstance(content, cp210x.Cp210xProgrammer):
+ self.content = content.get_eeprom_content()
+ else:
+ self.parse_hex_file(content.read())
+
+ def write_to_cp210x(self, cp210xDevice):
+ cp210xDevice.set_eeprom_content(self.content)
+
+ def parse_hex_file(self, hex_content):
+ self.content = ''
+ address = self.START_ADDRESS
+ for tag in hex_content.split('\n'):
+ if not tag.startswith(':'):
+ raise HexFileError("Line doesn't start with ':'")
+
+ try:
+ content = tag[1:].decode('hex')
+ except TypeError:
+ raise HexFileError("Hex data expected")
+
+ if len(content) < 5:
+ raise HexFileError("Line to short")
+
+ if checksum(content) != 0:
+ raise HexFileError("Checksum error")
+
+ size = from_binary(content[0])
+ tag_address = from_binary(content[1:3], le=False)
+ tag_type = from_binary(content[3:4])
+ line = content[4:-1]
+
+ if tag_type == 0x00:
+ if tag_address != address:
+ raise HexFileError("Expected address %04X but found %04X"
+ % (address, tag_address))
+ self.content += line
+ address += len(line)
+ elif tag_type == 0x01:
+ if size != 0 or len(line) != 0:
+ raise HexFileError("Defekt end tag")
+ break
+
+ else:
+ raise HexFileError("Unknown tag type %02X" % tag_type)
+
+ def build_hex_file(self):
+ for tag_start in range(0, len(self.content), 0x10):
+ line = self.content[tag_start:tag_start+0x10]
+ address = self.START_ADDRESS + tag_start
+ tag = (to_binary(len(line), 1) +
+ to_binary(address, le=False) +
+ '\x00' +
+ line)
+ cs = checksum(tag)
+ if cs == 0:
+ tag += '\x00'
+ else:
+ tag += chr(0x100 - cs)
+ yield ":%s\n" % tag.encode('hex')
+ yield ":00000001FF\n"
+
+ def write_hex_file(self, f):
+ if isinstance(f, str):
+ f = file(f, 'wb')
+ do_close = True
+ else:
+ do_close = False
+ for line in self.build_hex_file():
+ f.write(line)
+ if do_close:
+ f.close()
+
+ def read_hex_file(self, f):
+ if isinstance(f, str):
+ f = file(f, 'rb')
+ do_close = True
+ else:
+ do_close = False
+ self.parse_hex_file(f.read())
+ if do_close:
+ f.close()
+
+ def get(self, pos, length):
+ return self.content[pos:pos+length]
+
+ def set(self, pos, data):
+ self.content = (self.content[:pos] +
+ data +
+ self.content[pos + len(data):])
+
+ def _get_baudrate_table(self):
+ dat = self.get(POS_BAUDRATE_TABLE, cp210x.SIZE_BAUDRATE_TABLE)
+ return [cp210x.parse_baudrate_cfg(dat[pos:pos+cp210x.SIZE_BAUDRATE_CFG])
+ for pos in range(0, cp210x.SIZE_BAUDRATE_TABLE,
+ cp210x.SIZE_BAUDRATE_CFG)]
+ def _set_baudrate_table(self, baudrates):
+ assert len(baudrates) == cp210x.SIZE_BAUDRATES
+ self.set(POS_BAUDRATE_TABLE,
+ ''.join(cp210x.build_baudrate_cfg(*cfg) for cfg in baudrates))
+ baudrate_table = property(_get_baudrate_table, _set_baudrate_table)
+ product_string = _str_value(POS_PRODUCT_STRING, cp210x.SIZE_PRODUCT_STRING)
+ serial_number = _str_value(POS_SERIAL_NUMBER, cp210x.SIZE_SERIAL_NUMBER)
+ part_number = _int_value(POS_PART_NUMBER, 1)
+ product_id = _int_value(POS_PRODUCT_ID, 2)
+ vendor_id = _int_value(POS_VENDOR_ID, 2)
+ version = _int_value(POS_VERSION, 2,
+ cp210x.from_bcd2, cp210x.to_bcd2)
+ bus_powered = _int_value(POS_CFG_ATTRIBUTES, 1,
+ lambda a: bool(a & 0x40),
+ lambda a: iif(a, 0xC0, 0x80))
+ max_power = _int_value(POS_MAX_POWER, 1, lambda p: p*2, cp210x.to_div2)
+ vendor_string = _str_value(POS_VENDOR_STRING, cp210x.SIZE_VENDOR_STRING)
+ locked = _int_value(POS_LOCK_VALUE, 1,
+ lambda l: l == cp210x.LCK_LOCKED,
+ lambda b: iif(b, cp210x.LCK_LOCKED,
+ cp210x.LCK_UNLOCKED))
+
+ def get_values(self):
+ return dict((name, getattr(self, name)) for name, type in VALUES)
+
+ def set_values(self, values):
+ for name, value in values.items():
+ setattr(self, name, value)
+
+
diff --git a/contrib/cp210x-program/cp210x/eeprom.pyc b/contrib/cp210x-program/cp210x/eeprom.pyc
new file mode 100644
index 0000000..46f86dc
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/eeprom.pyc
Binary files differ
diff --git a/contrib/cp210x-program/cp210x/usb.py b/contrib/cp210x-program/cp210x/usb.py
new file mode 100644
index 0000000..be70f82
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/usb.py
@@ -0,0 +1,274 @@
+# Python interface for "usb.h" version 0.1.4.4.4
+#
+# Copyright (c) 2005 Robert Hoelzl <robert.hoelzl@gmx.de>
+# Copyright (c) 2007 Johannes Hoelzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+
+from ctypes import *
+import sys
+
+class LibUsbNotInstalled(OSError):
+ pass
+
+try:
+ if sys.platform == 'darwin':
+ PATH_MAX = 1024
+ dll=cdll.LoadLibrary("libusb.dylib")
+ elif sys.platform == 'linux2':
+ PATH_MAX = 4096
+ dll=cdll.LoadLibrary("libusb.so")
+ else:
+ raise NotImplementedError("Platform %s not supported by usb.py" % sys.platform)
+except OSError:
+ raise LibUsbNotInstalled()
+
+
+# helper functions
+def func(f, *args, **retval):
+ f.restype = retval.get('retval', None)
+ f.argtypes = args
+ if retval.has_key('rename'): globals()[retval['rename']] = f
+ else: globals()[f.__name__[4:]] = f
+
+# constants
+CLASS_PER_INTERFACE = 0
+USB_CLASS_AUDIO = 1
+CLASS_COMM = 2
+CLASS_HID = 3
+CLASS_PRINTER = 7
+CLASS_PTP = 6
+CLASS_MASS_STORAGE = 8
+CLASS_HUB = 9
+CLASS_DATA = 10
+CLASS_VENDOR_SPEC = 0xff
+
+DT_DEVICE = 0x01
+DT_CONFIG = 0x02
+DT_STRING = 0x03
+DT_INTERFACE = 0x04
+DT_ENDPOINT = 0x05
+
+DT_HID = 0x21
+DT_REPORT = 0x22
+DT_PHYSICAL = 0x23
+DT_HUB = 0x29
+
+DT_DEVICE_SIZE = 18
+DT_CONFIG_SIZE = 9
+DT_INTERFACE_SIZE = 9
+DT_ENDPOINT_SIZE = 7
+DT_ENDPOINT_AUDIO_SIZE = 9 # Audio extension
+DT_HUB_NONVAR_SIZE = 7
+
+
+class descriptor_header(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8) ]
+
+
+class string_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("wData", c_uint*1) ]
+
+class hid_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("bcdHID", c_uint16),
+ ("bCountryCode", c_uint8),
+ ("bNumDescriptors", c_uint8) ]
+
+MAXENDPOINTS = 32
+class endpoint_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("bEndpointAddress", c_uint8),
+ ("bmAttributes", c_uint8),
+ ("wMaxPacketSize", c_uint16),
+ ("bInterval", c_uint8),
+ ("bRefresh", c_uint8),
+ ("bSynchAddress", c_uint8),
+
+ ("extra", POINTER(c_uint8)),
+ ("extralen", c_int) ]
+
+
+ENDPOINT_ADDRESS_MASK = 0x0f # in bEndpointAddress
+ENDPOINT_DIR_MASK = 0x80
+
+ENDPOINT_TYPE_MASK = 0x03 # in bmAttributes
+ENDPOINT_TYPE_CONTROL = 0
+ENDPOINT_TYPE_ISOCHRONOUS = 1
+ENDPOINT_TYPE_BULK = 2
+ENDPOINT_TYPE_INTERRUPT = 3
+
+MAXINTERFACES = 32
+class interface_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("bInterfaceNumber", c_uint8),
+ ("bAlternateSetting", c_uint8),
+ ("bNumEndpoints", c_uint8),
+ ("bInterfaceClass", c_uint8),
+ ("bInterfaceSubClass", c_uint8),
+ ("bInterfaceProtocol", c_uint8),
+ ("iInterface", c_uint8),
+
+ ("endpoint", POINTER(endpoint_descriptor)),
+
+ ("extra", POINTER(c_uint8)),
+ ("extralen", c_int) ]
+
+MAXALTSETTING = 128 # Hard limit
+class interface(Structure): _fields_ = [
+ ("altsetting", POINTER(interface_descriptor)),
+
+ ("num_altsetting", c_int) ]
+
+MAXCONFIG = 8
+class config_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("wTotalLength", c_uint16),
+ ("bNumInterfaces", c_uint8),
+ ("bConfigurationValue", c_uint8),
+ ("iConfiguration", c_uint16),
+ ("bmAttributes", c_uint8),
+ ("MaxPower", c_uint8),
+
+ ("interface", POINTER(interface)),
+
+ ("extra", POINTER(c_uint8)), # Extra descriptors
+ ("extralen", c_int) ]
+
+class device_descriptor(Structure): _fields_ = [
+ ("bLength", c_uint8),
+ ("bDescriptorType", c_uint8),
+ ("bcdUSB", c_uint16),
+ ("bDeviceClass", c_uint8),
+ ("bDeviceSubClass", c_uint8),
+ ("bDeviceProtocol", c_uint8),
+ ("bMaxPacketSize0", c_uint8),
+ ("idVendor", c_uint16),
+ ("idProduct", c_uint16),
+ ("bcdDevice", c_uint16),
+ ("iManufacturer", c_uint8),
+ ("iProduct", c_uint8),
+ ("iSerialNumber", c_uint8),
+ ("bNumConfigurations", c_uint8) ]
+
+class ctrl_setup(Structure): _fields_ = [
+ ("bRequestType", c_uint8),
+ ("bRequest", c_uint8),
+ ("wValue", c_uint16),
+ ("wIndex", c_uint16),
+ ("wLength", c_uint16) ]
+
+
+REQ_GET_STATUS = 0x00
+REQ_CLEAR_FEATURE = 0x01
+# 0x02 is reserved
+REQ_SET_FEATURE = 0x03
+# 0x04 is reserved
+REQ_SET_ADDRESS = 0x05
+REQ_GET_DESCRIPTOR = 0x06
+REQ_SET_DESCRIPTOR = 0x07
+REQ_GET_CONFIGURATION = 0x08
+REQ_SET_CONFIGURATION = 0x09
+REQ_GET_INTERFACE = 0x0A
+REQ_SET_INTERFACE = 0x0B
+REQ_SYNCH_FRAME = 0x0C
+
+TYPE_STANDARD = (0x00 << 5)
+TYPE_CLASS = (0x01 << 5)
+TYPE_VENDOR = (0x02 << 5)
+TYPE_RESERVED = (0x03 << 5)
+
+RECIP_DEVICE = 0x00
+RECIP_INTERFACE = 0x01
+RECIP_ENDPOINT = 0x02
+RECIP_OTHER = 0x03
+
+ENDPOINT_IN = 0x80
+ENDPOINT_OUT = 0x00
+
+# Error codes
+ERROR_BEGIN = 500000
+
+#if 1
+#define USB_LE16_TO_CPU(x) do { x = ((x & 0xff) << 8) | ((x & 0xff00) >> 8); } while(0)
+#else
+#define USB_LE16_TO_CPU(x)
+#endif
+
+device_p = POINTER("device")
+bus_p = POINTER("bus")
+
+class device(Structure): _fields_ = [
+ ("next", device_p),
+ ("prev", device_p),
+ ("filename", c_char*(PATH_MAX + 1)),
+
+ ("bus", bus_p),
+ ("descriptor", device_descriptor),
+ ("config", POINTER(config_descriptor)),
+
+ ("dev", c_void_p), # Darwin support
+
+ ("devnum", c_char),
+
+ ("num_children", c_uint8),
+ ("children", POINTER(device_p)) ]
+SetPointerType(device_p, device)
+
+class bus(Structure): _fields_ = [
+ ("next", bus_p),
+ ("prev", bus_p),
+
+ ("dirname", c_char*(PATH_MAX + 1)),
+
+ ("devices", device_p),
+ ("location", c_uint),
+
+ ("root_dev", device_p) ]
+SetPointerType(bus_p, bus)
+
+
+dev_handle_p = c_void_p
+
+
+func(dll.usb_open, device_p, retval=dev_handle_p, rename="_open")
+func(dll.usb_close, dev_handle_p, retval=c_int)
+func(dll.usb_get_string, dev_handle_p, c_int, c_int, c_char_p, c_int, retval=c_int)
+func(dll.usb_get_string_simple, dev_handle_p, c_int, c_char_p, c_int, retval=c_int)
+func(dll.usb_get_descriptor_by_endpoint, dev_handle_p, c_int, c_uint8, c_uint8, c_void_p, c_int, retval=c_int)
+func(dll.usb_get_descriptor, dev_handle_p, c_uint8, c_uint8, c_void_p, c_int, retval=c_int)
+
+func(dll.usb_bulk_write, dev_handle_p, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_bulk_read, dev_handle_p, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_interrupt_write, dev_handle_p, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_interrupt_read, dev_handle_p, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_control_msg, dev_handle_p, c_int, c_int, c_int, c_int, c_char_p, c_int, c_int, retval=c_int)
+func(dll.usb_set_configuration, dev_handle_p, c_int, retval=c_int)
+func(dll.usb_claim_interface, dev_handle_p, c_int, retval=c_int)
+func(dll.usb_release_interface, dev_handle_p, c_int, retval=c_int)
+func(dll.usb_set_altinterface, dev_handle_p, c_int, retval=c_int)
+func(dll.usb_resetep, dev_handle_p, c_uint16, retval=c_int)
+func(dll.usb_clear_halt, dev_handle_p, c_uint16, retval=c_int)
+func(dll.usb_reset, dev_handle_p, retval=c_int)
+
+func(dll.usb_strerror, retval=c_char_p)
+
+func(dll.usb_init)
+func(dll.usb_set_debug, c_int)
+func(dll.usb_find_busses, retval=c_int)
+func(dll.usb_find_devices, retval=c_int)
+func(dll.usb_device, dev_handle_p, retval=device_p, rename="get_device")
+func(dll.usb_get_busses, retval=bus_p)
+
+func(dll.usb_detach_kernel_driver_np, dev_handle_p, c_int, retval=c_int)
+
+# workaround for bug in ctypes 0.9.6 (cannot create functions with c_void_p as retval)
+def open(dev):
+ return cast(_open(dev), dev_handle_p)
diff --git a/contrib/cp210x-program/cp210x/usb.pyc b/contrib/cp210x-program/cp210x/usb.pyc
new file mode 100644
index 0000000..d03aed5
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/usb.pyc
Binary files differ
diff --git a/contrib/cp210x-program/cp210x/valuefile.py b/contrib/cp210x-program/cp210x/valuefile.py
new file mode 100644
index 0000000..ae665d2
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/valuefile.py
@@ -0,0 +1,234 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2007 Johannes Hölzl <johannes.hoelzl@gmx.de>
+#
+# This library is covered by the GNU LGPL, read LICENSE for details.
+
+# For documentation of the baudrate table see:
+#
+# [AN205] Silicon Labs Application Note 205 Rev. 0.3
+# http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an205.pdf
+
+import re
+from ConfigParser import ConfigParser
+
+import cp210x
+from cp210x import VALUES, SIZE_BAUDRATES
+
+__all__ = ['read_file', 'write_file', 'update_values', 'PrescalerIsZero',
+ 'ValuesFileError']
+
+class ValuesError(StandardError):
+ pass
+
+class PrescalerIsZero(ValuesError):
+ pass
+
+class ValuesFileError(ValuesError):
+ pass
+
+version_pattern = re.compile(r'^\s*(\d\d?)\.(\d\d?)\s*$')
+def read_version(s):
+ match = version_pattern.match(s)
+ if match is None:
+ raise ValueError("Version does not match 'xx.yy'")
+ return (int(match.group(1)), int(match.group(2)))
+def write_version(v):
+ return "%d.%02d" % v
+
+def read_hex(s):
+ return int(s.strip(), 16)
+
+def write_hex(num):
+ return "%04X" % num
+
+def write_bool(b):
+ if b:
+ return 'yes'
+ else:
+ return 'no'
+
+def read_bool(s):
+ s = s.strip().lower()
+ if s not in ['true', 'yes', 'false', 'no']:
+ raise ValueError("Boolean must be either 'true', 'yes', 'false' or 'no'.")
+ return s in ['true', 'yes']
+
+def read_baudrate_info(s):
+ values = s.split(',')
+ if len(values) != 3:
+ raise ValueError("Baudrate info must be three comma-separated items")
+ try:
+ baudgen = read_hex(values[0])
+ except ValueError:
+ raise ValueError("The first baudrate info must be a hex-value")
+ try:
+ timer0 = read_hex(values[1])
+ except ValueError:
+ raise ValueError("The second baudrate info must be a hex-value")
+ try:
+ prescale = int(values[2])
+ except ValueError:
+ raise ValueError("The thirdbaudrate info must be a number")
+ return (baudgen, timer0, prescale)
+
+TYPES = {
+ 'boolean': (read_bool, write_bool),
+ 'int': (int, str),
+ 'id': (read_hex, write_hex),
+ 'string': (str, str),
+ 'version': (read_version, write_version),
+}
+
+def read_file(fp):
+ cp = ConfigParser()
+ if isinstance(fp, str):
+ cp.read([fp])
+ else:
+ cp.readfp(fp)
+
+ values = {}
+
+ for name, type in VALUES:
+ if name is 'baudrate_table':
+ continue
+ reader, _ = TYPES[type]
+ if cp.has_option('usb device', name):
+ try:
+ values[name] = reader(cp.get('usb device', name))
+ except ValueError, err:
+ raise ValuesFileError("Key '%s': %s" % (name, str(err)))
+
+ if cp.has_section('baudrate table'):
+ baudrate_table = []
+ for name, value in cp.items('baudrate table'):
+ try:
+ baudrate = int(name)
+ except ValueError:
+ raise ValuesFileError("Key names in 'baudrate table' must be"
+ " baudrate numbers.")
+ try:
+ baudrate_table.append(read_baudrate_info(value) + (baudrate, ))
+ except ValueError, err:
+ raise ValuesFileError("Wrong baudrate info %i: %s"
+ % (baudrate, str(err)))
+ baudrate_table.sort(key=(lambda i: i[3]), reverse=True)
+
+ values['baudrate_table'] = baudrate_table
+ return values
+
+def write_file(fp, values):
+ fp.write("[usb device]\n")
+
+ for name, type in VALUES:
+ if name == 'baudrate_table':
+ continue
+ _, writer = TYPES[type]
+ if name in values:
+ fp.write("%s = %s\n" % (name, writer(values[name])))
+
+ if 'baudrate_table' in values:
+ fp.write("\n")
+ fp.write("[baudrate table]\n")
+ for (baudgen, timegen, prescaler,
+ baudrate) in sorted(values['baudrate_table'], key=(lambda i: i[3]),
+ reverse=True):
+ fp.write("%7d = %04X, %04X, %d # %s\n"
+ % (baudrate, baudgen, timegen, prescaler,
+ show_baudrate(baudgen, timegen, prescaler)))
+
+def calc_baudrate(baudgen, timegen, prescaler):
+ # This formulas are from AN205 page 5.
+ if prescaler == 0:
+ raise PrescalerIsZero("Prescaler is 0")
+ baudrate = (24000000. / prescaler) / (0x10000 - baudgen)
+ return (baudrate, (0x10000 - timegen) * 2)
+
+def show_baudrate(baudgen, timegen, prescaler):
+ try:
+ baudrate, timeout = calc_baudrate(baudgen, timegen, prescaler)
+ except PrescalerIsZero:
+ return "Wrong data, Prescaler is 0."
+ if timeout >= 1000:
+ timeout = "%1.3f ms" % (float(timeout) / 1000)
+ else:
+ timeout = "%d us" % timeout
+ if baudrate is None:
+ return ", %s" % (baudrate, timeout)
+ else:
+ return "%7.0f Baud, %s" % (baudrate, timeout)
+
+def update_values(v, new, dev):
+ old_baudrate_table = v.get('baudrate_table')
+ new_baudrate_table = new.get('baudrate_table')
+
+ v.update(new)
+
+ # update baudrate table
+ # it is needed, that the baudrate table has 32 entries when it is written
+ # to the eeprom or device.
+ if ((old_baudrate_table is not None or new_baudrate_table is not None) and
+ (new_baudrate_table is None or
+ len(new_baudrate_table) < SIZE_BAUDRATES)):
+
+ if old_baudrate_table is not None:
+ if len(old_baudrate_table) < SIZE_BAUDRATES:
+ baudrate_table = old_baudrate_table
+ else:
+ baudrate_table = list(merge_baudrate_table(dev.baudrate_table,
+ old_baudrate_table))
+ else:
+ baudrate_table = dev.baudrate_table
+
+ if new_baudrate_table:
+ baudrate_table = list(merge_baudrate_table(baudrate_table,
+ new_baudrate_table))
+ v['baudrate_table'] = baudrate_table
+
+
+
+def merge_baudrate_table(old, new):
+ for (old_info, (start, stop)) in zip(old, REQUEST_BAUDRATE_RANGES):
+ for baudgen, timer, prescaler, baudrate in new:
+ if ((start is None or baudrate <= start) and
+ baudrate >= stop):
+ yield (baudgen, timer, prescaler, baudrate)
+ break
+ else:
+ yield old_info
+
+REQUEST_BAUDRATE_RANGES = [
+# The table data is from AN205 Table 1 on page 1.
+# Start End Default Baudrate
+ (None, 2457601), # Undefined
+ (2457600, 1474561), # Undefined
+ (1474560, 1053258), # Undefined
+ (1053257, 670255), # 921600
+ ( 670254, 567139), # 576000
+ ( 567138, 491521), # 500000
+ ( 491520, 273067), # 460800
+ ( 273066, 254235), # 256000
+ ( 254234, 237833), # 250000
+ ( 237832, 156869), # 230400
+ ( 156868, 129348), # 153600
+ ( 129347, 117029), # 128000
+ ( 117028, 77609), # 115200
+ ( 77608, 64112), # 76800
+ ( 64111, 58054), # 64000
+ ( 58053, 56281), # 57600
+ ( 56280, 51559), # 56000
+ ( 51558, 38602), # 51200
+ ( 38601, 28913), # 38400
+ ( 28912, 19251), # 28800
+ ( 19250, 16063), # 19200
+ ( 16062, 14429), # 16000
+ ( 14428, 9613), # 14400
+ ( 9612, 7208), # 9600
+ ( 7207, 4804), # 7200
+ ( 4803, 4001), # 4800
+ ( 4000, 2401), # 4000
+ ( 2400, 1801), # 2400
+ ( 1800, 1201), # 1800
+ ( 1200, 601), # 1200
+ ( 600, 301), # 600
+ ( 300, 57), # 300
+]
diff --git a/contrib/cp210x-program/cp210x/valuefile.pyc b/contrib/cp210x-program/cp210x/valuefile.pyc
new file mode 100644
index 0000000..e3c4115
--- /dev/null
+++ b/contrib/cp210x-program/cp210x/valuefile.pyc
Binary files differ
diff --git a/contrib/cp210x-program/doc/45-cp210x-programming.rules b/contrib/cp210x-program/doc/45-cp210x-programming.rules
new file mode 100644
index 0000000..84c32b2
--- /dev/null
+++ b/contrib/cp210x-program/doc/45-cp210x-programming.rules
@@ -0,0 +1,9 @@
+# udev rules file for CP210x device to be programmable py
+# cp210x-program
+
+SUBSYSTEM!="usb_device", GOTO="cp210x-programming_rules_end"
+
+SYSFS{idVendor}=="10C4", SYSFS{idProduct}=="EA60", MODE="0660", GROUP="plugdev"
+SYSFS{idVendor}=="10C4", SYSFS{idProduct}=="EA61", MODE="0660", GROUP="plugdev"
+
+LABEL="cp210x-programming_rules_end"
diff --git a/contrib/cp210x-program/doc/cp210x.txt b/contrib/cp210x-program/doc/cp210x.txt
new file mode 100644
index 0000000..f9b2156
--- /dev/null
+++ b/contrib/cp210x-program/doc/cp210x.txt
@@ -0,0 +1,107 @@
+
+
+COMMAND: 0xFF (ACCESS EEPROM)
+INDEX SIZE VALUE
+0x3701 2 VENDOR ID
+0x3702 2 PRODUCT ID
+0x3703 - PRODUCT STRING
+0x3704 - SERIAL NUMBER
+0x3705 ? ? (bmAttribute?)
+0x3706 1 MAX POWER (2mA) -
+0x3707 2 BCD DEV VERSION -
+0x3708 ? ?
+0x3709 1024 EEPROM DUMP
+0x370A 1 LOCK VALUE
+0x370B 1 PART NUMBER
+
+COMMAND: 0x0F UNKNOWN
+
+HEXFILE:
+
+0x3808: 256 Bytes PRODUCT STRING (incl length and language)
+0x3908: 128 Bytes SERIAL NUMBER (incl length and language)
+0x3987: 1 Byte probably PART NUMBER
+0x3988: 18 Byte DEVICE DESCRIPTOR
+0x399A: 32 Byte CONFIG DESCRIPTOR
+0x39C3: ? Byte VENDOR STRING
+0x39FF: 1 Byte LOCK VALUE
+
+1201100100000040ad139999020001020301
+
+02
+1201100100000040AD139999326401020301
+
+090220000101008096
+0904000002FF000002
+07058102400000
+07050102400000
+000000000000000000
+1A03530069006C00690063006F006E0020004C00610062007300000000
+00000000000000000000000000000000
+000000000000000000000000000000FF
+
+:10360000FFF0FFFA010060E31600FFF0FFFA01008F
+:1036100060E31600FFECFFF80100804F1200FFE4AA
+:10362000FF40010050F80C00FFD6FF40010000CA27
+:103630000800FFD0FFEE010020A10700FFCCFFEC47
+:10364000010000080700FFA2FFDC010000E8030002
+:10365000FFA0FFDC010090D00300FF98FFD901001C
+:1036600000840300FF64FFC5010000580200FF440E
+:10367000FFB9010000F40100FF2CFF40010000C26F
+:103680000100FEC8FF8B0100002C0100FE89FF73C2
+:10369000010000FA0000FE5FFF63010000E100008E
+:1036A000FE53FF5F0100C0DA0000FE2BFF50010057
+:1036B00000C80000FD8FFF15010000960000FCBF50
+:1036C000FEC7010080700000FB1EFE2B0100004BB6
+:1036D0000000FA24FE0C0100803E0000F97DFE0C83
+:1036E000010040380000F63CFE0C0100802500007F
+:1036F000F2FBFE0C0100201C0000EC78FE0C010027
+:10370000C0120000E890FE0C0100A00F0000D8F0ED
+:10371000FE0C010060090000CBEBFE0C0100080765
+:103720000000B1E0FE0C0100B004000063C0FE0C1C
+:10373000010058020000B1E0FE0C04002C01000062
+:103740000000000000000000000000000000000079
+:103750000000000000000000000000000000000069
+:103760000000000000000000000000000000000059
+:103770000000000000000000000000000000000049
+:103780000000000000000000000000000000000039
+:103790000000000000000000000000000000000029
+:1037A0000000000000000000000000000000000019
+:1037B0000000000000000000000000000000000009
+:1037C00000000000000000000000000000000000F9
+:1037D00000000000000000000000000000000000E9
+:1037E00000000000000000000000000000000000D9
+:1037F00000000000000000000000000000000002C7
+:1038000004030904000000002203500052004F008E
+:10381000440055004300540020005300540052005F
+:1038200049004E0047002100210065007200200081
+:1038300042007200690064006700650020004300D8
+:103840006F006E00740072006F006C006C00650009
+:1038500072000000000000000000000000000000F6
+:103860000000000000000000000000000000000058
+:103870000000000000000000000000000000000048
+:103880000000000000000000000000000000000038
+:103890000000000000000000000000000000000028
+:1038A0000000000000000000000000000000000018
+:1038B0000000000000000000000000000000000008
+:1038C00000000000000000000000000000000000F8
+:1038D00000000000000000000000000000000000E8
+:1038E00000000000000000000000000000000000D8
+:1038F00000000000000000000000000000000000C8
+:1039000000000000000000120331003100300030E0
+:1039100000300033003200380000000000000000DA
+:103920000000000000000000000000000000000097
+:103930000000000000000000000000000000000087
+:103940000000000000000000000000000000000077
+:103950000000000000000000000000000000000067
+:103960000000000000000000000000000000000057
+:103970000000000000000000000000000000000047
+:1039800000000000000000021201100100000040D1
+:10399000AD1399993264010203010902200001016B
+:1039A0000080960904000002FF0000020705810262
+:1039B0004000000705010240000000000000000078
+:1039C0000000001A03530069006C00690063006F77
+:1039D000006E0020004C00610062007300000000D7
+:1039E00000000000000000000000000000000000D7
+:1039F000000000000000000000000000000000FFC8
+:00000001FF
diff --git a/contrib/cp210x-program/doc/index.html b/contrib/cp210x-program/doc/index.html
new file mode 100644
index 0000000..1998469
--- /dev/null
+++ b/contrib/cp210x-program/doc/index.html
@@ -0,0 +1,129 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>CP210x Programmer</title>
+<style type="text/css">
+</style>
+</head><body>
+ <h1>CP210x Programmer</h1>
+
+ <p>
+ <strong>ATTENTION: THIS VERSION OF cp210x-program IS NOT FULLY TESTED.
+IT MAY RENDER YOUR CP210x USELESS OR DESTROY IT.</strong>
+ </p>
+
+ <ul>
+ <li><a href="http://sourceforge.net/projects/cp210x-program">Project Page</a>
+ </li><li><a href="http://sourceforge.net/tracker/?group_id=193093">Bug Database</a></li>
+ <li><a href="http://sourceforge.net/project/showfiles.php?group_id=193093">Download</a></li>
+ <li><a href="http://cp210x-program.hg.sourceforge.net/hgweb/cp210x-program/cp210x-program/">Code Repository (Mercurial)</a>
+ </li></ul>
+
+ <p>
+Be aware that the current version is only tested on CP2102.
+ </p>
+
+ <p>
+The goal of this library is to provide access to the EEPROM of an Silabs CP210x
+under Linux.
+ </p>
+
+ <p>
+The CP210x is an USB-to-serial chip used in a lot of USB devices (similar to
+FTDIs and PL2303). The CP210x has a EEPROM on the chip which can be programmed
+via USB. Silabs provides already a library and gui programm to program this
+EEPROM, but only for windows.
+ </p>
+
+ <p>
+This project uses results from monitoring the USB bus when the windows library
+programms an CP210x. The windows library was not disassembled for this protocol
+analysis.
+ </p>
+
+ <p>
+When the programm is finished, a later goal would be to provide a library which
+can be used to access further functions of the CP210x like the general IO pins
+of the CP2103. The goal is not to provide an tty driver, such driver exists
+already for linux and BSD.
+ </p>
+
+
+ <dl>
+ <dt>Version:</dt> <dd>0.2</dd>
+ <dt>Author:</dt> <dd>Johannes Hölzl &lt;johannes.hoelzl@gmx.de&gt;</dd>
+ </dl>
+
+ <h2>Dependencies</h2>
+
+ <ul>
+ <li>Python &gt;= 2.4</li>
+ <li>ctypes &gt;= 0.9 (only when Python 2.4 is used)</li>
+ <li>libusb 0.1</li>
+ </ul>
+
+ <p>
+Since libusb is available on most Linux, Mac OS X and FreeBSD cp210x-program
+should run flawlessly on these platforms. Currently it is only tested on
+Linux 2.6 (Ubuntu).
+ </p>
+
+ <p>
+If cp210x-program should run as non-root user, add the udev rule found in
+doc/45-cp210x-programming.rules to /etc/udev/rules.d. When devices with already
+programmed IDs are reprogrammed at this IDs to 45-cp210x-programming.rules.
+ </p>
+
+ <h2>Usage</h2>
+
+ <h3>Read EEPROM content into hexfile:</h3>
+<pre>$ cp210x-program --read-cp210x -F eeprom-content.hex
+</pre>
+
+ <h3>Show EEPROM content from device 002 on bus 001:</h3>
+<pre>$ cp210x-program --read-cp210x -m 001/002
+</pre>
+
+ <h3>Write some data to device with vendor id 0x10C4 and product id 0xEA62:</h3>
+<pre>$ cp210x-program --write-cp210x -m 10C4:EA62 \
+ --set-product-string="Product String" \
+ --set-max-power=100 \
+ --set-bus-powered=no
+</pre>
+
+ <h2>TODO</h2>
+
+ <ul>
+ <li>Test on other than CP2102</li>
+ <li>Implement CP2103 GIOP settings</li>
+ <li>Implement GUI</li>
+ </ul>
+
+ <h2>Development</h2>
+
+ <ul>
+ <li>Clone repository: <code>hg clone http://cp210x-program.hg.sourceforge.net/hgweb/cp210x-program/cp210x-program/</code></li>
+ <li>Run, Change, Debug, Commit, Repeat</li>
+ <li>Ask me to get commit rights</li>
+ <li>Profit!</li>
+ </ul>
+
+ <h2>Links</h2>
+
+ <ul>
+ <li><a href="http://www.silabs.com/tgwWebApp/public/web_content/products/Microcontrollers/Interface/en/interface.htm">CP210x Product page on Silicon Labs</a></li>
+ <li><a href="http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an144.pdf">AN114 Customization Guide</a> (<a href="http://www.silabs.com/public/documents/software_doc/othersoftware/Microcontrollers/Interface/en/an144sw.zip">Software</a>)</li>
+ <li><a href="http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an205.pdf">AN205 CP210x Baudrate Guide</a> (<a href="http://www.silabs.com/public/documents/software_doc/othersoftware/Microcontrollers/en/AN205SW.zip">Software</a>)</li>
+ <li><a href="http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an223.pdf">AN223 Port Configuration and GPIO for CP210x</a> (<a href="http://www.silabs.com/public/documents/software_doc/othersoftware/Microcontrollers/Interface/en/AN223SW.zip">Software</a>)</li>
+ </ul>
+
+ <h2>License</h2>
+
+ <p>
+ The python package 'cp210x' and the python script 'cp210x-program' are provided
+under the terms of the GNU LGPL. See LICENSE.
+ </p>
+
+</body></html>
diff --git a/contrib/cp210x-program/setup.py b/contrib/cp210x-program/setup.py
new file mode 100755
index 0000000..4889f35
--- /dev/null
+++ b/contrib/cp210x-program/setup.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from distutils.core import setup
+
+setup(
+ name="cp210x-program",
+ version="0.2",
+ description="Provides access to the EEPROM in an Silabs CP210x",
+ long_description="""
+The goal of this library is to provide access to the EEPROM of an Silabs CP210x
+under Linux.
+
+The CP210x is an USB-to-serial chip used in a lot of USB devices (similar to
+FTDIs and PL2303). The CP210x has a EEPROM on the chip which can be programmed
+via USB. Silabs provides already a library and gui programm to program this
+EEPROM, but only for windows.
+
+For more information see:
+* http://www.silabs.com/tgwWebApp/public/web_content/products/Microcontrollers/Interface/en/interface.htm
+* http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Interface/en/an144.pdf
+
+Requires:
+* libusb: http://libusb.sourceforge.net/
+* ctypes: http://starship.python.net/crew/theller/ctypes/
+""",
+ author="Johannes Hölzl",
+ author_email="johannes.hoelzl@gmx.de",
+ url="http://cp210x-program.sourceforge.net/",
+ license="GNU LGPL",
+ platforms="POSIX",
+ classifiers=[
+ "License :: OSI-Approved Open Source :: GNU Library or Lesser General Public License (LGPL)",
+ "Intended Audience :: Manufacturing",
+ "Development Status :: 4 - Beta",
+ "Topic :: System :: Hardware :: Hardware Drivers",
+ "Programming Language :: Python",
+ "Operating System :: POSIX :: Linux",
+ "Operating System :: POSIX :: BSD :: FreeBSD",
+ "Operating System :: MacOS :: MacOS X",
+ ],
+ packages=[
+ 'cp210x'
+ ],
+ scripts=[
+ 'cp210x-program'
+ ],
+)