Browse Source

first commit

Erik van der Zalm 12 years ago
parent
commit
750f6c33e3

+ 188
- 0
Marlin/COPYING View File

@@ -0,0 +1,188 @@
1
+GNU GENERAL PUBLIC LICENSE
2
+
3
+Version 3, 29 June 2007
4
+
5
+Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
6
+
7
+Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
8
+Preamble
9
+
10
+The GNU General Public License is a free, copyleft license for software and other kinds of works.
11
+
12
+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.
13
+
14
+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.
15
+
16
+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.
17
+
18
+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.
19
+
20
+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.
21
+
22
+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.
23
+
24
+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.
25
+
26
+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.
27
+
28
+The precise terms and conditions for copying, distribution and modification follow.
29
+TERMS AND CONDITIONS
30
+0. Definitions.
31
+
32
+“This License” refers to version 3 of the GNU General Public License.
33
+
34
+“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
35
+
36
+“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.
37
+
38
+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.
39
+
40
+A “covered work” means either the unmodified Program or a work based on the Program.
41
+
42
+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.
43
+
44
+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.
45
+
46
+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.
47
+1. Source Code.
48
+
49
+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.
50
+
51
+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.
52
+
53
+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.
54
+
55
+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.
56
+
57
+The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
58
+
59
+The Corresponding Source for a work in source code form is that same work.
60
+2. Basic Permissions.
61
+
62
+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.
63
+
64
+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.
65
+
66
+Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
67
+3. Protecting Users' Legal Rights From Anti-Circumvention Law.
68
+
69
+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.
70
+
71
+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.
72
+4. Conveying Verbatim Copies.
73
+
74
+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.
75
+
76
+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.
77
+5. Conveying Modified Source Versions.
78
+
79
+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:
80
+
81
+    a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
82
+    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”.
83
+    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.
84
+    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.
85
+
86
+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.
87
+6. Conveying Non-Source Forms.
88
+
89
+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:
90
+
91
+    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.
92
+    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.
93
+    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.
94
+    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.
95
+    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.
96
+
97
+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.
98
+
99
+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.
100
+
101
+“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.
102
+
103
+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).
104
+
105
+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.
106
+
107
+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.
108
+7. Additional Terms.
109
+
110
+“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.
111
+
112
+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.
113
+
114
+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:
115
+
116
+    a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
117
+    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
118
+    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
119
+    d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
120
+    e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
121
+    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.
122
+
123
+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.
124
+
125
+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.
126
+
127
+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.
128
+8. Termination.
129
+
130
+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).
131
+
132
+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.
133
+
134
+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.
135
+
136
+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.
137
+9. Acceptance Not Required for Having Copies.
138
+
139
+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.
140
+10. Automatic Licensing of Downstream Recipients.
141
+
142
+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.
143
+
144
+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.
145
+
146
+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.
147
+11. Patents.
148
+
149
+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”.
150
+
151
+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.
152
+
153
+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.
154
+
155
+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.
156
+
157
+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.
158
+
159
+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.
160
+
161
+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.
162
+
163
+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.
164
+12. No Surrender of Others' Freedom.
165
+
166
+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.
167
+13. Use with the GNU Affero General Public License.
168
+
169
+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.
170
+14. Revised Versions of this License.
171
+
172
+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.
173
+
174
+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.
175
+
176
+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.
177
+
178
+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.
179
+15. Disclaimer of Warranty.
180
+
181
+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.
182
+16. Limitation of Liability.
183
+
184
+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.
185
+17. Interpretation of Sections 15 and 16.
186
+
187
+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.
188
+

+ 133
- 0
Marlin/Configuration.h View File

@@ -0,0 +1,133 @@
1
+#ifndef CONFIGURATION_H
2
+#define CONFIGURATION_H
3
+
4
+// BASIC SETTINGS: select your board type, thermistor type, axis scaling, and endstop configuration
5
+
6
+//// The following define selects which electronics board you have. Please choose the one that matches your setup
7
+// Gen6 = 5, 
8
+#define MOTHERBOARD 5 
9
+
10
+//// Thermistor settings:
11
+// 1 is 100k thermistor
12
+// 2 is 200k thermistor
13
+// 3 is mendel-parts thermistor
14
+#define THERMISTORHEATER 3
15
+
16
+// extruder advance constant (s2/mm3)
17
+//
18
+// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2
19
+//
20
+// hooke's law says:		force = k * distance
21
+// bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant
22
+// so: v ^ 2 is proportional to number of steps we advance the extruder
23
+//#define ADVANCE
24
+
25
+#ifdef ADVANCE
26
+#define EXTRUDER_ADVANCE_K 0.02
27
+
28
+#define D_FILAMENT 1.7
29
+#define STEPS_MM_E 65
30
+//#define D_FILAMENT 2.85
31
+//#define STEPS_MM_E 367.35
32
+#define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
33
+#define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
34
+
35
+#endif // ADVANCE
36
+
37
+//// Calibration variables
38
+// X, Y, Z, E steps per unit - Metric Prusa Mendel with V9 extruder:
39
+float axis_steps_per_unit[] = {40, 40, 3333.92,76.2}; 
40
+// Metric Prusa Mendel with Makergear geared stepper extruder:
41
+//float axis_steps_per_unit[] = {80,80,3200/1.25,1380}; 
42
+
43
+//// Endstop Settings
44
+#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
45
+// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
46
+const bool ENDSTOPS_INVERTING = false; //set to true to invert the logic of the endstops
47
+
48
+// This determines the communication speed of the printer
49
+#define BAUDRATE 250000
50
+
51
+// Comment out (using // at the start of the line) to disable SD support:
52
+//#define SDSUPPORT
53
+
54
+
55
+//// ADVANCED SETTINGS - to tweak parameters
56
+
57
+#include "thermistortables.h"
58
+
59
+// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
60
+#define X_ENABLE_ON 0
61
+#define Y_ENABLE_ON 0
62
+#define Z_ENABLE_ON 0
63
+#define E_ENABLE_ON 0
64
+
65
+// Disables axis when it's not being used.
66
+#define DISABLE_X false
67
+#define DISABLE_Y false
68
+#define DISABLE_Z true
69
+#define DISABLE_E false
70
+
71
+// Inverting axis direction
72
+#define INVERT_X_DIR false
73
+#define INVERT_Y_DIR true
74
+#define INVERT_Z_DIR false
75
+#define INVERT_E_DIR true
76
+
77
+//// ENDSTOP SETTINGS:
78
+// Sets direction of endstops when homing; 1=MAX, -1=MIN
79
+#define X_HOME_DIR -1
80
+#define Y_HOME_DIR -1
81
+#define Z_HOME_DIR -1
82
+
83
+#define min_software_endstops false //If true, axis won't move to coordinates less than zero.
84
+#define max_software_endstops true  //If true, axis won't move to coordinates greater than the defined lengths below.
85
+#define X_MAX_LENGTH 200
86
+#define Y_MAX_LENGTH 200
87
+#define Z_MAX_LENGTH 100
88
+
89
+//// MOVEMENT SETTINGS
90
+#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
91
+float max_feedrate[] = {60000, 60000, 170, 500000};
92
+float homing_feedrate[] = {1500,1500,120,0};
93
+bool axis_relative_modes[] = {false, false, false, false};
94
+
95
+//// Acceleration settings
96
+// X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
97
+float acceleration = 3000;         // Normal acceleration mm/s^2
98
+float retract_acceleration = 7000; // Normal acceleration mm/s^2
99
+float max_jerk = 20*60;
100
+long max_acceleration_units_per_sq_second[] = {7000,7000,20,10000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts
101
+// Not used long max_travel_acceleration_units_per_sq_second[] = {500,500,50,500}; // X, Y, Z max acceleration in mm/s^2 for travel moves
102
+
103
+
104
+// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
105
+// If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109
106
+//#define WATCHPERIOD 5000 //5 seconds
107
+
108
+//// The minimal temperature defines the temperature below which the heater will not be enabled
109
+#define MINTEMP 5
110
+
111
+
112
+// When temperature exceeds max temp, your heater will be switched off.
113
+// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
114
+// You should use MINTEMP for thermistor short/failure protection.
115
+#define MAXTEMP 275
116
+
117
+
118
+/// PID settings:
119
+// Uncomment the following line to enable PID support.
120
+//#define PIDTEMP
121
+#ifdef PIDTEMP
122
+//#define PID_DEBUG 1 // Sends debug data to the serial port. 
123
+//#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
124
+#define PID_MAX 156 // limits current to nozzle
125
+#define PID_INTEGRAL_DRIVE_MAX 156.0
126
+#define PID_dT 0.16
127
+double Kp = 20.0;
128
+double Ki = 1.5*PID_dT;
129
+double Kd = 80/PID_dT;
130
+#endif // PIDTEMP
131
+
132
+
133
+#endif

+ 418
- 0
Marlin/FatStructs.h View File

@@ -0,0 +1,418 @@
1
+/* Arduino SdFat Library
2
+ * Copyright (C) 2009 by William Greiman
3
+ *
4
+ * This file is part of the Arduino SdFat Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino SdFat Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#ifndef FatStructs_h
21
+#define FatStructs_h
22
+/**
23
+ * \file
24
+ * FAT file structures
25
+ */
26
+/*
27
+ * mostly from Microsoft document fatgen103.doc
28
+ * http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
29
+ */
30
+//------------------------------------------------------------------------------
31
+/** Value for byte 510 of boot block or MBR */
32
+uint8_t const BOOTSIG0 = 0X55;
33
+/** Value for byte 511 of boot block or MBR */
34
+uint8_t const BOOTSIG1 = 0XAA;
35
+//------------------------------------------------------------------------------
36
+/**
37
+ * \struct partitionTable
38
+ * \brief MBR partition table entry
39
+ *
40
+ * A partition table entry for a MBR formatted storage device.
41
+ * The MBR partition table has four entries.
42
+ */
43
+struct partitionTable {
44
+          /**
45
+           * Boot Indicator . Indicates whether the volume is the active
46
+           * partition.  Legal values include: 0X00. Do not use for booting.
47
+           * 0X80 Active partition.
48
+           */
49
+  uint8_t  boot;
50
+          /**
51
+            * Head part of Cylinder-head-sector address of the first block in
52
+            * the partition. Legal values are 0-255. Only used in old PC BIOS.
53
+            */
54
+  uint8_t  beginHead;
55
+          /**
56
+           * Sector part of Cylinder-head-sector address of the first block in
57
+           * the partition. Legal values are 1-63. Only used in old PC BIOS.
58
+           */
59
+  unsigned beginSector : 6;
60
+           /** High bits cylinder for first block in partition. */
61
+  unsigned beginCylinderHigh : 2;
62
+          /**
63
+           * Combine beginCylinderLow with beginCylinderHigh. Legal values
64
+           * are 0-1023.  Only used in old PC BIOS.
65
+           */
66
+  uint8_t  beginCylinderLow;
67
+          /**
68
+           * Partition type. See defines that begin with PART_TYPE_ for
69
+           * some Microsoft partition types.
70
+           */
71
+  uint8_t  type;
72
+          /**
73
+           * head part of cylinder-head-sector address of the last sector in the
74
+           * partition.  Legal values are 0-255. Only used in old PC BIOS.
75
+           */
76
+  uint8_t  endHead;
77
+          /**
78
+           * Sector part of cylinder-head-sector address of the last sector in
79
+           * the partition.  Legal values are 1-63. Only used in old PC BIOS.
80
+           */
81
+  unsigned endSector : 6;
82
+           /** High bits of end cylinder */
83
+  unsigned endCylinderHigh : 2;
84
+          /**
85
+           * Combine endCylinderLow with endCylinderHigh. Legal values
86
+           * are 0-1023.  Only used in old PC BIOS.
87
+           */
88
+  uint8_t  endCylinderLow;
89
+           /** Logical block address of the first block in the partition. */
90
+  uint32_t firstSector;
91
+           /** Length of the partition, in blocks. */
92
+  uint32_t totalSectors;
93
+};
94
+/** Type name for partitionTable */
95
+typedef struct partitionTable part_t;
96
+//------------------------------------------------------------------------------
97
+/**
98
+ * \struct masterBootRecord
99
+ *
100
+ * \brief Master Boot Record
101
+ *
102
+ * The first block of a storage device that is formatted with a MBR.
103
+ */
104
+struct masterBootRecord {
105
+           /** Code Area for master boot program. */
106
+  uint8_t  codeArea[440];
107
+           /** Optional WindowsNT disk signature. May contain more boot code. */
108
+  uint32_t diskSignature;
109
+           /** Usually zero but may be more boot code. */
110
+  uint16_t usuallyZero;
111
+           /** Partition tables. */
112
+  part_t   part[4];
113
+           /** First MBR signature byte. Must be 0X55 */
114
+  uint8_t  mbrSig0;
115
+           /** Second MBR signature byte. Must be 0XAA */
116
+  uint8_t  mbrSig1;
117
+};
118
+/** Type name for masterBootRecord */
119
+typedef struct masterBootRecord mbr_t;
120
+//------------------------------------------------------------------------------
121
+/** 
122
+ * \struct biosParmBlock
123
+ *
124
+ * \brief BIOS parameter block
125
+ * 
126
+ *  The BIOS parameter block describes the physical layout of a FAT volume.
127
+ */
128
+struct biosParmBlock {
129
+          /**
130
+           * Count of bytes per sector. This value may take on only the
131
+           * following values: 512, 1024, 2048 or 4096
132
+           */
133
+  uint16_t bytesPerSector;
134
+          /**
135
+           * Number of sectors per allocation unit. This value must be a
136
+           * power of 2 that is greater than 0. The legal values are
137
+           * 1, 2, 4, 8, 16, 32, 64, and 128.
138
+           */
139
+  uint8_t  sectorsPerCluster;
140
+          /**
141
+           * Number of sectors before the first FAT.
142
+           * This value must not be zero.
143
+           */
144
+  uint16_t reservedSectorCount;
145
+          /** The count of FAT data structures on the volume. This field should
146
+           *  always contain the value 2 for any FAT volume of any type.
147
+           */
148
+  uint8_t  fatCount;
149
+          /**
150
+          * For FAT12 and FAT16 volumes, this field contains the count of
151
+          * 32-byte directory entries in the root directory. For FAT32 volumes,
152
+          * this field must be set to 0. For FAT12 and FAT16 volumes, this
153
+          * value should always specify a count that when multiplied by 32
154
+          * results in a multiple of bytesPerSector.  FAT16 volumes should
155
+          * use the value 512.
156
+          */
157
+  uint16_t rootDirEntryCount;
158
+          /**
159
+           * This field is the old 16-bit total count of sectors on the volume.
160
+           * This count includes the count of all sectors in all four regions
161
+           * of the volume. This field can be 0; if it is 0, then totalSectors32
162
+           * must be non-zero.  For FAT32 volumes, this field must be 0. For
163
+           * FAT12 and FAT16 volumes, this field contains the sector count, and
164
+           * totalSectors32 is 0 if the total sector count fits
165
+           * (is less than 0x10000).
166
+           */
167
+  uint16_t totalSectors16;
168
+          /**
169
+           * This dates back to the old MS-DOS 1.x media determination and is
170
+           * no longer usually used for anything.  0xF8 is the standard value
171
+           * for fixed (non-removable) media. For removable media, 0xF0 is
172
+           * frequently used. Legal values are 0xF0 or 0xF8-0xFF.
173
+           */
174
+  uint8_t  mediaType;
175
+          /**
176
+           * Count of sectors occupied by one FAT on FAT12/FAT16 volumes.
177
+           * On FAT32 volumes this field must be 0, and sectorsPerFat32
178
+           * contains the FAT size count.
179
+           */
180
+  uint16_t sectorsPerFat16;
181
+           /** Sectors per track for interrupt 0x13. Not used otherwise. */
182
+  uint16_t sectorsPerTrtack;
183
+           /** Number of heads for interrupt 0x13.  Not used otherwise. */
184
+  uint16_t headCount;
185
+          /**
186
+           * Count of hidden sectors preceding the partition that contains this
187
+           * FAT volume. This field is generally only relevant for media
188
+           *  visible on interrupt 0x13.
189
+           */
190
+  uint32_t hidddenSectors;
191
+          /**
192
+           * This field is the new 32-bit total count of sectors on the volume.
193
+           * This count includes the count of all sectors in all four regions
194
+           * of the volume.  This field can be 0; if it is 0, then
195
+           * totalSectors16 must be non-zero.
196
+           */
197
+  uint32_t totalSectors32;
198
+          /**
199
+           * Count of sectors occupied by one FAT on FAT32 volumes.
200
+           */
201
+  uint32_t sectorsPerFat32;
202
+          /**
203
+           * This field is only defined for FAT32 media and does not exist on
204
+           * FAT12 and FAT16 media.
205
+           * Bits 0-3 -- Zero-based number of active FAT.
206
+           *             Only valid if mirroring is disabled.
207
+           * Bits 4-6 -- Reserved.
208
+           * Bit 7	-- 0 means the FAT is mirrored at runtime into all FATs.
209
+	         *        -- 1 means only one FAT is active; it is the one referenced in bits 0-3.
210
+           * Bits 8-15 	-- Reserved.
211
+           */
212
+  uint16_t fat32Flags;
213
+          /**
214
+           * FAT32 version. High byte is major revision number.
215
+           * Low byte is minor revision number. Only 0.0 define.
216
+           */
217
+  uint16_t fat32Version;
218
+          /**
219
+           * Cluster number of the first cluster of the root directory for FAT32.
220
+           * This usually 2 but not required to be 2.
221
+           */
222
+  uint32_t fat32RootCluster;
223
+          /**
224
+           * Sector number of FSINFO structure in the reserved area of the
225
+           * FAT32 volume. Usually 1.
226
+           */
227
+  uint16_t fat32FSInfo;
228
+          /**
229
+           * If non-zero, indicates the sector number in the reserved area
230
+           * of the volume of a copy of the boot record. Usually 6.
231
+           * No value other than 6 is recommended.
232
+           */
233
+  uint16_t fat32BackBootBlock;
234
+          /**
235
+           * Reserved for future expansion. Code that formats FAT32 volumes
236
+           * should always set all of the bytes of this field to 0.
237
+           */
238
+  uint8_t  fat32Reserved[12];
239
+};
240
+/** Type name for biosParmBlock */
241
+typedef struct biosParmBlock bpb_t;
242
+//------------------------------------------------------------------------------
243
+/**
244
+ * \struct fat32BootSector
245
+ *
246
+ * \brief Boot sector for a FAT16 or FAT32 volume.
247
+ * 
248
+ */  
249
+struct fat32BootSector {
250
+           /** X86 jmp to boot program */
251
+  uint8_t  jmpToBootCode[3];
252
+           /** informational only - don't depend on it */
253
+  char     oemName[8];
254
+           /** BIOS Parameter Block */
255
+  bpb_t    bpb;
256
+           /** for int0x13 use value 0X80 for hard drive */
257
+  uint8_t  driveNumber;
258
+           /** used by Windows NT - should be zero for FAT */
259
+  uint8_t  reserved1;
260
+           /** 0X29 if next three fields are valid */
261
+  uint8_t  bootSignature;
262
+           /** usually generated by combining date and time */
263
+  uint32_t volumeSerialNumber;
264
+           /** should match volume label in root dir */
265
+  char     volumeLabel[11];
266
+           /** informational only - don't depend on it */
267
+  char     fileSystemType[8];
268
+           /** X86 boot code */
269
+  uint8_t  bootCode[420];
270
+           /** must be 0X55 */
271
+  uint8_t  bootSectorSig0;
272
+           /** must be 0XAA */
273
+  uint8_t  bootSectorSig1;
274
+};
275
+//------------------------------------------------------------------------------
276
+// End Of Chain values for FAT entries
277
+/** FAT16 end of chain value used by Microsoft. */
278
+uint16_t const FAT16EOC = 0XFFFF;
279
+/** Minimum value for FAT16 EOC.  Use to test for EOC. */
280
+uint16_t const FAT16EOC_MIN = 0XFFF8;
281
+/** FAT32 end of chain value used by Microsoft. */
282
+uint32_t const FAT32EOC = 0X0FFFFFFF;
283
+/** Minimum value for FAT32 EOC.  Use to test for EOC. */
284
+uint32_t const FAT32EOC_MIN = 0X0FFFFFF8;
285
+/** Mask a for FAT32 entry. Entries are 28 bits. */
286
+uint32_t const FAT32MASK = 0X0FFFFFFF;
287
+
288
+/** Type name for fat32BootSector */
289
+typedef struct fat32BootSector fbs_t;
290
+//------------------------------------------------------------------------------
291
+/**
292
+ * \struct directoryEntry
293
+ * \brief FAT short directory entry
294
+ *
295
+ * Short means short 8.3 name, not the entry size.
296
+ *  
297
+ * Date Format. A FAT directory entry date stamp is a 16-bit field that is 
298
+ * basically a date relative to the MS-DOS epoch of 01/01/1980. Here is the
299
+ * format (bit 0 is the LSB of the 16-bit word, bit 15 is the MSB of the 
300
+ * 16-bit word):
301
+ *   
302
+ * Bits 9-15: Count of years from 1980, valid value range 0-127 
303
+ * inclusive (1980-2107).
304
+ *   
305
+ * Bits 5-8: Month of year, 1 = January, valid value range 1-12 inclusive.
306
+ *
307
+ * Bits 0-4: Day of month, valid value range 1-31 inclusive.
308
+ *
309
+ * Time Format. A FAT directory entry time stamp is a 16-bit field that has
310
+ * a granularity of 2 seconds. Here is the format (bit 0 is the LSB of the 
311
+ * 16-bit word, bit 15 is the MSB of the 16-bit word).
312
+ *   
313
+ * Bits 11-15: Hours, valid value range 0-23 inclusive.
314
+ * 
315
+ * Bits 5-10: Minutes, valid value range 0-59 inclusive.
316
+ *      
317
+ * Bits 0-4: 2-second count, valid value range 0-29 inclusive (0 - 58 seconds).
318
+ *   
319
+ * The valid time range is from Midnight 00:00:00 to 23:59:58.
320
+ */
321
+struct directoryEntry {
322
+           /**
323
+            * Short 8.3 name.
324
+            * The first eight bytes contain the file name with blank fill.
325
+            * The last three bytes contain the file extension with blank fill.
326
+            */
327
+  uint8_t  name[11];
328
+          /** Entry attributes.
329
+           *
330
+           * The upper two bits of the attribute byte are reserved and should
331
+           * always be set to 0 when a file is created and never modified or
332
+           * looked at after that.  See defines that begin with DIR_ATT_.
333
+           */
334
+  uint8_t  attributes;
335
+          /**
336
+           * Reserved for use by Windows NT. Set value to 0 when a file is
337
+           * created and never modify or look at it after that.
338
+           */
339
+  uint8_t  reservedNT;
340
+          /**
341
+           * The granularity of the seconds part of creationTime is 2 seconds
342
+           * so this field is a count of tenths of a second and its valid
343
+           * value range is 0-199 inclusive. (WHG note - seems to be hundredths)
344
+           */
345
+  uint8_t  creationTimeTenths;
346
+           /** Time file was created. */
347
+  uint16_t creationTime;
348
+           /** Date file was created. */
349
+  uint16_t creationDate;
350
+          /**
351
+           * Last access date. Note that there is no last access time, only
352
+           * a date.  This is the date of last read or write. In the case of
353
+           * a write, this should be set to the same date as lastWriteDate.
354
+           */
355
+  uint16_t lastAccessDate;
356
+          /**
357
+           * High word of this entry's first cluster number (always 0 for a
358
+           * FAT12 or FAT16 volume).
359
+           */
360
+  uint16_t firstClusterHigh;
361
+           /** Time of last write. File creation is considered a write. */
362
+  uint16_t lastWriteTime;
363
+           /** Date of last write. File creation is considered a write. */
364
+  uint16_t lastWriteDate;
365
+           /** Low word of this entry's first cluster number. */
366
+  uint16_t firstClusterLow;
367
+           /** 32-bit unsigned holding this file's size in bytes. */
368
+  uint32_t fileSize;
369
+};
370
+//------------------------------------------------------------------------------
371
+// Definitions for directory entries
372
+//
373
+/** Type name for directoryEntry */
374
+typedef struct directoryEntry dir_t;
375
+/** escape for name[0] = 0XE5 */
376
+uint8_t const DIR_NAME_0XE5 = 0X05;
377
+/** name[0] value for entry that is free after being "deleted" */
378
+uint8_t const DIR_NAME_DELETED = 0XE5;
379
+/** name[0] value for entry that is free and no allocated entries follow */
380
+uint8_t const DIR_NAME_FREE = 0X00;
381
+/** file is read-only */
382
+uint8_t const DIR_ATT_READ_ONLY = 0X01;
383
+/** File should hidden in directory listings */
384
+uint8_t const DIR_ATT_HIDDEN = 0X02;
385
+/** Entry is for a system file */
386
+uint8_t const DIR_ATT_SYSTEM = 0X04;
387
+/** Directory entry contains the volume label */
388
+uint8_t const DIR_ATT_VOLUME_ID = 0X08;
389
+/** Entry is for a directory */
390
+uint8_t const DIR_ATT_DIRECTORY = 0X10;
391
+/** Old DOS archive bit for backup support */
392
+uint8_t const DIR_ATT_ARCHIVE = 0X20;
393
+/** Test value for long name entry.  Test is
394
+  (d->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME. */
395
+uint8_t const DIR_ATT_LONG_NAME = 0X0F;
396
+/** Test mask for long name entry */
397
+uint8_t const DIR_ATT_LONG_NAME_MASK = 0X3F;
398
+/** defined attribute bits */
399
+uint8_t const DIR_ATT_DEFINED_BITS = 0X3F;
400
+/** Directory entry is part of a long name */
401
+static inline uint8_t DIR_IS_LONG_NAME(const dir_t* dir) {
402
+  return (dir->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME;
403
+}
404
+/** Mask for file/subdirectory tests */
405
+uint8_t const DIR_ATT_FILE_TYPE_MASK = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY);
406
+/** Directory entry is for a file */
407
+static inline uint8_t DIR_IS_FILE(const dir_t* dir) {
408
+  return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == 0;
409
+}
410
+/** Directory entry is for a subdirectory */
411
+static inline uint8_t DIR_IS_SUBDIR(const dir_t* dir) {
412
+  return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == DIR_ATT_DIRECTORY;
413
+}
414
+/** Directory entry is for a file or subdirectory */
415
+static inline uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t* dir) {
416
+  return (dir->attributes & DIR_ATT_VOLUME_ID) == 0;
417
+}
418
+#endif  // FatStructs_h

