Browse Source

changed end of line to windows, which seems to be the majority of developers main platform.

Bernhard Kubicek 12 years ago
parent
commit
40e8081623
22 changed files with 9923 additions and 9923 deletions
  1. 418
    418
      Marlin/FatStructs.h
  2. 643
    643
      Marlin/Sd2Card.cpp
  3. 233
    233
      Marlin/Sd2Card.h
  4. 353
    353
      Marlin/Sd2PinMap.h
  5. 547
    547
      Marlin/SdFat.h
  6. 70
    70
      Marlin/SdFatUtil.h
  7. 202
    202
      Marlin/SdFatmainpage.h
  8. 1252
    1252
      Marlin/SdFile.cpp
  9. 232
    232
      Marlin/SdInfo.h
  10. 295
    295
      Marlin/SdVolume.cpp
  11. 2558
    2558
      Marlin/fastio.h
  12. 570
    570
      Marlin/pins.h
  13. 577
    577
      Marlin/planner.cpp
  14. 75
    75
      Marlin/speed_lookuptable.h
  15. 592
    592
      Marlin/stepper.cpp
  16. 84
    84
      Marlin/streaming.h
  17. 467
    467
      Marlin/temperature.cpp
  18. 410
    410
      Marlin/thermistortables.h
  19. 155
    155
      Marlin/ultralcd.h
  20. 64
    64
      README
  21. 69
    69
      README.md
  22. 57
    57
      merging still needs.txt

+ 418
- 418
Marlin/FatStructs.h View File

@@ -1,418 +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
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

+ 643
- 643
Marlin/Sd2Card.cpp
File diff suppressed because it is too large
View File


+ 233
- 233
Marlin/Sd2Card.h View File

@@ -1,233 +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
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
- 353
Marlin/Sd2PinMap.h View File

@@ -1,353 +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
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
- 547
Marlin/SdFat.h
File diff suppressed because it is too large
View File


+ 70
- 70
Marlin/SdFatUtil.h View File

@@ -1,70 +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
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
- 202
Marlin/SdFatmainpage.h View File

@@ -1,202 +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
- */  
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
- 1252
Marlin/SdFile.cpp
File diff suppressed because it is too large
View File


+ 232
- 232
Marlin/SdInfo.h View File

@@ -1,232 +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
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
- 295
Marlin/SdVolume.cpp View File

@@ -1,295 +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
-}
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
+}

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


+ 570
- 570
Marlin/pins.h
File diff suppressed because it is too large
View File


+ 577
- 577
Marlin/planner.cpp
File diff suppressed because it is too large
View File


+ 75
- 75
Marlin/speed_lookuptable.h View File

@@ -1,75 +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
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

+ 592
- 592
Marlin/stepper.cpp
File diff suppressed because it is too large
View File


+ 84
- 84
Marlin/streaming.h View File

@@ -1,84 +1,84 @@
1
-/*
2
-Streaming.h - Arduino library for supporting the << streaming operator
3
-Copyright (c) 2010 Mikal Hart.  All rights reserved.
4
-
5
-This library is free software; you can redistribute it and/or
6
-modify it under the terms of the GNU Lesser General Public
7
-License as published by the Free Software Foundation; either
8
-version 2.1 of the License, or (at your option) any later version.
9
-
10
-This library is distributed in the hope that it will be useful,
11
-but WITHOUT ANY WARRANTY; without even the implied warranty of
12
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
-Lesser General Public License for more details.
14
-
15
-You should have received a copy of the GNU Lesser General Public
16
-License along with this library; if not, write to the Free Software
17
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
-*/
19
-
20
-#ifndef ARDUINO_STREAMING
21
-#define ARDUINO_STREAMING
22
-
23
-//#include <WProgram.h>
24
-
25
-#define STREAMING_LIBRARY_VERSION 4
26
-
27
-// Generic template
28
-template<class T> 
29
-inline Print &operator <<(Print &stream, T arg) 
30
-{ stream.print(arg); return stream; }
31
-
32
-struct _BASED 
33
-{ 
34
-  long val; 
35
-  int base;
36
-  _BASED(long v, int b): val(v), base(b) 
37
-  {}
38
-};
39
-
40
-#define _HEX(a)     _BASED(a, HEX)
41
-#define _DEC(a)     _BASED(a, DEC)
42
-#define _OCT(a)     _BASED(a, OCT)
43
-#define _BIN(a)     _BASED(a, BIN)
44
-#define _BYTE(a)    _BASED(a, BYTE)
45
-
46
-// Specialization for class _BASED
47
-// Thanks to Arduino forum user Ben Combee who suggested this 
48
-// clever technique to allow for expressions like
49
-//   Serial << _HEX(a);
50
-
51
-inline Print &operator <<(Print &obj, const _BASED &arg)
52
-{ obj.print(arg.val, arg.base); return obj; } 
53
-
54
-#if ARDUINO >= 18
55
-// Specialization for class _FLOAT
56
-// Thanks to Michael Margolis for suggesting a way
57
-// to accommodate Arduino 0018's floating point precision
58
-// feature like this:
59
-//   Serial << _FLOAT(gps_latitude, 6); // 6 digits of precision
60
-
61
-struct _FLOAT
62
-{
63
-  float val;
64
-  int digits;
65
-  _FLOAT(double v, int d): val(v), digits(d)
66
-  {}
67
-};
68
-
69
-inline Print &operator <<(Print &obj, const _FLOAT &arg)
70
-{ obj.print(arg.val, arg.digits); return obj; }
71
-#endif
72
-
73
-// Specialization for enum _EndLineCode
74
-// Thanks to Arduino forum user Paul V. who suggested this
75
-// clever technique to allow for expressions like
76
-//   Serial << "Hello!" << endl;
77
-
78
-enum _EndLineCode { endl };
79
-
80
-inline Print &operator <<(Print &obj, _EndLineCode arg) 
81
-{ obj.println(); return obj; }
82
-
83
-#endif
84
-
1
+/*
2
+Streaming.h - Arduino library for supporting the << streaming operator
3
+Copyright (c) 2010 Mikal Hart.  All rights reserved.
4
+
5
+This library is free software; you can redistribute it and/or
6
+modify it under the terms of the GNU Lesser General Public
7
+License as published by the Free Software Foundation; either
8
+version 2.1 of the License, or (at your option) any later version.
9
+
10
+This library is distributed in the hope that it will be useful,
11
+but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+Lesser General Public License for more details.
14
+
15
+You should have received a copy of the GNU Lesser General Public
16
+License along with this library; if not, write to the Free Software
17
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+*/
19
+
20
+#ifndef ARDUINO_STREAMING
21
+#define ARDUINO_STREAMING
22
+
23
+//#include <WProgram.h>
24
+
25
+#define STREAMING_LIBRARY_VERSION 4
26
+
27
+// Generic template
28
+template<class T> 
29
+inline Print &operator <<(Print &stream, T arg) 
30
+{ stream.print(arg); return stream; }
31
+
32
+struct _BASED 
33
+{ 
34
+  long val; 
35
+  int base;
36
+  _BASED(long v, int b): val(v), base(b) 
37
+  {}
38
+};
39
+
40
+#define _HEX(a)     _BASED(a, HEX)
41
+#define _DEC(a)     _BASED(a, DEC)
42
+#define _OCT(a)     _BASED(a, OCT)
43
+#define _BIN(a)     _BASED(a, BIN)
44
+#define _BYTE(a)    _BASED(a, BYTE)
45
+
46
+// Specialization for class _BASED
47
+// Thanks to Arduino forum user Ben Combee who suggested this 
48
+// clever technique to allow for expressions like
49
+//   Serial << _HEX(a);
50
+
51
+inline Print &operator <<(Print &obj, const _BASED &arg)
52
+{ obj.print(arg.val, arg.base); return obj; } 
53
+
54
+#if ARDUINO >= 18
55
+// Specialization for class _FLOAT
56
+// Thanks to Michael Margolis for suggesting a way
57
+// to accommodate Arduino 0018's floating point precision
58
+// feature like this:
59
+//   Serial << _FLOAT(gps_latitude, 6); // 6 digits of precision
60
+
61
+struct _FLOAT
62
+{
63
+  float val;
64
+  int digits;
65
+  _FLOAT(double v, int d): val(v), digits(d)
66
+  {}
67
+};
68
+
69
+inline Print &operator <<(Print &obj, const _FLOAT &arg)
70
+{ obj.print(arg.val, arg.digits); return obj; }
71
+#endif
72
+
73
+// Specialization for enum _EndLineCode
74
+// Thanks to Arduino forum user Paul V. who suggested this
75
+// clever technique to allow for expressions like
76
+//   Serial << "Hello!" << endl;
77
+
78
+enum _EndLineCode { endl };
79
+
80
+inline Print &operator <<(Print &obj, _EndLineCode arg) 
81
+{ obj.println(); return obj; }
82
+
83
+#endif
84
+

+ 467
- 467
Marlin/temperature.cpp View File

@@ -1,483 +1,483 @@
1
-/*
2
-  temperature.c - temperature control
3
-  Part of Marlin
4
-  
5
- Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
6
- 
7
- This program is free software: you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License as published by
9
- the Free Software Foundation, either version 3 of the License, or
10
- (at your option) any later version.
11
- 
12
- This program 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
15
- GNU General Public License for more details.
16
- 
17
- You should have received a copy of the GNU General Public License
18
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
- */
20
-
21
-/*
22
- This firmware is a mashup between Sprinter and grbl.
23
-  (https://github.com/kliment/Sprinter)
24
-  (https://github.com/simen/grbl/tree)
25
- 
26
- It has preliminary support for Matthew Roberts advance algorithm 
27
-    http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
28
-
29
- This firmware is optimized for gen6 electronics.
30
- */
31
-
32
-#include "fastio.h"
33
-#include "Configuration.h"
34
-#include "pins.h"
35
-#include "Marlin.h"
36
-#include "ultralcd.h"
37
-#include "streaming.h"
38
-#include "temperature.h"
39
-
40
-int target_bed_raw = 0;
41
-int current_bed_raw = 0;
42
-
43
-int target_raw[3] = {0, 0, 0};
44
-int current_raw[3] = {0, 0, 0};
45
-unsigned char temp_meas_ready = false;
46
-
47
-unsigned long previous_millis_heater, previous_millis_bed_heater;
48
-
49
-#ifdef PIDTEMP
50
-  double temp_iState = 0;
51
-  double temp_dState = 0;
52
-  double pTerm;
53
-  double iTerm;
54
-  double dTerm;
55
-      //int output;
56
-  double pid_error;
57
-  double temp_iState_min;
58
-  double temp_iState_max;
59
-  double pid_setpoint = 0.0;
60
-  double pid_input;
61
-  double pid_output;
62
-  bool pid_reset;
63
-  float HeaterPower;
64
-  
65
-  float Kp=DEFAULT_Kp;
66
-  float Ki=DEFAULT_Ki;
67
-  float Kd=DEFAULT_Kd;
68
-  float Kc=DEFAULT_Kc;
69
-#endif //PIDTEMP
70
-
71
-#ifdef MINTEMP
72
-int minttemp = temp2analog(MINTEMP);
73
-#endif //MINTEMP
74
-#ifdef MAXTEMP
75
-int maxttemp = temp2analog(MAXTEMP);
76
-#endif //MAXTEMP
77
-
78
-#ifdef BED_MINTEMP
79
-int bed_minttemp = temp2analog(BED_MINTEMP);
80
-#endif //BED_MINTEMP
81
-#ifdef BED_MAXTEMP
82
-int bed_maxttemp = temp2analog(BED_MAXTEMP);
83
-#endif //BED_MAXTEMP
84
-
85
-void manage_heater()
86
-{
87
-#ifdef USE_WATCHDOG
88
-  wd_reset();
89
-#endif
90
-  
91
-  float pid_input;
92
-  float pid_output;
1
+/*
2
+  temperature.c - temperature control
3
+  Part of Marlin
4
+  
5
+ Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
6
+ 
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+ 
12
+ This program 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
15
+ GNU General Public License for more details.
16
+ 
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+/*
22
+ This firmware is a mashup between Sprinter and grbl.
23
+  (https://github.com/kliment/Sprinter)
24
+  (https://github.com/simen/grbl/tree)
25
+ 
26
+ It has preliminary support for Matthew Roberts advance algorithm 
27
+    http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
28
+
29
+ This firmware is optimized for gen6 electronics.
30
+ */
31
+
32
+#include "fastio.h"
33
+#include "Configuration.h"
34
+#include "pins.h"
35
+#include "Marlin.h"
36
+#include "ultralcd.h"
37
+#include "streaming.h"
38
+#include "temperature.h"
39
+
40
+int target_bed_raw = 0;
41
+int current_bed_raw = 0;
42
+
43
+int target_raw[3] = {0, 0, 0};
44
+int current_raw[3] = {0, 0, 0};
45
+unsigned char temp_meas_ready = false;
46
+
47
+unsigned long previous_millis_heater, previous_millis_bed_heater;
48
+
49
+#ifdef PIDTEMP
50
+  double temp_iState = 0;
51
+  double temp_dState = 0;
52
+  double pTerm;
53
+  double iTerm;
54
+  double dTerm;
55
+      //int output;
56
+  double pid_error;
57
+  double temp_iState_min;
58
+  double temp_iState_max;
59
+  double pid_setpoint = 0.0;
60
+  double pid_input;
61
+  double pid_output;
62
+  bool pid_reset;
63
+  float HeaterPower;
64
+  
65
+  float Kp=DEFAULT_Kp;
66
+  float Ki=DEFAULT_Ki;
67
+  float Kd=DEFAULT_Kd;
68
+  float Kc=DEFAULT_Kc;
69
+#endif //PIDTEMP
70
+
71
+#ifdef MINTEMP
72
+int minttemp = temp2analog(MINTEMP);
73
+#endif //MINTEMP
74
+#ifdef MAXTEMP
75
+int maxttemp = temp2analog(MAXTEMP);
76
+#endif //MAXTEMP
77
+
78
+#ifdef BED_MINTEMP
79
+int bed_minttemp = temp2analog(BED_MINTEMP);
80
+#endif //BED_MINTEMP
81
+#ifdef BED_MAXTEMP
82
+int bed_maxttemp = temp2analog(BED_MAXTEMP);
83
+#endif //BED_MAXTEMP
84
+
85
+void manage_heater()
86
+{
87
+#ifdef USE_WATCHDOG
88
+  wd_reset();
89
+#endif
90
+  
91
+  float pid_input;
92
+  float pid_output;
93 93
   if(temp_meas_ready != true)   //better readability
94 94
     return; 
95
-
96
-CRITICAL_SECTION_START;
97
-    temp_meas_ready = false;
98
-CRITICAL_SECTION_END;
99
-
100
-#ifdef PIDTEMP
95
+
96
+CRITICAL_SECTION_START;
97
+    temp_meas_ready = false;
98
+CRITICAL_SECTION_END;
99
+
100
+#ifdef PIDTEMP
101 101
     pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND]);
