diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7b8c725
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.zip
+*.7z
+.development
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..c4cfc8c
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,18 @@
+# A GitHub Manifesto
+### Notes on contributing to my repositories
+Jack Christensen
+Jan 2018
+
+Surely Git and GitHub are wonderful tools. They make coding and collaboration so much easier. I'm equally impressed with the open source movement, and with the Arduino ecosystem in particular.
+
+I'm just one guy, mostly a hobbyist. Posting my projects to GitHub is my way of giving back a little to the community. It's very gratifying that some of my code has received a modicum of popularity.
+
+Like many things, this has been somewhat of a double-edged sword. Especially since I tend to be a pretty busy guy with many varied interests.
+
+First, I am always interested in bug reports. Please raise an issue in the appropriate repository and please please please include a good, concise description of the issue and a Short, Self Contained, Correct (Compilable), Example (see [sscce.org](http://www.sscce.org/)). I will need to be able to reproduce the issue, with minimal hardware, and without installing a dozen other libraries. I work exclusively with the AVR architecture so most times I will not be able to reproduce issues on other platforms. (There have been one or two occasions where relatively simple changes have been made to accommodate another platform; I am not necessarily averse to these.)
+
+Second, bug reports should always be for problems with *my* code. I will not use GitHub to help you with *your* code, even if you happen to be using one of my libraries. Please use the [Arduino forum](https://forum.arduino.cc/) or other such venue instead.
+
+Finally, pull requests can be problematic, especially if they represent enhancements rather than fixes. I seldom intend my code to be all things to all people. This is mostly a hobby activity and I have very limited bandwidth. Reviewing and managing PRs requires time that I do not often have. Sometimes a PR will take a library in a direction that I'm not interested in. Sometimes a PR will be counter to my original design intent. No doubt the author of a PR thinks that their new feature is the best thing since canned beer, but if I don't happen to share that opinion, then I'll decline it. OTOH, I am certainly capable of making stupid mistakes and missing absolutely fundamental things, and I do appreciate it when these are pointed out.
+
+All this to say, that if I do decline a request, please do not take it personally. Feel free to consider it my problem, not yours. At the end of the day, it's my code, and I reserve the right to decline issues or PRs for any reason, or for no reason at all. But here is the beauty of open source. You can always fork the repository and have your way with it.
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..2fb2e74
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,675 @@
+### GNU GENERAL PUBLIC LICENSE
+
+Version 3, 29 June 2007
+
+Copyright (C) 2007 Free Software Foundation, Inc.
+
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+### Preamble
+
+The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom
+to share and change all versions of a program--to make sure it remains
+free software for all its users. We, the Free Software Foundation, use
+the GNU General Public License for most of our software; it applies
+also to any other work released this way by its authors. You can apply
+it to your programs, too.
+
+When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you
+have certain responsibilities if you distribute copies of the
+software, or if you modify it: responsibilities to respect the freedom
+of others.
+
+For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the
+manufacturer can do so. This is fundamentally incompatible with the
+aim of protecting users' freedom to change the software. The
+systematic pattern of such abuse occurs in the area of products for
+individuals to use, which is precisely where it is most unacceptable.
+Therefore, we have designed this version of the GPL to prohibit the
+practice for those products. If such problems arise substantially in
+other domains, we stand ready to extend this provision to those
+domains in future versions of the GPL, as needed to protect the
+freedom of users.
+
+Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish
+to avoid the special danger that patents applied to a free program
+could make it effectively proprietary. To prevent this, the GPL
+assures that patents cannot be used to render the program non-free.
+
+The precise terms and conditions for copying, distribution and
+modification follow.
+
+### TERMS AND CONDITIONS
+
+#### 0. Definitions.
+
+"This License" refers to version 3 of the GNU General Public License.
+
+"Copyright" also means copyright-like laws that apply to other kinds
+of works, such as semiconductor masks.
+
+"The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of
+an exact copy. The resulting work is called a "modified version" of
+the earlier work or a work "based on" the earlier work.
+
+A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user
+through a computer network, with no transfer of a copy, is not
+conveying.
+
+An interactive user interface displays "Appropriate Legal Notices" to
+the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+#### 1. Source Code.
+
+The "source code" for a work means the preferred form of the work for
+making modifications to it. "Object code" means any non-source form of
+a work.
+
+A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+The Corresponding Source need not include anything that users can
+regenerate automatically from other parts of the Corresponding Source.
+
+The Corresponding Source for a work in source code form is that same
+work.
+
+#### 2. Basic Permissions.
+
+All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+You may make, run and propagate covered works that you do not convey,
+without conditions so long as your license otherwise remains in force.
+You may convey covered works to others for the sole purpose of having
+them make modifications exclusively for you, or provide you with
+facilities for running those works, provided that you comply with the
+terms of this License in conveying all material for which you do not
+control copyright. Those thus making or running the covered works for
+you must do so exclusively on your behalf, under your direction and
+control, on terms that prohibit them from making any copies of your
+copyrighted material outside their relationship with you.
+
+Conveying under any other circumstances is permitted solely under the
+conditions stated below. Sublicensing is not allowed; section 10 makes
+it unnecessary.
+
+#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such
+circumvention is effected by exercising rights under this License with
+respect to the covered work, and you disclaim any intention to limit
+operation or modification of the work as a means of enforcing, against
+the work's users, your or third parties' legal rights to forbid
+circumvention of technological measures.
+
+#### 4. Conveying Verbatim Copies.
+
+You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+#### 5. Conveying Modified Source Versions.
+
+You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these
+conditions:
+
+- a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+- b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under
+ section 7. This requirement modifies the requirement in section 4
+ to "keep intact all notices".
+- c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+- d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+#### 6. Conveying Non-Source Forms.
+
+You may convey a covered work in object code form under the terms of
+sections 4 and 5, provided that you also convey the machine-readable
+Corresponding Source under the terms of this License, in one of these
+ways:
+
+- a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+- b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the Corresponding
+ Source from a network server at no charge.
+- c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+- d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+- e) Convey the object code using peer-to-peer transmission,
+ provided you inform other peers where the object code and
+ Corresponding Source of the work are being offered to the general
+ public at no charge under subsection 6d.
+
+A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal,
+family, or household purposes, or (2) anything designed or sold for
+incorporation into a dwelling. In determining whether a product is a
+consumer product, doubtful cases shall be resolved in favor of
+coverage. For a particular product received by a particular user,
+"normally used" refers to a typical or common use of that class of
+product, regardless of the status of the particular user or of the way
+in which the particular user actually uses, or expects or is expected
+to use, the product. A product is a consumer product regardless of
+whether the product has substantial commercial, industrial or
+non-consumer uses, unless such uses represent the only significant
+mode of use of the product.
+
+"Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to
+install and execute modified versions of a covered work in that User
+Product from a modified version of its Corresponding Source. The
+information must suffice to ensure that the continued functioning of
+the modified object code is in no case prevented or interfered with
+solely because modification has been made.
+
+If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or
+updates for a work that has been modified or installed by the
+recipient, or for the User Product in which it has been modified or
+installed. Access to a network may be denied when the modification
+itself materially and adversely affects the operation of the network
+or violates the rules and protocols for communication across the
+network.
+
+Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+#### 7. Additional Terms.
+
+"Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders
+of that material) supplement the terms of this License with terms:
+
+- a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+- b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+- c) Prohibiting misrepresentation of the origin of that material,
+ or requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+- d) Limiting the use for publicity purposes of names of licensors
+ or authors of the material; or
+- e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+- f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions
+ of it) with contractual assumptions of liability to the recipient,
+ for any liability that these contractual assumptions directly
+ impose on those licensors and authors.
+
+All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions; the
+above requirements apply either way.
+
+#### 8. Termination.
+
+You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+However, if you cease all violation of this License, then your license
+from a particular copyright holder is reinstated (a) provisionally,
+unless and until the copyright holder explicitly and finally
+terminates your license, and (b) permanently, if the copyright holder
+fails to notify you of the violation by some reasonable means prior to
+60 days after the cessation.
+
+Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+#### 9. Acceptance Not Required for Having Copies.
+
+You are not required to accept this License in order to receive or run
+a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+#### 10. Automatic Licensing of Downstream Recipients.
+
+Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+#### 11. Patents.
+
+A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+A contributor's "essential patent claims" are all patent claims owned
+or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+A patent license is "discriminatory" if it does not include within the
+scope of its coverage, prohibits the exercise of, or is conditioned on
+the non-exercise of one or more of the rights that are specifically
+granted under this License. You may not convey a covered work if you
+are a party to an arrangement with a third party that is in the
+business of distributing software, under which you make payment to the
+third party based on the extent of your activity of conveying the
+work, and under which the third party grants, to any of the parties
+who would receive the covered work from you, a discriminatory patent
+license (a) in connection with copies of the covered work conveyed by
+you (or copies made from those copies), or (b) primarily for and in
+connection with specific products or compilations that contain the
+covered work, unless you entered into that arrangement, or that patent
+license was granted, prior to 28 March 2007.
+
+Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+#### 12. No Surrender of Others' Freedom.
+
+If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under
+this License and any other pertinent obligations, then as a
+consequence you may not convey it at all. For example, if you agree to
+terms that obligate you to collect a royalty for further conveying
+from those to whom you convey the Program, the only way you could
+satisfy both those terms and this License would be to refrain entirely
+from conveying the Program.
+
+#### 13. Use with the GNU Affero General Public License.
+
+Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+#### 14. Revised Versions of this License.
+
+The Free Software Foundation may publish revised and/or new versions
+of the GNU General Public License from time to time. Such new versions
+will be similar in spirit to the present version, but may differ in
+detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies that a certain numbered version of the GNU General Public
+License "or any later version" applies to it, you have the option of
+following the terms and conditions either of that numbered version or
+of any later version published by the Free Software Foundation. If the
+Program does not specify a version number of the GNU General Public
+License, you may choose any version ever published by the Free
+Software Foundation.
+
+If the Program specifies that a proxy can decide which future versions
+of the GNU General Public License can be used, that proxy's public
+statement of acceptance of a version permanently authorizes you to
+choose that version for the Program.
+
+Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+#### 15. Disclaimer of Warranty.
+
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
+WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
+PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
+DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
+CORRECTION.
+
+#### 16. Limitation of Liability.
+
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
+CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
+NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
+LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
+TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
+PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+#### 17. Interpretation of Sections 15 and 16.
+
+If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+END OF TERMS AND CONDITIONS
+
+### How to Apply These Terms to Your New Programs
+
+If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these
+terms.
+
+To do so, attach the following notices to the program. It is safest to
+attach them to the start of each source file to most effectively state
+the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper
+mail.
+
+If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands \`show w' and \`show c' should show the
+appropriate parts of the General Public License. Of course, your
+program's commands might be different; for a GUI interface, you would
+use an "about box".
+
+You should also get your employer (if you work as a programmer) or
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. For more information on this, and how to apply and follow
+the GNU GPL, see .
+
+The GNU General Public License does not permit incorporating your
+program into proprietary programs. If your program is a subroutine
+library, you may consider it more useful to permit linking proprietary
+applications with the library. If this is what you want to do, use the
+GNU Lesser General Public License instead of this License. But first,
+please read .
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6393410
--- /dev/null
+++ b/README.md
@@ -0,0 +1,205 @@
+# Arduino EEPROM Library
+http://github.com/JChristensen/JC_EEPROM
+README file
+
+
+## License
+Arduino EEPROM Library Copyright (C) 2022 Jack Christensen GNU GPL v3.0
+
+This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License v3.0 as published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program. If not, see
+
+## Introduction
+**Arduino EEPROM Library**
+
+This library will work with most I2C serial EEPROM chips between 2k bits and 2048k bits (2M bits) in size. Multiple EEPROMs on the bus are supported as a single address space. I/O across block, page and device boundaries is supported. Certain assumptions are made regarding the EEPROM device addressing. These assumptions should be true for most EEPROMs but there are exceptions, so read the datasheet and know your hardware.
+
+The library should also work for EEPROMs smaller than 2k bits, assuming that there is only one EEPROM on the bus and also that the user is careful to not exceed the maximum address for the EEPROM.
+
+The **JC_EEPROM Library** has been tested with:
+- Microchip 24AA02E48 (2k bit)
+- 24xx32 (32k bit, thanks to Richard M)
+- Microchip 24LC256 (256k bit)
+- Microchip 24FC1026 (1M bit, thanks to Gabriele B on the Arduino forum)
+- ST Micro M24M02 (2M bit)
+
+The **JC_EEPROM Library** will **NOT** work with Microchip 24xx1025 as its control byte does not conform to the following assumptions.
+
+**Device addressing assumptions:**
+- The I2C address sequence consists of a control byte followed by one address byte (for EEPROMs <= 16k bits) or two address bytes (for EEPROMs > 16k bits).
+- The three least-significant bits in the control byte (excluding the R/W bit) comprise the three most-significant bits for the entire address space, i.e. all chips on the bus. As such, these may be chip-select bits or block-select bits (for individual chips that have an internal block organization), or a combination of both (in which case the block-select bits must be of lesser significance than the chip-select bits).
+- Regardless of the number of bits needed to address the entire address space, the three most-significant bits always go in the control byte. Depending on EEPROM device size, this may result in one or more of the most significant bits in the I2C address bytes being unused (or "don't care" bits).
+- An EEPROM contains an integral number of pages.
+
+Note that the Arduino Wire library has a buffer size of 32 bytes. This limits the size of physical I/Os that can be done to EEPROM. For writes, one or two bytes are used for the address, so writing is therefore limited to 31 or 30 bytes. Because the **JC_EEPROM Library** will handle I/O across block, page and device boundaries, the only consequence this has for the user is one of efficiency; arbitrarily large blocks of data can be written and read; however, carefully chosen block sizes may reduce the number of physical I/Os needed.
+
+## Installation
+The library can be installed using the Arduino Library Manager. To install manually:
+- Go to http://github.com/JChristensen/JC_EEPROM, click **Code > Download ZIP** and save the ZIP file to a convenient location on your PC.
+- Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, usually **JC_EEPROM-master**.
+- Rename the folder to just **JC_EEPROM**.
+- Copy the renamed folder to the Arduino sketchbook/libraries folder.
+
+## Examples
+The following example sketch is included with the **JC_EEPROM Library**:
+- **eepromTest:** Writes 32-bit integers to the entire EEPROM address space, starting at address 0 and continuing to the topmost address. These are then read back in and verified; any discrepancies are reported to the serial monitor.
+
+## Enumerations
+
+### eeprom_size_t
+##### Description
+EEPROM device size in k-bits. Many manufacturers' EEPROM part numbers are designated in k-bits.
+##### Values
+- JC_EEPROM::kbits_2
+- JC_EEPROM::kbits_4
+- JC_EEPROM::kbits_8
+- JC_EEPROM::kbits_16
+- JC_EEPROM::kbits_32
+- JC_EEPROM::kbits_64
+- JC_EEPROM::kbits_128
+- JC_EEPROM::kbits_256
+- JC_EEPROM::kbits_512
+- JC_EEPROM::kbits_1024
+- JC_EEPROM::kbits_2048
+
+### twiClockFreq_t
+##### Description
+I2C bus speed.
+##### Values
+- JC_EEPROM::twiClock100kHz
+- JC_EEPROM::twiClock400kHz
+
+## Constructor
+
+### JC_EEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr)
+##### Description
+Instantiates an external EEPROM object.
+##### Syntax
+`JC_EEPROM myEEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr));`
+##### Parameters
+**devCap** *(eeprom_size_t)*: The size of one EEPROM device in k-bits. Choose a value from the eeprom_size_t enumeration above.
+**nDev** *(byte)*: The number of EEPROM devices on the bus. Note that if there are multiple EEPROM devices on the bus, they must be identical and each must have its address pins strapped properly.
+**pgSize** *(unsigned int)*: The EEPROM page size in bytes. Consult the datasheet if you are unsure of the page size.
+**busAddr** *(byte)*: The base I2C bus address for the EEPROM(s). 0x50 is a common value and this parameter can be omitted, in which case 0x50 will be used as the default.
+##### Example
+```c++
+JC_EEPROM myEEPROM(kbits_256, 2, 64); //two 24LC256 EEPROMS on the bus
+JC_EEPROM oddEEPROM(kbits_8, 1, 16, 0x42); //an EEPROM with a non-standard I2C address
+```
+
+## Methods
+### begin(twiClockFreq_t freq)
+##### Description
+Initializes the library. Call this method once in the setup code. begin() does a dummy I/O so that the user may interrogate the return status to ensure the EEPROM is operational.
+##### Syntax
+`myEEPROM.begin(twiClockFreq_t freq);`
+##### Parameters
+**freq** *(twiClockFreq_t)*: The desired I2C bus speed, `JC_EEPROM::twiClock100kHz` or `JC_EEPROM::twiClock400kHz`. Can be omitted in which case it will default to `twiClock100kHz`. **NOTE:** When using 400kHz, if there are other devices on the bus they must all support a 400kHz bus speed. **Secondly**, the other devices should be initialized first, as other libraries may not support adjusting the bus speed. To ensure the desired speed is set, call the JC_EEPROM.begin() function *after* initializing all other I2C devices.
+##### Returns
+I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes.
+##### Example
+```c++
+JC_EEPROM myEEPROM(kbits_256, 2, 64);
+byte i2cStat = myEEPROM.begin(JC_EEPROM::twiClock400kHz);
+if ( i2cStat != 0 ) {
+ //there was a problem
+}
+```
+### write(unsigned long addr, byte *values, unsigned int nBytes)
+##### Description
+Write one or more bytes to external EEPROM.
+##### Syntax
+`myEEPROM.write(unsigned long addr, byte* values, byte nBytes);`
+##### Parameters
+**addr** *(unsigned long)*: The beginning EEPROM location to write.
+**values** _(byte*)_: Pointer to an array containing the data to write.
+**nBytes** *(unsigned int)*: The number of bytes to write.
+##### Returns
+I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
+##### Example
+```c++
+byte myData[10];
+//write 10 bytes starting at location 42
+byte i2cStat = myEEPROM.write(42, myData, 10);
+if ( i2cStat != 0 ) {
+ //there was a problem
+ if ( i2cStat == EEPROM_ADDR_ERR) {
+ //bad address
+ }
+ else {
+ //some other I2C error
+ }
+}
+```
+### write(unsigned long addr, byte value)
+##### Description
+Writes a single byte to external EEPROM.
+##### Syntax
+`myEEPROM.write(unsigned long addr, byte value);`
+##### Parameters
+**addr** *(unsigned long)*: The EEPROM location to write.
+**values** _(byte)_: The value to write.
+##### Returns
+Same as multiple-byte write() above.
+##### Example
+```c++
+//write the value 16 to EEPROM location 314.
+byte i2cStat = myEEPROM.write(314, 16);
+```
+### read(unsigned long addr, byte *values, unsigned int nBytes)
+##### Description
+Reads one or more bytes from external EEPROM into an array supplied by the caller.
+##### Syntax
+`myEEPROM.read(unsigned long addr, byte *values, byte nBytes);`
+##### Parameters
+**addr** *(unsigned long)*: The beginning EEPROM location to read from.
+**values** _(byte*)_: Pointer to an array to receive the data.
+**nBytes** *(unsigned int)*: The number of bytes to read.
+##### Returns
+I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
+##### Example
+```c++
+byte myData[10];
+//read 10 bytes starting at location 42
+byte i2cStat = myEEPROM.read(42, myData, 10);
+if ( i2cStat != 0 ) {
+ //there was a problem
+ if ( i2cStat == EEPROM_ADDR_ERR) {
+ //bad address
+ }
+ else {
+ //some other I2C error
+ }
+}
+```
+### read(unsigned long addr)
+##### Description
+Reads a single byte from external EEPROM.
+##### Syntax
+`myEEPROM.read(unsigned long addr);`
+##### Parameters
+**addr** *(unsigned long)*: The EEPROM location to read from.
+##### Returns
+The data read from EEPROM or an error code *(int)*. To distinguish error values from valid data, error values are returned as negative numbers. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
+
+##### Example
+```c++
+int myData;
+//read a byte from location 42
+int readValue = myEEPROM.read(42);
+if ( readValue < 0 ) {
+ //there was a problem
+ if ( -readValue == EEPROM_ADDR_ERR) {
+ //bad address
+ }
+ else {
+ //some other I2C error
+ }
+}
+else {
+ //data read ok
+}
+```
diff --git a/examples/eepromTest/eepromTest.ino b/examples/eepromTest/eepromTest.ino
new file mode 100644
index 0000000..93936aa
--- /dev/null
+++ b/examples/eepromTest/eepromTest.ino
@@ -0,0 +1,137 @@
+// Arduino JC_EEPROM Library
+// https://github.com/JChristensen/JC_EEPROM
+// Copyright (C) 2022 by Jack Christensen and licensed under
+// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
+//
+// Example sketch to test JC_EEPROM library.
+// Writes the EEPROM full of 32-bit integers and reads them back to verify.
+// Wire a button from digital pin 6 to ground, this is used as a start button
+// so the sketch doesn't do unnecessary EEPROM writes every time it's reset.
+// Jack Christensen 09Jul2014
+
+#include // https://github.com/JChristensen/JC_EEPROM
+#include // https://github.com/janelia-arduino/Streaming
+#include // https://arduino.cc/en/Reference/Wire
+
+// Two 24LC256 EEPROMs on the bus
+JC_EEPROM eep(JC_EEPROM::kbits_256, 2, 64); // device size, number of devices, page size
+
+constexpr uint32_t totalKBytes {64}; // for read and write test functions
+constexpr uint8_t btnStart {6}; // pin for start button
+
+void setup()
+{
+ pinMode(btnStart, INPUT_PULLUP);
+ Serial.begin(115200);
+ Serial << F( "\n" __FILE__ "\n" __DATE__ " " __TIME__ "\n" );
+
+ uint8_t eepStatus = eep.begin(JC_EEPROM::twiClock400kHz); // go fast!
+ if (eepStatus) {
+ Serial << endl << F("extEEPROM.begin() failed, status = ") << eepStatus << endl;
+ while (1);
+ }
+
+ Serial << endl << F("Press button to start...") << endl;
+ while (digitalRead(btnStart) == HIGH) delay(10); // wait for button push
+
+ // chunkSize can be changed, but must be a multiple of 4 since we're writing 32-bit integers
+ uint8_t chunkSize = 64;
+ //eeErase(chunkSize, 0, totalKBytes * 1024 - 1);
+ eeWrite(chunkSize);
+ eeRead(chunkSize);
+
+ dump(0, 16); // the first 16 bytes
+ dump(32752, 32); // across the device boundary
+ dump(65520, 16); // the last 16 bytes
+}
+
+void loop()
+{
+}
+
+// write test data (32-bit integers) to eeprom, "chunk" bytes at a time
+void eeWrite(uint8_t chunk)
+{
+ chunk &= 0xFC; // force chunk to be a multiple of 4
+ uint8_t data[chunk];
+ uint32_t val = 0;
+ Serial << F("Writing...") << endl;
+ uint32_t msStart = millis();
+
+ for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) {
+ if ( (addr &0xFFF) == 0 ) Serial << addr << endl;
+ for (uint8_t c = 0; c < chunk; c += 4) {
+ data[c+0] = val >> 24;
+ data[c+1] = val >> 16;
+ data[c+2] = val >> 8;
+ data[c+3] = val;
+ ++val;
+ }
+ eep.write(addr, data, chunk);
+ }
+ uint32_t msLapse = millis() - msStart;
+ Serial << "Write lapse: " << msLapse << " ms" << endl;
+}
+
+// read test data (32-bit integers) from eeprom, "chunk" bytes at a time
+void eeRead(uint8_t chunk)
+{
+ chunk &= 0xFC; // force chunk to be a multiple of 4
+ uint8_t data[chunk];
+ uint32_t val = 0, testVal;
+ Serial << F("Reading...") << endl;
+ uint32_t msStart = millis();
+
+ for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) {
+ if ( (addr &0xFFF) == 0 ) Serial << addr << endl;
+ eep.read(addr, data, chunk);
+ for (uint8_t c = 0; c < chunk; c += 4) {
+ testVal = ((uint32_t)data[c+0] << 24) + ((uint32_t)data[c+1] << 16) + ((uint32_t)data[c+2] << 8) + (uint32_t)data[c+3];
+ if (testVal != val) Serial << F("Error @ addr ") << addr+c << F(" Expected ") << val << F(" Read ") << testVal << F(" 0x") << _HEX(testVal) << endl;
+ ++val;
+ }
+ }
+ uint32_t msLapse = millis() - msStart;
+ Serial << "Last value: " << --val << " Read lapse: " << msLapse << " ms" << endl;
+}
+
+// write 0xFF to eeprom, "chunk" bytes at a time
+void eeErase(uint8_t chunk, uint32_t startAddr, uint32_t endAddr)
+{
+ chunk &= 0xFC; // force chunk to be a multiple of 4
+ uint8_t data[chunk];
+ Serial << F("Erasing...") << endl;
+ for (int i = 0; i < chunk; i++) data[i] = 0xFF;
+ uint32_t msStart = millis();
+
+ for (uint32_t a = startAddr; a <= endAddr; a += chunk) {
+ if ( (a &0xFFF) == 0 ) Serial << a << endl;
+ eep.write(a, data, chunk);
+ }
+ uint32_t msLapse = millis() - msStart;
+ Serial << "Erase lapse: " << msLapse << " ms" << endl;
+}
+
+// dump eeprom contents, 16 bytes at a time.
+// always dumps a multiple of 16 bytes.
+void dump(uint32_t startAddr, uint32_t nBytes)
+{
+ Serial << endl << F("EEPROM DUMP 0x") << _HEX(startAddr) << F(" 0x") << _HEX(nBytes) << ' ' << startAddr << ' ' << nBytes << endl;
+ uint32_t nRows = (nBytes + 15) >> 4;
+
+ uint8_t d[16];
+ for (uint32_t r = 0; r < nRows; r++) {
+ uint32_t a = startAddr + 16 * r;
+ eep.read(a, d, 16);
+ Serial << "0x";
+ if ( a < 16 * 16 * 16 ) Serial << '0';
+ if ( a < 16 * 16 ) Serial << '0';
+ if ( a < 16 ) Serial << '0';
+ Serial << _HEX(a) << ' ';
+ for ( int c = 0; c < 16; c++ ) {
+ if ( d[c] < 16 ) Serial << '0';
+ Serial << _HEX( d[c] ) << ( c == 7 ? " " : " " );
+ }
+ Serial << endl;
+ }
+}
diff --git a/keywords.txt b/keywords.txt
new file mode 100644
index 0000000..a1a38b1
--- /dev/null
+++ b/keywords.txt
@@ -0,0 +1,18 @@
+JC_EEPROM KEYWORD1
+begin KEYWORD2
+write KEYWORD2
+read KEYWORD2
+kbits_2 LITERAL1
+kbits_4 LITERAL1
+kbits_8 LITERAL1
+kbits_16 LITERAL1
+kbits_32 LITERAL1
+kbits_64 LITERAL1
+kbits_128 LITERAL1
+kbits_256 LITERAL1
+kbits_512 LITERAL1
+kbits_1024 LITERAL1
+kbits_2048 LITERAL1
+twiClock100kHz LITERAL1
+twiClock400kHz LITERAL1
+EEPROM_ADDR_ERR LITERAL1
diff --git a/library.properties b/library.properties
new file mode 100644
index 0000000..23f62fa
--- /dev/null
+++ b/library.properties
@@ -0,0 +1,10 @@
+name=JC_EEPROM
+version=1.0.0
+author=Jack Christensen
+maintainer=Jack Christensen
+sentence=Arduino library to support external I2C EEPROMs.
+paragraph=Copyright (C) 2022 by Jack Christensen and licensed under GNU GPL v3.0.
+category=Data Storage
+url=https://github.com/JChristensen/JC_EEPROM
+architectures=avr
+depends=Wire
diff --git a/src/JC_EEPROM.cpp b/src/JC_EEPROM.cpp
new file mode 100644
index 0000000..8dfdb34
--- /dev/null
+++ b/src/JC_EEPROM.cpp
@@ -0,0 +1,162 @@
+// Arduino JC_EEPROM Library
+// https://github.com/JChristensen/JC_EEPROM
+// Copyright (C) 2022 by Jack Christensen and licensed under
+// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
+//
+// Arduino library to support external I2C EEPROMs.
+
+#include
+#include
+
+// Constructor.
+// - deviceCapacity is the capacity of a single EEPROM device in
+// kilobits (kb) and should be one of the values defined in the
+// eeprom_size_t enumeration in the extEEPROM.h file. (Most
+// EEPROM manufacturers use kbits in their part numbers.)
+// - nDevice is the number of EEPROM devices on the I2C bus (all must
+// be identical).
+// - pageSize is the EEPROM's page size in bytes.
+// - eepromAddr is the EEPROM's I2C address and defaults to 0x50 which is common.
+JC_EEPROM::JC_EEPROM(eeprom_size_t deviceCapacity, byte nDevice, unsigned int pageSize, uint8_t eepromAddr)
+{
+ _dvcCapacity = deviceCapacity;
+ _nDevice = nDevice;
+ _pageSize = pageSize;
+ _eepromAddr = eepromAddr;
+ _totalCapacity = _nDevice * _dvcCapacity * 1024UL / 8;
+ _nAddrBytes = deviceCapacity > kbits_16 ? 2 : 1; // two address bytes needed for eeproms > 16kbits
+
+ // determine the bitshift needed to isolate the chip select bits from
+ // the address to put into the control byte
+ uint16_t kb = _dvcCapacity;
+ if ( kb <= kbits_16 ) _csShift = 8;
+ else if ( kb >= kbits_512 ) _csShift = 16;
+ else {
+ kb >>= 6;
+ _csShift = 12;
+ while ( kb >= 1 ) {
+ ++_csShift;
+ kb >>= 1;
+ }
+ }
+}
+
+// initialize the I2C bus and do a dummy write (no data sent)
+// to the device so that the caller can determine whether it is responding.
+// when using a 400kHz bus speed and there are multiple I2C devices on the
+// bus (other than EEPROM), call extEEPROM::begin() after any initialization
+// calls for the other devices to ensure the intended I2C clock speed is set.
+byte JC_EEPROM::begin(twiClockFreq_t twiFreq)
+{
+ Wire.begin();
+ TWBR = ( (F_CPU / twiFreq) - 16) / 2;
+ Wire.beginTransmission(_eepromAddr);
+ if (_nAddrBytes == 2) Wire.write(0); // high addr byte
+ Wire.write(0); // low addr byte
+ return Wire.endTransmission();
+}
+
+// Write bytes to external EEPROM.
+// If the I/O would extend past the top of the EEPROM address space,
+// a status of EEPROM_ADDR_ERR is returned. For I2C errors, the status
+// from the Arduino Wire library is passed back through to the caller.
+byte JC_EEPROM::write(unsigned long addr, byte *values, unsigned int nBytes)
+{
+ uint8_t ctrlByte; // control byte (I2C device address & chip/block select bits)
+ uint8_t txStatus = 0; // transmit status
+ uint16_t nWrite; // number of bytes to write
+ uint16_t nPage; // number of bytes remaining on current page, starting at addr
+
+ if (addr + nBytes > _totalCapacity) { // will this write go past the top of the EEPROM?
+ return EEPROM_ADDR_ERR; // yes, tell the caller
+ }
+
+ while (nBytes > 0) {
+ nPage = _pageSize - ( addr & (_pageSize - 1) );
+ // find min(nBytes, nPage, BUFFER_LENGTH) -- BUFFER_LENGTH is defined in the Wire library.
+ nWrite = nBytes < nPage ? nBytes : nPage;
+ nWrite = BUFFER_LENGTH - _nAddrBytes < nWrite ? BUFFER_LENGTH - _nAddrBytes : nWrite;
+ ctrlByte = _eepromAddr | (byte) (addr >> _csShift);
+ Wire.beginTransmission(ctrlByte);
+ if (_nAddrBytes == 2) Wire.write( (byte) (addr >> 8) ); // high addr byte
+ Wire.write( (byte) addr ); //low addr byte
+ Wire.write(values, nWrite);
+ txStatus = Wire.endTransmission();
+ if (txStatus != 0) return txStatus;
+
+ // wait up to 50ms for the write to complete
+ for (uint8_t i=100; i; --i) {
+ delayMicroseconds(500); // no point in waiting too fast
+ Wire.beginTransmission(ctrlByte);
+ if (_nAddrBytes == 2) Wire.write(0); // high addr byte
+ Wire.write(0); // low addr byte
+ txStatus = Wire.endTransmission();
+ if (txStatus == 0) break;
+ }
+ if (txStatus != 0) return txStatus;
+
+ addr += nWrite; // increment the EEPROM address
+ values += nWrite; // increment the input data pointer
+ nBytes -= nWrite; // decrement the number of bytes left to write
+ }
+ return txStatus;
+}
+
+// Read bytes from external EEPROM.
+// If the I/O would extend past the top of the EEPROM address space,
+// a status of EEPROM_ADDR_ERR is returned. For I2C errors, the status
+// from the Arduino Wire library is passed back through to the caller.
+byte JC_EEPROM::read(unsigned long addr, byte *values, unsigned int nBytes)
+{
+ byte ctrlByte;
+ byte rxStatus;
+ uint16_t nRead; // number of bytes to read
+ uint16_t nPage; // number of bytes remaining on current page, starting at addr
+
+ if (addr + nBytes > _totalCapacity) { // will this read take us past the top of the EEPROM?
+ return EEPROM_ADDR_ERR; // yes, tell the caller
+ }
+
+ while (nBytes > 0) {
+ nPage = _pageSize - ( addr & (_pageSize - 1) );
+ nRead = nBytes < nPage ? nBytes : nPage;
+ nRead = BUFFER_LENGTH < nRead ? BUFFER_LENGTH : nRead;
+ ctrlByte = _eepromAddr | (byte) (addr >> _csShift);
+ Wire.beginTransmission(ctrlByte);
+ if (_nAddrBytes == 2) Wire.write( (byte) (addr >> 8) ); // high addr byte
+ Wire.write( (byte) addr ); // low addr byte
+ rxStatus = Wire.endTransmission();
+ if (rxStatus != 0) return rxStatus; // read error
+
+ Wire.requestFrom(ctrlByte, nRead);
+ for (byte i=0; i 16k bits).
+// 2. The three least-significant bits in the control byte (excluding the R/W
+// bit) comprise the three most-significant bits for the entire address
+// space, i.e. all chips on the bus. As such, these may be chip-select
+// bits or block-select bits (for individual chips that have an internal
+// block organization), or a combination of both (in which case the
+// block-select bits must be of lesser significance than the chip-select
+// bits).
+// 3. Regardless of the number of bits needed to address the entire address
+// space, the three most-significant bits always go in the control byte.
+// Depending on EEPROM device size, this may result in one or more of the
+// most significant bits in the I2C address bytes being unused (or "don't
+// care").
+// 4. An EEPROM contains an integral number of pages.
+//
+// To use the extEEPROM library, the Arduino Wire library must also
+// be included.
+//
+// Jack Christensen 23Mar2013 v1
+// 29Mar2013 v2 - Updated to span page boundaries (and therefore also
+// device boundaries, assuming an integral number of pages per device)
+// 08Jul2014 v3 - Generalized for 2kb - 2Mb EEPROMs.
+// 11Jan2022 v1.0.0 - Rename to JC_EEPROM, conform to Arduino library standards.
+
+#ifndef JC_EEPROM_H_INCLUDED
+#define JC_EEPROM_H_INCLUDED
+
+#include
+#include
+
+class JC_EEPROM
+{
+ public:
+ // EEPROM size in kilobits.
+ // EEPROM part numbers are usually designated in k-bits.
+ enum eeprom_size_t {
+ kbits_2 = 2,
+ kbits_4 = 4,
+ kbits_8 = 8,
+ kbits_16 = 16,
+ kbits_32 = 32,
+ kbits_64 = 64,
+ kbits_128 = 128,
+ kbits_256 = 256,
+ kbits_512 = 512,
+ kbits_1024 = 1024,
+ kbits_2048 = 2048
+ };
+
+ // I2C clock frequencies
+ enum twiClockFreq_t { twiClock100kHz = 100000, twiClock400kHz = 400000 };
+
+ // EEPROM addressing error, returned by write() or read() if
+ // upper address bound is exceeded
+ static const uint8_t EEPROM_ADDR_ERR {9};
+
+ JC_EEPROM(eeprom_size_t deviceCapacity, byte nDevice, unsigned int pageSize, byte eepromAddr = 0x50);
+ byte begin(twiClockFreq_t twiFreq = twiClock100kHz);
+ byte write(unsigned long addr, byte *values, unsigned int nBytes);
+ byte write(unsigned long addr, byte value);
+ byte read(unsigned long addr, byte *values, unsigned int nBytes);
+ int read(unsigned long addr);
+
+ private:
+ uint8_t _eepromAddr; // eeprom i2c address
+ uint16_t _dvcCapacity; // capacity of one EEPROM device, in kbits
+ uint8_t _nDevice; // number of devices on the bus
+ uint16_t _pageSize; // page size in bytes
+ uint8_t _csShift; // number of bits to shift address for chip select bits in control byte
+ uint16_t _nAddrBytes; // number of address bytes (1 or 2)
+ unsigned long _totalCapacity; // capacity of all EEPROM devices on the bus, in bytes
+};
+
+#endif