+ 247
- 0
Marlin/Makefile View File

@@ -0,0 +1,247 @@
1
+# Marlin Arduino Project Makefile
2
+# 
3
+# Makefile Based on:
4
+# Arduino 0011 Makefile
5
+# Arduino adaptation by mellis, eighthave, oli.keller
6
+#
7
+# This has been tested with Arduino 0022.
8
+# 
9
+# This makefile allows you to build sketches from the command line
10
+# without the Arduino environment (or Java).
11
+#
12
+# Detailed instructions for using the makefile:
13
+#
14
+#  1. Modify the line containg "INSTALL_DIR" to point to the directory that
15
+#     contains the Arduino installation (for example, under Mac OS X, this
16
+#     might be /Applications/arduino-0012).
17
+#
18
+#  2. Modify the line containing "PORT" to refer to the filename
19
+#     representing the USB or serial connection to your Arduino board
20
+#     (e.g. PORT = /dev/tty.USB0).  If the exact name of this file
21
+#     changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*).
22
+#
23
+#  3. Set the line containing "MCU" to match your board's processor. 
24
+#     Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth
25
+#     or Diecimila have the atmega168.  If you're using a LilyPad Arduino,
26
+#     change F_CPU to 8000000.
27
+#
28
+#  4. Type "make" and press enter to compile/verify your program.
29
+#
30
+#  5. Type "make upload", reset your Arduino board, and press enter to
31
+#     upload your program to the Arduino board.
32
+#
33
+# $Id$
34
+
35
+TARGET = Marlin
36
+INSTALL_DIR = ../../Desktop/arduino-0018/
37
+UPLOAD_RATE = 38400
38
+AVRDUDE_PROGRAMMER = stk500v1
39
+PORT = /dev/ttyUSB0
40
+#MCU = atmega2560
41
+#For "old" Arduino Mega
42
+#MCU = atmega1280
43
+#For Sanguinololu
44
+MCU = atmega644p 
45
+F_CPU = 16000000
46
+
47
+
48
+############################################################################
49
+# Below here nothing should be changed...
50
+
51
+ARDUINO = $(INSTALL_DIR)/hardware/Sanguino/cores/arduino
52
+AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin
53
+SRC =  $(ARDUINO)/pins_arduino.c wiring.c wiring_serial.c \
54
+$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
55
+$(ARDUINO)/wiring_pulse.c \
56
+$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
57
+CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \
58
+$(ARDUINO)/Print.cpp ./SdFile.cpp ./SdVolume.cpp ./Sd2Card.cpp
59
+FORMAT = ihex
60
+
61
+
62
+# Name of this Makefile (used for "make depend").
63
+MAKEFILE = Makefile
64
+
65
+# Debugging format.
66
+# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
67
+# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
68
+DEBUG = stabs
69
+
70
+OPT = s
71
+
72
+# Place -D or -U options here
73
+CDEFS = -DF_CPU=$(F_CPU)
74
+CXXDEFS = -DF_CPU=$(F_CPU)
75
+
76
+# Place -I options here
77
+CINCS = -I$(ARDUINO)
78
+CXXINCS = -I$(ARDUINO)
79
+
80
+# Compiler flag to set the C Standard level.
81
+# c89   - "ANSI" C
82
+# gnu89 - c89 plus GCC extensions
83
+# c99   - ISO C99 standard (not yet fully implemented)
84
+# gnu99 - c99 plus GCC extensions
85
+#CSTANDARD = -std=gnu99
86
+CDEBUG = -g$(DEBUG)
87
+CWARN = -Wall -Wunused-variable
88
+CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -w -ffunction-sections -fdata-sections -DARDUINO=22
89
+#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
90
+
91
+CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
92
+CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) -Wall $(CEXTRA) $(CTUNING)
93
+#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
94
+LDFLAGS = -lm
95
+
96
+
97
+# Programming support using avrdude. Settings and variables.
98
+AVRDUDE_PORT = $(PORT)
99
+AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i
100
+AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
101
+-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
102
+-b $(UPLOAD_RATE)
103
+
104
+# Program settings
105
+CC = $(AVR_TOOLS_PATH)/avr-gcc
106
+CXX = $(AVR_TOOLS_PATH)/avr-g++
107
+OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
108
+OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
109
+AR  = $(AVR_TOOLS_PATH)/avr-ar
110
+SIZE = $(AVR_TOOLS_PATH)/avr-size
111
+NM = $(AVR_TOOLS_PATH)/avr-nm
112
+AVRDUDE = $(INSTALL_DIR)/hardware/tools/avrdude
113
+REMOVE = rm -f
114
+MV = mv -f
115
+
116
+# Define all object files.
117
+OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) 
118
+
119
+# Define all listing files.
120
+LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
121
+
122
+# Combine all necessary flags and optional flags.
123
+# Add target processor to flags.
124
+ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
125
+ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
126
+ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
127
+
128
+
129
+# Default target.
130
+all: applet_files_ez build sizeafter
131
+
132
+build: elf hex 
133
+
134
+applet_files_ez: $(TARGET).pde
135
+	# Here is the "preprocessing".
136
+	# It creates a .cpp file based with the same name as the .pde file.
137
+	# On top of the new .cpp file comes the WProgram.h header.
138
+	# At the end there is a generic main() function attached.
139
+	# Then the .cpp file will be compiled. Errors during compile will
140
+	# refer to this new, automatically generated, file. 
141
+	# Not the original .pde file you actually edit...
142
+	test -d applet || mkdir applet
143
+	echo '#include "WProgram.h"' > applet/$(TARGET).cpp
144
+	cat $(TARGET).pde >> applet/$(TARGET).cpp
145
+	cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp
146
+
147
+elf: applet/$(TARGET).elf
148
+hex: applet/$(TARGET).hex
149
+eep: applet/$(TARGET).eep
150
+lss: applet/$(TARGET).lss 
151
+sym: applet/$(TARGET).sym
152
+
153
+# Program the device.  
154
+upload: applet/$(TARGET).hex
155
+	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
156
+
157
+
158
+	# Display size of file.
159
+HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
160
+ELFSIZE = $(SIZE)  applet/$(TARGET).elf
161
+sizebefore:
162
+	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
163
+
164
+sizeafter:
165
+	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
166
+
167
+
168
+# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
169
+COFFCONVERT=$(OBJCOPY) --debugging \
170
+--change-section-address .data-0x800000 \
171
+--change-section-address .bss-0x800000 \
172
+--change-section-address .noinit-0x800000 \
173
+--change-section-address .eeprom-0x810000 
174
+
175
+
176
+coff: applet/$(TARGET).elf
177
+	$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
178
+
179
+
180
+extcoff: $(TARGET).elf
181
+	$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
182
+
183
+
184
+.SUFFIXES: .elf .hex .eep .lss .sym
185
+
186
+.elf.hex:
187
+	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
188
+
189
+.elf.eep:
190
+	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
191
+	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
192
+
193
+# Create extended listing file from ELF output file.
194
+.elf.lss:
195
+	$(OBJDUMP) -h -S $< > $@
196
+
197
+# Create a symbol table from ELF output file.
198
+.elf.sym:
199
+	$(NM) -n $< > $@
200
+
201
+	# Link: create ELF output file from library.
202
+applet/$(TARGET).elf: $(TARGET).pde applet/core.a 
203
+	$(CC) $(ALL_CFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
204
+
205
+applet/core.a: $(OBJ)
206
+	@for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
207
+
208
+
209
+
210
+# Compile: create object files from C++ source files.
211
+.cpp.o:
212
+	$(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 
213
+
214
+# Compile: create object files from C source files.
215
+.c.o:
216
+	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
217
+
218
+
219
+# Compile: create assembler files from C source files.
220
+.c.s:
221
+	$(CC) -S $(ALL_CFLAGS) $< -o $@
222
+
223
+
224
+# Assemble: create object files from assembler source files.
225
+.S.o:
226
+	$(CC) -c $(ALL_ASFLAGS) $< -o $@
227
+
228
+
229
+
230
+# Target: clean project.
231
+clean:
232
+	$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
233
+	applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \
234
+	$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
235
+
236
+depend:
237
+	if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
238
+	then \
239
+		sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
240
+			$(MAKEFILE).$$$$ && \
241
+		$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
242
+	fi
243
+	echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
244
+		>> $(MAKEFILE); \
245
+	$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
246
+
247
+.PHONY:	all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter

+ 107
- 0
Marlin/Marlin.h View File

@@ -0,0 +1,107 @@
1
+// Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
2
+// Licence: GPL
3
+#include <WProgram.h>
4
+#include "fastio.h"
5
+extern "C" void __cxa_pure_virtual();
6
+void __cxa_pure_virtual(){};
7
+void get_command();
8
+void process_commands();
9
+
10
+void manage_inactivity(byte debug);
11
+
12
+void manage_heater();
13
+int temp2analogu(int celsius, const short table[][2], int numtemps);
14
+float analog2tempu(int raw, const short table[][2], int numtemps);
15
+#ifdef HEATER_USES_THERMISTOR
16
+    #define HEATERSOURCE 1
17
+#endif
18
+#ifdef BED_USES_THERMISTOR
19
+    #define BEDSOURCE 1
20
+#endif
21
+
22
+#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS)
23
+#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS)
24
+
25
+#if X_ENABLE_PIN > -1
26
+#define  enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
27
+#define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)
28
+#else
29
+#define enable_x() ;
30
+#define disable_x() ;
31
+#endif
32
+#if Y_ENABLE_PIN > -1
33
+#define  enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
34
+#define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON)
35
+#else
36
+#define enable_y() ;
37
+#define disable_y() ;
38
+#endif
39
+#if Z_ENABLE_PIN > -1
40
+#define  enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
41
+#define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON)
42
+#else
43
+#define enable_z() ;
44
+#define disable_z() ;
45
+#endif
46
+#if E_ENABLE_PIN > -1
47
+#define  enable_e() WRITE(E_ENABLE_PIN, E_ENABLE_ON)
48
+#define disable_e() WRITE(E_ENABLE_PIN,!E_ENABLE_ON)
49
+#else
50
+#define enable_e() ;
51
+#define disable_e() ;
52
+#endif
53
+
54
+#define X_AXIS 0
55
+#define Y_AXIS 1
56
+#define Z_AXIS 2
57
+#define E_AXIS 3
58
+
59
+void FlushSerialRequestResend();
60
+void ClearToSend();
61
+
62
+void get_coordinates();
63
+void prepare_move();
64
+void linear_move(unsigned long steps_remaining[]);
65
+void do_step(int axis);
66
+void kill(byte debug);
67
+
68
+// This struct is used when buffering the setup for each linear movement "nominal" values are as specified in 
69
+// the source g-code and may never actually be reached if acceleration management is active.
70
+typedef struct {
71
+  // Fields used by the bresenham algorithm for tracing the line
72
+  long steps_x, steps_y, steps_z, steps_e;  // Step count along each axis
73
+  long step_event_count;                    // The number of step events required to complete this block
74
+  volatile long accelerate_until;                    // The index of the step event on which to stop acceleration
75
+  volatile long decelerate_after;                    // The index of the step event on which to start decelerating
76
+  volatile long acceleration_rate;                   // The acceleration rate used for acceleration calculation
77
+  unsigned char direction_bits;             // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
78
+
79
+  long advance_rate;
80
+  volatile long initial_advance;
81
+  volatile long final_advance;
82
+  float advance;
83
+
84
+  // Fields used by the motion planner to manage acceleration
85
+  float speed_x, speed_y, speed_z, speed_e;          // Nominal mm/minute for each axis
86
+  float nominal_speed;                               // The nominal speed for this block in mm/min  
87
+  float millimeters;                                 // The total travel of this block in mm
88
+  float entry_speed;
89
+
90
+  // Settings for the trapezoid generator
91
+  long nominal_rate;                                 // The nominal step rate for this block in step_events/sec 
92
+  volatile long initial_rate;                                 // The jerk-adjusted step rate at start of block  
93
+  volatile long final_rate;                                   // The minimal rate at exit
94
+  long acceleration;                                 // acceleration mm/sec^2
95
+  volatile char busy;
96
+} block_t;
97
+
98
+void check_axes_activity();
99
+void plan_init();
100
+void st_init();
101
+void tp_init();
102
+void plan_buffer_line(float x, float y, float z, float e, float feed_rate);
103
+void plan_set_position(float x, float y, float z, float e);
104
+void st_wake_up();
105
+void st_synchronize();
106
+
107
+

+ 2038
- 0
Marlin/Marlin.pde
File diff suppressed because it is too large
View File


+ 643
- 0
Marlin/Sd2Card.cpp View File

@@ -0,0 +1,643 @@
1
+/* Arduino Sd2Card Library
2
+ * Copyright (C) 2009 by William Greiman
3
+ *
4
+ * This file is part of the Arduino Sd2Card Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino Sd2Card Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#include <WProgram.h>
21
+#include "Sd2Card.h"
22
+//------------------------------------------------------------------------------
23
+#ifndef SOFTWARE_SPI
24
+// functions for hardware SPI
25
+/** Send a byte to the card */
26
+static void spiSend(uint8_t b) {
27
+  SPDR = b;
28
+  while (!(SPSR & (1 << SPIF)));
29
+}
30
+/** Receive a byte from the card */
31
+static  uint8_t spiRec(void) {
32
+  spiSend(0XFF);
33
+  return SPDR;
34
+}
35
+#else  // SOFTWARE_SPI
36
+//------------------------------------------------------------------------------
37
+/** nop to tune soft SPI timing */
38
+#define nop asm volatile ("nop\n\t")
39
+//------------------------------------------------------------------------------
40
+/** Soft SPI receive */
41
+uint8_t spiRec(void) {
42
+  uint8_t data = 0;
43
+  // no interrupts during byte receive - about 8 us
44
+  cli();
45
+  // output pin high - like sending 0XFF
46
+  fastDigitalWrite(SPI_MOSI_PIN, HIGH);
47
+
48
+  for (uint8_t i = 0; i < 8; i++) {
49
+    fastDigitalWrite(SPI_SCK_PIN, HIGH);
50
+
51
+    // adjust so SCK is nice
52
+    nop;
53
+    nop;
54
+
55
+    data <<= 1;
56
+
57
+    if (fastDigitalRead(SPI_MISO_PIN)) data |= 1;
58
+
59
+    fastDigitalWrite(SPI_SCK_PIN, LOW);
60
+  }
61
+  // enable interrupts
62
+  sei();
63
+  return data;
64
+}
65
+//------------------------------------------------------------------------------
66
+/** Soft SPI send */
67
+void spiSend(uint8_t data) {
68
+  // no interrupts during byte send - about 8 us
69
+  cli();
70
+  for (uint8_t i = 0; i < 8; i++) {
71
+    fastDigitalWrite(SPI_SCK_PIN, LOW);
72
+
73
+    fastDigitalWrite(SPI_MOSI_PIN, data & 0X80);
74
+
75
+    data <<= 1;
76
+
77
+    fastDigitalWrite(SPI_SCK_PIN, HIGH);
78
+  }
79
+  // hold SCK high for a few ns
80
+  nop;
81
+  nop;
82
+  nop;
83
+  nop;
84
+
85
+  fastDigitalWrite(SPI_SCK_PIN, LOW);
86
+  // enable interrupts
87
+  sei();
88
+}
89
+#endif  // SOFTWARE_SPI
90
+//------------------------------------------------------------------------------
91
+// send command and return error code.  Return zero for OK
92
+uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
93
+  // end read if in partialBlockRead mode
94
+  readEnd();
95
+
96
+  // select card
97
+  chipSelectLow();
98
+
99
+  // wait up to 300 ms if busy
100
+  waitNotBusy(300);
101
+
102
+  // send command
103
+  spiSend(cmd | 0x40);
104
+
105
+  // send argument
106
+  for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);
107
+
108
+  // send CRC
109
+  uint8_t crc = 0XFF;
110
+  if (cmd == CMD0) crc = 0X95;  // correct crc for CMD0 with arg 0
111
+  if (cmd == CMD8) crc = 0X87;  // correct crc for CMD8 with arg 0X1AA
112
+  spiSend(crc);
113
+
114
+  // wait for response
115
+  for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++);
116
+  return status_;
117
+}
118
+//------------------------------------------------------------------------------
119
+/**
120
+ * Determine the size of an SD flash memory card.
121
+ *
122
+ * \return The number of 512 byte data blocks in the card
123
+ *         or zero if an error occurs.
124
+ */
125
+uint32_t Sd2Card::cardSize(void) {
126
+  csd_t csd;
127
+  if (!readCSD(&csd)) return 0;
128
+  if (csd.v1.csd_ver == 0) {
129
+    uint8_t read_bl_len = csd.v1.read_bl_len;
130
+    uint16_t c_size = (csd.v1.c_size_high << 10)
131
+                      | (csd.v1.c_size_mid << 2) | csd.v1.c_size_low;
132
+    uint8_t c_size_mult = (csd.v1.c_size_mult_high << 1)
133
+                          | csd.v1.c_size_mult_low;
134
+    return (uint32_t)(c_size + 1) << (c_size_mult + read_bl_len - 7);
135
+  } else if (csd.v2.csd_ver == 1) {
136
+    uint32_t c_size = ((uint32_t)csd.v2.c_size_high << 16)
137
+                      | (csd.v2.c_size_mid << 8) | csd.v2.c_size_low;
138
+    return (c_size + 1) << 10;
139
+  } else {
140
+    error(SD_CARD_ERROR_BAD_CSD);
141
+    return 0;
142
+  }
143
+}
144
+//------------------------------------------------------------------------------
145
+void Sd2Card::chipSelectHigh(void) {
146
+  digitalWrite(chipSelectPin_, HIGH);
147
+}
148
+//------------------------------------------------------------------------------
149
+void Sd2Card::chipSelectLow(void) {
150
+  digitalWrite(chipSelectPin_, LOW);
151
+}
152
+//------------------------------------------------------------------------------
153
+/** Erase a range of blocks.
154
+ *
155
+ * \param[in] firstBlock The address of the first block in the range.
156
+ * \param[in] lastBlock The address of the last block in the range.
157
+ *
158
+ * \note This function requests the SD card to do a flash erase for a
159
+ * range of blocks.  The data on the card after an erase operation is
160
+ * either 0 or 1, depends on the card vendor.  The card must support
161
+ * single block erase.
162
+ *
163
+ * \return The value one, true, is returned for success and
164
+ * the value zero, false, is returned for failure.
165
+ */
166
+uint8_t Sd2Card::erase(uint32_t firstBlock, uint32_t lastBlock) {
167
+  if (!eraseSingleBlockEnable()) {
168
+    error(SD_CARD_ERROR_ERASE_SINGLE_BLOCK);
169
+    goto fail;
170
+  }
171
+  if (type_ != SD_CARD_TYPE_SDHC) {
172
+    firstBlock <<= 9;
173
+    lastBlock <<= 9;
174
+  }
175
+  if (cardCommand(CMD32, firstBlock)
176
+    || cardCommand(CMD33, lastBlock)
177
+    || cardCommand(CMD38, 0)) {
178
+      error(SD_CARD_ERROR_ERASE);
179
+      goto fail;
180
+  }
181
+  if (!waitNotBusy(SD_ERASE_TIMEOUT)) {
182
+    error(SD_CARD_ERROR_ERASE_TIMEOUT);
183
+    goto fail;
184
+  }
185
+  chipSelectHigh();
186
+  return true;
187
+
188
+ fail:
189
+  chipSelectHigh();
190
+  return false;
191
+}
192
+//------------------------------------------------------------------------------
193
+/** Determine if card supports single block erase.
194
+ *
195
+ * \return The value one, true, is returned if single block erase is supported.
196
+ * The value zero, false, is returned if single block erase is not supported.
197
+ */
198
+uint8_t Sd2Card::eraseSingleBlockEnable(void) {
199
+  csd_t csd;
200
+  return readCSD(&csd) ? csd.v1.erase_blk_en : 0;
201
+}
202
+//------------------------------------------------------------------------------
203
+/**
204
+ * Initialize an SD flash memory card.
205
+ *
206
+ * \param[in] sckRateID SPI clock rate selector. See setSckRate().
207
+ * \param[in] chipSelectPin SD chip select pin number.
208
+ *
209
+ * \return The value one, true, is returned for success and
210
+ * the value zero, false, is returned for failure.  The reason for failure
211
+ * can be determined by calling errorCode() and errorData().
212
+ */
213
+uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
214
+  errorCode_ = inBlock_ = partialBlockRead_ = type_ = 0;
215
+  chipSelectPin_ = chipSelectPin;
216
+  // 16-bit init start time allows over a minute
217
+  uint16_t t0 = (uint16_t)millis();
218
+  uint32_t arg;
219
+
220
+  // set pin modes
221
+  pinMode(chipSelectPin_, OUTPUT);
222
+  chipSelectHigh();
223
+  pinMode(SPI_MISO_PIN, INPUT);
224
+  pinMode(SPI_MOSI_PIN, OUTPUT);
225
+  pinMode(SPI_SCK_PIN, OUTPUT);
226
+
227
+#ifndef SOFTWARE_SPI
228
+  // SS must be in output mode even it is not chip select
229
+  pinMode(SS_PIN, OUTPUT);
230
+  // Enable SPI, Master, clock rate f_osc/128
231
+  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1) | (1 << SPR0);
232
+  // clear double speed
233
+  SPSR &= ~(1 << SPI2X);
234
+#endif  // SOFTWARE_SPI
235
+
236
+  // must supply min of 74 clock cycles with CS high.
237
+  for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);
238
+
239
+  chipSelectLow();
240
+
241
+  // command to go idle in SPI mode
242
+  while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
243
+    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
244
+      error(SD_CARD_ERROR_CMD0);
245
+      goto fail;
246
+    }
247
+  }
248
+  // check SD version
249
+  if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) {
250
+    type(SD_CARD_TYPE_SD1);
251
+  } else {
252
+    // only need last byte of r7 response
253
+    for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
254
+    if (status_ != 0XAA) {
255
+      error(SD_CARD_ERROR_CMD8);
256
+      goto fail;
257
+    }
258
+    type(SD_CARD_TYPE_SD2);
259
+  }
260
+  // initialize card and send host supports SDHC if SD2
261
+  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;
262
+
263
+  while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {
264
+    // check for timeout
265
+    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
266
+      error(SD_CARD_ERROR_ACMD41);
267
+      goto fail;
268
+    }
269
+  }
270
+  // if SD2 read OCR register to check for SDHC card
271
+  if (type() == SD_CARD_TYPE_SD2) {
272
+    if (cardCommand(CMD58, 0)) {
273
+      error(SD_CARD_ERROR_CMD58);
274
+      goto fail;
275
+    }
276
+    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);
277
+    // discard rest of ocr - contains allowed voltage range
278
+    for (uint8_t i = 0; i < 3; i++) spiRec();
279
+  }
280
+  chipSelectHigh();
281
+
282
+#ifndef SOFTWARE_SPI
283
+  return setSckRate(sckRateID);
284
+#else  // SOFTWARE_SPI
285
+  return true;
286
+#endif  // SOFTWARE_SPI
287
+
288
+ fail:
289
+  chipSelectHigh();
290
+  return false;
291
+}
292
+//------------------------------------------------------------------------------
293
+/**
294
+ * Enable or disable partial block reads.
295
+ *
296
+ * Enabling partial block reads improves performance by allowing a block
297
+ * to be read over the SPI bus as several sub-blocks.  Errors may occur
298
+ * if the time between reads is too long since the SD card may timeout.
299
+ * The SPI SS line will be held low until the entire block is read or
300
+ * readEnd() is called.
301
+ *
302
+ * Use this for applications like the Adafruit Wave Shield.
303
+ *
304
+ * \param[in] value The value TRUE (non-zero) or FALSE (zero).)
305
+ */
306
+void Sd2Card::partialBlockRead(uint8_t value) {
307
+  readEnd();
308
+  partialBlockRead_ = value;
309
+}
310
+//------------------------------------------------------------------------------
311
+/**
312
+ * Read a 512 byte block from an SD card device.
313
+ *
314
+ * \param[in] block Logical block to be read.
315
+ * \param[out] dst Pointer to the location that will receive the data.
316
+
317
+ * \return The value one, true, is returned for success and
318
+ * the value zero, false, is returned for failure.
319
+ */
320
+uint8_t Sd2Card::readBlock(uint32_t block, uint8_t* dst) {
321
+  return readData(block, 0, 512, dst);
322
+}
323
+//------------------------------------------------------------------------------
324
+/**
325
+ * Read part of a 512 byte block from an SD card.
326
+ *
327
+ * \param[in] block Logical block to be read.
328
+ * \param[in] offset Number of bytes to skip at start of block
329
+ * \param[out] dst Pointer to the location that will receive the data.
330
+ * \param[in] count Number of bytes to read
331
+ * \return The value one, true, is returned for success and
332
+ * the value zero, false, is returned for failure.
333
+ */
334
+uint8_t Sd2Card::readData(uint32_t block,
335
+        uint16_t offset, uint16_t count, uint8_t* dst) {
336
+  uint16_t n;
337
+  if (count == 0) return true;
338
+  if ((count + offset) > 512) {
339
+    goto fail;
340
+  }
341
+  if (!inBlock_ || block != block_ || offset < offset_) {
342
+    block_ = block;
343
+    // use address if not SDHC card
344
+    if (type()!= SD_CARD_TYPE_SDHC) block <<= 9;
345
+    if (cardCommand(CMD17, block)) {
346
+      error(SD_CARD_ERROR_CMD17);
347
+      goto fail;
348
+    }
349
+    if (!waitStartBlock()) {
350
+      goto fail;
351
+    }
352
+    offset_ = 0;
353
+    inBlock_ = 1;
354
+  }
355
+
356
+#ifdef OPTIMIZE_HARDWARE_SPI
357
+  // start first spi transfer
358
+  SPDR = 0XFF;
359
+
360
+  // skip data before offset
361
+  for (;offset_ < offset; offset_++) {
362
+    while (!(SPSR & (1 << SPIF)));
363
+    SPDR = 0XFF;
364
+  }
365
+  // transfer data
366
+  n = count - 1;
367
+  for (uint16_t i = 0; i < n; i++) {
368
+    while (!(SPSR & (1 << SPIF)));
369
+    dst[i] = SPDR;
370
+    SPDR = 0XFF;
371
+  }
372
+  // wait for last byte
373
+  while (!(SPSR & (1 << SPIF)));
374
+  dst[n] = SPDR;
375
+
376
+#else  // OPTIMIZE_HARDWARE_SPI
377
+
378
+  // skip data before offset
379
+  for (;offset_ < offset; offset_++) {
380
+    spiRec();
381
+  }
382
+  // transfer data
383
+  for (uint16_t i = 0; i < count; i++) {
384
+    dst[i] = spiRec();
385
+  }
386
+#endif  // OPTIMIZE_HARDWARE_SPI
387
+
388
+  offset_ += count;
389
+  if (!partialBlockRead_ || offset_ >= 512) {
390
+    // read rest of data, checksum and set chip select high
391
+    readEnd();
392
+  }
393
+  return true;
394
+
395
+ fail:
396
+  chipSelectHigh();
397
+  return false;
398
+}
399
+//------------------------------------------------------------------------------
400
+/** Skip remaining data in a block when in partial block read mode. */
401
+void Sd2Card::readEnd(void) {
402
+  if (inBlock_) {
403
+      // skip data and crc
404
+#ifdef OPTIMIZE_HARDWARE_SPI
405
+    // optimize skip for hardware
406
+    SPDR = 0XFF;
407
+    while (offset_++ < 513) {
408
+      while (!(SPSR & (1 << SPIF)));
409
+      SPDR = 0XFF;
410
+    }
411
+    // wait for last crc byte
412
+    while (!(SPSR & (1 << SPIF)));
413
+#else  // OPTIMIZE_HARDWARE_SPI
414
+    while (offset_++ < 514) spiRec();
415
+#endif  // OPTIMIZE_HARDWARE_SPI
416
+    chipSelectHigh();
417
+    inBlock_ = 0;
418
+  }
419
+}
420
+//------------------------------------------------------------------------------
421
+/** read CID or CSR register */
422
+uint8_t Sd2Card::readRegister(uint8_t cmd, void* buf) {
423
+  uint8_t* dst = reinterpret_cast<uint8_t*>(buf);
424
+  if (cardCommand(cmd, 0)) {
425
+    error(SD_CARD_ERROR_READ_REG);
426
+    goto fail;
427
+  }
428
+  if (!waitStartBlock()) goto fail;
429
+  // transfer data
430
+  for (uint16_t i = 0; i < 16; i++) dst[i] = spiRec();
431
+  spiRec();  // get first crc byte
432
+  spiRec();  // get second crc byte
433
+  chipSelectHigh();
434
+  return true;
435
+
436
+ fail:
437
+  chipSelectHigh();
438
+  return false;
439
+}
440
+//------------------------------------------------------------------------------
441
+/**
442
+ * Set the SPI clock rate.
443
+ *
444
+ * \param[in] sckRateID A value in the range [0, 6].
445
+ *
446
+ * The SPI clock will be set to F_CPU/pow(2, 1 + sckRateID). The maximum
447
+ * SPI rate is F_CPU/2 for \a sckRateID = 0 and the minimum rate is F_CPU/128
448
+ * for \a scsRateID = 6.
449
+ *
450
+ * \return The value one, true, is returned for success and the value zero,
451
+ * false, is returned for an invalid value of \a sckRateID.
452
+ */
453
+uint8_t Sd2Card::setSckRate(uint8_t sckRateID) {
454
+  if (sckRateID > 6) {
455
+    error(SD_CARD_ERROR_SCK_RATE);
456
+    return false;
457
+  }
458
+  // see avr processor datasheet for SPI register bit definitions
459
+  if ((sckRateID & 1) || sckRateID == 6) {
460
+    SPSR &= ~(1 << SPI2X);
461
+  } else {
462
+    SPSR |= (1 << SPI2X);
463
+  }
464
+  SPCR &= ~((1 <<SPR1) | (1 << SPR0));
465
+  SPCR |= (sckRateID & 4 ? (1 << SPR1) : 0)
466
+    | (sckRateID & 2 ? (1 << SPR0) : 0);
467
+  return true;
468
+}
469
+//------------------------------------------------------------------------------
470
+// wait for card to go not busy
471
+uint8_t Sd2Card::waitNotBusy(uint16_t timeoutMillis) {
472
+  uint16_t t0 = millis();
473
+  do {
474
+    if (spiRec() == 0XFF) return true;
475
+  }
476
+  while (((uint16_t)millis() - t0) < timeoutMillis);
477
+  return false;
478
+}
479
+//------------------------------------------------------------------------------
480
+/** Wait for start block token */
481
+uint8_t Sd2Card::waitStartBlock(void) {
482
+  uint16_t t0 = millis();
483
+  while ((status_ = spiRec()) == 0XFF) {
484
+    if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) {
485
+      error(SD_CARD_ERROR_READ_TIMEOUT);
486
+      goto fail;
487
+    }
488
+  }
489
+  if (status_ != DATA_START_BLOCK) {
490
+    error(SD_CARD_ERROR_READ);
491
+    goto fail;
492
+  }
493
+  return true;
494
+
495
+ fail:
496
+  chipSelectHigh();
497
+  return false;
498
+}
499
+//------------------------------------------------------------------------------
500
+/**
501
+ * Writes a 512 byte block to an SD card.
502
+ *
503
+ * \param[in] blockNumber Logical block to be written.
504
+ * \param[in] src Pointer to the location of the data to be written.
505
+ * \return The value one, true, is returned for success and
506
+ * the value zero, false, is returned for failure.
507
+ */
508
+uint8_t Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
509
+#if SD_PROTECT_BLOCK_ZERO
510
+  // don't allow write to first block
511
+  if (blockNumber == 0) {
512
+    error(SD_CARD_ERROR_WRITE_BLOCK_ZERO);
513
+    goto fail;
514
+  }
515
+#endif  // SD_PROTECT_BLOCK_ZERO
516
+
517
+  // use address if not SDHC card
518
+  if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;
519
+  if (cardCommand(CMD24, blockNumber)) {
520
+    error(SD_CARD_ERROR_CMD24);
521
+    goto fail;
522
+  }
523
+  if (!writeData(DATA_START_BLOCK, src)) goto fail;
524
+
525
+  // wait for flash programming to complete
526
+  if (!waitNotBusy(SD_WRITE_TIMEOUT)) {
527
+    error(SD_CARD_ERROR_WRITE_TIMEOUT);
528
+    goto fail;
529
+  }
530
+  // response is r2 so get and check two bytes for nonzero
531
+  if (cardCommand(CMD13, 0) || spiRec()) {
532
+    error(SD_CARD_ERROR_WRITE_PROGRAMMING);
533
+    goto fail;
534
+  }
535
+  chipSelectHigh();
536
+  return true;
537
+
538
+ fail:
539
+  chipSelectHigh();
540
+  return false;
541
+}
542
+//------------------------------------------------------------------------------
543
+/** Write one data block in a multiple block write sequence */
544
+uint8_t Sd2Card::writeData(const uint8_t* src) {
545
+  // wait for previous write to finish
546
+  if (!waitNotBusy(SD_WRITE_TIMEOUT)) {
547
+    error(SD_CARD_ERROR_WRITE_MULTIPLE);
548
+    chipSelectHigh();
549
+    return false;
550
+  }
551
+  return writeData(WRITE_MULTIPLE_TOKEN, src);
552
+}
553
+//------------------------------------------------------------------------------
554
+// send one block of data for write block or write multiple blocks
555
+uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {
556
+#ifdef OPTIMIZE_HARDWARE_SPI
557
+
558
+  // send data - optimized loop
559
+  SPDR = token;
560
+
561
+  // send two byte per iteration
562
+  for (uint16_t i = 0; i < 512; i += 2) {
563
+    while (!(SPSR & (1 << SPIF)));
564
+    SPDR = src[i];
565
+    while (!(SPSR & (1 << SPIF)));
566
+    SPDR = src[i+1];
567
+  }
568
+
569
+  // wait for last data byte
570
+  while (!(SPSR & (1 << SPIF)));
571
+
572
+#else  // OPTIMIZE_HARDWARE_SPI
573
+  spiSend(token);
574
+  for (uint16_t i = 0; i < 512; i++) {
575
+    spiSend(src[i]);
576
+  }
577
+#endif  // OPTIMIZE_HARDWARE_SPI
578
+  spiSend(0xff);  // dummy crc
579
+  spiSend(0xff);  // dummy crc
580
+
581
+  status_ = spiRec();
582
+  if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {
583
+    error(SD_CARD_ERROR_WRITE);
584
+    chipSelectHigh();
585
+    return false;
586
+  }
587
+  return true;
588
+}
589
+//------------------------------------------------------------------------------
590
+/** Start a write multiple blocks sequence.
591
+ *
592
+ * \param[in] blockNumber Address of first block in sequence.
593
+ * \param[in] eraseCount The number of blocks to be pre-erased.
594
+ *
595
+ * \note This function is used with writeData() and writeStop()
596
+ * for optimized multiple block writes.
597
+ *
598
+ * \return The value one, true, is returned for success and
599
+ * the value zero, false, is returned for failure.
600
+ */
601
+uint8_t Sd2Card::writeStart(uint32_t blockNumber, uint32_t eraseCount) {
602
+#if SD_PROTECT_BLOCK_ZERO
603
+  // don't allow write to first block
604
+  if (blockNumber == 0) {
605
+    error(SD_CARD_ERROR_WRITE_BLOCK_ZERO);
606
+    goto fail;
607
+  }
608
+#endif  // SD_PROTECT_BLOCK_ZERO
609
+  // send pre-erase count
610
+  if (cardAcmd(ACMD23, eraseCount)) {
611
+    error(SD_CARD_ERROR_ACMD23);
612
+    goto fail;
613
+  }
614
+  // use address if not SDHC card
615
+  if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;
616
+  if (cardCommand(CMD25, blockNumber)) {
617
+    error(SD_CARD_ERROR_CMD25);
618
+    goto fail;
619
+  }
620
+  return true;
621
+
622
+ fail:
623
+  chipSelectHigh();
624
+  return false;
625
+}
626
+//------------------------------------------------------------------------------
627
+/** End a write multiple blocks sequence.
628
+ *
629
+* \return The value one, true, is returned for success and
630
+ * the value zero, false, is returned for failure.
631
+ */
632
+uint8_t Sd2Card::writeStop(void) {
633
+  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail;
634
+  spiSend(STOP_TRAN_TOKEN);
635
+  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail;
636
+  chipSelectHigh();
637
+  return true;
638
+
639
+ fail:
640
+  error(SD_CARD_ERROR_STOP_TRAN);
641
+  chipSelectHigh();
642
+  return false;
643
+}

