浏览代码

Merge remote-tracking branch 'origin/Marlin_v1' into Marlin_v1

Conflicts:
	Marlin/Configuration.h
	Marlin/EEPROMwrite.h
	Marlin/Marlin.h
	Marlin/Marlin.pde
	Marlin/temperature.cpp
	Marlin/temperature.h
	Marlin/thermistortables.h
Erik van der Zalm 13 年前
父节点
当前提交
04d3b5537f
共有 33 个文件被更改,包括 11312 次插入11112 次删除
  1. 43
    20
      Marlin/Configuration.h
  2. 9
    3
      Marlin/EEPROMwrite.h
  3. 418
    418
      Marlin/FatStructs.h
  4. 314
    268
      Marlin/Makefile
  5. 2
    3
      Marlin/Marlin.h
  6. 38
    38
      Marlin/Marlin.pde
  7. 643
    643
      Marlin/Sd2Card.cpp
  8. 233
    233
      Marlin/Sd2Card.h
  9. 353
    353
      Marlin/Sd2PinMap.h
  10. 547
    547
      Marlin/SdFat.h
  11. 70
    70
      Marlin/SdFatUtil.h
  12. 202
    202
      Marlin/SdFatmainpage.h
  13. 1252
    1252
      Marlin/SdFile.cpp
  14. 232
    232
      Marlin/SdInfo.h
  15. 295
    295
      Marlin/SdVolume.cpp
  16. 2559
    2559
      Marlin/fastio.h
  17. 0
    10
      Marlin/lcd.h
  18. 0
    1
      Marlin/lcd.pde
  19. 570
    570
      Marlin/pins.h
  20. 586
    584
      Marlin/planner.cpp
  21. 92
    90
      Marlin/planner.h
  22. 75
    75
      Marlin/speed_lookuptable.h
  23. 592
    592
      Marlin/stepper.cpp
  24. 44
    40
      Marlin/stepper.h
  25. 84
    84
      Marlin/streaming.h
  26. 24
    19
      Marlin/temperature.cpp
  27. 5
    2
      Marlin/temperature.h
  28. 90
    90
      Marlin/thermistortables.h
  29. 156
    156
      Marlin/ultralcd.h
  30. 1593
    1593
      Marlin/ultralcd.pde
  31. 64
    70
      README
  32. 69
    0
      README.md
  33. 58
    0
      merging still needs.txt

+ 43
- 20
Marlin/Configuration.h 查看文件

@@ -54,16 +54,20 @@ const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the
54 54
 // Comment out (using // at the start of the line) to disable SD support:
55 55
 
56 56
 // #define ULTRA_LCD  //any lcd 
57
-#define LCD_WIDTH 16
58
-#define LCD_HEIGHT 2
59 57
 
60 58
 #define ULTIPANEL
59
+#define ULTIPANEL
61 60
 #ifdef ULTIPANEL
62 61
  //#define NEWPANEL  //enable this if you have a click-encoder panel
63 62
  #define SDSUPPORT
64 63
  #define ULTRA_LCD
65 64
  #define LCD_WIDTH 20
66 65
 #define LCD_HEIGHT 4
66
+#else //no panel but just lcd 
67
+  #ifdef ULTRA_LCD
68
+    #define LCD_WIDTH 16
69
+    #define LCD_HEIGHT 2
70
+  #endif
67 71
 #endif
68 72
 
69 73
 
@@ -169,26 +173,47 @@ const int dropsegments=5; //everything with this number of steps  will be ignore
169 173
 //#define_HEATER_1_MAXTEMP 275
170 174
 //#define BED_MAXTEMP 150
171 175
 
172
-/// PID settings:
173
-// Uncomment the following line to enable PID support.
174
-//#define SMOOTHING
175
-//#define SMOOTHFACTOR 5.0
176
-//float current_raw_average=0;
176
+
177
+
178
+
179
+
180
+
177 181
 
178 182
 #define PIDTEMP
179 183
 #ifdef PIDTEMP
180
-//#define PID_DEBUG // Sends debug data to the serial port. 
181
-//#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
182
-#define PID_MAX 255 // limits current to nozzle
183
-#define PID_INTEGRAL_DRIVE_MAX 255
184
-#define PID_dT 0.10 // 100ms sample time
185
-#define DEFAULT_Kp 20.0
186
-#define DEFAULT_Ki 1.5*PID_dT
187
-#define DEFAULT_Kd 80/PID_dT
188
-#define DEFAULT_Kc 0
184
+  /// PID settings:
185
+  // Uncomment the following line to enable PID support.
186
+  //#define SMOOTHING
187
+  //#define SMOOTHFACTOR 5.0
188
+  //float current_raw_average=0;
189
+    #define K1 0.95 //smoothing of the PID
190
+  //#define PID_DEBUG // Sends debug data to the serial port. 
191
+  //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
192
+  #define PID_MAX 255 // limits current to nozzle
193
+  #define PID_INTEGRAL_DRIVE_MAX 255
194
+  #define PID_dT 0.1
195
+ //machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47
196
+
197
+  #define PID_CRITIAL_GAIN 3000
198
+  #define PID_SWING_AT_CRITIAL 45 //seconds
199
+  #define PIDIADD 5
200
+  /*
201
+  //PID according to Ziegler-Nichols method
202
+  float Kp = 0.6*PID_CRITIAL_GAIN; 
203
+  float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT;  
204
+  float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT;  
205
+  */
206
+  //PI according to Ziegler-Nichols method
207
+  #define  DEFAULT_Kp (PID_CRITIAL_GAIN/2.2) 
208
+  #define  DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
209
+  #define  DEFAULT_Kd (0)
210
+  
211
+  #define PID_ADD_EXTRUSION_RATE  
212
+  #ifdef PID_ADD_EXTRUSION_RATE
213
+    #define  DEFAULT_Kc (5) //heatingpower=Kc*(e_speed)
214
+  #endif
189 215
 #endif // PIDTEMP
190 216
 
191
-
192 217
 // extruder advance constant (s2/mm3)
193 218
 //
194 219
 // advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2
@@ -208,6 +233,7 @@ const int dropsegments=5; //everything with this number of steps  will be ignore
208 233
 
209 234
 #endif // ADVANCE
210 235
 
236
+// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32 
211 237
 #if defined SDSUPPORT
212 238
 // The number of linear motions that can be in the plan at any give time.  
213 239
   #define BLOCK_BUFFER_SIZE 16   // SD,LCD,Buttons take more memory, block buffer needs to be smaller
@@ -215,8 +241,5 @@ const int dropsegments=5; //everything with this number of steps  will be ignore
215 241
   #define BLOCK_BUFFER_SIZE 16 // maximize block buffer
216 242
 #endif
217 243
 
218
-#ifdef SIMPLE_LCD
219
-  #define BLOCK_BUFFER_SIZE 16 // A little less buffer for just a simple LCD
220
-#endif
221 244
 
222 245
 #endif

Marlin/EEPROM.h → Marlin/EEPROMwrite.h 查看文件

@@ -1,13 +1,17 @@
1
-
1
+#ifndef __EEPROMH
2
+#define __EEPROMH
2 3
 #include "planner.h"
3 4
 #include "temperature.h"
5
+#include <EEPROM.h>
6
+#include "Marlin.h"
7
+#include "streaming.h"
4 8
 
5 9
 //======================================================================================
6 10
 template <class T> int EEPROM_writeAnything(int &ee, const T& value)
7 11
 {
8 12
     const byte* p = (const byte*)(const void*)&value;
9 13
     int i;
10
-    for (i = 0; i < sizeof(value); i++)
14
+    for (i = 0; i < (int)sizeof(value); i++)
11 15
 	  EEPROM.write(ee++, *p++);
12 16
     return i;
13 17
 }
@@ -16,7 +20,7 @@ template <class T> int EEPROM_readAnything(int &ee, T& value)
16 20
 {
17 21
     byte* p = (byte*)(void*)&value;
18 22
     int i;
19
-    for (i = 0; i < sizeof(value); i++)
23
+    for (i = 0; i < (int)sizeof(value); i++)
20 24
 	  *p++ = EEPROM.read(ee++);
21 25
     return i;
22 26
 }
@@ -120,4 +124,6 @@ void RetrieveSettings(bool def=false){  // if def=true, the default values will
120 124
   
121 125
 }  