102
-
103
-#ifndef PID_OPENLOOP
104
-    pid_error = pid_setpoint - pid_input;
105
-    if(pid_error > 10){
106
-      pid_output = PID_MAX;
107
-      pid_reset = true;
108
-    }
109
-    else if(pid_error < -10) {
110
-      pid_output = 0;
111
-      pid_reset = true;
112
-    }
113
-    else {
114
-      if(pid_reset == true) {
115
-        temp_iState = 0.0;
116
-        pid_reset = false;
117
-      }
118
-      pTerm = Kp * pid_error;
119
-      temp_iState += pid_error;
120
-      temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
121
-      iTerm = Ki * temp_iState;
102
+
103
+#ifndef PID_OPENLOOP
104
+    pid_error = pid_setpoint - pid_input;
105
+    if(pid_error > 10){
106
+      pid_output = PID_MAX;
107
+      pid_reset = true;
108
+    }
109
+    else if(pid_error < -10) {
110
+      pid_output = 0;
111
+      pid_reset = true;
112
+    }
113
+    else {
114
+      if(pid_reset == true) {
115
+        temp_iState = 0.0;
116
+        pid_reset = false;
117
+      }
118
+      pTerm = Kp * pid_error;
119
+      temp_iState += pid_error;
120
+      temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
121
+      iTerm = Ki * temp_iState;
122 122
       //K1 defined in Configuration.h in the PID settings
123
-      #define K2 (1.0-K1)
124
-      dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
125
-      temp_dState = pid_input;
123
+      #define K2 (1.0-K1)
124
+      dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
125
+      temp_dState = pid_input;
126 126
       #ifdef PID_ADD_EXTRUSION_RATE
127 127
         pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high
128 128
       #endif
129
-      pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
130
-    }
131
-#endif //PID_OPENLOOP
132
-#ifdef PID_DEBUG
133
-     Serial.print(" Input ");
134
-     Serial.print(pid_input);
135
-     Serial.print(" Output ");
136
-     Serial.print(pid_output);    
137
-     Serial.print(" pTerm ");
138
-     Serial.print(pTerm); 
139
-     Serial.print(" iTerm ");
140
-     Serial.print(iTerm); 
141
-     Serial.print(" dTerm ");
142
-     Serial.print(dTerm); 
143
-     Serial.println();
144
-#endif //PID_DEBUG
145
-    analogWrite(HEATER_0_PIN, pid_output);
146
-#endif //PIDTEMP
147
-
148
-#ifndef PIDTEMP
149
-    if(current_raw[0] >= target_raw[0])
150
-    {
151
-      WRITE(HEATER_0_PIN,LOW);
152
-    }
153
-    else 
154
-    {
155
-      WRITE(HEATER_0_PIN,HIGH);
156
-    }
157
-#endif
158
-    
159
-  if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
160
-    return;
161
-  previous_millis_bed_heater = millis();
162
-  
163
-  #if TEMP_1_PIN > -1
129
+      pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
130
+    }
131
+#endif //PID_OPENLOOP
132
+#ifdef PID_DEBUG
133
+     Serial.print(" Input ");
134
+     Serial.print(pid_input);
135
+     Serial.print(" Output ");
136
+     Serial.print(pid_output);    
137
+     Serial.print(" pTerm ");
138
+     Serial.print(pTerm); 
139
+     Serial.print(" iTerm ");
140
+     Serial.print(iTerm); 
141
+     Serial.print(" dTerm ");
142
+     Serial.print(dTerm); 
143
+     Serial.println();
144
+#endif //PID_DEBUG
145
+    analogWrite(HEATER_0_PIN, pid_output);
146
+#endif //PIDTEMP
147
+
148
+#ifndef PIDTEMP
149
+    if(current_raw[0] >= target_raw[0])
150
+    {
151
+      WRITE(HEATER_0_PIN,LOW);
152
+    }
153
+    else 
154
+    {
155
+      WRITE(HEATER_0_PIN,HIGH);
156
+    }
157
+#endif
158
+    
159
+  if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
160
+    return;
161
+  previous_millis_bed_heater = millis();
162
+  
163
+  #if TEMP_1_PIN > -1
164 164
     if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