+ 233
- 0
Marlin/Sd2Card.h View File

@@ -0,0 +1,233 @@
1
+/* Arduino Sd2Card Library
2
+ * Copyright (C) 2009 by William Greiman
3
+ *
4
+ * This file is part of the Arduino Sd2Card Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino Sd2Card Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#ifndef Sd2Card_h
21
+#define Sd2Card_h
22
+/**
23
+ * \file
24
+ * Sd2Card class
25
+ */
26
+#include "Sd2PinMap.h"
27
+#include "SdInfo.h"
28
+/** Set SCK to max rate of F_CPU/2. See Sd2Card::setSckRate(). */
29
+uint8_t const SPI_FULL_SPEED = 0;
30
+/** Set SCK rate to F_CPU/4. See Sd2Card::setSckRate(). */
31
+uint8_t const SPI_HALF_SPEED = 1;
32
+/** Set SCK rate to F_CPU/8. Sd2Card::setSckRate(). */
33
+uint8_t const SPI_QUARTER_SPEED = 2;
34
+/**
35
+ * Define MEGA_SOFT_SPI non-zero to use software SPI on Mega Arduinos.
36
+ * Pins used are SS 10, MOSI 11, MISO 12, and SCK 13.
37
+ *
38
+ * MEGA_SOFT_SPI allows an unmodified Adafruit GPS Shield to be used
39
+ * on Mega Arduinos.  Software SPI works well with GPS Shield V1.1
40
+ * but many SD cards will fail with GPS Shield V1.0.
41
+ */
42
+#define MEGA_SOFT_SPI 0
43
+//------------------------------------------------------------------------------
44
+#if MEGA_SOFT_SPI && (defined(__AVR_ATmega1280__)||defined(__AVR_ATmega2560__))
45
+#define SOFTWARE_SPI
46
+#endif  // MEGA_SOFT_SPI
47
+//------------------------------------------------------------------------------
48
+// SPI pin definitions
49
+//
50
+#ifndef SOFTWARE_SPI
51
+// hardware pin defs
52
+/**
53
+ * SD Chip Select pin
54
+ *
55
+ * Warning if this pin is redefined the hardware SS will pin will be enabled
56
+ * as an output by init().  An avr processor will not function as an SPI
57
+ * master unless SS is set to output mode.
58
+ */
59
+/** The default chip select pin for the SD card is SS. */
60
+uint8_t const  SD_CHIP_SELECT_PIN = SS_PIN;
61
+// The following three pins must not be redefined for hardware SPI.
62
+/** SPI Master Out Slave In pin */
63
+uint8_t const  SPI_MOSI_PIN = MOSI_PIN;
64
+/** SPI Master In Slave Out pin */
65
+uint8_t const  SPI_MISO_PIN = MISO_PIN;
66
+/** SPI Clock pin */
67
+uint8_t const  SPI_SCK_PIN = SCK_PIN;
68
+/** optimize loops for hardware SPI */
69
+#define OPTIMIZE_HARDWARE_SPI
70
+
71
+#else  // SOFTWARE_SPI
72
+// define software SPI pins so Mega can use unmodified GPS Shield
73
+/** SPI chip select pin */
74
+uint8_t const SD_CHIP_SELECT_PIN = 10;
75
+/** SPI Master Out Slave In pin */
76
+uint8_t const SPI_MOSI_PIN = 11;
77
+/** SPI Master In Slave Out pin */
78
+uint8_t const SPI_MISO_PIN = 12;
79
+/** SPI Clock pin */
80
+uint8_t const SPI_SCK_PIN = 13;
81
+#endif  // SOFTWARE_SPI
82
+//------------------------------------------------------------------------------
83
+/** Protect block zero from write if nonzero */
84
+#define SD_PROTECT_BLOCK_ZERO 1
85
+/** init timeout ms */
86
+uint16_t const SD_INIT_TIMEOUT = 2000;
87
+/** erase timeout ms */
88
+uint16_t const SD_ERASE_TIMEOUT = 10000;
89
+/** read timeout ms */
90
+uint16_t const SD_READ_TIMEOUT = 300;
91
+/** write time out ms */
92
+uint16_t const SD_WRITE_TIMEOUT = 600;
93
+//------------------------------------------------------------------------------
94
+// SD card errors
95
+/** timeout error for command CMD0 */
96
+uint8_t const SD_CARD_ERROR_CMD0 = 0X1;
97
+/** CMD8 was not accepted - not a valid SD card*/
98
+uint8_t const SD_CARD_ERROR_CMD8 = 0X2;
99
+/** card returned an error response for CMD17 (read block) */
100
+uint8_t const SD_CARD_ERROR_CMD17 = 0X3;
101
+/** card returned an error response for CMD24 (write block) */
102
+uint8_t const SD_CARD_ERROR_CMD24 = 0X4;
103
+/**  WRITE_MULTIPLE_BLOCKS command failed */
104
+uint8_t const SD_CARD_ERROR_CMD25 = 0X05;
105
+/** card returned an error response for CMD58 (read OCR) */
106
+uint8_t const SD_CARD_ERROR_CMD58 = 0X06;
107
+/** SET_WR_BLK_ERASE_COUNT failed */
108
+uint8_t const SD_CARD_ERROR_ACMD23 = 0X07;
109
+/** card's ACMD41 initialization process timeout */
110
+uint8_t const SD_CARD_ERROR_ACMD41 = 0X08;
111
+/** card returned a bad CSR version field */
112
+uint8_t const SD_CARD_ERROR_BAD_CSD = 0X09;
113
+/** erase block group command failed */
114
+uint8_t const SD_CARD_ERROR_ERASE = 0X0A;
115
+/** card not capable of single block erase */
116
+uint8_t const SD_CARD_ERROR_ERASE_SINGLE_BLOCK = 0X0B;
117
+/** Erase sequence timed out */
118
+uint8_t const SD_CARD_ERROR_ERASE_TIMEOUT = 0X0C;
119
+/** card returned an error token instead of read data */
120
+uint8_t const SD_CARD_ERROR_READ = 0X0D;
121
+/** read CID or CSD failed */
122
+uint8_t const SD_CARD_ERROR_READ_REG = 0X0E;
123
+/** timeout while waiting for start of read data */
124
+uint8_t const SD_CARD_ERROR_READ_TIMEOUT = 0X0F;
125
+/** card did not accept STOP_TRAN_TOKEN */
126
+uint8_t const SD_CARD_ERROR_STOP_TRAN = 0X10;
127
+/** card returned an error token as a response to a write operation */
128
+uint8_t const SD_CARD_ERROR_WRITE = 0X11;
129
+/** attempt to write protected block zero */
130
+uint8_t const SD_CARD_ERROR_WRITE_BLOCK_ZERO = 0X12;
131
+/** card did not go ready for a multiple block write */
132
+uint8_t const SD_CARD_ERROR_WRITE_MULTIPLE = 0X13;
133
+/** card returned an error to a CMD13 status check after a write */
134
+uint8_t const SD_CARD_ERROR_WRITE_PROGRAMMING = 0X14;
135
+/** timeout occurred during write programming */
136
+uint8_t const SD_CARD_ERROR_WRITE_TIMEOUT = 0X15;
137
+/** incorrect rate selected */
138
+uint8_t const SD_CARD_ERROR_SCK_RATE = 0X16;
139
+//------------------------------------------------------------------------------
140
+// card types
141
+/** Standard capacity V1 SD card */
142
+uint8_t const SD_CARD_TYPE_SD1 = 1;
143
+/** Standard capacity V2 SD card */
144
+uint8_t const SD_CARD_TYPE_SD2 = 2;
145
+/** High Capacity SD card */
146
+uint8_t const SD_CARD_TYPE_SDHC = 3;
147
+//------------------------------------------------------------------------------
148
+/**
149
+ * \class Sd2Card
150
+ * \brief Raw access to SD and SDHC flash memory cards.
151
+ */
152
+class Sd2Card {
153
+ public:
154
+  /** Construct an instance of Sd2Card. */
155
+  Sd2Card(void) : errorCode_(0), inBlock_(0), partialBlockRead_(0), type_(0) {}
156
+  uint32_t cardSize(void);
157
+  uint8_t erase(uint32_t firstBlock, uint32_t lastBlock);
158
+  uint8_t eraseSingleBlockEnable(void);
159
+  /**
160
+   * \return error code for last error. See Sd2Card.h for a list of error codes.
161
+   */
162
+  uint8_t errorCode(void) const {return errorCode_;}
163
+  /** \return error data for last error. */
164
+  uint8_t errorData(void) const {return status_;}
165
+  /**
166
+   * Initialize an SD flash memory card with default clock rate and chip
167
+   * select pin.  See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
168
+   */
169
+  uint8_t init(void) {
170
+    return init(SPI_FULL_SPEED, SD_CHIP_SELECT_PIN);
171
+  }
172
+  /**
173
+   * Initialize an SD flash memory card with the selected SPI clock rate
174
+   * and the default SD chip select pin.
175
+   * See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
176
+   */
177
+  uint8_t init(uint8_t sckRateID) {
178
+    return init(sckRateID, SD_CHIP_SELECT_PIN);
179
+  }
180
+  uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin);
181
+  void partialBlockRead(uint8_t value);
182
+  /** Returns the current value, true or false, for partial block read. */
183
+  uint8_t partialBlockRead(void) const {return partialBlockRead_;}
184
+  uint8_t readBlock(uint32_t block, uint8_t* dst);
185
+  uint8_t readData(uint32_t block,
186
+          uint16_t offset, uint16_t count, uint8_t* dst);
187
+  /**
188
+   * Read a cards CID register. The CID contains card identification
189
+   * information such as Manufacturer ID, Product name, Product serial
190
+   * number and Manufacturing date. */
191
+  uint8_t readCID(cid_t* cid) {
192
+    return readRegister(CMD10, cid);
193
+  }
194
+  /**
195
+   * Read a cards CSD register. The CSD contains Card-Specific Data that
196
+   * provides information regarding access to the card's contents. */
197
+  uint8_t readCSD(csd_t* csd) {
198
+    return readRegister(CMD9, csd);
199
+  }
200
+  void readEnd(void);
201
+  uint8_t setSckRate(uint8_t sckRateID);
202
+  /** Return the card type: SD V1, SD V2 or SDHC */
203
+  uint8_t type(void) const {return type_;}
204
+  uint8_t writeBlock(uint32_t blockNumber, const uint8_t* src);
205
+  uint8_t writeData(const uint8_t* src);
206
+  uint8_t writeStart(uint32_t blockNumber, uint32_t eraseCount);
207
+  uint8_t writeStop(void);
208
+ private:
209
+  uint32_t block_;
210
+  uint8_t chipSelectPin_;
211
+  uint8_t errorCode_;
212
+  uint8_t inBlock_;
213
+  uint16_t offset_;
214
+  uint8_t partialBlockRead_;
215
+  uint8_t status_;
216
+  uint8_t type_;
217
+  // private functions
218
+  uint8_t cardAcmd(uint8_t cmd, uint32_t arg) {
219
+    cardCommand(CMD55, 0);
220
+    return cardCommand(cmd, arg);
221
+  }
222
+  uint8_t cardCommand(uint8_t cmd, uint32_t arg);
223
+  void error(uint8_t code) {errorCode_ = code;}
224
+  uint8_t readRegister(uint8_t cmd, void* buf);
225
+  uint8_t sendWriteCommand(uint32_t blockNumber, uint32_t eraseCount);
226
+  void chipSelectHigh(void);
227
+  void chipSelectLow(void);
228
+  void type(uint8_t value) {type_ = value;}
229
+  uint8_t waitNotBusy(uint16_t timeoutMillis);
230
+  uint8_t writeData(uint8_t token, const uint8_t* src);
231
+  uint8_t waitStartBlock(void);
232
+};
233
+#endif  // Sd2Card_h

+ 353
- 0
Marlin/Sd2PinMap.h View File