122 126
 
127
+#endif
128
+
123 129
 

+ 418
- 418
Marlin/FatStructs.h 查看文件

@@ -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

+ 314
- 268
Marlin/Makefile 查看文件

@@ -1,274 +1,320 @@
1
+TARGET = $(notdir $(CURDIR))
2
+# CHANGE BELOW:
3
+#~ INSTALL_DIR = /Applications/Arduino.app/Contents/Resources/Java
4
+INSTALL_DIR = /home/bkubicek/software/arduino-0022
5
+#~ PORT = /dev/cu.usbserial*
6
+PORT = /dev/ttyACM0
7
+
8
+# Get these values from:
9
+#     $(INSTALL_DIR)/hardware/boards.txt
10
+#     (arduino-0022/hardware/arduino/boards.txt)
11
+# The values below are for the "Arduino Duemilanove or Nano w/ ATmega328"
12
+# now for "Arduino Mega 2560"
13
+UPLOAD_SPEED = 115200
14
+UPLOAD_PROTOCOL = stk500v2
15
+BUILD_MCU = atmega2560
16
+BUILD_F_CPU = 16000000L
17
+
18
+# getting undefined reference to `__cxa_pure_virtual'
19
+#~ [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254180518 Arduino Forum - Makefile]
20
+#~ http://www.arduino.cc/playground/OpenBSD/CLI
21
+#~ [http://arduino.cc/forum/index.php?topic=52041.0 A "simple" makefile for Arduino]
22
+#~ [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1275488191 Arduino Forum - Configuring avr-gcc options in arduino IDE]
23
+# found in /usr/lib/gcc/avr/4.3.5/cc1plus; fixed with -Wl,--gc-section
24
+
25
+############################################################################
26
+# Below here nothing should be changed...
27
+
28
+ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
1 29
 #
2
-# Arduino 0022 Makefile 
3
-# Uno with DOGS102 Shield
30
+#~ AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin
31
+# in Ubuntu, avr-gcc is installed separate;
32
+# only avrdude comes with the IDE
33
+AVR_TOOLS_PATH = /usr/bin
34
+AVR_DUDE_PATH = $(INSTALL_DIR)/hardware/tools
4 35
 #