165
-    {
166
-      WRITE(HEATER_1_PIN,LOW);
167
-    }
168
-    else 
169
-    {
170
-      WRITE(HEATER_1_PIN,HIGH);
171
-    }
172
-  #endif
173
-  }
174
-
175
-// Takes hot end temperature value as input and returns corresponding raw value. 
176
-// For a thermistor, it uses the RepRap thermistor temp table.
177
-// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
178
-// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
179
-float temp2analog(int celsius) {
180
-  #ifdef HEATER_USES_THERMISTOR_1
181
-    int raw = 0;
182
-    byte i;
183
-    
184
-    for (i=1; i<NUMTEMPS_HEATER_1; i++)
185
-    {
186
-      if (temptable_1[i][1] < celsius)
187
-      {
188
-        raw = temptable_1[i-1][0] + 
189
-          (celsius - temptable_1[i-1][1]) * 
190
-          (temptable_1[i][0] - temptable_1[i-1][0]) /
191
-          (temptable_1[i][1] - temptable_1[i-1][1]);
192
-      
193
-        break;
194
-      }
195
-    }
196
-
197
-    // Overflow: Set to last value in the table
198
-    if (i == NUMTEMPS_1) raw = temptable_1[i-1][0];
199
-
200
-    return (1023 * OVERSAMPLENR) - raw;
201
-  #elif defined HEATER_1_USES_AD595
202
-    return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
203
-  #endif
204
-}
205
-
206
-// Takes bed temperature value as input and returns corresponding raw value. 
207
-// For a thermistor, it uses the RepRap thermistor temp table.
208
-// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
209
-// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
210
-float temp2analogBed(int celsius) {
211
-  #ifdef BED_USES_THERMISTOR
212
-
213
-    int raw = 0;
214
-    byte i;
215
-    
216
-    for (i=1; i<BNUMTEMPS; i++)
217
-    {
218
-      if (bedtemptable[i][1] < celsius)
219
-      {
220
-        raw = bedtemptable[i-1][0] + 
221
-          (celsius - bedtemptable[i-1][1]) * 
222
-          (bedtemptable[i][0] - bedtemptable[i-1][0]) /
223
-          (bedtemptable[i][1] - bedtemptable[i-1][1]);
224
-      
225
-        break;
226
-      }
227
-    }
228
-
229
-    // Overflow: Set to last value in the table
230
-    if (i == BNUMTEMPS) raw = bedtemptable[i-1][0];
231
-
232
-    return (1023 * OVERSAMPLENR) - raw;
233
-  #elif defined BED_USES_AD595
234
-    return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
235
-  #endif
236
-}
237
-
238
-// Derived from RepRap FiveD extruder::getTemperature()
239
-// For hot end temperature measurement.
240
-float analog2temp(int raw) {
241
-  #ifdef HEATER_1_USES_THERMISTOR
242
-    int celsius = 0;
243
-    byte i;  
244
-    raw = (1023 * OVERSAMPLENR) - raw;
245
-    for (i=1; i<NUMTEMPS_HEATER_1; i++)
246
-    {
247
-      if (temptable_1[i][0] > raw)
248
-      {
249
-        celsius  = temptable_1[i-1][1] + 
250
-          (raw - temptable_1[i-1][0]) * 
251
-          (temptable_1[i][1] - temptable_1[i-1][1]) /
252
-          (temptable_1[i][0] - temptable_1[i-1][0]);
253
-
254
-        break;
255
-      }
256
-    }
257
-
258
-    // Overflow: Set to last value in the table
259
-    if (i == NUMTEMPS_HEATER_1) celsius = temptable_1[i-1][1];
260
-
261
-    return celsius;
262
-  #elif defined HEATER_1_USES_AD595
263
-    return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
264
-  #endif
265
-}
266
-
267
-// Derived from RepRap FiveD extruder::getTemperature()
268
-// For bed temperature measurement.
269
-float analog2tempBed(int raw) {
270
-  #ifdef BED_USES_THERMISTOR
271
-    int celsius = 0;
272
-    byte i;
273
-
274
-    raw = (1023 * OVERSAMPLENR) - raw;
275
-
276
-    for (i=1; i<BNUMTEMPS; i++)
277
-    {
278
-      if (bedtemptable[i][0] > raw)
279
-      {
280
-        celsius  = bedtemptable[i-1][1] + 
281
-          (raw - bedtemptable[i-1][0]) * 
282
-          (bedtemptable[i][1] - bedtemptable[i-1][1]) /
283
-          (bedtemptable[i][0] - bedtemptable[i-1][0]);
284
-
285
-        break;
286
-      }
287
-    }
288
-
289
-    // Overflow: Set to last value in the table
290
-    if (i == BNUMTEMPS) celsius = bedtemptable[i-1][1];
291
-
292
-    return celsius;
293
-    
294
-  #elif defined BED_USES_AD595
295
-    return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
296
-  #endif
297
-}
298
-
299
-void tp_init()
300
-{
301
-#if (HEATER_0_PIN > -1) 
302
-  SET_OUTPUT(HEATER_0_PIN);
303
-#endif  
304
-#if (HEATER_1_PIN > -1) 
305
-  SET_OUTPUT(HEATER_1_PIN);
306
-#endif  
307
-#if (HEATER_2_PIN > -1) 
308
-  SET_OUTPUT(HEATER_2_PIN);
309
-#endif  
310
-
311
-#ifdef PIDTEMP
312
-  temp_iState_min = 0.0;
313
-  temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
314
-#endif //PIDTEMP
315
-
316
-// Set analog inputs
317
-  ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
318
-  
319
-// Use timer0 for temperature measurement
320
-// Interleave temperature interrupt with millies interrupt
321
-  OCR0B = 128;
322
-  TIMSK0 |= (1<<OCIE0B);  
323
-}
324
-
325
-static unsigned char temp_count = 0;
326
-static unsigned long raw_temp_0_value = 0;
327
-static unsigned long raw_temp_1_value = 0;
328
-static unsigned long raw_temp_2_value = 0;
329
-static unsigned char temp_state = 0;
330
-
331
-// Timer 0 is shared with millies
332
-ISR(TIMER0_COMPB_vect)
333
-{
334
-  switch(temp_state) {
335
-    case 0: // Prepare TEMP_0
336
-            #if (TEMP_0_PIN > -1)
337
-              #if TEMP_0_PIN < 8
338
-                DIDR0 = 1 << TEMP_0_PIN; 
339
-              #else
340
-                DIDR2 = 1<<(TEMP_0_PIN - 8); 
341
-                ADCSRB = 1<<MUX5;
342
-              #endif
343
-              ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
344
-              ADCSRA |= 1<<ADSC; // Start conversion
345
-            #endif
346
-            #ifdef ULTIPANEL
347
-              buttons_check();
348
-            #endif
349
-            temp_state = 1;
350
-            break;
351
-    case 1: // Measure TEMP_0
352
-            #if (TEMP_0_PIN > -1)
353
-              raw_temp_0_value += ADC;
354
-            #endif
355
-            temp_state = 2;
356
-            break;
357
-    case 2: // Prepare TEMP_1
358
-            #if (TEMP_1_PIN > -1)
359
-              #if TEMP_1_PIN < 7
360
-                DIDR0 = 1<<TEMP_1_PIN; 
361
-              #else
362
-                DIDR2 = 1<<(TEMP_1_PIN - 8); 
363
-                ADCSRB = 1<<MUX5;
364
-              #endif
365
-              ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
366
-              ADCSRA |= 1<<ADSC; // Start conversion
367
-            #endif
368
-            #ifdef ULTIPANEL
369
-              buttons_check();
370
-            #endif
371
-            temp_state = 3;
372
-            break;
373
-    case 3: // Measure TEMP_1
374
-            #if (TEMP_1_PIN > -1)
375
-              raw_temp_1_value += ADC;
376
-            #endif
377
-            temp_state = 4;
378
-            break;
379
-    case 4: // Prepare TEMP_2
380
-            #if (TEMP_2_PIN > -1)
381
-              #if TEMP_2_PIN < 7
382
-                DIDR0 = 1 << TEMP_2_PIN; 
383
-              #else
384
-                DIDR2 = 1<<(TEMP_2_PIN - 8); 
385
-                ADCSRB = 1<<MUX5;
386
-              #endif
387
-              ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
388
-              ADCSRA |= 1<<ADSC; // Start conversion
389
-            #endif
390
-            #ifdef ULTIPANEL
391
-              buttons_check();
392
-            #endif
393
-            temp_state = 5;
394
-            break;
395
-    case 5: // Measure TEMP_2
396
-            #if (TEMP_2_PIN > -1)
397
-              raw_temp_2_value += ADC;
398
-            #endif
399
-            temp_state = 0;
400
-            temp_count++;
401
-            break;
402
-    default:
403
-            Serial.println("!! Temp measurement error !!");
404
-            break;
405
-  }
406
-    
407
-  if(temp_count >= 16) // 6 ms * 16 = 96ms.
408
-  {
409
-    #ifdef HEATER_1_USES_AD595
410
-      current_raw[0] = raw_temp_0_value;
411
-    #else
412
-      current_raw[0] = 16383 - raw_temp_0_value;
413
-    #endif
414
-    
415
-    #ifdef HEATER_2_USES_AD595
416
-      current_raw[2] = raw_temp_2_value;
417
-    #else
418
-      current_raw[2] = 16383 - raw_temp_2_value;
419
-    #endif
420
-    
421
-    #ifdef BED_USES_AD595
422
-      current_raw[1] = raw_temp_1_value;
423
-    #else
424
-      current_raw[1] = 16383 - raw_temp_1_value;
425
-    #endif
426
-    
427
-    temp_meas_ready = true;
428
-    temp_count = 0;
429
-    raw_temp_0_value = 0;
430
-    raw_temp_1_value = 0;
431
-    raw_temp_2_value = 0;
432
-#ifdef MAXTEMP
433
-  #if (HEATER_0_PIN > -1)
165
+    {
166
+      WRITE(HEATER_1_PIN,LOW);
167
+    }
168
+    else 
169
+    {
170
+      WRITE(HEATER_1_PIN,HIGH);
171
+    }
172
+  #endif
173
+  }
174
+
175
+// Takes hot end temperature value as input and returns corresponding raw value. 
176
+// For a thermistor, it uses the RepRap thermistor temp table.
177
+// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
178
+// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
179
+float temp2analog(int celsius) {
180
+  #ifdef HEATER_USES_THERMISTOR_1
181
+    int raw = 0;
182
+    byte i;
183
+    
184
+    for (i=1; i<NUMTEMPS_HEATER_1; i++)
185
+    {
186
+      if (temptable_1[i][1] < celsius)
187
+      {
188
+        raw = temptable_1[i-1][0] + 
189
+          (celsius - temptable_1[i-1][1]) * 
190
+          (temptable_1[i][0] - temptable_1[i-1][0]) /
191
+          (temptable_1[i][1] - temptable_1[i-1][1]);
192
+      
193
+        break;
194
+      }
195
+    }
196
+
197
+    // Overflow: Set to last value in the table
198
+    if (i == NUMTEMPS_1) raw = temptable_1[i-1][0];
199
+
200
+    return (1023 * OVERSAMPLENR) - raw;
201
+  #elif defined HEATER_1_USES_AD595
202
+    return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
203
+  #endif
204
+}
205
+
206
+// Takes bed temperature value as input and returns corresponding raw value. 
207
+// For a thermistor, it uses the RepRap thermistor temp table.
208
+// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
209
+// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
210
+float temp2analogBed(int celsius) {
211
+  #ifdef BED_USES_THERMISTOR
212
+
213
+    int raw = 0;
214
+    byte i;
215
+    
216
+    for (i=1; i<BNUMTEMPS; i++)
217
+    {
218
+      if (bedtemptable[i][1] < celsius)
219
+      {
220
+        raw = bedtemptable[i-1][0] + 
221
+          (celsius - bedtemptable[i-1][1]) * 
222
+          (bedtemptable[i][0] - bedtemptable[i-1][0]) /
223
+          (bedtemptable[i][1] - bedtemptable[i-1][1]);
224
+      
225
+        break;
226
+      }
227
+    }
228
+
229
+    // Overflow: Set to last value in the table
230
+    if (i == BNUMTEMPS) raw = bedtemptable[i-1][0];
231
+
232
+    return (1023 * OVERSAMPLENR) - raw;
233
+  #elif defined BED_USES_AD595
234
+    return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
235
+  #endif
236
+}
237
+
238
+// Derived from RepRap FiveD extruder::getTemperature()
239
+// For hot end temperature measurement.
240
+float analog2temp(int raw) {
241
+  #ifdef HEATER_1_USES_THERMISTOR
242
+    int celsius = 0;
243
+    byte i;  
244
+    raw = (1023 * OVERSAMPLENR) - raw;
245
+    for (i=1; i<NUMTEMPS_HEATER_1; i++)
246
+    {
247
+      if (temptable_1[i][0] > raw)
248
+      {
249
+        celsius  = temptable_1[i-1][1] + 
250
+          (raw - temptable_1[i-1][0]) * 
251
+          (temptable_1[i][1] - temptable_1[i-1][1]) /
252
+          (temptable_1[i][0] - temptable_1[i-1][0]);
253
+
254
+        break;
255
+      }
256
+    }
257
+
258
+    // Overflow: Set to last value in the table
259
+    if (i == NUMTEMPS_HEATER_1) celsius = temptable_1[i-1][1];
260
+
261
+    return celsius;
262
+  #elif defined HEATER_1_USES_AD595
263
+    return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
264
+  #endif
265
+}
266
+
267
+// Derived from RepRap FiveD extruder::getTemperature()
268
+// For bed temperature measurement.
269
+float analog2tempBed(int raw) {
270
+  #ifdef BED_USES_THERMISTOR
271
+    int celsius = 0;
272
+    byte i;
273
+
274
+    raw = (1023 * OVERSAMPLENR) - raw;
275
+
276
+    for (i=1; i<BNUMTEMPS; i++)
277
+    {
278
+      if (bedtemptable[i][0] > raw)
279
+      {
280
+        celsius  = bedtemptable[i-1][1] + 
281
+          (raw - bedtemptable[i-1][0]) * 
282
+          (bedtemptable[i][1] - bedtemptable[i-1][1]) /
283
+          (bedtemptable[i][0] - bedtemptable[i-1][0]);
284
+
285
+        break;
286
+      }
287
+    }
288
+
289
+    // Overflow: Set to last value in the table
290
+    if (i == BNUMTEMPS) celsius = bedtemptable[i-1][1];
291
+
292
+    return celsius;
293
+    
294
+  #elif defined BED_USES_AD595
295
+    return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
296
+  #endif
297
+}
298
+
299
+void tp_init()
300
+{
301
+#if (HEATER_0_PIN > -1) 
302
+  SET_OUTPUT(HEATER_0_PIN);
303
+#endif  
304
+#if (HEATER_1_PIN > -1) 
305
+  SET_OUTPUT(HEATER_1_PIN);
306
+#endif  
307
+#if (HEATER_2_PIN > -1) 
308
+  SET_OUTPUT(HEATER_2_PIN);
309
+#endif  
310
+
311
+#ifdef PIDTEMP
312
+  temp_iState_min = 0.0;
313
+  temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
314
+#endif //PIDTEMP
315
+
316
+// Set analog inputs
317
+  ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
318
+  
319
+// Use timer0 for temperature measurement
320
+// Interleave temperature interrupt with millies interrupt
321
+  OCR0B = 128;
322
+  TIMSK0 |= (1<<OCIE0B);  
323
+}
324
+
325
+static unsigned char temp_count = 0;
326
+static unsigned long raw_temp_0_value = 0;
327
+static unsigned long raw_temp_1_value = 0;
328
+static unsigned long raw_temp_2_value = 0;
329
+static unsigned char temp_state = 0;
330
+
331
+// Timer 0 is shared with millies
332
+ISR(TIMER0_COMPB_vect)
333
+{
334
+  switch(temp_state) {
335
+    case 0: // Prepare TEMP_0
336
+            #if (TEMP_0_PIN > -1)
337
+              #if TEMP_0_PIN < 8
338
+                DIDR0 = 1 << TEMP_0_PIN; 
339
+              #else
340
+                DIDR2 = 1<<(TEMP_0_PIN - 8); 
341
+                ADCSRB = 1<<MUX5;
342
+              #endif
343
+              ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
344
+              ADCSRA |= 1<<ADSC; // Start conversion
345
+            #endif
346
+            #ifdef ULTIPANEL
347
+              buttons_check();
348
+            #endif
349
+            temp_state = 1;
350
+            break;
351
+    case 1: // Measure TEMP_0
352
+            #if (TEMP_0_PIN > -1)
353
+              raw_temp_0_value += ADC;
354
+            #endif
355
+            temp_state = 2;
356
+            break;
357
+    case 2: // Prepare TEMP_1
358
+            #if (TEMP_1_PIN > -1)
359
+              #if TEMP_1_PIN < 7
360
+                DIDR0 = 1<<TEMP_1_PIN; 
361
+              #else
362
+                DIDR2 = 1<<(TEMP_1_PIN - 8); 
363
+                ADCSRB = 1<<MUX5;
364
+              #endif
365
+              ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
366
+              ADCSRA |= 1<<ADSC; // Start conversion
367
+            #endif
368
+            #ifdef ULTIPANEL
369
+              buttons_check();
370
+            #endif
371
+            temp_state = 3;
372
+            break;
373
+    case 3: // Measure TEMP_1
374
+            #if (TEMP_1_PIN > -1)
375
+              raw_temp_1_value += ADC;
376
+            #endif
377
+            temp_state = 4;
378
+            break;
379
+    case 4: // Prepare TEMP_2
380
+            #if (TEMP_2_PIN > -1)
381
+              #if TEMP_2_PIN < 7
382
+                DIDR0 = 1 << TEMP_2_PIN; 
383
+              #else
384
+                DIDR2 = 1<<(TEMP_2_PIN - 8); 
385
+                ADCSRB = 1<<MUX5;
386
+              #endif
387
+              ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
388
+              ADCSRA |= 1<<ADSC; // Start conversion
389
+            #endif
390
+            #ifdef ULTIPANEL
391
+              buttons_check();
392
+            #endif
393
+            temp_state = 5;
394
+            break;
395
+    case 5: // Measure TEMP_2
396
+            #if (TEMP_2_PIN > -1)
397
+              raw_temp_2_value += ADC;
398
+            #endif
399
+            temp_state = 0;
400
+            temp_count++;
401
+            break;
402
+    default:
403
+            Serial.println("!! Temp measurement error !!");
404
+            break;
405
+  }
406
+    
407
+  if(temp_count >= 16) // 6 ms * 16 = 96ms.
408
+  {
409
+    #ifdef HEATER_1_USES_AD595
410
+      current_raw[0] = raw_temp_0_value;
411
+    #else
412
+      current_raw[0] = 16383 - raw_temp_0_value;
413
+    #endif
414
+    
415
+    #ifdef HEATER_2_USES_AD595
416
+      current_raw[2] = raw_temp_2_value;
417
+    #else
418
+      current_raw[2] = 16383 - raw_temp_2_value;
419
+    #endif
420
+    
421
+    #ifdef BED_USES_AD595
422
+      current_raw[1] = raw_temp_1_value;
423
+    #else
424
+      current_raw[1] = 16383 - raw_temp_1_value;
425
+    #endif
426
+    
427
+    temp_meas_ready = true;
428
+    temp_count = 0;
429
+    raw_temp_0_value = 0;
430
+    raw_temp_1_value = 0;
431
+    raw_temp_2_value = 0;
432
+#ifdef MAXTEMP
433
+  #if (HEATER_0_PIN > -1)
434 434
     if(current_raw[TEMPSENSOR_HOTEND] >= maxttemp) {
435 435
       target_raw[TEMPSENSOR_HOTEND] = 0;
436
-      analogWrite(HEATER_0_PIN, 0);
437
-      Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!");
438
-    }
439
-  #endif
440
-  #if (HEATER_2_PIN > -1)
436
+      analogWrite(HEATER_0_PIN, 0);
437
+      Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!");
438
+    }
439
+  #endif
440
+  #if (HEATER_2_PIN > -1)
441 441
     if(current_raw[TEMPSENSOR_AUX] >= maxttemp) {
442 442
       target_raw[TEMPSENSOR_AUX] = 0;
443
-      analogWrite(HEATER_2_PIN, 0);
444
-      Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!");
445
-    }
446
-  #endif
447
-#endif //MAXTEMP
448
-#ifdef MINTEMP
449
-  #if (HEATER_0_PIN > -1)
443
+      analogWrite(HEATER_2_PIN, 0);
444
+      Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!");
445
+    }
446
+  #endif
447
+#endif //MAXTEMP
448
+#ifdef MINTEMP
449
+  #if (HEATER_0_PIN > -1)
450 450
     if(current_raw[TEMPSENSOR_HOTEND] <= minttemp) {
451 451
       target_raw[TEMPSENSOR_HOTEND] = 0;
452
-      analogWrite(HEATER_0_PIN, 0);
453
-      Serial.println("!! Temperature extruder 0 switched off. MINTEMP triggered !!");
454
-    }
455
-  #endif
456
-  #if (HEATER_2_PIN > -1)
452
+      analogWrite(HEATER_0_PIN, 0);
453
+      Serial.println("!! Temperature extruder 0 switched off. MINTEMP triggered !!");
454
+    }
455
+  #endif
456
+  #if (HEATER_2_PIN > -1)
457 457
     if(current_raw[TEMPSENSOR_AUX] <= minttemp) {
458 458
       target_raw[TEMPSENSOR_AUX] = 0;
459
-      analogWrite(HEATER_2_PIN, 0);
460
-      Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!");
461
-    }
462
-  #endif
463
-#endif //MAXTEMP
464
-#ifdef BED_MINTEMP
465
-  #if (HEATER_1_PIN > -1)
466
-    if(current_raw[1] <= bed_minttemp) {
467
-      target_raw[1] = 0;
468
-      WRITE(HEATER_1_PIN, 0);
469
-      Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!");
470
-    }
471
-  #endif
472
-#endif
473
-#ifdef BED_MAXTEMP
474
-  #if (HEATER_1_PIN > -1)
475
-    if(current_raw[1] >= bed_maxttemp) {
476
-      target_raw[1] = 0;
477
-      WRITE(HEATER_1_PIN, 0);
478
-      Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!");
479
-    }
480
-  #endif
481
-#endif
482
-  }
483
-}
459
+      analogWrite(HEATER_2_PIN, 0);
460
+      Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!");
461
+    }
462
+  #endif
463
+#endif //MAXTEMP
464
+#ifdef BED_MINTEMP
465
+  #if (HEATER_1_PIN > -1)
466
+    if(current_raw[1] <= bed_minttemp) {
467
+      target_raw[1] = 0;
468
+      WRITE(HEATER_1_PIN, 0);
469
+      Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!");
470
+    }
471
+  #endif
472
+#endif
473
+#ifdef BED_MAXTEMP
474
+  #if (HEATER_1_PIN > -1)
475
+    if(current_raw[1] >= bed_maxttemp) {
476
+      target_raw[1] = 0;
477
+      WRITE(HEATER_1_PIN, 0);
478
+      Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!");
479
+    }
480
+  #endif
481
+#endif
482
+  }
483
+}