@@ -0,0 +1,353 @@
1
+/* Arduino SdFat Library
2
+ * Copyright (C) 2010 by William Greiman
3
+ *
4
+ * This file is part of the Arduino SdFat Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino SdFat Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+// Warning this file was generated by a program.
21
+#ifndef Sd2PinMap_h
22
+#define Sd2PinMap_h
23
+#include <avr/io.h>
24
+
25
+//------------------------------------------------------------------------------
26
+/** struct for mapping digital pins */
27
+struct pin_map_t {
28
+  volatile uint8_t* ddr;
29
+  volatile uint8_t* pin;
30
+  volatile uint8_t* port;
31
+  uint8_t bit;
32
+};
33
+//------------------------------------------------------------------------------
34
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
35
+// Mega
36
+
37
+// Two Wire (aka I2C) ports
38
+uint8_t const SDA_PIN = 20;
39
+uint8_t const SCL_PIN = 21;
40
+
41
+// SPI port
42
+uint8_t const SS_PIN = 53;
43
+uint8_t const MOSI_PIN = 51;
44
+uint8_t const MISO_PIN = 50;
45
+uint8_t const SCK_PIN = 52;
46
+
47
+static const pin_map_t digitalPinMap[] = {
48
+  {&DDRE, &PINE, &PORTE, 0},  // E0  0
49
+  {&DDRE, &PINE, &PORTE, 1},  // E1  1
50
+  {&DDRE, &PINE, &PORTE, 4},  // E4  2
51
+  {&DDRE, &PINE, &PORTE, 5},  // E5  3
52
+  {&DDRG, &PING, &PORTG, 5},  // G5  4
53
+  {&DDRE, &PINE, &PORTE, 3},  // E3  5
54
+  {&DDRH, &PINH, &PORTH, 3},  // H3  6
55
+  {&DDRH, &PINH, &PORTH, 4},  // H4  7
56
+  {&DDRH, &PINH, &PORTH, 5},  // H5  8
57
+  {&DDRH, &PINH, &PORTH, 6},  // H6  9
58
+  {&DDRB, &PINB, &PORTB, 4},  // B4 10
59
+  {&DDRB, &PINB, &PORTB, 5},  // B5 11
60
+  {&DDRB, &PINB, &PORTB, 6},  // B6 12
61
+  {&DDRB, &PINB, &PORTB, 7},  // B7 13
62
+  {&DDRJ, &PINJ, &PORTJ, 1},  // J1 14
63
+  {&DDRJ, &PINJ, &PORTJ, 0},  // J0 15
64
+  {&DDRH, &PINH, &PORTH, 1},  // H1 16
65
+  {&DDRH, &PINH, &PORTH, 0},  // H0 17
66
+  {&DDRD, &PIND, &PORTD, 3},  // D3 18
67
+  {&DDRD, &PIND, &PORTD, 2},  // D2 19
68
+  {&DDRD, &PIND, &PORTD, 1},  // D1 20
69
+  {&DDRD, &PIND, &PORTD, 0},  // D0 21
70
+  {&DDRA, &PINA, &PORTA, 0},  // A0 22
71
+  {&DDRA, &PINA, &PORTA, 1},  // A1 23
72
+  {&DDRA, &PINA, &PORTA, 2},  // A2 24
73
+  {&DDRA, &PINA, &PORTA, 3},  // A3 25
74
+  {&DDRA, &PINA, &PORTA, 4},  // A4 26
75
+  {&DDRA, &PINA, &PORTA, 5},  // A5 27
76
+  {&DDRA, &PINA, &PORTA, 6},  // A6 28
77
+  {&DDRA, &PINA, &PORTA, 7},  // A7 29
78
+  {&DDRC, &PINC, &PORTC, 7},  // C7 30
79
+  {&DDRC, &PINC, &PORTC, 6},  // C6 31
80
+  {&DDRC, &PINC, &PORTC, 5},  // C5 32
81
+  {&DDRC, &PINC, &PORTC, 4},  // C4 33
82
+  {&DDRC, &PINC, &PORTC, 3},  // C3 34
83
+  {&DDRC, &PINC, &PORTC, 2},  // C2 35
84
+  {&DDRC, &PINC, &PORTC, 1},  // C1 36
85
+  {&DDRC, &PINC, &PORTC, 0},  // C0 37
86
+  {&DDRD, &PIND, &PORTD, 7},  // D7 38
87
+  {&DDRG, &PING, &PORTG, 2},  // G2 39
88
+  {&DDRG, &PING, &PORTG, 1},  // G1 40
89
+  {&DDRG, &PING, &PORTG, 0},  // G0 41
90
+  {&DDRL, &PINL, &PORTL, 7},  // L7 42
91
+  {&DDRL, &PINL, &PORTL, 6},  // L6 43
92
+  {&DDRL, &PINL, &PORTL, 5},  // L5 44
93
+  {&DDRL, &PINL, &PORTL, 4},  // L4 45
94
+  {&DDRL, &PINL, &PORTL, 3},  // L3 46
95
+  {&DDRL, &PINL, &PORTL, 2},  // L2 47
96
+  {&DDRL, &PINL, &PORTL, 1},  // L1 48
97
+  {&DDRL, &PINL, &PORTL, 0},  // L0 49
98
+  {&DDRB, &PINB, &PORTB, 3},  // B3 50
99
+  {&DDRB, &PINB, &PORTB, 2},  // B2 51
100
+  {&DDRB, &PINB, &PORTB, 1},  // B1 52
101
+  {&DDRB, &PINB, &PORTB, 0},  // B0 53
102
+  {&DDRF, &PINF, &PORTF, 0},  // F0 54
103
+  {&DDRF, &PINF, &PORTF, 1},  // F1 55
104
+  {&DDRF, &PINF, &PORTF, 2},  // F2 56
105
+  {&DDRF, &PINF, &PORTF, 3},  // F3 57
106
+  {&DDRF, &PINF, &PORTF, 4},  // F4 58
107
+  {&DDRF, &PINF, &PORTF, 5},  // F5 59
108
+  {&DDRF, &PINF, &PORTF, 6},  // F6 60
109
+  {&DDRF, &PINF, &PORTF, 7},  // F7 61
110
+  {&DDRK, &PINK, &PORTK, 0},  // K0 62
111
+  {&DDRK, &PINK, &PORTK, 1},  // K1 63
112
+  {&DDRK, &PINK, &PORTK, 2},  // K2 64
113
+  {&DDRK, &PINK, &PORTK, 3},  // K3 65
114
+  {&DDRK, &PINK, &PORTK, 4},  // K4 66
115
+  {&DDRK, &PINK, &PORTK, 5},  // K5 67
116
+  {&DDRK, &PINK, &PORTK, 6},  // K6 68
117
+  {&DDRK, &PINK, &PORTK, 7}   // K7 69
118
+};
119
+//------------------------------------------------------------------------------
120
+#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
121
+// Sanguino
122
+
123
+// Two Wire (aka I2C) ports
124
+uint8_t const SDA_PIN = 17;
125
+uint8_t const SCL_PIN = 18;
126
+
127
+// SPI port
128
+uint8_t const SS_PIN = 4;
129
+uint8_t const MOSI_PIN = 5;
130
+uint8_t const MISO_PIN = 6;
131
+uint8_t const SCK_PIN = 7;
132
+
133
+static const pin_map_t digitalPinMap[] = {
134
+  {&DDRB, &PINB, &PORTB, 0},  // B0  0
135
+  {&DDRB, &PINB, &PORTB, 1},  // B1  1
136
+  {&DDRB, &PINB, &PORTB, 2},  // B2  2
137
+  {&DDRB, &PINB, &PORTB, 3},  // B3  3
138
+  {&DDRB, &PINB, &PORTB, 4},  // B4  4
139
+  {&DDRB, &PINB, &PORTB, 5},  // B5  5
140
+  {&DDRB, &PINB, &PORTB, 6},  // B6  6
141
+  {&DDRB, &PINB, &PORTB, 7},  // B7  7
142
+  {&DDRD, &PIND, &PORTD, 0},  // D0  8
143
+  {&DDRD, &PIND, &PORTD, 1},  // D1  9
144
+  {&DDRD, &PIND, &PORTD, 2},  // D2 10
145
+  {&DDRD, &PIND, &PORTD, 3},  // D3 11
146
+  {&DDRD, &PIND, &PORTD, 4},  // D4 12
147
+  {&DDRD, &PIND, &PORTD, 5},  // D5 13
148
+  {&DDRD, &PIND, &PORTD, 6},  // D6 14
149
+  {&DDRD, &PIND, &PORTD, 7},  // D7 15
150
+  {&DDRC, &PINC, &PORTC, 0},  // C0 16
151
+  {&DDRC, &PINC, &PORTC, 1},  // C1 17
152
+  {&DDRC, &PINC, &PORTC, 2},  // C2 18
153
+  {&DDRC, &PINC, &PORTC, 3},  // C3 19
154
+  {&DDRC, &PINC, &PORTC, 4},  // C4 20
155
+  {&DDRC, &PINC, &PORTC, 5},  // C5 21
156
+  {&DDRC, &PINC, &PORTC, 6},  // C6 22
157
+  {&DDRC, &PINC, &PORTC, 7},  // C7 23
158
+  {&DDRA, &PINA, &PORTA, 7},  // A7 24
159
+  {&DDRA, &PINA, &PORTA, 6},  // A6 25
160
+  {&DDRA, &PINA, &PORTA, 5},  // A5 26
161
+  {&DDRA, &PINA, &PORTA, 4},  // A4 27
162
+  {&DDRA, &PINA, &PORTA, 3},  // A3 28
163
+  {&DDRA, &PINA, &PORTA, 2},  // A2 29
164
+  {&DDRA, &PINA, &PORTA, 1},  // A1 30
165
+  {&DDRA, &PINA, &PORTA, 0}   // A0 31
166
+};
167
+//------------------------------------------------------------------------------
168
+#elif defined(__AVR_ATmega32U4__)
169
+// Teensy 2.0
170
+
171
+// Two Wire (aka I2C) ports
172
+uint8_t const SDA_PIN = 6;
173
+uint8_t const SCL_PIN = 5;
174
+
175
+// SPI port
176
+uint8_t const SS_PIN = 0;
177
+uint8_t const MOSI_PIN = 2;
178
+uint8_t const MISO_PIN = 3;
179
+uint8_t const SCK_PIN = 1;
180
+
181
+static const pin_map_t digitalPinMap[] = {
182
+  {&DDRB, &PINB, &PORTB, 0},  // B0  0
183
+  {&DDRB, &PINB, &PORTB, 1},  // B1  1
184
+  {&DDRB, &PINB, &PORTB, 2},  // B2  2
185
+  {&DDRB, &PINB, &PORTB, 3},  // B3  3
186
+  {&DDRB, &PINB, &PORTB, 7},  // B7  4
187
+  {&DDRD, &PIND, &PORTD, 0},  // D0  5
188
+  {&DDRD, &PIND, &PORTD, 1},  // D1  6
189
+  {&DDRD, &PIND, &PORTD, 2},  // D2  7
190
+  {&DDRD, &PIND, &PORTD, 3},  // D3  8
191
+  {&DDRC, &PINC, &PORTC, 6},  // C6  9
192
+  {&DDRC, &PINC, &PORTC, 7},  // C7 10
193
+  {&DDRD, &PIND, &PORTD, 6},  // D6 11
194
+  {&DDRD, &PIND, &PORTD, 7},  // D7 12
195
+  {&DDRB, &PINB, &PORTB, 4},  // B4 13
196
+  {&DDRB, &PINB, &PORTB, 5},  // B5 14
197
+  {&DDRB, &PINB, &PORTB, 6},  // B6 15
198
+  {&DDRF, &PINF, &PORTF, 7},  // F7 16
199
+  {&DDRF, &PINF, &PORTF, 6},  // F6 17
200
+  {&DDRF, &PINF, &PORTF, 5},  // F5 18
201
+  {&DDRF, &PINF, &PORTF, 4},  // F4 19
202
+  {&DDRF, &PINF, &PORTF, 1},  // F1 20
203
+  {&DDRF, &PINF, &PORTF, 0},  // F0 21
204
+  {&DDRD, &PIND, &PORTD, 4},  // D4 22
205
+  {&DDRD, &PIND, &PORTD, 5},  // D5 23
206
+  {&DDRE, &PINE, &PORTE, 6}   // E6 24
207
+};
208
+//------------------------------------------------------------------------------
209
+#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
210
+// Teensy++ 1.0 & 2.0
211
+
212
+// Two Wire (aka I2C) ports
213
+uint8_t const SDA_PIN = 1;
214
+uint8_t const SCL_PIN = 0;
215
+
216
+// SPI port
217
+uint8_t const SS_PIN = 20;
218
+uint8_t const MOSI_PIN = 22;
219
+uint8_t const MISO_PIN = 23;
220
+uint8_t const SCK_PIN = 21;
221
+
222
+static const pin_map_t digitalPinMap[] = {
223
+  {&DDRD, &PIND, &PORTD, 0},  // D0  0
224
+  {&DDRD, &PIND, &PORTD, 1},  // D1  1
225
+  {&DDRD, &PIND, &PORTD, 2},  // D2  2
226
+  {&DDRD, &PIND, &PORTD, 3},  // D3  3
227
+  {&DDRD, &PIND, &PORTD, 4},  // D4  4
228
+  {&DDRD, &PIND, &PORTD, 5},  // D5  5
229
+  {&DDRD, &PIND, &PORTD, 6},  // D6  6
230
+  {&DDRD, &PIND, &PORTD, 7},  // D7  7
231
+  {&DDRE, &PINE, &PORTE, 0},  // E0  8
232
+  {&DDRE, &PINE, &PORTE, 1},  // E1  9
233
+  {&DDRC, &PINC, &PORTC, 0},  // C0 10
234
+  {&DDRC, &PINC, &PORTC, 1},  // C1 11
235
+  {&DDRC, &PINC, &PORTC, 2},  // C2 12
236
+  {&DDRC, &PINC, &PORTC, 3},  // C3 13
237
+  {&DDRC, &PINC, &PORTC, 4},  // C4 14
238
+  {&DDRC, &PINC, &PORTC, 5},  // C5 15
239
+  {&DDRC, &PINC, &PORTC, 6},  // C6 16
240
+  {&DDRC, &PINC, &PORTC, 7},  // C7 17
241
+  {&DDRE, &PINE, &PORTE, 6},  // E6 18
242
+  {&DDRE, &PINE, &PORTE, 7},  // E7 19
243
+  {&DDRB, &PINB, &PORTB, 0},  // B0 20
244
+  {&DDRB, &PINB, &PORTB, 1},  // B1 21
245
+  {&DDRB, &PINB, &PORTB, 2},  // B2 22
246
+  {&DDRB, &PINB, &PORTB, 3},  // B3 23
247
+  {&DDRB, &PINB, &PORTB, 4},  // B4 24
248
+  {&DDRB, &PINB, &PORTB, 5},  // B5 25
249
+  {&DDRB, &PINB, &PORTB, 6},  // B6 26
250
+  {&DDRB, &PINB, &PORTB, 7},  // B7 27
251
+  {&DDRA, &PINA, &PORTA, 0},  // A0 28
252
+  {&DDRA, &PINA, &PORTA, 1},  // A1 29
253
+  {&DDRA, &PINA, &PORTA, 2},  // A2 30
254
+  {&DDRA, &PINA, &PORTA, 3},  // A3 31
255
+  {&DDRA, &PINA, &PORTA, 4},  // A4 32
256
+  {&DDRA, &PINA, &PORTA, 5},  // A5 33
257
+  {&DDRA, &PINA, &PORTA, 6},  // A6 34
258
+  {&DDRA, &PINA, &PORTA, 7},  // A7 35
259
+  {&DDRE, &PINE, &PORTE, 4},  // E4 36
260
+  {&DDRE, &PINE, &PORTE, 5},  // E5 37
261
+  {&DDRF, &PINF, &PORTF, 0},  // F0 38
262
+  {&DDRF, &PINF, &PORTF, 1},  // F1 39
263
+  {&DDRF, &PINF, &PORTF, 2},  // F2 40
264
+  {&DDRF, &PINF, &PORTF, 3},  // F3 41
265
+  {&DDRF, &PINF, &PORTF, 4},  // F4 42
266
+  {&DDRF, &PINF, &PORTF, 5},  // F5 43
267
+  {&DDRF, &PINF, &PORTF, 6},  // F6 44
268
+  {&DDRF, &PINF, &PORTF, 7}   // F7 45
269
+};
270
+//------------------------------------------------------------------------------
271
+#else  // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
272
+// 168 and 328 Arduinos
273
+
274
+// Two Wire (aka I2C) ports
275
+uint8_t const SDA_PIN = 18;
276
+uint8_t const SCL_PIN = 19;
277
+
278
+// SPI port
279
+uint8_t const SS_PIN = 10;
280
+uint8_t const MOSI_PIN = 11;
281
+uint8_t const MISO_PIN = 12;
282
+uint8_t const SCK_PIN = 13;
283
+
284
+static const pin_map_t digitalPinMap[] = {
285
+  {&DDRD, &PIND, &PORTD, 0},  // D0  0
286
+  {&DDRD, &PIND, &PORTD, 1},  // D1  1
287
+  {&DDRD, &PIND, &PORTD, 2},  // D2  2
288
+  {&DDRD, &PIND, &PORTD, 3},  // D3  3
289
+  {&DDRD, &PIND, &PORTD, 4},  // D4  4
290
+  {&DDRD, &PIND, &PORTD, 5},  // D5  5
291
+  {&DDRD, &PIND, &PORTD, 6},  // D6  6
292
+  {&DDRD, &PIND, &PORTD, 7},  // D7  7
293
+  {&DDRB, &PINB, &PORTB, 0},  // B0  8
294
+  {&DDRB, &PINB, &PORTB, 1},  // B1  9
295
+  {&DDRB, &PINB, &PORTB, 2},  // B2 10
296
+  {&DDRB, &PINB, &PORTB, 3},  // B3 11
297
+  {&DDRB, &PINB, &PORTB, 4},  // B4 12
298
+  {&DDRB, &PINB, &PORTB, 5},  // B5 13
299
+  {&DDRC, &PINC, &PORTC, 0},  // C0 14
300
+  {&DDRC, &PINC, &PORTC, 1},  // C1 15
301
+  {&DDRC, &PINC, &PORTC, 2},  // C2 16
302
+  {&DDRC, &PINC, &PORTC, 3},  // C3 17
303
+  {&DDRC, &PINC, &PORTC, 4},  // C4 18
304
+  {&DDRC, &PINC, &PORTC, 5}   // C5 19
305
+};
306
+#endif  // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
307
+//------------------------------------------------------------------------------
308
+static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
309
+
310
+uint8_t badPinNumber(void)
311
+  __attribute__((error("Pin number is too large or not a constant")));
312
+
313
+static inline __attribute__((always_inline))
314
+  uint8_t getPinMode(uint8_t pin) {
315
+  if (__builtin_constant_p(pin) && pin < digitalPinCount) {
316
+    return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;
317
+  } else {
318
+    return badPinNumber();
319
+  }
320
+}
321
+static inline __attribute__((always_inline))
322
+  void setPinMode(uint8_t pin, uint8_t mode) {
323
+  if (__builtin_constant_p(pin) && pin < digitalPinCount) {
324
+    if (mode) {
325
+      *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
326
+    } else {
327
+      *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);
328
+    }
329
+  } else {
330
+    badPinNumber();
331
+  }
332
+}
333
+static inline __attribute__((always_inline))
334
+  uint8_t fastDigitalRead(uint8_t pin) {
335
+  if (__builtin_constant_p(pin) && pin < digitalPinCount) {
336
+    return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;
337
+  } else {
338
+    return badPinNumber();
339
+  }
340
+}
341
+static inline __attribute__((always_inline))
342
+  void fastDigitalWrite(uint8_t pin, uint8_t value) {
343
+  if (__builtin_constant_p(pin) && pin < digitalPinCount) {
344
+    if (value) {
345
+      *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;
346
+    } else {
347
+      *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);
348
+    }
349
+  } else {
350
+    badPinNumber();
351
+  }
352
+}
353
+#endif  // Sd2PinMap_h

+ 547
- 0
Marlin/SdFat.h View File