5
-# written by olikraus@gmail.com
6
-#
7
-# Features:
8
-#   - boards.txt is used to derive parameters
9
-#   - All intermediate files are put into a separate directory (TMPDIRNAME)
10
-#   - Simple use: Copy Makefile into the same directory of the .pde file
11
-#
12
-# Limitations:
13
-#   - requires UNIX environment
14
-#   - TMPDIRNAME must be subdirectory of the current directory.
15
-#
16
-# Targets
17
-# 	all		build everything
18
-#	upload	build and upload to arduino
19
-#	clean	remove all temporary files (includes final hex file)
20
-#
21
-# History
22
-#	001	28 Apr 2010	first  release
23
-#	002  05 Oct 2010	added 'uno'
24
-#
25
-
26
-#=== user configuration ===
27
-# All ...PATH variables must have a '/' at the end
28
-
29
-# Board (and prozessor) information: see $(ARDUINO_PATH)hardware/arduino/boards.txt
30
-# Some examples:
31
-#	BOARD		DESCRIPTION
32
-#	uno			Arduino Uno
33
-#	atmega328	Arduino Duemilanove or Nano w/ ATmega328
34
-#	diecimila		Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
35
-#	mega		Arduino Mega
36
-#	mini			Arduino Mini
37
-#	lilypad328	LilyPad Arduino w/ ATmega328  
38
-BOARD:=mega
39
-
40
-# additional (comma separated) defines 
41
-# -DDOGM128_HW		board is connected to DOGM128 display
42
-# -DDOGM132_HW		board is connected to DOGM132 display
43
-# -DDOGS102_HW		board is connected to DOGS102 display
44
-# -DDOG_REVERSE		180 degree rotation
45
-# -DDOG_SPI_SW_ARDUINO	force SW shiftOut
46
-DEFS=-DDOGS102_HW -DDOG_DOUBLE_MEMORY -DDOG_SPI_SW_ARDUINO
47
-
48
-# The location where the avr tools (e.g. avr-gcc) are located. Requires a '/' at the end.
49
-# Can be empty if all tools are accessable through the search path
50
-AVR_TOOLS_PATH:=/usr/bin/
51
-
52
-# Install path of the arduino software. Requires a '/' at the end.
53
-ARDUINO_PATH:=/home/bkubicek/software/arduino-0022/
54
-
55
-# Install path for avrdude. Requires a '/' at the end. Can be empty if avrdude is in the search path.
56
-AVRDUDE_PATH:= 
57
-
58
-# The unix device where we can reach the arduino board
59
-# Uno: /dev/ttyACM0
60
-# Duemilanove: /dev/ttyUSB0
61
-AVRDUDE_PORT:=/dev/ttyACM0
62
-
63
-# List of all libaries which should be included.
64
-#EXTRA_DIRS=$(ARDUINO_PATH)libraries/LiquidCrystal/
65
-#EXTRA_DIRS+=$(ARDUINO_PATH)libraries/Dogm/
66
-#EXTRA_DIRS+=/home/kraus/src/arduino/dogm128/hg/libraries/Dogm/
67
-
68
-#=== fetch parameter from boards.txt processor parameter ===
69
-# the basic idea is to get most of the information from boards.txt
70
-
71
-BOARDS_TXT:=$(ARDUINO_PATH)hardware/arduino/boards.txt
72
-
73
-# get the MCU value from the $(BOARD).build.mcu variable. For the atmega328 board this is atmega328p
74
-MCU:=$(shell sed -n -e "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_TXT))
75
-# get the F_CPU value from the $(BOARD).build.f_cpu variable. For the atmega328 board this is 16000000
76
-F_CPU:=$(shell sed -n -e "s/$(BOARD).build.f_cpu=\(.*\)/\1/p" $(BOARDS_TXT))
77
-
78
-# avrdude
79
-# get the AVRDUDE_UPLOAD_RATE value from the $(BOARD).upload.speed variable. For the atmega328 board this is 57600
80
-AVRDUDE_UPLOAD_RATE:=$(shell sed -n -e "s/$(BOARD).upload.speed=\(.*\)/\1/p" $(BOARDS_TXT))
81
-# get the AVRDUDE_PROGRAMMER value from the $(BOARD).upload.protocol variable. For the atmega328 board this is stk500
82
-# AVRDUDE_PROGRAMMER:=$(shell sed -n -e "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_TXT))
83
-# use stk500v1, because stk500 will default to stk500v2
84
-AVRDUDE_PROGRAMMER:=stk500v1
85
-
86
-#=== identify user files ===
87
-PDESRC:=$(shell ls *.pde)
88
-TARGETNAME=$(basename $(PDESRC))
89
-
90
-CDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
91
-CDIRS:=*.c utility/*.c $(addsuffix *.c,$(CDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.c
92
-CSRC:=$(shell ls $(CDIRS) 2>/dev/null)
93
-
94
-CCSRC:=$(shell ls *.cc 2>/dev/null)
95
-
96
-CPPDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
97
-CPPDIRS:=*.cpp utility/*.cpp $(addsuffix *.cpp,$(CPPDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.cpp 
98
-CPPSRC:=$(shell ls $(CPPDIRS) 2>/dev/null)
99
-
100
-#=== build internal variables ===
101
-
102
-# the name of the subdirectory where everything is stored
103
-TMPDIRNAME:=tmp
104
-TMPDIRPATH:=$(TMPDIRNAME)/
105
-
106
-AVRTOOLSPATH:=$(AVR_TOOLS_PATH)
107
-
108
-OBJCOPY:=$(AVRTOOLSPATH)avr-objcopy
109
-OBJDUMP:=$(AVRTOOLSPATH)avr-objdump
110
-SIZE:=$(AVRTOOLSPATH)avr-size
111
-
112
-CPPSRC:=$(addprefix $(TMPDIRPATH),$(PDESRC:.pde=.cpp)) $(CPPSRC)
113
-
114
-COBJ:=$(CSRC:.c=.o)
115
-CCOBJ:=$(CCSRC:.cc=.o)
116
-CPPOBJ:=$(CPPSRC:.cpp=.o)
117
-
118
-OBJFILES:=$(COBJ)  $(CCOBJ)  $(CPPOBJ)
119
-DIRS:= $(dir $(OBJFILES))
120
-
121
-DEPFILES:=$(OBJFILES:.o=.d)
122
-# assembler files from avr-gcc -S
123
-ASSFILES:=$(OBJFILES:.o=.s)
124
-# disassembled object files with avr-objdump -S
125
-DISFILES:=$(OBJFILES:.o=.dis)
126
-
127
-
128
-LIBNAME:=$(TMPDIRPATH)$(TARGETNAME).a
129
-ELFNAME:=$(TMPDIRPATH)$(TARGETNAME).elf
130
-HEXNAME:=$(TMPDIRPATH)$(TARGETNAME).hex
131
-
132
-AVRDUDE_FLAGS = -V -F
133
-AVRDUDE_FLAGS += -C $(ARDUINO_PATH)/hardware/tools/avrdude.conf 
134
-AVRDUDE_FLAGS += -p $(MCU)
135
-AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
136
-AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER) 
137
-AVRDUDE_FLAGS += -b $(AVRDUDE_UPLOAD_RATE)
138
-AVRDUDE_FLAGS += -U flash:w:$(HEXNAME)
139
-
140
-AVRDUDE = avrdude
141
-
142
-#=== predefined variable override ===
143
-# use "make -p -f/dev/null" to see the default rules and definitions
144
-
145
-# Build C and C++ flags. Include path information must be placed here
146
-COMMON_FLAGS = -DF_CPU=$(F_CPU) -mmcu=$(MCU) $(DEFS)
147
-# COMMON_FLAGS += -gdwarf-2
148
-COMMON_FLAGS += -Os
149
-COMMON_FLAGS += -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
150
-COMMON_FLAGS += -I. 
151
-COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/cores/arduino
152
-COMMON_FLAGS += $(addprefix -I,$(EXTRA_DIRS))
153
-COMMON_FLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections
154
-COMMON_FLAGS += -Wl,--relax
155
-COMMON_FLAGS += -mcall-prologues
156
-
157
-CFLAGS = $(COMMON_FLAGS) -std=gnu99 -Wstrict-prototypes  
158
-CXXFLAGS = $(COMMON_FLAGS) 
159
-
160
-# Replace standard build tools by avr tools
161
-CC = $(AVRTOOLSPATH)avr-gcc
162
-CXX = $(AVRTOOLSPATH)avr-g++
163
-AR  = @$(AVRTOOLSPATH)avr-ar
164
-
165
-
166
-# "rm" must be able to delete a directory tree
167
-RM = rm -rf 
168
-
169
-#=== rules ===
170
-
171
-# add rules for the C/C++ files where the .o file is placed in the TMPDIRPATH
172
-# reuse existing variables as far as possible
173
-
174
-$(TMPDIRPATH)%.o: %.c
175
-	@echo compile $<
176
-	@$(COMPILE.c) $(OUTPUT_OPTION) $<
177
-
178
-$(TMPDIRPATH)%.o: %.cc
179
-	@echo compile $< 
180
-	@$(COMPILE.cc) $(OUTPUT_OPTION) $<
181
-
182
-$(TMPDIRPATH)%.o: %.cpp
183
-	@echo compile $<
184
-	@$(COMPILE.cpp) $(OUTPUT_OPTION) $<
185
-
186
-$(TMPDIRPATH)%.s: %.c
187
-	@$(COMPILE.c) $(OUTPUT_OPTION) -S $<
188
-
189
-$(TMPDIRPATH)%.s: %.cc
190
-	@$(COMPILE.cc) $(OUTPUT_OPTION) -S $<
191
-
192
-$(TMPDIRPATH)%.s: %.cpp
193
-	@$(COMPILE.cpp) $(OUTPUT_OPTION) -S $<
194
-
195
-$(TMPDIRPATH)%.dis: $(TMPDIRPATH)%.o
196
-	@$(OBJDUMP) -S $< > $@
197
-
198
-.SUFFIXES: .elf .hex .pde
36
+SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
37
+    $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
38
+    $(ARDUINO)/wiring_pulse.c \
39
+    $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
40
+# added applet/$(TARGET).cpp as in IDE 0022
41
+CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \
42
+    $(ARDUINO)/Print.cpp \
43
+    $(ARDUINO)/main.cpp
44
+#    applet/$(TARGET).cpp # no need, having a rule now for applet/$(TARGET).cpp.o
45
+# added main.cpp, as in 0022
46
+FORMAT = ihex
47
+
48
+# Name of this Makefile (used for "make depend").
49
+MAKEFILE = Makefile
50
+
51
+# Debugging format.
52
+# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
53
+# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
54
+DEBUG = stabs
55
+
56
+OPT = 2
57
+
58
+# Place -D or -U options here
59
+#~ CDEFS = -DBUILD_F_CPU=$(BUILD_F_CPU)
60
+#~ CXXDEFS = -DBUILD_F_CPU=$(BUILD_F_CPU)
61
+# now called DF_CPU
62
+CDEFS = -DF_CPU=$(BUILD_F_CPU) -DARDUINO=22
63
+CXXDEFS = -DF_CPU=$(BUILD_F_CPU) -DARDUINO=22
64
+
65
+# Place -I options here
66
+CINCS = -I$(ARDUINO) -I$(INSTALL_DIR)/libraries/LiquidCrystal/ -I$(INSTALL_DIR)/libraries/EEPROM/
67
+CXXINCS = -I$(ARDUINO)
68
+
69
+# Compiler flag to set the C Standard level.
70
+# c89 - "ANSI" C
71
+# gnu89 - c89 plus GCC extensions
72
+# c99 - ISO C99 standard (not yet fully implemented)
73
+# gnu99 - c99 plus GCC extensions
74
+CSTANDARD = -std=gnu99
75
+CDEBUG = -g$(DEBUG)
76
+# note that typically, IDE 0022 uses -w to suppress warnings (both in cpp and c)!
77
+CWARN = -Wall
78
+#~ CWARN = -w
79
+#  "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++:
80
+CCWARN = -Wstrict-prototypes
81
+CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
82
+#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
83
+
84
+# to eliminate pins_ardiuno warnings:
85
+# http://arduino.cc/pipermail/developers_arduino.cc/2010-December/004005.html
86
+
87
+# [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254180518 Arduino Forum - Makefile]
88
+#~ For building the objects files "-ffunction-sections -fdata-sections" was missing
89
+#~ and the final avr-gcc call needs "-Wl,--gc-section".
90
+CXSECTF = -fno-exceptions -ffunction-sections -fdata-sections
91
+CFINALF = -Wl,--gc-section
92
+
93
+CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CCWARN) $(CSTANDARD) $(CEXTRA)
94
+# added CWARN also to .cpp
95
+CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CXSECTF)
96
+#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
97
+LDFLAGS = -lm
98
+
99
+# Programming support using avrdude. Settings and variables.
100
+AVRDUDE_PORT = $(PORT)
101
+AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
102
+AVRDUDE_FLAGS = -V -F \
103
+    -p $(BUILD_MCU) -P $(AVRDUDE_PORT) -c $(UPLOAD_PROTOCOL) \
104
+    -b $(UPLOAD_SPEED) -C $(INSTALL_DIR)/hardware/tools/avrdude.conf
105
+#    -b $(UPLOAD_SPEED) -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf
106
+
107
+# Program settings
108
+CC = $(AVR_TOOLS_PATH)/avr-gcc
109
+CXX = $(AVR_TOOLS_PATH)/avr-g++
110
+OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
111
+OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
112
+AR = $(AVR_TOOLS_PATH)/avr-ar
113
+SIZE = $(AVR_TOOLS_PATH)/avr-size
114
+NM = $(AVR_TOOLS_PATH)/avr-nm
115
+#~ AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
116
+AVRDUDE = $(AVR_DUDE_PATH)/avrdude
117
+REMOVE = rm -f
118
+MV = mv -f
119
+
120
+# Define all object files.
121
+# NOTE: obj files will be created in respective src directories (libraries or $(INSTALL_DIR));
122
+#  make clean deletes them fine
123
+# note that srcs are in libraries or other directories;
124
+# $(CXXSRC:.cpp=.o) will cause obj files to be in same loc as src files
125
+#~ OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
126
+# to change the output directory for object files;
127
+# must change the obj list here!
128
+# and then, match to corresponding rule somehow?
129
+# or leave this - and parse in rule (auth automatic variable $(@F))?
130
+# "Suffix Replacement"
131
+OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
132
+
133
+# added - OBJ list, transformed into applet/
134
+OBJT = $(addprefix applet/,$(notdir $(OBJ)))
135
+ALLSRC = $(SRC) $(CXXSRC) $(ASRC)
136
+
137
+# Define all listing files.
138
+LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
139
+
140
+# Combine all necessary flags and optional flags.
141
+# Add target processor to flags.
142
+ALL_CFLAGS = -mmcu=$(BUILD_MCU) -I. $(CFLAGS)
143
+ALL_CXXFLAGS = -mmcu=$(BUILD_MCU) -I. $(CXXFLAGS)
144
+ALL_ASFLAGS = -mmcu=$(BUILD_MCU) -I. -x assembler-with-cpp $(ASFLAGS)
145
+
146
+# depended libraries of .pde need to be added from
147
+# $(INSTALL_DIR)/libraries (TODO: and/or ~/sketchbook/libraries)
148
+# grep for 'include', test if exists, add...
149
+# note: prefix "a real tab character" http://www.delorie.com/djgpp/doc/ug/larger/makefiles.html
150
+# $$ to escape $ for shell;
151
+# note: must NOT put comments # inside bash execution;
152
+# those would get removed by make; making shell see "EOF in backquote substitution"
153
+#		 echo $$ix ; \
154
+# 'shell' twice - for each subprocess! Backtick doesn't get expanded?
155
+GREPRES:=$(shell for ix in $(shell grep include $(TARGET).pde | sed 's/.*[<"]\(.*\).h[>"].*/\1/'); do \
156
+		if [ -d $(INSTALL_DIR)/libraries/$$ix ] ; then \
157
+			LINCS="$$LINCS -I$(INSTALL_DIR)/libraries/$$ix" ;\
158
+		fi; \
159
+	done; \
160
+	echo $$LINCS)
161
+# append includes:
162
+CINCS += $(GREPRES)
163
+CXXINCS += $(GREPRES)
164
+# append library source .cpp files too (CXXSRC)
165
+GREPRESB:=$(shell for ix in $(shell grep include $(TARGET).pde | sed 's/.*[<"]\(.*\).h[>"].*/\1/'); do \
166
+		if [ -d $(INSTALL_DIR)/libraries/$$ix ] ; then \
167
+			CPPSRCS="$$CPPSRCS $(INSTALL_DIR)/libraries/$$ix/*.cpp" ;\
168
+		fi; \
169
+	done; \
170
+	echo $$CPPSRCS)
171
+CXXSRC += $(GREPRESB)
172
+# added - only CXX obj from libraries:
173
+CXXLIBOBJ = $(GREPRESB:.cpp=.o)
174
+
175
+# Default target.
176
+all: applet_files build sizeafter
177
+
178
+build: elf hex
179
+
180
+applet_files: $(TARGET).pde
181
+    # Here is the "preprocessing".
182
+    # It creates a .cpp file based with the same name as the .pde file.
183
+    # On top of the new .cpp file comes the WProgram.h header.
184
+    # At the end there is a generic main() function attached.
185
+    # Then the .cpp file will be compiled. Errors during compile will
186
+    # refer to this new, automatically generated, file.
187
+    # Not the original .pde file you actually edit...
188
+	test -d applet || mkdir applet
189
+    # @ supresses printout of the cmdline itself; so only the out of echo is printed
190
+	@echo ALL OBJT: $(OBJT)
191
+	@echo ALL CXXLIBOBJ: $(CXXLIBOBJ)
192
+#	echo '#include "WProgram.h"' > applet/$(TARGET).cpp
193
+	@echo "#include \"WProgram.h\"\nvoid setup();\nvoid loop();\n" > applet/$(TARGET).cpp
194
+	cat $(TARGET).pde >> applet/$(TARGET).cpp
195
+    # no more need to cat main.cpp (v0022) - now it is compiled in
196
+#	cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp
197
+
198
+
199
+elf: applet/$(TARGET).elf
200
+hex: applet/$(TARGET).hex
201
+eep: applet/$(TARGET).eep
202
+lss: applet/$(TARGET).lss
203
+sym: applet/$(TARGET).sym
204
+
205
+# Program the device.
206
+upload: applet/$(TARGET).hex
207
+	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
208
+
209
+# Display size of file.
210
+HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
211
+ELFSIZE = $(SIZE) applet/$(TARGET).elf
212
+sizebefore:
213
+	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
214
+
215
+sizeafter:
216
+	@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
217
+
218
+# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
219
+COFFCONVERT=$(OBJCOPY) --debugging \
220
+    --change-section-address .data-0x800000 \
221
+    --change-section-address .bss-0x800000 \
222
+    --change-section-address .noinit-0x800000 \
223
+    --change-section-address .eeprom-0x810000
224
+
225
+coff: applet/$(TARGET).elf
226
+	$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
227
+
228
+extcoff: $(TARGET).elf
229
+	$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
230
+
231
+.SUFFIXES: .elf .hex .eep .lss .sym
199 232
 