+ 410
- 410
Marlin/thermistortables.h View File

@@ -1,410 +1,410 @@
1
-#ifndef THERMISTORTABLES_H_
2
-#define THERMISTORTABLES_H_
3
-
4
-#define OVERSAMPLENR 16
5
-
6
-#if (THERMISTORHEATER_1 == 1) || (THERMISTORHEATER_2 == 1) || (THERMISTORBED == 1) //100k bed thermistor
7
-
8
-#define NUMTEMPS_1 61
9
-const short temptable_1[NUMTEMPS_1][2] = {
10
-{       23*OVERSAMPLENR ,       300     },
11
-{       25*OVERSAMPLENR ,       295     },
12
-{       27*OVERSAMPLENR ,       290     },
13
-{       28*OVERSAMPLENR ,       285     },
14
-{       31*OVERSAMPLENR ,       280     },
15
-{       33*OVERSAMPLENR ,       275     },
16
-{       35*OVERSAMPLENR ,       270     },
17
-{       38*OVERSAMPLENR ,       265     },
18
-{       41*OVERSAMPLENR ,       260     },
19
-{       44*OVERSAMPLENR ,       255     },
20
-{       48*OVERSAMPLENR ,       250     },
21
-{       52*OVERSAMPLENR ,       245     },
22
-{       56*OVERSAMPLENR ,       240     },
23
-{       61*OVERSAMPLENR ,       235     },
24
-{       66*OVERSAMPLENR ,       230     },
25
-{       71*OVERSAMPLENR ,       225     },
26
-{       78*OVERSAMPLENR ,       220     },
27
-{       84*OVERSAMPLENR ,       215     },
28
-{       92*OVERSAMPLENR ,       210     },
29
-{       100*OVERSAMPLENR        ,       205     },
30
-{       109*OVERSAMPLENR        ,       200     },
31
-{       120*OVERSAMPLENR        ,       195     },
32
-{       131*OVERSAMPLENR        ,       190     },
33
-{       143*OVERSAMPLENR        ,       185     },
34
-{       156*OVERSAMPLENR        ,       180     },
35
-{       171*OVERSAMPLENR        ,       175     },
36
-{       187*OVERSAMPLENR        ,       170     },
37
-{       205*OVERSAMPLENR        ,       165     },
38
-{       224*OVERSAMPLENR        ,       160     },
39
-{       245*OVERSAMPLENR        ,       155     },
40
-{       268*OVERSAMPLENR        ,       150     },
41
-{       293*OVERSAMPLENR        ,       145     },
42
-{       320*OVERSAMPLENR        ,       140     },
43
-{       348*OVERSAMPLENR        ,       135     },
44
-{       379*OVERSAMPLENR        ,       130     },
45
-{       411*OVERSAMPLENR        ,       125     },
46
-{       445*OVERSAMPLENR        ,       120     },
47
-{       480*OVERSAMPLENR        ,       115     },
48
-{       516*OVERSAMPLENR        ,       110     },
49
-{       553*OVERSAMPLENR        ,       105     },
50
-{       591*OVERSAMPLENR        ,       100     },
51
-{       628*OVERSAMPLENR        ,       95      },
52
-{       665*OVERSAMPLENR        ,       90      },
53
-{       702*OVERSAMPLENR        ,       85      },
54
-{       737*OVERSAMPLENR        ,       80      },
55
-{       770*OVERSAMPLENR        ,       75      },
56
-{       801*OVERSAMPLENR        ,       70      },
57
-{       830*OVERSAMPLENR        ,       65      },
58
-{       857*OVERSAMPLENR        ,       60      },
59
-{       881*OVERSAMPLENR        ,       55      },
60
-{       903*OVERSAMPLENR        ,       50      },
61
-{       922*OVERSAMPLENR        ,       45      },
62
-{       939*OVERSAMPLENR        ,       40      },
63
-{       954*OVERSAMPLENR        ,       35      },
64
-{       966*OVERSAMPLENR        ,       30      },
65
-{       977*OVERSAMPLENR        ,       25      },
66
-{       985*OVERSAMPLENR        ,       20      },
67
-{       993*OVERSAMPLENR        ,       15      },
68
-{       999*OVERSAMPLENR        ,       10      },
69
-{       1004*OVERSAMPLENR       ,       5       },
70
-{       1008*OVERSAMPLENR       ,       0       } //safety
71
-};
72
-#endif
73
-#if (THERMISTORHEATER_1 == 2) || (THERMISTORHEATER_2 == 2) || (THERMISTORBED == 2) //200k bed thermistor
74
-#define NUMTEMPS_2 21
75
-const short temptable_2[NUMTEMPS_2][2] = {
76
-   {1*OVERSAMPLENR, 848},
77
-   {54*OVERSAMPLENR, 275},
78
-   {107*OVERSAMPLENR, 228},
79
-   {160*OVERSAMPLENR, 202},
80
-   {213*OVERSAMPLENR, 185},
81
-   {266*OVERSAMPLENR, 171},
82
-   {319*OVERSAMPLENR, 160},
83
-   {372*OVERSAMPLENR, 150},
84
-   {425*OVERSAMPLENR, 141},
85
-   {478*OVERSAMPLENR, 133},
86
-   {531*OVERSAMPLENR, 125},
87
-   {584*OVERSAMPLENR, 118},
88
-   {637*OVERSAMPLENR, 110},
89
-   {690*OVERSAMPLENR, 103},
90
-   {743*OVERSAMPLENR, 95},
91
-   {796*OVERSAMPLENR, 86},
92
-   {849*OVERSAMPLENR, 77},
93
-   {902*OVERSAMPLENR, 65},
94
-   {955*OVERSAMPLENR, 49},
95
-   {1008*OVERSAMPLENR, 17},
96
-   {1020*OVERSAMPLENR, 0} //safety
97
-};
98
-
99
-#endif
100
-#if (THERMISTORHEATER_1 == 3) || (THERMISTORHEATER_2 == 3) || (THERMISTORBED == 3) //mendel-parts
101
-#define NUMTEMPS_3 28
102
-const short temptable_3[NUMTEMPS_3][2] = {
103
-                {1*OVERSAMPLENR,864},
104
-                {21*OVERSAMPLENR,300},
105
-                {25*OVERSAMPLENR,290},
106
-                {29*OVERSAMPLENR,280},
107
-                {33*OVERSAMPLENR,270},
108
-                {39*OVERSAMPLENR,260},
109
-                {46*OVERSAMPLENR,250},
110
-                {54*OVERSAMPLENR,240},
111
-                {64*OVERSAMPLENR,230},
112
-                {75*OVERSAMPLENR,220},
113
-                {90*OVERSAMPLENR,210},
114
-                {107*OVERSAMPLENR,200},
115
-                {128*OVERSAMPLENR,190},
116
-                {154*OVERSAMPLENR,180},
117
-                {184*OVERSAMPLENR,170},
118
-                {221*OVERSAMPLENR,160},
119
-                {265*OVERSAMPLENR,150},
120
-                {316*OVERSAMPLENR,140},
121
-                {375*OVERSAMPLENR,130},
122
-                {441*OVERSAMPLENR,120},
123
-                {513*OVERSAMPLENR,110},
124
-                {588*OVERSAMPLENR,100},
125
-                {734*OVERSAMPLENR,80},
126
-                {856*OVERSAMPLENR,60},
127
-                {938*OVERSAMPLENR,40},
128
-                {986*OVERSAMPLENR,20},
129
-                {1008*OVERSAMPLENR,0},
130
-                {1018*OVERSAMPLENR,-20}
131
-        };
132
-
133
-#endif
134
-#if (THERMISTORHEATER_1 == 4) || (THERMISTORHEATER_2 == 4) || (THERMISTORBED == 4) //10k thermistor
135
-
136
-#define NUMTEMPS_4 20
137
-short temptable_4[NUMTEMPS_4][2] = {
138
-   {1*OVERSAMPLENR, 430},
139
-   {54*OVERSAMPLENR, 137},
140
-   {107*OVERSAMPLENR, 107},
141
-   {160*OVERSAMPLENR, 91},
142
-   {213*OVERSAMPLENR, 80},
143
-   {266*OVERSAMPLENR, 71},
144
-   {319*OVERSAMPLENR, 64},
145
-   {372*OVERSAMPLENR, 57},
146
-   {425*OVERSAMPLENR, 51},
147
-   {478*OVERSAMPLENR, 46},
148
-   {531*OVERSAMPLENR, 41},
149
-   {584*OVERSAMPLENR, 35},
150
-   {637*OVERSAMPLENR, 30},
151
-   {690*OVERSAMPLENR, 25},
152
-   {743*OVERSAMPLENR, 20},
153
-   {796*OVERSAMPLENR, 14},
154
-   {849*OVERSAMPLENR, 7},
155
-   {902*OVERSAMPLENR, 0},
156
-   {955*OVERSAMPLENR, -11},
157
-   {1008*OVERSAMPLENR, -35}
158
-};
159
-#endif
160
-
161
-#if (THERMISTORHEATER_1 == 5) || (THERMISTORHEATER_2 == 5) || (THERMISTORBED == 5) //100k ParCan thermistor (104GT-2)
162
-
163
-#define NUMTEMPS_5 61
164
-const short temptable_5[NUMTEMPS_5][2] = {
165
-{1*OVERSAMPLENR, 713},
166
-{18*OVERSAMPLENR, 316},
167
-{35*OVERSAMPLENR, 266},
168
-{52*OVERSAMPLENR, 239},
169
-{69*OVERSAMPLENR, 221},
170
-{86*OVERSAMPLENR, 208},
171
-{103*OVERSAMPLENR, 197},
172
-{120*OVERSAMPLENR, 188},
173
-{137*OVERSAMPLENR, 181},
174
-{154*OVERSAMPLENR, 174},
175
-{171*OVERSAMPLENR, 169},
176
-{188*OVERSAMPLENR, 163},
177
-{205*OVERSAMPLENR, 159},
178
-{222*OVERSAMPLENR, 154},
179
-{239*OVERSAMPLENR, 150},
180
-{256*OVERSAMPLENR, 147},
181
-{273*OVERSAMPLENR, 143},
182
-{290*OVERSAMPLENR, 140},
183
-{307*OVERSAMPLENR, 136},
184
-{324*OVERSAMPLENR, 133},
185
-{341*OVERSAMPLENR, 130},
186
-{358*OVERSAMPLENR, 128},
187
-{375*OVERSAMPLENR, 125},
188
-{392*OVERSAMPLENR, 122},
189
-{409*OVERSAMPLENR, 120},
190
-{426*OVERSAMPLENR, 117},
191
-{443*OVERSAMPLENR, 115},
192
-{460*OVERSAMPLENR, 112},
193
-{477*OVERSAMPLENR, 110},
194
-{494*OVERSAMPLENR, 108},
195
-{511*OVERSAMPLENR, 106},
196
-{528*OVERSAMPLENR, 103},
197
-{545*OVERSAMPLENR, 101},
198
-{562*OVERSAMPLENR, 99},
199
-{579*OVERSAMPLENR, 97},
200
-{596*OVERSAMPLENR, 95},
201
-{613*OVERSAMPLENR, 92},
202
-{630*OVERSAMPLENR, 90},
203
-{647*OVERSAMPLENR, 88},
204
-{664*OVERSAMPLENR, 86},
205
-{681*OVERSAMPLENR, 84},
206
-{698*OVERSAMPLENR, 81},
207
-{715*OVERSAMPLENR, 79},
208
-{732*OVERSAMPLENR, 77},
209
-{749*OVERSAMPLENR, 75},
210
-{766*OVERSAMPLENR, 72},
211
-{783*OVERSAMPLENR, 70},
212
-{800*OVERSAMPLENR, 67},
213
-{817*OVERSAMPLENR, 64},
214
-{834*OVERSAMPLENR, 61},
215
-{851*OVERSAMPLENR, 58},
216
-{868*OVERSAMPLENR, 55},
217
-{885*OVERSAMPLENR, 52},
218
-{902*OVERSAMPLENR, 48},
219
-{919*OVERSAMPLENR, 44},
220
-{936*OVERSAMPLENR, 40},
221
-{953*OVERSAMPLENR, 34},
222
-{970*OVERSAMPLENR, 28},
223
-{987*OVERSAMPLENR, 20},
224
-{1004*OVERSAMPLENR, 8},
225
-{1021*OVERSAMPLENR, 0}
226
-};
227
-#endif
228
-
229
-#if (THERMISTORHEATER_1 == 6) || (THERMISTORHEATER_2 == 6) || (THERMISTORBED == 6) // 100k Epcos thermistor
230
-#define NUMTEMPS_6 36
231
-const short temptable_6[NUMTEMPS_6][2] = {
232
-   {28*OVERSAMPLENR, 250},
233
-   {31*OVERSAMPLENR, 245},
234
-   {35*OVERSAMPLENR, 240},
235
-   {39*OVERSAMPLENR, 235},
236
-   {42*OVERSAMPLENR, 230},
237
-   {44*OVERSAMPLENR, 225},
238
-   {49*OVERSAMPLENR, 220},
239
-   {53*OVERSAMPLENR, 215},
240
-   {62*OVERSAMPLENR, 210},
241
-   {73*OVERSAMPLENR, 205},
242
-   {72*OVERSAMPLENR, 200},
243
-   {94*OVERSAMPLENR, 190},
244
-   {102*OVERSAMPLENR, 185},
245
-   {116*OVERSAMPLENR, 170},
246
-   {143*OVERSAMPLENR, 160},
247
-   {183*OVERSAMPLENR, 150},
248
-   {223*OVERSAMPLENR, 140},
249
-   {270*OVERSAMPLENR, 130},
250
-   {318*OVERSAMPLENR, 120},
251
-   {383*OVERSAMPLENR, 110},
252
-   {413*OVERSAMPLENR, 105},
253
-   {439*OVERSAMPLENR, 100},
254
-   {484*OVERSAMPLENR, 95},
255
-   {513*OVERSAMPLENR, 90},
256
-   {607*OVERSAMPLENR, 80},
257
-   {664*OVERSAMPLENR, 70},
258
-   {781*OVERSAMPLENR, 60},
259
-   {810*OVERSAMPLENR, 55},
260
-   {849*OVERSAMPLENR, 50},
261
-   {914*OVERSAMPLENR, 45},
262
-   {914*OVERSAMPLENR, 40},
263
-   {935*OVERSAMPLENR, 35},
264
-   {954*OVERSAMPLENR, 30},
265
-   {970*OVERSAMPLENR, 25},
266
-   {978*OVERSAMPLENR, 22},
267
-   {1008*OVERSAMPLENR, 3}
268
-};
269
-#endif
270
-
271
-#if (THERMISTORHEATER_1 == 7) || (THERMISTORHEATER_2 == 7) || (THERMISTORBED == 7) // 100k Honeywell 135-104LAG-J01
272
-#define NUMTEMPS_7 54
273
-const short temptable_7[NUMTEMPS_7][2] = {
274
-   {46*OVERSAMPLENR, 270},
275
-   {50*OVERSAMPLENR, 265},
276
-   {54*OVERSAMPLENR, 260},
277
-   {58*OVERSAMPLENR, 255},
278
-   {62*OVERSAMPLENR, 250},
279
-   {67*OVERSAMPLENR, 245},
280
-   {72*OVERSAMPLENR, 240},
281
-   {79*OVERSAMPLENR, 235},
282
-   {85*OVERSAMPLENR, 230},
283
-   {91*OVERSAMPLENR, 225},
284
-   {99*OVERSAMPLENR, 220},
285
-   {107*OVERSAMPLENR, 215},
286
-   {116*OVERSAMPLENR, 210},
287
-   {126*OVERSAMPLENR, 205},
288
-   {136*OVERSAMPLENR, 200},
289
-   {149*OVERSAMPLENR, 195},
290
-   {160*OVERSAMPLENR, 190},
291
-   {175*OVERSAMPLENR, 185},
292
-   {191*OVERSAMPLENR, 180},
293
-   {209*OVERSAMPLENR, 175},
294
-   {224*OVERSAMPLENR, 170},
295
-   {246*OVERSAMPLENR, 165},
296
-   {267*OVERSAMPLENR, 160},
297
-   {293*OVERSAMPLENR, 155},
298
-   {316*OVERSAMPLENR, 150},
299
-   {340*OVERSAMPLENR, 145},
300
-   {364*OVERSAMPLENR, 140},
301
-   {396*OVERSAMPLENR, 135},
302
-   {425*OVERSAMPLENR, 130},
303
-   {460*OVERSAMPLENR, 125},
304
-   {489*OVERSAMPLENR, 120},
305
-   {526*OVERSAMPLENR, 115},
306
-   {558*OVERSAMPLENR, 110},
307
-   {591*OVERSAMPLENR, 105},
308
-   {628*OVERSAMPLENR, 100},
309
-   {660*OVERSAMPLENR, 95},
310
-   {696*OVERSAMPLENR, 90},
311
-   {733*OVERSAMPLENR, 85},
312
-   {761*OVERSAMPLENR, 80},
313
-   {794*OVERSAMPLENR, 75},
314
-   {819*OVERSAMPLENR, 70},
315
-   {847*OVERSAMPLENR, 65},
316
-   {870*OVERSAMPLENR, 60},
317
-   {892*OVERSAMPLENR, 55},
318
-   {911*OVERSAMPLENR, 50},
319
-   {929*OVERSAMPLENR, 45},
320
-   {944*OVERSAMPLENR, 40},
321
-   {959*OVERSAMPLENR, 35},
322
-   {971*OVERSAMPLENR, 30},
323
-   {981*OVERSAMPLENR, 25},
324
-   {989*OVERSAMPLENR, 20},
325
-   {994*OVERSAMPLENR, 15},
326
-   {1001*OVERSAMPLENR, 10},
327
-   {1005*OVERSAMPLENR, 5}
328
-};
329
-#endif
330
-
331
-
332
-
333
-#if THERMISTORHEATER_1 == 1
334
-#define NUMTEMPS_HEATER_1 NUMTEMPS_1
335
-#define temptable_1 temptable_1
336
-#elif THERMISTORHEATER_1 == 2
337
-#define NUMTEMPS_HEATER_1 NUMTEMPS_2
338
-#define temptable_1 temptable_2
339
-#elif THERMISTORHEATER_1 == 3
340
-#define NUMTEMPS_HEATER_1 NUMTEMPS_3
341
-#define temptable_1 temptable_3
342
-#elif THERMISTORHEATER_1 == 4
343
-#define NUMTEMPS_HEATER_1 NUMTEMPS_4
344
-#define temptable_1 temptable_4
345
-#elif THERMISTORHEATER_1 == 5
346
-#define NUMTEMPS_HEATER_1 NUMTEMPS_5
347
-#define temptable_1 temptable_5
348
-#elif THERMISTORHEATER_1 == 6
349
-#define NUMTEMPS_HEATER_1 NUMTEMPS_6
350
-#define temptable_1 temptable_6
351
-#elif THERMISTORHEATER_1 == 7
352
-#define NUMTEMPS_HEATER_1 NUMTEMPS_7
353
-#define temptable_1 temptable_7
354
-#elif defined HEATER_1_USES_THERMISTOR
355
-#error No heater 1 thermistor table specified
356
-#endif
357
-
358
-#if THERMISTORHEATER_2 == 1
359
-#define NUMTEMPS_HEATER_2 NUMTEMPS_1
360
-#define temptable_2 temptable_1
361
-#elif THERMISTORHEATER_2 == 2
362
-#define NUMTEMPS_HEATER_2 NUMTEMPS_2
363
-#define temptable_2 temptable_2
364
-#elif THERMISTORHEATER_2 == 3
365
-#define NUMTEMPS_HEATER_2 NUMTEMPS_3
366
-#define temptable_2 temptable_3
367
-#elif THERMISTORHEATER_2 == 4
368
-#define NUMTEMPS_HEATER_2 NUMTEMPS_4
369
-#define temptable_2 temptable_4
370
-#elif THERMISTORHEATER_2 == 5
371
-#define NUMTEMPS_HEATER_2 NUMTEMPS_5
372
-#define temptable_2 temptable_5
373
-#elif THERMISTORHEATER_2 == 6
374
-#define NUMTEMPS_HEATER_2 NUMTEMPS_6
375
-#define temptable_2 temptable_6
376
-#elif THERMISTORHEATER_2 == 7
377
-#define NUMTEMPS_HEATER22 NUMTEMPS_7
378
-#define temptable_2 temptable_7
379
-#elif defined HEATER_2_USES_THERMISTOR
380
-#error No heater 2 thermistor table specified
381
-#endif
382
-
383
-
384
-#if THERMISTORBED == 1
385
-#define BNUMTEMPS NUMTEMPS_1
386
-#define bedtemptable temptable_1
387
-#elif THERMISTORBED == 2
388
-#define BNUMTEMPS NUMTEMPS_2
389
-#define bedtemptable temptable_2
390
-#elif THERMISTORBED == 3
391
-#define BNUMTEMPS NUMTEMPS_3
392
-#define bedtemptable temptable_3
393
-#elif THERMISTORBED == 4
394
-#define BNUMTEMPS NUMTEMPS_4
395
-#define bedtemptable temptable_4
396
-#elif THERMISTORBED == 5
397
-#define BNUMTEMPS NUMTEMPS_5
398
-#define bedtemptable temptable_5
399
-#elif THERMISTORBED == 6
400
-#define BNUMTEMPS NUMTEMPS_6
401
-#define bedtemptable temptable_6
402
-#elif THERMISTORBED == 7
403
-#define BNUMTEMPS NUMTEMPS_7
404
-#define bedtemptable temptable_7
405
-#elif defined BED_USES_THERMISTOR
406
-#error No bed thermistor table specified
407
-#endif
408
-
409
-#endif //THERMISTORTABLES_H_
410
-
1
+#ifndef THERMISTORTABLES_H_
2
+#define THERMISTORTABLES_H_
3
+
4
+#define OVERSAMPLENR 16
5
+
6
+#if (THERMISTORHEATER_1 == 1) || (THERMISTORHEATER_2 == 1) || (THERMISTORBED == 1) //100k bed thermistor
7
+
8
+#define NUMTEMPS_1 61
9
+const short temptable_1[NUMTEMPS_1][2] = {
10
+{       23*OVERSAMPLENR ,       300     },
11
+{       25*OVERSAMPLENR ,       295     },
12
+{       27*OVERSAMPLENR ,       290     },
13
+{       28*OVERSAMPLENR ,       285     },
14
+{       31*OVERSAMPLENR ,       280     },
15
+{       33*OVERSAMPLENR ,       275     },
16
+{       35*OVERSAMPLENR ,       270     },
17
+{       38*OVERSAMPLENR ,       265     },
18
+{       41*OVERSAMPLENR ,       260     },
19
+{       44*OVERSAMPLENR ,       255     },
20
+{       48*OVERSAMPLENR ,       250     },
21
+{       52*OVERSAMPLENR ,       245     },
22
+{       56*OVERSAMPLENR ,       240     },
23
+{       61*OVERSAMPLENR ,       235     },
24
+{       66*OVERSAMPLENR ,       230     },
25
+{       71*OVERSAMPLENR ,       225     },
26
+{       78*OVERSAMPLENR ,       220     },
27
+{       84*OVERSAMPLENR ,       215     },
28
+{       92*OVERSAMPLENR ,       210     },
29
+{       100*OVERSAMPLENR        ,       205     },
30
+{       109*OVERSAMPLENR        ,       200     },
31
+{       120*OVERSAMPLENR        ,       195     },
32
+{       131*OVERSAMPLENR        ,       190     },
33
+{       143*OVERSAMPLENR        ,       185     },
34
+{       156*OVERSAMPLENR        ,       180     },
35
+{       171*OVERSAMPLENR        ,       175     },
36
+{       187*OVERSAMPLENR        ,       170     },
37
+{       205*OVERSAMPLENR        ,       165     },
38
+{       224*OVERSAMPLENR        ,       160     },
39
+{       245*OVERSAMPLENR        ,       155     },
40
+{       268*OVERSAMPLENR        ,       150     },
41
+{       293*OVERSAMPLENR        ,       145     },
42
+{       320*OVERSAMPLENR        ,       140     },
43
+{       348*OVERSAMPLENR        ,       135     },
44
+{       379*OVERSAMPLENR        ,       130     },
45
+{       411*OVERSAMPLENR        ,       125     },
46
+{       445*OVERSAMPLENR        ,       120     },
47
+{       480*OVERSAMPLENR        ,       115     },
48
+{       516*OVERSAMPLENR        ,       110     },
49
+{       553*OVERSAMPLENR        ,       105     },
50
+{       591*OVERSAMPLENR        ,       100     },
51
+{       628*OVERSAMPLENR        ,       95      },
52
+{       665*OVERSAMPLENR        ,       90      },
53
+{       702*OVERSAMPLENR        ,       85      },
54
+{       737*OVERSAMPLENR        ,       80      },
55
+{       770*OVERSAMPLENR        ,       75      },
56
+{       801*OVERSAMPLENR        ,       70      },
57
+{       830*OVERSAMPLENR        ,       65      },
58
+{       857*OVERSAMPLENR        ,       60      },
59
+{       881*OVERSAMPLENR        ,       55      },
60
+{       903*OVERSAMPLENR        ,       50      },
61
+{       922*OVERSAMPLENR        ,       45      },
62
+{       939*OVERSAMPLENR        ,       40      },
63
+{       954*OVERSAMPLENR        ,       35      },
64
+{       966*OVERSAMPLENR        ,       30      },
65
+{       977*OVERSAMPLENR        ,       25      },
66
+{       985*OVERSAMPLENR        ,       20      },
67
+{       993*OVERSAMPLENR        ,       15      },
68
+{       999*OVERSAMPLENR        ,       10      },
69
+{       1004*OVERSAMPLENR       ,       5       },
70
+{       1008*OVERSAMPLENR       ,       0       } //safety
71
+};
72
+#endif
73
+#if (THERMISTORHEATER_1 == 2) || (THERMISTORHEATER_2 == 2) || (THERMISTORBED == 2) //200k bed thermistor
74
+#define NUMTEMPS_2 21
75
+const short temptable_2[NUMTEMPS_2][2] = {
76
+   {1*OVERSAMPLENR, 848},
77
+   {54*OVERSAMPLENR, 275},
78
+   {107*OVERSAMPLENR, 228},
79
+   {160*OVERSAMPLENR, 202},
80
+   {213*OVERSAMPLENR, 185},
81
+   {266*OVERSAMPLENR, 171},
82
+   {319*OVERSAMPLENR, 160},
83
+   {372*OVERSAMPLENR, 150},
84
+   {425*OVERSAMPLENR, 141},
85
+   {478*OVERSAMPLENR, 133},
86
+   {531*OVERSAMPLENR, 125},
87
+   {584*OVERSAMPLENR, 118},
88
+   {637*OVERSAMPLENR, 110},
89
+   {690*OVERSAMPLENR, 103},
90
+   {743*OVERSAMPLENR, 95},
91
+   {796*OVERSAMPLENR, 86},
92
+   {849*OVERSAMPLENR, 77},
93
+   {902*OVERSAMPLENR, 65},
94
+   {955*OVERSAMPLENR, 49},
95
+   {1008*OVERSAMPLENR, 17},
96
+   {1020*OVERSAMPLENR, 0} //safety
97
+};
98
+
99
+#endif
100
+#if (THERMISTORHEATER_1 == 3) || (THERMISTORHEATER_2 == 3) || (THERMISTORBED == 3) //mendel-parts
101
+#define NUMTEMPS_3 28
102
+const short temptable_3[NUMTEMPS_3][2] = {
103
+                {1*OVERSAMPLENR,864},
104
+                {21*OVERSAMPLENR,300},
105
+                {25*OVERSAMPLENR,290},
106
+                {29*OVERSAMPLENR,280},
107
+                {33*OVERSAMPLENR,270},
108
+                {39*OVERSAMPLENR,260},
109
+                {46*OVERSAMPLENR,250},
110
+                {54*OVERSAMPLENR,240},
111
+                {64*OVERSAMPLENR,230},
112
+                {75*OVERSAMPLENR,220},
113
+                {90*OVERSAMPLENR,210},
114
+                {107*OVERSAMPLENR,200},
115
+                {128*OVERSAMPLENR,190},
116
+                {154*OVERSAMPLENR,180},
117
+                {184*OVERSAMPLENR,170},
118
+                {221*OVERSAMPLENR,160},
119
+                {265*OVERSAMPLENR,150},
120
+                {316*OVERSAMPLENR,140},
121
+                {375*OVERSAMPLENR,130},
122
+                {441*OVERSAMPLENR,120},
123
+                {513*OVERSAMPLENR,110},
124
+                {588*OVERSAMPLENR,100},
125
+                {734*OVERSAMPLENR,80},
126
+                {856*OVERSAMPLENR,60},
127
+                {938*OVERSAMPLENR,40},
128
+                {986*OVERSAMPLENR,20},
129
+                {1008*OVERSAMPLENR,0},
130
+                {1018*OVERSAMPLENR,-20}
131
+        };
132
+
133
+#endif
134
+#if (THERMISTORHEATER_1 == 4) || (THERMISTORHEATER_2 == 4) || (THERMISTORBED == 4) //10k thermistor
135
+
136
+#define NUMTEMPS_4 20
137
+short temptable_4[NUMTEMPS_4][2] = {
138
+   {1*OVERSAMPLENR, 430},
139
+   {54*OVERSAMPLENR, 137},
140
+   {107*OVERSAMPLENR, 107},
141
+   {160*OVERSAMPLENR, 91},
142
+   {213*OVERSAMPLENR, 80},
143
+   {266*OVERSAMPLENR, 71},
144
+   {319*OVERSAMPLENR, 64},
145
+   {372*OVERSAMPLENR, 57},
146
+   {425*OVERSAMPLENR, 51},
147
+   {478*OVERSAMPLENR, 46},
148
+   {531*OVERSAMPLENR, 41},
149
+   {584*OVERSAMPLENR, 35},
150
+   {637*OVERSAMPLENR, 30},
151
+   {690*OVERSAMPLENR, 25},
152
+   {743*OVERSAMPLENR, 20},
153
+   {796*OVERSAMPLENR, 14},
154
+   {849*OVERSAMPLENR, 7},
155
+   {902*OVERSAMPLENR, 0},
156
+   {955*OVERSAMPLENR, -11},
157
+   {1008*OVERSAMPLENR, -35}
158
+};
159
+#endif
160
+
161
+#if (THERMISTORHEATER_1 == 5) || (THERMISTORHEATER_2 == 5) || (THERMISTORBED == 5) //100k ParCan thermistor (104GT-2)
162
+
163
+#define NUMTEMPS_5 61
164
+const short temptable_5[NUMTEMPS_5][2] = {
165
+{1*OVERSAMPLENR, 713},
166
+{18*OVERSAMPLENR, 316},
167
+{35*OVERSAMPLENR, 266},
168
+{52*OVERSAMPLENR, 239},
169
+{69*OVERSAMPLENR, 221},
170
+{86*OVERSAMPLENR, 208},
171
+{103*OVERSAMPLENR, 197},
172
+{120*OVERSAMPLENR, 188},
173
+{137*OVERSAMPLENR, 181},
174
+{154*OVERSAMPLENR, 174},
175
+{171*OVERSAMPLENR, 169},
176
+{188*OVERSAMPLENR, 163},
177
+{205*OVERSAMPLENR, 159},
178
+{222*OVERSAMPLENR, 154},
179
+{239*OVERSAMPLENR, 150},
180
+{256*OVERSAMPLENR, 147},
181
+{273*OVERSAMPLENR, 143},
182
+{290*OVERSAMPLENR, 140},
183
+{307*OVERSAMPLENR, 136},
184
+{324*OVERSAMPLENR, 133},
185
+{341*OVERSAMPLENR, 130},
186
+{358*OVERSAMPLENR, 128},
187
+{375*OVERSAMPLENR, 125},
188
+{392*OVERSAMPLENR, 122},
189
+{409*OVERSAMPLENR, 120},
190
+{426*OVERSAMPLENR, 117},
191
+{443*OVERSAMPLENR, 115},
192
+{460*OVERSAMPLENR, 112},
193
+{477*OVERSAMPLENR, 110},
194
+{494*OVERSAMPLENR, 108},
195
+{511*OVERSAMPLENR, 106},
196
+{528*OVERSAMPLENR, 103},
197
+{545*OVERSAMPLENR, 101},
198
+{562*OVERSAMPLENR, 99},
199
+{579*OVERSAMPLENR, 97},
200
+{596*OVERSAMPLENR, 95},
201
+{613*OVERSAMPLENR, 92},
202
+{630*OVERSAMPLENR, 90},
203
+{647*OVERSAMPLENR, 88},
204
+{664*OVERSAMPLENR, 86},
205
+{681*OVERSAMPLENR, 84},
206
+{698*OVERSAMPLENR, 81},
207
+{715*OVERSAMPLENR, 79},
208
+{732*OVERSAMPLENR, 77},
209
+{749*OVERSAMPLENR, 75},
210
+{766*OVERSAMPLENR, 72},
211
+{783*OVERSAMPLENR, 70},
212
+{800*OVERSAMPLENR, 67},
213
+{817*OVERSAMPLENR, 64},
214
+{834*OVERSAMPLENR, 61},
215
+{851*OVERSAMPLENR, 58},
216
+{868*OVERSAMPLENR, 55},
217
+{885*OVERSAMPLENR, 52},
218
+{902*OVERSAMPLENR, 48},
219
+{919*OVERSAMPLENR, 44},
220
+{936*OVERSAMPLENR, 40},
221
+{953*OVERSAMPLENR, 34},
222
+{970*OVERSAMPLENR, 28},
223
+{987*OVERSAMPLENR, 20},
224
+{1004*OVERSAMPLENR, 8},
225
+{1021*OVERSAMPLENR, 0}
226
+};
227
+#endif
228
+
229
+#if (THERMISTORHEATER_1 == 6) || (THERMISTORHEATER_2 == 6) || (THERMISTORBED == 6) // 100k Epcos thermistor
230
+#define NUMTEMPS_6 36
231
+const short temptable_6[NUMTEMPS_6][2] = {
232
+   {28*OVERSAMPLENR, 250},
233
+   {31*OVERSAMPLENR, 245},
234
+   {35*OVERSAMPLENR, 240},
235
+   {39*OVERSAMPLENR, 235},
236
+   {42*OVERSAMPLENR, 230},
237
+   {44*OVERSAMPLENR, 225},
238
+   {49*OVERSAMPLENR, 220},
239
+   {53*OVERSAMPLENR, 215},
240
+   {62*OVERSAMPLENR, 210},
241
+   {73*OVERSAMPLENR, 205},
242
+   {72*OVERSAMPLENR, 200},
243
+   {94*OVERSAMPLENR, 190},
244
+   {102*OVERSAMPLENR, 185},
245
+   {116*OVERSAMPLENR, 170},
246
+   {143*OVERSAMPLENR, 160},
247
+   {183*OVERSAMPLENR, 150},
248
+   {223*OVERSAMPLENR, 140},
249
+   {270*OVERSAMPLENR, 130},
250
+   {318*OVERSAMPLENR, 120},
251
+   {383*OVERSAMPLENR, 110},
252
+   {413*OVERSAMPLENR, 105},
253
+   {439*OVERSAMPLENR, 100},
254
+   {484*OVERSAMPLENR, 95},
255
+   {513*OVERSAMPLENR, 90},
256
+   {607*OVERSAMPLENR, 80},
257
+   {664*OVERSAMPLENR, 70},
258
+   {781*OVERSAMPLENR, 60},
259
+   {810*OVERSAMPLENR, 55},
260
+   {849*OVERSAMPLENR, 50},
261
+   {914*OVERSAMPLENR, 45},
262
+   {914*OVERSAMPLENR, 40},
263
+   {935*OVERSAMPLENR, 35},
264
+   {954*OVERSAMPLENR, 30},
265
+   {970*OVERSAMPLENR, 25},
266
+   {978*OVERSAMPLENR, 22},
267
+   {1008*OVERSAMPLENR, 3}
268
+};
269
+#endif
270
+
271
+#if (THERMISTORHEATER_1 == 7) || (THERMISTORHEATER_2 == 7) || (THERMISTORBED == 7) // 100k Honeywell 135-104LAG-J01
272
+#define NUMTEMPS_7 54
273
+const short temptable_7[NUMTEMPS_7][2] = {
274
+   {46*OVERSAMPLENR, 270},
275
+   {50*OVERSAMPLENR, 265},
276
+   {54*OVERSAMPLENR, 260},
277
+   {58*OVERSAMPLENR, 255},
278
+   {62*OVERSAMPLENR, 250},
279
+   {67*OVERSAMPLENR, 245},
280
+   {72*OVERSAMPLENR, 240},
281
+   {79*OVERSAMPLENR, 235},
282
+   {85*OVERSAMPLENR, 230},
283
+   {91*OVERSAMPLENR, 225},
284
+   {99*OVERSAMPLENR, 220},
285
+   {107*OVERSAMPLENR, 215},
286
+   {116*OVERSAMPLENR, 210},
287
+   {126*OVERSAMPLENR, 205},
288
+   {136*OVERSAMPLENR, 200},
289
+   {149*OVERSAMPLENR, 195},
290
+   {160*OVERSAMPLENR, 190},
291
+   {175*OVERSAMPLENR, 185},
292
+   {191*OVERSAMPLENR, 180},
293
+   {209*OVERSAMPLENR, 175},
294
+   {224*OVERSAMPLENR, 170},
295
+   {246*OVERSAMPLENR, 165},
296
+   {267*OVERSAMPLENR, 160},
297
+   {293*OVERSAMPLENR, 155},
298
+   {316*OVERSAMPLENR, 150},
299
+   {340*OVERSAMPLENR, 145},
300
+   {364*OVERSAMPLENR, 140},
301
+   {396*OVERSAMPLENR, 135},
302
+   {425*OVERSAMPLENR, 130},
303
+   {460*OVERSAMPLENR, 125},
304
+   {489*OVERSAMPLENR, 120},
305
+   {526*OVERSAMPLENR, 115},
306
+   {558*OVERSAMPLENR, 110},
307
+   {591*OVERSAMPLENR, 105},
308
+   {628*OVERSAMPLENR, 100},
309
+   {660*OVERSAMPLENR, 95},
310
+   {696*OVERSAMPLENR, 90},
311
+   {733*OVERSAMPLENR, 85},
312
+   {761*OVERSAMPLENR, 80},
313
+   {794*OVERSAMPLENR, 75},
314
+   {819*OVERSAMPLENR, 70},
315
+   {847*OVERSAMPLENR, 65},
316
+   {870*OVERSAMPLENR, 60},
317
+   {892*OVERSAMPLENR, 55},
318
+   {911*OVERSAMPLENR, 50},
319
+   {929*OVERSAMPLENR, 45},
320
+   {944*OVERSAMPLENR, 40},
321
+   {959*OVERSAMPLENR, 35},
322
+   {971*OVERSAMPLENR, 30},
323
+   {981*OVERSAMPLENR, 25},
324
+   {989*OVERSAMPLENR, 20},
325
+   {994*OVERSAMPLENR, 15},
326
+   {1001*OVERSAMPLENR, 10},
327
+   {1005*OVERSAMPLENR, 5}
328
+};
329
+#endif
330
+
331
+
332
+
333
+#if THERMISTORHEATER_1 == 1
334
+#define NUMTEMPS_HEATER_1 NUMTEMPS_1
335
+#define temptable_1 temptable_1
336
+#elif THERMISTORHEATER_1 == 2
337
+#define NUMTEMPS_HEATER_1 NUMTEMPS_2
338
+#define temptable_1 temptable_2
339
+#elif THERMISTORHEATER_1 == 3
340
+#define NUMTEMPS_HEATER_1 NUMTEMPS_3
341
+#define temptable_1 temptable_3
342
+#elif THERMISTORHEATER_1 == 4
343
+#define NUMTEMPS_HEATER_1 NUMTEMPS_4
344
+#define temptable_1 temptable_4
345
+#elif THERMISTORHEATER_1 == 5
346
+#define NUMTEMPS_HEATER_1 NUMTEMPS_5
347
+#define temptable_1 temptable_5
348
+#elif THERMISTORHEATER_1 == 6
349
+#define NUMTEMPS_HEATER_1 NUMTEMPS_6
350
+#define temptable_1 temptable_6
351
+#elif THERMISTORHEATER_1 == 7
352
+#define NUMTEMPS_HEATER_1 NUMTEMPS_7
353
+#define temptable_1 temptable_7
354
+#elif defined HEATER_1_USES_THERMISTOR
355
+#error No heater 1 thermistor table specified
356
+#endif
357
+
358
+#if THERMISTORHEATER_2 == 1
359
+#define NUMTEMPS_HEATER_2 NUMTEMPS_1
360
+#define temptable_2 temptable_1
361
+#elif THERMISTORHEATER_2 == 2
362
+#define NUMTEMPS_HEATER_2 NUMTEMPS_2
363
+#define temptable_2 temptable_2
364
+#elif THERMISTORHEATER_2 == 3
365
+#define NUMTEMPS_HEATER_2 NUMTEMPS_3
366
+#define temptable_2 temptable_3
367
+#elif THERMISTORHEATER_2 == 4
368
+#define NUMTEMPS_HEATER_2 NUMTEMPS_4
369
+#define temptable_2 temptable_4
370
+#elif THERMISTORHEATER_2 == 5
371
+#define NUMTEMPS_HEATER_2 NUMTEMPS_5
372
+#define temptable_2 temptable_5
373
+#elif THERMISTORHEATER_2 == 6
374
+#define NUMTEMPS_HEATER_2 NUMTEMPS_6
375
+#define temptable_2 temptable_6
376
+#elif THERMISTORHEATER_2 == 7
377
+#define NUMTEMPS_HEATER22 NUMTEMPS_7
378
+#define temptable_2 temptable_7
379
+#elif defined HEATER_2_USES_THERMISTOR
380
+#error No heater 2 thermistor table specified
381
+#endif
382
+
383
+
384
+#if THERMISTORBED == 1
385
+#define BNUMTEMPS NUMTEMPS_1
386
+#define bedtemptable temptable_1
387
+#elif THERMISTORBED == 2
388
+#define BNUMTEMPS NUMTEMPS_2
389
+#define bedtemptable temptable_2
390
+#elif THERMISTORBED == 3
391
+#define BNUMTEMPS NUMTEMPS_3
392
+#define bedtemptable temptable_3
393
+#elif THERMISTORBED == 4
394
+#define BNUMTEMPS NUMTEMPS_4
395
+#define bedtemptable temptable_4
396
+#elif THERMISTORBED == 5
397
+#define BNUMTEMPS NUMTEMPS_5
398
+#define bedtemptable temptable_5
399
+#elif THERMISTORBED == 6
400
+#define BNUMTEMPS NUMTEMPS_6
401
+#define bedtemptable temptable_6
402
+#elif THERMISTORBED == 7
403
+#define BNUMTEMPS NUMTEMPS_7
404
+#define bedtemptable temptable_7
405
+#elif defined BED_USES_THERMISTOR
406
+#error No bed thermistor table specified
407
+#endif
408
+
409
+#endif //THERMISTORTABLES_H_
410
+