@@ -0,0 +1,547 @@
1
+/* Arduino SdFat Library
2
+ * Copyright (C) 2009 by William Greiman
3
+ *
4
+ * This file is part of the Arduino SdFat Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino SdFat Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#ifndef SdFat_h
21
+#define SdFat_h
22
+/**
23
+ * \file
24
+ * SdFile and SdVolume classes
25
+ */
26
+#include <avr/pgmspace.h>
27
+#include "Sd2Card.h"
28
+#include "FatStructs.h"
29
+#include "Print.h"
30
+//------------------------------------------------------------------------------
31
+/**
32
+ * Allow use of deprecated functions if non-zero
33
+ */
34
+#define ALLOW_DEPRECATED_FUNCTIONS 1
35
+//------------------------------------------------------------------------------
36
+// forward declaration since SdVolume is used in SdFile
37
+class SdVolume;
38
+//==============================================================================
39
+// SdFile class
40
+
41
+// flags for ls()
42
+/** ls() flag to print modify date */
43
+uint8_t const LS_DATE = 1;
44
+/** ls() flag to print file size */
45
+uint8_t const LS_SIZE = 2;
46
+/** ls() flag for recursive list of subdirectories */
47
+uint8_t const LS_R = 4;
48
+
49
+// use the gnu style oflag in open()
50
+/** open() oflag for reading */
51
+uint8_t const O_READ = 0X01;
52
+/** open() oflag - same as O_READ */
53
+uint8_t const O_RDONLY = O_READ;
54
+/** open() oflag for write */
55
+uint8_t const O_WRITE = 0X02;
56
+/** open() oflag - same as O_WRITE */
57
+uint8_t const O_WRONLY = O_WRITE;
58
+/** open() oflag for reading and writing */
59
+uint8_t const O_RDWR = (O_READ | O_WRITE);
60
+/** open() oflag mask for access modes */
61
+uint8_t const O_ACCMODE = (O_READ | O_WRITE);
62
+/** The file offset shall be set to the end of the file prior to each write. */
63
+uint8_t const O_APPEND = 0X04;
64
+/** synchronous writes - call sync() after each write */
65
+uint8_t const O_SYNC = 0X08;
66
+/** create the file if nonexistent */
67
+uint8_t const O_CREAT = 0X10;
68
+/** If O_CREAT and O_EXCL are set, open() shall fail if the file exists */
69
+uint8_t const O_EXCL = 0X20;
70
+/** truncate the file to zero length */
71
+uint8_t const O_TRUNC = 0X40;
72
+
73
+// flags for timestamp
74
+/** set the file's last access date */
75
+uint8_t const T_ACCESS = 1;
76
+/** set the file's creation date and time */
77
+uint8_t const T_CREATE = 2;
78
+/** Set the file's write date and time */
79
+uint8_t const T_WRITE = 4;
80
+// values for type_
81
+/** This SdFile has not been opened. */
82
+uint8_t const FAT_FILE_TYPE_CLOSED = 0;
83
+/** SdFile for a file */
84
+uint8_t const FAT_FILE_TYPE_NORMAL = 1;
85
+/** SdFile for a FAT16 root directory */
86
+uint8_t const FAT_FILE_TYPE_ROOT16 = 2;
87
+/** SdFile for a FAT32 root directory */
88
+uint8_t const FAT_FILE_TYPE_ROOT32 = 3;
89
+/** SdFile for a subdirectory */
90
+uint8_t const FAT_FILE_TYPE_SUBDIR = 4;
91
+/** Test value for directory type */
92
+uint8_t const FAT_FILE_TYPE_MIN_DIR = FAT_FILE_TYPE_ROOT16;
93
+
94
+/** date field for FAT directory entry */
95
+static inline uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day) {
96
+  return (year - 1980) << 9 | month << 5 | day;
97
+}
98
+/** year part of FAT directory date field */
99
+static inline uint16_t FAT_YEAR(uint16_t fatDate) {
100
+  return 1980 + (fatDate >> 9);
101
+}
102
+/** month part of FAT directory date field */
103
+static inline uint8_t FAT_MONTH(uint16_t fatDate) {
104
+  return (fatDate >> 5) & 0XF;
105
+}
106
+/** day part of FAT directory date field */
107
+static inline uint8_t FAT_DAY(uint16_t fatDate) {
108
+  return fatDate & 0X1F;
109
+}
110
+/** time field for FAT directory entry */
111
+static inline uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second) {
112
+  return hour << 11 | minute << 5 | second >> 1;
113
+}
114
+/** hour part of FAT directory time field */
115
+static inline uint8_t FAT_HOUR(uint16_t fatTime) {
116
+  return fatTime >> 11;
117
+}
118
+/** minute part of FAT directory time field */
119
+static inline uint8_t FAT_MINUTE(uint16_t fatTime) {
120
+  return(fatTime >> 5) & 0X3F;
121
+}
122
+/** second part of FAT directory time field */
123
+static inline uint8_t FAT_SECOND(uint16_t fatTime) {
124
+  return 2*(fatTime & 0X1F);
125
+}
126
+/** Default date for file timestamps is 1 Jan 2000 */
127
+uint16_t const FAT_DEFAULT_DATE = ((2000 - 1980) << 9) | (1 << 5) | 1;
128
+/** Default time for file timestamp is 1 am */
129
+uint16_t const FAT_DEFAULT_TIME = (1 << 11);
130
+//------------------------------------------------------------------------------
131
+/**
132
+ * \class SdFile
133
+ * \brief Access FAT16 and FAT32 files on SD and SDHC cards.
134
+ */
135
+class SdFile : public Print {
136
+ public:
137
+  /** Create an instance of SdFile. */
138
+  SdFile(void) : type_(FAT_FILE_TYPE_CLOSED) {}
139
+  /**
140
+   * writeError is set to true if an error occurs during a write().
141
+   * Set writeError to false before calling print() and/or write() and check
142
+   * for true after calls to print() and/or write().
143
+   */
144
+  bool writeError;
145
+  /**
146
+   * Cancel unbuffered reads for this file.
147
+   * See setUnbufferedRead()
148
+   */
149
+  void clearUnbufferedRead(void) {
150
+    flags_ &= ~F_FILE_UNBUFFERED_READ;
151
+  }
152
+  uint8_t close(void);
153
+  uint8_t contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock);
154
+  uint8_t createContiguous(SdFile* dirFile,
155
+          const char* fileName, uint32_t size);
156
+  /** \return The current cluster number for a file or directory. */
157
+  uint32_t curCluster(void) const {return curCluster_;}
158
+  /** \return The current position for a file or directory. */
159
+  uint32_t curPosition(void) const {return curPosition_;}
160
+  /**
161
+   * Set the date/time callback function
162
+   *
163
+   * \param[in] dateTime The user's call back function.  The callback
164
+   * function is of the form:
165
+   *
166
+   * \code
167
+   * void dateTime(uint16_t* date, uint16_t* time) {
168
+   *   uint16_t year;
169
+   *   uint8_t month, day, hour, minute, second;
170
+   *
171
+   *   // User gets date and time from GPS or real-time clock here
172
+   *
173
+   *   // return date using FAT_DATE macro to format fields
174
+   *   *date = FAT_DATE(year, month, day);
175
+   *
176
+   *   // return time using FAT_TIME macro to format fields
177
+   *   *time = FAT_TIME(hour, minute, second);
178
+   * }
179
+   * \endcode
180
+   *
181
+   * Sets the function that is called when a file is created or when
182
+   * a file's directory entry is modified by sync(). All timestamps,
183
+   * access, creation, and modify, are set when a file is created.
184
+   * sync() maintains the last access date and last modify date/time.
185
+   *
186
+   * See the timestamp() function.
187
+   */
188
+  static void dateTimeCallback(
189
+    void (*dateTime)(uint16_t* date, uint16_t* time)) {
190
+    dateTime_ = dateTime;
191
+  }
192
+  /**
193
+   * Cancel the date/time callback function.
194
+   */
195
+  static void dateTimeCallbackCancel(void) {
196
+    // use explicit zero since NULL is not defined for Sanguino
197
+    dateTime_ = 0;
198
+  }
199
+  /** \return Address of the block that contains this file's directory. */
200
+  uint32_t dirBlock(void) const {return dirBlock_;}
201
+  uint8_t dirEntry(dir_t* dir);
202
+  /** \return Index of this file's directory in the block dirBlock. */
203
+  uint8_t dirIndex(void) const {return dirIndex_;}
204
+  static void dirName(const dir_t& dir, char* name);
205
+  /** \return The total number of bytes in a file or directory. */
206
+  uint32_t fileSize(void) const {return fileSize_;}
207
+  /** \return The first cluster number for a file or directory. */
208
+  uint32_t firstCluster(void) const {return firstCluster_;}
209
+  /** \return True if this is a SdFile for a directory else false. */
210
+  uint8_t isDir(void) const {return type_ >= FAT_FILE_TYPE_MIN_DIR;}
211
+  /** \return True if this is a SdFile for a file else false. */
212
+  uint8_t isFile(void) const {return type_ == FAT_FILE_TYPE_NORMAL;}
213
+  /** \return True if this is a SdFile for an open file/directory else false. */
214
+  uint8_t isOpen(void) const {return type_ != FAT_FILE_TYPE_CLOSED;}
215
+  /** \return True if this is a SdFile for a subdirectory else false. */
216
+  uint8_t isSubDir(void) const {return type_ == FAT_FILE_TYPE_SUBDIR;}
217
+  /** \return True if this is a SdFile for the root directory. */
218
+  uint8_t isRoot(void) const {
219
+    return type_ == FAT_FILE_TYPE_ROOT16 || type_ == FAT_FILE_TYPE_ROOT32;
220
+  }
221
+  void ls(uint8_t flags = 0, uint8_t indent = 0);
222
+  uint8_t makeDir(SdFile* dir, const char* dirName);
223
+  uint8_t open(SdFile* dirFile, uint16_t index, uint8_t oflag);
224
+  uint8_t open(SdFile* dirFile, const char* fileName, uint8_t oflag);
225
+
226
+  uint8_t openRoot(SdVolume* vol);
227
+  static void printDirName(const dir_t& dir, uint8_t width);
228
+  static void printFatDate(uint16_t fatDate);
229
+  static void printFatTime(uint16_t fatTime);
230
+  static void printTwoDigits(uint8_t v);
231
+  /**
232
+   * Read the next byte from a file.
233
+   *
234
+   * \return For success read returns the next byte in the file as an int.
235
+   * If an error occurs or end of file is reached -1 is returned.
236
+   */
237
+  int16_t read(void) {
238
+    uint8_t b;
239
+    return read(&b, 1) == 1 ? b : -1;
240
+  }
241
+  int16_t read(void* buf, uint16_t nbyte);
242
+  int8_t readDir(dir_t* dir);
243
+  static uint8_t remove(SdFile* dirFile, const char* fileName);
244
+  uint8_t remove(void);
245
+  /** Set the file's current position to zero. */
246
+  void rewind(void) {
247
+    curPosition_ = curCluster_ = 0;
248
+  }
249
+  uint8_t rmDir(void);
250
+  uint8_t rmRfStar(void);
251
+  /** Set the files position to current position + \a pos. See seekSet(). */
252
+  uint8_t seekCur(uint32_t pos) {
253
+    return seekSet(curPosition_ + pos);
254
+  }
255
+  /**
256
+   *  Set the files current position to end of file.  Useful to position
257
+   *  a file for append. See seekSet().
258
+   */
259
+  uint8_t seekEnd(void) {return seekSet(fileSize_);}
260
+  uint8_t seekSet(uint32_t pos);
261
+  /**
262
+   * Use unbuffered reads to access this file.  Used with Wave
263
+   * Shield ISR.  Used with Sd2Card::partialBlockRead() in WaveRP.
264
+   *
265
+   * Not recommended for normal applications.
266
+   */
267
+  void setUnbufferedRead(void) {
268
+    if (isFile()) flags_ |= F_FILE_UNBUFFERED_READ;
269
+  }
270
+  uint8_t timestamp(uint8_t flag, uint16_t year, uint8_t month, uint8_t day,
271
+          uint8_t hour, uint8_t minute, uint8_t second);
272
+  uint8_t sync(void);
273
+  /** Type of this SdFile.  You should use isFile() or isDir() instead of type()
274
+   * if possible.
275
+   *
276
+   * \return The file or directory type.
277
+   */
278
+  uint8_t type(void) const {return type_;}
279
+  uint8_t truncate(uint32_t size);
280
+  /** \return Unbuffered read flag. */
281
+  uint8_t unbufferedRead(void) const {
282
+    return flags_ & F_FILE_UNBUFFERED_READ;
283
+  }
284
+  /** \return SdVolume that contains this file. */
285
+  SdVolume* volume(void) const {return vol_;}
286
+  void write(uint8_t b);
287
+  int16_t write(const void* buf, uint16_t nbyte);
288
+  void write(const char* str);
289
+  void write_P(PGM_P str);
290
+  void writeln_P(PGM_P str);
291
+//------------------------------------------------------------------------------
292
+#if ALLOW_DEPRECATED_FUNCTIONS
293
+// Deprecated functions  - suppress cpplint warnings with NOLINT comment
294
+  /** \deprecated Use:
295
+   * uint8_t SdFile::contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock);
296
+   */
297
+  uint8_t contiguousRange(uint32_t& bgnBlock, uint32_t& endBlock) {  // NOLINT
298
+    return contiguousRange(&bgnBlock, &endBlock);
299
+  }
300
+ /** \deprecated Use:
301
+   * uint8_t SdFile::createContiguous(SdFile* dirFile,
302
+   *   const char* fileName, uint32_t size)
303
+   */
304
+  uint8_t createContiguous(SdFile& dirFile,  // NOLINT
305
+    const char* fileName, uint32_t size) {
306
+    return createContiguous(&dirFile, fileName, size);
307
+  }
308
+
309
+  /**
310
+   * \deprecated Use:
311
+   * static void SdFile::dateTimeCallback(
312
+   *   void (*dateTime)(uint16_t* date, uint16_t* time));
313
+   */
314
+  static void dateTimeCallback(
315
+    void (*dateTime)(uint16_t& date, uint16_t& time)) {  // NOLINT
316
+    oldDateTime_ = dateTime;
317
+    dateTime_ = dateTime ? oldToNew : 0;
318
+  }
319
+  /** \deprecated Use: uint8_t SdFile::dirEntry(dir_t* dir); */
320
+  uint8_t dirEntry(dir_t& dir) {return dirEntry(&dir);}  // NOLINT
321
+  /** \deprecated Use:
322
+   * uint8_t SdFile::makeDir(SdFile* dir, const char* dirName);
323
+   */
324
+  uint8_t makeDir(SdFile& dir, const char* dirName) {  // NOLINT
325
+    return makeDir(&dir, dirName);
326
+  }
327
+  /** \deprecated Use:
328
+   * uint8_t SdFile::open(SdFile* dirFile, const char* fileName, uint8_t oflag);
329
+   */
330
+  uint8_t open(SdFile& dirFile, // NOLINT
331
+    const char* fileName, uint8_t oflag) {
332
+    return open(&dirFile, fileName, oflag);
333
+  }
334
+  /** \deprecated  Do not use in new apps */
335
+  uint8_t open(SdFile& dirFile, const char* fileName) {  // NOLINT
336
+    return open(dirFile, fileName, O_RDWR);
337
+  }
338
+  /** \deprecated Use:
339
+   * uint8_t SdFile::open(SdFile* dirFile, uint16_t index, uint8_t oflag);
340
+   */
341
+  uint8_t open(SdFile& dirFile, uint16_t index, uint8_t oflag) {  // NOLINT
342
+    return open(&dirFile, index, oflag);
343
+  }
344
+  /** \deprecated Use: uint8_t SdFile::openRoot(SdVolume* vol); */
345
+  uint8_t openRoot(SdVolume& vol) {return openRoot(&vol);}  // NOLINT
346
+
347
+  /** \deprecated Use: int8_t SdFile::readDir(dir_t* dir); */
348
+  int8_t readDir(dir_t& dir) {return readDir(&dir);}  // NOLINT
349
+  /** \deprecated Use:
350
+   * static uint8_t SdFile::remove(SdFile* dirFile, const char* fileName);
351
+   */
352
+  static uint8_t remove(SdFile& dirFile, const char* fileName) {  // NOLINT
353
+    return remove(&dirFile, fileName);
354
+  }
355
+//------------------------------------------------------------------------------
356
+// rest are private
357
+ private:
358
+  static void (*oldDateTime_)(uint16_t& date, uint16_t& time);  // NOLINT
359
+  static void oldToNew(uint16_t* date, uint16_t* time) {
360
+    uint16_t d;
361
+    uint16_t t;
362
+    oldDateTime_(d, t);
363
+    *date = d;
364
+    *time = t;
365
+  }
366
+#endif  // ALLOW_DEPRECATED_FUNCTIONS
367
+ private:
368
+  // bits defined in flags_
369
+  // should be 0XF
370
+  static uint8_t const F_OFLAG = (O_ACCMODE | O_APPEND | O_SYNC);
371
+  // available bits
372
+  static uint8_t const F_UNUSED = 0X30;
373
+  // use unbuffered SD read
374
+  static uint8_t const F_FILE_UNBUFFERED_READ = 0X40;
375
+  // sync of directory entry required
376
+  static uint8_t const F_FILE_DIR_DIRTY = 0X80;
377
+
378
+// make sure F_OFLAG is ok
379
+#if ((F_UNUSED | F_FILE_UNBUFFERED_READ | F_FILE_DIR_DIRTY) & F_OFLAG)
380
+#error flags_ bits conflict
381
+#endif  // flags_ bits
382
+
383
+  // private data
384
+  uint8_t   flags_;         // See above for definition of flags_ bits
385
+  uint8_t   type_;          // type of file see above for values
386
+  uint32_t  curCluster_;    // cluster for current file position
387
+  uint32_t  curPosition_;   // current file position in bytes from beginning
388
+  uint32_t  dirBlock_;      // SD block that contains directory entry for file
389
+  uint8_t   dirIndex_;      // index of entry in dirBlock 0 <= dirIndex_ <= 0XF
390
+  uint32_t  fileSize_;      // file size in bytes
391
+  uint32_t  firstCluster_;  // first cluster of file
392
+  SdVolume* vol_;           // volume where file is located
393
+
394
+  // private functions
395
+  uint8_t addCluster(void);
396
+  uint8_t addDirCluster(void);
397
+  dir_t* cacheDirEntry(uint8_t action);
398
+  static void (*dateTime_)(uint16_t* date, uint16_t* time);
399
+  static uint8_t make83Name(const char* str, uint8_t* name);
400
+  uint8_t openCachedEntry(uint8_t cacheIndex, uint8_t oflags);
401
+  dir_t* readDirCache(void);
402
+};
403
+//==============================================================================
404
+// SdVolume class
405
+/**
406
+ * \brief Cache for an SD data block
407
+ */
408
+union cache_t {
409
+           /** Used to access cached file data blocks. */
410
+  uint8_t  data[512];
411
+           /** Used to access cached FAT16 entries. */
412
+  uint16_t fat16[256];
413
+           /** Used to access cached FAT32 entries. */
414
+  uint32_t fat32[128];
415
+           /** Used to access cached directory entries. */
416
+  dir_t    dir[16];
417
+           /** Used to access a cached MasterBoot Record. */
418
+  mbr_t    mbr;
419
+           /** Used to access to a cached FAT boot sector. */
420
+  fbs_t    fbs;
421
+};
422
+//------------------------------------------------------------------------------
423
+/**
424
+ * \class SdVolume
425
+ * \brief Access FAT16 and FAT32 volumes on SD and SDHC cards.
426
+ */
427
+class SdVolume {
428
+ public:
429
+  /** Create an instance of SdVolume */
430
+  SdVolume(void) :allocSearchStart_(2), fatType_(0) {}
431
+  /** Clear the cache and returns a pointer to the cache.  Used by the WaveRP
432
+   *  recorder to do raw write to the SD card.  Not for normal apps.
433
+   */
434
+  static uint8_t* cacheClear(void) {
435
+    cacheFlush();
436
+    cacheBlockNumber_ = 0XFFFFFFFF;
437
+    return cacheBuffer_.data;
438
+  }
439
+  /**
440
+   * Initialize a FAT volume.  Try partition one first then try super
441
+   * floppy format.
442
+   *
443
+   * \param[in] dev The Sd2Card where the volume is located.
444
+   *
445
+   * \return The value one, true, is returned for success and
446
+   * the value zero, false, is returned for failure.  Reasons for
447
+   * failure include not finding a valid partition, not finding a valid
448
+   * FAT file system or an I/O error.
449
+   */
450
+  uint8_t init(Sd2Card* dev) { return init(dev, 1) ? true : init(dev, 0);}
451
+  uint8_t init(Sd2Card* dev, uint8_t part);
452
+
453
+  // inline functions that return volume info
454
+  /** \return The volume's cluster size in blocks. */
455
+  uint8_t blocksPerCluster(void) const {return blocksPerCluster_;}
456
+  /** \return The number of blocks in one FAT. */
457
+  uint32_t blocksPerFat(void)  const {return blocksPerFat_;}
458
+  /** \return The total number of clusters in the volume. */
459
+  uint32_t clusterCount(void) const {return clusterCount_;}
460
+  /** \return The shift count required to multiply by blocksPerCluster. */
461
+  uint8_t clusterSizeShift(void) const {return clusterSizeShift_;}
462
+  /** \return The logical block number for the start of file data. */
463
+  uint32_t dataStartBlock(void) const {return dataStartBlock_;}
464
+  /** \return The number of FAT structures on the volume. */
465
+  uint8_t fatCount(void) const {return fatCount_;}
466
+  /** \return The logical block number for the start of the first FAT. */
467
+  uint32_t fatStartBlock(void) const {return fatStartBlock_;}
468
+  /** \return The FAT type of the volume. Values are 12, 16 or 32. */
469
+  uint8_t fatType(void) const {return fatType_;}
470
+  /** \return The number of entries in the root directory for FAT16 volumes. */
471
+  uint32_t rootDirEntryCount(void) const {return rootDirEntryCount_;}
472
+  /** \return The logical block number for the start of the root directory
473
+       on FAT16 volumes or the first cluster number on FAT32 volumes. */
474
+  uint32_t rootDirStart(void) const {return rootDirStart_;}
475
+  /** return a pointer to the Sd2Card object for this volume */
476
+  static Sd2Card* sdCard(void) {return sdCard_;}
477
+//------------------------------------------------------------------------------
478
+#if ALLOW_DEPRECATED_FUNCTIONS
479
+  // Deprecated functions  - suppress cpplint warnings with NOLINT comment
480
+  /** \deprecated Use: uint8_t SdVolume::init(Sd2Card* dev); */
481
+  uint8_t init(Sd2Card& dev) {return init(&dev);}  // NOLINT
482
+
483
+  /** \deprecated Use: uint8_t SdVolume::init(Sd2Card* dev, uint8_t vol); */
484
+  uint8_t init(Sd2Card& dev, uint8_t part) {  // NOLINT
485
+    return init(&dev, part);
486
+  }
487
+#endif  // ALLOW_DEPRECATED_FUNCTIONS
488
+//------------------------------------------------------------------------------
489
+  private:
490
+  // Allow SdFile access to SdVolume private data.
491
+  friend class SdFile;
492
+
493
+  // value for action argument in cacheRawBlock to indicate read from cache
494
+  static uint8_t const CACHE_FOR_READ = 0;
495
+  // value for action argument in cacheRawBlock to indicate cache dirty
496
+  static uint8_t const CACHE_FOR_WRITE = 1;
497
+
498
+  static cache_t cacheBuffer_;        // 512 byte cache for device blocks
499
+  static uint32_t cacheBlockNumber_;  // Logical number of block in the cache
500
+  static Sd2Card* sdCard_;            // Sd2Card object for cache
501
+  static uint8_t cacheDirty_;         // cacheFlush() will write block if true
502
+  static uint32_t cacheMirrorBlock_;  // block number for mirror FAT
503
+//
504
+  uint32_t allocSearchStart_;   // start cluster for alloc search
505
+  uint8_t blocksPerCluster_;    // cluster size in blocks
506
+  uint32_t blocksPerFat_;       // FAT size in blocks
507
+  uint32_t clusterCount_;       // clusters in one FAT
508
+  uint8_t clusterSizeShift_;    // shift to convert cluster count to block count
509
+  uint32_t dataStartBlock_;     // first data block number
510
+  uint8_t fatCount_;            // number of FATs on volume
511
+  uint32_t fatStartBlock_;      // start block for first FAT
512
+  uint8_t fatType_;             // volume type (12, 16, OR 32)
513
+  uint16_t rootDirEntryCount_;  // number of entries in FAT16 root dir
514
+  uint32_t rootDirStart_;       // root start block for FAT16, cluster for FAT32
515
+  //----------------------------------------------------------------------------
516
+  uint8_t allocContiguous(uint32_t count, uint32_t* curCluster);
517
+  uint8_t blockOfCluster(uint32_t position) const {
518
+          return (position >> 9) & (blocksPerCluster_ - 1);}
519
+  uint32_t clusterStartBlock(uint32_t cluster) const {
520
+           return dataStartBlock_ + ((cluster - 2) << clusterSizeShift_);}
521
+  uint32_t blockNumber(uint32_t cluster, uint32_t position) const {
522
+           return clusterStartBlock(cluster) + blockOfCluster(position);}
523
+  static uint8_t cacheFlush(void);
524
+  static uint8_t cacheRawBlock(uint32_t blockNumber, uint8_t action);
525
+  static void cacheSetDirty(void) {cacheDirty_ |= CACHE_FOR_WRITE;}
526
+  static uint8_t cacheZeroBlock(uint32_t blockNumber);
527
+  uint8_t chainSize(uint32_t beginCluster, uint32_t* size) const;
528
+  uint8_t fatGet(uint32_t cluster, uint32_t* value) const;
529
+  uint8_t fatPut(uint32_t cluster, uint32_t value);
530
+  uint8_t fatPutEOC(uint32_t cluster) {
531
+    return fatPut(cluster, 0x0FFFFFFF);
532
+  }
533
+  uint8_t freeChain(uint32_t cluster);
534
+  uint8_t isEOC(uint32_t cluster) const {
535
+    return  cluster >= (fatType_ == 16 ? FAT16EOC_MIN : FAT32EOC_MIN);
536
+  }
537
+  uint8_t readBlock(uint32_t block, uint8_t* dst) {
538
+    return sdCard_->readBlock(block, dst);}
539
+  uint8_t readData(uint32_t block, uint16_t offset,
540
+    uint16_t count, uint8_t* dst) {
541
+      return sdCard_->readData(block, offset, count, dst);
542
+  }
543
+  uint8_t writeBlock(uint32_t block, const uint8_t* dst) {
544
+    return sdCard_->writeBlock(block, dst);
545
+  }
546
+};
547
+#endif  // SdFat_h

+ 70
- 0
Marlin/SdFatUtil.h View File

@@ -0,0 +1,70 @@
1
+/* Arduino SdFat Library
2
+ * Copyright (C) 2008 by William Greiman
3
+ *
4
+ * This file is part of the Arduino SdFat Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino SdFat Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#ifndef SdFatUtil_h
21
+#define SdFatUtil_h
22
+/**
23
+ * \file
24
+ * Useful utility functions.
25
+ */
26
+#include <WProgram.h>
27
+#include <avr/pgmspace.h>
28
+/** Store and print a string in flash memory.*/
29
+#define PgmPrint(x) SerialPrint_P(PSTR(x))
30
+/** Store and print a string in flash memory followed by a CR/LF.*/
31
+#define PgmPrintln(x) SerialPrintln_P(PSTR(x))
32
+/** Defined so doxygen works for function definitions. */
33
+#define NOINLINE __attribute__((noinline))
34
+//------------------------------------------------------------------------------
35
+/** Return the number of bytes currently free in RAM. */
36
+static int FreeRam(void) {
37
+  extern int  __bss_end;
38
+  extern int* __brkval;
39
+  int free_memory;
40
+  if (reinterpret_cast<int>(__brkval) == 0) {
41
+    // if no heap use from end of bss section
42
+    free_memory = reinterpret_cast<int>(&free_memory)
43
+                  - reinterpret_cast<int>(&__bss_end);
44
+  } else {
45
+    // use from top of stack to heap
46
+    free_memory = reinterpret_cast<int>(&free_memory)
47
+                  - reinterpret_cast<int>(__brkval);
48
+  }
49
+  return free_memory;
50
+}
51
+//------------------------------------------------------------------------------
52
+/**
53
+ * %Print a string in flash memory to the serial port.
54
+ *
55
+ * \param[in] str Pointer to string stored in flash memory.
56
+ */
57
+static NOINLINE void SerialPrint_P(PGM_P str) {
58
+  for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.print(c);
59
+}
60
+//------------------------------------------------------------------------------
61
+/**
62
+ * %Print a string in flash memory followed by a CR/LF.
63
+ *
64
+ * \param[in] str Pointer to string stored in flash memory.
65
+ */
66
+static NOINLINE void SerialPrintln_P(PGM_P str) {
67
+  SerialPrint_P(str);
68
+  Serial.println();
69
+}
70
+#endif  // #define SdFatUtil_h

+ 202
- 0
Marlin/SdFatmainpage.h View File

@@ -0,0 +1,202 @@
1
+/* Arduino SdFat Library
2
+ * Copyright (C) 2009 by William Greiman
3
+ *  
4
+ * This file is part of the Arduino SdFat Library
5
+ *  
6
+ * This Library is free software: you can redistribute it and/or modify 
7
+ * it under the terms of the GNU General Public License as published by 
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ * 
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino SdFat Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+/**
22
+\mainpage Arduino SdFat Library
23
+<CENTER>Copyright &copy; 2009 by William Greiman
24
+</CENTER>
25
+
26
+\section Intro Introduction
27
+The Arduino SdFat Library is a minimal implementation of FAT16 and FAT32
28
+file systems on SD flash memory cards.  Standard SD and high capacity
29
+SDHC cards are supported.
30
+
31
+The SdFat only supports short 8.3 names.
32
+
33
+The main classes in SdFat are Sd2Card, SdVolume, and SdFile.
34
+
35
+The Sd2Card class supports access to standard SD cards and SDHC cards.  Most
36
+applications will only need to call the Sd2Card::init() member function.
37
+
38
+The SdVolume class supports FAT16 and FAT32 partitions.  Most applications
39
+will only need to call the SdVolume::init() member function.
40
+
41
+The SdFile class provides file access functions such as open(), read(),
42
+remove(), write(), close() and sync(). This class supports access to the root
43
+directory and subdirectories.
44
+
45
+A number of example are provided in the SdFat/examples folder.  These were
46
+developed to test SdFat and illustrate its use.
47
+
48
+SdFat was developed for high speed data recording.  SdFat was used to implement
49
+an audio record/play class, WaveRP, for the Adafruit Wave Shield.  This
50
+application uses special Sd2Card calls to write to contiguous files in raw mode.
51
+These functions reduce write latency so that audio can be recorded with the
52
+small amount of RAM in the Arduino.
53
+
54
+\section SDcard SD\SDHC Cards
55
+
56
+Arduinos access SD cards using the cards SPI protocol.  PCs, Macs, and
57
+most consumer devices use the 4-bit parallel SD protocol.  A card that
58
+functions well on A PC or Mac may not work well on the Arduino.
59
+
60
+Most cards have good SPI read performance but cards vary widely in SPI
61
+write performance.  Write performance is limited by how efficiently the
62
+card manages internal erase/remapping operations.  The Arduino cannot
63
+optimize writes to reduce erase operations because of its limit RAM.
64
+
65
+SanDisk cards generally have good write performance.  They seem to have
66
+more internal RAM buffering than other cards and therefore can limit
67
+the number of flash erase operations that the Arduino forces due to its
68
+limited RAM.
69
+
70
+\section Hardware Hardware Configuration
71
+
72
+SdFat was developed using an
73
+<A HREF = "http://www.adafruit.com/"> Adafruit Industries</A> 
74
+<A HREF = "http://www.ladyada.net/make/waveshield/"> Wave Shield</A>.
75
+
76
+The hardware interface to the SD card should not use a resistor based level
77
+shifter.  SdFat sets the SPI bus frequency to 8 MHz which results in signal
78
+rise times that are too slow for the edge detectors in many newer SD card
79
+controllers when resistor voltage dividers are used.
80
+
81
+The 5 to 3.3 V level shifter for 5 V Arduinos should be IC based like the
82
+74HC4050N based circuit shown in the file SdLevel.png.  The Adafruit Wave Shield
83
+uses a 74AHC125N.  Gravitech sells SD and MicroSD Card Adapters based on the
84
+74LCX245.
85
+
86
+If you are using a resistor based level shifter and are having problems try
87
+setting the SPI bus frequency to 4 MHz.  This can be done by using 
88
+card.init(SPI_HALF_SPEED) to initialize the SD card.
89
+
90
+\section comment Bugs and Comments
91
+
92
+If you wish to report bugs or have comments, send email to fat16lib@sbcglobal.net.
93
+
94
+\section SdFatClass SdFat Usage
95
+
96
+SdFat uses a slightly restricted form of short names.
97
+Only printable ASCII characters are supported. No characters with code point
98
+values greater than 127 are allowed.  Space is not allowed even though space
99
+was allowed in the API of early versions of DOS.
100
+
101
+Short names are limited to 8 characters followed by an optional period (.)
102
+and extension of up to 3 characters.  The characters may be any combination
103
+of letters and digits.  The following special characters are also allowed:
104
+
105
+$ % ' - _ @ ~ ` ! ( ) { } ^ # &
106
+
107
+Short names are always converted to upper case and their original case
108
+value is lost.
109
+
110
+\note
111
+  The Arduino Print class uses character
112
+at a time writes so it was necessary to use a \link SdFile::sync() sync() \endlink
113
+function to control when data is written to the SD card.
114
+
115
+\par
116
+An application which writes to a file using \link Print::print() print()\endlink,
117
+\link Print::println() println() \endlink
118
+or \link SdFile::write write() \endlink must call \link SdFile::sync() sync() \endlink
119
+at the appropriate time to force data and directory information to be written
120
+to the SD Card.  Data and directory information are also written to the SD card
121
+when \link SdFile::close() close() \endlink is called.
122
+
123
+\par
124
+Applications must use care calling \link SdFile::sync() sync() \endlink
125
+since 2048 bytes of I/O is required to update file and
126
+directory information.  This includes writing the current data block, reading
127
+the block that contains the directory entry for update, writing the directory
128
+block back and reading back the current data block.
129
+
130
+It is possible to open a file with two or more instances of SdFile.  A file may
131
+be corrupted if data is written to the file by more than one instance of SdFile.
132
+
133
+\section HowTo How to format SD Cards as FAT Volumes
134
+
135
+You should use a freshly formatted SD card for best performance.  FAT
136
+file systems become slower if many files have been created and deleted.
137
+This is because the directory entry for a deleted file is marked as deleted,
138
+but is not deleted.  When a new file is created, these entries must be scanned
139
+before creating the file, a flaw in the FAT design.  Also files can become
140
+fragmented which causes reads and writes to be slower.
141
+
142
+Microsoft operating systems support removable media formatted with a
143
+Master Boot Record, MBR, or formatted as a super floppy with a FAT Boot Sector
144
+in block zero.
145
+
146
+Microsoft operating systems expect MBR formatted removable media
147
+to have only one partition. The first partition should be used.
148
+
149
+Microsoft operating systems do not support partitioning SD flash cards.
150
+If you erase an SD card with a program like KillDisk, Most versions of
151
+Windows will format the card as a super floppy.
152
+
153
+The best way to restore an SD card's format is to use SDFormatter
154
+which can be downloaded from:
155
+
156
+http://www.sdcard.org/consumers/formatter/
157
+
158
+SDFormatter aligns flash erase boundaries with file
159
+system structures which reduces write latency and file system overhead.
160
+
161
+SDFormatter does not have an option for FAT type so it may format
162
+small cards as FAT12.
163
+
164
+After the MBR is restored by SDFormatter you may need to reformat small
165
+cards that have been formatted FAT12 to force the volume type to be FAT16.
166
+
167
+If you reformat the SD card with an OS utility, choose a cluster size that
168
+will result in:
169
+
170
+4084 < CountOfClusters && CountOfClusters < 65525
171
+
172
+The volume will then be FAT16.
173
+
174
+If you are formatting an SD card on OS X or Linux, be sure to use the first
175
+partition. Format this partition with a cluster count in above range.
176
+
177
+\section  References References
178
+
179
+Adafruit Industries:
180
+
181
+http://www.adafruit.com/
182
+
183
+http://www.ladyada.net/make/waveshield/
184
+
185
+The Arduino site:
186
+
187
+http://www.arduino.cc/
188
+
189
+For more information about FAT file systems see:
190
+
191
+http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
192
+
193
+For information about using SD cards as SPI devices see:
194
+
195
+http://www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf
196
+
197
+The ATmega328 datasheet:
198
+
199
+http://www.atmel.com/dyn/resources/prod_documents/doc8161.pdf
200
+ 
201
+
202
+ */  