200 233
 .elf.hex:
201
-	@$(OBJCOPY) -O ihex -R .eeprom $< $@
202
-	
203
-$(TMPDIRPATH)%.cpp: %.pde
204
-	@cat $(ARDUINO_PATH)hardware/arduino/cores/arduino/main.cpp > $@
205
-	@cat $< >> $@
206
-	@echo >> $@
207
-	@echo 'extern "C" void __cxa_pure_virtual() { while (1); }' >> $@
208
-
209
-
210
-.PHONY: all
211
-all: tmpdir $(HEXNAME) assemblersource showsize
212
-	ls -al $(HEXNAME) $(ELFNAME)
213
-
214
-$(ELFNAME): $(LIBNAME)($(addprefix $(TMPDIRPATH),$(OBJFILES))) 
215
-	$(LINK.o) $(COMMON_FLAGS) $(LIBNAME) $(LOADLIBES) $(LDLIBS) -o $@
216
-
217
-$(LIBNAME)(): $(addprefix $(TMPDIRPATH),$(OBJFILES))
218
-
219
-#=== create temp directory ===
220
-# not really required, because it will be also created during the dependency handling
221
-.PHONY: tmpdir
222
-tmpdir:
223
-	@test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH)
224
-
225
-#=== create assembler files for each C/C++ file ===
226
-.PHONY: assemblersource
227
-assemblersource: $(addprefix $(TMPDIRPATH),$(ASSFILES)) $(addprefix $(TMPDIRPATH),$(DISFILES))
228
-
229
-
230
-#=== show the section sizes of the ELF file ===
231
-.PHONY: showsize
232
-showsize: $(ELFNAME)
233
-	$(SIZE) $<
234
-
235
-#=== clean up target ===
236
-# this is simple: the TMPDIRPATH is removed
237
-.PHONY: clean
234
+	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
235
+
236
+.elf.eep:
237
+    -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
238
+    --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
239
+
240
+# Create extended listing file from ELF output file.
241
+.elf.lss:
242
+	$(OBJDUMP) -h -S $< > $@
243
+
244
+# Create a symbol table from ELF output file.
245
+.elf.sym:
246
+	$(NM) -n $< > $@
247
+
248
+# Link: create ELF output file from library.
249
+# NOTE: applet/$(TARGET).cpp.o MUST BE BEFORE applet/core.a
250
+#  in the dependency list, so its rule runs first!
251
+applet/$(TARGET).elf: $(TARGET).pde applet/$(TARGET).cpp.o applet/core.a
252
+#	$(CC) $(ALL_CFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
253
+# changed as in IDE v0022: link cpp obj files
254
+	@echo $$(tput bold)$$(tput setaf 2) $(CC) $$(tput sgr0) $(ALL_CFLAGS) $(CFINALF) -o $@ applet/$(TARGET).cpp.o $(CXXOBJ) -L. applet/core.a $(LDFLAGS)
255
+	@$(CC) $(ALL_CFLAGS) $(CFINALF) -o $@ applet/$(TARGET).cpp.o $(CXXOBJ) -L. applet/core.a $(LDFLAGS)
256
+
257
+# added: cpp.o depends on cpp (and .pde which generates it)
258
+# $< "first item in the dependencies list"; $@ "left side of the :"; $^ "right side of the :"
259
+# http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
260
+applet/$(TARGET).cpp.o: applet/$(TARGET).cpp
261
+	@echo $$(tput bold) $(CXX) $$(tput sgr0) -c $(ALL_CXXFLAGS) $< -o $@
262
+	@$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
263
+
264
+#~ applet/core.a: $(OBJ)
265
+#~	 @for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
266
+
267
+applet/core.a: $(OBJT)
268
+	 @for i in $(OBJT); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
269
+
270
+# iterate through OBJ to find the original location; then build depending on source extension
271
+# TODO: add handling of assembler files
272
+applet/%.o:
273
+	@for iob in $(OBJ); do \
274
+		if [ "`basename $$iob`" = "`basename $@`" ]; then \
275
+			for ios in $(ALLSRC); do \
276
+				if [ "$${iob%%.*}" = "$${ios%%.*}" ]; then \
277
+					case $${ios##*.} in \
278
+						"cpp") \
279
+							echo "$$(tput bold)$$(tput setaf 1) $(CXX) $$(tput sgr0) -c $(ALL_CXXFLAGS) $$ios -o $@"; \
280
+							$(CXX) -c $(ALL_CXXFLAGS) $$ios -o $@;; \
281
+						"c") \
282
+							echo "$$(tput bold)$$(tput setaf 1) $(CC) $$(tput sgr0) -c $(ALL_CFLAGS) $$ios -o $@"; \
283
+							$(CC) -c $(ALL_CFLAGS) $$ios -o $@;; \
284
+					esac; \
285
+				fi; \
286
+			done; \
287
+		fi; \
288
+	done;
289
+
290
+#~ # Compile: create object files from C++ source files.
291
+#~ .cpp.o:
292
+#~	 $(CXX) -c $(ALL_CXXFLAGS) $< -o $@
293
+
294
+#~ # Compile: create object files from C source files.
295
+#~ .c.o:
296
+#~	 $(CC) -c $(ALL_CFLAGS) $< -o $@
297
+
298
+#~ # Compile: create assembler files from C source files.
299
+#~ .c.s:
300
+#~	 $(CC) -S $(ALL_CFLAGS) $< -o $@
301
+
302
+#~ # Assemble: create object files from assembler source files.
303
+#~ .S.o:
304
+#~	 $(CC) -c $(ALL_ASFLAGS) $< -o $@
305
+
306
+#~ # Automatic dependencies
307
+#~ %.d: %.c
308
+#~	 $(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
309
+
310
+#~ %.d: %.cpp
311
+#~	 $(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
312
+
313
+# Target: clean project.
238 314
 clean:
239
-	$(RM) $(TMPDIRPATH)
240
-
241
-# Program the device.  
242
-# step 1: reset the arduino board with the stty command
243
-# step 2: user avrdude to upload the software
244
-.PHONY: upload
245
-upload: $(HEXNAME)
246
-	stty -F $(AVRDUDE_PORT) hupcl
247
-	$(AVRDUDE) $(AVRDUDE_FLAGS)
248
-
249
-
250
-# === dependency handling ===
251
-# From the gnu make manual (section 4.14, Generating Prerequisites Automatically)
252
-# Additionally (because this will be the first executed rule) TMPDIRPATH is created here.
253
-# Instead of "sed" the "echo" command is used
254
-# cd $(TMPDIRPATH); mkdir -p $(DIRS) 2> /dev/null; cd ..
255
-DEPACTION=test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH);\
256
-mkdir -p $(addprefix $(TMPDIRPATH),$(DIRS));\
257
-set -e; echo -n $@ $(dir $@) > $@; $(CC) -MM $(COMMON_FLAGS) $< >> $@
258
-
259
-
260
-$(TMPDIRPATH)%.d: %.c
261
-	@$(DEPACTION)
262
-
263
-$(TMPDIRPATH)%.d: %.cc
264
-	@$(DEPACTION)
265
-
266
-
267
-$(TMPDIRPATH)%.d: %.cpp
268
-	@$(DEPACTION)
269
-
270
-# Include dependency files. If a .d file is missing, a warning is created and the .d file is created
271
-# This warning is not a problem (gnu make manual, section 3.3 Including Other Makefiles)
272
--include $(addprefix $(TMPDIRPATH),$(DEPFILES))
273
-
315
+	$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
316
+        applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \
317
+        $(OBJT) applet/$(TARGET).cpp.o \
318
+        $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
274 319
 
320
+.PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter

+ 2
- 3
Marlin/Marlin.h 查看文件

@@ -68,7 +68,7 @@ void kill();
68 68
 //void st_wake_up();
69 69
 //void st_synchronize();
70 70
 void enquecommand(const char *cmd);
71
-void wd_reset();
71
+
72 72
 
73 73
 #ifndef CRITICAL_SECTION_START
74 74
 #define CRITICAL_SECTION_START  unsigned char _sreg = SREG; cli();
@@ -78,6 +78,5 @@ void wd_reset();
78 78
 extern float homing_feedrate[];
79 79
 extern bool axis_relative_modes[];
80 80
 
81
-void manage_inactivity(byte debug);
82
-
81
+void wd_reset() ;
83 82
 #endif

+ 38
- 38
Marlin/Marlin.pde 查看文件

@@ -25,7 +25,7 @@
25 25
     http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
26 26
  */
27 27
 
28
-#include <EEPROM.h>
28
+#include "EEPROMwrite.h"
29 29
 #include "fastio.h"
30 30
 #include "Configuration.h"
31 31
 #include "pins.h"
@@ -171,7 +171,7 @@ bool sdmode = false;
171 171
 bool sdactive = false;
172 172
 bool savetosd = false;
173 173
 int16_t n;
174
-long autostart_atmillis=0;
174
+unsigned long autostart_atmillis=0;
175 175
 
176 176
 void initsd(){
177 177
   sdactive = false;
@@ -290,24 +290,24 @@ void checkautostart(bool force)
290 290
 		if(!sdactive) //fail
291 291
 		return;
292 292
 	}
293
-	static int lastnr=0;
294
-	char autoname[30];
295
-	sprintf(autoname,"auto%i.g",lastnr);
296
-	for(int i=0;i<strlen(autoname);i++)
297
-		autoname[i]=tolower(autoname[i]);
298
-	dir_t p;
299
-
300
-	root.rewind();
301
-	char filename[11];
302
-	int cnt=0;
303
-
304
-	bool found=false;
305
-	while (root.readDir(p) > 0) 
306
-	{
307
-		for(int i=0;i<strlen((char*)p.name);i++)
308
-			p.name[i]=tolower(p.name[i]);
309
-		//Serial.print((char*)p.name);
310
-		//Serial.print(" ");
293
+        static int lastnr=0;
294
+        char autoname[30];
295
+        sprintf(autoname,"auto%i.g",lastnr);
296
+        for(int i=0;i<(int)strlen(autoname);i++)
297
+                autoname[i]=tolower(autoname[i]);
298
+        dir_t p;
299
+
300
+        root.rewind();
301
+        //char filename[11];
302
+        //int cnt=0;
303
+
304
+        bool found=false;
305
+        while (root.readDir(p) > 0) 
306
+        {
307
+                for(int i=0;i<(int)strlen((char*)p.name);i++)
308
+                        p.name[i]=tolower(p.name[i]);
309
+                //Serial.print((char*)p.name);
310
+                //Serial.print(" ");
311 311
 		//Serial.println(autoname);
312 312
 		if(p.name[9]!='~') //skip safety copies
313 313
 		if(strncmp((char*)p.name,autoname,5)==0)
@@ -774,8 +774,8 @@ inline void process_commands()
774 774
 				sprintf(time,"%i min, %i sec",min,sec);
775 775
 				Serial.println(time);
776 776
 				LCD_MESSAGE(time);
777
-		}
778
-				break;
777
+                }
778
+                                break;
779 779
 #endif //SDSUPPORT
780 780
       case 42: //M42 -Change pin status via gcode
781 781
         if (code_seen('S'))
@@ -784,7 +784,7 @@ inline void process_commands()
784 784
           if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