+ 155
- 155
Marlin/ultralcd.h View File

@@ -1,156 +1,156 @@
1
-#ifndef __ULTRALCDH
2
-#define __ULTRALCDH
3
-#include "Configuration.h"
4
-
5
-#ifdef ULTRA_LCD
6
-
7
-  void lcd_status();
8
-  void lcd_init();
9
-  void lcd_status(const char* message);
10
-  void beep();
11
-  void buttons_check();
12
-  #define LCDSTATUSRIGHT
13
-
14
-  #define LCD_UPDATE_INTERVAL 100
15
-  #define STATUSTIMEOUT 15000
16
-
17
-  #include "Configuration.h"
18
-
19
-  #include <LiquidCrystal.h>
20
-  extern LiquidCrystal lcd;
21
-
22
-  //lcd display size
23
-
24
-#ifdef NEWPANEL
25
- //arduino pin witch triggers an piezzo beeper
26
-  #define BEEPER 18
27
-
28
-  #define LCD_PINS_RS 20 
29
-  #define LCD_PINS_ENABLE 17
30
-  #define LCD_PINS_D4 16
31
-  #define LCD_PINS_D5 21 
32
-  #define LCD_PINS_D6 5
33
-  #define LCD_PINS_D7 6
34
-  
35
-  //buttons are directly attached
36
-  #define BTN_EN1 40
37
-  #define BTN_EN2 42
38
-  #define BTN_ENC 19  //the click
39
-  
40
-  #define BLEN_C 2
41
-  #define BLEN_B 1
42
-  #define BLEN_A 0
43
-  
44
-  #define SDCARDDETECT 38
45
-  
46
-  #define EN_C (1<<BLEN_C)
47
-  #define EN_B (1<<BLEN_B)
48
-  #define EN_A (1<<BLEN_A)
49
-  
50
-   //encoder rotation values
51
-  #define encrot0 0
52
-  #define encrot1 2
53
-  #define encrot2 3
54
-  #define encrot3 1
55
-
56
-  
57
-  #define CLICKED (buttons&EN_C)
58
-  #define BLOCK {blocking=millis()+blocktime;}
59
-  #define CARDINSERTED (READ(SDCARDDETECT)==0)
60
-  
61
-#else
62
-  //arduino pin witch triggers an piezzo beeper
63
-  #define BEEPER 18
64
-
65
-  //buttons are attached to a shift register
66
-  #define SHIFT_CLK 38
67
-  #define SHIFT_LD 42
68
-  #define SHIFT_OUT 40
69
-  #define SHIFT_EN 17
70
-  
71
-  #define LCD_PINS_RS 16 
72
-  #define LCD_PINS_ENABLE 5
73
-  #define LCD_PINS_D4 6
74
-  #define LCD_PINS_D5 21 
75
-  #define LCD_PINS_D6 20
76
-  #define LCD_PINS_D7 19
77
-  
78
-   //bits in the shift register that carry the buttons for:
79
-  // left up center down right red
80
-  #define BL_LE 7
81
-  #define BL_UP 6
82
-  #define BL_MI 5
83
-  #define BL_DW 4
84
-  #define BL_RI 3
85
-  #define BL_ST 2
86
-
87
-  #define BLEN_B 1
88
-  #define BLEN_A 0
89
-
90
-  //encoder rotation values
91
-  #define encrot0 0
92
-  #define encrot1 2
93
-  #define encrot2 3
94
-  #define encrot3 1
95
-
96
-  //atomatic, do not change
97
-  #define B_LE (1<<BL_LE)
98
-  #define B_UP (1<<BL_UP)
99
-  #define B_MI (1<<BL_MI)
100
-  #define B_DW (1<<BL_DW)
101
-  #define B_RI (1<<BL_RI)
102
-  #define B_ST (1<<BL_ST)
103
-  #define EN_B (1<<BLEN_B)
104
-  #define EN_A (1<<BLEN_A)
105
-  
106
-  #define CLICKED ((buttons&B_MI)||(buttons&B_ST))
107
-  #define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;}
108
-  
109
-#endif
110
-  // blocking time for recognizing a new keypress of one key, ms
111
-#define blocktime 500
112
-#define lcdslow 5
113
-  enum MainStatus{Main_Status, Main_Menu, Main_Prepare, Main_Control, Main_SD};
114
-
115
-  class MainMenu{
116
-  public:
117
-    MainMenu();
118
-    void update();
119
-    void getfilename(const uint8_t nr);
120
-    uint8_t activeline;
121
-    MainStatus status;
122
-    uint8_t displayStartingRow;
123
-    
124
-    void showStatus();
125
-    void showMainMenu();
126
-    void showPrepare();
127
-    void showControl();
128
-    void showSD();
129
-    bool force_lcd_update;
130
-    int lastencoderpos;
131
-    int8_t lineoffset;
132
-    int8_t lastlineoffset;
133
-    char filename[11];
134
-    bool linechanging;
135
-  };
136
-
137
-  char *fillto(int8_t n,char *c);
138
-  char *ftostr51(const float &x);
139
-  char *ftostr31(const float &x);
140
-  char *ftostr3(const float &x);
141
-
142
-
143
-
144
-  #define LCD_MESSAGE(x) lcd_status(x);
145
-  #define LCD_STATUS lcd_status()
146
-#else //no lcd
147
-  #define LCD_STATUS
148
-  #define LCD_MESSAGE(x)
149
-#endif
150
-  
151
-#ifndef ULTIPANEL  
152
- #define CLICKED false
153
-#define BLOCK ;
154
-#endif 
155
-#endif //ULTRALCD
1
+#ifndef __ULTRALCDH
2
+#define __ULTRALCDH
3
+#include "Configuration.h"
4
+
5
+#ifdef ULTRA_LCD
6
+
7
+  void lcd_status();
8
+  void lcd_init();
9
+  void lcd_status(const char* message);
10
+  void beep();
11
+  void buttons_check();
12
+  #define LCDSTATUSRIGHT
13
+
14
+  #define LCD_UPDATE_INTERVAL 100
15
+  #define STATUSTIMEOUT 15000
16
+
17
+  #include "Configuration.h"
18
+
19
+  #include <LiquidCrystal.h>
20
+  extern LiquidCrystal lcd;
21
+
22
+  //lcd display size
23
+
24
+#ifdef NEWPANEL
25
+ //arduino pin witch triggers an piezzo beeper
26
+  #define BEEPER 18
27
+
28
+  #define LCD_PINS_RS 20 
29
+  #define LCD_PINS_ENABLE 17
30
+  #define LCD_PINS_D4 16
31
+  #define LCD_PINS_D5 21 
32
+  #define LCD_PINS_D6 5
33
+  #define LCD_PINS_D7 6
34
+  
35
+  //buttons are directly attached
36
+  #define BTN_EN1 40
37
+  #define BTN_EN2 42
38
+  #define BTN_ENC 19  //the click
39
+  
40
+  #define BLEN_C 2
41
+  #define BLEN_B 1
42
+  #define BLEN_A 0
43
+  
44
+  #define SDCARDDETECT 38
45
+  
46
+  #define EN_C (1<<BLEN_C)
47
+  #define EN_B (1<<BLEN_B)
48
+  #define EN_A (1<<BLEN_A)
49
+  
50
+   //encoder rotation values
51
+  #define encrot0 0
52
+  #define encrot1 2
53
+  #define encrot2 3
54
+  #define encrot3 1
55
+
56
+  
57
+  #define CLICKED (buttons&EN_C)
58
+  #define BLOCK {blocking=millis()+blocktime;}
59
+  #define CARDINSERTED (READ(SDCARDDETECT)==0)
60
+  
61
+#else
62
+  //arduino pin witch triggers an piezzo beeper
63
+  #define BEEPER 18
64
+
65
+  //buttons are attached to a shift register
66
+  #define SHIFT_CLK 38
67
+  #define SHIFT_LD 42
68
+  #define SHIFT_OUT 40
69
+  #define SHIFT_EN 17
70
+  
71
+  #define LCD_PINS_RS 16 
72
+  #define LCD_PINS_ENABLE 5
73
+  #define LCD_PINS_D4 6
74
+  #define LCD_PINS_D5 21 
75
+  #define LCD_PINS_D6 20
76
+  #define LCD_PINS_D7 19
77
+  
78
+   //bits in the shift register that carry the buttons for:
79
+  // left up center down right red
80
+  #define BL_LE 7
81
+  #define BL_UP 6
82
+  #define BL_MI 5
83
+  #define BL_DW 4
84
+  #define BL_RI 3
85
+  #define BL_ST 2
86
+
87
+  #define BLEN_B 1
88
+  #define BLEN_A 0
89
+
90
+  //encoder rotation values
91
+  #define encrot0 0
92
+  #define encrot1 2
93
+  #define encrot2 3
94
+  #define encrot3 1
95
+
96
+  //atomatic, do not change
97
+  #define B_LE (1<<BL_LE)
98
+  #define B_UP (1<<BL_UP)
99
+  #define B_MI (1<<BL_MI)
100
+  #define B_DW (1<<BL_DW)
101
+  #define B_RI (1<<BL_RI)
102
+  #define B_ST (1<<BL_ST)
103
+  #define EN_B (1<<BLEN_B)
104
+  #define EN_A (1<<BLEN_A)
105
+  
106
+  #define CLICKED ((buttons&B_MI)||(buttons&B_ST))
107
+  #define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;}
108
+  
109
+#endif
110
+  // blocking time for recognizing a new keypress of one key, ms
111
+#define blocktime 500
112
+#define lcdslow 5
113
+  enum MainStatus{Main_Status, Main_Menu, Main_Prepare, Main_Control, Main_SD};
114
+
115
+  class MainMenu{
116
+  public:
117
+    MainMenu();
118
+    void update();
119
+    void getfilename(const uint8_t nr);
120
+    uint8_t activeline;
121
+    MainStatus status;
122
+    uint8_t displayStartingRow;
123
+    
124
+    void showStatus();
125
+    void showMainMenu();
126
+    void showPrepare();
127
+    void showControl();
128
+    void showSD();
129
+    bool force_lcd_update;
130
+    int lastencoderpos;
131
+    int8_t lineoffset;
132
+    int8_t lastlineoffset;
133
+    char filename[11];
134
+    bool linechanging;
135
+  };
136
+
137
+  char *fillto(int8_t n,char *c);
138
+  char *ftostr51(const float &x);
139
+  char *ftostr31(const float &x);
140
+  char *ftostr3(const float &x);
141
+
142
+
143
+
144
+  #define LCD_MESSAGE(x) lcd_status(x);
145
+  #define LCD_STATUS lcd_status()
146
+#else //no lcd
147
+  #define LCD_STATUS
148
+  #define LCD_MESSAGE(x)
149
+#endif
150
+  
151
+#ifndef ULTIPANEL  
152
+ #define CLICKED false
153
+#define BLOCK ;
154
+#endif 
155
+#endif //ULTRALCD
156 156
 