+ 1252
- 0
Marlin/SdFile.cpp
File diff suppressed because it is too large
View File


+ 232
- 0
Marlin/SdInfo.h View File

@@ -0,0 +1,232 @@
1
+/* Arduino Sd2Card Library
2
+ * Copyright (C) 2009 by William Greiman
3
+ *
4
+ * This file is part of the Arduino Sd2Card Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino Sd2Card Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#ifndef SdInfo_h
21
+#define SdInfo_h
22
+#include <stdint.h>
23
+// Based on the document:
24
+//
25
+// SD Specifications
26
+// Part 1
27
+// Physical Layer
28
+// Simplified Specification
29
+// Version 2.00
30
+// September 25, 2006
31
+//
32
+// www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf
33
+//------------------------------------------------------------------------------
34
+// SD card commands
35
+/** GO_IDLE_STATE - init card in spi mode if CS low */
36
+uint8_t const CMD0 = 0X00;
37
+/** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
38
+uint8_t const CMD8 = 0X08;
39
+/** SEND_CSD - read the Card Specific Data (CSD register) */
40
+uint8_t const CMD9 = 0X09;
41
+/** SEND_CID - read the card identification information (CID register) */
42
+uint8_t const CMD10 = 0X0A;
43
+/** SEND_STATUS - read the card status register */
44
+uint8_t const CMD13 = 0X0D;
45
+/** READ_BLOCK - read a single data block from the card */
46
+uint8_t const CMD17 = 0X11;
47
+/** WRITE_BLOCK - write a single data block to the card */
48
+uint8_t const CMD24 = 0X18;
49
+/** WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION */
50
+uint8_t const CMD25 = 0X19;
51
+/** ERASE_WR_BLK_START - sets the address of the first block to be erased */
52
+uint8_t const CMD32 = 0X20;
53
+/** ERASE_WR_BLK_END - sets the address of the last block of the continuous
54
+    range to be erased*/
55
+uint8_t const CMD33 = 0X21;
56
+/** ERASE - erase all previously selected blocks */
57
+uint8_t const CMD38 = 0X26;
58
+/** APP_CMD - escape for application specific command */
59
+uint8_t const CMD55 = 0X37;
60
+/** READ_OCR - read the OCR register of a card */
61
+uint8_t const CMD58 = 0X3A;
62
+/** SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be
63
+     pre-erased before writing */
64
+uint8_t const ACMD23 = 0X17;
65
+/** SD_SEND_OP_COMD - Sends host capacity support information and
66
+    activates the card's initialization process */
67
+uint8_t const ACMD41 = 0X29;
68
+//------------------------------------------------------------------------------
69
+/** status for card in the ready state */
70
+uint8_t const R1_READY_STATE = 0X00;
71
+/** status for card in the idle state */
72
+uint8_t const R1_IDLE_STATE = 0X01;
73
+/** status bit for illegal command */
74
+uint8_t const R1_ILLEGAL_COMMAND = 0X04;
75
+/** start data token for read or write single block*/
76
+uint8_t const DATA_START_BLOCK = 0XFE;
77
+/** stop token for write multiple blocks*/
78
+uint8_t const STOP_TRAN_TOKEN = 0XFD;
79
+/** start data token for write multiple blocks*/
80
+uint8_t const WRITE_MULTIPLE_TOKEN = 0XFC;
81
+/** mask for data response tokens after a write block operation */
82
+uint8_t const DATA_RES_MASK = 0X1F;
83
+/** write data accepted token */
84
+uint8_t const DATA_RES_ACCEPTED = 0X05;
85
+//------------------------------------------------------------------------------
86
+typedef struct CID {
87
+  // byte 0
88
+  uint8_t mid;  // Manufacturer ID
89
+  // byte 1-2
90
+  char oid[2];  // OEM/Application ID
91
+  // byte 3-7
92
+  char pnm[5];  // Product name
93
+  // byte 8
94
+  unsigned prv_m : 4;  // Product revision n.m
95
+  unsigned prv_n : 4;
96
+  // byte 9-12
97
+  uint32_t psn;  // Product serial number
98
+  // byte 13
99
+  unsigned mdt_year_high : 4;  // Manufacturing date
100
+  unsigned reserved : 4;
101
+  // byte 14
102
+  unsigned mdt_month : 4;
103
+  unsigned mdt_year_low :4;
104
+  // byte 15
105
+  unsigned always1 : 1;
106
+  unsigned crc : 7;
107
+}cid_t;
108
+//------------------------------------------------------------------------------
109
+// CSD for version 1.00 cards
110
+typedef struct CSDV1 {
111
+  // byte 0
112
+  unsigned reserved1 : 6;
113
+  unsigned csd_ver : 2;
114
+  // byte 1
115
+  uint8_t taac;
116
+  // byte 2
117
+  uint8_t nsac;
118
+  // byte 3
119
+  uint8_t tran_speed;
120
+  // byte 4
121
+  uint8_t ccc_high;
122
+  // byte 5
123
+  unsigned read_bl_len : 4;
124
+  unsigned ccc_low : 4;
125
+  // byte 6
126
+  unsigned c_size_high : 2;
127
+  unsigned reserved2 : 2;
128
+  unsigned dsr_imp : 1;
129
+  unsigned read_blk_misalign :1;
130
+  unsigned write_blk_misalign : 1;
131
+  unsigned read_bl_partial : 1;
132
+  // byte 7
133
+  uint8_t c_size_mid;
134
+  // byte 8
135
+  unsigned vdd_r_curr_max : 3;
136
+  unsigned vdd_r_curr_min : 3;
137
+  unsigned c_size_low :2;
138
+  // byte 9
139
+  unsigned c_size_mult_high : 2;
140
+  unsigned vdd_w_cur_max : 3;
141
+  unsigned vdd_w_curr_min : 3;
142
+  // byte 10
143
+  unsigned sector_size_high : 6;
144
+  unsigned erase_blk_en : 1;
145
+  unsigned c_size_mult_low : 1;
146
+  // byte 11
147
+  unsigned wp_grp_size : 7;
148
+  unsigned sector_size_low : 1;
149
+  // byte 12
150
+  unsigned write_bl_len_high : 2;
151
+  unsigned r2w_factor : 3;
152
+  unsigned reserved3 : 2;
153
+  unsigned wp_grp_enable : 1;
154
+  // byte 13
155
+  unsigned reserved4 : 5;
156
+  unsigned write_partial : 1;
157
+  unsigned write_bl_len_low : 2;
158
+  // byte 14
159
+  unsigned reserved5: 2;
160
+  unsigned file_format : 2;
161
+  unsigned tmp_write_protect : 1;
162
+  unsigned perm_write_protect : 1;
163
+  unsigned copy : 1;
164
+  unsigned file_format_grp : 1;
165
+  // byte 15
166
+  unsigned always1 : 1;
167
+  unsigned crc : 7;
168
+}csd1_t;
169
+//------------------------------------------------------------------------------
170
+// CSD for version 2.00 cards
171
+typedef struct CSDV2 {
172
+  // byte 0
173
+  unsigned reserved1 : 6;
174
+  unsigned csd_ver : 2;
175
+  // byte 1
176
+  uint8_t taac;
177
+  // byte 2
178
+  uint8_t nsac;
179
+  // byte 3
180
+  uint8_t tran_speed;
181
+  // byte 4
182
+  uint8_t ccc_high;
183
+  // byte 5
184
+  unsigned read_bl_len : 4;
185
+  unsigned ccc_low : 4;
186
+  // byte 6
187
+  unsigned reserved2 : 4;
188
+  unsigned dsr_imp : 1;
189
+  unsigned read_blk_misalign :1;
190
+  unsigned write_blk_misalign : 1;
191
+  unsigned read_bl_partial : 1;
192
+  // byte 7
193
+  unsigned reserved3 : 2;
194
+  unsigned c_size_high : 6;
195
+  // byte 8
196
+  uint8_t c_size_mid;
197
+  // byte 9
198
+  uint8_t c_size_low;
199
+  // byte 10
200
+  unsigned sector_size_high : 6;
201
+  unsigned erase_blk_en : 1;
202
+  unsigned reserved4 : 1;
203
+  // byte 11
204
+  unsigned wp_grp_size : 7;
205
+  unsigned sector_size_low : 1;
206
+  // byte 12
207
+  unsigned write_bl_len_high : 2;
208
+  unsigned r2w_factor : 3;
209
+  unsigned reserved5 : 2;
210
+  unsigned wp_grp_enable : 1;
211
+  // byte 13
212
+  unsigned reserved6 : 5;
213
+  unsigned write_partial : 1;
214
+  unsigned write_bl_len_low : 2;
215
+  // byte 14
216
+  unsigned reserved7: 2;
217
+  unsigned file_format : 2;
218
+  unsigned tmp_write_protect : 1;
219
+  unsigned perm_write_protect : 1;
220
+  unsigned copy : 1;
221
+  unsigned file_format_grp : 1;
222
+  // byte 15
223
+  unsigned always1 : 1;
224
+  unsigned crc : 7;
225
+}csd2_t;
226
+//------------------------------------------------------------------------------
227
+// union of old and new style CSD register
228
+union csd_t {
229
+  csd1_t v1;
230
+  csd2_t v2;
231
+};
232
+#endif  // SdInfo_h

+ 295
- 0
Marlin/SdVolume.cpp View File

@@ -0,0 +1,295 @@
1
+/* Arduino SdFat Library
2
+ * Copyright (C) 2009 by William Greiman
3
+ *
4
+ * This file is part of the Arduino SdFat Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino SdFat Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#include "SdFat.h"
21
+//------------------------------------------------------------------------------
22
+// raw block cache
23
+// init cacheBlockNumber_to invalid SD block number
24
+uint32_t SdVolume::cacheBlockNumber_ = 0XFFFFFFFF;
25
+cache_t  SdVolume::cacheBuffer_;     // 512 byte cache for Sd2Card
26
+Sd2Card* SdVolume::sdCard_;          // pointer to SD card object
27
+uint8_t  SdVolume::cacheDirty_ = 0;  // cacheFlush() will write block if true
28
+uint32_t SdVolume::cacheMirrorBlock_ = 0;  // mirror  block for second FAT
29
+//------------------------------------------------------------------------------
30
+// find a contiguous group of clusters
31
+uint8_t SdVolume::allocContiguous(uint32_t count, uint32_t* curCluster) {
32
+  // start of group
33
+  uint32_t bgnCluster;
34
+
35
+  // flag to save place to start next search
36
+  uint8_t setStart;
37
+
38
+  // set search start cluster
39
+  if (*curCluster) {
40
+    // try to make file contiguous
41
+    bgnCluster = *curCluster + 1;
42
+
43
+    // don't save new start location
44
+    setStart = false;
45
+  } else {
46
+    // start at likely place for free cluster
47
+    bgnCluster = allocSearchStart_;
48
+
49
+    // save next search start if one cluster
50
+    setStart = 1 == count;
51
+  }
52
+  // end of group
53
+  uint32_t endCluster = bgnCluster;
54
+
55
+  // last cluster of FAT
56
+  uint32_t fatEnd = clusterCount_ + 1;
57
+
58
+  // search the FAT for free clusters
59
+  for (uint32_t n = 0;; n++, endCluster++) {
60
+    // can't find space checked all clusters
61
+    if (n >= clusterCount_) return false;
62
+
63
+    // past end - start from beginning of FAT
64
+    if (endCluster > fatEnd) {
65
+      bgnCluster = endCluster = 2;
66
+    }
67
+    uint32_t f;
68
+    if (!fatGet(endCluster, &f)) return false;
69
+
70
+    if (f != 0) {
71
+      // cluster in use try next cluster as bgnCluster
72
+      bgnCluster = endCluster + 1;
73
+    } else if ((endCluster - bgnCluster + 1) == count) {
74
+      // done - found space
75
+      break;
76
+    }
77
+  }
78
+  // mark end of chain
79
+  if (!fatPutEOC(endCluster)) return false;
80
+
81
+  // link clusters
82
+  while (endCluster > bgnCluster) {
83
+    if (!fatPut(endCluster - 1, endCluster)) return false;
84
+    endCluster--;
85
+  }
86
+  if (*curCluster != 0) {
87
+    // connect chains
88
+    if (!fatPut(*curCluster, bgnCluster)) return false;
89
+  }
90
+  // return first cluster number to caller
91
+  *curCluster = bgnCluster;
92
+
93
+  // remember possible next free cluster
94
+  if (setStart) allocSearchStart_ = bgnCluster + 1;
95
+
96
+  return true;
97
+}
98
+//------------------------------------------------------------------------------
99
+uint8_t SdVolume::cacheFlush(void) {
100
+  if (cacheDirty_) {
101
+    if (!sdCard_->writeBlock(cacheBlockNumber_, cacheBuffer_.data)) {
102
+      return false;
103
+    }
104
+    // mirror FAT tables
105
+    if (cacheMirrorBlock_) {
106
+      if (!sdCard_->writeBlock(cacheMirrorBlock_, cacheBuffer_.data)) {
107
+        return false;
108
+      }
109
+      cacheMirrorBlock_ = 0;
110
+    }
111
+    cacheDirty_ = 0;
112
+  }
113
+  return true;
114
+}
115
+//------------------------------------------------------------------------------
116
+uint8_t SdVolume::cacheRawBlock(uint32_t blockNumber, uint8_t action) {
117
+  if (cacheBlockNumber_ != blockNumber) {
118
+    if (!cacheFlush()) return false;
119
+    if (!sdCard_->readBlock(blockNumber, cacheBuffer_.data)) return false;
120
+    cacheBlockNumber_ = blockNumber;
121
+  }
122
+  cacheDirty_ |= action;
123
+  return true;
124
+}
125
+//------------------------------------------------------------------------------
126
+// cache a zero block for blockNumber
127
+uint8_t SdVolume::cacheZeroBlock(uint32_t blockNumber) {
128
+  if (!cacheFlush()) return false;
129
+
130
+  // loop take less flash than memset(cacheBuffer_.data, 0, 512);
131
+  for (uint16_t i = 0; i < 512; i++) {
132
+    cacheBuffer_.data[i] = 0;
133
+  }
134
+  cacheBlockNumber_ = blockNumber;
135
+  cacheSetDirty();
136
+  return true;
137
+}
138
+//------------------------------------------------------------------------------
139
+// return the size in bytes of a cluster chain
140
+uint8_t SdVolume::chainSize(uint32_t cluster, uint32_t* size) const {
141
+  uint32_t s = 0;
142
+  do {
143
+    if (!fatGet(cluster, &cluster)) return false;
144
+    s += 512UL << clusterSizeShift_;
145
+  } while (!isEOC(cluster));
146
+  *size = s;
147
+  return true;
148
+}
149
+//------------------------------------------------------------------------------
150
+// Fetch a FAT entry
151
+uint8_t SdVolume::fatGet(uint32_t cluster, uint32_t* value) const {
152
+  if (cluster > (clusterCount_ + 1)) return false;
153
+  uint32_t lba = fatStartBlock_;
154
+  lba += fatType_ == 16 ? cluster >> 8 : cluster >> 7;
155
+  if (lba != cacheBlockNumber_) {
156
+    if (!cacheRawBlock(lba, CACHE_FOR_READ)) return false;
157
+  }
158
+  if (fatType_ == 16) {
159
+    *value = cacheBuffer_.fat16[cluster & 0XFF];
160
+  } else {
161
+    *value = cacheBuffer_.fat32[cluster & 0X7F] & FAT32MASK;
162
+  }
163
+  return true;
164
+}
165
+//------------------------------------------------------------------------------
166
+// Store a FAT entry
167
+uint8_t SdVolume::fatPut(uint32_t cluster, uint32_t value) {
168
+  // error if reserved cluster
169
+  if (cluster < 2) return false;
170
+
171
+  // error if not in FAT
172
+  if (cluster > (clusterCount_ + 1)) return false;
173
+
174
+  // calculate block address for entry
175
+  uint32_t lba = fatStartBlock_;
176
+  lba += fatType_ == 16 ? cluster >> 8 : cluster >> 7;
177
+
178
+  if (lba != cacheBlockNumber_) {
179
+    if (!cacheRawBlock(lba, CACHE_FOR_READ)) return false;
180
+  }
181
+  // store entry
182
+  if (fatType_ == 16) {
183
+    cacheBuffer_.fat16[cluster & 0XFF] = value;
184
+  } else {
185
+    cacheBuffer_.fat32[cluster & 0X7F] = value;
186
+  }
187
+  cacheSetDirty();
188
+
189
+  // mirror second FAT
190
+  if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
191
+  return true;
192
+}
193
+//------------------------------------------------------------------------------
194
+// free a cluster chain
195
+uint8_t SdVolume::freeChain(uint32_t cluster) {
196
+  // clear free cluster location
197
+  allocSearchStart_ = 2;
198
+
199
+  do {
200
+    uint32_t next;
201
+    if (!fatGet(cluster, &next)) return false;
202
+
203
+    // free cluster
204
+    if (!fatPut(cluster, 0)) return false;
205
+
206
+    cluster = next;
207
+  } while (!isEOC(cluster));
208
+
209
+  return true;
210
+}
211
+//------------------------------------------------------------------------------
212
+/**
213
+ * Initialize a FAT volume.
214
+ *
215
+ * \param[in] dev The SD card where the volume is located.
216
+ *
217
+ * \param[in] part The partition to be used.  Legal values for \a part are
218
+ * 1-4 to use the corresponding partition on a device formatted with
219
+ * a MBR, Master Boot Record, or zero if the device is formatted as
220
+ * a super floppy with the FAT boot sector in block zero.
221
+ *
222
+ * \return The value one, true, is returned for success and
223
+ * the value zero, false, is returned for failure.  Reasons for
224
+ * failure include not finding a valid partition, not finding a valid
225
+ * FAT file system in the specified partition or an I/O error.
226
+ */
227
+uint8_t SdVolume::init(Sd2Card* dev, uint8_t part) {
228
+  uint32_t volumeStartBlock = 0;
229
+  sdCard_ = dev;
230
+  // if part == 0 assume super floppy with FAT boot sector in block zero
231
+  // if part > 0 assume mbr volume with partition table
232
+  if (part) {
233
+    if (part > 4)return false;
234
+    if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) return false;
235
+    part_t* p = &cacheBuffer_.mbr.part[part-1];
236
+    if ((p->boot & 0X7F) !=0  ||
237
+      p->totalSectors < 100 ||
238
+      p->firstSector == 0) {
239
+      // not a valid partition
240
+      return false;
241
+    }
242
+    volumeStartBlock = p->firstSector;
243
+  }
244
+  if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) return false;
245
+  bpb_t* bpb = &cacheBuffer_.fbs.bpb;
246
+  if (bpb->bytesPerSector != 512 ||
247
+    bpb->fatCount == 0 ||
248
+    bpb->reservedSectorCount == 0 ||
249
+    bpb->sectorsPerCluster == 0) {
250
+       // not valid FAT volume
251
+      return false;
252
+  }
253
+  fatCount_ = bpb->fatCount;
254
+  blocksPerCluster_ = bpb->sectorsPerCluster;
255
+
256
+  // determine shift that is same as multiply by blocksPerCluster_
257
+  clusterSizeShift_ = 0;
258
+  while (blocksPerCluster_ != (1 << clusterSizeShift_)) {
259
+    // error if not power of 2
260
+    if (clusterSizeShift_++ > 7) return false;
261
+  }
262
+  blocksPerFat_ = bpb->sectorsPerFat16 ?
263
+                    bpb->sectorsPerFat16 : bpb->sectorsPerFat32;
264
+
265
+  fatStartBlock_ = volumeStartBlock + bpb->reservedSectorCount;
266
+
267
+  // count for FAT16 zero for FAT32
268
+  rootDirEntryCount_ = bpb->rootDirEntryCount;
269
+
270
+  // directory start for FAT16 dataStart for FAT32
271
+  rootDirStart_ = fatStartBlock_ + bpb->fatCount * blocksPerFat_;
272
+
273
+  // data start for FAT16 and FAT32
274
+  dataStartBlock_ = rootDirStart_ + ((32 * bpb->rootDirEntryCount + 511)/512);
275
+
276
+  // total blocks for FAT16 or FAT32
277
+  uint32_t totalBlocks = bpb->totalSectors16 ?
278
+                           bpb->totalSectors16 : bpb->totalSectors32;
279
+  // total data blocks
280
+  clusterCount_ = totalBlocks - (dataStartBlock_ - volumeStartBlock);
281
+
282
+  // divide by cluster size to get cluster count
283
+  clusterCount_ >>= clusterSizeShift_;
284
+
285
+  // FAT type is determined by cluster count
286
+  if (clusterCount_ < 4085) {
287
+    fatType_ = 12;
288
+  } else if (clusterCount_ < 65525) {
289
+    fatType_ = 16;
290
+  } else {
291
+    rootDirStart_ = bpb->fat32RootCluster;
292
+    fatType_ = 32;
293
+  }
294
+  return true;
295
+}

+ 2050
- 0
Marlin/applet/Marlin.cpp
File diff suppressed because it is too large
View File


+ 127
- 0
Marlin/createTemperatureLookup.py View File