785 785
           {
786 786
             int pin_number = code_value();
787
-            for(int i = 0; i < sizeof(sensitive_pins); i++)
787
+            for(int i = 0; i < (int)sizeof(sensitive_pins); i++)
788 788
             {
789 789
               if (sensitive_pins[i] == pin_number)
790 790
               {
@@ -803,28 +803,28 @@ inline void process_commands()
803 803
         }
804 804
         break;
805 805
       case 104: // M104
806
-                if (code_seen('S')) target_raw[0] = temp2analog(code_value());
806
+                if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
807 807
 #ifdef PIDTEMP
808 808
                 pid_setpoint = code_value();
809 809
 #endif //PIDTEM
810 810
         #ifdef WATCHPERIOD
811
-            if(target_raw[0] > current_raw[0]){
811
+            if(target_raw[TEMPSENSOR_HOTEND] > current_raw[TEMPSENSOR_HOTEND]){
812 812
                 watchmillis = max(1,millis());
813
-                watch_raw = current_raw[0];
813
+                watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
814 814
             }else{
815 815
                 watchmillis = 0;
816 816
             }
817 817
         #endif
818 818
         break;
819 819
       case 140: // M140 set bed temp
820
-                if (code_seen('S')) target_raw[1] = temp2analogBed(code_value());
820
+                if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analogBed(code_value());
821 821
         break;
822 822
       case 105: // M105
823 823
         #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
824
-                tt = analog2temp(current_raw[0]);
824
+                tt = analog2temp(current_raw[TEMPSENSOR_HOTEND]);
825 825
         #endif
826 826
         #if TEMP_1_PIN > -1
827
-                bt = analog2tempBed(current_raw[1]);
827
+                bt = analog2tempBed(current_raw[TEMPSENSOR_BED]);
828 828
         #endif
829 829
         #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
830 830
             Serial.print("ok T:");
@@ -852,14 +852,14 @@ inline void process_commands()
852 852
         //break;
853 853
       case 109: {// M109 - Wait for extruder heater to reach target.
854 854
             LCD_MESSAGE("Heating...");
855
-            if (code_seen('S')) target_raw[0] = temp2analog(code_value());
855
+               if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
856 856
             #ifdef PIDTEMP
857 857
             pid_setpoint = code_value();
858 858
             #endif //PIDTEM
859 859
             #ifdef WATCHPERIOD
860
-            if(target_raw[0]>current_raw[0]) {
860
+          if(target_raw[TEMPSENSOR_HOTEND]>current_raw[TEMPSENSOR_HOTEND]){
861 861
               watchmillis = max(1,millis());
862
-              watch_raw = current_raw[0];
862
+              watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
863 863
             } else {
864 864
               watchmillis = 0;
865 865
             }
@@ -881,7 +881,7 @@ inline void process_commands()
881 881
             #endif //TEMP_RESIDENCY_TIME
882 882
               if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
883 883
                 Serial.print("T:");
884
-                Serial.println( analog2temp(current_raw[0]) );
884
+              Serial.println( analog2temp(current_raw[TEMPSENSOR_HOTEND]) ); 
885 885
                 codenum = millis();
886 886
               }
887 887
               manage_heater();
@@ -895,25 +895,25 @@ inline void process_commands()
895 895
                 residencyStart = millis();
896 896
               }
897 897
               #endif //TEMP_RESIDENCY_TIME
898
-	    }
898
+            }
899 899
             LCD_MESSAGE("Marlin ready.");
900 900
           }
901 901
           break;
902 902
       case 190: // M190 - Wait bed for heater to reach target.
903 903
       #if TEMP_1_PIN > -1
904
-          if (code_seen('S')) target_raw[1] = temp2analog(code_value());
904
+          if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analog(code_value());
905 905
         codenum = millis(); 
906
-          while(current_raw[1] < target_raw[1]) 
906
+          while(current_raw[TEMPSENSOR_BED] < target_raw[TEMPSENSOR_BED]) 
907 907
                                 {
908 908
           if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
909 909
           {
910
-            float tt=analog2temp(current_raw[0]);
910
+            float tt=analog2temp(current_raw[TEMPSENSOR_HOTEND]);
911 911
             Serial.print("T:");
912 912
             Serial.println( tt );
913 913
             Serial.print("ok T:");
914 914
             Serial.print( tt ); 
915 915
             Serial.print(" B:");
916
-            Serial.println( analog2temp(current_raw[1]) ); 
916
+            Serial.println( analog2temp(current_raw[TEMPSENSOR_BED]) ); 
917 917
             codenum = millis(); 
918 918
           }
919 919
             manage_heater();

+ 643
- 643
Marlin/Sd2Card.cpp
文件差异内容过多而无法显示
查看文件


+ 233
- 233
Marlin/Sd2Card.h 查看文件

@@ -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 查看文件

@@ -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
文件差异内容过多而无法显示
查看文件


+ 70
- 70
Marlin/SdFatUtil.h 查看文件

@@ -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 查看文件

@@ -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
文件差异内容过多而无法显示
查看文件


+ 232
- 232
Marlin/SdInfo.h 查看文件

@@ -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 查看文件

@@ -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
+}

+ 2559
- 2559
Marlin/fastio.h
文件差异内容过多而无法显示
查看文件


+ 0
- 10
Marlin/lcd.h 查看文件

@@ -1,10 +0,0 @@
1
-#ifndef __LCDH
2
-#define __LCDH
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-#endif

+ 0
- 1
Marlin/lcd.pde 查看文件

@@ -1 +0,0 @@
1
-

+ 570
- 570
Marlin/pins.h
文件差异内容过多而无法显示
查看文件


+ 586
- 584
Marlin/planner.cpp
文件差异内容过多而无法显示
查看文件


+ 92
- 90
Marlin/planner.h 查看文件