+ 64
- 64
README View File

@@ -1,64 +1,64 @@
1
-This RepRap firmware is a mashup between Sprinter, grbl and many original parts.
2
- (https://github.com/kliment/Sprinter)
3
- (https://github.com/simen/grbl/tree)
4
-
5
-Derived from Sprinter and Grbl by Erik van der Zalm.
6
-Sprinters lead developers are Kliment and caru.
7
-Grbls lead developer is Simen Svale Skogsrud.
8
-It has been adapted to the Ultimaker Printer by:
9
-Bernhard Kubicek, Matthijs Keuper, Bradley Feldman, and others...
10
-
11
-
12
-Features:
13
- - Interrupt based movement with real linear acceleration
14
- - High steprate
15
- - Look ahead (Keep the speed high when possible. High cornering speed)
16
- - Interrupt based temperature protection
17
- - preliminary support for Matthew Roberts advance algorithm 
18
-   For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
19
- - Full endstop support
20
- - Simple LCD support (16x2)
21
- - SD Card support
22
- - Provisions for Bernhard Kubicek's new hardware control console and 20x4 lcd
23
-
24
-This firmware is optimized for Ultimaker's gen6 electronics (including the Ultimaker 1.5.x daughterboard and Arduino Mega 2560).
25
-
26
-The default baudrate is 115200. 
27
-
28
-
29
-========================================================================================
30
-
31
-Configuring and compilation
32
-
33
-
34
-Install the latest arduino software IDE/toolset (currently 0022)
35
-   http://www.arduino.cc/en/Main/Software
36
-
37
-Install Ultimaker's RepG 25 build
38
-    http://software.ultimaker.com
39
-(or alternatively install Kliment's printrun/pronterface  https://github.com/kliment/Printrun_)
40
-
41
-Copy the Ultimaker Marlin firmware
42
-   https:/github.com/bkubicek/Marlin
43
-   (Use the download button)
44
-
45
-Start the arduino IDE.
46
-Select Tools -> Board -> Arduino Mega 2560 
47
-Select the correct serial port in Tools ->Serial Port
48
-Open Marlin.pde
49
-
50
-Click the Verify/Compile button
51
-
52
-Click the Upload button
53
-If all goes well the firmware is uploading
54
-
55
-Start Ultimaker's Custom RepG 25
56
-Make sure Show Experimental Profiles is enabled in Preferences
57
-Select Sprinter as the Driver
58
-
59
-Press the Connect button.
60
-
61
-KNOWN ISSUES: RepG will display:  Unknown: marlin x.y.z
62
-
63
-That's ok.  Enjoy Silky Smooth Printing.
64
-
1
+This RepRap firmware is a mashup between Sprinter, grbl and many original parts.
2
+ (https://github.com/kliment/Sprinter)
3
+ (https://github.com/simen/grbl/tree)
4
+
5
+Derived from Sprinter and Grbl by Erik van der Zalm.
6
+Sprinters lead developers are Kliment and caru.
7
+Grbls lead developer is Simen Svale Skogsrud.
8
+It has been adapted to the Ultimaker Printer by:
9
+Bernhard Kubicek, Matthijs Keuper, Bradley Feldman, and others...
10
+
11
+
12
+Features:
13
+ - Interrupt based movement with real linear acceleration
14
+ - High steprate
15
+ - Look ahead (Keep the speed high when possible. High cornering speed)
16
+ - Interrupt based temperature protection
17
+ - preliminary support for Matthew Roberts advance algorithm 
18
+   For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
19
+ - Full endstop support
20
+ - Simple LCD support (16x2)
21
+ - SD Card support
22
+ - Provisions for Bernhard Kubicek's new hardware control console and 20x4 lcd
23
+
24
+This firmware is optimized for Ultimaker's gen6 electronics (including the Ultimaker 1.5.x daughterboard and Arduino Mega 2560).
25
+
26
+The default baudrate is 115200. 
27
+
28
+
29
+========================================================================================
30
+
31
+Configuring and compilation
32
+
33
+
34
+Install the latest arduino software IDE/toolset (currently 0022)
35
+   http://www.arduino.cc/en/Main/Software
36
+
37
+Install Ultimaker's RepG 25 build
38
+    http://software.ultimaker.com
39
+(or alternatively install Kliment's printrun/pronterface  https://github.com/kliment/Printrun_)
40
+
41
+Copy the Ultimaker Marlin firmware
42
+   https:/github.com/bkubicek/Marlin
43
+   (Use the download button)
44
+
45
+Start the arduino IDE.
46
+Select Tools -> Board -> Arduino Mega 2560 
47
+Select the correct serial port in Tools ->Serial Port
48
+Open Marlin.pde
49
+
50
+Click the Verify/Compile button
51
+
52
+Click the Upload button
53
+If all goes well the firmware is uploading
54
+
55
+Start Ultimaker's Custom RepG 25
56
+Make sure Show Experimental Profiles is enabled in Preferences
57
+Select Sprinter as the Driver
58
+
59
+Press the Connect button.
60
+
61
+KNOWN ISSUES: RepG will display:  Unknown: marlin x.y.z
62
+
63
+That's ok.  Enjoy Silky Smooth Printing.
64
+

+ 69
- 69
README.md View File

@@ -1,69 +1,69 @@
1
-WARNING: THIS IN A PROCESS OF HEAVY OVERWORKING.
2
-DO NOT USE THIS ON YOUR MACHINE UNTIL FURTHER NOTICE!!!
3
-
4
-===========================================
5
-
6
-This RepRap firmware is a mashup between <a href="https://github.com/kliment/Sprinter">Sprinter</a>, <a href="https://github.com/simen/grbl/tree">grbl</a> and many original parts.
7
-
8
-Derived from Sprinter and Grbl by Erik van der Zalm.
9
-Sprinters lead developers are Kliment and caru.
10
-Grbls lead developer is Simen Svale Skogsrud.
11
-Some features have been added by and configuration has been added by:
12
-Bernhard Kubicek, Matthijs Keuper, Bradley Feldman, and others...
13
-
14
-
15
-Features:
16
- - Interrupt based movement with real linear acceleration
17
- - High steprate
18
- - Look ahead (Keep the speed high when possible. High cornering speed)
19
- - Interrupt based temperature protection
20
- - preliminary support for Matthew Roberts advance algorithm 
21
-   For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
22
- - Full endstop support
23
- - Simple LCD support (16x2)
24
- - SD Card support
25
- - Provisions for Bernhard Kubicek's new hardware control console and 20x4 lcd
26
-
27
-This firmware is optimized for Ultimaker's gen6 electronics (including the Ultimaker 1.5.x daughterboard and Arduino Mega 2560).
28
-
29
-The default baudrate is 115200. 
30
-
31
-
32
-========================================================================================
33
-
34
-Configuring and compilation
35
-
36
-
37
-Install the latest arduino software IDE/toolset (currently 0022)
38
-   http://www.arduino.cc/en/Main/Software
39
-
40
-Install Ultimaker's RepG 25 build
41
-    http://software.ultimaker.com
42
-(or alternatively install Kliment's printrun/pronterface  https://github.com/kliment/Printrun_)
43
-
44
-Copy the Ultimaker Marlin firmware
45
-   https:/github.com/bkubicek/Marlin
46
-   (Use the download button)
47
-
48
-Start the arduino IDE.
49
-Select Tools -> Board -> Arduino Mega 2560 
50
-Select the correct serial port in Tools ->Serial Port
51
-Open Marlin.pde
52
-
53
-Click the Verify/Compile button
54
-
55
-Click the Upload button
56
-If all goes well the firmware is uploading
57
-
58
-Start Ultimaker's Custom RepG 25
59
-Make sure Show Experimental Profiles is enabled in Preferences
60
-Select Sprinter as the Driver
61
-
62
-Press the Connect button.
63
-
64
-KNOWN ISSUES: RepG will display:  Unknown: marlin x.y.z
65
-
66
-That's ok.  Enjoy Silky Smooth Printing.
67
-
68
-
69
-
1
+WARNING: THIS IN A PROCESS OF HEAVY OVERWORKING.
2
+DO NOT USE THIS ON YOUR MACHINE UNTIL FURTHER NOTICE!!!
3
+
4
+===========================================
5
+
6
+This RepRap firmware is a mashup between <a href="https://github.com/kliment/Sprinter">Sprinter</a>, <a href="https://github.com/simen/grbl/tree">grbl</a> and many original parts.
7
+
8
+Derived from Sprinter and Grbl by Erik van der Zalm.
9
+Sprinters lead developers are Kliment and caru.
10
+Grbls lead developer is Simen Svale Skogsrud.
11
+Some features have been added by and configuration has been added by:
12
+Bernhard Kubicek, Matthijs Keuper, Bradley Feldman, and others...
13
+
14
+
15
+Features:
16
+ - Interrupt based movement with real linear acceleration
17
+ - High steprate
18
+ - Look ahead (Keep the speed high when possible. High cornering speed)
19
+ - Interrupt based temperature protection
20
+ - preliminary support for Matthew Roberts advance algorithm 
21
+   For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
22
+ - Full endstop support
23
+ - Simple LCD support (16x2)
24
+ - SD Card support
25
+ - Provisions for Bernhard Kubicek's new hardware control console and 20x4 lcd
26
+
27
+This firmware is optimized for Ultimaker's gen6 electronics (including the Ultimaker 1.5.x daughterboard and Arduino Mega 2560).
28
+
29
+The default baudrate is 115200. 
30
+
31
+
32
+========================================================================================
33
+
34
+Configuring and compilation
35
+
36
+
37
+Install the latest arduino software IDE/toolset (currently 0022)
38
+   http://www.arduino.cc/en/Main/Software
39
+
40
+Install Ultimaker's RepG 25 build
41
+    http://software.ultimaker.com
42
+(or alternatively install Kliment's printrun/pronterface  https://github.com/kliment/Printrun_)
43
+
44
+Copy the Ultimaker Marlin firmware
45
+   https:/github.com/bkubicek/Marlin
46
+   (Use the download button)
47
+
48
+Start the arduino IDE.
49
+Select Tools -> Board -> Arduino Mega 2560 
50
+Select the correct serial port in Tools ->Serial Port
51
+Open Marlin.pde
52
+
53
+Click the Verify/Compile button
54
+
55
+Click the Upload button
56
+If all goes well the firmware is uploading
57
+
58
+Start Ultimaker's Custom RepG 25
59
+Make sure Show Experimental Profiles is enabled in Preferences
60
+Select Sprinter as the Driver
61
+
62
+Press the Connect button.
63
+
64
+KNOWN ISSUES: RepG will display:  Unknown: marlin x.y.z
65
+
66
+That's ok.  Enjoy Silky Smooth Printing.
67
+
68
+
69
+

+ 57
- 57
merging still needs.txt View File

@@ -1,58 +1,58 @@
1
-files to compare manually:
2
-planner.cpp
3
-stepper.cpp
4
-temperature.cpp
5
-
6
----
7
-things that changed:
8
-* planner.cpp
9
-estimate_acc_distance now works with floats.
10
-in calculate_trapezoid:for_block
11
- long acceleration_rate=(long)((float)acceleration*8.388608) is gone
12
- so is block_>acceleration_rate
13
-void planner_reverse_pass:
14
- some stuff I don't understand right now changed
15
-in planner_forward_pass:
16
- done: BLOCK_BUFFER_SIZE is now necessarily power of 2 (aka 8 16, 32). Inportant to document this somewhere.
17
-no more inline in void plan_discard_current_block()
18
-no more inline in plan_get_current_block()
19
-in plan_buffer_line(...)
20
- the long target[4]; and calculations of thoose should go after the while(block_buffer_tail==..). if the axis_steps_per_unit are changed from the gcode (M92) the calculation for the currently planned buffer move will be corrupt, because Target is calculated with one value, and the stuff afterwards with another. At least this solved the problem I had with the M92 E* changes in the code. Very sure about this, I took me 20min to find this as the solution for the bug I was hunting.
21
-around if(feed_rate<minimumfeedrate) this only should be done if it is not a pure extrusion. I think there is a bug right now.
22
-~line 447 blockcount= 
23
- not sure if this also works if the difference is negative, as it would happen if the ringbuffer runs over the end and start at 0.
24
-~line 507 tmp_aceleration. not sure whats going on, but a lot changed.
25
-
26
-
27
-* stepper.cpp
28
-~214: if (busy) should be a echoln, maybe
29
-~331: great, The Z_M_PIN checks are in :)
30
-
31
-*temperature.cpp
32
-done: enum for heater, bed,
33
-manage_heater() is seriously different.
34
-  done: if tem_meas_ready ==true->!true+return?
35
-done #define K1 0.95 maybe in the configuration.h?
36
-semi-done: PID-C checking needed. Untested but added.
37
-----
38
-
39
-still needed to finish the merge, before testin!
40
-
41
- manage_heater
42
- ISR
43
- movement planner
44
-
45
-TODO:
46
-
47
-remove traveling at maxpseed
48
-remove Simplelcd
49
-
50
-remove DEBUG_STEPS?
51
-
52
-block_t
53
-pid_dt ->0.1  whats the changes to the PID, checking needed
54
-
55
-
56
-----
57
-second merge saturday morning:
1
+files to compare manually:
2
+planner.cpp
3
+stepper.cpp
4
+temperature.cpp
5
+
6
+---
7
+things that changed:
8
+* planner.cpp
9
+estimate_acc_distance now works with floats.
10
+in calculate_trapezoid:for_block
11
+ long acceleration_rate=(long)((float)acceleration*8.388608) is gone
12
+ so is block_>acceleration_rate
13
+void planner_reverse_pass:
14
+ some stuff I don't understand right now changed
15
+in planner_forward_pass:
16
+ done: BLOCK_BUFFER_SIZE is now necessarily power of 2 (aka 8 16, 32). Inportant to document this somewhere.
17
+no more inline in void plan_discard_current_block()
18
+no more inline in plan_get_current_block()
19
+in plan_buffer_line(...)
20
+ the long target[4]; and calculations of thoose should go after the while(block_buffer_tail==..). if the axis_steps_per_unit are changed from the gcode (M92) the calculation for the currently planned buffer move will be corrupt, because Target is calculated with one value, and the stuff afterwards with another. At least this solved the problem I had with the M92 E* changes in the code. Very sure about this, I took me 20min to find this as the solution for the bug I was hunting.
21
+around if(feed_rate<minimumfeedrate) this only should be done if it is not a pure extrusion. I think there is a bug right now.
22
+~line 447 blockcount= 
23
+ not sure if this also works if the difference is negative, as it would happen if the ringbuffer runs over the end and start at 0.
24
+~line 507 tmp_aceleration. not sure whats going on, but a lot changed.
25
+
26
+
27
+* stepper.cpp
28
+~214: if (busy) should be a echoln, maybe
29
+~331: great, The Z_M_PIN checks are in :)
30
+
31
+*temperature.cpp
32
+done: enum for heater, bed,
33
+manage_heater() is seriously different.
34
+  done: if tem_meas_ready ==true->!true+return?
35
+done #define K1 0.95 maybe in the configuration.h?
36
+semi-done: PID-C checking needed. Untested but added.
37
+----
38
+
39
+still needed to finish the merge, before testin!
40
+
41
+ manage_heater
42
+ ISR
43
+ movement planner
44
+
45
+TODO:
46
+
47
+remove traveling at maxpseed
48
+remove Simplelcd
49
+
50
+remove DEBUG_STEPS?
51
+
52
+block_t
53
+pid_dt ->0.1  whats the changes to the PID, checking needed
54
+
55
+
56
+----
57
+second merge saturday morning:
58 58
 done: PID_dt->0.1

Loading…
Cancel
Save