@@ -0,0 +1,127 @@
1
+#!/usr/bin/python
2
+#
3
+# Creates a C code lookup table for doing ADC to temperature conversion
4
+# on a microcontroller
5
+# based on: http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html
6
+"""Thermistor Value Lookup Table Generator
7
+
8
+Generates lookup to temperature values for use in a microcontroller in C format based on: 
9
+http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html
10
+
11
+The main use is for Arduino programs that read data from the circuit board described here:
12
+http://make.rrrf.org/ts-1.0
13
+
14
+Usage: python createTemperatureLookup.py [options]
15
+
16
+Options:
17
+  -h, --help            show this help
18
+  --r0=...          thermistor rating where # is the ohm rating of the thermistor at t0 (eg: 10K = 10000)
19
+  --t0=...          thermistor temp rating where # is the temperature in Celsuis to get r0 (from your datasheet)
20
+  --beta=...            thermistor beta rating. see http://reprap.org/bin/view/Main/MeasuringThermistorBeta
21
+  --r1=...          R1 rating where # is the ohm rating of R1 (eg: 10K = 10000)
22
+  --r2=...          R2 rating where # is the ohm rating of R2 (eg: 10K = 10000)
23
+  --num-temps=...   the number of temperature points to calculate (default: 20)
24
+  --max-adc=...     the max ADC reading to use.  if you use R1, it limits the top value for the thermistor circuit, and thus the possible range of ADC values
25
+"""
26
+
27
+from math import *
28
+import sys
29
+import getopt
30
+
31
+class Thermistor:
32
+    "Class to do the thermistor maths"
33
+    def __init__(self, r0, t0, beta, r1, r2):
34
+        self.r0 = r0                        # stated resistance, e.g. 10K
35
+        self.t0 = t0 + 273.15               # temperature at stated resistance, e.g. 25C
36
+        self.beta = beta                    # stated beta, e.g. 3500
37
+        self.vadc = 5.0                     # ADC reference
38
+        self.vcc = 5.0                      # supply voltage to potential divider
39
+        self.k = r0 * exp(-beta / self.t0)   # constant part of calculation
40
+
41
+        if r1 > 0:
42
+            self.vs = r1 * self.vcc / (r1 + r2) # effective bias voltage
43
+            self.rs = r1 * r2 / (r1 + r2)       # effective bias impedance
44
+        else:
45
+            self.vs = self.vcc                   # effective bias voltage
46
+            self.rs = r2                         # effective bias impedance
47
+
48
+    def temp(self,adc):
49
+        "Convert ADC reading into a temperature in Celcius"
50
+        v = adc * self.vadc / 1024          # convert the 10 bit ADC value to a voltage
51
+        r = self.rs * v / (self.vs - v)     # resistance of thermistor
52
+        return (self.beta / log(r / self.k)) - 273.15        # temperature
53
+
54
+    def setting(self, t):
55
+        "Convert a temperature into a ADC value"
56
+        r = self.r0 * exp(self.beta * (1 / (t + 273.15) - 1 / self.t0)) # resistance of the thermistor
57
+        v = self.vs * r / (self.rs + r)     # the voltage at the potential divider
58
+        return round(v / self.vadc * 1024)  # the ADC reading
59
+
60
+def main(argv):
61
+
62
+    r0 = 10000;
63
+    t0 = 25;
64
+    beta = 3947;
65
+    r1 = 680;
66
+    r2 = 1600;
67
+    num_temps = int(20);
68
+    
69
+    try:
70
+        opts, args = getopt.getopt(argv, "h", ["help", "r0=", "t0=", "beta=", "r1=", "r2="])
71
+    except getopt.GetoptError:
72
+        usage()
73
+        sys.exit(2)
74
+        
75
+    for opt, arg in opts:
76
+        if opt in ("-h", "--help"):
77
+            usage()
78
+            sys.exit()
79
+        elif opt == "--r0":
80
+            r0 = int(arg)
81
+        elif opt == "--t0":
82
+            t0 = int(arg)
83
+        elif opt == "--beta":
84
+            beta = int(arg)
85
+        elif opt == "--r1":
86
+            r1 = int(arg)
87
+        elif opt == "--r2":
88
+            r2 = int(arg)
89
+
90
+    if r1:
91
+        max_adc = int(1023 * r1 / (r1 + r2));
92
+    else:
93
+        max_adc = 1023
94
+    increment = int(max_adc/(num_temps-1));
95
+            
96
+    t = Thermistor(r0, t0, beta, r1, r2)
97
+
98
+    adcs = range(1, max_adc, increment);
99
+#   adcs = [1, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 110, 130, 150, 190, 220,  250, 300]
100
+    first = 1
101
+
102
+    print "// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts)"
103
+    print "// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py)"
104
+    print "// ./createTemperatureLookup.py --r0=%s --t0=%s --r1=%s --r2=%s --beta=%s --max-adc=%s" % (r0, t0, r1, r2, beta, max_adc)
105
+    print "// r0: %s" % (r0)
106
+    print "// t0: %s" % (t0)
107
+    print "// r1: %s" % (r1)
108
+    print "// r2: %s" % (r2)
109
+    print "// beta: %s" % (beta)
110
+    print "// max adc: %s" % (max_adc)
111
+    print "#define NUMTEMPS %s" % (len(adcs))
112
+    print "short temptable[NUMTEMPS][2] = {"
113
+
114
+    counter = 0
115
+    for adc in adcs:
116
+        counter = counter +1
117
+        if counter == len(adcs):
118
+            print "   {%s, %s}" % (adc, int(t.temp(adc)))
119
+        else:
120
+            print "   {%s, %s}," % (adc, int(t.temp(adc)))
121
+    print "};"
122
+    
123
+def usage():
124
+    print __doc__
125
+
126
+if __name__ == "__main__":
127
+    main(sys.argv[1:])

+ 2558
- 0
Marlin/fastio.h
File diff suppressed because it is too large
View File


+ 494
- 0
Marlin/pins.h View File

@@ -0,0 +1,494 @@
1
+#ifndef PINS_H
2
+#define PINS_H
3
+
4
+/****************************************************************************************
5
+* Arduino pin assignment
6
+*
7
+*                  ATMega168
8
+*                   +-\/-+
9
+*             PC6  1|    |28  PC5 (AI 5 / D19)
10
+*       (D 0) PD0  2|    |27  PC4 (AI 4 / D18)
11
+*       (D 1) PD1  3|    |26  PC3 (AI 3 / D17)
12
+*       (D 2) PD2  4|    |25  PC2 (AI 2 / D16)
13
+*  PWM+ (D 3) PD3  5|    |24  PC1 (AI 1 / D15)
14
+*       (D 4) PD4  6|    |23  PC0 (AI 0 / D14)
15
+*             VCC  7|    |22  GND
16
+*             GND  8|    |21  AREF
17
+*             PB6  9|    |20  AVCC
18
+*             PB7 10|    |19  PB5 (D 13)
19
+*  PWM+ (D 5) PD5 11|    |18  PB4 (D 12)
20
+*  PWM+ (D 6) PD6 12|    |17  PB3 (D 11) PWM
21
+*       (D 7) PD7 13|    |16  PB2 (D 10) PWM
22
+*       (D 8) PB0 14|    |15  PB1 (D 9)  PWM
23
+*                   +----+
24
+****************************************************************************************/
25
+#if MOTHERBOARD == 0
26
+#define KNOWN_BOARD 1
27
+
28
+#ifndef __AVR_ATmega168__
29
+#error Oops!  Make sure you have 'Arduino Diecimila' selected from the boards menu.
30
+#endif
31
+
32
+#define X_STEP_PIN          2
33
+#define X_DIR_PIN           3
34
+#define X_ENABLE_PIN       -1
35
+#define X_MIN_PIN           4
36
+#define X_MAX_PIN           9
37
+
38
+#define Y_STEP_PIN         10
39
+#define Y_DIR_PIN           7
40
+#define Y_ENABLE_PIN       -1
41
+#define Y_MIN_PIN           8
42
+#define Y_MAX_PIN          13
43
+
44
+#define Z_STEP_PIN         19
45
+#define Z_DIR_PIN          18
46
+#define Z_ENABLE_PIN        5
47
+#define Z_MIN_PIN          17
48
+#define Z_MAX_PIN          16
49
+
50
+#define E_STEP_PIN         11
51
+#define E_DIR_PIN          12
52
+#define E_ENABLE_PIN       -1
53
+
54
+#define SDPOWER          -1
55
+#define SDSS          -1
56
+#define LED_PIN            -1
57
+#define FAN_PIN            -1
58
+#define PS_ON_PIN          15
59
+#define KILL_PIN           -1
60
+
61
+#define HEATER_0_PIN        6
62
+#define TEMP_0_PIN          0    // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
63
+
64
+
65
+#endif
66
+
67
+
68
+
69
+/****************************************************************************************
70
+* Sanguino/RepRap Motherboard with direct-drive extruders
71
+*
72
+*                        ATMega644P
73
+*
74
+*                        +---\/---+
75
+*            (D 0) PB0  1|        |40  PA0 (AI 0 / D31)
76
+*            (D 1) PB1  2|        |39  PA1 (AI 1 / D30)
77
+*       INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D29)
78
+*        PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D28)
79
+*        PWM (D 4) PB4  5|        |36  PA4 (AI 4 / D27)
80
+*       MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D26)
81
+*       MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D25)
82
+*        SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D24)
83
+*                  RST  9|        |32  AREF
84
+*                  VCC 10|        |31  GND 
85
+*                  GND 11|        |30  AVCC
86
+*                XTAL2 12|        |29  PC7 (D 23)
87
+*                XTAL1 13|        |28  PC6 (D 22)
88
+*       RX0 (D 8)  PD0 14|        |27  PC5 (D 21) TDI
89
+*       TX0 (D 9)  PD1 15|        |26  PC4 (D 20) TDO
90
+*  INT0 RX1 (D 10) PD2 16|        |25  PC3 (D 19) TMS
91
+*  INT1 TX1 (D 11) PD3 17|        |24  PC2 (D 18) TCK
92
+*       PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA
93
+*       PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL
94
+*       PWM (D 14) PD6 20|        |21  PD7 (D 15) PWM
95
+*                        +--------+
96
+*
97
+****************************************************************************************/
98
+#if MOTHERBOARD == 1
99
+#define KNOWN_BOARD 1
100
+
101
+#ifndef __AVR_ATmega644P__
102
+#error Oops!  Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu.
103
+#endif
104
+
105
+#define X_STEP_PIN         15
106
+#define X_DIR_PIN          18
107
+#define X_ENABLE_PIN       19
108
+#define X_MIN_PIN          20
109
+#define X_MAX_PIN          21
110
+
111
+#define Y_STEP_PIN         23
112
+#define Y_DIR_PIN          22
113
+#define Y_ENABLE_PIN       19
114
+#define Y_MIN_PIN          25
115
+#define Y_MAX_PIN          26
116
+
117
+#define Z_STEP_PIN         29
118
+#define Z_DIR_PIN          30
119
+#define Z_ENABLE_PIN       31
120
+#define Z_MIN_PIN           2
121
+#define Z_MAX_PIN           1
122
+
123
+#define E_STEP_PIN         12
124
+#define E_DIR_PIN          16
125
+#define E_ENABLE_PIN        3
126
+
127
+#define SDPOWER          -1
128
+#define SDSS          -1
129
+#define LED_PIN             0
130
+#define FAN_PIN            -1
131
+#define PS_ON_PIN          -1
132
+#define KILL_PIN           -1
133
+
134
+#define HEATER_0_PIN       14
135
+#define TEMP_0_PIN          4 //D27   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
136
+
137
+/*  Unused (1) (2) (3) 4 5 6 7 8 9 10 11 12 13 (14) (15) (16) 17 (18) (19) (20) (21) (22) (23) 24 (25) (26) (27) 28 (29) (30) (31)  */
138
+
139
+
140
+
141
+#endif
142
+
143
+
144
+/****************************************************************************************
145
+* RepRap Motherboard  ****---NOOOOOO RS485/EXTRUDER CONTROLLER!!!!!!!!!!!!!!!!!---*******
146
+*
147
+****************************************************************************************/
148
+#if MOTHERBOARD == 2
149
+#define KNOWN_BOARD 1
150
+
151
+#ifndef __AVR_ATmega644P__
152
+#error Oops!  Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu.
153
+#endif
154
+
155
+#define X_STEP_PIN      15
156
+#define X_DIR_PIN       18
157
+#define X_ENABLE_PIN    19
158
+#define X_MIN_PIN       20
159
+#define X_MAX_PIN       21
160
+
161
+#define Y_STEP_PIN      23
162
+#define Y_DIR_PIN       22
163
+#define Y_ENABLE_PIN    24
164
+#define Y_MIN_PIN       25
165
+#define Y_MAX_PIN       26
166
+
167
+#define Z_STEP_PINN     27
168
+#define Z_DIR_PINN      28
169
+#define Z_ENABLE_PIN    29
170
+#define Z_MIN_PIN       30
171
+#define Z_MAX_PIN       31
172
+
173
+#define E_STEP_PIN      17
174
+#define E_DIR_PIN       16
175
+#define E_ENABLE_PIN    -1
176
+
177
+#define SDPOWER          -1
178
+#define SDSS          4
179
+#define LED_PIN          0
180
+
181
+#define SD_CARD_WRITE    2
182
+#define SD_CARD_DETECT   3
183
+#define SD_CARD_SELECT   4
184
+
185
+//our RS485 pins
186
+#define TX_ENABLE_PIN	12
187
+#define RX_ENABLE_PIN	13
188
+
189
+//pin for controlling the PSU.
190
+#define PS_ON_PIN       14
191
+
192
+#define FAN_PIN         -1
193
+#define KILL_PIN        -1
194
+
195
+#define HEATER_0_PIN    -1
196
+#define TEMP_0_PIN      -1    // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
197
+
198
+
199
+
200
+
201
+#endif
202
+
203
+/****************************************************************************************
204
+* Arduino Mega pin assignment
205
+*
206
+****************************************************************************************/
207
+#if MOTHERBOARD == 33
208
+#define MOTHERBOARD 3
209
+#define RAMPS_V_1_3
210
+#endif
211
+#if MOTHERBOARD == 3
212
+#define KNOWN_BOARD 1
213
+
214
+//////////////////FIX THIS//////////////
215
+#ifndef __AVR_ATmega1280__
216
+ #ifndef __AVR_ATmega2560__
217
+ #error Oops!  Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu.
218
+ #endif
219
+#endif
220
+
221
+// uncomment one of the following lines for RAMPS v1.3 or v1.0, comment both for v1.2 or 1.1
222
+// #define RAMPS_V_1_3
223
+// #define RAMPS_V_1_0
224
+
225
+#ifdef RAMPS_V_1_3
226
+
227
+#define X_STEP_PIN         54
228
+#define X_DIR_PIN          55
229
+#define X_ENABLE_PIN       38
230
+#define X_MIN_PIN           3
231
+#define X_MAX_PIN          -1   //2 //Max endstops default to disabled "-1", set to commented value to enable.
232
+
233
+#define Y_STEP_PIN         60
234
+#define Y_DIR_PIN          61
235
+#define Y_ENABLE_PIN       56
236
+#define Y_MIN_PIN          14
237
+#define Y_MAX_PIN          -1   //15
238
+
239
+#define Z_STEP_PIN         46
240
+#define Z_DIR_PIN          48
241
+#define Z_ENABLE_PIN       62
242
+#define Z_MIN_PIN          18
243
+#define Z_MAX_PIN          -1   //19
244
+
245
+#define E_STEP_PIN         26
246
+#define E_DIR_PIN          28
247
+#define E_ENABLE_PIN       24
248
+
249
+#define SDPOWER            -1
250
+#define SDSS               53
251
+#define LED_PIN            13
252
+#define FAN_PIN            9
253
+#define PS_ON_PIN          12
254
+#define KILL_PIN           -1
255
+
256
+#define HEATER_0_PIN       10
257
+#define HEATER_1_PIN       8
258
+#define TEMP_0_PIN         13   // ANALOG NUMBERING
259
+#define TEMP_1_PIN         14   // ANALOG NUMBERING
260
+
261
+
262
+#else // RAMPS_V_1_1 or RAMPS_V_1_2 as default
263
+
264
+#define X_STEP_PIN         26
265
+#define X_DIR_PIN          28
266
+#define X_ENABLE_PIN       24
267
+#define X_MIN_PIN           3
268
+#define X_MAX_PIN          -1    //2
269
+
270
+#define Y_STEP_PIN         38
271
+#define Y_DIR_PIN          40
272
+#define Y_ENABLE_PIN       36
273
+#define Y_MIN_PIN          16
274
+#define Y_MAX_PIN          -1    //17
275
+
276
+#define Z_STEP_PIN         44
277
+#define Z_DIR_PIN          46
278
+#define Z_ENABLE_PIN       42
279
+#define Z_MIN_PIN          18
280
+#define Z_MAX_PIN          -1    //19
281
+
282
+#define E_STEP_PIN         32
283
+#define E_DIR_PIN          34
284
+#define E_ENABLE_PIN       30
285
+
286
+#define SDPOWER            48
287
+#define SDSS               53
288
+#define LED_PIN            13
289
+#define PS_ON_PIN          -1
290
+#define KILL_PIN           -1
291
+
292
+
293
+
294
+#ifdef RAMPS_V_1_0 // RAMPS_V_1_0
295
+  #define HEATER_0_PIN     12    // RAMPS 1.0
296
+  #define HEATER_1_PIN     -1    // RAMPS 1.0
297
+  #define FAN_PIN          11    // RAMPS 1.0
298
+
299
+#else // RAMPS_V_1_1 or RAMPS_V_1_2
300
+  #define HEATER_0_PIN     10    // RAMPS 1.1
301
+  #define HEATER_1_PIN      8    // RAMPS 1.1
302
+  #define FAN_PIN           9    // RAMPS 1.1
303
+#endif
304
+
305
+#define TEMP_0_PIN          2    // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
306
+#define TEMP_1_PIN          1    // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
307
+#endif
308
+
309
+// SPI for Max6675 Thermocouple 
310
+
311
+#ifndef SDSUPPORT
312
+// these pins are defined in the SD library if building with SD support  #define SCK_PIN          52
313
+  #define MISO_PIN         50
314
+  #define MOSI_PIN         51
315
+  #define MAX6675_SS       53
316
+#else
317
+  #define MAX6675_SS       49
318
+#endif
319
+
320
+
321
+#endif
322
+/****************************************************************************************
323
+* Duemilanove w/ ATMega328P pin assignment
324
+*
325
+****************************************************************************************/
326
+#if MOTHERBOARD == 4
327
+#define KNOWN_BOARD 1
328
+
329
+#ifndef __AVR_ATmega328P__
330
+#error Oops!  Make sure you have 'Arduino Duemilanove w/ ATMega328' selected from the 'Tools -> Boards' menu.
331
+#endif
332
+
333
+#define X_STEP_PIN         19
334
+#define X_DIR_PIN          18
335
+#define X_ENABLE_PIN       -1
336
+#define X_MIN_PIN          17
337
+#define X_MAX_PIN          -1
338
+
339
+#define Y_STEP_PIN         10
340
+#define Y_DIR_PIN           7
341
+#define Y_ENABLE_PIN       -1
342
+#define Y_MIN_PIN           8
343
+#define Y_MAX_PIN          -1
344
+
345
+#define Z_STEP_PIN         13
346
+#define Z_DIR_PIN           3
347
+#define Z_ENABLE_PIN        2
348
+#define Z_MIN_PIN           4
349
+#define Z_MAX_PIN          -1
350
+
351
+#define E_STEP_PIN         11
352
+#define E_DIR_PIN          12
353
+#define E_ENABLE_PIN       -1
354
+
355
+#define SDPOWER          -1
356
+#define SDSS          -1
357
+#define LED_PIN            -1
358
+#define FAN_PIN             5
359
+#define PS_ON_PIN          -1
360
+#define KILL_PIN           -1
361
+
362
+#define HEATER_0_PIN        6
363
+#define TEMP_0_PIN          0    // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
364
+
365
+
366
+#endif
367
+
368
+/****************************************************************************************
369
+* Gen6 pin assignment
370
+*
371
+****************************************************************************************/
372
+#if MOTHERBOARD == 5
373
+#define KNOWN_BOARD 1
374
+
375
+#ifndef __AVR_ATmega644P__
376
+    #error Oops!  Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu.
377
+#endif
378
+
379
+//x axis pins
380
+    #define X_STEP_PIN      15
381
+    #define X_DIR_PIN       18
382
+    #define X_ENABLE_PIN    19
383
+    #define X_MIN_PIN       20
384
+    #define X_MAX_PIN       -1
385
+    
386
+    //y axis pins
387
+    #define Y_STEP_PIN      23
388
+    #define Y_DIR_PIN       22
389
+    #define Y_ENABLE_PIN    24
390
+    #define Y_MIN_PIN       25
391
+    #define Y_MAX_PIN       -1
392
+    
393
+    //z axis pins
394
+    #define Z_STEP_PIN      27
395
+    #define Z_DIR_PIN       28
396
+    #define Z_ENABLE_PIN    29
397
+    #define Z_MIN_PIN       30
398
+    #define Z_MAX_PIN       -1
399
+    
400
+    //extruder pins
401
+    #define E_STEP_PIN      4     //Edited @ EJE Electronics 20100715
402
+    #define E_DIR_PIN       2     //Edited @ EJE Electronics 20100715
403
+    #define E_ENABLE_PIN    3     //Added @ EJE Electronics 20100715
404
+    #define TEMP_0_PIN      5     //changed @ rkoeppl 20110410
405
+    #define HEATER_0_PIN    14    //changed @ rkoeppl 20110410
406
+    #define HEATER_1_PIN    -1    //changed @ rkoeppl 20110410
407
+    
408
+    
409
+    #define SDPOWER          -1
410
+    #define SDSS          17
411
+    #define LED_PIN         -1    //changed @ rkoeppl 20110410
412
+    #define TEMP_1_PIN      -1    //changed @ rkoeppl 20110410
413
+    #define FAN_PIN         -1    //changed @ rkoeppl 20110410
414
+    #define PS_ON_PIN       -1    //changed @ rkoeppl 20110410
415
+    //our pin for debugging.
416
+    
417
+    #define DEBUG_PIN        0
418
+    
419
+    //our RS485 pins
420
+    #define TX_ENABLE_PIN	12
421
+    #define RX_ENABLE_PIN	13
422
+
423
+#endif
424
+/****************************************************************************************
425
+* Sanguinololu pin assignment
426
+*
427
+****************************************************************************************/
428
+#if MOTHERBOARD == 62
429
+#define MOTHERBOARD 6
430
+#define SANGUINOLOLU_V_1_2 
431
+#endif
432
+#if MOTHERBOARD == 6
433
+#define KNOWN_BOARD 1
434
+#ifndef __AVR_ATmega644P__
435
+#error Oops!  Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu.
436
+#endif
437
+
438
+#define X_STEP_PIN         15
439
+#define X_DIR_PIN          21
440
+#define X_MIN_PIN          18
441
+#define X_MAX_PIN           -2
442
+
443
+#define Y_STEP_PIN         22
444
+#define Y_DIR_PIN          23
445
+#define Y_MIN_PIN          19
446
+#define Y_MAX_PIN          -1
447
+
448
+#define Z_STEP_PIN         3
449
+#define Z_DIR_PIN          2
450
+#define Z_MIN_PIN          20
451
+#define Z_MAX_PIN          -1
452
+
453
+#define E_STEP_PIN         1
454
+#define E_DIR_PIN          0
455
+
456
+#define LED_PIN            -1
457
+
458
+#define FAN_PIN            -1 
459
+
460
+#define PS_ON_PIN          -1
461
+#define KILL_PIN           -1
462
+
463
+#define HEATER_0_PIN       13 // (extruder)
464
+
465
+#ifdef SANGUINOLOLU_V_1_2
466
+
467
+#define HEATER_1_PIN       12 // (bed)
468
+#define X_ENABLE_PIN       14
469
+#define Y_ENABLE_PIN       14
470
+#define Z_ENABLE_PIN       26
471
+#define E_ENABLE_PIN       14
472
+
473
+#else
474
+
475
+#define HEATER_1_PIN       14  // (bed)
476
+#define X_ENABLE_PIN       -1
477
+#define Y_ENABLE_PIN       -1
478
+#define Z_ENABLE_PIN       -1
479
+#define E_ENABLE_PIN       -1
480
+
481
+#endif
482
+
483
+#define TEMP_0_PIN          7   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! (pin 33 extruder)
484
+#define TEMP_1_PIN          6   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! (pin 34 bed)
485
+#define SDPOWER          -1
486
+#define SDSS          31
487
+
488
+#ifndef KNOWN_BOARD
489
+#error Unknown MOTHERBOARD value in configuration.h
490
+#endif
491
+
492
+#endif
493
+
494
+#endif

+ 75
- 0
Marlin/speed_lookuptable.h View File