@@ -1,90 +1,92 @@
1
-/*
2
-  planner.h - buffers movement commands and manages the acceleration profile plan
3
-  Part of Grbl
4
-
5
-  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
-
7
-  Grbl 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
-  Grbl 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 Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
-*/
20
-
21
-// This module is to be considered a sub-module of stepper.c. Please don't include 
22
-// this file from any other module.
23
-
24
-#ifndef planner_h
25
-#define planner_h
26
-
27
-// This struct is used when buffering the setup for each linear movement "nominal" values are as specified in 
28
-// the source g-code and may never actually be reached if acceleration management is active.
29
-typedef struct {
30
-  // Fields used by the bresenham algorithm for tracing the line
31
-  long steps_x, steps_y, steps_z, steps_e;  // Step count along each axis
32
-  long step_event_count;                    // The number of step events required to complete this block
33
-  volatile long accelerate_until;                    // The index of the step event on which to stop acceleration
34
-  volatile long decelerate_after;                    // The index of the step event on which to start decelerating
35
-  volatile long acceleration_rate;                   // The acceleration rate used for acceleration calculation
36
-  unsigned char direction_bits;             // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
37
-#ifdef ADVANCE
38
-  long advance_rate;
39
-  volatile long initial_advance;
40
-  volatile long final_advance;
41
-  float advance;
42
-#endif
43
-
44
-  // Fields used by the motion planner to manage acceleration
45
-  float speed_x, speed_y, speed_z, speed_e;          // Nominal mm/minute for each axis
46
-  float nominal_speed;                               // The nominal speed for this block in mm/min  
47
-  float millimeters;                                 // The total travel of this block in mm
48
-  float entry_speed;
49
-  float acceleration;                                // acceleration mm/sec^2
50
-
51
-  // Settings for the trapezoid generator
52
-  long nominal_rate;                                 // The nominal step rate for this block in step_events/sec 
53
-  volatile long initial_rate;                        // The jerk-adjusted step rate at start of block  
54
-  volatile long final_rate;                          // The minimal rate at exit
55
-  long acceleration_st;                              // acceleration steps/sec^2
56
-  volatile char busy;
57
-} block_t;
58
-      
59
-// Initialize the motion plan subsystem      
60
-void plan_init();
61
-
62
-// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 
63
-// millimaters. Feed rate specifies the speed of the motion.
64
-void plan_buffer_line(float x, float y, float z, float e, float feed_rate);
65
-
66
-// Set position. Used for G92 instructions.
67
-void plan_set_position(float x, float y, float z, float e);
68
-
69
-// Called when the current block is no longer needed. Discards the block and makes the memory
70
-// availible for new blocks.
71
-void plan_discard_current_block();
72
-
73
-// Gets the current block. Returns NULL if buffer empty
74
-block_t *plan_get_current_block();
75
-
76
-void check_axes_activity();
77
-
78
-extern unsigned long minsegmenttime;
79
-extern float max_feedrate[4]; // set the max speeds
80
-extern float axis_steps_per_unit[4];
81
-extern long max_acceleration_units_per_sq_second[4]; // Use M201 to override by software
82
-extern float minimumfeedrate;
83
-extern float acceleration;         // Normal acceleration mm/s^2  THIS IS THE DEFAULT ACCELERATION for all moves. M204 SXXXX
84
-extern float retract_acceleration; //  mm/s^2   filament pull-pack and push-forward  while standing still in the other axis M204 TXXXX
85
-extern float max_xy_jerk; //speed than can be stopped at once, if i understand correctly.
86
-extern float max_z_jerk;
87
-extern float mintravelfeedrate;
88
-extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
89
-
90
-#endif
1
+/*
2
+  planner.h - buffers movement commands and manages the acceleration profile plan
3
+  Part of Grbl
4
+
5
+  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
+
7
+  Grbl 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
+  Grbl 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 Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
+*/
20
+
21
+// This module is to be considered a sub-module of stepper.c. Please don't include 
22
+// this file from any other module.
23
+
24
+#ifndef planner_h
25
+#define planner_h
26
+
27
+#include "Configuration.h"
28
+
29
+// This struct is used when buffering the setup for each linear movement "nominal" values are as specified in 
30
+// the source g-code and may never actually be reached if acceleration management is active.
31
+typedef struct {
32
+  // Fields used by the bresenham algorithm for tracing the line
33
+  long steps_x, steps_y, steps_z, steps_e;  // Step count along each axis
34
+  long step_event_count;                    // The number of step events required to complete this block
35
+  volatile long accelerate_until;                    // The index of the step event on which to stop acceleration
36
+  volatile long decelerate_after;                    // The index of the step event on which to start decelerating
37
+  volatile long acceleration_rate;                   // The acceleration rate used for acceleration calculation
38
+  unsigned char direction_bits;             // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
39
+#ifdef ADVANCE
40
+  long advance_rate;
41
+  volatile long initial_advance;
42
+  volatile long final_advance;
43
+  float advance;
44
+#endif
45
+
46
+  // Fields used by the motion planner to manage acceleration
47
+  float speed_x, speed_y, speed_z, speed_e;          // Nominal mm/minute for each axis
48
+  float nominal_speed;                               // The nominal speed for this block in mm/min  
49
+  float millimeters;                                 // The total travel of this block in mm
50
+  float entry_speed;
51
+  float acceleration;                                // acceleration mm/sec^2
52
+
53
+  // Settings for the trapezoid generator
54
+  long nominal_rate;                                 // The nominal step rate for this block in step_events/sec 
55
+  volatile long initial_rate;                        // The jerk-adjusted step rate at start of block  
56
+  volatile long final_rate;                          // The minimal rate at exit
57
+  long acceleration_st;                              // acceleration steps/sec^2
58
+  volatile char busy;
59
+} block_t;
60
+      
61
+// Initialize the motion plan subsystem      
62
+void plan_init();
63
+
64
+// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 
65
+// millimaters. Feed rate specifies the speed of the motion.
66
+void plan_buffer_line(float x, float y, float z, float e, float feed_rate);
67
+
68
+// Set position. Used for G92 instructions.
69
+void plan_set_position(float x, float y, float z, float e);
70
+
71
+// Called when the current block is no longer needed. Discards the block and makes the memory
72
+// availible for new blocks.
73
+void plan_discard_current_block();
74
+
75
+// Gets the current block. Returns NULL if buffer empty
76
+block_t *plan_get_current_block();
77
+
78
+void check_axes_activity();
79
+
80
+extern unsigned long minsegmenttime;
81
+extern float max_feedrate[4]; // set the max speeds
82
+extern float axis_steps_per_unit[4];
83
+extern long max_acceleration_units_per_sq_second[4]; // Use M201 to override by software
84
+extern float minimumfeedrate;
85
+extern float acceleration;         // Normal acceleration mm/s^2  THIS IS THE DEFAULT ACCELERATION for all moves. M204 SXXXX
86
+extern float retract_acceleration; //  mm/s^2   filament pull-pack and push-forward  while standing still in the other axis M204 TXXXX
87
+extern float max_xy_jerk; //speed than can be stopped at once, if i understand correctly.
88
+extern float max_z_jerk;
89
+extern float mintravelfeedrate;
90
+extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
91
+
92
+#endif

+ 75
- 75
Marlin/speed_lookuptable.h 查看文件

@@ -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
文件差异内容过多而无法显示
查看文件


+ 44
- 40
Marlin/stepper.h 查看文件

@@ -1,40 +1,44 @@
1
-/*
2
-  stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
3
-  Part of Grbl
4
-
5
-  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
-
7
-  Grbl 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
-  Grbl 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 Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
-*/
20
-
21
-#ifndef stepper_h
22
-#define stepper_h 
23
-// Initialize and start the stepper motor subsystem
24
-void st_init();
25
-
26
-// Block until all buffered steps are executed
27
-void st_synchronize();
28
-
29
-// The stepper subsystem goes to sleep when it runs out of things to execute. Call this
30
-// to notify the subsystem that it is time to go to work.
31
-void st_wake_up();
32
-
33
-// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
34
-// for debugging purposes only, should be disabled by default
35
-#ifdef DEBUG_STEPS
36
-extern volatile long count_position[NUM_AXIS];
37
-extern volatile int count_direction[NUM_AXIS];
38
-#endif
39
-
40
-#endif
1
+/*
2
+  stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
3
+  Part of Grbl
4
+
5
+  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
+
7
+  Grbl 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
+  Grbl 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 Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
+*/
20
+
21
+#ifndef stepper_h
22
+#define stepper_h 
23
+
24
+#include "planner.h"
25
+
26
+// Initialize and start the stepper motor subsystem
27
+void st_init();
28
+
29
+// Block until all buffered steps are executed
30
+void st_synchronize();
31
+
32
+// The stepper subsystem goes to sleep when it runs out of things to execute. Call this
33
+// to notify the subsystem that it is time to go to work.
34
+void st_wake_up();
35
+
36
+// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
37
+// for debugging purposes only, should be disabled by default
38
+#ifdef DEBUG_STEPS
39
+extern volatile long count_position[NUM_AXIS];
40
+extern volatile int count_direction[NUM_AXIS];
41
+#endif
42
+
43
+extern block_t *current_block;  // A pointer to the block currently being traced
44
+#endif

+ 84
- 84
Marlin/streaming.h 查看文件

@@ -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
+

+ 24
- 19
Marlin/temperature.cpp 查看文件

@@ -97,14 +97,15 @@ void manage_heater()
97 97
   
98 98
   float pid_input;
99 99
   float pid_output;
100
-  if(temp_meas_ready == true) {
100
+  if(temp_meas_ready != true)   //better readability
101
+    return; 
101 102
 
102 103
 CRITICAL_SECTION_START;
103 104
     temp_meas_ready = false;
104 105
 CRITICAL_SECTION_END;
105 106
 
106 107
 #ifdef PIDTEMP
107
-    pid_input = analog2temp(current_raw[0]);
108
+    pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND]);
108 109
 
109 110
 #ifndef PID_OPENLOOP
110 111
     pid_error = pid_setpoint - pid_input;
@@ -125,10 +126,13 @@ CRITICAL_SECTION_END;
125 126
       temp_iState += pid_error;
126 127
       temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
127 128
       iTerm = Ki * temp_iState;
128
-      #define K1 0.95
129
+      //K1 defined in Configuration.h in the PID settings
129 130
       #define K2 (1.0-K1)
130 131
       dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
131 132
       temp_dState = pid_input;
133
+      #ifdef PID_ADD_EXTRUSION_RATE
134
+        pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high
135
+      #endif
132 136
       pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
133 137
     }
134 138
 #endif //PID_OPENLOOP
@@ -164,7 +168,7 @@ CRITICAL_SECTION_END;
164 168
   previous_millis_bed_heater = millis();
165 169
   
166 170
   #if TEMP_1_PIN > -1
167
-    if(current_raw[1] >= target_raw[1])
171
+    if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
168 172
     {
169 173
       WRITE(HEATER_1_PIN,LOW);
170 174
     }