@@ -0,0 +1,75 @@
1
+#ifndef SPEED_LOOKUPTABLE_H
2
+#define SPEED_LOOKUPTABLE_H
3
+
4
+#include <avr/pgmspace.h>
5
+
6
+uint16_t speed_lookuptable_fast[256][2] PROGMEM = {
7
+{ 62500, 55556}, { 6944, 3268}, { 3676, 1176}, { 2500, 607}, { 1893, 369}, { 1524, 249}, { 1275, 179}, { 1096, 135}, 
8
+{ 961, 105}, { 856, 85}, { 771, 69}, { 702, 58}, { 644, 49}, { 595, 42}, { 553, 37}, { 516, 32}, 
9
+{ 484, 28}, { 456, 25}, { 431, 23}, { 408, 20}, { 388, 19}, { 369, 16}, { 353, 16}, { 337, 14}, 
10
+{ 323, 13}, { 310, 11}, { 299, 11}, { 288, 11}, { 277, 9}, { 268, 9}, { 259, 8}, { 251, 8}, 
11
+{ 243, 8}, { 235, 7}, { 228, 6}, { 222, 6}, { 216, 6}, { 210, 6}, { 204, 5}, { 199, 5}, 
12
+{ 194, 5}, { 189, 4}, { 185, 4}, { 181, 4}, { 177, 4}, { 173, 4}, { 169, 4}, { 165, 3}, 
13
+{ 162, 3}, { 159, 4}, { 155, 3}, { 152, 3}, { 149, 2}, { 147, 3}, { 144, 3}, { 141, 2}, 
14
+{ 139, 3}, { 136, 2}, { 134, 2}, { 132, 3}, { 129, 2}, { 127, 2}, { 125, 2}, { 123, 2}, 
15
+{ 121, 2}, { 119, 1}, { 118, 2}, { 116, 2}, { 114, 1}, { 113, 2}, { 111, 2}, { 109, 1}, 
16
+{ 108, 2}, { 106, 1}, { 105, 2}, { 103, 1}, { 102, 1}, { 101, 1}, { 100, 2}, { 98, 1}, 
17
+{ 97, 1}, { 96, 1}, { 95, 2}, { 93, 1}, { 92, 1}, { 91, 1}, { 90, 1}, { 89, 1}, 
18
+{ 88, 1}, { 87, 1}, { 86, 1}, { 85, 1}, { 84, 1}, { 83, 0}, { 83, 1}, { 82, 1}, 
19
+{ 81, 1}, { 80, 1}, { 79, 1}, { 78, 0}, { 78, 1}, { 77, 1}, { 76, 1}, { 75, 0}, 
20
+{ 75, 1}, { 74, 1}, { 73, 1}, { 72, 0}, { 72, 1}, { 71, 1}, { 70, 0}, { 70, 1}, 
21
+{ 69, 0}, { 69, 1}, { 68, 1}, { 67, 0}, { 67, 1}, { 66, 0}, { 66, 1}, { 65, 0}, 
22
+{ 65, 1}, { 64, 1}, { 63, 0}, { 63, 1}, { 62, 0}, { 62, 1}, { 61, 0}, { 61, 1}, 
23
+{ 60, 0}, { 60, 0}, { 60, 1}, { 59, 0}, { 59, 1}, { 58, 0}, { 58, 1}, { 57, 0}, 
24
+{ 57, 1}, { 56, 0}, { 56, 0}, { 56, 1}, { 55, 0}, { 55, 1}, { 54, 0}, { 54, 0}, 
25
+{ 54, 1}, { 53, 0}, { 53, 0}, { 53, 1}, { 52, 0}, { 52, 0}, { 52, 1}, { 51, 0}, 
26
+{ 51, 0}, { 51, 1}, { 50, 0}, { 50, 0}, { 50, 1}, { 49, 0}, { 49, 0}, { 49, 1}, 
27
+{ 48, 0}, { 48, 0}, { 48, 1}, { 47, 0}, { 47, 0}, { 47, 0}, { 47, 1}, { 46, 0}, 
28
+{ 46, 0}, { 46, 1}, { 45, 0}, { 45, 0}, { 45, 0}, { 45, 1}, { 44, 0}, { 44, 0}, 
29
+{ 44, 0}, { 44, 1}, { 43, 0}, { 43, 0}, { 43, 0}, { 43, 1}, { 42, 0}, { 42, 0}, 
30
+{ 42, 0}, { 42, 1}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 1}, { 40, 0}, 
31
+{ 40, 0}, { 40, 0}, { 40, 0}, { 40, 1}, { 39, 0}, { 39, 0}, { 39, 0}, { 39, 0}, 
32
+{ 39, 1}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 1}, { 37, 0}, { 37, 0}, 
33
+{ 37, 0}, { 37, 0}, { 37, 0}, { 37, 1}, { 36, 0}, { 36, 0}, { 36, 0}, { 36, 0}, 
34
+{ 36, 1}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 1}, 
35
+{ 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 1}, { 33, 0}, { 33, 0}, 
36
+{ 33, 0}, { 33, 0}, { 33, 0}, { 33, 0}, { 33, 1}, { 32, 0}, { 32, 0}, { 32, 0}, 
37
+{ 32, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 1}, { 31, 0}, { 31, 0}, { 31, 0}, 
38
+{ 31, 0}, { 31, 0}, { 31, 0}, { 31, 1}, { 30, 0}, { 30, 0}, { 30, 0}, { 30, 0}, 
39
+};
40
+uint16_t speed_lookuptable_slow[256][2] PROGMEM = {
41
+{ 62500, 12500}, { 50000, 8334}, { 41666, 5952}, { 35714, 4464}, { 31250, 3473}, { 27777, 2777}, { 25000, 2273}, { 22727, 1894}, 
42
+{ 20833, 1603}, { 19230, 1373}, { 17857, 1191}, { 16666, 1041}, { 15625, 920}, { 14705, 817}, { 13888, 731}, { 13157, 657}, 
43
+{ 12500, 596}, { 11904, 541}, { 11363, 494}, { 10869, 453}, { 10416, 416}, { 10000, 385}, { 9615, 356}, { 9259, 331}, 
44
+{ 8928, 308}, { 8620, 287}, { 8333, 269}, { 8064, 252}, { 7812, 237}, { 7575, 223}, { 7352, 210}, { 7142, 198}, 
45
+{ 6944, 188}, { 6756, 178}, { 6578, 168}, { 6410, 160}, { 6250, 153}, { 6097, 145}, { 5952, 139}, { 5813, 132}, 
46
+{ 5681, 126}, { 5555, 121}, { 5434, 115}, { 5319, 111}, { 5208, 106}, { 5102, 102}, { 5000, 99}, { 4901, 94}, 
47
+{ 4807, 91}, { 4716, 87}, { 4629, 84}, { 4545, 81}, { 4464, 79}, { 4385, 75}, { 4310, 73}, { 4237, 71}, 
48
+{ 4166, 68}, { 4098, 66}, { 4032, 64}, { 3968, 62}, { 3906, 60}, { 3846, 59}, { 3787, 56}, { 3731, 55}, 
49
+{ 3676, 53}, { 3623, 52}, { 3571, 50}, { 3521, 49}, { 3472, 48}, { 3424, 46}, { 3378, 45}, { 3333, 44}, 
50
+{ 3289, 43}, { 3246, 41}, { 3205, 41}, { 3164, 39}, { 3125, 39}, { 3086, 38}, { 3048, 36}, { 3012, 36}, 
51
+{ 2976, 35}, { 2941, 35}, { 2906, 33}, { 2873, 33}, { 2840, 32}, { 2808, 31}, { 2777, 30}, { 2747, 30}, 
52
+{ 2717, 29}, { 2688, 29}, { 2659, 28}, { 2631, 27}, { 2604, 27}, { 2577, 26}, { 2551, 26}, { 2525, 25}, 
53
+{ 2500, 25}, { 2475, 25}, { 2450, 23}, { 2427, 24}, { 2403, 23}, { 2380, 22}, { 2358, 22}, { 2336, 22}, 
54
+{ 2314, 21}, { 2293, 21}, { 2272, 20}, { 2252, 20}, { 2232, 20}, { 2212, 20}, { 2192, 19}, { 2173, 18}, 
55
+{ 2155, 19}, { 2136, 18}, { 2118, 18}, { 2100, 17}, { 2083, 17}, { 2066, 17}, { 2049, 17}, { 2032, 16}, 
56
+{ 2016, 16}, { 2000, 16}, { 1984, 16}, { 1968, 15}, { 1953, 16}, { 1937, 14}, { 1923, 15}, { 1908, 15}, 
57
+{ 1893, 14}, { 1879, 14}, { 1865, 14}, { 1851, 13}, { 1838, 14}, { 1824, 13}, { 1811, 13}, { 1798, 13}, 
58
+{ 1785, 12}, { 1773, 13}, { 1760, 12}, { 1748, 12}, { 1736, 12}, { 1724, 12}, { 1712, 12}, { 1700, 11}, 
59
+{ 1689, 12}, { 1677, 11}, { 1666, 11}, { 1655, 11}, { 1644, 11}, { 1633, 10}, { 1623, 11}, { 1612, 10}, 
60
+{ 1602, 10}, { 1592, 10}, { 1582, 10}, { 1572, 10}, { 1562, 10}, { 1552, 9}, { 1543, 10}, { 1533, 9}, 
61
+{ 1524, 9}, { 1515, 9}, { 1506, 9}, { 1497, 9}, { 1488, 9}, { 1479, 9}, { 1470, 9}, { 1461, 8}, 
62
+{ 1453, 8}, { 1445, 9}, { 1436, 8}, { 1428, 8}, { 1420, 8}, { 1412, 8}, { 1404, 8}, { 1396, 8}, 
63
+{ 1388, 7}, { 1381, 8}, { 1373, 7}, { 1366, 8}, { 1358, 7}, { 1351, 7}, { 1344, 8}, { 1336, 7}, 
64
+{ 1329, 7}, { 1322, 7}, { 1315, 7}, { 1308, 6}, { 1302, 7}, { 1295, 7}, { 1288, 6}, { 1282, 7}, 
65
+{ 1275, 6}, { 1269, 7}, { 1262, 6}, { 1256, 6}, { 1250, 7}, { 1243, 6}, { 1237, 6}, { 1231, 6}, 
66
+{ 1225, 6}, { 1219, 6}, { 1213, 6}, { 1207, 6}, { 1201, 5}, { 1196, 6}, { 1190, 6}, { 1184, 5}, 
67
+{ 1179, 6}, { 1173, 5}, { 1168, 6}, { 1162, 5}, { 1157, 5}, { 1152, 6}, { 1146, 5}, { 1141, 5}, 
68
+{ 1136, 5}, { 1131, 5}, { 1126, 5}, { 1121, 5}, { 1116, 5}, { 1111, 5}, { 1106, 5}, { 1101, 5}, 
69
+{ 1096, 5}, { 1091, 5}, { 1086, 4}, { 1082, 5}, { 1077, 5}, { 1072, 4}, { 1068, 5}, { 1063, 4}, 
70
+{ 1059, 5}, { 1054, 4}, { 1050, 4}, { 1046, 5}, { 1041, 4}, { 1037, 4}, { 1033, 5}, { 1028, 4}, 
71
+{ 1024, 4}, { 1020, 4}, { 1016, 4}, { 1012, 4}, { 1008, 4}, { 1004, 4}, { 1000, 4}, { 996, 4}, 
72
+{ 992, 4}, { 988, 4}, { 984, 4}, { 980, 4}, { 976, 4}, { 972, 4}, { 968, 3}, { 965, 3}, 
73
+};
74
+
75
+#endif

+ 148
- 0
Marlin/thermistortables.h View File

@@ -0,0 +1,148 @@
1
+#ifndef THERMISTORTABLES_H_
2
+#define THERMISTORTABLES_H_
3
+
4
+#if (THERMISTORHEATER == 1) || (THERMISTORBED == 1) //100k bed thermistor
5
+
6
+
7
+#define NUMTEMPS_1 61
8
+const short temptable_1[NUMTEMPS_1][2] = {
9
+{	(23*16)	,	300	},
10
+{	(25*16)	,	295	},
11
+{	(27*16)	,	290	},
12
+{	(28*16)	,	285	},
13
+{	(31*16)	,	280	},
14
+{	(33*16)	,	275	},
15
+{	(35*16)	,	270	},
16
+{	(38*16)	,	265	},
17
+{	(41*16)	,	260	},
18
+{	(44*16)	,	255	},
19
+{	(48*16)	,	250	},
20
+{	(52*16)	,	245	},
21
+{	(56*16)	,	240	},
22
+{	(61*16)	,	235	},
23
+{	(66*16)	,	230	},
24
+{	(71*16)	,	225	},
25
+{	(78*16)	,	220	},
26
+{	(84*16)	,	215	},
27
+{	(92*16)	,	210	},
28
+{	(100*16),	205	},
29
+{	(109*16),	200	},
30
+{	(120*16),	195	},
31
+{	(131*16),	190	},
32
+{	(143*16),	185	},
33
+{	(156*16),	180	},
34
+{	(171*16),	175	},
35
+{	(187*16),	170	},
36
+{	(205*16),	165	},
37
+{	(224*16),	160	},
38
+{	(245*16),	155	},
39
+{	(268*16),	150	},
40
+{	(293*16),	145	},
41
+{	(320*16),	140	},
42
+{	(348*16),	135	},
43
+{	(379*16),	130	},
44
+{	(411*16),	125	},
45
+{	(445*16),	120	},
46
+{	(480*16),	115	},
47
+{	(516*16),	110	},
48
+{	(553*16),	105	},
49
+{	(591*16),	100	},
50
+{	(628*16),	95	},
51
+{	(665*16),	90	},
52
+{	(702*16),	85	},
53
+{	(737*16),	80	},
54
+{	(770*16),	75	},
55
+{	(801*16),	70	},
56
+{	(830*16),	65	},
57
+{	(857*16),	60	},
58
+{	(881*16),	55	},
59
+{	(903*16),	50	},
60
+{	(922*16),	45	},
61
+{	(939*16),	40	},
62
+{	(954*16),	35	},
63
+{	(966*16),	30	},
64
+{	(977*16),	25	},
65
+{	(985*16),	20	},
66
+{	(993*16),	15	},
67
+{	(999*16),	10	},
68
+{	(1004*16),	5	},
69
+{	(1008*16),	0	} //safety
70
+};
71
+#endif
72
+#if (THERMISTORHEATER == 2) || (THERMISTORBED == 2) //200k bed thermistor
73
+#define NUMTEMPS_2 21
74
+const short temptable_2[NUMTEMPS_2][2] = {
75
+   {(1*16), 848},
76
+   {(54*16), 275},
77
+   {(107*16), 228},
78
+   {(160*16), 202},
79
+   {(213*16), 185},
80
+   {(266*16), 171},
81
+   {(319*16), 160},
82
+   {(372*16), 150},
83
+   {(425*16), 141},
84
+   {(478*16), 133},
85
+   {(531*16), 125},
86
+   {(584*16), 118},
87
+   {(637*16), 110},
88
+   {(690*16), 103},
89
+   {(743*16), 95},
90
+   {(796*16), 86},
91
+   {(849*16), 77},
92
+   {(902*16), 65},
93
+   {(955*16), 49},
94
+   {(1008*16), 17},
95
+   {(1020*16), 0} //safety
96
+};
97
+
98
+#endif
99
+#if (THERMISTORHEATER == 3) || (THERMISTORBED == 3) //mendel-parts
100
+#define NUMTEMPS_3 28
101
+const short temptable_3[NUMTEMPS_3][2] = {
102
+		{(1*16),864},
103
+		{(21*16),300},
104
+		{(25*16),290},
105
+		{(29*16),280},
106
+		{(33*16),270},
107
+		{(39*16),260},
108
+		{(46*16),250},
109
+		{(54*16),240},
110
+		{(64*16),230},
111
+		{(75*16),220},
112
+		{(90*16),210},
113
+		{(107*16),200},
114
+		{(128*16),190},
115
+		{(154*16),180},
116
+		{(184*16),170},
117
+		{(221*16),160},
118
+		{(265*16),150},
119
+		{(316*16),140},
120
+		{(375*16),130},
121
+		{(441*16),120},
122
+		{(513*16),110},
123
+		{(588*16),100},
124
+		{(734*16),80},
125
+		{(856*16),60},
126
+		{(938*16),40},
127
+		{(986*16),20},
128
+		{(1008*16),0},
129
+		{(1018*16),-20}
130
+	};
131
+
132
+#endif
133
+
134
+#if THERMISTORHEATER == 1
135
+#define NUMTEMPS NUMTEMPS_1
136
+#define temptable temptable_1
137
+#elif THERMISTORHEATER == 2
138
+#define NUMTEMPS NUMTEMPS_2
139
+#define temptable temptable_2
140
+#elif THERMISTORHEATER == 3
141
+#define NUMTEMPS NUMTEMPS_3
142
+#define temptable temptable_3
143
+#else
144
+#error No heater thermistor table specified
145
+#endif
146
+
147
+
148
+#endif //THERMISTORTABLES_H_

+ 176
- 0
Marlin/wiring.c View File

@@ -0,0 +1,176 @@
1
+/*
2
+  wiring.c - Partial implementation of the Wiring API for the ATmega8.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.c 388 2008-03-08 22:05:23Z mellis $
23
+*/
24
+
25
+#include "wiring_private.h"
26
+
27
+volatile unsigned long timer0_millis = 0;
28
+
29
+SIGNAL(TIMER0_OVF_vect)
30
+{
31
+	// timer 0 prescale factor is 64 and the timer overflows at 256
32
+        timer0_millis++;
33
+}
34
+
35
+unsigned long millis()
36
+{
37
+	unsigned long m;
38
+	uint8_t oldSREG = SREG;
39
+	
40
+	// disable interrupts while we read timer0_millis or we might get an
41
+	// inconsistent value (e.g. in the middle of the timer0_millis++)
42
+	cli();
43
+	m = timer0_millis;
44
+	SREG = oldSREG;
45
+	
46
+	return m;
47
+}
48
+
49
+void delay(unsigned long ms)
50
+{
51
+	unsigned long start = millis();
52
+	
53
+	while (millis() - start <= ms)
54
+		;
55
+}
56
+
57
+/* Delay for the given number of microseconds.  Assumes a 8 or 16 MHz clock. 
58
+ * Disables interrupts, which will disrupt the millis() function if used
59
+ * too frequently. */
60
+void delayMicroseconds(unsigned int us)
61
+{
62
+	uint8_t oldSREG;
63
+
64
+	// calling avrlib's delay_us() function with low values (e.g. 1 or
65
+	// 2 microseconds) gives delays longer than desired.
66
+	//delay_us(us);
67
+
68
+#if F_CPU >= 16000000L
69
+	// for the 16 MHz clock on most Arduino boards
70
+
71
+	// for a one-microsecond delay, simply return.  the overhead
72
+	// of the function call yields a delay of approximately 1 1/8 us.
73
+	if (--us == 0)
74
+		return;
75
+
76
+	// the following loop takes a quarter of a microsecond (4 cycles)
77
+	// per iteration, so execute it four times for each microsecond of
78
+	// delay requested.
79
+	us <<= 2;
80
+
81
+	// account for the time taken in the preceeding commands.
82
+	us -= 2;
83
+#else
84
+	// for the 8 MHz internal clock on the ATmega168
85
+
86
+	// for a one- or two-microsecond delay, simply return.  the overhead of
87
+	// the function calls takes more than two microseconds.  can't just
88
+	// subtract two, since us is unsigned; we'd overflow.
89
+	if (--us == 0)
90
+		return;
91
+	if (--us == 0)
92
+		return;
93
+
94
+	// the following loop takes half of a microsecond (4 cycles)
95
+	// per iteration, so execute it twice for each microsecond of
96
+	// delay requested.
97
+	us <<= 1;
98
+
99
+	// partially compensate for the time taken by the preceeding commands.
100
+	// we can't subtract any more than this or we'd overflow w/ small delays.
101
+	us--;
102
+#endif
103
+
104
+	// disable interrupts, otherwise the timer 0 overflow interrupt that
105
+	// tracks milliseconds will make us delay longer than we want.
106
+	oldSREG = SREG;
107
+	cli();
108
+
109
+	// busy wait
110
+	__asm__ __volatile__ (
111
+		"1: sbiw %0,1" "\n\t" // 2 cycles
112
+		"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
113
+	);
114
+
115
+	// reenable interrupts.
116
+	SREG = oldSREG;
117
+}
118
+
119
+void init()
120
+{
121
+	// this needs to be called before setup() or some functions won't
122
+	// work there
123
+	sei();
124
+	
125
+	// on the ATmega168, timer 0 is also used for fast hardware pwm
126
+	// (using phase-correct PWM would mean that timer 0 overflowed half as often
127
+	// resulting in different millis() behavior on the ATmega8 and ATmega168)
128
+	sbi(TCCR0A, WGM01);
129
+	sbi(TCCR0A, WGM00);
130
+
131
+	// set timer 0 prescale factor to 64
132
+	sbi(TCCR0B, CS01);
133
+	sbi(TCCR0B, CS00);
134
+
135
+	// enable timer 0 overflow interrupt
136
+	sbi(TIMSK0, TOIE0);
137
+
138
+	// timers 1 and 2 are used for phase-correct hardware pwm
139
+	// this is better for motors as it ensures an even waveform
140
+	// note, however, that fast pwm mode can achieve a frequency of up
141
+	// 8 MHz (with a 16 MHz clock) at 50% duty cycle
142
+#if 0
143
+	// set timer 1 prescale factor to 64
144
+	sbi(TCCR1B, CS11);
145
+	sbi(TCCR1B, CS10);
146
+
147
+	// put timer 1 in 8-bit phase correct pwm mode
148
+	sbi(TCCR1A, WGM10);
149
+
150
+	// set timer 2 prescale factor to 64
151
+	sbi(TCCR2B, CS22);
152
+
153
+	// configure timer 2 for phase correct pwm (8-bit)
154
+	sbi(TCCR2A, WGM20);
155
+
156
+	// set a2d prescale factor to 128
157
+	// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
158
+	// XXX: this will not work properly for other clock speeds, and
159
+	// this code should use F_CPU to determine the prescale factor.
160
+	sbi(ADCSRA, ADPS2);
161
+	sbi(ADCSRA, ADPS1);
162
+	sbi(ADCSRA, ADPS0);
163
+
164
+	// enable a2d conversions
165
+	sbi(ADCSRA, ADEN);
166
+
167
+	// the bootloader connects pins 0 and 1 to the USART; disconnect them
168
+	// here so they can be used as normal digital i/o; they will be
169
+	// reconnected in Serial.begin()
170
+	UCSR0B = 0;
171
+	#if defined(__AVR_ATmega644P__)
172
+	//TODO: test to see if disabling this helps?
173
+	//UCSR1B = 0;
174
+	#endif
175
+#endif
176
+}

+ 139
- 0
Marlin/wiring_serial.c View File

@@ -0,0 +1,139 @@
1
+/*
2
+  wiring_serial.c - serial functions.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+  Modified 29 January 2009, Marius Kintel for Sanguino - http://www.sanguino.cc/
7
+
8
+  This library is free software; you can redistribute it and/or
9
+  modify it under the terms of the GNU Lesser General Public
10
+  License as published by the Free Software Foundation; either
11
+  version 2.1 of the License, or (at your option) any later version.
12
+
13
+  This library is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+  Lesser General Public License for more details.
17
+
18
+  You should have received a copy of the GNU Lesser General
19
+  Public License along with this library; if not, write to the
20
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
+  Boston, MA  02111-1307  USA
22
+
23
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
24
+*/
25
+
26
+
27
+#include "wiring_private.h"
28
+
29
+// Define constants and variables for buffering incoming serial data.  We're
30
+// using a ring buffer (I think), in which rx_buffer_head is the index of the
31
+// location to which to write the next incoming character and rx_buffer_tail
32
+// is the index of the location from which to read.
33
+#define RX_BUFFER_SIZE 128
34
+#define RX_BUFFER_MASK 0x7f
35
+
36
+#if defined(__AVR_ATmega644P__)
37
+unsigned char rx_buffer[2][RX_BUFFER_SIZE];
38
+int rx_buffer_head[2] = {0, 0};
39
+int rx_buffer_tail[2] = {0, 0};
40
+#else
41
+unsigned char rx_buffer[1][RX_BUFFER_SIZE];
42
+int rx_buffer_head[1] = {0};
43
+int rx_buffer_tail[1] = {0};
44
+#endif
45
+
46
+
47
+#define BEGIN_SERIAL(uart_, baud_) \
48
+{ \
49
+    UBRR##uart_##H = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8; \
50
+    UBRR##uart_##L = ((F_CPU / 16 + baud / 2) / baud - 1); \
51
+    \
52
+    /* reset config for UART */ \
53
+    UCSR##uart_##A = 0; \
54
+    UCSR##uart_##B = 0; \
55
+    UCSR##uart_##C = 0; \
56
+    \
57
+    /* enable rx and tx */ \
58
+    sbi(UCSR##uart_##B, RXEN##uart_);\
59
+    sbi(UCSR##uart_##B, TXEN##uart_);\
60
+    \
61
+    /* enable interrupt on complete reception of a byte */ \
62
+    sbi(UCSR##uart_##B, RXCIE##uart_); \
63
+    UCSR##uart_##C = _BV(UCSZ##uart_##1)|_BV(UCSZ##uart_##0); \
64
+    /* defaults to 8-bit, no parity, 1 stop bit */ \
65
+}
66
+
67
+void beginSerial(uint8_t uart, long baud)
68
+{
69
+  if (uart == 0) BEGIN_SERIAL(0, baud)
70
+#if defined(__AVR_ATmega644P__)
71
+  else BEGIN_SERIAL(1, baud)
72
+#endif
73
+}
74
+
75
+#define SERIAL_WRITE(uart_, c_) \
76
+    while (!(UCSR##uart_##A & (1 << UDRE##uart_))) \
77
+      ; \
78
+    UDR##uart_ = c
79
+
80
+void serialWrite(uint8_t uart, unsigned char c)
81
+{
82
+  if (uart == 0) {
83
+    SERIAL_WRITE(0, c);
84
+  }
85
+#if defined(__AVR_ATmega644P__)
86
+  else {
87
+    SERIAL_WRITE(1, c);
88
+  }
89
+#endif
90
+}
91
+
92
+int serialAvailable(uint8_t uart)
93
+{
94
+  return (RX_BUFFER_SIZE + rx_buffer_head[uart] - rx_buffer_tail[uart]) & RX_BUFFER_MASK;
95
+}
96
+
97
+int serialRead(uint8_t uart)
98
+{
99
+  // if the head isn't ahead of the tail, we don't have any characters
100
+  if (rx_buffer_head[uart] == rx_buffer_tail[uart]) {
101
+    return -1;
102
+  } else {
103
+    unsigned char c = rx_buffer[uart][rx_buffer_tail[uart]];
104
+    rx_buffer_tail[uart] = (rx_buffer_tail[uart] + 1) & RX_BUFFER_MASK;
105
+    return c;
106
+  }
107
+}
108
+
109
+void serialFlush(uint8_t uart)
110
+{
111
+  // don't reverse this or there may be problems if the RX interrupt
112
+  // occurs after reading the value of rx_buffer_head but before writing
113
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
114
+  // may be written to rx_buffer_tail, making it appear as if the buffer
115
+  // were full, not empty.
116
+  rx_buffer_head[uart] = rx_buffer_tail[uart];
117
+}
118
+
119
+#define UART_ISR(uart_) \
120
+ISR(USART##uart_##_RX_vect) \
121
+{ \
122
+  unsigned char c = UDR##uart_; \
123
+  \
124
+  int i = (rx_buffer_head[uart_] + 1) & RX_BUFFER_MASK; \
125
+  \  
126
+  /* if we should be storing the received character into the location \
127
+     just before the tail (meaning that the head would advance to the \
128
+     current location of the tail), we're about to overflow the buffer \
129
+     and so we don't write the character or advance the head. */ \
130
+  if (i != rx_buffer_tail[uart_]) { \
131
+    rx_buffer[uart_][rx_buffer_head[uart_]] = c; \
132
+    rx_buffer_head[uart_] = i; \
133
+  } \
134
+}
135
+
136
+UART_ISR(0)
137
+#if defined(__AVR_ATmega644P__) 
138
+UART_ISR(1)
139
+#endif

Loading…
Cancel
Save