@@ -174,7 +178,6 @@ CRITICAL_SECTION_END;
174 178
     }
175 179
   #endif
176 180
   }
177
-}
178 181
 
179 182
 // Takes hot end temperature value as input and returns corresponding raw value. 
180 183
 // For a thermistor, it uses the RepRap thermistor temp table.
@@ -325,15 +328,18 @@ void tp_init()
325 328
   TIMSK0 |= (1<<OCIE0B);  
326 329
 }
327 330
 
328
-static unsigned char temp_count = 0;
329
-static unsigned long raw_temp_0_value = 0;
330
-static unsigned long raw_temp_1_value = 0;
331
-static unsigned long raw_temp_2_value = 0;
332
-static unsigned char temp_state = 0;
331
+
333 332
 
334 333
 // Timer 0 is shared with millies
335 334
 ISR(TIMER0_COMPB_vect)
336 335
 {
336
+  //these variables are only accesible from the ISR, but static, so they don't loose their value
337
+  static unsigned char temp_count = 0;
338
+  static unsigned long raw_temp_0_value = 0;
339
+  static unsigned long raw_temp_1_value = 0;
340
+  static unsigned long raw_temp_2_value = 0;
341
+  static unsigned char temp_state = 0;
342
+  
337 343
   switch(temp_state) {
338 344
     case 0: // Prepare TEMP_0
339 345
             #if (TEMP_0_PIN > -1)
@@ -434,18 +440,17 @@ ISR(TIMER0_COMPB_vect)
434 440
     raw_temp_2_value = 0;
435 441
 #ifdef HEATER_0_MAXTEMP
436 442
   #if (HEATER_0_PIN > -1)
437
-    if(current_raw[0] >= maxttemp_0) {
438
-      target_raw[0] = 0;
443
+    if(current_raw[TEMPSENSOR_HOTEND] >= maxttemp) {
444
+      target_raw[TEMPSENSOR_HOTEND] = 0;
439 445
       analogWrite(HEATER_0_PIN, 0);
440 446
       Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!");
441 447
       kill();
442 448
     }
443 449
   #endif
444 450
 #endif
445
-#ifdef HEATER_1_MAXTEMP
446
-  #if (HEATER_1_PIN > -1)
451
+    if(current_raw[TEMPSENSOR_AUX] >= maxttemp) {
452
+      target_raw[TEMPSENSOR_AUX] = 0;
447 453
     if(current_raw[2] >= maxttemp_1) {
448
-      target_raw[2] = 0;
449 454
       analogWrite(HEATER_2_PIN, 0);
450 455
       Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!");
451 456
       kill()
@@ -454,8 +459,8 @@ ISR(TIMER0_COMPB_vect)
454 459
 #endif //MAXTEMP
455 460
 #ifdef HEATER_0_MINTEMP
456 461
   #if (HEATER_0_PIN > -1)
457
-    if(current_raw[0] <= minttemp_0) {
458
-      target_raw[0] = 0;
462
+    if(current_raw[TEMPSENSOR_HOTEND] <= minttemp) {
463
+      target_raw[TEMPSENSOR_HOTEND] = 0;
459 464
       analogWrite(HEATER_0_PIN, 0);
460 465
       Serial.println("!! Temperature extruder 0 switched off. MINTEMP triggered !!");
461 466
       kill();
@@ -464,8 +469,8 @@ ISR(TIMER0_COMPB_vect)
464 469
 #endif
465 470
 #ifdef HEATER_1_MINTEMP
466 471
   #if (HEATER_2_PIN > -1)
467
-    if(current_raw[2] <= minttemp_1) {
468
-      target_raw[2] = 0;
472
+    if(current_raw[TEMPSENSOR_AUX] <= minttemp) {
473
+      target_raw[TEMPSENSOR_AUX] = 0;
469 474
       analogWrite(HEATER_2_PIN, 0);
470 475
       Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!");
471 476
       kill();

+ 5
- 2
Marlin/temperature.h 查看文件

@@ -21,8 +21,10 @@
21 21
 #ifndef temperature_h
22 22
 #define temperature_h 
23 23
 
24
-void manage_inactivity(byte debug);
25
-
24
+#include "Marlin.h"
25
+#ifdef PID_ADD_EXTRUSION_RATE
26
+  #include "stepper.h"
27
+#endif
26 28
 void tp_init();
27 29
 void manage_heater();
28 30
 //int temp2analogu(int celsius, const short table[][2], int numtemps);
@@ -48,6 +50,7 @@ extern float Ki;
48 50
 extern float Kd;
49 51
 extern float Kc;
50 52
 
53
+enum {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2};
51 54
 extern int target_raw[3];
52 55
 extern int current_raw[3];
53 56
 extern double pid_setpoint;

+ 90
- 90
Marlin/thermistortables.h 查看文件

@@ -7,67 +7,67 @@
7 7
 
8 8
 #define NUMTEMPS_1 61
9 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
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 71
 };
72 72
 #endif
73 73
 #if (THERMISTORHEATER_0 == 2) || (THERMISTORHEATER_1 == 2) || (THERMISTORBED == 2) //200k bed thermistor
@@ -100,35 +100,35 @@ const short temptable_2[NUMTEMPS_2][2] = {
100 100
 #if (THERMISTORHEATER_0 == 3) || (THERMISTORHEATER_1 == 3) || (THERMISTORBED == 3) //mendel-parts
101 101
 #define NUMTEMPS_3 28
102 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
-	};
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 132
 
133 133
 #endif
134 134
 #if (THERMISTORHEATER_0 == 4) || (THERMISTORHEATER_1 == 4) || (THERMISTORBED == 4) //10k thermistor

+ 156
- 156
Marlin/ultralcd.h 查看文件

@@ -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
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
156
+

+ 1593
- 1593
Marlin/ultralcd.pde
文件差异内容过多而无法显示
查看文件


+ 64
- 70
README 查看文件

@@ -1,70 +1,64 @@
1
-This 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
-Features:
6
- - Interrupt based movement with real linear acceleration
7
- - High steprate
8
- - Look ahead (Keep the speed high when possible. High cornering speed)
9
- - Interrupt based temperature protection
10
- - preliminary support for Matthew Roberts advance algorithm 
11
-   For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
12
-
13
-This firmware is optimized for gen6 electronics.
14
-
15
-The default baudrate is 250000. 
16
-This gives less communication errors then regular baudrates.
17
-
18
-========================================================================================
19
-
20
-Configuring and compilation
21
-
22
-
23
-Install the arduino software version 0018
24
-   http://www.arduino.cc/en/Main/Software
25
-
26
-Install the sanguino software, version 0018
27
-   http://sanguino.cc/useit
28
-
29
-Install pronterface
30
-   https://github.com/kliment/Printrun
31
-
32
-Copy the Marlin firmware
33
-   https:/github.com/ErikZalm/Marlin
34
-   (Use the download button)
35
-
36
-Start the arduino IDE.
37
-Select Tools -> Board -> Sanguino 
38
-Select the correct serial port in Tools ->Serial Port
39
-Open Marlin.pde
40
-
41
-Change the printer specific setting in Configuration.h to the correct values.
42
-
43
-The following values are the most important:
44
- - float axis_steps_per_unit[]....         // Set the correct steps / mm in the corresponding field
45
- - const bool ENDSTOPS_INVERTING = false;  // Change if only positive moves are executed
46
- - #define INVERT_x_DIR true               // Change if the motor direction is wrong
47
-
48
-Click the Upload button
49
-If all goes well the firmware is uploading
50
-
51
-Start pronterface
52
-
53
-Select the correct Serial Port. Type 250000 in the baudrate field.
54
-Press the Connect button
55
-
56
-===============================================================================================
57
-Known issues
58
-
59
-On some systems we get compilation errors.
60
-
61
-This is caused by the "wiring_serial.c" and "wiring.c".
62
-The simple fix is to delete these files but this may have a performance impact.
63
-
64
-The best workaround is to move these files to sanguino directory. 
65
-(".../arduino-0018/hardware/Sanguino/cores/arduino/" on windows systems)
66
-
67
-
68
-
69
-
70
-
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
- 0
README.md 查看文件

@@ -0,0 +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
+

+ 58
- 0
merging still needs.txt 查看文件

@@ -0,0 +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:
58
+done: PID_dt->0.1

正在加载...
取消
保存