drake 12 роки тому
коміт
fc32e20881
100 змінених файлів з 17738 додано та 0 видалено
  1. 5
    0
      Marlin/.gitignore
  2. 35
    0
      Marlin/Marlin/Boards/boards.txt
  3. 713
    0
      Marlin/Marlin/Boards/bootloaders/atmega644p/ATmegaBOOT.c
  4. 121
    0
      Marlin/Marlin/Boards/bootloaders/atmega644p/ATmegaBOOT_324P.hex
  5. 120
    0
      Marlin/Marlin/Boards/bootloaders/atmega644p/ATmegaBOOT_644.hex
  6. 121
    0
      Marlin/Marlin/Boards/bootloaders/atmega644p/ATmegaBOOT_644P.hex
  7. 56
    0
      Marlin/Marlin/Boards/bootloaders/atmega644p/Makefile
  8. 3
    0
      Marlin/Marlin/Boards/bootloaders/atmega644p/README.txt
  9. 1
    0
      Marlin/Marlin/Boards/cores/arduino/Arduino.h
  10. 135
    0
      Marlin/Marlin/Boards/cores/arduino/Copy of wiring.h
  11. 202
    0
      Marlin/Marlin/Boards/cores/arduino/HardwareSerial.cpp
  12. 87
    0
      Marlin/Marlin/Boards/cores/arduino/HardwareSerial.h
  13. 220
    0
      Marlin/Marlin/Boards/cores/arduino/Print.cpp
  14. 77
    0
      Marlin/Marlin/Boards/cores/arduino/Print.h
  15. 35
    0
      Marlin/Marlin/Boards/cores/arduino/Stream.h
  16. 601
    0
      Marlin/Marlin/Boards/cores/arduino/Tone.cpp
  17. 168
    0
      Marlin/Marlin/Boards/cores/arduino/WCharacter.h
  18. 1
    0
      Marlin/Marlin/Boards/cores/arduino/WConstants.h
  19. 249
    0
      Marlin/Marlin/Boards/cores/arduino/WInterrupts.c
  20. 60
    0
      Marlin/Marlin/Boards/cores/arduino/WMath.cpp
  21. 63
    0
      Marlin/Marlin/Boards/cores/arduino/WProgram.h
  22. 443
    0
      Marlin/Marlin/Boards/cores/arduino/WString.cpp
  23. 112
    0
      Marlin/Marlin/Boards/cores/arduino/WString.h
  24. 515
    0
      Marlin/Marlin/Boards/cores/arduino/binary.h
  25. 14
    0
      Marlin/Marlin/Boards/cores/arduino/main.cpp
  26. 200
    0
      Marlin/Marlin/Boards/cores/arduino/pins_arduino.c
  27. 65
    0
      Marlin/Marlin/Boards/cores/arduino/pins_arduino.h
  28. 289
    0
      Marlin/Marlin/Boards/cores/arduino/wiring.c
  29. 136
    0
      Marlin/Marlin/Boards/cores/arduino/wiring.h
  30. 259
    0
      Marlin/Marlin/Boards/cores/arduino/wiring_analog.c
  31. 166
    0
      Marlin/Marlin/Boards/cores/arduino/wiring_digital.c
  32. 68
    0
      Marlin/Marlin/Boards/cores/arduino/wiring_private.h
  33. 69
    0
      Marlin/Marlin/Boards/cores/arduino/wiring_pulse.c
  34. 55
    0
      Marlin/Marlin/Boards/cores/arduino/wiring_shift.c
  35. 188
    0
      Marlin/Marlin/COPYING
  36. 294
    0
      Marlin/Marlin/Configuration.h
  37. 263
    0
      Marlin/Marlin/Configuration_adv.h
  38. 232
    0
      Marlin/Marlin/EEPROMwrite.h
  39. 101
    0
      Marlin/Marlin/Gen7/boards.txt
  40. 113
    0
      Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-1284P-16MHz.hex
  41. 75
    0
      Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-644-16MHz.hex
  42. 75
    0
      Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-644-20MHz.hex
  43. 75
    0
      Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-644P-16MHz.hex
  44. 75
    0
      Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-644P-20MHz.hex
  45. 239
    0
      Marlin/Marlin/Gen7/cores/arduino/HardwareSerial.cpp
  46. 69
    0
      Marlin/Marlin/Gen7/cores/arduino/HardwareSerial.h
  47. 243
    0
      Marlin/Marlin/Gen7/cores/arduino/Makefile
  48. 203
    0
      Marlin/Marlin/Gen7/cores/arduino/Print.cpp
  49. 59
    0
      Marlin/Marlin/Gen7/cores/arduino/Print.h
  50. 515
    0
      Marlin/Marlin/Gen7/cores/arduino/Tone.cpp
  51. 168
    0
      Marlin/Marlin/Gen7/cores/arduino/WCharacter.h
  52. 1
    0
      Marlin/Marlin/Gen7/cores/arduino/WConstants.h
  53. 87
    0
      Marlin/Marlin/Gen7/cores/arduino/WInterrupts.c
  54. 60
    0
      Marlin/Marlin/Gen7/cores/arduino/WMath.cpp
  55. 34
    0
      Marlin/Marlin/Gen7/cores/arduino/WProgram.h
  56. 443
    0
      Marlin/Marlin/Gen7/cores/arduino/WString.cpp
  57. 112
    0
      Marlin/Marlin/Gen7/cores/arduino/WString.h
  58. 515
    0
      Marlin/Marlin/Gen7/cores/arduino/binary.h
  59. 14
    0
      Marlin/Marlin/Gen7/cores/arduino/main.cpp
  60. 12
    0
      Marlin/Marlin/Gen7/cores/arduino/main.cxx
  61. 200
    0
      Marlin/Marlin/Gen7/cores/arduino/pins_arduino.c
  62. 65
    0
      Marlin/Marlin/Gen7/cores/arduino/pins_arduino.h
  63. 203
    0
      Marlin/Marlin/Gen7/cores/arduino/wiring.c
  64. 133
    0
      Marlin/Marlin/Gen7/cores/arduino/wiring.h
  65. 116
    0
      Marlin/Marlin/Gen7/cores/arduino/wiring_analog.c
  66. 95
    0
      Marlin/Marlin/Gen7/cores/arduino/wiring_digital.c
  67. 60
    0
      Marlin/Marlin/Gen7/cores/arduino/wiring_private.h
  68. 66
    0
      Marlin/Marlin/Gen7/cores/arduino/wiring_pulse.c
  69. 138
    0
      Marlin/Marlin/Gen7/cores/arduino/wiring_serial.c
  70. 40
    0
      Marlin/Marlin/Gen7/cores/arduino/wiring_shift.c
  71. BIN
      Marlin/Marlin/LCD Menu Tree.pdf
  72. 298
    0
      Marlin/Marlin/Makefile
  73. 203
    0
      Marlin/Marlin/Marlin.h
  74. 1832
    0
      Marlin/Marlin/Marlin.pde
  75. 329
    0
      Marlin/Marlin/MarlinSerial.cpp
  76. 150
    0
      Marlin/Marlin/MarlinSerial.h
  77. BIN
      Marlin/Marlin/Menu Plans.xlsx
  78. 16
    0
      Marlin/Marlin/Sanguino/boards.txt
  79. 713
    0
      Marlin/Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT.c
  80. 121
    0
      Marlin/Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_324P.hex
  81. 120
    0
      Marlin/Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_644.hex
  82. 121
    0
      Marlin/Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_644P.hex
  83. 56
    0
      Marlin/Marlin/Sanguino/bootloaders/atmega644p/Makefile
  84. 3
    0
      Marlin/Marlin/Sanguino/bootloaders/atmega644p/README.txt
  85. 135
    0
      Marlin/Marlin/Sanguino/cores/arduino/Copy of wiring.h
  86. 187
    0
      Marlin/Marlin/Sanguino/cores/arduino/HardwareSerial.cpp
  87. 76
    0
      Marlin/Marlin/Sanguino/cores/arduino/HardwareSerial.h
  88. 220
    0
      Marlin/Marlin/Sanguino/cores/arduino/Print.cpp
  89. 66
    0
      Marlin/Marlin/Sanguino/cores/arduino/Print.h
  90. 35
    0
      Marlin/Marlin/Sanguino/cores/arduino/Stream.h
  91. 601
    0
      Marlin/Marlin/Sanguino/cores/arduino/Tone.cpp
  92. 168
    0
      Marlin/Marlin/Sanguino/cores/arduino/WCharacter.h
  93. 1
    0
      Marlin/Marlin/Sanguino/cores/arduino/WConstants.h
  94. 249
    0
      Marlin/Marlin/Sanguino/cores/arduino/WInterrupts.c
  95. 60
    0
      Marlin/Marlin/Sanguino/cores/arduino/WMath.cpp
  96. 63
    0
      Marlin/Marlin/Sanguino/cores/arduino/WProgram.h
  97. 443
    0
      Marlin/Marlin/Sanguino/cores/arduino/WString.cpp
  98. 112
    0
      Marlin/Marlin/Sanguino/cores/arduino/WString.h
  99. 515
    0
      Marlin/Marlin/Sanguino/cores/arduino/binary.h
  100. 0
    0
      Marlin/Marlin/Sanguino/cores/arduino/main.cpp

+ 5
- 0
Marlin/.gitignore Переглянути файл

1
+*.o
2
+applet/
3
+*~
4
+*.orig
5
+*.rej

+ 35
- 0
Marlin/Marlin/Boards/boards.txt Переглянути файл

1
+##############################################################
2
+
3
+Generation_Series.name=Gen6 & Gen6 Deluxe 
4
+Generation_Series.upload.protocol=stk500
5
+Generation_Series.upload.maximum_size=63488
6
+Generation_Series.upload.speed=38400
7
+Generation_Series.bootloader.low_fuses=0xFF
8
+Generation_Series.bootloader.high_fuses=0xDC
9
+Generation_Series.bootloader.extended_fuses=0xFD
10
+Generation_Series.bootloader.path=atmega644p
11
+Generation_Series.bootloader.file=ATmegaBOOT_644P.hex
12
+Generation_Series.bootloader.unlock_bits=0x3F
13
+Generation_Series.bootloader.lock_bits=0x0F
14
+Generation_Series.build.mcu=atmega644p
15
+Generation_Series.build.f_cpu=16000000L
16
+Generation_Series.build.core=arduino
17
+
18
+
19
+##############################################################
20
+
21
+
22
+Sanguinololu.name=Sanguinololu 1.2 and above
23
+Sanguinololu.upload.protocol=stk500
24
+Sanguinololu.upload.maximum_size=63488
25
+Sanguinololu.upload.speed=38400
26
+Sanguinololu.bootloader.low_fuses=0xFF
27
+Sanguinololu.bootloader.high_fuses=0xDC
28
+Sanguinololu.bootloader.extended_fuses=0xFD
29
+Sanguinololu.bootloader.path=atmega644p
30
+Sanguinololu.bootloader.file=ATmegaBOOT_644P.hex
31
+Sanguinololu.bootloader.unlock_bits=0x3F
32
+Sanguinololu.bootloader.lock_bits=0x0F
33
+Sanguinololu.build.mcu=atmega644p
34
+Sanguinololu.build.f_cpu=16000000L
35
+Sanguinololu.build.core=arduino

+ 713
- 0
Marlin/Marlin/Boards/bootloaders/atmega644p/ATmegaBOOT.c Переглянути файл

1
+/**********************************************************/
2
+/* Serial Bootloader for Atmel megaAVR Controllers        */
3
+/*                                                        */
4
+/* tested with ATmega644 and ATmega644P                   */
5
+/* should work with other mega's, see code for details    */
6
+/*                                                        */
7
+/* ATmegaBOOT.c                                           */
8
+/*                                                        */
9
+/* 20090131: Added 324P support from Alex Leone           */
10
+/*           Marius Kintel                                */
11
+/* 20080915: applied ADABoot mods for Sanguino 644P       */
12
+/*           Brian Riley                                  */
13
+/* 20080711: hacked for Sanguino by Zach Smith            */
14
+/*           and Justin Day                               */
15
+/* 20070626: hacked for Arduino Diecimila (which auto-    */
16
+/*           resets when a USB connection is made to it)  */
17
+/*           by D. Mellis                                 */
18
+/* 20060802: hacked for Arduino by D. Cuartielles         */
19
+/*           based on a previous hack by D. Mellis        */
20
+/*           and D. Cuartielles                           */
21
+/*                                                        */
22
+/* Monitor and debug functions were added to the original */
23
+/* code by Dr. Erik Lins, chip45.com. (See below)         */
24
+/*                                                        */
25
+/* Thanks to Karl Pitrich for fixing a bootloader pin     */
26
+/* problem and more informative LED blinking!             */
27
+/*                                                        */
28
+/* For the latest version see:                            */
29
+/* http://www.chip45.com/                                 */
30
+/*                                                        */
31
+/* ------------------------------------------------------ */
32
+/*                                                        */
33
+/* based on stk500boot.c                                  */
34
+/* Copyright (c) 2003, Jason P. Kyle                      */
35
+/* All rights reserved.                                   */
36
+/* see avr1.org for original file and information         */
37
+/*                                                        */
38
+/* This program is free software; you can redistribute it */
39
+/* and/or modify it under the terms of the GNU General    */
40
+/* Public License as published by the Free Software       */
41
+/* Foundation; either version 2 of the License, or        */
42
+/* (at your option) any later version.                    */
43
+/*                                                        */
44
+/* This program is distributed in the hope that it will   */
45
+/* be useful, but WITHOUT ANY WARRANTY; without even the  */
46
+/* implied warranty of MERCHANTABILITY or FITNESS FOR A   */
47
+/* PARTICULAR PURPOSE.  See the GNU General Public        */
48
+/* License for more details.                              */
49
+/*                                                        */
50
+/* You should have received a copy of the GNU General     */
51
+/* Public License along with this program; if not, write  */
52
+/* to the Free Software Foundation, Inc.,                 */
53
+/* 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA */
54
+/*                                                        */
55
+/* Licence can be viewed at                               */
56
+/* http://www.fsf.org/licenses/gpl.txt                    */
57
+/*                                                        */
58
+/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */
59
+/* m8515,m8535. ATmega161 has a very small boot block so  */
60
+/* isn't supported.                                       */
61
+/*                                                        */
62
+/* Tested with m168                                       */
63
+/**********************************************************/
64
+
65
+/* $Id$ */
66
+
67
+
68
+/* some includes */
69
+#include <inttypes.h>
70
+#include <avr/io.h>
71
+#include <avr/pgmspace.h>
72
+#include <avr/interrupt.h>
73
+#include <avr/wdt.h>
74
+#include <avr/boot.h>
75
+
76
+#ifdef ADABOOT
77
+    #define NUM_LED_FLASHES 3
78
+    #define ADABOOT_VER	1
79
+#endif
80
+
81
+
82
+/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
83
+#define MAX_ERROR_COUNT 5
84
+
85
+/* set the UART baud rate */
86
+/* 20080711: hack by Zach Hoeken */
87
+#define BAUD_RATE   38400
88
+
89
+/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
90
+/* never allow AVR Studio to do an update !!!! */
91
+#define HW_VER	 0x02
92
+#define SW_MAJOR 0x01
93
+#define SW_MINOR 0x10
94
+
95
+/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
96
+/* if monitor functions are included, LED goes on after monitor was entered */
97
+#define LED_DDR  DDRB
98
+#define LED_PORT PORTB
99
+#define LED_PIN  PINB
100
+#define LED      PINB0
101
+
102
+/* define various device id's */
103
+/* manufacturer byte is always the same */
104
+#define SIG1	0x1E	// Yep, Atmel is the only manufacturer of AVR micros.  Single source :(
105
+#if defined(__AVR_ATmega644P__)
106
+#define SIG2	0x96
107
+#define SIG3	0x0A
108
+#elif defined(__AVR_ATmega644__)
109
+#define SIG2	0x96
110
+#define SIG3	0x09
111
+#elif defined(__AVR_ATmega324P__)
112
+#define SIG2	0x95
113
+#define SIG3	0x08
114
+#endif
115
+#define PAGE_SIZE		0x080U   //128 words
116
+#define PAGE_SIZE_BYTES	0x100U   //256 bytes
117
+
118
+/* function prototypes */
119
+void putch(char);
120
+char getch(void);
121
+void getNch(uint8_t);
122
+void byte_response(uint8_t);
123
+void nothing_response(void);
124
+char gethex(void);
125
+void puthex(char);
126
+void flash_led(uint8_t);
127
+
128
+/* some variables */
129
+union address_union
130
+{
131
+    uint16_t word;
132
+    uint8_t  byte[2];
133
+} address;
134
+
135
+union length_union
136
+{
137
+    uint16_t word;
138
+    uint8_t  byte[2];
139
+} length;
140
+
141
+struct flags_struct
142
+{
143
+    unsigned eeprom : 1;
144
+    unsigned rampz  : 1;
145
+} flags;
146
+
147
+uint8_t buff[256];
148
+
149
+uint8_t error_count = 0;
150
+uint8_t sreg;
151
+
152
+void (*app_start)(void) = 0x0000;
153
+
154
+/* main program starts here */
155
+int main(void)
156
+{
157
+    uint8_t ch,ch2;
158
+    uint16_t w;
159
+	uint16_t i;
160
+	
161
+    asm volatile("nop\n\t");
162
+
163
+#ifdef ADABOOT		// BBR/LF 10/8/2007 & 9/13/2008
164
+    ch = MCUSR;
165
+    MCUSR = 0;
166
+
167
+    WDTCSR |= _BV(WDCE) | _BV(WDE);
168
+    WDTCSR = 0;
169
+
170
+    // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
171
+    if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
172
+      app_start();  // skip bootloader
173
+#endif
174
+
175
+
176
+	//initialize our serial port.
177
+    UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
178
+    UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
179
+    UCSR0B = (1<<RXEN0) | (1<<TXEN0);
180
+    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
181
+
182
+    /* Enable internal pull-up resistor on pin D0 (RX), in order
183
+    to supress line noise that prevents the bootloader from
184
+    timing out (DAM: 20070509) */
185
+    DDRD &= ~_BV(PIND0);
186
+    PORTD |= _BV(PIND0);
187
+
188
+    /* set LED pin as output */
189
+    LED_DDR |= _BV(LED);
190
+
191
+	    /* flash onboard LED to signal entering of bootloader                   */
192
+	    /* ADABOOT will do two series of flashes. first 4 - signifying ADABOOT  */
193
+	    /* then a pause and another flash series signifying ADABOOT sub-version */
194
+
195
+
196
+	flash_led(NUM_LED_FLASHES);
197
+
198
+	#ifdef	ADABOOT
199
+		flash_led(ADABOOT_VER);		// BBR 9/13/2008
200
+	#endif 
201
+
202
+    /* forever loop */
203
+    for (;;)
204
+	{
205
+		/* get character from UART */
206
+		ch = getch();
207
+
208
+		/* A bunch of if...else if... gives smaller code than switch...case ! */
209
+
210
+		/* Hello is anyone home ? */ 
211
+		if(ch=='0')
212
+		    nothing_response();
213
+
214
+
215
+		/* Request programmer ID */
216
+		/* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry  */
217
+		/* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares.  */
218
+		else if(ch=='1')
219
+		{
220
+		    if (getch() == ' ')
221
+			{
222
+				putch(0x14);
223
+				putch('A');
224
+				putch('V');
225
+				putch('R');
226
+				putch(' ');
227
+				putch('I');
228
+				putch('S');
229
+				putch('P');
230
+				putch(0x10);
231
+		    }
232
+			else
233
+			{
234
+				if (++error_count == MAX_ERROR_COUNT)
235
+				    app_start();
236
+		    }
237
+		}
238
+
239
+
240
+		/* AVR ISP/STK500 board commands  DON'T CARE so default nothing_response */
241
+		else if(ch=='@')
242
+		{
243
+		    ch2 = getch();
244
+		    if (ch2 > 0x85)
245
+				getch();
246
+		    nothing_response();
247
+		}
248
+
249
+
250
+		/* AVR ISP/STK500 board requests */
251
+		else if(ch=='A')
252
+		{
253
+		    ch2 = getch();
254
+		    if(ch2 == 0x80)
255
+				byte_response(HW_VER);		// Hardware version
256
+		    else if(ch2==0x81)
257
+				byte_response(SW_MAJOR);	// Software major version
258
+		    else if(ch2==0x82)
259
+				byte_response(SW_MINOR);	// Software minor version
260
+		    else if(ch2==0x98)
261
+				byte_response(0x03);		// Unknown but seems to be required by avr studio 3.56
262
+		    else
263
+				byte_response(0x00);		// Covers various unnecessary responses we don't care about
264
+		}
265
+
266
+
267
+		/* Device Parameters  DON'T CARE, DEVICE IS FIXED  */
268
+		else if(ch=='B')
269
+		{
270
+		    getNch(20);
271
+		    nothing_response();
272
+		}
273
+
274
+
275
+		/* Parallel programming stuff  DON'T CARE  */
276
+		else if(ch=='E')
277
+		{
278
+		    getNch(5);
279
+		    nothing_response();
280
+		}
281
+
282
+
283
+		/* Enter programming mode  */
284
+		else if(ch=='P')
285
+		{
286
+		    nothing_response();
287
+		}
288
+
289
+
290
+		/* Leave programming mode  */
291
+		else if(ch=='Q')
292
+		{
293
+		    nothing_response();
294
+#ifdef ADABOOT		
295
+			// autoreset via watchdog (sneaky!) BBR/LF 9/13/2008
296
+	  		WDTCSR = _BV(WDE);
297
+	  		while (1); // 16 ms
298
+#endif		
299
+		}
300
+
301
+
302
+		/* Erase device, don't care as we will erase one page at a time anyway.  */
303
+		else if(ch=='R')
304
+		{
305
+		    nothing_response();
306
+		}
307
+
308
+
309
+		/* Set address, little endian. EEPROM in bytes, FLASH in words  */
310
+		/* Perhaps extra address bytes may be added in future to support > 128kB FLASH.  */
311
+		/* This might explain why little endian was used here, big endian used everywhere else.  */
312
+		else if(ch=='U')
313
+		{
314
+		    address.byte[0] = getch();
315
+		    address.byte[1] = getch();
316
+		    nothing_response();
317
+		}
318
+
319
+
320
+		/* Universal SPI programming command, disabled.  Would be used for fuses and lock bits.  */
321
+		else if(ch=='V')
322
+		{
323
+		    getNch(4);
324
+		    byte_response(0x00);
325
+		}
326
+
327
+
328
+		/* Write memory, length is big endian and is in bytes  */
329
+		else if(ch=='d')
330
+		{
331
+		    length.byte[1] = getch();
332
+		    length.byte[0] = getch();
333
+	
334
+		    flags.eeprom = 0;
335
+		    if (getch() == 'E')
336
+				flags.eeprom = 1;
337
+
338
+			for (i=0; i<PAGE_SIZE; i++)
339
+				buff[i] = 0;
340
+		
341
+		    for (w = 0; w < length.word; w++)
342
+			{
343
+				// Store data in buffer, can't keep up with serial data stream whilst programming pages
344
+				buff[w] = getch();
345
+		    }
346
+	
347
+		    if (getch() == ' ')
348
+			{
349
+				if (flags.eeprom)
350
+				{		                
351
+					//Write to EEPROM one byte at a time
352
+				    for(w=0;w<length.word;w++)
353
+					{
354
+						while(EECR & (1<<EEPE));
355
+					
356
+						EEAR = (uint16_t)(void *)address.word;
357
+						EEDR = buff[w];
358
+						EECR |= (1<<EEMPE);
359
+						EECR |= (1<<EEPE);
360
+
361
+						address.word++;
362
+				    }			
363
+				}
364
+				else
365
+				{
366
+					//address * 2 -> byte location
367
+				    address.word = address.word << 1;
368
+			    
369
+					//Even up an odd number of bytes
370
+					if ((length.byte[0] & 0x01))
371
+						length.word++;
372
+				
373
+					// HACKME: EEPE used to be EEWE
374
+				    //Wait for previous EEPROM writes to complete
375
+					//while(bit_is_set(EECR,EEPE));
376
+					while(EECR & (1<<EEPE));
377
+				
378
+				    asm volatile(
379
+						 "clr	r17		\n\t"	//page_word_count
380
+						 "lds	r30,address	\n\t"	//Address of FLASH location (in bytes)
381
+						 "lds	r31,address+1	\n\t"
382
+						 "ldi	r28,lo8(buff)	\n\t"	//Start of buffer array in RAM
383
+						 "ldi	r29,hi8(buff)	\n\t"
384
+						 "lds	r24,length	\n\t"	//Length of data to be written (in bytes)
385
+						 "lds	r25,length+1	\n\t"
386
+						 "length_loop:		\n\t"	//Main loop, repeat for number of words in block							 							 
387
+						 "cpi	r17,0x00	\n\t"	//If page_word_count=0 then erase page
388
+						 "brne	no_page_erase	\n\t"						 
389
+						 "wait_spm1:		\n\t"
390
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
391
+						 "andi	r16,1           \n\t"
392
+						 "cpi	r16,1           \n\t"
393
+						 "breq	wait_spm1       \n\t"
394
+						 "ldi	r16,0x03	\n\t"	//Erase page pointed to by Z
395
+						 "sts	%0,r16		\n\t"
396
+						 "spm			\n\t"							 
397
+						 "wait_spm2:		\n\t"
398
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
399
+						 "andi	r16,1           \n\t"
400
+						 "cpi	r16,1           \n\t"
401
+						 "breq	wait_spm2       \n\t"									 
402
+
403
+						 "ldi	r16,0x11	\n\t"	//Re-enable RWW section
404
+						 "sts	%0,r16		\n\t"						 			 
405
+						 "spm			\n\t"
406
+						 "no_page_erase:		\n\t"							 
407
+						 "ld	r0,Y+		\n\t"	//Write 2 bytes into page buffer
408
+						 "ld	r1,Y+		\n\t"							 
409
+							 
410
+						 "wait_spm3:		\n\t"
411
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
412
+						 "andi	r16,1           \n\t"
413
+						 "cpi	r16,1           \n\t"
414
+						 "breq	wait_spm3       \n\t"
415
+						 "ldi	r16,0x01	\n\t"	//Load r0,r1 into FLASH page buffer
416
+						 "sts	%0,r16		\n\t"
417
+						 "spm			\n\t"
418
+							 
419
+						 "inc	r17		\n\t"	//page_word_count++
420
+						 "cpi r17,%1	        \n\t"
421
+						 "brlo	same_page	\n\t"	//Still same page in FLASH
422
+						 "write_page:		\n\t"
423
+						 "clr	r17		\n\t"	//New page, write current one first
424
+						 "wait_spm4:		\n\t"
425
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
426
+						 "andi	r16,1           \n\t"
427
+						 "cpi	r16,1           \n\t"
428
+						 "breq	wait_spm4       \n\t"						 							 
429
+						 "ldi	r16,0x05	\n\t"	//Write page pointed to by Z
430
+						 "sts	%0,r16		\n\t"
431
+						 "spm			\n\t"
432
+						 "wait_spm5:		\n\t"
433
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
434
+						 "andi	r16,1           \n\t"
435
+						 "cpi	r16,1           \n\t"
436
+						 "breq	wait_spm5       \n\t"									 
437
+						 "ldi	r16,0x11	\n\t"	//Re-enable RWW section
438
+						 "sts	%0,r16		\n\t"						 			 
439
+						 "spm			\n\t"					 		 
440
+						 "same_page:		\n\t"							 
441
+						 "adiw	r30,2		\n\t"	//Next word in FLASH
442
+						 "sbiw	r24,2		\n\t"	//length-2
443
+						 "breq	final_write	\n\t"	//Finished
444
+						 "rjmp	length_loop	\n\t"
445
+						 "final_write:		\n\t"
446
+						 "cpi	r17,0		\n\t"
447
+						 "breq	block_done	\n\t"
448
+						 "adiw	r24,2		\n\t"	//length+2, fool above check on length after short page write
449
+						 "rjmp	write_page	\n\t"
450
+						 "block_done:		\n\t"
451
+						 "clr	__zero_reg__	\n\t"	//restore zero register
452
+						 : "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
453
+
454
+						 );
455
+				}
456
+				putch(0x14);
457
+				putch(0x10);
458
+		    }
459
+			else
460
+			{
461
+				if (++error_count == MAX_ERROR_COUNT)
462
+				    app_start();
463
+		    }		
464
+		}
465
+    
466
+		/* Read memory block mode, length is big endian.  */
467
+		else if(ch=='t')
468
+		{
469
+			length.byte[1] = getch();
470
+			length.byte[0] = getch();
471
+
472
+			if (getch() == 'E')
473
+				flags.eeprom = 1;
474
+			else
475
+			{
476
+				flags.eeprom = 0;
477
+				address.word = address.word << 1;	        // address * 2 -> byte location
478
+			}
479
+
480
+			// Command terminator
481
+			if (getch() == ' ')
482
+			{
483
+				putch(0x14);
484
+				for (w=0; w<length.word; w++)
485
+				{
486
+					// Can handle odd and even lengths okay
487
+				    if (flags.eeprom) 
488
+					{
489
+						// Byte access EEPROM read
490
+						while(EECR & (1<<EEPE));
491
+						EEAR = (uint16_t)(void *)address.word;
492
+						EECR |= (1<<EERE);
493
+						putch(EEDR);
494
+
495
+						address.word++;
496
+				    }
497
+				    else
498
+					{
499
+						if (!flags.rampz)
500
+							putch(pgm_read_byte_near(address.word));
501
+
502
+						address.word++;
503
+				    }
504
+				}
505
+				putch(0x10);
506
+		    }
507
+		}
508
+
509
+
510
+		/* Get device signature bytes  */
511
+		else if(ch=='u')
512
+		{
513
+			if (getch() == ' ')
514
+			{
515
+				putch(0x14);
516
+				putch(SIG1);
517
+				putch(SIG2);
518
+				putch(SIG3);
519
+				putch(0x10);
520
+			}
521
+			else
522
+			{
523
+				if (++error_count == MAX_ERROR_COUNT)
524
+					app_start();
525
+			}
526
+		}
527
+
528
+
529
+		/* Read oscillator calibration byte */
530
+		else if(ch=='v')
531
+			byte_response(0x00);
532
+
533
+		else if (++error_count == MAX_ERROR_COUNT)
534
+		    app_start();
535
+
536
+	}
537
+    /* end of forever loop */
538
+}
539
+
540
+
541
+char gethex(void)
542
+{
543
+    char ah,al;
544
+
545
+    ah = getch();
546
+	putch(ah);
547
+    al = getch();
548
+	putch(al);
549
+    
550
+	if(ah >= 'a')
551
+		ah = ah - 'a' + 0x0a;
552
+	else if(ah >= '0')
553
+		ah -= '0';
554
+    if(al >= 'a')
555
+		al = al - 'a' + 0x0a;
556
+	else if(al >= '0')
557
+		al -= '0';
558
+
559
+    return (ah << 4) + al;
560
+}
561
+
562
+
563
+void puthex(char ch)
564
+{
565
+    char ah,al;
566
+
567
+    ah = (ch & 0xf0) >> 4;
568
+	if(ah >= 0x0a)
569
+		ah = ah - 0x0a + 'a';
570
+	else
571
+		ah += '0';
572
+
573
+    al = (ch & 0x0f);
574
+	if(al >= 0x0a)
575
+		al = al - 0x0a + 'a';
576
+	else
577
+		al += '0';
578
+
579
+    putch(ah);
580
+    putch(al);
581
+}
582
+
583
+
584
+void putch(char ch)
585
+{
586
+    while (!(UCSR0A & _BV(UDRE0)));
587
+    UDR0 = ch;
588
+}
589
+
590
+
591
+
592
+
593
+char getch(void)
594
+{
595
+    uint32_t count = 0;
596
+
597
+#ifdef ADABOOT
598
+	LED_PORT &= ~_BV(LED);          // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
599
+#endif
600
+
601
+    while(!(UCSR0A & _BV(RXC0)))
602
+	{
603
+    	/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/               
604
+    	/* HACKME:: here is a good place to count times*/
605
+    	count++;
606
+    	if (count > MAX_TIME_COUNT)
607
+    		app_start();
608
+     }
609
+
610
+#ifdef ADABOOT
611
+	LED_PORT |= _BV(LED);          // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
612
+#endif
613
+
614
+    return UDR0;
615
+}
616
+
617
+
618
+void getNch(uint8_t count)
619
+{
620
+    uint8_t i;
621
+    for(i=0;i<count;i++)
622
+	{
623
+		while(!(UCSR0A & _BV(RXC0)));
624
+		UDR0;
625
+    }
626
+}
627
+
628
+
629
+void byte_response(uint8_t val)
630
+{
631
+    if (getch() == ' ')
632
+	{
633
+		putch(0x14);
634
+		putch(val);
635
+		putch(0x10);
636
+    }
637
+	else
638
+	{
639
+		if (++error_count == MAX_ERROR_COUNT)
640
+		    app_start();
641
+    }
642
+}
643
+
644
+
645
+void nothing_response(void)
646
+{
647
+    if (getch() == ' ')
648
+	{
649
+		putch(0x14);
650
+		putch(0x10);
651
+    }
652
+	else
653
+	{
654
+		if (++error_count == MAX_ERROR_COUNT)
655
+		    app_start();
656
+    }
657
+}
658
+
659
+#ifdef ADABOOT
660
+
661
+void flash_led(uint8_t count)
662
+{
663
+    /* flash onboard LED count times to signal entering of bootloader */
664
+	/* l needs to be volatile or the delay loops below might get      */
665
+	/* optimized away if compiling with optimizations (DAM).          */
666
+	
667
+    volatile uint32_t l;
668
+
669
+    if (count == 0) {
670
+      count = ADABOOT;
671
+    }
672
+    
673
+
674
+	int8_t i;
675
+    for (i = 0; i < count; ++i) {
676
+		LED_PORT |= _BV(LED);					// LED on
677
+		for(l = 0; l < (F_CPU / 1000); ++l);		// delay NGvalue was 1000 for both loops - BBR
678
+		LED_PORT &= ~_BV(LED);					// LED off
679
+		for(l = 0; l < (F_CPU / 250); ++l);		// delay asymmteric for ADA BOOT BBR 
680
+	}
681
+
682
+	for(l = 0; l < (F_CPU / 100); ++l);		    // pause ADA BOOT BBR 
683
+		
684
+}
685
+
686
+#else
687
+
688
+void flash_led(uint8_t count)
689
+{
690
+    /* flash onboard LED three times to signal entering of bootloader */
691
+	/* l needs to be volatile or the delay loops below might get
692
+	optimized away if compiling with optimizations (DAM). */
693
+    volatile uint32_t l;
694
+
695
+    if (count == 0) {
696
+      count = 3;
697
+    }
698
+    
699
+	int8_t i;
700
+    for (i = 0; i < count; ++i) {
701
+		LED_PORT |= _BV(LED);
702
+		for(l = 0; l < (F_CPU / 1000); ++l);
703
+		LED_PORT &= ~_BV(LED);
704
+		for(l = 0; l < (F_CPU / 1000); ++l); 
705
+	}
706
+		
707
+}
708
+
709
+
710
+#endif
711
+
712
+
713
+/* end of file ATmegaBOOT.c */

+ 121
- 0
Marlin/Marlin/Boards/bootloaders/atmega644p/ATmegaBOOT_324P.hex Переглянути файл

1
+:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
2
+:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
3
+:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
4
+:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
5
+:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
6
+:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
7
+:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
8
+:10F870000C945B7C0C945B7C0C945B7C11241FBE11
9
+:10F88000CFEFD8E0DEBFCDBF11E0A0E0B1E0E6E60B
10
+:10F89000FFEF02C005900D92A030B107D9F712E03A
11
+:10F8A000A0E0B1E001C01D92A930B107E1F70E94CC
12
+:10F8B000537D0C94B27F0C94007CCF93DF93CDB733
13
+:10F8C000DEB724970FB6F894DEBF0FBECDBF8823F6
14
+:10F8D00009F481E020E0482F55274115510509F42E
15
+:10F8E0003DC0289A19821A821B821C820BC0898112
16
+:10F8F0009A81AB81BC810196A11DB11D89839A8338
17
+:10F90000AB83BC8389819A81AB81BC8180589E4343
18
+:10F91000A040B04060F3289819821A821B821C8292
19
+:10F920000BC089819A81AB81BC810196A11DB11D5B
20
+:10F9300089839A83AB83BC8389819A81AB81BC81A3
21
+:10F9400080509A4FA040B04060F32F5F822F9927DC
22
+:10F9500087FD9095841795070CF4C3CF19821A82FE
23
+:10F960001B821C8289819A81AB81BC818050914726
24
+:10F97000A240B040A0F489819A81AB81BC810196FC
25
+:10F98000A11DB11D89839A83AB83BC8389819A8130
26
+:10F99000AB81BC8180509147A240B04060F3249677
27
+:10F9A0000FB6F894DEBF0FBECDBFDF91CF910895A3
28
+:10F9B000EF92FF920F931F93EE24FF248701289864
29
+:10F9C0008091C00087FD17C00894E11CF11C011D47
30
+:10F9D000111D81E0E81689E0F8068DE3080780E054
31
+:10F9E000180770F3E0910001F091010109958091F1
32
+:10F9F000C00087FFE9CF289A8091C600992787FD2C
33
+:10FA000090951F910F91FF90EF900895982F8091FE
34
+:10FA1000C00085FFFCCF9093C60008950E94D87C5B
35
+:10FA2000803271F0809102018F5F809302018530F6
36
+:10FA300009F00895E0910001F09101010995089500
37
+:10FA400084E10E94067D80E10E94067D0895CF93A7
38
+:10FA5000C82F0E94D87C803241F0809102018F5FD4
39
+:10FA600080930201853081F40AC084E10E94067D02
40
+:10FA70008C2F0E94067D80E10E94067D05C0E091EA
41
+:10FA80000001F09101010995CF910895282F90E090
42
+:10FA900007C08091C0008823E4F78091C6009F5F73
43
+:10FAA0009217B8F30895CFEFD8E0DEBFCDBF0000C6
44
+:10FAB00094B714BE809160008861809360001092BA
45
+:10FAC000600091FF74C189E18093C4001092C50069
46
+:10FAD00088E18093C10086E08093C2005098589AD4
47
+:10FAE000209A83E00E945D7C81E00E945D7C0E9400
48
+:10FAF000D87C8033B9F18133C1F1803409F456C028
49
+:10FB0000813409F45CC0823409F46EC0853409F490
50
+:10FB100071C0803539F1813509F4F3C0823511F1B6
51
+:10FB2000853509F4D3C0863509F4CBC0843609F491
52
+:10FB300065C0843709F4EBC0853709F4D2C0863735
53
+:10FB400009F44AC0809102018F5F809302018530E1
54
+:10FB500071F6E0910001F091010109950E94D87CB5
55
+:10FB6000803349F60E940E7DC2CF0E94D87CC82FF8
56
+:10FB7000803241F784E10E94067D81E40E94067D87
57
+:10FB800086E50E94067D82E50E94067D8C2F0E94FC
58
+:10FB9000067D89E40E94067D83E50E94067D80E55E
59
+:10FBA0000E94067D80E10E94067DA1CF0E94D87C44
60
+:10FBB0008638C0F20E94D87C0E940E7D98CF0E94A9
61
+:10FBC000D87C803809F407C1813809F400C1823833
62
+:10FBD00009F4F9C0883921F080E00E94277D87CFA1
63
+:10FBE00083E00E94277D83CF84E10E94467D0E94AE
64
+:10FBF0000E7D7DCF85E00E94467DF9CF0E94D87CA6
65
+:10FC0000809306020E94D87C8093050280910802AE
66
+:10FC10008E7F809308020E94D87C853409F44BC003
67
+:10FC2000E5E0F1E0119281E0E438F807D9F3D0F390
68
+:10FC3000C0E0D0E0809105029091060218161906E6
69
+:10FC400078F405E011E00E94D87CF80181938F01DF
70
+:10FC500021968091050290910602C817D90798F362
71
+:10FC60000E94D87C803209F06DCF8091080280FF1D
72
+:10FC7000B6C0C0E0D0E02091050230910602121615
73
+:10FC80001306B8F4E0910301F0910401A5E0B1E09E
74
+:10FC9000F999FECFF2BDE1BD8D9180BDFA9AF99A36
75
+:10FCA00031962196C217D30798F3F0930401E0939D
76
+:10FCB000030184E175CF809108028160809308027E
77
+:10FCC000AFCF84E00E94467D80E087CF0E94D87C41
78
+:10FCD000809303010E94D87C809304010E940E7DD2
79
+:10FCE00006CF0E94D87C803209F02CCF84E10E949C
80
+:10FCF000067D8EE10E94067D85E90E94067D88E0F2
81
+:10FD00004FCF0E940E7D88E080936000FFCF0E945D
82
+:10FD1000D87C809306020E94D87C809305020E94C2
83
+:10FD2000D87C853409F449C0809108028E7F809385
84
+:10FD300008028091030190910401880F991F90930C
85
+:10FD40000401809303010E94D87C803209F0CFCE59
86
+:10FD500084E10E94067DC0E0D0E020910502309150
87
+:10FD600006021216130608F01DCFE0910301F09170
88
+:10FD700004018091080280FF96C0F999FECFF2BD80
89
+:10FD8000E1BDF89A80B50E94067DE0910301F091F3
90
+:10FD900004013196F0930401E093030120910502E0
91
+:10FDA000309106022196C217D30718F3FBCEE091DB
92
+:10FDB0000001F0910101099586CE809108028160D1
93
+:10FDC00080930802C0CF80E10E94277D90CE81E021
94
+:10FDD0000E94277D8CCE82E00E94277D88CE809174
95
+:10FDE000030190910401880F991F9093040180935F
96
+:10FDF00003018091050280FF09C080910502909166
97
+:10FE0000060201969093060280930502F999FECFAF
98
+:10FE10001127E0910301F0910401C5E0D1E0809148
99
+:10FE2000050290910602103091F400915700017084
100
+:10FE30000130D9F303E000935700E8950091570093
101
+:10FE400001700130D9F301E100935700E895099062
102
+:10FE500019900091570001700130D9F301E000932F
103
+:10FE60005700E8951395103898F011270091570026
104
+:10FE700001700130D9F305E000935700E895009137
105
+:10FE8000570001700130D9F301E100935700E89564
106
+:10FE90003296029709F0C7CF103011F00296E5CFE5
107
+:10FEA000112484E17DCE869580FF06C03196F093C3
108
+:10FEB0000401E093030176CF84910E94067D209196
109
+:10FEC000050230910602E0910301F0910401EECFAA
110
+:10FED0001F93CF930E94D87CC82F0E94067D0E945A
111
+:10FEE000D87C182F0E94067DC1362CF0C7551136DC
112
+:10FEF0003CF0175508C0C033D4F3C0531136CCF7CB
113
+:10FF000010330CF01053C295C07FC10F8C2F99276E
114
+:10FF100087FD9095CF911F910895CF93282F992712
115
+:10FF200087FD9095807F907095958795959587959D
116
+:10FF300095958795959587958A303CF0895AC22F7B
117
+:10FF4000CF70CA303CF0C95A06C0805DC22FCF7056
118
+:10FF5000CA30CCF7C05D0E94067D8C2F0E94067DC2
119
+:06FF6000CF910895FFCFD0
120
+:040000030000F80001
121
+:00000001FF

+ 120
- 0
Marlin/Marlin/Boards/bootloaders/atmega644p/ATmegaBOOT_644.hex Переглянути файл

1
+:10F800000C94387C0C94557C0C94557C0C94557C51
2
+:10F810000C94557C0C94557C0C94557C0C94557C24
3
+:10F820000C94557C0C94557C0C94557C0C94557C14
4
+:10F830000C94557C0C94557C0C94557C0C94557C04
5
+:10F840000C94557C0C94557C0C94557C0C94557CF4
6
+:10F850000C94557C0C94557C0C94557C0C94557CE4
7
+:10F860000C94557C0C94557C0C94557C0C94557CD4
8
+:10F8700011241FBECFEFD0E1DEBFCDBF11E0A0E06D
9
+:10F88000B1E0EAE5FFEF02C005900D92A030B107AC
10
+:10F89000D9F712E0A0E0B1E001C01D92A930B10794
11
+:10F8A000E1F70E944D7D0C94AC7F0C94007CCF93CB
12
+:10F8B000DF93CDB7DEB724970FB6F894DEBF0FBE47
13
+:10F8C000CDBF882309F481E020E0482F552741155A
14
+:10F8D000510509F43DC0289A19821A821B821C82A4
15
+:10F8E0000BC089819A81AB81BC810196A11DB11D9C
16
+:10F8F00089839A83AB83BC8389819A81AB81BC81E4
17
+:10F9000080589E43A040B04060F3289819821A8224
18
+:10F910001B821C820BC089819A81AB81BC810196BC
19
+:10F92000A11DB11D89839A83AB83BC8389819A8190
20
+:10F93000AB81BC8180509A4FA040B04060F32F5FF4
21
+:10F94000822F992787FD9095841795070CF4C3CFD4
22
+:10F9500019821A821B821C8289819A81AB81BC81A7
23
+:10F9600080509147A240B040A0F489819A81AB8138
24
+:10F97000BC810196A11DB11D89839A83AB83BC8391
25
+:10F9800089819A81AB81BC8180509147A240B0406F
26
+:10F9900060F324960FB6F894DEBF0FBECDBFDF91A3
27
+:10F9A000CF910895EF92FF920F931F93EE24FF24BF
28
+:10F9B000870128988091C00087FD17C00894E11C3A
29
+:10F9C000F11C011D111D81E0E81689E0F8068DE3A8
30
+:10F9D000080780E0180770F3E0910001F091010141
31
+:10F9E00009958091C00087FFE9CF289A8091C600D1
32
+:10F9F000992787FD90951F910F91FF90EF900895A3
33
+:10FA0000982F8091C00085FFFCCF9093C600089589
34
+:10FA10000E94D27C803271F0809102018F5F8093CE
35
+:10FA20000201853009F00895E0910001F091010193
36
+:10FA30000995089584E10E94007D80E10E94007D87
37
+:10FA40000895CF93C82F0E94D27C803241F08091DC
38
+:10FA500002018F5F80930201853081F40AC084E146
39
+:10FA60000E94007D8C2F0E94007D80E10E94007D1D
40
+:10FA700005C0E0910001F09101010995CF91089531
41
+:10FA8000282F90E007C08091C0008823E4F7809180
42
+:10FA9000C6009F5F9217B8F30895CFEFD0E1DEBFA5
43
+:10FAA000CDBF000094B714BE809160008861809340
44
+:10FAB00060001092600091FF74C189E18093C400DE
45
+:10FAC0001092C50088E18093C10086E08093C20057
46
+:10FAD0005098589A209A83E00E94577C81E00E94B7
47
+:10FAE000577C0E94D27C8033B9F18133C1F18034DC
48
+:10FAF00009F456C0813409F45CC0823409F46EC044
49
+:10FB0000853409F471C0803539F1813509F4F3C0C9
50
+:10FB1000823511F1853509F4D3C0863509F4CBC09F
51
+:10FB2000843609F465C0843709F4EBC0853709F4DD
52
+:10FB3000D2C0863709F44AC0809102018F5F80935A
53
+:10FB40000201853071F6E0910001F0910101099503
54
+:10FB50000E94D27C803349F60E94087DC2CF0E9469
55
+:10FB6000D27CC82F803241F784E10E94007D81E47D
56
+:10FB70000E94007D86E50E94007D82E50E94007D56
57
+:10FB80008C2F0E94007D89E40E94007D83E50E9405
58
+:10FB9000007D80E50E94007D80E10E94007DA1CF74
59
+:10FBA0000E94D27C8638C0F20E94D27C0E94087DDE
60
+:10FBB00098CF0E94D27C803809F407C1813809F4BB
61
+:10FBC00000C1823809F4F9C0883921F080E00E9430
62
+:10FBD000217D87CF83E00E94217D83CF84E10E9435
63
+:10FBE000407D0E94087D7DCF85E00E94407DF9CF59
64
+:10FBF0000E94D27C809306020E94D27C80930502F0
65
+:10FC0000809108028E7F809308020E94D27C853406
66
+:10FC100009F44BC0E5E0F1E0119281E0E438F80727
67
+:10FC2000D9F3D0F3C0E0D0E08091050290910602B4
68
+:10FC30001816190678F405E011E00E94D27CF8014C
69
+:10FC400081938F0121968091050290910602C81739
70
+:10FC5000D90798F30E94D27C803209F06DCF809151
71
+:10FC6000080280FFB6C0C0E0D0E0209105023091CC
72
+:10FC7000060212161306B8F4E0910301F091040194
73
+:10FC8000A5E0B1E0F999FECFF2BDE1BD8D9180BD57
74
+:10FC9000FA9AF99A31962196C217D30798F3F093FE
75
+:10FCA0000401E093030184E175CF80910802816033
76
+:10FCB00080930802AFCF84E00E94407D80E087CF30
77
+:10FCC0000E94D27C809303010E94D27C8093040125
78
+:10FCD0000E94087D06CF0E94D27C803209F02CCF92
79
+:10FCE00084E10E94007D8EE10E94007D86E90E94F1
80
+:10FCF000007D89E04FCF0E94087D88E080936000FE
81
+:10FD0000FFCF0E94D27C809306020E94D27C809317
82
+:10FD100005020E94D27C853409F449C08091080212
83
+:10FD20008E7F809308028091030190910401880FD7
84
+:10FD3000991F90930401809303010E94D27C80322A
85
+:10FD400009F0CFCE84E10E94007DC0E0D0E0209198
86
+:10FD50000502309106021216130608F01DCFE0913D
87
+:10FD60000301F09104018091080280FF96C0F99987
88
+:10FD7000FECFF2BDE1BDF89A80B50E94007DE09112
89
+:10FD80000301F09104013196F0930401E093030123
90
+:10FD900020910502309106022196C217D30718F36D
91
+:10FDA000FBCEE0910001F0910101099586CE809192
92
+:10FDB0000802816080930802C0CF80E10E94217D0B
93
+:10FDC00090CE81E00E94217D8CCE82E00E94217D38
94
+:10FDD00088CE8091030190910401880F991F909320
95
+:10FDE0000401809303018091050280FF09C0809186
96
+:10FDF00005029091060201969093060280930502F7
97
+:10FE0000F999FECF1127E0910301F0910401C5E0BB
98
+:10FE1000D1E08091050290910602103091F400919A
99
+:10FE2000570001700130D9F303E000935700E895C3
100
+:10FE30000091570001700130D9F301E100935700A0
101
+:10FE4000E895099019900091570001700130D9F39D
102
+:10FE500001E000935700E8951395103898F01127AA
103
+:10FE60000091570001700130D9F305E0009357006D
104
+:10FE7000E8950091570001700130D9F301E100933A
105
+:10FE80005700E8953296029709F0C7CF103011F06D
106
+:10FE90000296E5CF112484E17DCE869580FF06C0D1
107
+:10FEA0003196F0930401E093030176CF84910E9490
108
+:10FEB000007D2091050230910602E0910301F0914E
109
+:10FEC0000401EECF1F93CF930E94D27CC82F0E94D3
110
+:10FED000007D0E94D27C182F0E94007DC1362CF03C
111
+:10FEE000C75511363CF0175508C0C033D4F3C05382
112
+:10FEF0001136CCF710330CF01053C295C07FC10FF0
113
+:10FF00008C2F992787FD9095CF911F910895CF93BE
114
+:10FF1000282F992787FD9095807F907095958795DC
115
+:10FF20009595879595958795959587958A303CF019
116
+:10FF3000895AC22FCF70CA303CF0C95A06C0805DC2
117
+:10FF4000C22FCF70CA30CCF7C05D0E94007D8C2FCD
118
+:0AFF50000E94007DCF910895FFCFBD
119
+:040000030000F80001
120
+:00000001FF

+ 121
- 0
Marlin/Marlin/Boards/bootloaders/atmega644p/ATmegaBOOT_644P.hex Переглянути файл

1
+:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
2
+:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
3
+:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
4
+:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
5
+:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
6
+:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
7
+:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
8
+:10F870000C945B7C0C945B7C0C945B7C11241FBE11
9
+:10F88000CFEFD0E1DEBFCDBF11E0A0E0B1E0E6E612
10
+:10F89000FFEF02C005900D92A030B107D9F712E03A
11
+:10F8A000A0E0B1E001C01D92A930B107E1F70E94CC
12
+:10F8B000537D0C94B27F0C94007CCF93DF93CDB733
13
+:10F8C000DEB724970FB6F894DEBF0FBECDBF8823F6
14
+:10F8D00009F481E020E0482F55274115510509F42E
15
+:10F8E0003DC0289A19821A821B821C820BC0898112
16
+:10F8F0009A81AB81BC810196A11DB11D89839A8338
17
+:10F90000AB83BC8389819A81AB81BC8180589E4343
18
+:10F91000A040B04060F3289819821A821B821C8292
19
+:10F920000BC089819A81AB81BC810196A11DB11D5B
20
+:10F9300089839A83AB83BC8389819A81AB81BC81A3
21
+:10F9400080509A4FA040B04060F32F5F822F9927DC
22
+:10F9500087FD9095841795070CF4C3CF19821A82FE
23
+:10F960001B821C8289819A81AB81BC818050914726
24
+:10F97000A240B040A0F489819A81AB81BC810196FC
25
+:10F98000A11DB11D89839A83AB83BC8389819A8130
26
+:10F99000AB81BC8180509147A240B04060F3249677
27
+:10F9A0000FB6F894DEBF0FBECDBFDF91CF910895A3
28
+:10F9B000EF92FF920F931F93EE24FF248701289864
29
+:10F9C0008091C00087FD17C00894E11CF11C011D47
30
+:10F9D000111D81E0E81689E0F8068DE3080780E054
31
+:10F9E000180770F3E0910001F091010109958091F1
32
+:10F9F000C00087FFE9CF289A8091C600992787FD2C
33
+:10FA000090951F910F91FF90EF900895982F8091FE
34
+:10FA1000C00085FFFCCF9093C60008950E94D87C5B
35
+:10FA2000803271F0809102018F5F809302018530F6
36
+:10FA300009F00895E0910001F09101010995089500
37
+:10FA400084E10E94067D80E10E94067D0895CF93A7
38
+:10FA5000C82F0E94D87C803241F0809102018F5FD4
39
+:10FA600080930201853081F40AC084E10E94067D02
40
+:10FA70008C2F0E94067D80E10E94067D05C0E091EA
41
+:10FA80000001F09101010995CF910895282F90E090
42
+:10FA900007C08091C0008823E4F78091C6009F5F73
43
+:10FAA0009217B8F30895CFEFD0E1DEBFCDBF0000CD
44
+:10FAB00094B714BE809160008861809360001092BA
45
+:10FAC000600091FF74C189E18093C4001092C50069
46
+:10FAD00088E18093C10086E08093C2005098589AD4
47
+:10FAE000209A83E00E945D7C81E00E945D7C0E9400
48
+:10FAF000D87C8033B9F18133C1F1803409F456C028
49
+:10FB0000813409F45CC0823409F46EC0853409F490
50
+:10FB100071C0803539F1813509F4F3C0823511F1B6
51
+:10FB2000853509F4D3C0863509F4CBC0843609F491
52
+:10FB300065C0843709F4EBC0853709F4D2C0863735
53
+:10FB400009F44AC0809102018F5F809302018530E1
54
+:10FB500071F6E0910001F091010109950E94D87CB5
55
+:10FB6000803349F60E940E7DC2CF0E94D87CC82FF8
56
+:10FB7000803241F784E10E94067D81E40E94067D87
57
+:10FB800086E50E94067D82E50E94067D8C2F0E94FC
58
+:10FB9000067D89E40E94067D83E50E94067D80E55E
59
+:10FBA0000E94067D80E10E94067DA1CF0E94D87C44
60
+:10FBB0008638C0F20E94D87C0E940E7D98CF0E94A9
61
+:10FBC000D87C803809F407C1813809F400C1823833
62
+:10FBD00009F4F9C0883921F080E00E94277D87CFA1
63
+:10FBE00083E00E94277D83CF84E10E94467D0E94AE
64
+:10FBF0000E7D7DCF85E00E94467DF9CF0E94D87CA6
65
+:10FC0000809306020E94D87C8093050280910802AE
66
+:10FC10008E7F809308020E94D87C853409F44BC003
67
+:10FC2000E5E0F1E0119281E0E438F807D9F3D0F390
68
+:10FC3000C0E0D0E0809105029091060218161906E6
69
+:10FC400078F405E011E00E94D87CF80181938F01DF
70
+:10FC500021968091050290910602C817D90798F362
71
+:10FC60000E94D87C803209F06DCF8091080280FF1D
72
+:10FC7000B6C0C0E0D0E02091050230910602121615
73
+:10FC80001306B8F4E0910301F0910401A5E0B1E09E
74
+:10FC9000F999FECFF2BDE1BD8D9180BDFA9AF99A36
75
+:10FCA00031962196C217D30798F3F0930401E0939D
76
+:10FCB000030184E175CF809108028160809308027E
77
+:10FCC000AFCF84E00E94467D80E087CF0E94D87C41
78
+:10FCD000809303010E94D87C809304010E940E7DD2
79
+:10FCE00006CF0E94D87C803209F02CCF84E10E949C
80
+:10FCF000067D8EE10E94067D86E90E94067D8AE0EF
81
+:10FD00004FCF0E940E7D88E080936000FFCF0E945D
82
+:10FD1000D87C809306020E94D87C809305020E94C2
83
+:10FD2000D87C853409F449C0809108028E7F809385
84
+:10FD300008028091030190910401880F991F90930C
85
+:10FD40000401809303010E94D87C803209F0CFCE59
86
+:10FD500084E10E94067DC0E0D0E020910502309150
87
+:10FD600006021216130608F01DCFE0910301F09170
88
+:10FD700004018091080280FF96C0F999FECFF2BD80
89
+:10FD8000E1BDF89A80B50E94067DE0910301F091F3
90
+:10FD900004013196F0930401E093030120910502E0
91
+:10FDA000309106022196C217D30718F3FBCEE091DB
92
+:10FDB0000001F0910101099586CE809108028160D1
93
+:10FDC00080930802C0CF80E10E94277D90CE81E021
94
+:10FDD0000E94277D8CCE82E00E94277D88CE809174
95
+:10FDE000030190910401880F991F9093040180935F
96
+:10FDF00003018091050280FF09C080910502909166
97
+:10FE0000060201969093060280930502F999FECFAF
98
+:10FE10001127E0910301F0910401C5E0D1E0809148
99
+:10FE2000050290910602103091F400915700017084
100
+:10FE30000130D9F303E000935700E8950091570093
101
+:10FE400001700130D9F301E100935700E895099062
102
+:10FE500019900091570001700130D9F301E000932F
103
+:10FE60005700E8951395103898F011270091570026
104
+:10FE700001700130D9F305E000935700E895009137
105
+:10FE8000570001700130D9F301E100935700E89564
106
+:10FE90003296029709F0C7CF103011F00296E5CFE5
107
+:10FEA000112484E17DCE869580FF06C03196F093C3
108
+:10FEB0000401E093030176CF84910E94067D209196
109
+:10FEC000050230910602E0910301F0910401EECFAA
110
+:10FED0001F93CF930E94D87CC82F0E94067D0E945A
111
+:10FEE000D87C182F0E94067DC1362CF0C7551136DC
112
+:10FEF0003CF0175508C0C033D4F3C0531136CCF7CB
113
+:10FF000010330CF01053C295C07FC10F8C2F99276E
114
+:10FF100087FD9095CF911F910895CF93282F992712
115
+:10FF200087FD9095807F907095958795959587959D
116
+:10FF300095958795959587958A303CF0895AC22F7B
117
+:10FF4000CF70CA303CF0C95A06C0805DC22FCF7056
118
+:10FF5000CA30CCF7C05D0E94067D8C2F0E94067DC2
119
+:06FF6000CF910895FFCFD0
120
+:040000030000F80001
121
+:00000001FF

+ 56
- 0
Marlin/Marlin/Boards/bootloaders/atmega644p/Makefile Переглянути файл

1
+# Makefile for ATmegaBOOT
2
+# E.Lins, 18.7.2005
3
+# $Id$
4
+
5
+
6
+# program name should not be changed...
7
+PROGRAM    = ATmegaBOOT_644P
8
+
9
+# enter the target CPU frequency
10
+AVR_FREQ   = 16000000L
11
+
12
+MCU_TARGET = atmega644p
13
+LDSECTION  = --section-start=.text=0xF800
14
+
15
+OBJ        = $(PROGRAM).o
16
+OPTIMIZE   = -O2
17
+
18
+DEFS       = 
19
+LIBS       = 
20
+
21
+CC         = avr-gcc
22
+
23
+
24
+# Override is only needed by avr-lib build system.
25
+
26
+override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
27
+override LDFLAGS       = -Wl,$(LDSECTION)
28
+#override LDFLAGS       = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
29
+
30
+OBJCOPY        = avr-objcopy
31
+OBJDUMP        = avr-objdump
32
+
33
+all: CFLAGS += '-DMAX_TIME_COUNT=8000000L>>1' -DADABOOT
34
+all: $(PROGRAM).hex
35
+
36
+$(PROGRAM).hex: $(PROGRAM).elf
37
+	$(OBJCOPY) -j .text -j .data -O ihex $< $@
38
+	
39
+$(PROGRAM).elf: $(OBJ)
40
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
41
+	
42
+$(OBJ): ATmegaBOOT.c
43
+	avr-gcc $(CFLAGS) $(LDFLAGS) -c -g -O2 -Wall -mmcu=$(MCU_TARGET) ATmegaBOOT.c -o $(PROGRAM).o
44
+
45
+%.lst: %.elf
46
+	$(OBJDUMP) -h -S $< > $@
47
+
48
+%.srec: %.elf
49
+	$(OBJCOPY) -j .text -j .data -O srec $< $@
50
+
51
+%.bin: %.elf
52
+	$(OBJCOPY) -j .text -j .data -O binary $< $@
53
+
54
+clean:
55
+	rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
56
+	

+ 3
- 0
Marlin/Marlin/Boards/bootloaders/atmega644p/README.txt Переглянути файл

1
+Note: This bootloader support ATmega644, ATmega644P and ATmega324P.
2
+To build, set PROGRAM and MCU_TARGET in the Makefile according to your target device.
3
+

+ 1
- 0
Marlin/Marlin/Boards/cores/arduino/Arduino.h Переглянути файл

1
+    #include "WProgram.h"

+ 135
- 0
Marlin/Marlin/Boards/cores/arduino/Copy of wiring.h Переглянути файл

1
+/*
2
+  wiring.h - Partial implementation of the Wiring API for the ATmega8.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id$
23
+*/
24
+
25
+#ifndef Wiring_h
26
+#define Wiring_h
27
+
28
+#include <avr/io.h>
29
+#include <stdlib.h>
30
+#include "binary.h"
31
+
32
+#ifdef __cplusplus
33
+extern "C"{
34
+#endif
35
+
36
+#define HIGH 0x1
37
+#define LOW  0x0
38
+
39
+#define INPUT 0x0
40
+#define OUTPUT 0x1
41
+
42
+#define true 0x1
43
+#define false 0x0
44
+
45
+#define PI 3.1415926535897932384626433832795
46
+#define HALF_PI 1.5707963267948966192313216916398
47
+#define TWO_PI 6.283185307179586476925286766559
48
+#define DEG_TO_RAD 0.017453292519943295769236907684886
49
+#define RAD_TO_DEG 57.295779513082320876798154814105
50
+
51
+#define SERIAL  0x0
52
+#define DISPLAY 0x1
53
+
54
+#define LSBFIRST 0
55
+#define MSBFIRST 1
56
+
57
+#define CHANGE 1
58
+#define FALLING 2
59
+#define RISING 3
60
+
61
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
62
+#define INTERNAL1V1 2
63
+#define INTERNAL2V56 3
64
+#else
65
+#define INTERNAL 3
66
+#endif
67
+#define DEFAULT 1
68
+#define EXTERNAL 0
69
+
70
+// undefine stdlib's abs if encountered
71
+#ifdef abs
72
+#undef abs
73
+#endif
74
+
75
+#define min(a,b) ((a)<(b)?(a):(b))
76
+#define max(a,b) ((a)>(b)?(a):(b))
77
+#define abs(x) ((x)>0?(x):-(x))
78
+#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
79
+#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
80
+#define radians(deg) ((deg)*DEG_TO_RAD)
81
+#define degrees(rad) ((rad)*RAD_TO_DEG)
82
+#define sq(x) ((x)*(x))
83
+
84
+#define interrupts() sei()
85
+#define noInterrupts() cli()
86
+
87
+#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
88
+#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
89
+#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
90
+
91
+#define lowByte(w) ((uint8_t) ((w) & 0xff))
92
+#define highByte(w) ((uint8_t) ((w) >> 8))
93
+
94
+#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
95
+#define bitSet(value, bit) ((value) |= (1UL << (bit)))
96
+#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
97
+#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
98
+
99
+
100
+typedef unsigned int word;
101
+
102
+#define bit(b) (1UL << (b))
103
+
104
+typedef uint8_t boolean;
105
+typedef uint8_t byte;
106
+
107
+void init(void);
108
+
109
+void pinMode(uint8_t, uint8_t);
110
+void digitalWrite(uint8_t, uint8_t);
111
+int digitalRead(uint8_t);
112
+int analogRead(uint8_t);
113
+void analogReference(uint8_t mode);
114
+void analogWrite(uint8_t, int);
115
+
116
+unsigned long millis(void);
117
+unsigned long micros(void);
118
+void delay(unsigned long);
119
+void delayMicroseconds(unsigned int us);
120
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
121
+
122
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
123
+uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
124
+
125
+void attachInterrupt(uint8_t, void (*)(void), int mode);
126
+void detachInterrupt(uint8_t);
127
+
128
+void setup(void);
129
+void loop(void);
130
+
131
+#ifdef __cplusplus
132
+} // extern "C"
133
+#endif
134
+
135
+#endif

+ 202
- 0
Marlin/Marlin/Boards/cores/arduino/HardwareSerial.cpp Переглянути файл

1
+/*
2
+  HardwareSerial.cpp - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right 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
+  Modified 23 November 2006 by David A. Mellis
20
+  Modified 28 September 2010 by Mark Sproul
21
+*/
22
+
23
+#include <stdlib.h>
24
+#include <stdio.h>
25
+#include <string.h>
26
+#include <inttypes.h>
27
+#include "wiring.h"
28
+#include "wiring_private.h"
29
+
30
+// this next line disables the entire HardwareSerial.cpp, 
31
+// this is so I can support Attiny series and any other chip without a uart
32
+#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
33
+
34
+#include "HardwareSerial.h"
35
+
36
+// Define constants and variables for buffering incoming serial data.  We're
37
+// using a ring buffer (I think), in which rx_buffer_head is the index of the
38
+// location to which to write the next incoming character and rx_buffer_tail
39
+// is the index of the location from which to read.
40
+#define RX_BUFFER_SIZE 128
41
+
42
+struct ring_buffer
43
+{
44
+  unsigned char buffer[RX_BUFFER_SIZE];
45
+  int head;
46
+  int tail;
47
+};
48
+
49
+ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
50
+
51
+inline void store_char(unsigned char c, ring_buffer *rx_buffer)
52
+{
53
+  int i = (unsigned int)(rx_buffer->head + 1) & (RX_BUFFER_SIZE -1);
54
+
55
+  // if we should be storing the received character into the location
56
+  // just before the tail (meaning that the head would advance to the
57
+  // current location of the tail), we're about to overflow the buffer
58
+  // and so we don't write the character or advance the head.
59
+  if (i != rx_buffer->tail) {
60
+    rx_buffer->buffer[rx_buffer->head] = c;
61
+    rx_buffer->head = i;
62
+  }
63
+}
64
+
65
+// fixed by Mark Sproul this is on the 644/644p
66
+//SIGNAL(SIG_USART_RECV)
67
+SIGNAL(USART0_RX_vect)
68
+{
69
+  unsigned char c  =  UDR0;
70
+  store_char(c, &rx_buffer);
71
+}
72
+
73
+
74
+// Constructors ////////////////////////////////////////////////////////////////
75
+
76
+HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
77
+  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
78
+  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
79
+  volatile uint8_t *udr,
80
+  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
81
+{
82
+  _rx_buffer = rx_buffer;
83
+  _ubrrh = ubrrh;
84
+  _ubrrl = ubrrl;
85
+  _ucsra = ucsra;
86
+  _ucsrb = ucsrb;
87
+  _udr = udr;
88
+  _rxen = rxen;
89
+  _txen = txen;
90
+  _rxcie = rxcie;
91
+  _udre = udre;
92
+  _u2x = u2x;
93
+}
94
+
95
+// Public Methods //////////////////////////////////////////////////////////////
96
+
97
+void HardwareSerial::begin(long baud)
98
+{
99
+  uint16_t baud_setting;
100
+  bool use_u2x = true;
101
+
102
+#if F_CPU == 16000000UL
103
+  // hardcoded exception for compatibility with the bootloader shipped
104
+  // with the Duemilanove and previous boards and the firmware on the 8U2
105
+  // on the Uno and Mega 2560.
106
+  if (baud == 57600) {
107
+    use_u2x = false;
108
+  }
109
+#endif
110
+  
111
+  if (use_u2x) {
112
+    *_ucsra = 1 << _u2x;
113
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
114
+  } else {
115
+    *_ucsra = 0;
116
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
117
+  }
118
+
119
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
120
+  *_ubrrh = baud_setting >> 8;
121
+  *_ubrrl = baud_setting;
122
+
123
+  sbi(*_ucsrb, _rxen);
124
+  sbi(*_ucsrb, _txen);
125
+  sbi(*_ucsrb, _rxcie);
126
+}
127
+
128
+void HardwareSerial::end()
129
+{
130
+  cbi(*_ucsrb, _rxen);
131
+  cbi(*_ucsrb, _txen);
132
+  cbi(*_ucsrb, _rxcie);  
133
+}
134
+
135
+int HardwareSerial::available(void)
136
+{
137
+  return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) & (RX_BUFFER_SIZE-1);
138
+}
139
+
140
+int HardwareSerial::peek(void)
141
+{
142
+  if (_rx_buffer->head == _rx_buffer->tail) {
143
+    return -1;
144
+  } else {
145
+    return _rx_buffer->buffer[_rx_buffer->tail];
146
+  }
147
+}
148
+
149
+int HardwareSerial::read(void)
150
+{
151
+  // if the head isn't ahead of the tail, we don't have any characters
152
+  if (_rx_buffer->head == _rx_buffer->tail) {
153
+    return -1;
154
+  } else {
155
+    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
156
+    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) & (RX_BUFFER_SIZE-1);
157
+    return c;
158
+  }
159
+}
160
+
161
+void HardwareSerial::flush()
162
+{
163
+  // don't reverse this or there may be problems if the RX interrupt
164
+  // occurs after reading the value of rx_buffer_head but before writing
165
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
166
+  // may be written to rx_buffer_tail, making it appear as if the buffer
167
+  // don't reverse this or there may be problems if the RX interrupt
168
+  // occurs after reading the value of rx_buffer_head but before writing
169
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
170
+  // may be written to rx_buffer_tail, making it appear as if the buffer
171
+  // were full, not empty.
172
+  _rx_buffer->head = _rx_buffer->tail;
173
+}
174
+
175
+//
176
+// Drakelive  2012-09-04
177
+//
178
+#if ARDUINO >= 100 
179
+	size_t  HardwareSerial::write(uint8_t c)
180
+	{
181
+	  while (!((*_ucsra) & (1 << _udre)))
182
+	    ;
183
+
184
+	  *_udr = c;
185
+	}
186
+#else
187
+	void HardwareSerial::write(uint8_t c)
188
+	{
189
+	  while (!((*_ucsra) & (1 << _udre)))
190
+		 ;
191
+
192
+	  *_udr = c;
193
+	}        
194
+#endif
195
+
196
+// Drakelive  2012-09-04
197
+
198
+// Preinstantiate Objects //////////////////////////////////////////////////////
199
+HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
200
+
201
+#endif // whole file
202
+

+ 87
- 0
Marlin/Marlin/Boards/cores/arduino/HardwareSerial.h Переглянути файл

1
+/*
2
+  HardwareSerial.h - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right 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
+  Modified 28 September 2010 by Mark Sproul
20
+*/
21
+
22
+#ifndef HardwareSerial_h
23
+#define HardwareSerial_h
24
+
25
+#include <inttypes.h>
26
+
27
+#include "Stream.h"
28
+
29
+struct ring_buffer;
30
+
31
+class HardwareSerial : public Stream
32
+{
33
+  private:
34
+    ring_buffer *_rx_buffer;
35
+    volatile uint8_t *_ubrrh;
36
+    volatile uint8_t *_ubrrl;
37
+    volatile uint8_t *_ucsra;
38
+    volatile uint8_t *_ucsrb;
39
+    volatile uint8_t *_udr;
40
+    uint8_t _rxen;
41
+    uint8_t _txen;
42
+    uint8_t _rxcie;
43
+    uint8_t _udre;
44
+    uint8_t _u2x;
45
+  public:
46
+    HardwareSerial(ring_buffer *rx_buffer,
47
+      volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
48
+      volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
49
+      volatile uint8_t *udr,
50
+      uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
51
+    void begin(long);
52
+    void end();
53
+    virtual int available(void);
54
+    virtual int peek(void);
55
+    virtual int read(void);
56
+    virtual void flush(void);
57
+    
58
+    //
59
+    // Drakelive  2012-09-04
60
+    //
61
+    #if ARDUINO >= 100 
62
+        virtual size_t write(uint8_t);
63
+    #else
64
+        virtual void write(uint8_t);
65
+    #endif
66
+     
67
+    // Drakelive  2012-09-04
68
+
69
+    using Print::write; // pull in write(str) and write(buf, size) from Print
70
+};
71
+
72
+#if defined(UBRRH) || defined(UBRR0H)
73
+  extern HardwareSerial Serial;
74
+#elif defined(USBCON)
75
+  #include "usb_api.h"
76
+#endif
77
+#if defined(UBRR1H)
78
+  extern HardwareSerial Serial1;
79
+#endif
80
+#if defined(UBRR2H)
81
+  extern HardwareSerial Serial2;
82
+#endif
83
+#if defined(UBRR3H)
84
+  extern HardwareSerial Serial3;
85
+#endif
86
+
87
+#endif

+ 220
- 0
Marlin/Marlin/Boards/cores/arduino/Print.cpp Переглянути файл

1
+/*
2
+ Print.cpp - Base class that provides print() and println()
3
+ Copyright (c) 2008 David A. Mellis.  All right 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
+ Modified 23 November 2006 by David A. Mellis
20
+ */
21
+
22
+#include <stdlib.h>
23
+#include <stdio.h>
24
+#include <string.h>
25
+#include <math.h>
26
+#include "wiring.h"
27
+
28
+#include "Print.h"
29
+
30
+// Public Methods //////////////////////////////////////////////////////////////
31
+
32
+/* default implementation: may be overridden */
33
+void Print::write(const char *str)
34
+{
35
+  while (*str)
36
+    write(*str++);
37
+}
38
+
39
+/* default implementation: may be overridden */
40
+void Print::write(const uint8_t *buffer, size_t size)
41
+{
42
+  while (size--)
43
+    write(*buffer++);
44
+}
45
+
46
+void Print::print(const String &s)
47
+{
48
+  for (int i = 0; i < s.length(); i++) {
49
+    write(s[i]);
50
+  }
51
+}
52
+
53
+void Print::print(const char str[])
54
+{
55
+  write(str);
56
+}
57
+
58
+void Print::print(char c, int base)
59
+{
60
+  print((long) c, base);
61
+}
62
+
63
+void Print::print(unsigned char b, int base)
64
+{
65
+  print((unsigned long) b, base);
66
+}
67
+
68
+void Print::print(int n, int base)
69
+{
70
+  print((long) n, base);
71
+}
72
+
73
+void Print::print(unsigned int n, int base)
74
+{
75
+  print((unsigned long) n, base);
76
+}
77
+
78
+void Print::print(long n, int base)
79
+{
80
+  if (base == 0) {
81
+    write(n);
82
+  } else if (base == 10) {
83
+    if (n < 0) {
84
+      print('-');
85
+      n = -n;
86
+    }
87
+    printNumber(n, 10);
88
+  } else {
89
+    printNumber(n, base);
90
+  }
91
+}
92
+
93
+void Print::print(unsigned long n, int base)
94
+{
95
+  if (base == 0) write(n);
96
+  else printNumber(n, base);
97
+}
98
+
99
+void Print::print(double n, int digits)
100
+{
101
+  printFloat(n, digits);
102
+}
103
+
104
+void Print::println(void)
105
+{
106
+  print('\r');
107
+  print('\n');  
108
+}
109
+
110
+void Print::println(const String &s)
111
+{
112
+  print(s);
113
+  println();
114
+}
115
+
116
+void Print::println(const char c[])
117
+{
118
+  print(c);
119
+  println();
120
+}
121
+
122
+void Print::println(char c, int base)
123
+{
124
+  print(c, base);
125
+  println();
126
+}
127
+
128
+void Print::println(unsigned char b, int base)
129
+{
130
+  print(b, base);
131
+  println();
132
+}
133
+
134
+void Print::println(int n, int base)
135
+{
136
+  print(n, base);
137
+  println();
138
+}
139
+
140
+void Print::println(unsigned int n, int base)
141
+{
142
+  print(n, base);
143
+  println();
144
+}
145
+
146
+void Print::println(long n, int base)
147
+{
148
+  print(n, base);
149
+  println();
150
+}
151
+
152
+void Print::println(unsigned long n, int base)
153
+{
154
+  print(n, base);
155
+  println();
156
+}
157
+
158
+void Print::println(double n, int digits)
159
+{
160
+  print(n, digits);
161
+  println();
162
+}
163
+
164
+// Private Methods /////////////////////////////////////////////////////////////
165
+
166
+void Print::printNumber(unsigned long n, uint8_t base)
167
+{
168
+  unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
169
+  unsigned long i = 0;
170
+
171
+  if (n == 0) {
172
+    print('0');
173
+    return;
174
+  } 
175
+
176
+  while (n > 0) {
177
+    buf[i++] = n % base;
178
+    n /= base;
179
+  }
180
+
181
+  for (; i > 0; i--)
182
+    print((char) (buf[i - 1] < 10 ?
183
+      '0' + buf[i - 1] :
184
+      'A' + buf[i - 1] - 10));
185
+}
186
+
187
+void Print::printFloat(double number, uint8_t digits) 
188
+{ 
189
+  // Handle negative numbers
190
+  if (number < 0.0)
191
+  {
192
+     print('-');
193
+     number = -number;
194
+  }
195
+
196
+  // Round correctly so that print(1.999, 2) prints as "2.00"
197
+  double rounding = 0.5;
198
+  for (uint8_t i=0; i<digits; ++i)
199
+    rounding /= 10.0;
200
+  
201
+  number += rounding;
202
+
203
+  // Extract the integer part of the number and print it
204
+  unsigned long int_part = (unsigned long)number;
205
+  double remainder = number - (double)int_part;
206
+  print(int_part);
207
+
208
+  // Print the decimal point, but only if there are digits beyond
209
+  if (digits > 0)
210
+    print("."); 
211
+
212
+  // Extract digits from the remainder one at a time
213
+  while (digits-- > 0)
214
+  {
215
+    remainder *= 10.0;
216
+    int toPrint = int(remainder);
217
+    print(toPrint);
218
+    remainder -= toPrint; 
219
+  } 
220
+}

+ 77
- 0
Marlin/Marlin/Boards/cores/arduino/Print.h Переглянути файл

1
+/*
2
+  Print.h - Base class that provides print() and println()
3
+  Copyright (c) 2008 David A. Mellis.  All right 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 Print_h
21
+#define Print_h
22
+
23
+#include <inttypes.h>
24
+#include <stdio.h> // for size_t
25
+
26
+#include "WString.h"
27
+
28
+#define DEC 10
29
+#define HEX 16
30
+#define OCT 8
31
+#define BIN 2
32
+#define BYTE 0
33
+
34
+class Print
35
+{
36
+  private:
37
+    void printNumber(unsigned long, uint8_t);
38
+    void printFloat(double, uint8_t);
39
+  public:
40
+     
41
+    //
42
+    // Drakelive  2012-09-04
43
+    //
44
+    #if ARDUINO >= 100 
45
+        virtual size_t write(uint8_t) = 0;
46
+    #else
47
+        virtual void write(uint8_t) = 0;
48
+    #endif
49
+     
50
+    // Drakelive  2012-09-04     
51
+
52
+    virtual void write(const char *str);
53
+    virtual void write(const uint8_t *buffer, size_t size);
54
+    
55
+    void print(const String &);
56
+    void print(const char[]);
57
+    void print(char, int = BYTE);
58
+    void print(unsigned char, int = BYTE);
59
+    void print(int, int = DEC);
60
+    void print(unsigned int, int = DEC);
61
+    void print(long, int = DEC);
62
+    void print(unsigned long, int = DEC);
63
+    void print(double, int = 2);
64
+
65
+    void println(const String &s);
66
+    void println(const char[]);
67
+    void println(char, int = BYTE);
68
+    void println(unsigned char, int = BYTE);
69
+    void println(int, int = DEC);
70
+    void println(unsigned int, int = DEC);
71
+    void println(long, int = DEC);
72
+    void println(unsigned long, int = DEC);
73
+    void println(double, int = 2);
74
+    void println(void);
75
+};
76
+
77
+#endif

+ 35
- 0
Marlin/Marlin/Boards/cores/arduino/Stream.h Переглянути файл

1
+/*
2
+  Stream.h - base class for character-based streams.
3
+  Copyright (c) 2010 David A. Mellis.  All right 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 Stream_h
21
+#define Stream_h
22
+
23
+#include <inttypes.h>
24
+#include "Print.h"
25
+
26
+class Stream : public Print
27
+{
28
+  public:
29
+    virtual int available() = 0;
30
+    virtual int read() = 0;
31
+    virtual int peek() = 0;
32
+    virtual void flush() = 0;
33
+};
34
+
35
+#endif

+ 601
- 0
Marlin/Marlin/Boards/cores/arduino/Tone.cpp Переглянути файл

1
+/* Tone.cpp
2
+
3
+  A Tone Generator Library
4
+
5
+  Written by Brett Hagman
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General Public
18
+  License along with this library; if not, write to the Free Software
19
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
+
21
+Version Modified By Date     Comments
22
+------- ----------- -------- --------
23
+0001    B Hagman    09/08/02 Initial coding
24
+0002    B Hagman    09/08/18 Multiple pins
25
+0003    B Hagman    09/08/18 Moved initialization from constructor to begin()
26
+0004    B Hagman    09/09/26 Fixed problems with ATmega8
27
+0005    B Hagman    09/11/23 Scanned prescalars for best fit on 8 bit timers
28
+                    09/11/25 Changed pin toggle method to XOR
29
+                    09/11/25 Fixed timer0 from being excluded
30
+0006    D Mellis    09/12/29 Replaced objects with functions
31
+0007    M Sproul    10/08/29 Changed #ifdefs from cpu to register
32
+*************************************************/
33
+
34
+#include <avr/interrupt.h>
35
+#include <avr/pgmspace.h>
36
+#include "wiring.h"
37
+#include "pins_arduino.h"
38
+
39
+#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
40
+#define TCCR2A TCCR2
41
+#define TCCR2B TCCR2
42
+#define COM2A1 COM21
43
+#define COM2A0 COM20
44
+#define OCR2A OCR2
45
+#define TIMSK2 TIMSK
46
+#define OCIE2A OCIE2
47
+#define TIMER2_COMPA_vect TIMER2_COMP_vect
48
+#define TIMSK1 TIMSK
49
+#endif
50
+
51
+// timerx_toggle_count:
52
+//  > 0 - duration specified
53
+//  = 0 - stopped
54
+//  < 0 - infinitely (until stop() method called, or new play() called)
55
+
56
+#if !defined(__AVR_ATmega8__)
57
+volatile long timer0_toggle_count;
58
+volatile uint8_t *timer0_pin_port;
59
+volatile uint8_t timer0_pin_mask;
60
+#endif
61
+
62
+volatile long timer1_toggle_count;
63
+volatile uint8_t *timer1_pin_port;
64
+volatile uint8_t timer1_pin_mask;
65
+volatile long timer2_toggle_count;
66
+volatile uint8_t *timer2_pin_port;
67
+volatile uint8_t timer2_pin_mask;
68
+
69
+#if defined(TIMSK3)
70
+volatile long timer3_toggle_count;
71
+volatile uint8_t *timer3_pin_port;
72
+volatile uint8_t timer3_pin_mask;
73
+#endif
74
+
75
+#if defined(TIMSK4)
76
+volatile long timer4_toggle_count;
77
+volatile uint8_t *timer4_pin_port;
78
+volatile uint8_t timer4_pin_mask;
79
+#endif
80
+
81
+#if defined(TIMSK5)
82
+volatile long timer5_toggle_count;
83
+volatile uint8_t *timer5_pin_port;
84
+volatile uint8_t timer5_pin_mask;
85
+#endif
86
+
87
+
88
+// MLS: This does not make sense, the 3 options are the same
89
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
90
+
91
+#define AVAILABLE_TONE_PINS 1
92
+
93
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
94
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
95
+
96
+#elif defined(__AVR_ATmega8__)
97
+
98
+#define AVAILABLE_TONE_PINS 1
99
+
100
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ };
101
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
102
+
103
+#else
104
+
105
+#define AVAILABLE_TONE_PINS 1
106
+
107
+// Leave timer 0 to last.
108
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
109
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255 */ };
110
+
111
+#endif
112
+
113
+
114
+
115
+static int8_t toneBegin(uint8_t _pin)
116
+{
117
+  int8_t _timer = -1;
118
+
119
+  // if we're already using the pin, the timer should be configured.  
120
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
121
+    if (tone_pins[i] == _pin) {
122
+      return pgm_read_byte(tone_pin_to_timer_PGM + i);
123
+    }
124
+  }
125
+  
126
+  // search for an unused timer.
127
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
128
+    if (tone_pins[i] == 255) {
129
+      tone_pins[i] = _pin;
130
+      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
131
+      break;
132
+    }
133
+  }
134
+  
135
+  if (_timer != -1)
136
+  {
137
+    // Set timer specific stuff
138
+    // All timers in CTC mode
139
+    // 8 bit timers will require changing prescalar values,
140
+    // whereas 16 bit timers are set to either ck/1 or ck/64 prescalar
141
+    switch (_timer)
142
+    {
143
+      #if defined(TCCR0A) && defined(TCCR0B)
144
+      case 0:
145
+        // 8 bit timer
146
+        TCCR0A = 0;
147
+        TCCR0B = 0;
148
+        bitWrite(TCCR0A, WGM01, 1);
149
+        bitWrite(TCCR0B, CS00, 1);
150
+        timer0_pin_port = portOutputRegister(digitalPinToPort(_pin));
151
+        timer0_pin_mask = digitalPinToBitMask(_pin);
152
+        break;
153
+      #endif
154
+
155
+      #if defined(TCCR1A) && defined(TCCR1B) && defined(WGM12)
156
+      case 1:
157
+        // 16 bit timer
158
+        TCCR1A = 0;
159
+        TCCR1B = 0;
160
+        bitWrite(TCCR1B, WGM12, 1);
161
+        bitWrite(TCCR1B, CS10, 1);
162
+        timer1_pin_port = portOutputRegister(digitalPinToPort(_pin));
163
+        timer1_pin_mask = digitalPinToBitMask(_pin);
164
+        break;
165
+      #endif
166
+
167
+      #if defined(TCCR2A) && defined(TCCR2B)
168
+      case 2:
169
+        // 8 bit timer
170
+        TCCR2A = 0;
171
+        TCCR2B = 0;
172
+        bitWrite(TCCR2A, WGM21, 1);
173
+        bitWrite(TCCR2B, CS20, 1);
174
+        timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
175
+        timer2_pin_mask = digitalPinToBitMask(_pin);
176
+        break;
177
+      #endif
178
+
179
+      #if defined(TCCR3A) && defined(TCCR3B) &&  defined(TIMSK3)
180
+      case 3:
181
+        // 16 bit timer
182
+        TCCR3A = 0;
183
+        TCCR3B = 0;
184
+        bitWrite(TCCR3B, WGM32, 1);
185
+        bitWrite(TCCR3B, CS30, 1);
186
+        timer3_pin_port = portOutputRegister(digitalPinToPort(_pin));
187
+        timer3_pin_mask = digitalPinToBitMask(_pin);
188
+        break;
189
+      #endif
190
+
191
+      #if defined(TCCR4A) && defined(TCCR4B) &&  defined(TIMSK4)
192
+      case 4:
193
+        // 16 bit timer
194
+        TCCR4A = 0;
195
+        TCCR4B = 0;
196
+        #if defined(WGM42)
197
+          bitWrite(TCCR4B, WGM42, 1);
198
+        #elif defined(CS43)
199
+          #warning this may not be correct
200
+          // atmega32u4
201
+          bitWrite(TCCR4B, CS43, 1);
202
+        #endif
203
+        bitWrite(TCCR4B, CS40, 1);
204
+        timer4_pin_port = portOutputRegister(digitalPinToPort(_pin));
205
+        timer4_pin_mask = digitalPinToBitMask(_pin);
206
+        break;
207
+      #endif
208
+
209
+      #if defined(TCCR5A) && defined(TCCR5B) &&  defined(TIMSK5)
210
+      case 5:
211
+        // 16 bit timer
212
+        TCCR5A = 0;
213
+        TCCR5B = 0;
214
+        bitWrite(TCCR5B, WGM52, 1);
215
+        bitWrite(TCCR5B, CS50, 1);
216
+        timer5_pin_port = portOutputRegister(digitalPinToPort(_pin));
217
+        timer5_pin_mask = digitalPinToBitMask(_pin);
218
+        break;
219
+      #endif
220
+    }
221
+  }
222
+
223
+  return _timer;
224
+}
225
+
226
+
227
+
228
+// frequency (in hertz) and duration (in milliseconds).
229
+
230
+void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
231
+{
232
+  uint8_t prescalarbits = 0b001;
233
+  long toggle_count = 0;
234
+  uint32_t ocr = 0;
235
+  int8_t _timer;
236
+
237
+  _timer = toneBegin(_pin);
238
+
239
+  if (_timer >= 0)
240
+  {
241
+    // Set the pinMode as OUTPUT
242
+    pinMode(_pin, OUTPUT);
243
+    
244
+    // if we are using an 8 bit timer, scan through prescalars to find the best fit
245
+    if (_timer == 0 || _timer == 2)
246
+    {
247
+      ocr = F_CPU / frequency / 2 - 1;
248
+      prescalarbits = 0b001;  // ck/1: same for both timers
249
+      if (ocr > 255)
250
+      {
251
+        ocr = F_CPU / frequency / 2 / 8 - 1;
252
+        prescalarbits = 0b010;  // ck/8: same for both timers
253
+
254
+        if (_timer == 2 && ocr > 255)
255
+        {
256
+          ocr = F_CPU / frequency / 2 / 32 - 1;
257
+          prescalarbits = 0b011;
258
+        }
259
+
260
+        if (ocr > 255)
261
+        {
262
+          ocr = F_CPU / frequency / 2 / 64 - 1;
263
+          prescalarbits = _timer == 0 ? 0b011 : 0b100;
264
+
265
+          if (_timer == 2 && ocr > 255)
266
+          {
267
+            ocr = F_CPU / frequency / 2 / 128 - 1;
268
+            prescalarbits = 0b101;
269
+          }
270
+
271
+          if (ocr > 255)
272
+          {
273
+            ocr = F_CPU / frequency / 2 / 256 - 1;
274
+            prescalarbits = _timer == 0 ? 0b100 : 0b110;
275
+            if (ocr > 255)
276
+            {
277
+              // can't do any better than /1024
278
+              ocr = F_CPU / frequency / 2 / 1024 - 1;
279
+              prescalarbits = _timer == 0 ? 0b101 : 0b111;
280
+            }
281
+          }
282
+        }
283
+      }
284
+
285
+#if defined(TCCR0B)
286
+      if (_timer == 0)
287
+      {
288
+        TCCR0B = prescalarbits;
289
+      }
290
+      else
291
+#endif
292
+#if defined(TCCR2B)
293
+      {
294
+        TCCR2B = prescalarbits;
295
+      }
296
+#else
297
+      {
298
+        // dummy place holder to make the above ifdefs work
299
+      }
300
+#endif
301
+    }
302
+    else
303
+    {
304
+      // two choices for the 16 bit timers: ck/1 or ck/64
305
+      ocr = F_CPU / frequency / 2 - 1;
306
+
307
+      prescalarbits = 0b001;
308
+      if (ocr > 0xffff)
309
+      {
310
+        ocr = F_CPU / frequency / 2 / 64 - 1;
311
+        prescalarbits = 0b011;
312
+      }
313
+
314
+      if (_timer == 1)
315
+      {
316
+#if defined(TCCR1B)
317
+        TCCR1B = (TCCR1B & 0b11111000) | prescalarbits;
318
+#endif
319
+      }
320
+#if defined(TCCR3B)
321
+      else if (_timer == 3)
322
+        TCCR3B = (TCCR3B & 0b11111000) | prescalarbits;
323
+#endif
324
+#if defined(TCCR4B)
325
+      else if (_timer == 4)
326
+        TCCR4B = (TCCR4B & 0b11111000) | prescalarbits;
327
+#endif
328
+#if defined(TCCR5B)
329
+      else if (_timer == 5)
330
+        TCCR5B = (TCCR5B & 0b11111000) | prescalarbits;
331
+#endif
332
+
333
+    }
334
+    
335
+
336
+    // Calculate the toggle count
337
+    if (duration > 0)
338
+    {
339
+      toggle_count = 2 * frequency * duration / 1000;
340
+    }
341
+    else
342
+    {
343
+      toggle_count = -1;
344
+    }
345
+
346
+    // Set the OCR for the given timer,
347
+    // set the toggle count,
348
+    // then turn on the interrupts
349
+    switch (_timer)
350
+    {
351
+
352
+#if defined(OCR0A) && defined(TIMSK0) && defined(OCIE0A)
353
+      case 0:
354
+        OCR0A = ocr;
355
+        timer0_toggle_count = toggle_count;
356
+        bitWrite(TIMSK0, OCIE0A, 1);
357
+        break;
358
+#endif
359
+
360
+      case 1:
361
+#if defined(OCR1A) && defined(TIMSK1) && defined(OCIE1A)
362
+        OCR1A = ocr;
363
+        timer1_toggle_count = toggle_count;
364
+        bitWrite(TIMSK1, OCIE1A, 1);
365
+#elif defined(OCR1A) && defined(TIMSK) && defined(OCIE1A)
366
+        // this combination is for at least the ATmega32
367
+        OCR1A = ocr;
368
+        timer1_toggle_count = toggle_count;
369
+        bitWrite(TIMSK, OCIE1A, 1);
370
+#endif
371
+        break;
372
+
373
+#if defined(OCR2A) && defined(TIMSK2) && defined(OCIE2A)
374
+      case 2:
375
+        OCR2A = ocr;
376
+        timer2_toggle_count = toggle_count;
377
+        bitWrite(TIMSK2, OCIE2A, 1);
378
+        break;
379
+#endif
380
+
381
+#if defined(TIMSK3)
382
+      case 3:
383
+        OCR3A = ocr;
384
+        timer3_toggle_count = toggle_count;
385
+        bitWrite(TIMSK3, OCIE3A, 1);
386
+        break;
387
+#endif
388
+
389
+#if defined(TIMSK4)
390
+      case 4:
391
+        OCR4A = ocr;
392
+        timer4_toggle_count = toggle_count;
393
+        bitWrite(TIMSK4, OCIE4A, 1);
394
+        break;
395
+#endif
396
+
397
+#if defined(OCR5A) && defined(TIMSK5) && defined(OCIE5A)
398
+      case 5:
399
+        OCR5A = ocr;
400
+        timer5_toggle_count = toggle_count;
401
+        bitWrite(TIMSK5, OCIE5A, 1);
402
+        break;
403
+#endif
404
+
405
+    }
406
+  }
407
+}
408
+
409
+
410
+// XXX: this function only works properly for timer 2 (the only one we use
411
+// currently).  for the others, it should end the tone, but won't restore
412
+// proper PWM functionality for the timer.
413
+void disableTimer(uint8_t _timer)
414
+{
415
+  switch (_timer)
416
+  {
417
+    case 0:
418
+      #if defined(TIMSK0)
419
+        TIMSK0 = 0;
420
+      #elif defined(TIMSK)
421
+        TIMSK = 0; // atmega32
422
+      #endif
423
+      break;
424
+
425
+#if defined(TIMSK1) && defined(OCIE1A)
426
+    case 1:
427
+      bitWrite(TIMSK1, OCIE1A, 0);
428
+      break;
429
+#endif
430
+
431
+    case 2:
432
+      #if defined(TIMSK2) && defined(OCIE2A)
433
+        bitWrite(TIMSK2, OCIE2A, 0); // disable interrupt
434
+      #endif
435
+      #if defined(TCCR2A) && defined(WGM20)
436
+        TCCR2A = (1 << WGM20);
437
+      #endif
438
+      #if defined(TCCR2B) && defined(CS22)
439
+        TCCR2B = (TCCR2B & 0b11111000) | (1 << CS22);
440
+      #endif
441
+      #if defined(OCR2A)
442
+        OCR2A = 0;
443
+      #endif
444
+      break;
445
+
446
+#if defined(TIMSK3)
447
+    case 3:
448
+      TIMSK3 = 0;
449
+      break;
450
+#endif
451
+
452
+#if defined(TIMSK4)
453
+    case 4:
454
+      TIMSK4 = 0;
455
+      break;
456
+#endif
457
+
458
+#if defined(TIMSK5)
459
+    case 5:
460
+      TIMSK5 = 0;
461
+      break;
462
+#endif
463
+  }
464
+}
465
+
466
+
467
+void noTone(uint8_t _pin)
468
+{
469
+  int8_t _timer = -1;
470
+  
471
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
472
+    if (tone_pins[i] == _pin) {
473
+      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
474
+      tone_pins[i] = 255;
475
+    }
476
+  }
477
+  
478
+  disableTimer(_timer);
479
+
480
+  digitalWrite(_pin, 0);
481
+}
482
+
483
+#if 0
484
+#if !defined(__AVR_ATmega8__)
485
+ISR(TIMER0_COMPA_vect)
486
+{
487
+  if (timer0_toggle_count != 0)
488
+  {
489
+    // toggle the pin
490
+    *timer0_pin_port ^= timer0_pin_mask;
491
+
492
+    if (timer0_toggle_count > 0)
493
+      timer0_toggle_count--;
494
+  }
495
+  else
496
+  {
497
+    disableTimer(0);
498
+    *timer0_pin_port &= ~(timer0_pin_mask);  // keep pin low after stop
499
+  }
500
+}
501
+#endif
502
+
503
+
504
+ISR(TIMER1_COMPA_vect)
505
+{
506
+  if (timer1_toggle_count != 0)
507
+  {
508
+    // toggle the pin
509
+    *timer1_pin_port ^= timer1_pin_mask;
510
+
511
+    if (timer1_toggle_count > 0)
512
+      timer1_toggle_count--;
513
+  }
514
+  else
515
+  {
516
+    disableTimer(1);
517
+    *timer1_pin_port &= ~(timer1_pin_mask);  // keep pin low after stop
518
+  }
519
+}
520
+#endif
521
+
522
+
523
+ISR(TIMER2_COMPA_vect)
524
+{
525
+
526
+  if (timer2_toggle_count != 0)
527
+  {
528
+    // toggle the pin
529
+    *timer2_pin_port ^= timer2_pin_mask;
530
+
531
+    if (timer2_toggle_count > 0)
532
+      timer2_toggle_count--;
533
+  }
534
+  else
535
+  {
536
+    // need to call noTone() so that the tone_pins[] entry is reset, so the
537
+    // timer gets initialized next time we call tone().
538
+    // XXX: this assumes timer 2 is always the first one used.
539
+    noTone(tone_pins[0]);
540
+//    disableTimer(2);
541
+//    *timer2_pin_port &= ~(timer2_pin_mask);  // keep pin low after stop
542
+  }
543
+}
544
+
545
+
546
+
547
+//#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
548
+#if 0
549
+
550
+ISR(TIMER3_COMPA_vect)
551
+{
552
+  if (timer3_toggle_count != 0)
553
+  {
554
+    // toggle the pin
555
+    *timer3_pin_port ^= timer3_pin_mask;
556
+
557
+    if (timer3_toggle_count > 0)
558
+      timer3_toggle_count--;
559
+  }
560
+  else
561
+  {
562
+    disableTimer(3);
563
+    *timer3_pin_port &= ~(timer3_pin_mask);  // keep pin low after stop
564
+  }
565
+}
566
+
567
+ISR(TIMER4_COMPA_vect)
568
+{
569
+  if (timer4_toggle_count != 0)
570
+  {
571
+    // toggle the pin
572
+    *timer4_pin_port ^= timer4_pin_mask;
573
+
574
+    if (timer4_toggle_count > 0)
575
+      timer4_toggle_count--;
576
+  }
577
+  else
578
+  {
579
+    disableTimer(4);
580
+    *timer4_pin_port &= ~(timer4_pin_mask);  // keep pin low after stop
581
+  }
582
+}
583
+
584
+ISR(TIMER5_COMPA_vect)
585
+{
586
+  if (timer5_toggle_count != 0)
587
+  {
588
+    // toggle the pin
589
+    *timer5_pin_port ^= timer5_pin_mask;
590
+
591
+    if (timer5_toggle_count > 0)
592
+      timer5_toggle_count--;
593
+  }
594
+  else
595
+  {
596
+    disableTimer(5);
597
+    *timer5_pin_port &= ~(timer5_pin_mask);  // keep pin low after stop
598
+  }
599
+}
600
+
601
+#endif

+ 168
- 0
Marlin/Marlin/Boards/cores/arduino/WCharacter.h Переглянути файл

1
+/*
2
+ WCharacter.h - Character utility functions for Wiring & Arduino
3
+ Copyright (c) 2010 Hernando Barragan.  All right 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 Character_h
21
+#define Character_h
22
+
23
+#include <ctype.h>
24
+
25
+// WCharacter.h prototypes
26
+inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
27
+inline boolean isAlpha(int c) __attribute__((always_inline));
28
+inline boolean isAscii(int c) __attribute__((always_inline));
29
+inline boolean isWhitespace(int c) __attribute__((always_inline));
30
+inline boolean isControl(int c) __attribute__((always_inline));
31
+inline boolean isDigit(int c) __attribute__((always_inline));
32
+inline boolean isGraph(int c) __attribute__((always_inline));
33
+inline boolean isLowerCase(int c) __attribute__((always_inline));
34
+inline boolean isPrintable(int c) __attribute__((always_inline));
35
+inline boolean isPunct(int c) __attribute__((always_inline));
36
+inline boolean isSpace(int c) __attribute__((always_inline));
37
+inline boolean isUpperCase(int c) __attribute__((always_inline));
38
+inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
39
+inline int toAscii(int c) __attribute__((always_inline));
40
+inline int toLowerCase(int c) __attribute__((always_inline));
41
+inline int toUpperCase(int c)__attribute__((always_inline));
42
+
43
+
44
+// Checks for an alphanumeric character. 
45
+// It is equivalent to (isalpha(c) || isdigit(c)).
46
+inline boolean isAlphaNumeric(int c) 
47
+{
48
+  return ( isalnum(c) == 0 ? false : true);
49
+}
50
+
51
+
52
+// Checks for an alphabetic character. 
53
+// It is equivalent to (isupper(c) || islower(c)).
54
+inline boolean isAlpha(int c)
55
+{
56
+  return ( isalpha(c) == 0 ? false : true);
57
+}
58
+
59
+
60
+// Checks whether c is a 7-bit unsigned char value 
61
+// that fits into the ASCII character set.
62
+inline boolean isAscii(int c)
63
+{
64
+  return ( isascii (c) == 0 ? false : true);
65
+}
66
+
67
+
68
+// Checks for a blank character, that is, a space or a tab.
69
+inline boolean isWhitespace(int c)
70
+{
71
+  return ( isblank (c) == 0 ? false : true);
72
+}
73
+
74
+
75
+// Checks for a control character.
76
+inline boolean isControl(int c)
77
+{
78
+  return ( iscntrl (c) == 0 ? false : true);
79
+}
80
+
81
+
82
+// Checks for a digit (0 through 9).
83
+inline boolean isDigit(int c)
84
+{
85
+  return ( isdigit (c) == 0 ? false : true);
86
+}
87
+
88
+
89
+// Checks for any printable character except space.
90
+inline boolean isGraph(int c)
91
+{
92
+  return ( isgraph (c) == 0 ? false : true);
93
+}
94
+
95
+
96
+// Checks for a lower-case character.
97
+inline boolean isLowerCase(int c)
98
+{
99
+  return (islower (c) == 0 ? false : true);
100
+}
101
+
102
+
103
+// Checks for any printable character including space.
104
+inline boolean isPrintable(int c)
105
+{
106
+  return ( isprint (c) == 0 ? false : true);
107
+}
108
+
109
+
110
+// Checks for any printable character which is not a space 
111
+// or an alphanumeric character.
112
+inline boolean isPunct(int c)
113
+{
114
+  return ( ispunct (c) == 0 ? false : true);
115
+}
116
+
117
+
118
+// Checks for white-space characters. For the avr-libc library, 
119
+// these are: space, formfeed ('\f'), newline ('\n'), carriage 
120
+// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
121
+inline boolean isSpace(int c)
122
+{
123
+  return ( isspace (c) == 0 ? false : true);
124
+}
125
+
126
+
127
+// Checks for an uppercase letter.
128
+inline boolean isUpperCase(int c)
129
+{
130
+  return ( isupper (c) == 0 ? false : true);
131
+}
132
+
133
+
134
+// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 
135
+// 8 9 a b c d e f A B C D E F.
136
+inline boolean isHexadecimalDigit(int c)
137
+{
138
+  return ( isxdigit (c) == 0 ? false : true);
139
+}
140
+
141
+
142
+// Converts c to a 7-bit unsigned char value that fits into the 
143
+// ASCII character set, by clearing the high-order bits.
144
+inline int toAscii(int c)
145
+{
146
+  return toascii (c);
147
+}
148
+
149
+
150
+// Warning:
151
+// Many people will be unhappy if you use this function. 
152
+// This function will convert accented letters into random 
153
+// characters.
154
+
155
+// Converts the letter c to lower case, if possible.
156
+inline int toLowerCase(int c)
157
+{
158
+  return tolower (c);
159
+}
160
+
161
+
162
+// Converts the letter c to upper case, if possible.
163
+inline int toUpperCase(int c)
164
+{
165
+  return toupper (c);
166
+}
167
+
168
+#endif

+ 1
- 0
Marlin/Marlin/Boards/cores/arduino/WConstants.h Переглянути файл

1
+#include "wiring.h"

+ 249
- 0
Marlin/Marlin/Boards/cores/arduino/WInterrupts.c Переглянути файл

1
+/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
3
+/*
4
+  Part of the Wiring project - http://wiring.uniandes.edu.co
5
+
6
+  Copyright (c) 2004-05 Hernando Barragan
7
+
8
+  This library is free software; you can redistribute it and/or
9
+  modify it under the terms of the GNU Lesser General Public
10
+  License as published by the Free Software Foundation; either
11
+  version 2.1 of the License, or (at your option) any later version.
12
+
13
+  This library is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+  Lesser General Public License for more details.
17
+
18
+  You should have received a copy of the GNU Lesser General
19
+  Public License along with this library; if not, write to the
20
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
+  Boston, MA  02111-1307  USA
22
+  
23
+  Modified 24 November 2006 by David A. Mellis
24
+  Modified 1 August 2010 by Mark Sproul
25
+*/
26
+
27
+#include <inttypes.h>
28
+#include <avr/io.h>
29
+#include <avr/interrupt.h>
30
+#include <avr/pgmspace.h>
31
+#include <stdio.h>
32
+
33
+#include "WConstants.h"
34
+#include "wiring_private.h"
35
+
36
+volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
37
+// volatile static voidFuncPtr twiIntFunc;
38
+
39
+void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
40
+  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
41
+    intFunc[interruptNum] = userFunc;
42
+    
43
+    // Configure the interrupt mode (trigger on low input, any change, rising
44
+    // edge, or falling edge).  The mode constants were chosen to correspond
45
+    // to the configuration bits in the hardware register, so we simply shift
46
+    // the mode into place.
47
+      
48
+    // Enable the interrupt.
49
+      
50
+    switch (interruptNum) {
51
+#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
52
+    case 2:
53
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
54
+      EIMSK |= (1 << INT0);
55
+      break;
56
+    case 3:
57
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
58
+      EIMSK |= (1 << INT1);
59
+      break;
60
+    case 4:
61
+      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
62
+      EIMSK |= (1 << INT2);
63
+      break;
64
+    case 5:
65
+      EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
66
+      EIMSK |= (1 << INT3);
67
+      break;
68
+    case 0:
69
+      EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
70
+      EIMSK |= (1 << INT4);
71
+      break;
72
+    case 1:
73
+      EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
74
+      EIMSK |= (1 << INT5);
75
+      break;
76
+    case 6:
77
+      EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
78
+      EIMSK |= (1 << INT6);
79
+      break;
80
+    case 7:
81
+      EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
82
+      EIMSK |= (1 << INT7);
83
+      break;
84
+#else
85
+    case 0:
86
+    #if defined(EICRA) && defined(ISC00) && defined(EIMSK)
87
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
88
+      EIMSK |= (1 << INT0);
89
+    #elif defined(MCUCR) && defined(ISC00) && defined(GICR)
90
+      MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
91
+      GICR |= (1 << INT0);
92
+    #elif defined(MCUCR) && defined(ISC00) && defined(GIMSK)
93
+      MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
94
+      GIMSK |= (1 << INT0);
95
+    #else
96
+      #error attachInterrupt not finished for this CPU (case 0)
97
+    #endif
98
+      break;
99
+
100
+    case 1:
101
+    #if defined(EICRA) && defined(ISC10) && defined(ISC11) && defined(EIMSK)
102
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
103
+      EIMSK |= (1 << INT1);
104
+    #elif defined(MCUCR) && defined(ISC10) && defined(ISC11) && defined(GICR)
105
+      MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
106
+      GICR |= (1 << INT1);
107
+    #elif defined(MCUCR) && defined(ISC10) && defined(GIMSK) && defined(GIMSK)
108
+      MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
109
+      GIMSK |= (1 << INT1);
110
+    #else
111
+      #warning attachInterrupt may need some more work for this cpu (case 1)
112
+    #endif
113
+      break;
114
+#endif
115
+    }
116
+  }
117
+}
118
+
119
+void detachInterrupt(uint8_t interruptNum) {
120
+  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
121
+    // Disable the interrupt.  (We can't assume that interruptNum is equal
122
+    // to the number of the EIMSK bit to clear, as this isn't true on the 
123
+    // ATmega8.  There, INT0 is 6 and INT1 is 7.)
124
+    switch (interruptNum) {
125
+#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
126
+    case 2:
127
+      EIMSK &= ~(1 << INT0);
128
+      break;
129
+    case 3:
130
+      EIMSK &= ~(1 << INT1);
131
+      break;
132
+    case 4:
133
+      EIMSK &= ~(1 << INT2);
134
+      break;
135
+    case 5:
136
+      EIMSK &= ~(1 << INT3);
137
+      break;
138
+    case 0:
139
+      EIMSK &= ~(1 << INT4);
140
+      break;
141
+    case 1:
142
+      EIMSK &= ~(1 << INT5);
143
+      break;
144
+    case 6:
145
+      EIMSK &= ~(1 << INT6);
146
+      break;
147
+    case 7:
148
+      EIMSK &= ~(1 << INT7);
149
+      break;
150
+#else
151
+    case 0:
152
+    #if defined(EIMSK) && defined(INT0)
153
+      EIMSK &= ~(1 << INT0);
154
+    #elif defined(GICR) && defined(ISC00)
155
+      GICR &= ~(1 << INT0); // atmega32
156
+    #elif defined(GIMSK) && defined(INT0)
157
+      GIMSK &= ~(1 << INT0);
158
+    #else
159
+      #error detachInterrupt not finished for this cpu
160
+    #endif
161
+      break;
162
+
163
+    case 1:
164
+    #if defined(EIMSK) && defined(INT1)
165
+      EIMSK &= ~(1 << INT1);
166
+    #elif defined(GICR) && defined(INT1)
167
+      GICR &= ~(1 << INT1); // atmega32
168
+    #elif defined(GIMSK) && defined(INT1)
169
+      GIMSK &= ~(1 << INT1);
170
+    #else
171
+      #warning detachInterrupt may need some more work for this cpu (case 1)
172
+    #endif
173
+      break;
174
+#endif
175
+    }
176
+      
177
+    intFunc[interruptNum] = 0;
178
+  }
179
+}
180
+
181
+/*
182
+void attachInterruptTwi(void (*userFunc)(void) ) {
183
+  twiIntFunc = userFunc;
184
+}
185
+*/
186
+
187
+#if defined(EICRA) && defined(EICRB)
188
+
189
+SIGNAL(INT0_vect) {
190
+  if(intFunc[EXTERNAL_INT_2])
191
+    intFunc[EXTERNAL_INT_2]();
192
+}
193
+
194
+SIGNAL(INT1_vect) {
195
+  if(intFunc[EXTERNAL_INT_3])
196
+    intFunc[EXTERNAL_INT_3]();
197
+}
198
+
199
+SIGNAL(INT2_vect) {
200
+  if(intFunc[EXTERNAL_INT_4])
201
+    intFunc[EXTERNAL_INT_4]();
202
+}
203
+
204
+SIGNAL(INT3_vect) {
205
+  if(intFunc[EXTERNAL_INT_5])
206
+    intFunc[EXTERNAL_INT_5]();
207
+}
208
+
209
+SIGNAL(INT4_vect) {
210
+  if(intFunc[EXTERNAL_INT_0])
211
+    intFunc[EXTERNAL_INT_0]();
212
+}
213
+
214
+SIGNAL(INT5_vect) {
215
+  if(intFunc[EXTERNAL_INT_1])
216
+    intFunc[EXTERNAL_INT_1]();
217
+}
218
+
219
+SIGNAL(INT6_vect) {
220
+  if(intFunc[EXTERNAL_INT_6])
221
+    intFunc[EXTERNAL_INT_6]();
222
+}
223
+
224
+SIGNAL(INT7_vect) {
225
+  if(intFunc[EXTERNAL_INT_7])
226
+    intFunc[EXTERNAL_INT_7]();
227
+}
228
+
229
+#else
230
+
231
+SIGNAL(INT0_vect) {
232
+  if(intFunc[EXTERNAL_INT_0])
233
+    intFunc[EXTERNAL_INT_0]();
234
+}
235
+
236
+SIGNAL(INT1_vect) {
237
+  if(intFunc[EXTERNAL_INT_1])
238
+    intFunc[EXTERNAL_INT_1]();
239
+}
240
+
241
+#endif
242
+
243
+/*
244
+SIGNAL(SIG_2WIRE_SERIAL) {
245
+  if(twiIntFunc)
246
+    twiIntFunc();
247
+}
248
+*/
249
+

+ 60
- 0
Marlin/Marlin/Boards/cores/arduino/WMath.cpp Переглянути файл

1
+/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
3
+/*
4
+  Part of the Wiring project - http://wiring.org.co
5
+  Copyright (c) 2004-06 Hernando Barragan
6
+  Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/
7
+  
8
+  This library is free software; you can redistribute it and/or
9
+  modify it under the terms of the GNU Lesser General Public
10
+  License as published by the Free Software Foundation; either
11
+  version 2.1 of the License, or (at your option) any later version.
12
+
13
+  This library is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+  Lesser General Public License for more details.
17
+
18
+  You should have received a copy of the GNU Lesser General
19
+  Public License along with this library; if not, write to the
20
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
+  Boston, MA  02111-1307  USA
22
+  
23
+  $Id$
24
+*/
25
+
26
+extern "C" {
27
+  #include "stdlib.h"
28
+}
29
+
30
+void randomSeed(unsigned int seed)
31
+{
32
+  if (seed != 0) {
33
+    srandom(seed);
34
+  }
35
+}
36
+
37
+long random(long howbig)
38
+{
39
+  if (howbig == 0) {
40
+    return 0;
41
+  }
42
+  return random() % howbig;
43
+}
44
+
45
+long random(long howsmall, long howbig)
46
+{
47
+  if (howsmall >= howbig) {
48
+    return howsmall;
49
+  }
50
+  long diff = howbig - howsmall;
51
+  return random(diff) + howsmall;
52
+}
53
+
54
+long map(long x, long in_min, long in_max, long out_min, long out_max)
55
+{
56
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
57
+}
58
+
59
+unsigned int makeWord(unsigned int w) { return w; }
60
+unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; }

+ 63
- 0
Marlin/Marlin/Boards/cores/arduino/WProgram.h Переглянути файл

1
+#ifndef WProgram_h
2
+#define WProgram_h
3
+
4
+#include <stdlib.h>
5
+#include <string.h>
6
+#include <math.h>
7
+
8
+#include <avr/interrupt.h>
9
+
10
+#include "wiring.h"
11
+
12
+#ifdef __cplusplus
13
+#include "WCharacter.h"
14
+#include "WString.h"
15
+#include "HardwareSerial.h"
16
+
17
+uint16_t makeWord(uint16_t w);
18
+uint16_t makeWord(byte h, byte l);
19
+
20
+#define word(...) makeWord(__VA_ARGS__)
21
+
22
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
23
+
24
+void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
25
+void noTone(uint8_t _pin);
26
+
27
+// WMath prototypes
28
+long random(long);
29
+long random(long, long);
30
+void randomSeed(unsigned int);
31
+long map(long, long, long, long, long);
32
+
33
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
34
+const static uint8_t A0 = 54;
35
+const static uint8_t A1 = 55;
36
+const static uint8_t A2 = 56;
37
+const static uint8_t A3 = 57;
38
+const static uint8_t A4 = 58;
39
+const static uint8_t A5 = 59;
40
+const static uint8_t A6 = 60;
41
+const static uint8_t A7 = 61;
42
+const static uint8_t A8 = 62;
43
+const static uint8_t A9 = 63;
44
+const static uint8_t A10 = 64;
45
+const static uint8_t A11 = 65;
46
+const static uint8_t A12 = 66;
47
+const static uint8_t A13 = 67;
48
+const static uint8_t A14 = 68;
49
+const static uint8_t A15 = 69;
50
+#else
51
+const static uint8_t A0 = 14;
52
+const static uint8_t A1 = 15;
53
+const static uint8_t A2 = 16;
54
+const static uint8_t A3 = 17;
55
+const static uint8_t A4 = 18;
56
+const static uint8_t A5 = 19;
57
+const static uint8_t A6 = 20;
58
+const static uint8_t A7 = 21;
59
+#endif
60
+
61
+#endif
62
+
63
+#endif

+ 443
- 0
Marlin/Marlin/Boards/cores/arduino/WString.cpp Переглянути файл

1
+/*
2
+  WString.cpp - String library for Wiring & Arduino
3
+  Copyright (c) 2009-10 Hernando Barragan.  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
+#include <stdlib.h>
21
+#include "WProgram.h"
22
+#include "WString.h"
23
+
24
+
25
+String::String( const char *value )
26
+{
27
+  if ( value == NULL )
28
+    value = "";
29
+  getBuffer( _length = strlen( value ) );
30
+  if ( _buffer != NULL )
31
+    strcpy( _buffer, value );
32
+}
33
+
34
+String::String( const String &value )
35
+{
36
+  getBuffer( _length = value._length );
37
+  if ( _buffer != NULL )
38
+    strcpy( _buffer, value._buffer );
39
+}
40
+
41
+String::String( const char value )
42
+{
43
+  _length = 1;
44
+  getBuffer(1);
45
+  if ( _buffer != NULL ) {
46
+    _buffer[0] = value;
47
+    _buffer[1] = 0;
48
+  }
49
+}
50
+
51
+String::String( const unsigned char value )
52
+{
53
+  _length = 1;
54
+  getBuffer(1);
55
+  if ( _buffer != NULL) {
56
+    _buffer[0] = value;
57
+    _buffer[1] = 0;
58
+  }
59
+}
60
+
61
+String::String( const int value, const int base )
62
+{
63
+  char buf[33];   
64
+  itoa((signed long)value, buf, base);
65
+  getBuffer( _length = strlen(buf) );
66
+  if ( _buffer != NULL )
67
+    strcpy( _buffer, buf );
68
+}
69
+
70
+String::String( const unsigned int value, const int base )
71
+{
72
+  char buf[33];   
73
+  ultoa((unsigned long)value, buf, base);
74
+  getBuffer( _length = strlen(buf) );
75
+  if ( _buffer != NULL )
76
+    strcpy( _buffer, buf );
77
+}
78
+
79
+String::String( const long value, const int base )
80
+{
81
+  char buf[33];   
82
+  ltoa(value, buf, base);
83
+  getBuffer( _length = strlen(buf) );
84
+  if ( _buffer != NULL )
85
+    strcpy( _buffer, buf );
86
+}
87
+
88
+String::String( const unsigned long value, const int base )
89
+{
90
+  char buf[33];   
91
+  ultoa(value, buf, 10);
92
+  getBuffer( _length = strlen(buf) );
93
+  if ( _buffer != NULL )
94
+    strcpy( _buffer, buf );
95
+}
96
+
97
+char String::charAt( unsigned int loc ) const
98
+{
99
+  return operator[]( loc );
100
+}
101
+
102
+void String::setCharAt( unsigned int loc, const char aChar ) 
103
+{
104
+  if(_buffer == NULL) return;
105
+  if(_length > loc) {
106
+    _buffer[loc] = aChar;
107
+  }
108
+}
109
+
110
+int String::compareTo( const String &s2 ) const
111
+{
112
+  return strcmp( _buffer, s2._buffer );
113
+}
114
+
115
+const String & String::concat( const String &s2 )
116
+{
117
+  return (*this) += s2;
118
+}
119
+
120
+const String & String::operator=( const String &rhs )
121
+{
122
+  if ( this == &rhs )
123
+    return *this;
124
+
125
+  if ( rhs._length > _length )
126
+  {
127
+    free(_buffer);
128
+    getBuffer( rhs._length );
129
+  }
130
+  
131
+  if ( _buffer != NULL ) {
132
+    _length = rhs._length;
133
+    strcpy( _buffer, rhs._buffer );
134
+  }
135
+  return *this;
136
+}
137
+
138
+//const String & String::operator+=( const char aChar )
139
+//{
140
+//  if ( _length == _capacity )
141
+//    doubleBuffer();
142
+//
143
+//  _buffer[ _length++ ] = aChar;
144
+//  _buffer[ _length ] = '\0';
145
+//  return *this;
146
+//}
147
+
148
+const String & String::operator+=( const String &other )
149
+{
150
+  _length += other._length;
151
+  if ( _length > _capacity )
152
+  {
153
+    char *temp = (char *)realloc(_buffer, _length + 1);
154
+    if ( temp != NULL ) {
155
+      _buffer = temp;
156
+      _capacity = _length;
157
+    } else {
158
+      _length -= other._length;
159
+      return *this;
160
+    }
161
+  }
162
+  strcat( _buffer, other._buffer );
163
+  return *this;
164
+}
165
+
166
+
167
+int String::operator==( const String &rhs ) const
168
+{
169
+  return ( _length == rhs._length && strcmp( _buffer, rhs._buffer ) == 0 );
170
+}
171
+
172
+int String::operator!=( const String &rhs ) const
173
+{
174
+  return ( _length != rhs.length() || strcmp( _buffer, rhs._buffer ) != 0 );
175
+}
176
+
177
+int String::operator<( const String &rhs ) const
178
+{
179
+  return strcmp( _buffer, rhs._buffer ) < 0;
180
+}
181
+
182
+int String::operator>( const String &rhs ) const
183
+{
184
+  return strcmp( _buffer, rhs._buffer ) > 0;
185
+}
186
+
187
+int String::operator<=( const String &rhs ) const
188
+{
189
+  return strcmp( _buffer, rhs._buffer ) <= 0;
190
+}
191
+
192
+int String::operator>=( const String & rhs ) const
193
+{
194
+  return strcmp( _buffer, rhs._buffer ) >= 0;
195
+}
196
+
197
+char & String::operator[]( unsigned int index )
198
+{
199
+  static char dummy_writable_char;
200
+  if (index >= _length || !_buffer) {
201
+    dummy_writable_char = 0;
202
+    return dummy_writable_char;
203
+  }
204
+  return _buffer[ index ];
205
+}
206
+
207
+char String::operator[]( unsigned int index ) const
208
+{
209
+  // need to check for valid index, to do later
210
+  return _buffer[ index ];
211
+}
212
+
213
+boolean String::endsWith( const String &s2 ) const
214
+{
215
+  if ( _length < s2._length )
216
+    return 0;
217
+
218
+  return strcmp( &_buffer[ _length - s2._length], s2._buffer ) == 0;
219
+}
220
+
221
+boolean String::equals( const String &s2 ) const
222
+{
223
+  return ( _length == s2._length && strcmp( _buffer,s2._buffer ) == 0 );
224
+}
225
+
226
+boolean String::equalsIgnoreCase( const String &s2 ) const
227
+{
228
+  if ( this == &s2 )
229
+    return true; //1;
230
+  else if ( _length != s2._length )
231
+    return false; //0;
232
+
233
+  return strcmp(toLowerCase()._buffer, s2.toLowerCase()._buffer) == 0;
234
+}
235
+
236
+String String::replace( char findChar, char replaceChar )
237
+{
238
+  if ( _buffer == NULL ) return *this;
239
+  String theReturn = _buffer;
240
+  char* temp = theReturn._buffer;
241
+  while( (temp = strchr( temp, findChar )) != 0 )
242
+    *temp = replaceChar;
243
+
244
+  return theReturn;
245
+}
246
+
247
+String String::replace( const String& match, const String& replace )
248
+{
249
+  if ( _buffer == NULL ) return *this;
250
+  String temp = _buffer, newString;
251
+
252
+  int loc;
253
+  while ( (loc = temp.indexOf( match )) != -1 )
254
+  {
255
+    newString += temp.substring( 0, loc );
256
+    newString += replace;
257
+    temp = temp.substring( loc + match._length );
258
+  }
259
+  newString += temp;  
260
+  return newString;
261
+}
262
+
263
+int String::indexOf( char temp ) const
264
+{
265
+  return indexOf( temp, 0 );
266
+}
267
+
268
+int String::indexOf( char ch, unsigned int fromIndex ) const
269
+{
270
+  if ( fromIndex >= _length )
271
+    return -1;
272
+
273
+  const char* temp = strchr( &_buffer[fromIndex], ch );
274
+  if ( temp == NULL )
275
+    return -1;
276
+
277
+  return temp - _buffer;
278
+}
279
+
280
+int String::indexOf( const String &s2 ) const
281
+{
282
+  return indexOf( s2, 0 );
283
+}
284
+
285
+int String::indexOf( const String &s2, unsigned int fromIndex ) const
286
+{
287
+  if ( fromIndex >= _length )
288
+    return -1;
289
+
290
+  const char *theFind = strstr( &_buffer[ fromIndex ], s2._buffer );
291
+
292
+  if ( theFind == NULL )
293
+    return -1;
294
+
295
+  return theFind - _buffer; // pointer subtraction
296
+}
297
+
298
+int String::lastIndexOf( char theChar ) const
299
+{
300
+  return lastIndexOf( theChar, _length - 1 );
301
+}
302
+
303
+int String::lastIndexOf( char ch, unsigned int fromIndex ) const
304
+{
305
+  if ( fromIndex >= _length )
306
+    return -1;
307
+
308
+  char tempchar = _buffer[fromIndex + 1];
309
+  _buffer[fromIndex + 1] = '\0';
310
+  char* temp = strrchr( _buffer, ch );
311
+  _buffer[fromIndex + 1] = tempchar;
312
+
313
+  if ( temp == NULL )
314
+    return -1;
315
+
316
+  return temp - _buffer;
317
+}
318
+
319
+int String::lastIndexOf( const String &s2 ) const
320
+{
321
+  return lastIndexOf( s2, _length - s2._length );
322
+}
323
+
324
+int String::lastIndexOf( const String &s2, unsigned int fromIndex ) const
325
+{
326
+  // check for empty strings
327
+  if ( s2._length == 0 || s2._length - 1 > fromIndex || fromIndex >= _length )
328
+    return -1;
329
+
330
+  // matching first character
331
+  char temp = s2[ 0 ];
332
+
333
+  for ( int i = fromIndex; i >= 0; i-- )
334
+  {
335
+    if ( _buffer[ i ] == temp && (*this).substring( i, i + s2._length ).equals( s2 ) )
336
+    return i;
337
+  }
338
+  return -1;
339
+}
340
+
341
+boolean String::startsWith( const String &s2 ) const
342
+{
343
+  if ( _length < s2._length )
344
+    return 0;
345
+
346
+  return startsWith( s2, 0 );
347
+}
348
+
349
+boolean String::startsWith( const String &s2, unsigned int offset ) const
350
+{
351
+  if ( offset > _length - s2._length )
352
+    return 0;
353
+
354
+  return strncmp( &_buffer[offset], s2._buffer, s2._length ) == 0;
355
+}
356
+
357
+String String::substring( unsigned int left ) const
358
+{
359
+  return substring( left, _length );
360
+}
361
+
362
+String String::substring( unsigned int left, unsigned int right ) const
363
+{
364
+  if ( left > right )
365
+  {
366
+    int temp = right;
367
+    right = left;
368
+    left = temp;
369
+  }
370
+
371
+  if ( right > _length )
372
+  {
373
+    right = _length;
374
+  } 
375
+
376
+  char temp = _buffer[ right ];  // save the replaced character
377
+  _buffer[ right ] = '\0';	
378
+  String outPut = ( _buffer + left );  // pointer arithmetic
379
+  _buffer[ right ] = temp;  //restore character
380
+  return outPut;
381
+}
382
+
383
+String String::toLowerCase() const
384
+{
385
+  String temp = _buffer;
386
+
387
+  for ( unsigned int i = 0; i < _length; i++ )
388
+    temp._buffer[ i ] = (char)tolower( temp._buffer[ i ] );
389
+  return temp;
390
+}
391
+
392
+String String::toUpperCase() const
393
+{
394
+  String temp = _buffer;
395
+
396
+  for ( unsigned int i = 0; i < _length; i++ )
397
+    temp._buffer[ i ] = (char)toupper( temp._buffer[ i ] );
398
+  return temp;
399
+}
400
+
401
+String String::trim() const
402
+{
403
+  if ( _buffer == NULL ) return *this;
404
+  String temp = _buffer;
405
+  unsigned int i,j;
406
+
407
+  for ( i = 0; i < _length; i++ )
408
+  {
409
+    if ( !isspace(_buffer[i]) )
410
+      break;
411
+  }
412
+
413
+  for ( j = temp._length - 1; j > i; j-- )
414
+  {
415
+    if ( !isspace(_buffer[j]) )
416
+      break;
417
+  }
418
+
419
+  return temp.substring( i, j + 1);
420
+}
421
+
422
+void String::getBytes(unsigned char *buf, unsigned int bufsize)
423
+{
424
+  if (!bufsize || !buf) return;
425
+  unsigned int len = bufsize - 1;
426
+  if (len > _length) len = _length;
427
+  strncpy((char *)buf, _buffer, len);
428
+  buf[len] = 0;
429
+}
430
+
431
+void String::toCharArray(char *buf, unsigned int bufsize)
432
+{
433
+  if (!bufsize || !buf) return;
434
+  unsigned int len = bufsize - 1;
435
+  if (len > _length) len = _length;
436
+  strncpy(buf, _buffer, len);
437
+  buf[len] = 0;
438
+}
439
+
440
+
441
+long String::toInt() {
442
+  return atol(_buffer);
443
+}

+ 112
- 0
Marlin/Marlin/Boards/cores/arduino/WString.h Переглянути файл

1
+/*
2
+  WString.h - String library for Wiring & Arduino
3
+  Copyright (c) 2009-10 Hernando Barragan.  All right 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 String_h
21
+#define String_h
22
+
23
+//#include "WProgram.h"
24
+#include <stdlib.h>
25
+#include <string.h>
26
+#include <ctype.h>
27
+
28
+class String
29
+{
30
+  public:
31
+    // constructors
32
+    String( const char *value = "" );
33
+    String( const String &value );
34
+    String( const char );
35
+    String( const unsigned char );
36
+    String( const int, const int base=10);
37
+    String( const unsigned int, const int base=10 );
38
+    String( const long, const int base=10 );
39
+    String( const unsigned long, const int base=10 );
40
+    ~String() { free(_buffer); _length = _capacity = 0;}     //added _length = _capacity = 0;
41
+
42
+    // operators
43
+    const String & operator = ( const String &rhs );
44
+    const String & operator +=( const String &rhs );
45
+    //const String & operator +=( const char );
46
+    int operator ==( const String &rhs ) const;
47
+    int	operator !=( const String &rhs ) const;
48
+    int	operator < ( const String &rhs ) const;
49
+    int	operator > ( const String &rhs ) const;
50
+    int	operator <=( const String &rhs ) const;
51
+    int	operator >=( const String &rhs ) const;
52
+    char operator []( unsigned int index ) const;
53
+    char& operator []( unsigned int index );
54
+    //operator const char *() const { return _buffer; }
55
+    
56
+    // general methods
57
+    char charAt( unsigned int index ) const;
58
+    int	compareTo( const String &anotherString ) const;
59
+    unsigned char endsWith( const String &suffix ) const;
60
+    unsigned char equals( const String &anObject ) const;
61
+    unsigned char equalsIgnoreCase( const String &anotherString ) const;
62
+    int	indexOf( char ch ) const;
63
+    int	indexOf( char ch, unsigned int fromIndex ) const;
64
+    int	indexOf( const String &str ) const;
65
+    int	indexOf( const String &str, unsigned int fromIndex ) const;
66
+    int	lastIndexOf( char ch ) const;
67
+    int	lastIndexOf( char ch, unsigned int fromIndex ) const;
68
+    int	lastIndexOf( const String &str ) const;
69
+    int	lastIndexOf( const String &str, unsigned int fromIndex ) const;
70
+    const unsigned int length( ) const { return _length; }
71
+    void setCharAt(unsigned int index, const char ch);
72
+    unsigned char startsWith( const String &prefix ) const;
73
+    unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
74
+    String substring( unsigned int beginIndex ) const;
75
+    String substring( unsigned int beginIndex, unsigned int endIndex ) const;
76
+    String toLowerCase( ) const;
77
+    String toUpperCase( ) const;
78
+    String trim( ) const;
79
+    void getBytes(unsigned char *buf, unsigned int bufsize);
80
+    void toCharArray(char *buf, unsigned int bufsize);
81
+    long toInt( );
82
+    const String& concat( const String &str );
83
+    String replace( char oldChar, char newChar );
84
+    String replace( const String& match, const String& replace );
85
+    friend String operator + ( String lhs, const String &rhs );
86
+
87
+  protected:
88
+    char *_buffer;	     // the actual char array
89
+    unsigned int _capacity;  // the array length minus one (for the '\0')
90
+    unsigned int _length;    // the String length (not counting the '\0')
91
+
92
+    void getBuffer(unsigned int maxStrLen);
93
+
94
+  private:
95
+
96
+};
97
+
98
+// allocate buffer space
99
+inline void String::getBuffer(unsigned int maxStrLen)
100
+{
101
+  _capacity = maxStrLen;
102
+  _buffer = (char *) malloc(_capacity + 1);
103
+  if (_buffer == NULL) _length = _capacity = 0;
104
+}
105
+
106
+inline String operator+( String lhs, const String &rhs )
107
+{
108
+  return lhs += rhs;
109
+}
110
+
111
+
112
+#endif

+ 515
- 0
Marlin/Marlin/Boards/cores/arduino/binary.h Переглянути файл

1
+#ifndef Binary_h
2
+#define Binary_h
3
+
4
+#define B0 0
5
+#define B00 0
6
+#define B000 0
7
+#define B0000 0
8
+#define B00000 0
9
+#define B000000 0
10
+#define B0000000 0
11
+#define B00000000 0
12
+#define B1 1
13
+#define B01 1
14
+#define B001 1
15
+#define B0001 1
16
+#define B00001 1
17
+#define B000001 1
18
+#define B0000001 1
19
+#define B00000001 1
20
+#define B10 2
21
+#define B010 2
22
+#define B0010 2
23
+#define B00010 2
24
+#define B000010 2
25
+#define B0000010 2
26
+#define B00000010 2
27
+#define B11 3
28
+#define B011 3
29
+#define B0011 3
30
+#define B00011 3
31
+#define B000011 3
32
+#define B0000011 3
33
+#define B00000011 3
34
+#define B100 4
35
+#define B0100 4
36
+#define B00100 4
37
+#define B000100 4
38
+#define B0000100 4
39
+#define B00000100 4
40
+#define B101 5
41
+#define B0101 5
42
+#define B00101 5
43
+#define B000101 5
44
+#define B0000101 5
45
+#define B00000101 5
46
+#define B110 6
47
+#define B0110 6
48
+#define B00110 6
49
+#define B000110 6
50
+#define B0000110 6
51
+#define B00000110 6
52
+#define B111 7
53
+#define B0111 7
54
+#define B00111 7
55
+#define B000111 7
56
+#define B0000111 7
57
+#define B00000111 7
58
+#define B1000 8
59
+#define B01000 8
60
+#define B001000 8
61
+#define B0001000 8
62
+#define B00001000 8
63
+#define B1001 9
64
+#define B01001 9
65
+#define B001001 9
66
+#define B0001001 9
67
+#define B00001001 9
68
+#define B1010 10
69
+#define B01010 10
70
+#define B001010 10
71
+#define B0001010 10
72
+#define B00001010 10
73
+#define B1011 11
74
+#define B01011 11
75
+#define B001011 11
76
+#define B0001011 11
77
+#define B00001011 11
78
+#define B1100 12
79
+#define B01100 12
80
+#define B001100 12
81
+#define B0001100 12
82
+#define B00001100 12
83
+#define B1101 13
84
+#define B01101 13
85
+#define B001101 13
86
+#define B0001101 13
87
+#define B00001101 13
88
+#define B1110 14
89
+#define B01110 14
90
+#define B001110 14
91
+#define B0001110 14
92
+#define B00001110 14
93
+#define B1111 15
94
+#define B01111 15
95
+#define B001111 15
96
+#define B0001111 15
97
+#define B00001111 15
98
+#define B10000 16
99
+#define B010000 16
100
+#define B0010000 16
101
+#define B00010000 16
102
+#define B10001 17
103
+#define B010001 17
104
+#define B0010001 17
105
+#define B00010001 17
106
+#define B10010 18
107
+#define B010010 18
108
+#define B0010010 18
109
+#define B00010010 18
110
+#define B10011 19
111
+#define B010011 19
112
+#define B0010011 19
113
+#define B00010011 19
114
+#define B10100 20
115
+#define B010100 20
116
+#define B0010100 20
117
+#define B00010100 20
118
+#define B10101 21
119
+#define B010101 21
120
+#define B0010101 21
121
+#define B00010101 21
122
+#define B10110 22
123
+#define B010110 22
124
+#define B0010110 22
125
+#define B00010110 22
126
+#define B10111 23
127
+#define B010111 23
128
+#define B0010111 23
129
+#define B00010111 23
130
+#define B11000 24
131
+#define B011000 24
132
+#define B0011000 24
133
+#define B00011000 24
134
+#define B11001 25
135
+#define B011001 25
136
+#define B0011001 25
137
+#define B00011001 25
138
+#define B11010 26
139
+#define B011010 26
140
+#define B0011010 26
141
+#define B00011010 26
142
+#define B11011 27
143
+#define B011011 27
144
+#define B0011011 27
145
+#define B00011011 27
146
+#define B11100 28
147
+#define B011100 28
148
+#define B0011100 28
149
+#define B00011100 28
150
+#define B11101 29
151
+#define B011101 29
152
+#define B0011101 29
153
+#define B00011101 29
154
+#define B11110 30
155
+#define B011110 30
156
+#define B0011110 30
157
+#define B00011110 30
158
+#define B11111 31
159
+#define B011111 31
160
+#define B0011111 31
161
+#define B00011111 31
162
+#define B100000 32
163
+#define B0100000 32
164
+#define B00100000 32
165
+#define B100001 33
166
+#define B0100001 33
167
+#define B00100001 33
168
+#define B100010 34
169
+#define B0100010 34
170
+#define B00100010 34
171
+#define B100011 35
172
+#define B0100011 35
173
+#define B00100011 35
174
+#define B100100 36
175
+#define B0100100 36
176
+#define B00100100 36
177
+#define B100101 37
178
+#define B0100101 37
179
+#define B00100101 37
180
+#define B100110 38
181
+#define B0100110 38
182
+#define B00100110 38
183
+#define B100111 39
184
+#define B0100111 39
185
+#define B00100111 39
186
+#define B101000 40
187
+#define B0101000 40
188
+#define B00101000 40
189
+#define B101001 41
190
+#define B0101001 41
191
+#define B00101001 41
192
+#define B101010 42
193
+#define B0101010 42
194
+#define B00101010 42
195
+#define B101011 43
196
+#define B0101011 43
197
+#define B00101011 43
198
+#define B101100 44
199
+#define B0101100 44
200
+#define B00101100 44
201
+#define B101101 45
202
+#define B0101101 45
203
+#define B00101101 45
204
+#define B101110 46
205
+#define B0101110 46
206
+#define B00101110 46
207
+#define B101111 47
208
+#define B0101111 47
209
+#define B00101111 47
210
+#define B110000 48
211
+#define B0110000 48
212
+#define B00110000 48
213
+#define B110001 49
214
+#define B0110001 49
215
+#define B00110001 49
216
+#define B110010 50
217
+#define B0110010 50
218
+#define B00110010 50
219
+#define B110011 51
220
+#define B0110011 51
221
+#define B00110011 51
222
+#define B110100 52
223
+#define B0110100 52
224
+#define B00110100 52
225
+#define B110101 53
226
+#define B0110101 53
227
+#define B00110101 53
228
+#define B110110 54
229
+#define B0110110 54
230
+#define B00110110 54
231
+#define B110111 55
232
+#define B0110111 55
233
+#define B00110111 55
234
+#define B111000 56
235
+#define B0111000 56
236
+#define B00111000 56
237
+#define B111001 57
238
+#define B0111001 57
239
+#define B00111001 57
240
+#define B111010 58
241
+#define B0111010 58
242
+#define B00111010 58
243
+#define B111011 59
244
+#define B0111011 59
245
+#define B00111011 59
246
+#define B111100 60
247
+#define B0111100 60
248
+#define B00111100 60
249
+#define B111101 61
250
+#define B0111101 61
251
+#define B00111101 61
252
+#define B111110 62
253
+#define B0111110 62
254
+#define B00111110 62
255
+#define B111111 63
256
+#define B0111111 63
257
+#define B00111111 63
258
+#define B1000000 64
259
+#define B01000000 64
260
+#define B1000001 65
261
+#define B01000001 65
262
+#define B1000010 66
263
+#define B01000010 66
264
+#define B1000011 67
265
+#define B01000011 67
266
+#define B1000100 68
267
+#define B01000100 68
268
+#define B1000101 69
269
+#define B01000101 69
270
+#define B1000110 70
271
+#define B01000110 70
272
+#define B1000111 71
273
+#define B01000111 71
274
+#define B1001000 72
275
+#define B01001000 72
276
+#define B1001001 73
277
+#define B01001001 73
278
+#define B1001010 74
279
+#define B01001010 74
280
+#define B1001011 75
281
+#define B01001011 75
282
+#define B1001100 76
283
+#define B01001100 76
284
+#define B1001101 77
285
+#define B01001101 77
286
+#define B1001110 78
287
+#define B01001110 78
288
+#define B1001111 79
289
+#define B01001111 79
290
+#define B1010000 80
291
+#define B01010000 80
292
+#define B1010001 81
293
+#define B01010001 81
294
+#define B1010010 82
295
+#define B01010010 82
296
+#define B1010011 83
297
+#define B01010011 83
298
+#define B1010100 84
299
+#define B01010100 84
300
+#define B1010101 85
301
+#define B01010101 85
302
+#define B1010110 86
303
+#define B01010110 86
304
+#define B1010111 87
305
+#define B01010111 87
306
+#define B1011000 88
307
+#define B01011000 88
308
+#define B1011001 89
309
+#define B01011001 89
310
+#define B1011010 90
311
+#define B01011010 90
312
+#define B1011011 91
313
+#define B01011011 91
314
+#define B1011100 92
315
+#define B01011100 92
316
+#define B1011101 93
317
+#define B01011101 93
318
+#define B1011110 94
319
+#define B01011110 94
320
+#define B1011111 95
321
+#define B01011111 95
322
+#define B1100000 96
323
+#define B01100000 96
324
+#define B1100001 97
325
+#define B01100001 97
326
+#define B1100010 98
327
+#define B01100010 98
328
+#define B1100011 99
329
+#define B01100011 99
330
+#define B1100100 100
331
+#define B01100100 100
332
+#define B1100101 101
333
+#define B01100101 101
334
+#define B1100110 102
335
+#define B01100110 102
336
+#define B1100111 103
337
+#define B01100111 103
338
+#define B1101000 104
339
+#define B01101000 104
340
+#define B1101001 105
341
+#define B01101001 105
342
+#define B1101010 106
343
+#define B01101010 106
344
+#define B1101011 107
345
+#define B01101011 107
346
+#define B1101100 108
347
+#define B01101100 108
348
+#define B1101101 109
349
+#define B01101101 109
350
+#define B1101110 110
351
+#define B01101110 110
352
+#define B1101111 111
353
+#define B01101111 111
354
+#define B1110000 112
355
+#define B01110000 112
356
+#define B1110001 113
357
+#define B01110001 113
358
+#define B1110010 114
359
+#define B01110010 114
360
+#define B1110011 115
361
+#define B01110011 115
362
+#define B1110100 116
363
+#define B01110100 116
364
+#define B1110101 117
365
+#define B01110101 117
366
+#define B1110110 118
367
+#define B01110110 118
368
+#define B1110111 119
369
+#define B01110111 119
370
+#define B1111000 120
371
+#define B01111000 120
372
+#define B1111001 121
373
+#define B01111001 121
374
+#define B1111010 122
375
+#define B01111010 122
376
+#define B1111011 123
377
+#define B01111011 123
378
+#define B1111100 124
379
+#define B01111100 124
380
+#define B1111101 125
381
+#define B01111101 125
382
+#define B1111110 126
383
+#define B01111110 126
384
+#define B1111111 127
385
+#define B01111111 127
386
+#define B10000000 128
387
+#define B10000001 129
388
+#define B10000010 130
389
+#define B10000011 131
390
+#define B10000100 132
391
+#define B10000101 133
392
+#define B10000110 134
393
+#define B10000111 135
394
+#define B10001000 136
395
+#define B10001001 137
396
+#define B10001010 138
397
+#define B10001011 139
398
+#define B10001100 140
399
+#define B10001101 141
400
+#define B10001110 142
401
+#define B10001111 143
402
+#define B10010000 144
403
+#define B10010001 145
404
+#define B10010010 146
405
+#define B10010011 147
406
+#define B10010100 148
407
+#define B10010101 149
408
+#define B10010110 150
409
+#define B10010111 151
410
+#define B10011000 152
411
+#define B10011001 153
412
+#define B10011010 154
413
+#define B10011011 155
414
+#define B10011100 156
415
+#define B10011101 157
416
+#define B10011110 158
417
+#define B10011111 159
418
+#define B10100000 160
419
+#define B10100001 161
420
+#define B10100010 162
421
+#define B10100011 163
422
+#define B10100100 164
423
+#define B10100101 165
424
+#define B10100110 166
425
+#define B10100111 167
426
+#define B10101000 168
427
+#define B10101001 169
428
+#define B10101010 170
429
+#define B10101011 171
430
+#define B10101100 172
431
+#define B10101101 173
432
+#define B10101110 174
433
+#define B10101111 175
434
+#define B10110000 176
435
+#define B10110001 177
436
+#define B10110010 178
437
+#define B10110011 179
438
+#define B10110100 180
439
+#define B10110101 181
440
+#define B10110110 182
441
+#define B10110111 183
442
+#define B10111000 184
443
+#define B10111001 185
444
+#define B10111010 186
445
+#define B10111011 187
446
+#define B10111100 188
447
+#define B10111101 189
448
+#define B10111110 190
449
+#define B10111111 191
450
+#define B11000000 192
451
+#define B11000001 193
452
+#define B11000010 194
453
+#define B11000011 195
454
+#define B11000100 196
455
+#define B11000101 197
456
+#define B11000110 198
457
+#define B11000111 199
458
+#define B11001000 200
459
+#define B11001001 201
460
+#define B11001010 202
461
+#define B11001011 203
462
+#define B11001100 204
463
+#define B11001101 205
464
+#define B11001110 206
465
+#define B11001111 207
466
+#define B11010000 208
467
+#define B11010001 209
468
+#define B11010010 210
469
+#define B11010011 211
470
+#define B11010100 212
471
+#define B11010101 213
472
+#define B11010110 214
473
+#define B11010111 215
474
+#define B11011000 216
475
+#define B11011001 217
476
+#define B11011010 218
477
+#define B11011011 219
478
+#define B11011100 220
479
+#define B11011101 221
480
+#define B11011110 222
481
+#define B11011111 223
482
+#define B11100000 224
483
+#define B11100001 225
484
+#define B11100010 226
485
+#define B11100011 227
486
+#define B11100100 228
487
+#define B11100101 229
488
+#define B11100110 230
489
+#define B11100111 231
490
+#define B11101000 232
491
+#define B11101001 233
492
+#define B11101010 234
493
+#define B11101011 235
494
+#define B11101100 236
495
+#define B11101101 237
496
+#define B11101110 238
497
+#define B11101111 239
498
+#define B11110000 240
499
+#define B11110001 241
500
+#define B11110010 242
501
+#define B11110011 243
502
+#define B11110100 244
503
+#define B11110101 245
504
+#define B11110110 246
505
+#define B11110111 247
506
+#define B11111000 248
507
+#define B11111001 249
508
+#define B11111010 250
509
+#define B11111011 251
510
+#define B11111100 252
511
+#define B11111101 253
512
+#define B11111110 254
513
+#define B11111111 255
514
+
515
+#endif

+ 14
- 0
Marlin/Marlin/Boards/cores/arduino/main.cpp Переглянути файл

1
+#include <WProgram.h>
2
+
3
+int main(void)
4
+{
5
+	init();
6
+
7
+	setup();
8
+    
9
+	for (;;)
10
+		loop();
11
+        
12
+	return 0;
13
+}
14
+

+ 200
- 0
Marlin/Marlin/Boards/cores/arduino/pins_arduino.c Переглянути файл

1
+/*
2
+  pins_arduino.c - pin definitions for the Arduino board
3
+  Part of Arduino / Wiring Lite
4
+
5
+  Copyright (c) 2005 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: pins_arduino.c 254 2007-04-20 23:17:38Z mellis $
23
+*/
24
+
25
+#include <avr/io.h>
26
+#include "wiring_private.h"
27
+#include "pins_arduino.h"
28
+
29
+// On the Sanguino board, digital pins are also used
30
+// for the analog output (software PWM).  Analog input
31
+// pins are a separate set.
32
+
33
+// ATMEL ATMEGA644P / SANGUINO
34
+//
35
+//                   +---\/---+
36
+//  INT0 (D 0) PB0  1|        |40  PA0 (AI 0 / D31)
37
+//  INT1 (D 1) PB1  2|        |39  PA1 (AI 1 / D30)
38
+//  INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D29)
39
+//   PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D28)
40
+//   PWM (D 4) PB4  5|        |36  PA4 (AI 4 / D27)
41
+//  MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D26)
42
+//  MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D25)
43
+//   SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D24)
44
+//             RST  9|        |32  AREF
45
+//             VCC 10|        |31  GND 
46
+//             GND 11|        |30  AVCC
47
+//           XTAL2 12|        |29  PC7 (D 23)
48
+//           XTAL1 13|        |28  PC6 (D 22)
49
+//  RX0 (D 8)  PD0 14|        |27  PC5 (D 21) TDI
50
+//  TX0 (D 9)  PD1 15|        |26  PC4 (D 20) TDO
51
+//  RX1 (D 10) PD2 16|        |25  PC3 (D 19) TMS
52
+//  TX1 (D 11) PD3 17|        |24  PC2 (D 18) TCK
53
+//  PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA
54
+//  PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL
55
+//  PWM (D 14) PD6 20|        |21  PD7 (D 15) PWM
56
+//                   +--------+
57
+//
58
+
59
+#define PA 1
60
+#define PB 2
61
+#define PC 3
62
+#define PD 4
63
+
64
+// these arrays map port names (e.g. port B) to the
65
+// appropriate addresses for various functions (e.g. reading
66
+// and writing)
67
+const uint8_t PROGMEM port_to_mode_PGM[] =
68
+{
69
+	NOT_A_PORT,
70
+	(uint8_t) (uint16_t) &DDRA,
71
+	(uint8_t) (uint16_t) &DDRB,
72
+	(uint8_t) (uint16_t) &DDRC,
73
+	(uint8_t) (uint16_t) &DDRD,
74
+};
75
+
76
+const uint8_t PROGMEM port_to_output_PGM[] =
77
+{
78
+	NOT_A_PORT,
79
+	(uint8_t) (uint16_t) &PORTA,
80
+	(uint8_t) (uint16_t) &PORTB,
81
+	(uint8_t) (uint16_t) &PORTC,
82
+	(uint8_t) (uint16_t) &PORTD,
83
+};
84
+
85
+const uint8_t PROGMEM port_to_input_PGM[] =
86
+{
87
+	NOT_A_PORT,
88
+	(uint8_t) (uint16_t) &PINA,
89
+	(uint8_t) (uint16_t) &PINB,
90
+	(uint8_t) (uint16_t) &PINC,
91
+	(uint8_t) (uint16_t) &PIND,
92
+};
93
+
94
+const uint8_t PROGMEM digital_pin_to_port_PGM[] =
95
+{
96
+	PB, /* 0 */
97
+	PB,
98
+	PB,
99
+	PB,
100
+	PB,
101
+	PB,
102
+	PB,
103
+	PB,
104
+	PD, /* 8 */
105
+	PD,
106
+	PD,
107
+	PD,
108
+	PD,
109
+	PD,
110
+	PD,
111
+	PD,
112
+	PC, /* 16 */
113
+	PC,
114
+	PC,
115
+	PC,
116
+	PC,
117
+	PC,
118
+   	PC,
119
+	PC,
120
+	PA, /* 24 */
121
+	PA,
122
+	PA,
123
+	PA,
124
+	PA,
125
+	PA,
126
+	PA,
127
+	PA  /* 31 */
128
+};
129
+
130
+const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
131
+{
132
+	_BV(0), /* 0, port B */
133
+	_BV(1),
134
+	_BV(2),
135
+	_BV(3),
136
+	_BV(4),
137
+	_BV(5),
138
+	_BV(6),
139
+	_BV(7),
140
+	_BV(0), /* 8, port D */
141
+	_BV(1),
142
+	_BV(2),
143
+	_BV(3),
144
+	_BV(4),
145
+	_BV(5),
146
+	_BV(6),
147
+	_BV(7),
148
+	_BV(0), /* 16, port C */
149
+	_BV(1),
150
+	_BV(2),
151
+	_BV(3),
152
+	_BV(4),
153
+	_BV(5),
154
+	_BV(6),
155
+	_BV(7),
156
+	_BV(7), /* 24, port A */
157
+	_BV(6),
158
+	_BV(5),
159
+	_BV(4),
160
+	_BV(3),
161
+	_BV(2),
162
+	_BV(1),
163
+	_BV(0)
164
+};
165
+
166
+const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
167
+{
168
+	NOT_ON_TIMER, 	/* 0  - PB0 */
169
+	NOT_ON_TIMER, 	/* 1  - PB1 */
170
+	NOT_ON_TIMER, 	/* 2  - PB2 */
171
+	TIMER0A,     	/* 3  - PB3 */
172
+	TIMER0B, 		/* 4  - PB4 */
173
+	NOT_ON_TIMER, 	/* 5  - PB5 */
174
+	NOT_ON_TIMER, 	/* 6  - PB6 */
175
+	NOT_ON_TIMER,	/* 7  - PB7 */
176
+	NOT_ON_TIMER, 	/* 8  - PD0 */
177
+	NOT_ON_TIMER, 	/* 9  - PD1 */
178
+	NOT_ON_TIMER, 	/* 10 - PD2 */
179
+	NOT_ON_TIMER, 	/* 11 - PD3 */
180
+	TIMER1B,     	/* 12 - PD4 */
181
+	TIMER1A,     	/* 13 - PD5 */
182
+	TIMER2B,     	/* 14 - PD6 */
183
+	TIMER2A,     	/* 15 - PD7 */
184
+	NOT_ON_TIMER, 	/* 16 - PC0 */
185
+	NOT_ON_TIMER,   /* 17 - PC1 */
186
+	NOT_ON_TIMER,   /* 18 - PC2 */
187
+	NOT_ON_TIMER,   /* 19 - PC3 */
188
+	NOT_ON_TIMER,   /* 20 - PC4 */
189
+	NOT_ON_TIMER,   /* 21 - PC5 */
190
+	NOT_ON_TIMER,   /* 22 - PC6 */
191
+	NOT_ON_TIMER,   /* 23 - PC7 */
192
+	NOT_ON_TIMER,   /* 24 - PA0 */
193
+	NOT_ON_TIMER,   /* 25 - PA1 */
194
+	NOT_ON_TIMER,   /* 26 - PA2 */
195
+	NOT_ON_TIMER,   /* 27 - PA3 */
196
+	NOT_ON_TIMER,   /* 28 - PA4 */
197
+	NOT_ON_TIMER,   /* 29 - PA5 */
198
+	NOT_ON_TIMER,   /* 30 - PA6 */
199
+	NOT_ON_TIMER   /* 31 - PA7 */
200
+};

+ 65
- 0
Marlin/Marlin/Boards/cores/arduino/pins_arduino.h Переглянути файл

1
+/*
2
+  pins_arduino.h - Pin definition functions for Arduino
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2007 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
23
+*/
24
+
25
+#ifndef Pins_Arduino_h
26
+#define Pins_Arduino_h
27
+
28
+#include <avr/pgmspace.h>
29
+
30
+#define NOT_A_PIN 0
31
+#define NOT_A_PORT 0
32
+
33
+#define NOT_ON_TIMER 0
34
+#define TIMER0A 1
35
+#define TIMER0B 2
36
+#define TIMER1A 3
37
+#define TIMER1B 4
38
+#define TIMER2  5
39
+#define TIMER2A 6
40
+#define TIMER2B 7
41
+
42
+extern const uint8_t PROGMEM port_to_mode_PGM[];
43
+extern const uint8_t PROGMEM port_to_input_PGM[];
44
+extern const uint8_t PROGMEM port_to_output_PGM[];
45
+
46
+extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
47
+extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
48
+extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
49
+
50
+extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
51
+
52
+// Get the bit location within the hardware port of the given virtual pin.
53
+// This comes from the pins_*.c file for the active board configuration.
54
+// 
55
+// These perform slightly better as macros compared to inline functions
56
+//
57
+#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
58
+#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
59
+#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
60
+#define analogInPinToBit(P) (P)
61
+#define portOutputRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_output_PGM + (P))) )
62
+#define portInputRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_input_PGM + (P))) )
63
+#define portModeRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_mode_PGM + (P))) )
64
+
65
+#endif

+ 289
- 0
Marlin/Marlin/Boards/cores/arduino/wiring.c Переглянути файл

1
+/*
2
+  wiring.c - Partial implementation of the Wiring API for the ATmega8.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id$
23
+*/
24
+
25
+#include "wiring_private.h"
26
+
27
+// the prescaler is set so that timer0 ticks every 64 clock cycles, and the
28
+// the overflow handler is called every 256 ticks.
29
+#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256))
30
+
31
+// the whole number of milliseconds per timer0 overflow
32
+#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000)
33
+
34
+// the fractional number of milliseconds per timer0 overflow. we shift right
35
+// by three to fit these numbers into a byte. (for the clock speeds we care
36
+// about - 8 and 16 MHz - this doesn't lose precision.)
37
+#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3)
38
+#define FRACT_MAX (1000 >> 3)
39
+
40
+volatile unsigned long timer0_overflow_count = 0;
41
+volatile unsigned long timer0_millis = 0;
42
+static unsigned char timer0_fract = 0;
43
+
44
+SIGNAL(TIMER0_OVF_vect)
45
+{
46
+	// copy these to local variables so they can be stored in registers
47
+	// (volatile variables must be read from memory on every access)
48
+	unsigned long m = timer0_millis;
49
+	unsigned char f = timer0_fract;
50
+
51
+	m += MILLIS_INC;
52
+	f += FRACT_INC;
53
+	if (f >= FRACT_MAX) {
54
+		f -= FRACT_MAX;
55
+		m += 1;
56
+	}
57
+
58
+	timer0_fract = f;
59
+	timer0_millis = m;
60
+	timer0_overflow_count++;
61
+}
62
+
63
+unsigned long millis()
64
+{
65
+	unsigned long m;
66
+	uint8_t oldSREG = SREG;
67
+
68
+	// disable interrupts while we read timer0_millis or we might get an
69
+	// inconsistent value (e.g. in the middle of a write to timer0_millis)
70
+	cli();
71
+	m = timer0_millis;
72
+	SREG = oldSREG;
73
+
74
+	return m;
75
+}
76
+
77
+unsigned long micros() {
78
+	unsigned long m;
79
+	uint8_t oldSREG = SREG, t;
80
+	
81
+	cli();
82
+	m = timer0_overflow_count;
83
+#if defined(TCNT0)
84
+	t = TCNT0;
85
+#elif defined(TCNT0L)
86
+	t = TCNT0L;
87
+#else
88
+	#error TIMER 0 not defined
89
+#endif
90
+
91
+  
92
+#ifdef TIFR0
93
+	if ((TIFR0 & _BV(TOV0)) && (t < 255))
94
+		m++;
95
+#else
96
+	if ((TIFR & _BV(TOV0)) && (t < 255))
97
+		m++;
98
+#endif
99
+
100
+	SREG = oldSREG;
101
+	
102
+	return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
103
+}
104
+
105
+void delay(unsigned long ms)
106
+{
107
+	uint16_t start = (uint16_t)micros();
108
+
109
+	while (ms > 0) {
110
+		if (((uint16_t)micros() - start) >= 1000) {
111
+			ms--;
112
+			start += 1000;
113
+		}
114
+	}
115
+}
116
+
117
+/* Delay for the given number of microseconds.  Assumes a 8 or 16 MHz clock. */
118
+void delayMicroseconds(unsigned int us)
119
+{
120
+	// calling avrlib's delay_us() function with low values (e.g. 1 or
121
+	// 2 microseconds) gives delays longer than desired.
122
+	//delay_us(us);
123
+
124
+#if F_CPU >= 16000000L
125
+	// for the 16 MHz clock on most Arduino boards
126
+
127
+	// for a one-microsecond delay, simply return.  the overhead
128
+	// of the function call yields a delay of approximately 1 1/8 us.
129
+	if (--us == 0)
130
+		return;
131
+
132
+	// the following loop takes a quarter of a microsecond (4 cycles)
133
+	// per iteration, so execute it four times for each microsecond of
134
+	// delay requested.
135
+	us <<= 2;
136
+
137
+	// account for the time taken in the preceeding commands.
138
+	us -= 2;
139
+#else
140
+	// for the 8 MHz internal clock on the ATmega168
141
+
142
+	// for a one- or two-microsecond delay, simply return.  the overhead of
143
+	// the function calls takes more than two microseconds.  can't just
144
+	// subtract two, since us is unsigned; we'd overflow.
145
+	if (--us == 0)
146
+		return;
147
+	if (--us == 0)
148
+		return;
149
+
150
+	// the following loop takes half of a microsecond (4 cycles)
151
+	// per iteration, so execute it twice for each microsecond of
152
+	// delay requested.
153
+	us <<= 1;
154
+    
155
+	// partially compensate for the time taken by the preceeding commands.
156
+	// we can't subtract any more than this or we'd overflow w/ small delays.
157
+	us--;
158
+#endif
159
+
160
+	// busy wait
161
+	__asm__ __volatile__ (
162
+		"1: sbiw %0,1" "\n\t" // 2 cycles
163
+		"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
164
+	);
165
+}
166
+
167
+void init()
168
+{
169
+	// this needs to be called before setup() or some functions won't
170
+	// work there
171
+	sei();
172
+	
173
+	// on the ATmega168, timer 0 is also used for fast hardware pwm
174
+	// (using phase-correct PWM would mean that timer 0 overflowed half as often
175
+	// resulting in different millis() behavior on the ATmega8 and ATmega168)
176
+#if defined(TCCR0A) && defined(WGM01)
177
+	sbi(TCCR0A, WGM01);
178
+	sbi(TCCR0A, WGM00);
179
+#endif  
180
+
181
+	// set timer 0 prescale factor to 64
182
+#if defined(__AVR_ATmega128__)
183
+	// CPU specific: different values for the ATmega128
184
+	sbi(TCCR0, CS02);
185
+#elif defined(TCCR0) && defined(CS01) && defined(CS00)
186
+	// this combination is for the standard atmega8
187
+	sbi(TCCR0, CS01);
188
+	sbi(TCCR0, CS00);
189
+#elif defined(TCCR0B) && defined(CS01) && defined(CS00)
190
+	// this combination is for the standard 168/328/1280/2560
191
+	sbi(TCCR0B, CS01);
192
+	sbi(TCCR0B, CS00);
193
+#elif defined(TCCR0A) && defined(CS01) && defined(CS00)
194
+	// this combination is for the __AVR_ATmega645__ series
195
+	sbi(TCCR0A, CS01);
196
+	sbi(TCCR0A, CS00);
197
+#else
198
+	#error Timer 0 prescale factor 64 not set correctly
199
+#endif
200
+
201
+	// enable timer 0 overflow interrupt
202
+#if defined(TIMSK) && defined(TOIE0)
203
+	sbi(TIMSK, TOIE0);
204
+#elif defined(TIMSK0) && defined(TOIE0)
205
+	sbi(TIMSK0, TOIE0);
206
+#else
207
+	#error	Timer 0 overflow interrupt not set correctly
208
+#endif
209
+
210
+	// timers 1 and 2 are used for phase-correct hardware pwm
211
+	// this is better for motors as it ensures an even waveform
212
+	// note, however, that fast pwm mode can achieve a frequency of up
213
+	// 8 MHz (with a 16 MHz clock) at 50% duty cycle
214
+
215
+	TCCR1B = 0;
216
+
217
+	// set timer 1 prescale factor to 64
218
+#if defined(TCCR1B) && defined(CS11) && defined(CS10)
219
+	sbi(TCCR1B, CS11);
220
+	sbi(TCCR1B, CS10);
221
+#elif defined(TCCR1) && defined(CS11) && defined(CS10)
222
+	sbi(TCCR1, CS11);
223
+	sbi(TCCR1, CS10);
224
+#endif
225
+	// put timer 1 in 8-bit phase correct pwm mode
226
+#if defined(TCCR1A) && defined(WGM10)
227
+	sbi(TCCR1A, WGM10);
228
+#elif defined(TCCR1)
229
+	#warning this needs to be finished
230
+#endif
231
+
232
+	// set timer 2 prescale factor to 64
233
+#if defined(TCCR2) && defined(CS22)
234
+	sbi(TCCR2, CS22);
235
+#elif defined(TCCR2B) && defined(CS22)
236
+	sbi(TCCR2B, CS22);
237
+#else
238
+	#warning Timer 2 not finished (may not be present on this CPU)
239
+#endif
240
+
241
+	// configure timer 2 for phase correct pwm (8-bit)
242
+#if defined(TCCR2) && defined(WGM20)
243
+	sbi(TCCR2, WGM20);
244
+#elif defined(TCCR2A) && defined(WGM20)
245
+	sbi(TCCR2A, WGM20);
246
+#else
247
+	#warning Timer 2 not finished (may not be present on this CPU)
248
+#endif
249
+
250
+#if defined(TCCR3B) && defined(CS31) && defined(WGM30)
251
+	sbi(TCCR3B, CS31);		// set timer 3 prescale factor to 64
252
+	sbi(TCCR3B, CS30);
253
+	sbi(TCCR3A, WGM30);		// put timer 3 in 8-bit phase correct pwm mode
254
+#endif
255
+	
256
+#if defined(TCCR4B) && defined(CS41) && defined(WGM40)
257
+	sbi(TCCR4B, CS41);		// set timer 4 prescale factor to 64
258
+	sbi(TCCR4B, CS40);
259
+	sbi(TCCR4A, WGM40);		// put timer 4 in 8-bit phase correct pwm mode
260
+#endif
261
+
262
+#if defined(TCCR5B) && defined(CS51) && defined(WGM50)
263
+	sbi(TCCR5B, CS51);		// set timer 5 prescale factor to 64
264
+	sbi(TCCR5B, CS50);
265
+	sbi(TCCR5A, WGM50);		// put timer 5 in 8-bit phase correct pwm mode
266
+#endif
267
+
268
+#if defined(ADCSRA)
269
+	// set a2d prescale factor to 128
270
+	// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
271
+	// XXX: this will not work properly for other clock speeds, and
272
+	// this code should use F_CPU to determine the prescale factor.
273
+	sbi(ADCSRA, ADPS2);
274
+	sbi(ADCSRA, ADPS1);
275
+	sbi(ADCSRA, ADPS0);
276
+
277
+	// enable a2d conversions
278
+	sbi(ADCSRA, ADEN);
279
+#endif
280
+
281
+	// the bootloader connects pins 0 and 1 to the USART; disconnect them
282
+	// here so they can be used as normal digital i/o; they will be
283
+	// reconnected in Serial.begin()
284
+#if defined(UCSRB)
285
+	UCSRB = 0;
286
+#elif defined(UCSR0B)
287
+	UCSR0B = 0;
288
+#endif
289
+}

+ 136
- 0
Marlin/Marlin/Boards/cores/arduino/wiring.h Переглянути файл

1
+/*
2
+  wiring.h - Partial implementation of the Wiring API for the ATmega8.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id$
23
+*/
24
+
25
+#ifndef Wiring_h
26
+#define Wiring_h
27
+
28
+#include <math.h>
29
+#include <avr/io.h>
30
+#include <stdlib.h>
31
+#include "binary.h"
32
+
33
+#ifdef __cplusplus
34
+extern "C"{
35
+#endif
36
+
37
+#define HIGH 0x1
38
+#define LOW  0x0
39
+
40
+#define INPUT 0x0
41
+#define OUTPUT 0x1
42
+
43
+#define true 0x1
44
+#define false 0x0
45
+
46
+#define PI 3.1415926535897932384626433832795
47
+#define HALF_PI 1.5707963267948966192313216916398
48
+#define TWO_PI 6.283185307179586476925286766559
49
+#define DEG_TO_RAD 0.017453292519943295769236907684886
50
+#define RAD_TO_DEG 57.295779513082320876798154814105
51
+
52
+#define SERIAL  0x0
53
+#define DISPLAY 0x1
54
+
55
+#define LSBFIRST 0
56
+#define MSBFIRST 1
57
+
58
+#define CHANGE 1
59
+#define FALLING 2
60
+#define RISING 3
61
+
62
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
63
+#define INTERNAL1V1 2
64
+#define INTERNAL2V56 3
65
+#else
66
+#define INTERNAL 3
67
+#endif
68
+#define DEFAULT 1
69
+#define EXTERNAL 0
70
+
71
+// undefine stdlib's abs if encountered
72
+#ifdef abs
73
+#undef abs
74
+#endif
75
+
76
+#define min(a,b) ((a)<(b)?(a):(b))
77
+#define max(a,b) ((a)>(b)?(a):(b))
78
+#define abs(x) ((x)>0?(x):-(x))
79
+#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
80
+#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
81
+#define radians(deg) ((deg)*DEG_TO_RAD)
82
+#define degrees(rad) ((rad)*RAD_TO_DEG)
83
+#define sq(x) ((x)*(x))
84
+
85
+#define interrupts() sei()
86
+#define noInterrupts() cli()
87
+
88
+#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
89
+#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
90
+#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
91
+
92
+#define lowByte(w) ((uint8_t) ((w) & 0xff))
93
+#define highByte(w) ((uint8_t) ((w) >> 8))
94
+
95
+#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
96
+#define bitSet(value, bit) ((value) |= (1UL << (bit)))
97
+#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
98
+#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
99
+
100
+
101
+typedef unsigned int word;
102
+
103
+#define bit(b) (1UL << (b))
104
+
105
+typedef uint8_t boolean;
106
+typedef uint8_t byte;
107
+
108
+void init(void);
109
+
110
+void pinMode(uint8_t, uint8_t);
111
+void digitalWrite(uint8_t, uint8_t);
112
+int digitalRead(uint8_t);
113
+int analogRead(uint8_t);
114
+void analogReference(uint8_t mode);
115
+void analogWrite(uint8_t, int);
116
+
117
+unsigned long millis(void);
118
+unsigned long micros(void);
119
+void delay(unsigned long);
120
+void delayMicroseconds(unsigned int us);
121
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
122
+
123
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
124
+uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
125
+
126
+void attachInterrupt(uint8_t, void (*)(void), int mode);
127
+void detachInterrupt(uint8_t);
128
+
129
+void setup(void);
130
+void loop(void);
131
+
132
+#ifdef __cplusplus
133
+} // extern "C"
134
+#endif
135
+
136
+#endif

+ 259
- 0
Marlin/Marlin/Boards/cores/arduino/wiring_analog.c Переглянути файл

1
+/*
2
+  wiring_analog.c - analog input and output
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  Modified 28 September 2010 by Mark Sproul
23
+
24
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
25
+*/
26
+
27
+#include "wiring_private.h"
28
+#include "pins_arduino.h"
29
+
30
+uint8_t analog_reference = DEFAULT;
31
+
32
+void analogReference(uint8_t mode)
33
+{
34
+	// can't actually set the register here because the default setting
35
+	// will connect AVCC and the AREF pin, which would cause a short if
36
+	// there's something connected to AREF.
37
+	analog_reference = mode;
38
+}
39
+
40
+int analogRead(uint8_t pin)
41
+{
42
+	uint8_t low, high;
43
+
44
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
45
+	if (pin >= 54) pin -= 54; // allow for channel or pin numbers
46
+#else
47
+	if (pin >= 14) pin -= 14; // allow for channel or pin numbers
48
+#endif
49
+
50
+#if defined(ADCSRB) && defined(MUX5)
51
+	// the MUX5 bit of ADCSRB selects whether we're reading from channels
52
+	// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
53
+	ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
54
+#endif
55
+  
56
+	// set the analog reference (high two bits of ADMUX) and select the
57
+	// channel (low 4 bits).  this also sets ADLAR (left-adjust result)
58
+	// to 0 (the default).
59
+#if defined(ADMUX)
60
+	ADMUX = (analog_reference << 6) | (pin & 0x07);
61
+#endif
62
+
63
+	// without a delay, we seem to read from the wrong channel
64
+	//delay(1);
65
+
66
+#if defined(ADCSRA) && defined(ADCL)
67
+	// start the conversion
68
+	sbi(ADCSRA, ADSC);
69
+
70
+	// ADSC is cleared when the conversion finishes
71
+	while (bit_is_set(ADCSRA, ADSC));
72
+
73
+	// we have to read ADCL first; doing so locks both ADCL
74
+	// and ADCH until ADCH is read.  reading ADCL second would
75
+	// cause the results of each conversion to be discarded,
76
+	// as ADCL and ADCH would be locked when it completed.
77
+	low  = ADCL;
78
+	high = ADCH;
79
+#else
80
+	// we dont have an ADC, return 0
81
+	low  = 0;
82
+	high = 0;
83
+#endif
84
+
85
+	// combine the two bytes
86
+	return (high << 8) | low;
87
+}
88
+
89
+// Right now, PWM output only works on the pins with
90
+// hardware support.  These are defined in the appropriate
91
+// pins_*.c file.  For the rest of the pins, we default
92
+// to digital output.
93
+void analogWrite(uint8_t pin, int val)
94
+{
95
+	// We need to make sure the PWM output is enabled for those pins
96
+	// that support it, as we turn it off when digitally reading or
97
+	// writing with them.  Also, make sure the pin is in output mode
98
+	// for consistenty with Wiring, which doesn't require a pinMode
99
+	// call for the analog output pins.
100
+	pinMode(pin, OUTPUT);
101
+	if (val == 0)
102
+	{
103
+		digitalWrite(pin, LOW);
104
+	}
105
+	else if (val == 255)
106
+	{
107
+		digitalWrite(pin, HIGH);
108
+	}
109
+	else
110
+	{
111
+		switch(digitalPinToTimer(pin))
112
+		{
113
+			// XXX fix needed for atmega8
114
+			#if defined(TCCR0) && defined(COM00) && !defined(__AVR_ATmega8__)
115
+			case TIMER0A:
116
+				// connect pwm to pin on timer 0
117
+				sbi(TCCR0, COM00);
118
+				OCR0 = val; // set pwm duty
119
+				break;
120
+			#endif
121
+
122
+			#if defined(TCCR0A) && defined(COM0A1)
123
+			case TIMER0A:
124
+				// connect pwm to pin on timer 0, channel A
125
+				sbi(TCCR0A, COM0A1);
126
+				OCR0A = val; // set pwm duty
127
+				break;
128
+			#endif
129
+
130
+			#if defined(TCCR0A) && defined(COM0B1)
131
+			case TIMER0B:
132
+				// connect pwm to pin on timer 0, channel B
133
+				sbi(TCCR0A, COM0B1);
134
+				OCR0B = val; // set pwm duty
135
+				break;
136
+			#endif
137
+
138
+			#if defined(TCCR1A) && defined(COM1A1)
139
+			case TIMER1A:
140
+				// connect pwm to pin on timer 1, channel A
141
+				sbi(TCCR1A, COM1A1);
142
+				OCR1A = val; // set pwm duty
143
+				break;
144
+			#endif
145
+
146
+			#if defined(TCCR1A) && defined(COM1B1)
147
+			case TIMER1B:
148
+				// connect pwm to pin on timer 1, channel B
149
+				sbi(TCCR1A, COM1B1);
150
+				OCR1B = val; // set pwm duty
151
+				break;
152
+			#endif
153
+
154
+			#if defined(TCCR2) && defined(COM21)
155
+			case TIMER2:
156
+				// connect pwm to pin on timer 2
157
+				sbi(TCCR2, COM21);
158
+				OCR2 = val; // set pwm duty
159
+				break;
160
+			#endif
161
+
162
+			#if defined(TCCR2A) && defined(COM2A1)
163
+			case TIMER2A:
164
+				// connect pwm to pin on timer 2, channel A
165
+				sbi(TCCR2A, COM2A1);
166
+				OCR2A = val; // set pwm duty
167
+				break;
168
+			#endif
169
+
170
+			#if defined(TCCR2A) && defined(COM2B1)
171
+			case TIMER2B:
172
+				// connect pwm to pin on timer 2, channel B
173
+				sbi(TCCR2A, COM2B1);
174
+				OCR2B = val; // set pwm duty
175
+				break;
176
+			#endif
177
+
178
+			#if defined(TCCR3A) && defined(COM3A1)
179
+			case TIMER3A:
180
+				// connect pwm to pin on timer 3, channel A
181
+				sbi(TCCR3A, COM3A1);
182
+				OCR3A = val; // set pwm duty
183
+				break;
184
+			#endif
185
+
186
+			#if defined(TCCR3A) && defined(COM3B1)
187
+			case TIMER3B:
188
+				// connect pwm to pin on timer 3, channel B
189
+				sbi(TCCR3A, COM3B1);
190
+				OCR3B = val; // set pwm duty
191
+				break;
192
+			#endif
193
+
194
+			#if defined(TCCR3A) && defined(COM3C1)
195
+			case TIMER3C:
196
+				// connect pwm to pin on timer 3, channel C
197
+				sbi(TCCR3A, COM3C1);
198
+				OCR3C = val; // set pwm duty
199
+				break;
200
+			#endif
201
+
202
+			#if defined(TCCR4A) && defined(COM4A1)
203
+			case TIMER4A:
204
+				// connect pwm to pin on timer 4, channel A
205
+				sbi(TCCR4A, COM4A1);
206
+				OCR4A = val; // set pwm duty
207
+				break;
208
+			#endif
209
+
210
+			#if defined(TCCR4A) && defined(COM4B1)
211
+			case TIMER4B:
212
+				// connect pwm to pin on timer 4, channel B
213
+				sbi(TCCR4A, COM4B1);
214
+				OCR4B = val; // set pwm duty
215
+				break;
216
+			#endif
217
+
218
+			#if defined(TCCR4A) && defined(COM4C1)
219
+			case TIMER4C:
220
+				// connect pwm to pin on timer 4, channel C
221
+				sbi(TCCR4A, COM4C1);
222
+				OCR4C = val; // set pwm duty
223
+				break;
224
+			#endif
225
+
226
+			#if defined(TCCR5A) && defined(COM5A1)
227
+			case TIMER5A:
228
+				// connect pwm to pin on timer 5, channel A
229
+				sbi(TCCR5A, COM5A1);
230
+				OCR5A = val; // set pwm duty
231
+				break;
232
+			#endif
233
+
234
+			#if defined(TCCR5A) && defined(COM5B1)
235
+			case TIMER5B:
236
+				// connect pwm to pin on timer 5, channel B
237
+				sbi(TCCR5A, COM5B1);
238
+				OCR5B = val; // set pwm duty
239
+				break;
240
+			#endif
241
+
242
+			#if defined(TCCR5A) && defined(COM5C1)
243
+			case TIMER5C:
244
+				// connect pwm to pin on timer 5, channel C
245
+				sbi(TCCR5A, COM5C1);
246
+				OCR5C = val; // set pwm duty
247
+				break;
248
+			#endif
249
+
250
+			case NOT_ON_TIMER:
251
+			default:
252
+				if (val < 128) {
253
+					digitalWrite(pin, LOW);
254
+				} else {
255
+					digitalWrite(pin, HIGH);
256
+				}
257
+		}
258
+	}
259
+}

+ 166
- 0
Marlin/Marlin/Boards/cores/arduino/wiring_digital.c Переглянути файл

1
+/*
2
+  wiring_digital.c - digital input and output functions
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  Modified 28 September 2010 by Mark Sproul
23
+
24
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
25
+*/
26
+
27
+#include "wiring_private.h"
28
+#include "pins_arduino.h"
29
+
30
+void pinMode(uint8_t pin, uint8_t mode)
31
+{
32
+	uint8_t bit = digitalPinToBitMask(pin);
33
+	uint8_t port = digitalPinToPort(pin);
34
+	volatile uint8_t *reg;
35
+
36
+	if (port == NOT_A_PIN) return;
37
+
38
+	// JWS: can I let the optimizer do this?
39
+	reg = portModeRegister(port);
40
+
41
+	if (mode == INPUT) { 
42
+		uint8_t oldSREG = SREG;
43
+                cli();
44
+		*reg &= ~bit;
45
+		SREG = oldSREG;
46
+	} else {
47
+		uint8_t oldSREG = SREG;
48
+                cli();
49
+		*reg |= bit;
50
+		SREG = oldSREG;
51
+	}
52
+}
53
+
54
+// Forcing this inline keeps the callers from having to push their own stuff
55
+// on the stack. It is a good performance win and only takes 1 more byte per
56
+// user than calling. (It will take more bytes on the 168.)
57
+//
58
+// But shouldn't this be moved into pinMode? Seems silly to check and do on
59
+// each digitalread or write.
60
+//
61
+// Mark Sproul:
62
+// - Removed inline. Save 170 bytes on atmega1280
63
+// - changed to a switch statment; added 32 bytes but much easier to read and maintain.
64
+// - Added more #ifdefs, now compiles for atmega645
65
+//
66
+//static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
67
+//static inline void turnOffPWM(uint8_t timer)
68
+static void turnOffPWM(uint8_t timer)
69
+{
70
+	switch (timer)
71
+	{
72
+		#if defined(TCCR1A) && defined(COM1A1)
73
+		case TIMER1A:   cbi(TCCR1A, COM1A1);    break;
74
+		#endif
75
+		#if defined(TCCR1A) && defined(COM1B1)
76
+		case TIMER1B:   cbi(TCCR1A, COM1B1);    break;
77
+		#endif
78
+		
79
+		#if defined(TCCR2) && defined(COM21)
80
+		case  TIMER2:   cbi(TCCR2, COM21);      break;
81
+		#endif
82
+		
83
+		#if defined(TCCR0A) && defined(COM0A1)
84
+		case  TIMER0A:  cbi(TCCR0A, COM0A1);    break;
85
+		#endif
86
+		
87
+		#if defined(TIMER0B) && defined(COM0B1)
88
+		case  TIMER0B:  cbi(TCCR0A, COM0B1);    break;
89
+		#endif
90
+		#if defined(TCCR2A) && defined(COM2A1)
91
+		case  TIMER2A:  cbi(TCCR2A, COM2A1);    break;
92
+		#endif
93
+		#if defined(TCCR2A) && defined(COM2B1)
94
+		case  TIMER2B:  cbi(TCCR2A, COM2B1);    break;
95
+		#endif
96
+		
97
+		#if defined(TCCR3A) && defined(COM3A1)
98
+		case  TIMER3A:  cbi(TCCR3A, COM3A1);    break;
99
+		#endif
100
+		#if defined(TCCR3A) && defined(COM3B1)
101
+		case  TIMER3B:  cbi(TCCR3A, COM3B1);    break;
102
+		#endif
103
+		#if defined(TCCR3A) && defined(COM3C1)
104
+		case  TIMER3C:  cbi(TCCR3A, COM3C1);    break;
105
+		#endif
106
+
107
+		#if defined(TCCR4A) && defined(COM4A1)
108
+		case  TIMER4A:  cbi(TCCR4A, COM4A1);    break;
109
+		#endif
110
+		#if defined(TCCR4A) && defined(COM4B1)
111
+		case  TIMER4B:  cbi(TCCR4A, COM4B1);    break;
112
+		#endif
113
+		#if defined(TCCR4A) && defined(COM4C1)
114
+		case  TIMER4C:  cbi(TCCR4A, COM4C1);    break;
115
+		#endif
116
+		#if defined(TCCR5A)
117
+		case  TIMER5A:  cbi(TCCR5A, COM5A1);    break;
118
+		case  TIMER5B:  cbi(TCCR5A, COM5B1);    break;
119
+		case  TIMER5C:  cbi(TCCR5A, COM5C1);    break;
120
+		#endif
121
+	}
122
+}
123
+
124
+void digitalWrite(uint8_t pin, uint8_t val)
125
+{
126
+	uint8_t timer = digitalPinToTimer(pin);
127
+	uint8_t bit = digitalPinToBitMask(pin);
128
+	uint8_t port = digitalPinToPort(pin);
129
+	volatile uint8_t *out;
130
+
131
+	if (port == NOT_A_PIN) return;
132
+
133
+	// If the pin that support PWM output, we need to turn it off
134
+	// before doing a digital write.
135
+	if (timer != NOT_ON_TIMER) turnOffPWM(timer);
136
+
137
+	out = portOutputRegister(port);
138
+
139
+	if (val == LOW) {
140
+		uint8_t oldSREG = SREG;
141
+                cli();
142
+		*out &= ~bit;
143
+		SREG = oldSREG;
144
+	} else {
145
+		uint8_t oldSREG = SREG;
146
+                cli();
147
+		*out |= bit;
148
+		SREG = oldSREG;
149
+	}
150
+}
151
+
152
+int digitalRead(uint8_t pin)
153
+{
154
+	uint8_t timer = digitalPinToTimer(pin);
155
+	uint8_t bit = digitalPinToBitMask(pin);
156
+	uint8_t port = digitalPinToPort(pin);
157
+
158
+	if (port == NOT_A_PIN) return LOW;
159
+
160
+	// If the pin that support PWM output, we need to turn it off
161
+	// before getting a digital reading.
162
+	if (timer != NOT_ON_TIMER) turnOffPWM(timer);
163
+
164
+	if (*portInputRegister(port) & bit) return HIGH;
165
+	return LOW;
166
+}

+ 68
- 0
Marlin/Marlin/Boards/cores/arduino/wiring_private.h Переглянути файл

1
+/*
2
+  wiring_private.h - Internal header file.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
23
+*/
24
+
25
+#ifndef WiringPrivate_h
26
+#define WiringPrivate_h
27
+#include <math.h>
28
+#include <avr/io.h>
29
+#include <avr/interrupt.h>
30
+#include <util/delay.h>
31
+#include <stdio.h>
32
+#include <stdarg.h>
33
+
34
+#include "wiring.h"
35
+
36
+#ifdef __cplusplus
37
+extern "C"{
38
+#endif
39
+
40
+#ifndef cbi
41
+#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
42
+#endif
43
+#ifndef sbi
44
+#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
45
+#endif
46
+
47
+#define EXTERNAL_INT_0 0
48
+#define EXTERNAL_INT_1 1
49
+#define EXTERNAL_INT_2 2
50
+#define EXTERNAL_INT_3 3
51
+#define EXTERNAL_INT_4 4
52
+#define EXTERNAL_INT_5 5
53
+#define EXTERNAL_INT_6 6
54
+#define EXTERNAL_INT_7 7
55
+
56
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
57
+#define EXTERNAL_NUM_INTERRUPTS 8
58
+#else
59
+#define EXTERNAL_NUM_INTERRUPTS 2
60
+#endif
61
+
62
+typedef void (*voidFuncPtr)(void);
63
+
64
+#ifdef __cplusplus
65
+} // extern "C"
66
+#endif
67
+
68
+#endif

+ 69
- 0
Marlin/Marlin/Boards/cores/arduino/wiring_pulse.c Переглянути файл

1
+/*
2
+  wiring_pulse.c - pulseIn() function
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
23
+*/
24
+
25
+#include "wiring_private.h"
26
+#include "pins_arduino.h"
27
+
28
+/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
29
+ * or LOW, the type of pulse to measure.  Works on pulses from 2-3 microseconds
30
+ * to 3 minutes in length, but must be called at least a few dozen microseconds
31
+ * before the start of the pulse. */
32
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
33
+{
34
+	// cache the port and bit of the pin in order to speed up the
35
+	// pulse width measuring loop and achieve finer resolution.  calling
36
+	// digitalRead() instead yields much coarser resolution.
37
+	uint8_t bit = digitalPinToBitMask(pin);
38
+	uint8_t port = digitalPinToPort(pin);
39
+	uint8_t stateMask = (state ? bit : 0);
40
+	unsigned long width = 0; // keep initialization out of time critical area
41
+	
42
+	// convert the timeout from microseconds to a number of times through
43
+	// the initial loop; it takes 16 clock cycles per iteration.
44
+	unsigned long numloops = 0;
45
+	unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
46
+	
47
+	// wait for any previous pulse to end
48
+	while ((*portInputRegister(port) & bit) == stateMask)
49
+		if (numloops++ == maxloops)
50
+			return 0;
51
+	
52
+	// wait for the pulse to start
53
+	while ((*portInputRegister(port) & bit) != stateMask)
54
+		if (numloops++ == maxloops)
55
+			return 0;
56
+	
57
+	// wait for the pulse to stop
58
+	while ((*portInputRegister(port) & bit) == stateMask) {
59
+		if (numloops++ == maxloops)
60
+			return 0;
61
+		width++;
62
+	}
63
+
64
+	// convert the reading to microseconds. The loop has been determined
65
+	// to be 20 clock cycles long and have about 16 clocks between the edge
66
+	// and the start of the loop. There will be some error introduced by
67
+	// the interrupt handlers.
68
+	return clockCyclesToMicroseconds(width * 21 + 16); 
69
+}

+ 55
- 0
Marlin/Marlin/Boards/cores/arduino/wiring_shift.c Переглянути файл

1
+/*
2
+  wiring_shift.c - shiftOut() function
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
23
+*/
24
+
25
+#include "wiring_private.h"
26
+
27
+uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
28
+	uint8_t value = 0;
29
+	uint8_t i;
30
+
31
+	for (i = 0; i < 8; ++i) {
32
+		digitalWrite(clockPin, HIGH);
33
+		if (bitOrder == LSBFIRST)
34
+			value |= digitalRead(dataPin) << i;
35
+		else
36
+			value |= digitalRead(dataPin) << (7 - i);
37
+		digitalWrite(clockPin, LOW);
38
+	}
39
+	return value;
40
+}
41
+
42
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
43
+{
44
+	uint8_t i;
45
+
46
+	for (i = 0; i < 8; i++)  {
47
+		if (bitOrder == LSBFIRST)
48
+			digitalWrite(dataPin, !!(val & (1 << i)));
49
+		else	
50
+			digitalWrite(dataPin, !!(val & (1 << (7 - i))));
51
+			
52
+		digitalWrite(clockPin, HIGH);
53
+		digitalWrite(clockPin, LOW);		
54
+	}
55
+}

+ 188
- 0
Marlin/Marlin/COPYING Переглянути файл

1
+GNU GENERAL PUBLIC LICENSE
2
+
3
+Version 3, 29 June 2007
4
+
5
+Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
6
+
7
+Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
8
+Preamble
9
+
10
+The GNU General Public License is a free, copyleft license for software and other kinds of works.
11
+
12
+The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
13
+
14
+When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
15
+
16
+To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
17
+
18
+For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
19
+
20
+Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
21
+
22
+For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
23
+
24
+Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
25
+
26
+Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
27
+
28
+The precise terms and conditions for copying, distribution and modification follow.
29
+TERMS AND CONDITIONS
30
+0. Definitions.
31
+
32
+“This License” refers to version 3 of the GNU General Public License.
33
+
34
+“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
35
+
36
+“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
37
+
38
+To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
39
+
40
+A “covered work” means either the unmodified Program or a work based on the Program.
41
+
42
+To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
43
+
44
+To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
45
+
46
+An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
47
+1. Source Code.
48
+
49
+The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
50
+
51
+A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
52
+
53
+The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
54
+
55
+The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
56
+
57
+The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
58
+
59
+The Corresponding Source for a work in source code form is that same work.
60
+2. Basic Permissions.
61
+
62
+All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
63
+
64
+You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
65
+
66
+Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
67
+3. Protecting Users' Legal Rights From Anti-Circumvention Law.
68
+
69
+No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
70
+
71
+When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
72
+4. Conveying Verbatim Copies.
73
+
74
+You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
75
+
76
+You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
77
+5. Conveying Modified Source Versions.
78
+
79
+You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
80
+
81
+    a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
82
+    b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
83
+    c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
84
+    d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
85
+
86
+A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
87
+6. Conveying Non-Source Forms.
88
+
89
+You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
90
+
91
+    a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
92
+    b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
93
+    c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
94
+    d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
95
+    e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
96
+
97
+A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
98
+
99
+A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
100
+
101
+“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
102
+
103
+If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
104
+
105
+The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
106
+
107
+Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
108
+7. Additional Terms.
109
+
110
+“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
111
+
112
+When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
113
+
114
+Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
115
+
116
+    a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
117
+    b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
118
+    c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
119
+    d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
120
+    e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
121
+    f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
122
+
123
+All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
124
+
125
+If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
126
+
127
+Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
128
+8. Termination.
129
+
130
+You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
131
+
132
+However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
133
+
134
+Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
135
+
136
+Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
137
+9. Acceptance Not Required for Having Copies.
138
+
139
+You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
140
+10. Automatic Licensing of Downstream Recipients.
141
+
142
+Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
143
+
144
+An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
145
+
146
+You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
147
+11. Patents.
148
+
149
+A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
150
+
151
+A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
152
+
153
+Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
154
+
155
+In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
156
+
157
+If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
158
+
159
+If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
160
+
161
+A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
162
+
163
+Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
164
+12. No Surrender of Others' Freedom.
165
+
166
+If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
167
+13. Use with the GNU Affero General Public License.
168
+
169
+Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
170
+14. Revised Versions of this License.
171
+
172
+The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
173
+
174
+Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
175
+
176
+If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
177
+
178
+Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
179
+15. Disclaimer of Warranty.
180
+
181
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
182
+16. Limitation of Liability.
183
+
184
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
185
+17. Interpretation of Sections 15 and 16.
186
+
187
+If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
188
+

+ 294
- 0
Marlin/Marlin/Configuration.h Переглянути файл

1
+#ifndef CONFIGURATION_H
2
+#define CONFIGURATION_H
3
+
4
+// This configurtion file contains the basic settings.
5
+// Advanced settings can be found in Configuration_adv.h 
6
+// BASIC SETTINGS: select your board type, temperature sensor type, axis scaling, and endstop configuration
7
+
8
+//User specified version info of THIS file to display in [Pronterface, etc] terminal window during startup.
9
+//Implementation of an idea by Prof Braino to inform user that any changes made
10
+//to THIS file by the user have been successfully uploaded into firmware.
11
+#define STRING_VERSION_CONFIG_H "2012-05-02" //Personal revision number for changes to THIS file.
12
+#define STRING_CONFIG_H_AUTHOR "erik" //Who made the changes.
13
+
14
+// This determines the communication speed of the printer
15
+#define BAUDRATE 250000
16
+//#define BAUDRATE 115200
17
+
18
+//// The following define selects which electronics board you have. Please choose the one that matches your setup
19
+// Gen7 custom (Alfons3 Version) = 10 "https://github.com/Alfons3/Generation_7_Electronics"
20
+// Gen7 v1.1, v1.2 = 11
21
+// Gen7 v1.3 = 12
22
+// Gen7 v1.4 = 13
23
+// MEGA/RAMPS up to 1.2 = 3
24
+// RAMPS 1.3 = 33 (Power outputs: Extruder, Bed, Fan)
25
+// RAMPS 1.3 = 34 (Power outputs: Extruder0, Extruder1, Bed)
26
+// Gen6 = 5
27
+// Gen6 deluxe = 51
28
+// Sanguinololu 1.2 and above = 62
29
+// Melzi = 63
30
+// Ultimaker = 7
31
+// Teensylu = 8
32
+// Gen3+ =9
33
+
34
+#ifndef MOTHERBOARD
35
+#define MOTHERBOARD 7
36
+#endif
37
+
38
+
39
+
40
+//===========================================================================
41
+//=============================Thermal Settings  ============================
42
+//===========================================================================
43
+//
44
+//--NORMAL IS 4.7kohm PULLUP!-- 1kohm pullup can be used on hotend sensor, using correct resistor and table
45
+//
46
+//// Temperature sensor settings:
47
+// -2 is thermocouple with MAX6675 (only for sensor 0)
48
+// -1 is thermocouple with AD595
49
+// 0 is not used
50
+// 1 is 100k thermistor - best choice for EPCOS 100k (4.7k pullup)
51
+// 2 is 200k thermistor - ATC Semitec 204GT-2 (4.7k pullup)
52
+// 3 is mendel-parts thermistor (4.7k pullup)
53
+// 4 is 10k thermistor !! do not use it for a hotend. It gives bad resolution at high temp. !!
54
+// 5 is 100K thermistor - ATC Semitec 104GT-2 (Used in ParCan) (4.7k pullup)
55
+// 6 is 100k EPCOS - Not as accurate as table 1 (created using a fluke thermocouple) (4.7k pullup)
56
+// 7 is 100k Honeywell thermistor 135-104LAG-J01 (4.7k pullup)
57
+//
58
+//    1k ohm pullup tables - This is not normal, you would have to have changed out your 4.7k for 1k 
59
+//                          (but gives greater accuracy and more stable PID)
60
+// 51 is 100k thermistor - EPCOS (1k pullup)
61
+// 52 is 200k thermistor - ATC Semitec 204GT-2 (1k pullup)
62
+// 55 is 100k thermistor - ATC Semitec 104GT-2 (Used in ParCan) (1k pullup)
63
+
64
+#define TEMP_SENSOR_0 -1
65
+#define TEMP_SENSOR_1 0
66
+#define TEMP_SENSOR_2 0
67
+#define TEMP_SENSOR_BED 0
68
+
69
+// Actual temperature must be close to target for this long before M109 returns success
70
+#define TEMP_RESIDENCY_TIME 10	// (seconds)
71
+#define TEMP_HYSTERESIS 3       // (degC) range of +/- temperatures considered "close" to the target one
72
+#define TEMP_WINDOW     1       // (degC) Window around target to start the recidency timer x degC early.
73
+
74
+// The minimal temperature defines the temperature below which the heater will not be enabled It is used
75
+// to check that the wiring to the thermistor is not broken. 
76
+// Otherwise this would lead to the heater being powered on all the time.
77
+#define HEATER_0_MINTEMP 5
78
+#define HEATER_1_MINTEMP 5
79
+#define HEATER_2_MINTEMP 5
80
+#define BED_MINTEMP 5
81
+
82
+// When temperature exceeds max temp, your heater will be switched off.
83
+// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
84
+// You should use MINTEMP for thermistor short/failure protection.
85
+#define HEATER_0_MAXTEMP 275
86
+#define HEATER_1_MAXTEMP 275
87
+#define HEATER_2_MAXTEMP 275
88
+#define BED_MAXTEMP 150
89
+
90
+// If your bed has low resistance e.g. .6 ohm and throws the fuse you can duty cycle it to reduce the
91
+// average current. The value should be an integer and the heat bed will be turned on for 1 interval of
92
+// HEATER_BED_DUTY_CYCLE_DIVIDER intervals.
93
+//#define HEATER_BED_DUTY_CYCLE_DIVIDER 4
94
+
95
+// PID settings:
96
+// Comment the following line to disable PID and enable bang-bang.
97
+#define PIDTEMP
98
+#define PID_MAX 255 // limits current to nozzle; 255=full current
99
+#ifdef PIDTEMP
100
+  //#define PID_DEBUG // Sends debug data to the serial port. 
101
+  //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
102
+  #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
103
+  #define K1 0.95 //smoothing factor withing the PID
104
+  #define PID_dT ((16.0 * 8.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the
105
+
106
+// If you are using a preconfigured hotend then you can use one of the value sets by uncommenting it
107
+// Ultimaker
108
+    #define  DEFAULT_Kp 22.2
109
+    #define  DEFAULT_Ki 1.08  
110
+    #define  DEFAULT_Kd 114  
111
+
112
+// Makergear
113
+//    #define  DEFAULT_Kp 7.0
114
+//    #define  DEFAULT_Ki 0.1  
115
+//    #define  DEFAULT_Kd 12  
116
+
117
+// Mendel Parts V9 on 12V    
118
+//    #define  DEFAULT_Kp 63.0
119
+//    #define  DEFAULT_Ki 2.25
120
+//    #define  DEFAULT_Kd 440
121
+#endif // PIDTEMP
122
+
123
+//this prevents dangerous Extruder moves, i.e. if the temperature is under the limit
124
+//can be software-disabled for whatever purposes by
125
+#define PREVENT_DANGEROUS_EXTRUDE
126
+//if PREVENT_DANGEROUS_EXTRUDE is on, you can still disable (uncomment) very long bits of extrusion separately.
127
+#define PREVENT_LENGTHY_EXTRUDE
128
+
129
+#define EXTRUDE_MINTEMP 170
130
+#define EXTRUDE_MAXLENGTH (X_MAX_LENGTH+Y_MAX_LENGTH) //prevent extrusion of very large distances.
131
+
132
+//===========================================================================
133
+//=============================Mechanical Settings===========================
134
+//===========================================================================
135
+
136
+// Uncomment the following line to enable CoreXY kinematics
137
+// #define COREXY
138
+
139
+// corse Endstop Settings
140
+#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
141
+
142
+#ifndef ENDSTOPPULLUPS
143
+  // fine Enstop settings: Individual Pullups. will be ignord if ENDSTOPPULLUPS is defined
144
+  #define ENDSTOPPULLUP_XMAX
145
+  #define ENDSTOPPULLUP_YMAX
146
+  #define ENDSTOPPULLUP_ZMAX
147
+  #define ENDSTOPPULLUP_XMIN
148
+  #define ENDSTOPPULLUP_YMIN
149
+  //#define ENDSTOPPULLUP_ZMIN
150
+#endif
151
+
152
+#ifdef ENDSTOPPULLUPS
153
+  #define ENDSTOPPULLUP_XMAX
154
+  #define ENDSTOPPULLUP_YMAX
155
+  #define ENDSTOPPULLUP_ZMAX
156
+  #define ENDSTOPPULLUP_XMIN
157
+  #define ENDSTOPPULLUP_YMIN
158
+  #define ENDSTOPPULLUP_ZMIN
159
+#endif
160
+
161
+// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
162
+const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
163
+const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
164
+const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
165
+//#define DISABLE_MAX_ENDSTOPS
166
+
167
+// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
168
+#define X_ENABLE_ON 0
169
+#define Y_ENABLE_ON 0
170
+#define Z_ENABLE_ON 0
171
+#define E_ENABLE_ON 0 // For all extruders
172
+
173
+// Disables axis when it's not being used.
174
+#define DISABLE_X false
175
+#define DISABLE_Y false
176
+#define DISABLE_Z false
177
+#define DISABLE_E false // For all extruders
178
+
179
+#define INVERT_X_DIR true    // for Mendel set to false, for Orca set to true
180
+#define INVERT_Y_DIR false    // for Mendel set to true, for Orca set to false
181
+#define INVERT_Z_DIR true     // for Mendel set to false, for Orca set to true
182
+#define INVERT_E0_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
183
+#define INVERT_E1_DIR false    // for direct drive extruder v9 set to true, for geared extruder set to false
184
+#define INVERT_E2_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
185
+
186
+// ENDSTOP SETTINGS:
187
+// Sets direction of endstops when homing; 1=MAX, -1=MIN
188
+#define X_HOME_DIR -1
189
+#define Y_HOME_DIR -1
190
+#define Z_HOME_DIR -1
191
+
192
+#define min_software_endstops true //If true, axis won't move to coordinates less than HOME_POS.
193
+#define max_software_endstops true  //If true, axis won't move to coordinates greater than the defined lengths below.
194
+// Travel limits after homing
195
+#define X_MAX_POS 205
196
+#define X_MIN_POS 0
197
+#define Y_MAX_POS 205
198
+#define Y_MIN_POS 0
199
+#define Z_MAX_POS 200
200
+#define Z_MIN_POS 0
201
+
202
+#define X_MAX_LENGTH (X_MAX_POS - X_MIN_POS)
203
+#define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS)
204
+#define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS)
205
+
206
+// The position of the homing switches. Use MAX_LENGTH * -0.5 if the center should be 0, 0, 0
207
+#define X_HOME_POS 0
208
+#define Y_HOME_POS 0
209
+#define Z_HOME_POS 0
210
+
211
+//// MOVEMENT SETTINGS
212
+#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
213
+#define HOMING_FEEDRATE {50*60, 50*60, 4*60, 0}  // set the homing speeds (mm/min)
214
+
215
+// default settings 
216
+
217
+#define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200*8/3,760*1.1}  // default steps per unit for ultimaker 
218
+#define DEFAULT_MAX_FEEDRATE          {500, 500, 5, 45}    // (mm/sec)    
219
+#define DEFAULT_MAX_ACCELERATION      {9000,9000,100,10000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
220
+
221
+#define DEFAULT_ACCELERATION          3000    // X, Y, Z and E max acceleration in mm/s^2 for printing moves 
222
+#define DEFAULT_RETRACT_ACCELERATION  3000   // X, Y, Z and E max acceleration in mm/s^2 for r retracts
223
+
224
+// 
225
+#define DEFAULT_XYJERK                20.0    // (mm/sec)
226
+#define DEFAULT_ZJERK                 0.4     // (mm/sec)
227
+#define DEFAULT_EJERK                 5.0    // (mm/sec)
228
+
229
+//===========================================================================
230
+//=============================Additional Features===========================
231
+//===========================================================================
232
+
233
+// EEPROM
234
+// the microcontroller can store settings in the EEPROM, e.g. max velocity...
235
+// M500 - stores paramters in EEPROM
236
+// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).  
237
+// M502 - reverts to the default "factory settings".  You still need to store them in EEPROM afterwards if you want to.
238
+//define this to enable eeprom support
239
+//#define EEPROM_SETTINGS
240
+//to disable EEPROM Serial responses and decrease program space by ~1700 byte: comment this out:
241
+// please keep turned on if you can.
242
+//#define EEPROM_CHITCHAT
243
+
244
+//LCD and SD support
245
+//#define ULTRA_LCD  //general lcd support, also 16x2
246
+//#define SDSUPPORT // Enable SD Card Support in Hardware Console
247
+
248
+//#define ULTIMAKERCONTROLLER //as available from the ultimaker online store.
249
+//#define ULTIPANEL  //the ultipanel as on thingiverse
250
+
251
+
252
+#ifdef ULTIMAKERCONTROLLER    //automatic expansion
253
+ #define ULTIPANEL
254
+ #define NEWPANEL
255
+#endif 
256
+ 
257
+
258
+#ifdef ULTIPANEL
259
+//  #define NEWPANEL  //enable this if you have a click-encoder panel
260
+  #define SDSUPPORT
261
+  #define ULTRA_LCD
262
+  #define LCD_WIDTH 20
263
+  #define LCD_HEIGHT 4
264
+  
265
+// Preheat Constants
266
+  #define PLA_PREHEAT_HOTEND_TEMP 180 
267
+  #define PLA_PREHEAT_HPB_TEMP 70
268
+  #define PLA_PREHEAT_FAN_SPEED 255		// Insert Value between 0 and 255
269
+
270
+  #define ABS_PREHEAT_HOTEND_TEMP 240
271
+  #define ABS_PREHEAT_HPB_TEMP 100
272
+  #define ABS_PREHEAT_FAN_SPEED 255		// Insert Value between 0 and 255
273
+
274
+#else //no panel but just lcd 
275
+  #ifdef ULTRA_LCD
276
+    #define LCD_WIDTH 16
277
+    #define LCD_HEIGHT 2    
278
+  #endif
279
+#endif
280
+
281
+// Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino
282
+//#define FAST_PWM_FAN
283
+
284
+// M240  Triggers a camera by emulating a Canon RC-1 Remote
285
+// Data from: http://www.doc-diy.net/photo/rc-1_hacked/
286
+// #define PHOTOGRAPH_PIN     23
287
+
288
+// SF send wrong arc g-codes when using Arc Point as fillet procedure
289
+//#define SF_ARC_FIX
290
+
291
+#include "Configuration_adv.h"
292
+#include "thermistortables.h"
293
+
294
+#endif //__CONFIGURATION_H

+ 263
- 0
Marlin/Marlin/Configuration_adv.h Переглянути файл

1
+#ifndef CONFIGURATION_ADV_H
2
+#define CONFIGURATION_ADV_H
3
+
4
+//===========================================================================
5
+//=============================Thermal Settings  ============================
6
+//===========================================================================
7
+
8
+// Select one of these only to define how the bed temp is read.
9
+//
10
+//#define BED_LIMIT_SWITCHING
11
+#ifdef BED_LIMIT_SWITCHING
12
+  #define BED_HYSTERESIS 2 //only disable heating if T>target+BED_HYSTERESIS and enable heating if T>target-BED_HYSTERESIS
13
+#endif
14
+#define BED_CHECK_INTERVAL 5000 //ms
15
+
16
+//// Heating sanity check:
17
+// This waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
18
+// If the temperature has not increased at the end of that period, the target temperature is set to zero. 
19
+// It can be reset with another M104/M109
20
+//#define WATCHPERIOD 20000 //20 seconds
21
+
22
+// Wait for Cooldown
23
+// This defines if the M109 call should not block if it is cooling down.
24
+// example: From a current temp of 220, you set M109 S200. 
25
+// if CooldownNoWait is defined M109 will not wait for the cooldown to finish
26
+#define CooldownNoWait true
27
+
28
+#ifdef PIDTEMP
29
+  // this adds an experimental additional term to the heatingpower, proportional to the extrusion speed.
30
+  // if Kc is choosen well, the additional required power due to increased melting should be compensated.
31
+  #define PID_ADD_EXTRUSION_RATE  
32
+  #ifdef PID_ADD_EXTRUSION_RATE
33
+    #define  DEFAULT_Kc (1) //heatingpower=Kc*(e_speed)
34
+  #endif
35
+#endif
36
+
37
+
38
+//automatic temperature: The hot end target temperature is calculated by all the buffered lines of gcode.
39
+//The maximum buffered steps/sec of the extruder motor are called "se".
40
+//You enter the autotemp mode by a M109 S<mintemp> T<maxtemp> F<factor>
41
+// the target temperature is set to mintemp+factor*se[steps/sec] and limited by mintemp and maxtemp
42
+// you exit the value by any M109 without F*
43
+// Also, if the temperature is set to a value <mintemp, it is not changed by autotemp.
44
+// on an ultimaker, some initial testing worked with M109 S215 B260 F1 in the start.gcode
45
+#define AUTOTEMP
46
+#ifdef AUTOTEMP
47
+  #define AUTOTEMP_OLDWEIGHT 0.98
48
+#endif
49
+
50
+//  extruder run-out prevention. 
51
+//if the machine is idle, and the temperature over MINTEMP, every couple of SECONDS some filament is extruded
52
+//#define EXTRUDER_RUNOUT_PREVENT  
53
+#define EXTRUDER_RUNOUT_MINTEMP 190  
54
+#define EXTRUDER_RUNOUT_SECONDS 30.
55
+#define EXTRUDER_RUNOUT_ESTEPS 14. //mm filament
56
+#define EXTRUDER_RUNOUT_SPEED 1500.  //extrusion speed
57
+#define EXTRUDER_RUNOUT_EXTRUDE 100
58
+
59
+//These defines help to calibrate the AD595 sensor in case you get wrong temperature measurements.
60
+//The measured temperature is defined as "actualTemp = (measuredTemp * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET"
61
+#define TEMP_SENSOR_AD595_OFFSET 0.0
62
+#define TEMP_SENSOR_AD595_GAIN   1.0
63
+
64
+//This is for controlling a fan to cool down the stepper drivers
65
+//it will turn on when any driver is enabled
66
+//and turn off after the set amount of seconds from last driver being disabled again
67
+//#define CONTROLLERFAN_PIN 23 //Pin used for the fan to cool controller, comment out to disable this function
68
+#define CONTROLLERFAN_SEC 60 //How many seconds, after all motors were disabled, the fan should run
69
+
70
+//===========================================================================
71
+//=============================Mechanical Settings===========================
72
+//===========================================================================
73
+
74
+// This defines the number of extruders
75
+#define EXTRUDERS 1
76
+
77
+#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
78
+
79
+//#define Z_LATE_ENABLE // Enable Z the last moment. Needed if your Z driver overheats.
80
+
81
+// A single Z stepper driver is usually used to drive 2 stepper motors.
82
+// Uncomment this define to utilize a separate stepper driver for each Z axis motor.
83
+// Only a few motherboards support this, like RAMPS, which have dual extruder support (the 2nd, often unused, extruder driver is used
84
+// to control the 2nd Z axis stepper motor). The pins are currently only defined for a RAMPS motherboards.
85
+// On a RAMPS (or other 5 driver) motherboard, using this feature will limit you to using 1 extruder.
86
+//#define Z_DUAL_STEPPER_DRIVERS
87
+
88
+#ifdef Z_DUAL_STEPPER_DRIVERS
89
+  #undef EXTRUDERS
90
+  #define EXTRUDERS 1
91
+#endif
92
+
93
+//homing hits the endstop, then retracts by this distance, before it tries to slowly bump again:
94
+#define X_HOME_RETRACT_MM 5 
95
+#define Y_HOME_RETRACT_MM 5 
96
+#define Z_HOME_RETRACT_MM 1 
97
+//#define QUICK_HOME  //if this is defined, if both x and y are to be homed, a diagonal move will be performed initially.
98
+
99
+#define AXIS_RELATIVE_MODES {false, false, false, false}
100
+
101
+#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
102
+
103
+//By default pololu step drivers require an active high signal. However, some high power drivers require an active low signal as step.
104
+#define INVERT_X_STEP_PIN false
105
+#define INVERT_Y_STEP_PIN false
106
+#define INVERT_Z_STEP_PIN false
107
+#define INVERT_E_STEP_PIN false
108
+
109
+//default stepper release if idle
110
+#define DEFAULT_STEPPER_DEACTIVE_TIME 60
111
+
112
+#define DEFAULT_MINIMUMFEEDRATE       0.0     // minimum feedrate
113
+#define DEFAULT_MINTRAVELFEEDRATE     0.0
114
+
115
+// minimum time in microseconds that a movement needs to take if the buffer is emptied.
116
+#define DEFAULT_MINSEGMENTTIME        20000
117
+
118
+// If defined the movements slow down when the look ahead buffer is only half full
119
+#define SLOWDOWN
120
+
121
+// Frequency limit
122
+// See nophead's blog for more info
123
+// Not working O
124
+//#define XY_FREQUENCY_LIMIT  15
125
+
126
+// Minimum planner junction speed. Sets the default minimum speed the planner plans for at the end
127
+// of the buffer and all stops. This should not be much greater than zero and should only be changed
128
+// if unwanted behavior is observed on a user's machine when running at very slow speeds.
129
+#define MINIMUM_PLANNER_SPEED 0.05// (mm/sec)
130
+
131
+//===========================================================================
132
+//=============================Additional Features===========================
133
+//===========================================================================
134
+
135
+
136
+#define SD_FINISHED_STEPPERRELEASE true  //if sd support and the file is finished: disable steppers?
137
+#define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // no z because of layer shift.
138
+
139
+// The hardware watchdog should halt the Microcontroller, in case the firmware gets stuck somewhere. However:
140
+// the Watchdog is not working well, so please only enable this for testing
141
+// this enables the watchdog interrupt.
142
+//#define USE_WATCHDOG
143
+//#ifdef USE_WATCHDOG
144
+  // you cannot reboot on a mega2560 due to a bug in he bootloader. Hence, you have to reset manually, and this is done hereby:
145
+//#define RESET_MANUAL
146
+//#define WATCHDOG_TIMEOUT 4  //seconds
147
+//#endif
148
+
149
+// extruder advance constant (s2/mm3)
150
+//
151
+// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2
152
+//
153
+// hooke's law says:		force = k * distance
154
+// bernoulli's priniciple says:	v ^ 2 / 2 + g . h + pressure / density = constant
155
+// so: v ^ 2 is proportional to number of steps we advance the extruder
156
+//#define ADVANCE
157
+
158
+#ifdef ADVANCE
159
+  #define EXTRUDER_ADVANCE_K .0
160
+
161
+  #define D_FILAMENT 2.85
162
+  #define STEPS_MM_E 836
163
+  #define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
164
+  #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
165
+
166
+#endif // ADVANCE
167
+
168
+// Arc interpretation settings:
169
+#define MM_PER_ARC_SEGMENT 1
170
+#define N_ARC_CORRECTION 25
171
+
172
+const int dropsegments=5; //everything with less than this number of steps will be ignored as move and joined with the next movement
173
+
174
+// If you are using a RAMPS board or cheap E-bay purchased boards that do not detect when an SD card is inserted
175
+// You can get round this by connecting a push button or single throw switch to the pin defined as SDCARDCARDDETECT 
176
+// in the pins.h file.  When using a push button pulling the pin to ground this will need inverted.  This setting should
177
+// be commented out otherwise
178
+#define SDCARDDETECTINVERTED 
179
+
180
+#ifdef ULTIPANEL
181
+ #undef SDCARDDETECTINVERTED
182
+#endif
183
+//===========================================================================
184
+//=============================Buffers           ============================
185
+//===========================================================================
186
+
187
+// The number of linear motions that can be in the plan at any give time.  
188
+// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ringbuffering.
189
+#if defined SDSUPPORT
190
+  #define BLOCK_BUFFER_SIZE 16   // SD,LCD,Buttons take more memory, block buffer needs to be smaller
191
+#else
192
+  #define BLOCK_BUFFER_SIZE 16 // maximize block buffer
193
+#endif
194
+
195
+
196
+//The ASCII buffer for recieving from the serial:
197
+#define MAX_CMD_SIZE 96
198
+#define BUFSIZE 4
199
+
200
+
201
+// Firmware based and LCD controled retract
202
+// M207 and M208 can be used to define parameters for the retraction. 
203
+// The retraction can be called by the slicer using G10 and G11
204
+// until then, intended retractions can be detected by moves that only extrude and the direction. 
205
+// the moves are than replaced by the firmware controlled ones.
206
+
207
+// #define FWRETRACT  //ONLY PARTIALLY TESTED
208
+#define MIN_RETRACT 0.1 //minimum extruded mm to accept a automatic gcode retraction attempt
209
+
210
+//===========================================================================
211
+//=============================  Define Defines  ============================
212
+//===========================================================================
213
+
214
+#if TEMP_SENSOR_0 > 0
215
+  #define THERMISTORHEATER_0 TEMP_SENSOR_0
216
+  #define HEATER_0_USES_THERMISTOR
217
+#endif
218
+#if TEMP_SENSOR_1 > 0
219
+  #define THERMISTORHEATER_1 TEMP_SENSOR_1
220
+  #define HEATER_1_USES_THERMISTOR
221
+#endif
222
+#if TEMP_SENSOR_2 > 0
223
+  #define THERMISTORHEATER_2 TEMP_SENSOR_2
224
+  #define HEATER_2_USES_THERMISTOR
225
+#endif
226
+#if TEMP_SENSOR_BED > 0
227
+  #define THERMISTORBED TEMP_SENSOR_BED
228
+  #define BED_USES_THERMISTOR
229
+#endif
230
+#if TEMP_SENSOR_0 == -1
231
+  #define HEATER_0_USES_AD595
232
+#endif
233
+#if TEMP_SENSOR_1 == -1
234
+  #define HEATER_1_USES_AD595
235
+#endif
236
+#if TEMP_SENSOR_2 == -1
237
+  #define HEATER_2_USES_AD595
238
+#endif
239
+#if TEMP_SENSOR_BED == -1
240
+  #define BED_USES_AD595
241
+#endif
242
+#if TEMP_SENSOR_0 == -2
243
+  #define HEATER_0_USES_MAX6675
244
+#endif
245
+#if TEMP_SENSOR_0 == 0
246
+  #undef HEATER_0_MINTEMP
247
+  #undef HEATER_0_MAXTEMP
248
+#endif
249
+#if TEMP_SENSOR_1 == 0
250
+  #undef HEATER_1_MINTEMP
251
+  #undef HEATER_1_MAXTEMP
252
+#endif
253
+#if TEMP_SENSOR_2 == 0
254
+  #undef HEATER_2_MINTEMP
255
+  #undef HEATER_2_MAXTEMP
256
+#endif
257
+#if TEMP_SENSOR_BED == 0
258
+  #undef BED_MINTEMP
259
+  #undef BED_MAXTEMP
260
+#endif
261
+
262
+
263
+#endif //__CONFIGURATION_ADV_H

+ 232
- 0
Marlin/Marlin/EEPROMwrite.h Переглянути файл

1
+#ifndef EEPROM_H
2
+#define EEPROM_H
3
+
4
+#include "Marlin.h"
5
+#include "planner.h"
6
+#include "temperature.h"
7
+//#include <EEPROM.h>
8
+
9
+int plaPreheatHotendTemp;
10
+int plaPreheatHPBTemp;
11
+int plaPreheatFanSpeed;
12
+
13
+int absPreheatHotendTemp;
14
+int absPreheatHPBTemp;
15
+int absPreheatFanSpeed;
16
+
17
+template <class T> int EEPROM_writeAnything(int &ee, const T& value)
18
+{
19
+  const byte* p = (const byte*)(const void*)&value;
20
+  int i;
21
+  for (i = 0; i < (int)sizeof(value); i++)
22
+    eeprom_write_byte((unsigned char *)ee++, *p++);
23
+  return i;
24
+}
25
+
26
+template <class T> int EEPROM_readAnything(int &ee, T& value)
27
+{
28
+  byte* p = (byte*)(void*)&value;
29
+  int i;
30
+  for (i = 0; i < (int)sizeof(value); i++)
31
+    *p++ = eeprom_read_byte((unsigned char *)ee++);
32
+  return i;
33
+}
34
+//======================================================================================
35
+
36
+
37
+
38
+
39
+#define EEPROM_OFFSET 100
40
+
41
+
42
+// IMPORTANT:  Whenever there are changes made to the variables stored in EEPROM
43
+// in the functions below, also increment the version number. This makes sure that
44
+// the default values are used whenever there is a change to the data, to prevent
45
+// wrong data being written to the variables.
46
+// ALSO:  always make sure the variables in the Store and retrieve sections are in the same order.
47
+#define EEPROM_VERSION "V07"
48
+
49
+inline void EEPROM_StoreSettings() 
50
+{
51
+#ifdef EEPROM_SETTINGS
52
+  char ver[4]= "000";
53
+  int i=EEPROM_OFFSET;
54
+  EEPROM_writeAnything(i,ver); // invalidate data first 
55
+  EEPROM_writeAnything(i,axis_steps_per_unit);  
56
+  EEPROM_writeAnything(i,max_feedrate);  
57
+  EEPROM_writeAnything(i,max_acceleration_units_per_sq_second);
58
+  EEPROM_writeAnything(i,acceleration);
59
+  EEPROM_writeAnything(i,retract_acceleration);
60
+  EEPROM_writeAnything(i,minimumfeedrate);
61
+  EEPROM_writeAnything(i,mintravelfeedrate);
62
+  EEPROM_writeAnything(i,minsegmenttime);
63
+  EEPROM_writeAnything(i,max_xy_jerk);
64
+  EEPROM_writeAnything(i,max_z_jerk);
65
+  EEPROM_writeAnything(i,max_e_jerk);
66
+  EEPROM_writeAnything(i,add_homeing);
67
+  EEPROM_writeAnything(i,plaPreheatHotendTemp);
68
+  EEPROM_writeAnything(i,plaPreheatHPBTemp);
69
+  EEPROM_writeAnything(i,plaPreheatFanSpeed);
70
+  EEPROM_writeAnything(i,absPreheatHotendTemp);
71
+  EEPROM_writeAnything(i,absPreheatHPBTemp);
72
+  EEPROM_writeAnything(i,absPreheatFanSpeed);
73
+  #ifdef PIDTEMP
74
+    EEPROM_writeAnything(i,Kp);
75
+    EEPROM_writeAnything(i,Ki);
76
+    EEPROM_writeAnything(i,Kd);
77
+  #else
78
+    EEPROM_writeAnything(i,3000);
79
+    EEPROM_writeAnything(i,0);
80
+    EEPROM_writeAnything(i,0);
81
+  #endif
82
+  char ver2[4]=EEPROM_VERSION;
83
+  i=EEPROM_OFFSET;
84
+  EEPROM_writeAnything(i,ver2); // validate data
85
+  SERIAL_ECHO_START;
86
+  SERIAL_ECHOLNPGM("Settings Stored");
87
+#endif //EEPROM_SETTINGS
88
+}
89
+
90
+
91
+inline void EEPROM_printSettings()
92
+{  // if def=true, the default values will be used
93
+//  #ifdef EEPROM_SETTINGS  
94
+      SERIAL_ECHO_START;
95
+      SERIAL_ECHOLNPGM("Steps per unit:");
96
+      SERIAL_ECHO_START;
97
+      SERIAL_ECHOPAIR("  M92 X",axis_steps_per_unit[0]);
98
+      SERIAL_ECHOPAIR(" Y",axis_steps_per_unit[1]);
99
+      SERIAL_ECHOPAIR(" Z",axis_steps_per_unit[2]);
100
+      SERIAL_ECHOPAIR(" E",axis_steps_per_unit[3]);
101
+      SERIAL_ECHOLN("");
102
+      
103
+    SERIAL_ECHO_START;
104
+      SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
105
+      SERIAL_ECHO_START;
106
+      SERIAL_ECHOPAIR("  M203 X",max_feedrate[0]);
107
+      SERIAL_ECHOPAIR(" Y",max_feedrate[1] ); 
108
+      SERIAL_ECHOPAIR(" Z", max_feedrate[2] ); 
109
+      SERIAL_ECHOPAIR(" E", max_feedrate[3]);
110
+      SERIAL_ECHOLN("");
111
+    SERIAL_ECHO_START;
112
+      SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
113
+      SERIAL_ECHO_START;
114
+      SERIAL_ECHOPAIR("  M201 X" ,max_acceleration_units_per_sq_second[0] ); 
115
+      SERIAL_ECHOPAIR(" Y" , max_acceleration_units_per_sq_second[1] ); 
116
+      SERIAL_ECHOPAIR(" Z" ,max_acceleration_units_per_sq_second[2] );
117
+      SERIAL_ECHOPAIR(" E" ,max_acceleration_units_per_sq_second[3]);
118
+      SERIAL_ECHOLN("");
119
+    SERIAL_ECHO_START;
120
+      SERIAL_ECHOLNPGM("Acceleration: S=acceleration, T=retract acceleration");
121
+      SERIAL_ECHO_START;
122
+      SERIAL_ECHOPAIR("  M204 S",acceleration ); 
123
+      SERIAL_ECHOPAIR(" T" ,retract_acceleration);
124
+      SERIAL_ECHOLN("");
125
+    SERIAL_ECHO_START;
126
+      SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum xY jerk (mm/s),  Z=maximum Z jerk (mm/s)");
127
+      SERIAL_ECHO_START;
128
+      SERIAL_ECHOPAIR("  M205 S",minimumfeedrate ); 
129
+      SERIAL_ECHOPAIR(" T" ,mintravelfeedrate ); 
130
+      SERIAL_ECHOPAIR(" B" ,minsegmenttime ); 
131
+      SERIAL_ECHOPAIR(" X" ,max_xy_jerk ); 
132
+      SERIAL_ECHOPAIR(" Z" ,max_z_jerk);
133
+      SERIAL_ECHOPAIR(" E" ,max_e_jerk);
134
+      SERIAL_ECHOLN(""); 
135
+    SERIAL_ECHO_START;
136
+      SERIAL_ECHOLNPGM("Home offset (mm):");
137
+      SERIAL_ECHO_START;
138
+      SERIAL_ECHOPAIR("  M206 X",add_homeing[0] );
139
+      SERIAL_ECHOPAIR(" Y" ,add_homeing[1] );
140
+      SERIAL_ECHOPAIR(" Z" ,add_homeing[2] );
141
+      SERIAL_ECHOLN("");
142
+    #ifdef PIDTEMP
143
+      SERIAL_ECHO_START;
144
+      SERIAL_ECHOLNPGM("PID settings:");
145
+      SERIAL_ECHO_START;
146
+      SERIAL_ECHOPAIR("   M301 P",Kp); 
147
+      SERIAL_ECHOPAIR(" I" ,Ki/PID_dT); 
148
+      SERIAL_ECHOPAIR(" D" ,Kd*PID_dT);
149
+      SERIAL_ECHOLN(""); 
150
+    #endif
151
+//  #endif
152
+} 
153
+
154
+
155
+inline void EEPROM_RetrieveSettings(bool def=false)
156
+{  // if def=true, the default values will be used
157
+  #ifdef EEPROM_SETTINGS
158
+    int i=EEPROM_OFFSET;
159
+    char stored_ver[4];
160
+    char ver[4]=EEPROM_VERSION;
161
+    EEPROM_readAnything(i,stored_ver); //read stored version
162
+    //  SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
163
+    if ((!def)&&(strncmp(ver,stored_ver,3)==0)) 
164
+    {   // version number match
165
+      EEPROM_readAnything(i,axis_steps_per_unit);  
166
+      EEPROM_readAnything(i,max_feedrate);  
167
+      EEPROM_readAnything(i,max_acceleration_units_per_sq_second);
168
+      EEPROM_readAnything(i,acceleration);
169
+      EEPROM_readAnything(i,retract_acceleration);
170
+      EEPROM_readAnything(i,minimumfeedrate);
171
+      EEPROM_readAnything(i,mintravelfeedrate);
172
+      EEPROM_readAnything(i,minsegmenttime);
173
+      EEPROM_readAnything(i,max_xy_jerk);
174
+      EEPROM_readAnything(i,max_z_jerk);
175
+      EEPROM_readAnything(i,max_e_jerk);
176
+      EEPROM_readAnything(i,add_homeing);
177
+	  EEPROM_readAnything(i,plaPreheatHotendTemp);
178
+	  EEPROM_readAnything(i,plaPreheatHPBTemp);
179
+	  EEPROM_readAnything(i,plaPreheatFanSpeed);
180
+	  EEPROM_readAnything(i,absPreheatHotendTemp);
181
+	  EEPROM_readAnything(i,absPreheatHPBTemp);
182
+	  EEPROM_readAnything(i,absPreheatFanSpeed);
183
+      #ifndef PIDTEMP
184
+        float Kp,Ki,Kd;
185
+      #endif
186
+      EEPROM_readAnything(i,Kp);
187
+      EEPROM_readAnything(i,Ki);
188
+      EEPROM_readAnything(i,Kd);
189
+
190
+      SERIAL_ECHO_START;
191
+      SERIAL_ECHOLNPGM("Stored settings retreived:");
192
+    }
193
+    else 
194
+  #endif
195
+    {
196
+      float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
197
+      float tmp2[]=DEFAULT_MAX_FEEDRATE;
198
+      long tmp3[]=DEFAULT_MAX_ACCELERATION;
199
+      for (short i=0;i<4;i++) 
200
+      {
201
+        axis_steps_per_unit[i]=tmp1[i];  
202
+        max_feedrate[i]=tmp2[i];  
203
+        max_acceleration_units_per_sq_second[i]=tmp3[i];
204
+      }
205
+      acceleration=DEFAULT_ACCELERATION;
206
+      retract_acceleration=DEFAULT_RETRACT_ACCELERATION;
207
+      minimumfeedrate=DEFAULT_MINIMUMFEEDRATE;
208
+      minsegmenttime=DEFAULT_MINSEGMENTTIME;       
209
+      mintravelfeedrate=DEFAULT_MINTRAVELFEEDRATE;
210
+      max_xy_jerk=DEFAULT_XYJERK;
211
+      max_z_jerk=DEFAULT_ZJERK;
212
+      max_e_jerk=DEFAULT_EJERK;
213
+      add_homeing[0] = add_homeing[1] = add_homeing[2] = 0;
214
+      SERIAL_ECHO_START;
215
+      SERIAL_ECHOLN("Using Default settings:");
216
+#ifdef ULTIPANEL
217
+	  plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP;
218
+	  plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP;
219
+	  plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
220
+	  absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP;
221
+	  absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
222
+	  absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
223
+#endif
224
+    }
225
+  #ifdef EEPROM_CHITCHAT
226
+    EEPROM_printSettings();
227
+  #endif
228
+}  
229
+
230
+#endif
231
+
232
+

+ 101
- 0
Marlin/Marlin/Gen7/boards.txt Переглянути файл

1
+##############################################################
2
+
3
+Gen7-644-16.name=Gen7 with ATmega644 and 16 MHz
4
+Gen7-644-16.upload.protocol=stk500v2
5
+Gen7-644-16.upload.maximum_size=63488
6
+Gen7-644-16.upload.speed=115200
7
+Gen7-644-16.bootloader.low_fuses=0xF7
8
+Gen7-644-16.bootloader.high_fuses=0xD4
9
+Gen7-644-16.bootloader.extended_fuses=0xFD
10
+Gen7-644-16.bootloader.path=Gen7
11
+Gen7-644-16.bootloader.file=bootloader-644-16MHz.hex
12
+Gen7-644-16.bootloader.unlock_bits=0x3F
13
+Gen7-644-16.bootloader.lock_bits=0x0F
14
+Gen7-644-16.build.mcu=atmega644
15
+Gen7-644-16.build.f_cpu=16000000L
16
+Gen7-644-16.build.core=arduino
17
+
18
+##############################################################
19
+
20
+Gen7-644-20.name=Gen7 with ATmega644 and 20 MHz
21
+Gen7-644-20.upload.protocol=stk500v2
22
+Gen7-644-20.upload.maximum_size=63488
23
+Gen7-644-20.upload.speed=115200
24
+Gen7-644-20.bootloader.low_fuses=0xF7
25
+Gen7-644-20.bootloader.high_fuses=0xD4
26
+Gen7-644-20.bootloader.extended_fuses=0xFD
27
+Gen7-644-20.bootloader.path=Gen7
28
+Gen7-644-20.bootloader.file=bootloader-644-20MHz.hex
29
+Gen7-644-20.bootloader.unlock_bits=0x3F
30
+Gen7-644-20.bootloader.lock_bits=0x0F
31
+Gen7-644-20.build.mcu=atmega644
32
+Gen7-644-20.build.f_cpu=20000000L
33
+Gen7-644-20.build.core=arduino
34
+
35
+##############################################################
36
+
37
+Gen7-644P-16.name=Gen7 with ATmega644P and 16 MHz
38
+Gen7-644P-16.upload.protocol=stk500v2
39
+Gen7-644P-16.upload.maximum_size=63488
40
+Gen7-644P-16.upload.speed=115200
41
+Gen7-644P-16.bootloader.low_fuses=0xF7
42
+Gen7-644P-16.bootloader.high_fuses=0xD4
43
+Gen7-644P-16.bootloader.extended_fuses=0xFD
44
+Gen7-644P-16.bootloader.path=Gen7
45
+Gen7-644P-16.bootloader.file=bootloader-644P-16MHz.hex
46
+Gen7-644P-16.bootloader.unlock_bits=0x3F
47
+Gen7-644P-16.bootloader.lock_bits=0x0F
48
+Gen7-644P-16.build.mcu=atmega644p
49
+Gen7-644P-16.build.f_cpu=16000000L
50
+Gen7-644P-16.build.core=arduino
51
+
52
+##############################################################
53
+
54
+Gen7-644P-20.name=Gen7 with ATmega644P and 20 MHz
55
+Gen7-644P-20.upload.protocol=stk500v2
56
+Gen7-644P-20.upload.maximum_size=63488
57
+Gen7-644P-20.upload.speed=115200
58
+Gen7-644P-20.bootloader.low_fuses=0xF7
59
+Gen7-644P-20.bootloader.high_fuses=0xD4
60
+Gen7-644P-20.bootloader.extended_fuses=0xFD
61
+Gen7-644P-20.bootloader.path=Gen7
62
+Gen7-644P-20.bootloader.file=bootloader-644P-20MHz.hex
63
+Gen7-644P-20.bootloader.unlock_bits=0x3F
64
+Gen7-644P-20.bootloader.lock_bits=0x0F
65
+Gen7-644P-20.build.mcu=atmega644p
66
+Gen7-644P-20.build.f_cpu=20000000L
67
+Gen7-644P-20.build.core=arduino
68
+
69
+##############################################################
70
+
71
+Gen7-1284p-16.name=Gen7 with ATmega1284 and 16 MHz
72
+Gen7-1284p-16.upload.protocol=stk500v2
73
+Gen7-1284p-16.upload.maximum_size=129024
74
+Gen7-1284p-16.upload.speed=115200
75
+Gen7-1284p-16.bootloader.low_fuses=0xF7
76
+Gen7-1284p-16.bootloader.high_fuses=0xD4
77
+Gen7-1284p-16.bootloader.extended_fuses=0xFD
78
+Gen7-1284p-16.bootloader.path=Gen7
79
+Gen7-1284p-16.bootloader.file=bootloader-1284P-16MHz.hex
80
+Gen7-1284p-16.bootloader.unlock_bits=0x3F
81
+Gen7-1284p-16.bootloader.lock_bits=0x2F
82
+Gen7-1284p-16.build.mcu=atmega1284p
83
+Gen7-1284p-16.build.f_cpu=16000000L
84
+Gen7-1284p-16.build.core=arduino
85
+
86
+##############################################################
87
+
88
+Gen7-1284p-20.name=Gen7 with ATmega1284 and 20 MHz
89
+Gen7-1284p-20.upload.protocol=stk500v2
90
+Gen7-1284p-20.upload.maximum_size=129024
91
+Gen7-1284p-20.upload.speed=115200
92
+Gen7-1284p-20.bootloader.low_fuses=0xF7
93
+Gen7-1284p-20.bootloader.high_fuses=0xD4
94
+Gen7-1284p-20.bootloader.extended_fuses=0xFD
95
+Gen7-1284p-20.bootloader.path=Gen7
96
+Gen7-1284p-20.bootloader.file=bootloader-1284P-16MHz.hex
97
+Gen7-1284p-20.bootloader.unlock_bits=0x3F
98
+Gen7-1284p-20.bootloader.lock_bits=0x2F
99
+Gen7-1284p-20.build.mcu=atmega1284p
100
+Gen7-1284p-20.build.f_cpu=20000000L
101
+Gen7-1284p-20.build.core=arduino

+ 113
- 0
Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-1284P-16MHz.hex Переглянути файл

1
+:020000021000EC
2
+:10F8000011241FBE8FEF90E49EBF8DBF01C32F92C6
3
+:10F810003F924F925F926F927F928F929F92AF92A0
4
+:10F82000BF92CF92DF92EF92FF920F931F93DF93DD
5
+:10F83000CF93CDB7DEB7C252D1400FB6F894DEBF3A
6
+:10F840000FBECDBF44245524DD24C25EDE4F188296
7
+:10F85000CE51D1408824992454013AC20E9428FFF5
8
+:10F86000282F133059F1143028F4113081F0123060
9
+:10F8700000F507C0153081F1153030F1163071F701
10
+:10F880003DC08B3159F711E05BE1D52EE7CF8130D8
11
+:10F8900041F0C25EDE4F3881CE51D140831709F06E
12
+:10F8A00019C2D226C25EDE4F2883CE51D14012E06B
13
+:10F8B000D5CFF82EEE24D82613E0D0CF90E0E82A5A
14
+:10F8C000F92AD22614E0CACF8E3009F003C2D82616
15
+:10F8D00015E044245524C2CFE1E0F0E0EC0FFD1F19
16
+:10F8E000E40DF51D80830894411C511CD8264E144C
17
+:10F8F0005F0409F0B3CF720116E0B0CF8D1509F0A7
18
+:10F90000E9C1EAC1CC2447C08D81803311F090E079
19
+:10F910000AC08F81882311F49EE105C0813011F067
20
+:10F9200095E001C097E91A821B828D818C838E81BC
21
+:10F930008D839E831F8247E0E42EF12C88C11A82BA
22
+:10F9400068E06B8383E58C8394E59D83EBE4EE8331
23
+:10F9500085E38F8380E3888789878FE58A8782E3C1
24
+:10F960008B873BE0E32EF12C72C18A81813941F013
25
+:10F97000823941F0803911F48FE005C080E003C086
26
+:10F9800082E001C08AE01A828B8323E0E22EF12C10
27
+:10F990005EC1CC24C3941A8292E0E92EF12C58C1A6
28
+:10F9A0008D81882311F48EE128C0813011F085E02B
29
+:10F9B00024C087E922C01A8229E0E1E0F0E0209328
30
+:10F9C000570084911BC08B81803589F48C818830ED
31
+:10F9D00039F439E0E2E0F0E03093570084910DC053
32
+:10F9E00069E0E0E0F0E060935700849106C099E0A0
33
+:10F9F000E3E0F0E09093570084911A828B831C829D
34
+:10FA000084E0E82EF12C23C18A8190E0A0E0B0E0F0
35
+:10FA1000B82EAA24992488248B8190E0A0E0B0E03D
36
+:10FA2000DC0199278827882A992AAA2ABB2A8D814E
37
+:10FA300090E0A0E0B0E0882A992AAA2ABB2A8C810B
38
+:10FA400090E0A0E0B0E0BA2FA92F982F8827882A4D
39
+:10FA5000992AAA2ABB2A88C0EA81C05EDE4FE883C1
40
+:10FA6000C052D140C15EDE4F1882CF51D1408B8150
41
+:10FA7000A82FB0E0C15EDE4F28813981CF51D1403F
42
+:10FA8000A22BB32B933109F042C075016401CC0C59
43
+:10FA9000DD1CEE1CFF1C33E0F601E0925B003093AE
44
+:10FAA0005700E89507B600FCFDCF8E01055F1F4F9C
45
+:10FAB000F801808161810E5F1F4FA5019401220F23
46
+:10FAC000331F441F551F362E222490E0822993298C
47
+:10FAD00061E00C01F90140935B0060935700E895E9
48
+:10FAE00011240894811C911CA11CB11C129701F7D0
49
+:10FAF00085E0F601E0925B0080935700E89507B639
50
+:10FB000000FCFDCF81E180935700E8952DC0FE01F8
51
+:10FB10003B9620E030E040E050E011977D0100E0AE
52
+:10FB200010E00894E11CF11C011D111D6081F99980
53
+:10FB3000FECF1FBAC901880D991D92BD81BD60BD60
54
+:10FB40000FB6F894FA9AF99A0FBE2F5F3F4F4F4FB6
55
+:10FB50005F4F2E153F054007510711F03196E6CF54
56
+:10FB6000820E931EA41EB51E1A826EC09A81CE5DAF
57
+:10FB7000DE4F9883C252D140CF5DDE4F1882C15212
58
+:10FB8000D1408B81C82EDD24CF5DDE4FE881F98125
59
+:10FB9000C152D140CE2ADF2A1A8289818431E1F410
60
+:10FBA0009601BE016D5F7F4FD501C401880F991F7B
61
+:10FBB000AA1FBB1FABBFFC0187919691FB018083FD
62
+:10FBC00091836E5F7F4F0894811C911CA11CB11C16
63
+:10FBD0002250304049F72EC0BE016D5F7F4F20E0BC
64
+:10FBE00030E040E050E00894C108D108760100E020
65
+:10FBF00010E00894C11CD11C0894E11CF11C011DEB
66
+:10FC0000111DF999FECFC901880D991D92BD81BDC5
67
+:10FC1000F89A80B5FB018193BF012F5F3F4F4F4F93
68
+:10FC20005F4F2E153F054007510759F7820E931E6F
69
+:10FC3000A41EB51E23E0E22EF12CEC0CFD1CFB01F2
70
+:10FC4000108205C080EC8A8392E0E92EF12CCC244E
71
+:10FC50008BE10E94C7FEC25EDE4F8881CE51D1404B
72
+:10FC60000E94C7FE8F2D0E94C7FE8E2D0E94C7FEE8
73
+:10FC70008EE00E94C7FE85E1D82EC25EDE4FF8817D
74
+:10FC8000CE51D140DF26DE24DF243E010894611CE2
75
+:10FC9000711C0AC0F30111913F01812F0E94C7FE20
76
+:10FCA000D1260894E108F108E114F10499F78D2DAB
77
+:10FCB0000E94C7FECC2009F044C0C25EDE4FF8812E
78
+:10FCC000CE51D140FF5FC25EDE4FF883CE51D140AE
79
+:10FCD000EE24FF2410E0C2CD9981933109F4BCCE0B
80
+:10FCE0009431B0F4933009F440CE943038F491302C
81
+:10FCF00009F425CE923009F0A5CF04CE903109F455
82
+:10FD000001CE913109F445CE963009F09BCF7CCEDF
83
+:10FD1000983109F458CE993150F4953109F49CCEBC
84
+:10FD2000953108F423CF963109F08CCF1FCF9B314A
85
+:10FD300009F436CE9D3109F4E7CD9A3109F082CF2E
86
+:10FD40003ACECE5DDE4F0FB6F894DEBF0FBECDBF0C
87
+:10FD5000CF91DF911F910F91FF90EF90DF90CF90A7
88
+:10FD6000BF90AF909F908F907F906F905F904F90DB
89
+:10FD70003F902F9008958091C00087FFFCCF089599
90
+:10FD80008091C00087FFFCCF8091C6000895982F16
91
+:10FD90008091C00085FFFCCF9093C60008959B0121
92
+:10FDA000AC0197FF11C08091C00082608093C000B9
93
+:10FDB00050954095309521953F4F4F4F5F4F60E0F4
94
+:10FDC00074E284EF90E009C08091C0008D7F809341
95
+:10FDD000C00060E072E18AE790E00E9447FF2C5F7C
96
+:10FDE0003F4F4F4F5F4F83E0569547953795279587
97
+:10FDF0008A95D1F7215030403093C5002093C4003C
98
+:10FE0000089518B817B81F921F921F920895FFCF38
99
+:10FE100084B714BE90E083709070892B39F418B8C1
100
+:10FE200017B81F921F921F920895FFCF88E1809309
101
+:10FE3000C10060E07EE38EEF9FEF0E94CFFE0E9444
102
+:10FE400007FC18B817B81F921F921F920895FFCF92
103
+:10FE500020E030E040E050E013C02F5F3F4F4F4FB5
104
+:10FE60005F4F21308AE6380788E1480780E058076D
105
+:10FE700039F418B817B81F921F921F920895FFCF38
106
+:10FE80008091C00087FFE9CF0E94C0FE0895A1E2E3
107
+:10FE90001A2EAA1BBB1BFD010DC0AA1FBB1FEE1F04
108
+:10FEA000FF1FA217B307E407F50720F0A21BB30B4F
109
+:10FEB000E40BF50B661F771F881F991F1A9469F7CB
110
+:10FEC00060957095809590959B01AC01BD01CF0127
111
+:02FED000089593
112
+:040000031000F800F1
113
+:00000001FF

+ 75
- 0
Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-644-16MHz.hex Переглянути файл

1
+:10F800008FEF90E19EBF8DBF11241FBE5A9A00C09A
2
+:10F81000CDB7DEB7CD51D140DEBFCDBF1092C50010
3
+:10F8200088E08093C40088E18093C100EE24FF2427
4
+:10F8300020E0552400E010E039E0432E9BE0292E23
5
+:10F84000312C2C0E3D1ECFC14150504060407040C5
6
+:10F8500011F43FE206C08091C00087FFF5CF3091E0
7
+:10F86000C600933021F1943028F4913099F0923011
8
+:10F87000C8F407C0953049F1953000F19630D1F5C4
9
+:10F8800035C03B3119F491E02BE134C03F3291F5A2
10
+:10F890003983BBC1313011F0351559F52327532E6B
11
+:10F8A00092E028C0B32FA0E0232793E023C0832F4A
12
+:10F8B00090E0A82BB92B232794E01CC03E30C9F45C
13
+:10F8C000232795E0EE24FF2415C0E1E0F0E0EC0FE3
14
+:10F8D000FD1FEE0DFF1D30830894E11CF11C232752
15
+:10F8E000EA16FB0639F4D70196E004C0321709F492
16
+:10F8F0008CC190E044E755E962E470E0ACCF90E061
17
+:10F9000044C08D81803311F090E00AC08F8188233C
18
+:10F9100011F49EE105C0813011F099E001C096E933
19
+:10F920001A821B828D818C838E818D839E831F82A0
20
+:10F9300047E050E0F4C01A8288E08B8381E48C8336
21
+:10F9400086E58D8382E58E8389E48F8383E58887CE
22
+:10F9500080E589878FE58A8782E38B874BE050E0DB
23
+:10F96000DEC08A81813941F0823941F0803911F459
24
+:10F970008FE005C080E003C082E001C08AE01A8207
25
+:10F980008B8343E050E0CBC091E01A8242E050E02C
26
+:10F99000C7C08D81882311F48EE124C0813011F01D
27
+:10F9A00089E020C086E91EC01A82E1E0F0E04092C2
28
+:10F9B0005700849118C08B81803579F48C81883010
29
+:10F9C00031F4E2E0F0E04092570084910BC0E0E0B7
30
+:10F9D000F0E040925700849105C0E3E0F0E04092EF
31
+:10F9E000570084911A828B831C8244E050E097C0B8
32
+:10F9F000BC80AA248D81082F10E00A291B29000F42
33
+:10FA0000111F1A828AC09A8088248B81682F70E027
34
+:10FA100068297929933109F033C0F7EF0F3F1F07A9
35
+:10FA200010F0A8013FC023E0F80120935700E895AB
36
+:10FA300007B600FCFDCFA801D1018C9111962C9145
37
+:10FA400011971296D22ECC2490E08C299D2921E08A
38
+:10FA5000FA010C0120935700E89511244E5F5F4F87
39
+:10FA60006250704051F725E0F80120935700E89567
40
+:10FA700007B600FCFDCF81E180935700E89512C0E6
41
+:10FA8000A801FB01D10141BD52BD4F5F5F4F8D9178
42
+:10FA900080BDFA9AF99AF999FECF3197A1F7A8019A
43
+:10FAA000460F571F1A828A0138C07A8066248B81DC
44
+:10FAB000A82FB0E0A629B7291A828981843191F450
45
+:10FAC000BD019E012D5F3F4FF80185919491F90191
46
+:10FAD000808391832E5F3F4F0E5F1F4F62507040B7
47
+:10FAE00099F713C0A801BD019E012D5F3F4F41BD95
48
+:10FAF00052BD4F5F5F4FF89A80B5F90181939F0126
49
+:10FB000061507040A1F70A0F1B1FAD014D5F5F4FA1
50
+:10FB1000F901108204C080EC8A8342E050E090E05A
51
+:10FB2000FBE1F093C6008091C00086FFFCCF80917E
52
+:10FB3000C00080648093C0005092C6008091C000D5
53
+:10FB400086FFFCCF8091C00080648093C000652F49
54
+:10FB50005093C6008091C00086FFFCCF8091C0000A
55
+:10FB600080648093C000342F4093C6008091C00011
56
+:10FB700086FFFCCF8091C00080648093C0008EE03F
57
+:10FB80008093C6008091C00086FFFCCF8091C000AA
58
+:10FB900080648093C00025E1252523272627FE01C8
59
+:10FBA000319610C030813093C6008091C00086FF2E
60
+:10FBB000FCCF31968091C00080648093C0002327E1
61
+:10FBC000415050404115510569F72093C60080917E
62
+:10FBD000C00086FFFCCF8091C00080648093C0008D
63
+:10FBE000992349F4539444E755E962E470E090E0C6
64
+:10FBF000A0E0B0E030CE5A9881E180935700E895BC
65
+:10FC000011241F921F920895FFCF9981933109F417
66
+:10FC1000FACE9431C8F4963009F4EACE973050F415
67
+:10FC2000923009F46CCE933009F49BCE913009F0F8
68
+:10FC300072CF81CE913109F4A7CE923108F0E1CE96
69
+:10FC4000903109F068CF5BCE983109F4B4CE993188
70
+:10FC500050F4953109F4D7CE953108F426CF96317A
71
+:10FC600009F059CF22CF9B3109F493CE9C3120F477
72
+:10FC70009A3109F050CF98CE9D3109F442CE9F328F
73
+:06FC800009F049CFB8CFE6
74
+:040000030000F80001
75
+:00000001FF

+ 75
- 0
Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-644-20MHz.hex Переглянути файл

1
+:10F800008FEF90E19EBF8DBF11241FBE5A9A00C09A
2
+:10F81000CDB7DEB7CD51D140DEBFCDBF1092C50010
3
+:10F820008AE08093C40088E18093C100EE24FF2425
4
+:10F8300020E0552400E010E039E0432E9BE0292E23
5
+:10F84000312C2C0E3D1ECFC14150504060407040C5
6
+:10F8500011F43FE206C08091C00087FFF5CF3091E0
7
+:10F86000C600933021F1943028F4913099F0923011
8
+:10F87000C8F407C0953049F1953000F19630D1F5C4
9
+:10F8800035C03B3119F491E02BE134C03F3291F5A2
10
+:10F890003983BBC1313011F0351559F52327532E6B
11
+:10F8A00092E028C0B32FA0E0232793E023C0832F4A
12
+:10F8B00090E0A82BB92B232794E01CC03E30C9F45C
13
+:10F8C000232795E0EE24FF2415C0E1E0F0E0EC0FE3
14
+:10F8D000FD1FEE0DFF1D30830894E11CF11C232752
15
+:10F8E000EA16FB0639F4D70196E004C0321709F492
16
+:10F8F0008CC190E041ED5AE363E570E0ACCF90E05D
17
+:10F9000044C08D81803311F090E00AC08F8188233C
18
+:10F9100011F49EE105C0813011F099E001C096E933
19
+:10F920001A821B828D818C838E818D839E831F82A0
20
+:10F9300047E050E0F4C01A8288E08B8381E48C8336
21
+:10F9400086E58D8382E58E8389E48F8383E58887CE
22
+:10F9500080E589878FE58A8782E38B874BE050E0DB
23
+:10F96000DEC08A81813941F0823941F0803911F459
24
+:10F970008FE005C080E003C082E001C08AE01A8207
25
+:10F980008B8343E050E0CBC091E01A8242E050E02C
26
+:10F99000C7C08D81882311F48EE124C0813011F01D
27
+:10F9A00089E020C086E91EC01A82E1E0F0E04092C2
28
+:10F9B0005700849118C08B81803579F48C81883010
29
+:10F9C00031F4E2E0F0E04092570084910BC0E0E0B7
30
+:10F9D000F0E040925700849105C0E3E0F0E04092EF
31
+:10F9E000570084911A828B831C8244E050E097C0B8
32
+:10F9F000BC80AA248D81082F10E00A291B29000F42
33
+:10FA0000111F1A828AC09A8088248B81682F70E027
34
+:10FA100068297929933109F033C0F7EF0F3F1F07A9
35
+:10FA200010F0A8013FC023E0F80120935700E895AB
36
+:10FA300007B600FCFDCFA801D1018C9111962C9145
37
+:10FA400011971296D22ECC2490E08C299D2921E08A
38
+:10FA5000FA010C0120935700E89511244E5F5F4F87
39
+:10FA60006250704051F725E0F80120935700E89567
40
+:10FA700007B600FCFDCF81E180935700E89512C0E6
41
+:10FA8000A801FB01D10141BD52BD4F5F5F4F8D9178
42
+:10FA900080BDFA9AF99AF999FECF3197A1F7A8019A
43
+:10FAA000460F571F1A828A0138C07A8066248B81DC
44
+:10FAB000A82FB0E0A629B7291A828981843191F450
45
+:10FAC000BD019E012D5F3F4FF80185919491F90191
46
+:10FAD000808391832E5F3F4F0E5F1F4F62507040B7
47
+:10FAE00099F713C0A801BD019E012D5F3F4F41BD95
48
+:10FAF00052BD4F5F5F4FF89A80B5F90181939F0126
49
+:10FB000061507040A1F70A0F1B1FAD014D5F5F4FA1
50
+:10FB1000F901108204C080EC8A8342E050E090E05A
51
+:10FB2000FBE1F093C6008091C00086FFFCCF80917E
52
+:10FB3000C00080648093C0005092C6008091C000D5
53
+:10FB400086FFFCCF8091C00080648093C000652F49
54
+:10FB50005093C6008091C00086FFFCCF8091C0000A
55
+:10FB600080648093C000342F4093C6008091C00011
56
+:10FB700086FFFCCF8091C00080648093C0008EE03F
57
+:10FB80008093C6008091C00086FFFCCF8091C000AA
58
+:10FB900080648093C00025E1252523272627FE01C8
59
+:10FBA000319610C030813093C6008091C00086FF2E
60
+:10FBB000FCCF31968091C00080648093C0002327E1
61
+:10FBC000415050404115510569F72093C60080917E
62
+:10FBD000C00086FFFCCF8091C00080648093C0008D
63
+:10FBE000992349F4539441ED5AE363E570E090E0C2
64
+:10FBF000A0E0B0E030CE5A9881E180935700E895BC
65
+:10FC000011241F921F920895FFCF9981933109F417
66
+:10FC1000FACE9431C8F4963009F4EACE973050F415
67
+:10FC2000923009F46CCE933009F49BCE913009F0F8
68
+:10FC300072CF81CE913109F4A7CE923108F0E1CE96
69
+:10FC4000903109F068CF5BCE983109F4B4CE993188
70
+:10FC500050F4953109F4D7CE953108F426CF96317A
71
+:10FC600009F059CF22CF9B3109F493CE9C3120F477
72
+:10FC70009A3109F050CF98CE9D3109F442CE9F328F
73
+:06FC800009F049CFB8CFE6
74
+:040000030000F80001
75
+:00000001FF

+ 75
- 0
Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-644P-16MHz.hex Переглянути файл

1
+:10F800008FEF90E19EBF8DBF11241FBE5A9A00C09A
2
+:10F81000CDB7DEB7CD51D140DEBFCDBF1092C50010
3
+:10F8200088E08093C40088E18093C100EE24FF2427
4
+:10F8300020E0552400E010E039E0432E93E0292E2B
5
+:10F84000312C2C0E3D1ECDC14150504060407040C7
6
+:10F8500011F43FE206C08091C00087FFF5CF3091E0
7
+:10F86000C600933021F1943028F4913099F0923011
8
+:10F87000C8F407C0953049F1953000F19630D1F5C4
9
+:10F8800035C03B3119F491E02BE134C03F3291F5A2
10
+:10F890003983B9C1313011F0351559F52327532E6D
11
+:10F8A00092E028C0B32FA0E0232793E023C0832F4A
12
+:10F8B00090E0A82BB92B232794E01CC03E30C9F45C
13
+:10F8C000232795E0EE24FF2415C0E1E0F0E0EC0FE3
14
+:10F8D000FD1FEE0DFF1D30830894E11CF11C232752
15
+:10F8E000EA16FB0639F4D70196E004C0321709F492
16
+:10F8F0008AC190E044E755E962E470E0ACCF90E063
17
+:10F9000044C08D81803311F090E00AC08F8188233C
18
+:10F9100011F49EE105C0813011F09AE001C096E932
19
+:10F920001A821B828D818C838E818D839E831F82A0
20
+:10F9300047E050E0F2C01A8288E08B8381E48C8338
21
+:10F9400086E58D8382E58E8389E48F8383E58887CE
22
+:10F9500080E589878FE58A8782E38B874BE050E0DB
23
+:10F96000DCC08A81813941F0823941F0803911F45B
24
+:10F970008FE005C080E003C082E001C08AE01A8207
25
+:10F980008B8343E050E0C9C091E01A8242E050E02E
26
+:10F99000C5C08D81882311F48EE124C0813011F01F
27
+:10F9A0008AE020C086E91EC01A82E1E0F0E04092C1
28
+:10F9B0005700849118C08B81803579F48C81883010
29
+:10F9C00031F4E2E0F0E04092570084910BC0E0E0B7
30
+:10F9D000F0E040925700849105C0E3E0F0E04092EF
31
+:10F9E000570084911A828B831C8244E050E095C0BA
32
+:10F9F000BC80AA248D81082F10E00A291B29000F42
33
+:10FA0000111F1A8288C09A8088248B81682F70E029
34
+:10FA100068297929933109F034C0F7EF0F3F1F07A8
35
+:10FA200010F0A80141C023E0F80120935700E895A9
36
+:10FA300007B600FCFDCFA801DE011B968C91119644
37
+:10FA40002C9111971296D22ECC2490E08C299D29CE
38
+:10FA500021E0FA010C0120935700E89511244E5F34
39
+:10FA60005F4F6250704051F725E0F8012093570036
40
+:10FA7000E89507B600FCFDCF81E180935700E8953B
41
+:10FA800013C0A801FB01DE011B9641BD52BD4F5FB3
42
+:10FA90005F4F8D9180BDFA9AF99AF999FECF31970F
43
+:10FAA000A1F7A801460F571F1A828A0134C07A8035
44
+:10FAB00066248B81A82FB0E0A629B7291A828981F4
45
+:10FAC000843181F4BD019101F80185919491F9018E
46
+:10FAD000808391832E5F3F4F0E5F1F4F62507040B7
47
+:10FAE00099F711C0A801BD01910141BD52BD4F5F01
48
+:10FAF0005F4FF89A80B5F90181939F016150704082
49
+:10FB0000A1F70A0F1B1FAD014D5F5F4FF901108276
50
+:10FB100004C080EC8A8342E050E090E0FBE1F09387
51
+:10FB2000C6008091C00086FFFCCF8091C000806439
52
+:10FB30008093C0005092C6008091C00086FFFCCF29
53
+:10FB40008091C00080648093C000652F5093C600F0
54
+:10FB50008091C00086FFFCCF8091C00080648093BC
55
+:10FB6000C000342F4093C6008091C00086FFFCCFB8
56
+:10FB70008091C00080648093C0008EE08093C600B6
57
+:10FB80008091C00086FFFCCF8091C000806480938C
58
+:10FB9000C00025E1252523272627FE01319610C028
59
+:10FBA00030813093C6008091C00086FFFCCF319633
60
+:10FBB0008091C00080648093C00023274150504052
61
+:10FBC0004115510569F72093C6008091C00086FF5A
62
+:10FBD000FCCF8091C00080648093C000992349F4D9
63
+:10FBE000539444E755E962E470E090E0A0E0B0E0AF
64
+:10FBF00032CE5A9881E180935700E89511241F92E4
65
+:10FC00001F920895FFCF9981933109F4FCCE94316E
66
+:10FC1000C8F4963009F4ECCE973050F4923009F4E1
67
+:10FC20006ECE933009F49DCE913009F072CF83CE21
68
+:10FC3000913109F4A9CE923108F0E3CE903109F068
69
+:10FC400068CF5DCE983109F4B6CE993150F4953134
70
+:10FC500009F4D9CE953108F42ACF963109F059CF5D
71
+:10FC600026CF9B3109F495CE9C3120F49A3109F0CE
72
+:10FC700050CF9ACE9D3109F444CE9F3209F049CF3E
73
+:02FC8000B8CFFB
74
+:040000030000F80001
75
+:00000001FF

+ 75
- 0
Marlin/Marlin/Gen7/bootloaders/Gen7/bootloader-644P-20MHz.hex Переглянути файл

1
+:10F800008FEF90E19EBF8DBF11241FBE5A9A00C09A
2
+:10F81000CDB7DEB7CD51D140DEBFCDBF1092C50010
3
+:10F820008AE08093C40088E18093C100EE24FF2425
4
+:10F8300020E0552400E010E039E0432E93E0292E2B
5
+:10F84000312C2C0E3D1ECDC14150504060407040C7
6
+:10F8500011F43FE206C08091C00087FFF5CF3091E0
7
+:10F86000C600933021F1943028F4913099F0923011
8
+:10F87000C8F407C0953049F1953000F19630D1F5C4
9
+:10F8800035C03B3119F491E02BE134C03F3291F5A2
10
+:10F890003983B9C1313011F0351559F52327532E6D
11
+:10F8A00092E028C0B32FA0E0232793E023C0832F4A
12
+:10F8B00090E0A82BB92B232794E01CC03E30C9F45C
13
+:10F8C000232795E0EE24FF2415C0E1E0F0E0EC0FE3
14
+:10F8D000FD1FEE0DFF1D30830894E11CF11C232752
15
+:10F8E000EA16FB0639F4D70196E004C0321709F492
16
+:10F8F0008AC190E041ED5AE363E570E0ACCF90E05F
17
+:10F9000044C08D81803311F090E00AC08F8188233C
18
+:10F9100011F49EE105C0813011F09AE001C096E932
19
+:10F920001A821B828D818C838E818D839E831F82A0
20
+:10F9300047E050E0F2C01A8288E08B8381E48C8338
21
+:10F9400086E58D8382E58E8389E48F8383E58887CE
22
+:10F9500080E589878FE58A8782E38B874BE050E0DB
23
+:10F96000DCC08A81813941F0823941F0803911F45B
24
+:10F970008FE005C080E003C082E001C08AE01A8207
25
+:10F980008B8343E050E0C9C091E01A8242E050E02E
26
+:10F99000C5C08D81882311F48EE124C0813011F01F
27
+:10F9A0008AE020C086E91EC01A82E1E0F0E04092C1
28
+:10F9B0005700849118C08B81803579F48C81883010
29
+:10F9C00031F4E2E0F0E04092570084910BC0E0E0B7
30
+:10F9D000F0E040925700849105C0E3E0F0E04092EF
31
+:10F9E000570084911A828B831C8244E050E095C0BA
32
+:10F9F000BC80AA248D81082F10E00A291B29000F42
33
+:10FA0000111F1A8288C09A8088248B81682F70E029
34
+:10FA100068297929933109F034C0F7EF0F3F1F07A8
35
+:10FA200010F0A80141C023E0F80120935700E895A9
36
+:10FA300007B600FCFDCFA801DE011B968C91119644
37
+:10FA40002C9111971296D22ECC2490E08C299D29CE
38
+:10FA500021E0FA010C0120935700E89511244E5F34
39
+:10FA60005F4F6250704051F725E0F8012093570036
40
+:10FA7000E89507B600FCFDCF81E180935700E8953B
41
+:10FA800013C0A801FB01DE011B9641BD52BD4F5FB3
42
+:10FA90005F4F8D9180BDFA9AF99AF999FECF31970F
43
+:10FAA000A1F7A801460F571F1A828A0134C07A8035
44
+:10FAB00066248B81A82FB0E0A629B7291A828981F4
45
+:10FAC000843181F4BD019101F80185919491F9018E
46
+:10FAD000808391832E5F3F4F0E5F1F4F62507040B7
47
+:10FAE00099F711C0A801BD01910141BD52BD4F5F01
48
+:10FAF0005F4FF89A80B5F90181939F016150704082
49
+:10FB0000A1F70A0F1B1FAD014D5F5F4FF901108276
50
+:10FB100004C080EC8A8342E050E090E0FBE1F09387
51
+:10FB2000C6008091C00086FFFCCF8091C000806439
52
+:10FB30008093C0005092C6008091C00086FFFCCF29
53
+:10FB40008091C00080648093C000652F5093C600F0
54
+:10FB50008091C00086FFFCCF8091C00080648093BC
55
+:10FB6000C000342F4093C6008091C00086FFFCCFB8
56
+:10FB70008091C00080648093C0008EE08093C600B6
57
+:10FB80008091C00086FFFCCF8091C000806480938C
58
+:10FB9000C00025E1252523272627FE01319610C028
59
+:10FBA00030813093C6008091C00086FFFCCF319633
60
+:10FBB0008091C00080648093C00023274150504052
61
+:10FBC0004115510569F72093C6008091C00086FF5A
62
+:10FBD000FCCF8091C00080648093C000992349F4D9
63
+:10FBE000539441ED5AE363E570E090E0A0E0B0E0AB
64
+:10FBF00032CE5A9881E180935700E89511241F92E4
65
+:10FC00001F920895FFCF9981933109F4FCCE94316E
66
+:10FC1000C8F4963009F4ECCE973050F4923009F4E1
67
+:10FC20006ECE933009F49DCE913009F072CF83CE21
68
+:10FC3000913109F4A9CE923108F0E3CE903109F068
69
+:10FC400068CF5DCE983109F4B6CE993150F4953134
70
+:10FC500009F4D9CE953108F42ACF963109F059CF5D
71
+:10FC600026CF9B3109F495CE9C3120F49A3109F0CE
72
+:10FC700050CF9ACE9D3109F444CE9F3209F049CF3E
73
+:02FC8000B8CFFB
74
+:040000030000F80001
75
+:00000001FF

+ 239
- 0
Marlin/Marlin/Gen7/cores/arduino/HardwareSerial.cpp Переглянути файл

1
+/*
2
+  HardwareSerial.cpp - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right 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
+  Modified 23 November 2006 by David A. Mellis
20
+*/
21
+
22
+#include <stdio.h>
23
+#include <string.h>
24
+#include <inttypes.h>
25
+#include "wiring.h"
26
+#include "wiring_private.h"
27
+
28
+#include "HardwareSerial.h"
29
+
30
+// Define constants and variables for buffering incoming serial data.  We're
31
+// using a ring buffer (I think), in which rx_buffer_head is the index of the
32
+// location to which to write the next incoming character and rx_buffer_tail
33
+// is the index of the location from which to read.
34
+#define RX_BUFFER_SIZE 128
35
+
36
+struct ring_buffer {
37
+  unsigned char buffer[RX_BUFFER_SIZE];
38
+  int head;
39
+  int tail;
40
+};
41
+
42
+ring_buffer rx_buffer = { { 0 }, 0, 0 };
43
+
44
+#ifdef UDR1
45
+ring_buffer rx_buffer1 = { { 0 }, 0, 0 };
46
+#endif
47
+
48
+#ifdef UDR2
49
+ring_buffer rx_buffer2 = { { 0 }, 0, 0 };
50
+#endif
51
+#ifdef UDR3
52
+ring_buffer rx_buffer3 = { { 0 }, 0, 0 };
53
+#endif
54
+
55
+inline void store_char(unsigned char c, ring_buffer *rx_buffer)
56
+{
57
+  int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE;
58
+
59
+  // if we should be storing the received character into the location
60
+  // just before the tail (meaning that the head would advance to the
61
+  // current location of the tail), we're about to overflow the buffer
62
+  // and so we don't write the character or advance the head.
63
+  if (i != rx_buffer->tail) {
64
+    rx_buffer->buffer[rx_buffer->head] = c;
65
+    rx_buffer->head = i;
66
+  }
67
+}
68
+
69
+ISR(USART0_RX_vect)
70
+{
71
+  unsigned char c = UDR0;
72
+  store_char(c, &rx_buffer);
73
+}
74
+
75
+#ifdef UDR1
76
+ISR(USART1_RX_vect)
77
+{
78
+  unsigned char c = UDR1;
79
+  store_char(c, &rx_buffer1);
80
+}
81
+
82
+#ifdef UDR2
83
+ISR(USART2_RX_vect)
84
+{
85
+  unsigned char c = UDR2;
86
+  store_char(c, &rx_buffer2);
87
+}
88
+
89
+#ifdef UDR2
90
+ISR(USART3_RX_vect)
91
+{
92
+  unsigned char c = UDR3;
93
+  store_char(c, &rx_buffer3);
94
+}
95
+#endif
96
+#endif
97
+
98
+#else
99
+
100
+#if defined(__AVR_ATmega8__)
101
+SIGNAL(SIG_UART_RECV)
102
+#else
103
+SIGNAL(USART_RX_vect)
104
+#endif
105
+{
106
+#if defined(__AVR_ATmega8__)
107
+  unsigned char c = UDR;
108
+#else
109
+  unsigned char c = UDR0;
110
+#endif
111
+  store_char(c, &rx_buffer);
112
+}
113
+
114
+#endif
115
+
116
+// Constructors ////////////////////////////////////////////////////////////////
117
+
118
+HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
119
+  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
120
+  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
121
+  volatile uint8_t *udr,
122
+  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
123
+{
124
+  _rx_buffer = rx_buffer;
125
+  _ubrrh = ubrrh;
126
+  _ubrrl = ubrrl;
127
+  _ucsra = ucsra;
128
+  _ucsrb = ucsrb;
129
+  _udr = udr;
130
+  _rxen = rxen;
131
+  _txen = txen;
132
+  _rxcie = rxcie;
133
+  _udre = udre;
134
+  _u2x = u2x;
135
+}
136
+
137
+// Public Methods //////////////////////////////////////////////////////////////
138
+
139
+void HardwareSerial::begin(long baud)
140
+{
141
+  uint16_t baud_setting;
142
+  bool use_u2x;
143
+
144
+  // U2X mode is needed for baud rates higher than (CPU Hz / 16)
145
+  if (baud > F_CPU / 16) {
146
+    use_u2x = true;
147
+  } else {
148
+    // figure out if U2X mode would allow for a better connection
149
+    
150
+    // calculate the percent difference between the baud-rate specified and
151
+    // the real baud rate for both U2X and non-U2X mode (0-255 error percent)
152
+    uint8_t nonu2x_baud_error = abs((int)(255-((F_CPU/(16*(((F_CPU/8/baud-1)/2)+1))*255)/baud)));
153
+    uint8_t u2x_baud_error = abs((int)(255-((F_CPU/(8*(((F_CPU/4/baud-1)/2)+1))*255)/baud)));
154
+    
155
+    // prefer non-U2X mode because it handles clock skew better
156
+    use_u2x = (nonu2x_baud_error > u2x_baud_error);
157
+  }
158
+  
159
+  if (use_u2x) {
160
+    *_ucsra = 1 << _u2x;
161
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
162
+  } else {
163
+    *_ucsra = 0;
164
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
165
+  }
166
+
167
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
168
+  *_ubrrh = baud_setting >> 8;
169
+  *_ubrrl = baud_setting;
170
+
171
+  sbi(*_ucsrb, _rxen);
172
+  sbi(*_ucsrb, _txen);
173
+  sbi(*_ucsrb, _rxcie);
174
+}
175
+
176
+void HardwareSerial::end()
177
+{
178
+  cbi(*_ucsrb, _rxen);
179
+  cbi(*_ucsrb, _txen);
180
+  cbi(*_ucsrb, _rxcie);  
181
+}
182
+
183
+uint8_t HardwareSerial::available(void)
184
+{
185
+  return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
186
+}
187
+
188
+int HardwareSerial::read(void)
189
+{
190
+  // if the head isn't ahead of the tail, we don't have any characters
191
+  if (_rx_buffer->head == _rx_buffer->tail) {
192
+    return -1;
193
+  } else {
194
+    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
195
+    _rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
196
+    return c;
197
+  }
198
+}
199
+
200
+void HardwareSerial::flush()
201
+{
202
+  // don't reverse this or there may be problems if the RX interrupt
203
+  // occurs after reading the value of rx_buffer_head but before writing
204
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
205
+  // may be written to rx_buffer_tail, making it appear as if the buffer
206
+  // don't reverse this or there may be problems if the RX interrupt
207
+  // occurs after reading the value of rx_buffer_head but before writing
208
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
209
+  // may be written to rx_buffer_tail, making it appear as if the buffer
210
+  // were full, not empty.
211
+  _rx_buffer->head = _rx_buffer->tail;
212
+}
213
+
214
+void HardwareSerial::write(uint8_t c)
215
+{
216
+  while (!((*_ucsra) & (1 << _udre)))
217
+    ;
218
+
219
+  *_udr = c;
220
+}
221
+
222
+// Preinstantiate Objects //////////////////////////////////////////////////////
223
+
224
+#if defined(__AVR_ATmega8__)
225
+HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X);
226
+#else
227
+HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
228
+#endif
229
+
230
+#ifdef UDR1
231
+HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
232
+#endif
233
+
234
+#ifdef UDR2
235
+HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
236
+#endif
237
+#ifdef UDR3
238
+HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
239
+#endif

+ 69
- 0
Marlin/Marlin/Gen7/cores/arduino/HardwareSerial.h Переглянути файл

1
+/*
2
+  HardwareSerial.h - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right 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 HardwareSerial_h
21
+#define HardwareSerial_h
22
+
23
+#include <inttypes.h>
24
+
25
+#include "Print.h"
26
+
27
+struct ring_buffer;
28
+
29
+class HardwareSerial : public Print
30
+{
31
+  private:
32
+    ring_buffer *_rx_buffer;
33
+    volatile uint8_t *_ubrrh;
34
+    volatile uint8_t *_ubrrl;
35
+    volatile uint8_t *_ucsra;
36
+    volatile uint8_t *_ucsrb;
37
+    volatile uint8_t *_udr;
38
+    uint8_t _rxen;
39
+    uint8_t _txen;
40
+    uint8_t _rxcie;
41
+    uint8_t _udre;
42
+    uint8_t _u2x;
43
+  public:
44
+    HardwareSerial(ring_buffer *rx_buffer,
45
+      volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
46
+      volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
47
+      volatile uint8_t *udr,
48
+      uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
49
+    void begin(long);
50
+    void end();
51
+    uint8_t available(void);
52
+    int read(void);
53
+    void flush(void);
54
+    virtual void write(uint8_t);
55
+    using Print::write; // pull in write(str) and write(buf, size) from Print
56
+};
57
+
58
+extern HardwareSerial Serial;
59
+
60
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1280__)
61
+extern HardwareSerial Serial1;
62
+#endif
63
+
64
+#if defined(__AVR_ATmega1280__)
65
+extern HardwareSerial Serial2;
66
+extern HardwareSerial Serial3;
67
+#endif
68
+
69
+#endif

+ 243
- 0
Marlin/Marlin/Gen7/cores/arduino/Makefile Переглянути файл

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

+ 203
- 0
Marlin/Marlin/Gen7/cores/arduino/Print.cpp Переглянути файл

1
+/*
2
+ Print.cpp - Base class that provides print() and println()
3
+ Copyright (c) 2008 David A. Mellis.  All right 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
+ Modified 23 November 2006 by David A. Mellis
20
+ */
21
+
22
+#include <stdio.h>
23
+#include <string.h>
24
+#include <inttypes.h>
25
+#include <math.h>
26
+#include "wiring.h"
27
+
28
+#include "Print.h"
29
+
30
+// Public Methods //////////////////////////////////////////////////////////////
31
+
32
+void Print::print(uint8_t b)
33
+{
34
+  this->write(b);
35
+}
36
+
37
+void Print::print(char c)
38
+{
39
+  print((byte) c);
40
+}
41
+
42
+void Print::print(const char c[])
43
+{
44
+  while (*c)
45
+    print(*c++);
46
+}
47
+
48
+void Print::print(int n)
49
+{
50
+  print((long) n);
51
+}
52
+
53
+void Print::print(unsigned int n)
54
+{
55
+  print((unsigned long) n);
56
+}
57
+
58
+void Print::print(long n)
59
+{
60
+  if (n < 0) {
61
+    print('-');
62
+    n = -n;
63
+  }
64
+  printNumber(n, 10);
65
+}
66
+
67
+void Print::print(unsigned long n)
68
+{
69
+  printNumber(n, 10);
70
+}
71
+
72
+void Print::print(long n, int base)
73
+{
74
+  if (base == 0)
75
+    print((char) n);
76
+  else if (base == 10)
77
+    print(n);
78
+  else
79
+    printNumber(n, base);
80
+}
81
+
82
+void Print::print(double n)
83
+{
84
+  printFloat(n, 2);
85
+}
86
+
87
+void Print::println(void)
88
+{
89
+  print('\r');
90
+  print('\n');  
91
+}
92
+
93
+void Print::println(char c)
94
+{
95
+  print(c);
96
+  println();  
97
+}
98
+
99
+void Print::println(const char c[])
100
+{
101
+  print(c);
102
+  println();
103
+}
104
+
105
+void Print::println(uint8_t b)
106
+{
107
+  print(b);
108
+  println();
109
+}
110
+
111
+void Print::println(int n)
112
+{
113
+  print(n);
114
+  println();
115
+}
116
+
117
+void Print::println(unsigned int n)
118
+{
119
+  print(n);
120
+  println();
121
+}
122
+
123
+void Print::println(long n)
124
+{
125
+  print(n);
126
+  println();  
127
+}
128
+
129
+void Print::println(unsigned long n)
130
+{
131
+  print(n);
132
+  println();  
133
+}
134
+
135
+void Print::println(long n, int base)
136
+{
137
+  print(n, base);
138
+  println();
139
+}
140
+
141
+void Print::println(double n)
142
+{
143
+  print(n);
144
+  println();
145
+}
146
+
147
+// Private Methods /////////////////////////////////////////////////////////////
148
+
149
+void Print::printNumber(unsigned long n, uint8_t base)
150
+{
151
+  unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
152
+  unsigned long i = 0;
153
+
154
+  if (n == 0) {
155
+    print('0');
156
+    return;
157
+  } 
158
+
159
+  while (n > 0) {
160
+    buf[i++] = n % base;
161
+    n /= base;
162
+  }
163
+
164
+  for (; i > 0; i--)
165
+    print((char) (buf[i - 1] < 10 ?
166
+      '0' + buf[i - 1] :
167
+      'A' + buf[i - 1] - 10));
168
+}
169
+
170
+void Print::printFloat(double number, uint8_t digits) 
171
+{ 
172
+  // Handle negative numbers
173
+  if (number < 0.0)
174
+  {
175
+     print('-');
176
+     number = -number;
177
+  }
178
+
179
+  // Round correctly so that print(1.999, 2) prints as "2.00"
180
+  double rounding = 0.5;
181
+  for (uint8_t i=0; i<digits; ++i)
182
+    rounding /= 10.0;
183
+  
184
+  number += rounding;
185
+
186
+  // Extract the integer part of the number and print it
187
+  unsigned long int_part = (unsigned long)number;
188
+  double remainder = number - (double)int_part;
189
+  print(int_part);
190
+
191
+  // Print the decimal point, but only if there are digits beyond
192
+  if (digits > 0)
193
+    print("."); 
194
+
195
+  // Extract digits from the remainder one at a time
196
+  while (digits-- > 0)
197
+  {
198
+    remainder *= 10.0;
199
+    int toPrint = int(remainder);
200
+    print(toPrint);
201
+    remainder -= toPrint; 
202
+  } 
203
+}

+ 59
- 0
Marlin/Marlin/Gen7/cores/arduino/Print.h Переглянути файл

1
+/*
2
+  Print.h - Base class that provides print() and println()
3
+  Copyright (c) 2008 David A. Mellis.  All right 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 Print_h
21
+#define Print_h
22
+
23
+#include <inttypes.h>
24
+
25
+#define DEC 10
26
+#define HEX 16
27
+#define OCT 8
28
+#define BIN 2
29
+#define BYTE 0
30
+
31
+class Print
32
+{
33
+  private:
34
+    void printNumber(unsigned long, uint8_t);
35
+    void printFloat(double, uint8_t);
36
+  public:
37
+    virtual void write(uint8_t);
38
+    void print(char);
39
+    void print(const char[]);
40
+    void print(uint8_t);
41
+    void print(int);
42
+    void print(unsigned int);
43
+    void print(long);
44
+    void print(unsigned long);
45
+    void print(long, int);
46
+    void print(double);
47
+    void println(void);
48
+    void println(char);
49
+    void println(const char[]);
50
+    void println(uint8_t);
51
+    void println(int);
52
+    void println(unsigned int);
53
+    void println(long);
54
+    void println(unsigned long);
55
+    void println(long, int);
56
+    void println(double);
57
+};
58
+
59
+#endif

+ 515
- 0
Marlin/Marlin/Gen7/cores/arduino/Tone.cpp Переглянути файл

1
+/* Tone.cpp
2
+
3
+  A Tone Generator Library
4
+
5
+  Written by Brett Hagman
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General Public
18
+  License along with this library; if not, write to the Free Software
19
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
+
21
+Version Modified By Date     Comments
22
+------- ----------- -------- --------
23
+0001    B Hagman    09/08/02 Initial coding
24
+0002    B Hagman    09/08/18 Multiple pins
25
+0003    B Hagman    09/08/18 Moved initialization from constructor to begin()
26
+0004    B Hagman    09/09/26 Fixed problems with ATmega8
27
+0005    B Hagman    09/11/23 Scanned prescalars for best fit on 8 bit timers
28
+                    09/11/25 Changed pin toggle method to XOR
29
+                    09/11/25 Fixed timer0 from being excluded
30
+0006    D Mellis    09/12/29 Replaced objects with functions
31
+
32
+*************************************************/
33
+
34
+#include <avr/interrupt.h>
35
+#include <avr/pgmspace.h>
36
+#include <wiring.h>
37
+#include <pins_arduino.h>
38
+
39
+#if defined(__AVR_ATmega8__)
40
+#define TCCR2A TCCR2
41
+#define TCCR2B TCCR2
42
+#define COM2A1 COM21
43
+#define COM2A0 COM20
44
+#define OCR2A OCR2
45
+#define TIMSK2 TIMSK
46
+#define OCIE2A OCIE2
47
+#define TIMER2_COMPA_vect TIMER2_COMP_vect
48
+#define TIMSK1 TIMSK
49
+#endif
50
+
51
+// timerx_toggle_count:
52
+//  > 0 - duration specified
53
+//  = 0 - stopped
54
+//  < 0 - infinitely (until stop() method called, or new play() called)
55
+
56
+#if !defined(__AVR_ATmega8__)
57
+volatile long timer0_toggle_count;
58
+volatile uint8_t *timer0_pin_port;
59
+volatile uint8_t timer0_pin_mask;
60
+#endif
61
+
62
+volatile long timer1_toggle_count;
63
+volatile uint8_t *timer1_pin_port;
64
+volatile uint8_t timer1_pin_mask;
65
+volatile long timer2_toggle_count;
66
+volatile uint8_t *timer2_pin_port;
67
+volatile uint8_t timer2_pin_mask;
68
+
69
+#if defined(__AVR_ATmega1280__)
70
+volatile long timer3_toggle_count;
71
+volatile uint8_t *timer3_pin_port;
72
+volatile uint8_t timer3_pin_mask;
73
+volatile long timer4_toggle_count;
74
+volatile uint8_t *timer4_pin_port;
75
+volatile uint8_t timer4_pin_mask;
76
+volatile long timer5_toggle_count;
77
+volatile uint8_t *timer5_pin_port;
78
+volatile uint8_t timer5_pin_mask;
79
+#endif
80
+
81
+
82
+#if defined(__AVR_ATmega1280__)
83
+
84
+#define AVAILABLE_TONE_PINS 1
85
+
86
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
87
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
88
+
89
+#elif defined(__AVR_ATmega8__)
90
+
91
+#define AVAILABLE_TONE_PINS 1
92
+
93
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ };
94
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
95
+
96
+#else
97
+
98
+#define AVAILABLE_TONE_PINS 1
99
+
100
+// Leave timer 0 to last.
101
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
102
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255 */ };
103
+
104
+#endif
105
+
106
+
107
+
108
+static int8_t toneBegin(uint8_t _pin)
109
+{
110
+  int8_t _timer = -1;
111
+
112
+  // if we're already using the pin, the timer should be configured.  
113
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
114
+    if (tone_pins[i] == _pin) {
115
+      return pgm_read_byte(tone_pin_to_timer_PGM + i);
116
+    }
117
+  }
118
+  
119
+  // search for an unused timer.
120
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
121
+    if (tone_pins[i] == 255) {
122
+      tone_pins[i] = _pin;
123
+      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
124
+      break;
125
+    }
126
+  }
127
+  
128
+  if (_timer != -1)
129
+  {
130
+    // Set timer specific stuff
131
+    // All timers in CTC mode
132
+    // 8 bit timers will require changing prescalar values,
133
+    // whereas 16 bit timers are set to either ck/1 or ck/64 prescalar
134
+    switch (_timer)
135
+    {
136
+#if !defined(__AVR_ATmega8__)
137
+      case 0:
138
+        // 8 bit timer
139
+        TCCR0A = 0;
140
+        TCCR0B = 0;
141
+        bitWrite(TCCR0A, WGM01, 1);
142
+        bitWrite(TCCR0B, CS00, 1);
143
+        timer0_pin_port = portOutputRegister(digitalPinToPort(_pin));
144
+        timer0_pin_mask = digitalPinToBitMask(_pin);
145
+        break;
146
+#endif
147
+
148
+      case 1:
149
+        // 16 bit timer
150
+        TCCR1A = 0;
151
+        TCCR1B = 0;
152
+        bitWrite(TCCR1B, WGM12, 1);
153
+        bitWrite(TCCR1B, CS10, 1);
154
+        timer1_pin_port = portOutputRegister(digitalPinToPort(_pin));
155
+        timer1_pin_mask = digitalPinToBitMask(_pin);
156
+        break;
157
+      case 2:
158
+        // 8 bit timer
159
+        TCCR2A = 0;
160
+        TCCR2B = 0;
161
+        bitWrite(TCCR2A, WGM21, 1);
162
+        bitWrite(TCCR2B, CS20, 1);
163
+        timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
164
+        timer2_pin_mask = digitalPinToBitMask(_pin);
165
+        break;
166
+
167
+#if defined(__AVR_ATmega1280__)
168
+      case 3:
169
+        // 16 bit timer
170
+        TCCR3A = 0;
171
+        TCCR3B = 0;
172
+        bitWrite(TCCR3B, WGM32, 1);
173
+        bitWrite(TCCR3B, CS30, 1);
174
+        timer3_pin_port = portOutputRegister(digitalPinToPort(_pin));
175
+        timer3_pin_mask = digitalPinToBitMask(_pin);
176
+        break;
177
+      case 4:
178
+        // 16 bit timer
179
+        TCCR4A = 0;
180
+        TCCR4B = 0;
181
+        bitWrite(TCCR4B, WGM42, 1);
182
+        bitWrite(TCCR4B, CS40, 1);
183
+        timer4_pin_port = portOutputRegister(digitalPinToPort(_pin));
184
+        timer4_pin_mask = digitalPinToBitMask(_pin);
185
+        break;
186
+      case 5:
187
+        // 16 bit timer
188
+        TCCR5A = 0;
189
+        TCCR5B = 0;
190
+        bitWrite(TCCR5B, WGM52, 1);
191
+        bitWrite(TCCR5B, CS50, 1);
192
+        timer5_pin_port = portOutputRegister(digitalPinToPort(_pin));
193
+        timer5_pin_mask = digitalPinToBitMask(_pin);
194
+        break;
195
+#endif
196
+    }
197
+  }
198
+
199
+  return _timer;
200
+}
201
+
202
+
203
+
204
+// frequency (in hertz) and duration (in milliseconds).
205
+
206
+void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
207
+{
208
+  uint8_t prescalarbits = 0b001;
209
+  long toggle_count = 0;
210
+  uint32_t ocr = 0;
211
+  int8_t _timer;
212
+
213
+  _timer = toneBegin(_pin);
214
+
215
+  if (_timer >= 0)
216
+  {
217
+    // Set the pinMode as OUTPUT
218
+    pinMode(_pin, OUTPUT);
219
+    
220
+    // if we are using an 8 bit timer, scan through prescalars to find the best fit
221
+    if (_timer == 0 || _timer == 2)
222
+    {
223
+      ocr = F_CPU / frequency / 2 - 1;
224
+      prescalarbits = 0b001;  // ck/1: same for both timers
225
+      if (ocr > 255)
226
+      {
227
+        ocr = F_CPU / frequency / 2 / 8 - 1;
228
+        prescalarbits = 0b010;  // ck/8: same for both timers
229
+
230
+        if (_timer == 2 && ocr > 255)
231
+        {
232
+          ocr = F_CPU / frequency / 2 / 32 - 1;
233
+          prescalarbits = 0b011;
234
+        }
235
+
236
+        if (ocr > 255)
237
+        {
238
+          ocr = F_CPU / frequency / 2 / 64 - 1;
239
+          prescalarbits = _timer == 0 ? 0b011 : 0b100;
240
+
241
+          if (_timer == 2 && ocr > 255)
242
+          {
243
+            ocr = F_CPU / frequency / 2 / 128 - 1;
244
+            prescalarbits = 0b101;
245
+          }
246
+
247
+          if (ocr > 255)
248
+          {
249
+            ocr = F_CPU / frequency / 2 / 256 - 1;
250
+            prescalarbits = _timer == 0 ? 0b100 : 0b110;
251
+            if (ocr > 255)
252
+            {
253
+              // can't do any better than /1024
254
+              ocr = F_CPU / frequency / 2 / 1024 - 1;
255
+              prescalarbits = _timer == 0 ? 0b101 : 0b111;
256
+            }
257
+          }
258
+        }
259
+      }
260
+
261
+#if !defined(__AVR_ATmega8__)
262
+      if (_timer == 0)
263
+        TCCR0B = prescalarbits;
264
+      else
265
+#endif
266
+        TCCR2B = prescalarbits;
267
+    }
268
+    else
269
+    {
270
+      // two choices for the 16 bit timers: ck/1 or ck/64
271
+      ocr = F_CPU / frequency / 2 - 1;
272
+
273
+      prescalarbits = 0b001;
274
+      if (ocr > 0xffff)
275
+      {
276
+        ocr = F_CPU / frequency / 2 / 64 - 1;
277
+        prescalarbits = 0b011;
278
+      }
279
+
280
+      if (_timer == 1)
281
+        TCCR1B = (TCCR1B & 0b11111000) | prescalarbits;
282
+#if defined(__AVR_ATmega1280__)
283
+      else if (_timer == 3)
284
+        TCCR3B = (TCCR3B & 0b11111000) | prescalarbits;
285
+      else if (_timer == 4)
286
+        TCCR4B = (TCCR4B & 0b11111000) | prescalarbits;
287
+      else if (_timer == 5)
288
+        TCCR5B = (TCCR5B & 0b11111000) | prescalarbits;
289
+#endif
290
+
291
+    }
292
+    
293
+
294
+    // Calculate the toggle count
295
+    if (duration > 0)
296
+    {
297
+      toggle_count = 2 * frequency * duration / 1000;
298
+    }
299
+    else
300
+    {
301
+      toggle_count = -1;
302
+    }
303
+
304
+    // Set the OCR for the given timer,
305
+    // set the toggle count,
306
+    // then turn on the interrupts
307
+    switch (_timer)
308
+    {
309
+
310
+#if !defined(__AVR_ATmega8__)
311
+      case 0:
312
+        OCR0A = ocr;
313
+        timer0_toggle_count = toggle_count;
314
+        bitWrite(TIMSK0, OCIE0A, 1);
315
+        break;
316
+#endif
317
+
318
+      case 1:
319
+        OCR1A = ocr;
320
+        timer1_toggle_count = toggle_count;
321
+        bitWrite(TIMSK1, OCIE1A, 1);
322
+        break;
323
+      case 2:
324
+        OCR2A = ocr;
325
+        timer2_toggle_count = toggle_count;
326
+        bitWrite(TIMSK2, OCIE2A, 1);
327
+        break;
328
+
329
+#if defined(__AVR_ATmega1280__)
330
+      case 3:
331
+        OCR3A = ocr;
332
+        timer3_toggle_count = toggle_count;
333
+        bitWrite(TIMSK3, OCIE3A, 1);
334
+        break;
335
+      case 4:
336
+        OCR4A = ocr;
337
+        timer4_toggle_count = toggle_count;
338
+        bitWrite(TIMSK4, OCIE4A, 1);
339
+        break;
340
+      case 5:
341
+        OCR5A = ocr;
342
+        timer5_toggle_count = toggle_count;
343
+        bitWrite(TIMSK5, OCIE5A, 1);
344
+        break;
345
+#endif
346
+
347
+    }
348
+  }
349
+}
350
+
351
+
352
+void noTone(uint8_t _pin)
353
+{
354
+  int8_t _timer = -1;
355
+  
356
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
357
+    if (tone_pins[i] == _pin) {
358
+      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
359
+      tone_pins[i] = 255;
360
+    }
361
+  }
362
+  
363
+  switch (_timer)
364
+  {
365
+#if defined(__AVR_ATmega8__)
366
+    case 1:
367
+      bitWrite(TIMSK1, OCIE1A, 0);
368
+      break;
369
+    case 2:
370
+      bitWrite(TIMSK2, OCIE2A, 0);
371
+      break;
372
+
373
+#else
374
+    case 0:
375
+      TIMSK0 = 0;
376
+      break;
377
+    case 1:
378
+      TIMSK1 = 0;
379
+      break;
380
+    case 2:
381
+      TIMSK2 = 0;
382
+      break;
383
+#endif
384
+
385
+#if defined(__AVR_ATmega1280__)
386
+    case 3:
387
+      TIMSK3 = 0;
388
+      break;
389
+    case 4:
390
+      TIMSK4 = 0;
391
+      break;
392
+    case 5:
393
+      TIMSK5 = 0;
394
+      break;
395
+#endif
396
+  }
397
+
398
+  digitalWrite(_pin, 0);
399
+}
400
+
401
+#if 0
402
+#if !defined(__AVR_ATmega8__)
403
+ISR(TIMER0_COMPA_vect)
404
+{
405
+  if (timer0_toggle_count != 0)
406
+  {
407
+    // toggle the pin
408
+    *timer0_pin_port ^= timer0_pin_mask;
409
+
410
+    if (timer0_toggle_count > 0)
411
+      timer0_toggle_count--;
412
+  }
413
+  else
414
+  {
415
+    TIMSK0 = 0;   // disable the interrupt
416
+    *timer0_pin_port &= ~(timer0_pin_mask);  // keep pin low after stop
417
+  }
418
+}
419
+#endif
420
+
421
+
422
+ISR(TIMER1_COMPA_vect)
423
+{
424
+  if (timer1_toggle_count != 0)
425
+  {
426
+    // toggle the pin
427
+    *timer1_pin_port ^= timer1_pin_mask;
428
+
429
+    if (timer1_toggle_count > 0)
430
+      timer1_toggle_count--;
431
+  }
432
+  else
433
+  {
434
+    TIMSK1 = 0;   // disable the interrupt
435
+    *timer1_pin_port &= ~(timer1_pin_mask);  // keep pin low after stop
436
+  }
437
+}
438
+#endif
439
+
440
+
441
+ISR(TIMER2_COMPA_vect)
442
+{
443
+
444
+  if (timer2_toggle_count != 0)
445
+  {
446
+    // toggle the pin
447
+    *timer2_pin_port ^= timer2_pin_mask;
448
+
449
+    if (timer2_toggle_count > 0)
450
+      timer2_toggle_count--;
451
+  }
452
+  else
453
+  {
454
+    TIMSK2 = 0;   // disable the interrupt
455
+    *timer2_pin_port &= ~(timer2_pin_mask);  // keep pin low after stop
456
+  }
457
+}
458
+
459
+
460
+
461
+//#if defined(__AVR_ATmega1280__)
462
+#if 0
463
+
464
+ISR(TIMER3_COMPA_vect)
465
+{
466
+  if (timer3_toggle_count != 0)
467
+  {
468
+    // toggle the pin
469
+    *timer3_pin_port ^= timer3_pin_mask;
470
+
471
+    if (timer3_toggle_count > 0)
472
+      timer3_toggle_count--;
473
+  }
474
+  else
475
+  {
476
+    TIMSK3 = 0;   // disable the interrupt
477
+    *timer3_pin_port &= ~(timer3_pin_mask);  // keep pin low after stop
478
+  }
479
+}
480
+
481
+ISR(TIMER4_COMPA_vect)
482
+{
483
+  if (timer4_toggle_count != 0)
484
+  {
485
+    // toggle the pin
486
+    *timer4_pin_port ^= timer4_pin_mask;
487
+
488
+    if (timer4_toggle_count > 0)
489
+      timer4_toggle_count--;
490
+  }
491
+  else
492
+  {
493
+    TIMSK4 = 0;   // disable the interrupt
494
+    *timer4_pin_port &= ~(timer4_pin_mask);  // keep pin low after stop
495
+  }
496
+}
497
+
498
+ISR(TIMER5_COMPA_vect)
499
+{
500
+  if (timer5_toggle_count != 0)
501
+  {
502
+    // toggle the pin
503
+    *timer5_pin_port ^= timer5_pin_mask;
504
+
505
+    if (timer5_toggle_count > 0)
506
+      timer5_toggle_count--;
507
+  }
508
+  else
509
+  {
510
+    TIMSK5 = 0;   // disable the interrupt
511
+    *timer5_pin_port &= ~(timer5_pin_mask);  // keep pin low after stop
512
+  }
513
+}
514
+
515
+#endif

+ 168
- 0
Marlin/Marlin/Gen7/cores/arduino/WCharacter.h Переглянути файл

1
+/*
2
+ WCharacter.h - Character utility functions for Wiring & Arduino
3
+ Copyright (c) 2010 Hernando Barragan.  All right 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 Character_h
21
+#define Character_h
22
+
23
+#include <ctype.h>
24
+
25
+// WCharacter.h prototypes
26
+inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
27
+inline boolean isAlpha(int c) __attribute__((always_inline));
28
+inline boolean isAscii(int c) __attribute__((always_inline));
29
+inline boolean isWhitespace(int c) __attribute__((always_inline));
30
+inline boolean isControl(int c) __attribute__((always_inline));
31
+inline boolean isDigit(int c) __attribute__((always_inline));
32
+inline boolean isGraph(int c) __attribute__((always_inline));
33
+inline boolean isLowerCase(int c) __attribute__((always_inline));
34
+inline boolean isPrintable(int c) __attribute__((always_inline));
35
+inline boolean isPunct(int c) __attribute__((always_inline));
36
+inline boolean isSpace(int c) __attribute__((always_inline));
37
+inline boolean isUpperCase(int c) __attribute__((always_inline));
38
+inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
39
+inline int toAscii(int c) __attribute__((always_inline));
40
+inline int toLowerCase(int c) __attribute__((always_inline));
41
+inline int toUpperCase(int c)__attribute__((always_inline));
42
+
43
+
44
+// Checks for an alphanumeric character. 
45
+// It is equivalent to (isalpha(c) || isdigit(c)).
46
+inline boolean isAlphaNumeric(int c) 
47
+{
48
+  return ( isalnum(c) == 0 ? false : true);
49
+}
50
+
51
+
52
+// Checks for an alphabetic character. 
53
+// It is equivalent to (isupper(c) || islower(c)).
54
+inline boolean isAlpha(int c)
55
+{
56
+  return ( isalpha(c) == 0 ? false : true);
57
+}
58
+
59
+
60
+// Checks whether c is a 7-bit unsigned char value 
61
+// that fits into the ASCII character set.
62
+inline boolean isAscii(int c)
63
+{
64
+  return ( isascii (c) == 0 ? false : true);
65
+}
66
+
67
+
68
+// Checks for a blank character, that is, a space or a tab.
69
+inline boolean isWhitespace(int c)
70
+{
71
+  return ( isblank (c) == 0 ? false : true);
72
+}
73
+
74
+
75
+// Checks for a control character.
76
+inline boolean isControl(int c)
77
+{
78
+  return ( iscntrl (c) == 0 ? false : true);
79
+}
80
+
81
+
82
+// Checks for a digit (0 through 9).
83
+inline boolean isDigit(int c)
84
+{
85
+  return ( isdigit (c) == 0 ? false : true);
86
+}
87
+
88
+
89
+// Checks for any printable character except space.
90
+inline boolean isGraph(int c)
91
+{
92
+  return ( isgraph (c) == 0 ? false : true);
93
+}
94
+
95
+
96
+// Checks for a lower-case character.
97
+inline boolean isLowerCase(int c)
98
+{
99
+  return (islower (c) == 0 ? false : true);
100
+}
101
+
102
+
103
+// Checks for any printable character including space.
104
+inline boolean isPrintable(int c)
105
+{
106
+  return ( isprint (c) == 0 ? false : true);
107
+}
108
+
109
+
110
+// Checks for any printable character which is not a space 
111
+// or an alphanumeric character.
112
+inline boolean isPunct(int c)
113
+{
114
+  return ( ispunct (c) == 0 ? false : true);
115
+}
116
+
117
+
118
+// Checks for white-space characters. For the avr-libc library, 
119
+// these are: space, formfeed ('\f'), newline ('\n'), carriage 
120
+// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
121
+inline boolean isSpace(int c)
122
+{
123
+  return ( isspace (c) == 0 ? false : true);
124
+}
125
+
126
+
127
+// Checks for an uppercase letter.
128
+inline boolean isUpperCase(int c)
129
+{
130
+  return ( isupper (c) == 0 ? false : true);
131
+}
132
+
133
+
134
+// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 
135
+// 8 9 a b c d e f A B C D E F.
136
+inline boolean isHexadecimalDigit(int c)
137
+{
138
+  return ( isxdigit (c) == 0 ? false : true);
139
+}
140
+
141
+
142
+// Converts c to a 7-bit unsigned char value that fits into the 
143
+// ASCII character set, by clearing the high-order bits.
144
+inline int toAscii(int c)
145
+{
146
+  return toascii (c);
147
+}
148
+
149
+
150
+// Warning:
151
+// Many people will be unhappy if you use this function. 
152
+// This function will convert accented letters into random 
153
+// characters.
154
+
155
+// Converts the letter c to lower case, if possible.
156
+inline int toLowerCase(int c)
157
+{
158
+  return tolower (c);
159
+}
160
+
161
+
162
+// Converts the letter c to upper case, if possible.
163
+inline int toUpperCase(int c)
164
+{
165
+  return toupper (c);
166
+}
167
+
168
+#endif

+ 1
- 0
Marlin/Marlin/Gen7/cores/arduino/WConstants.h Переглянути файл

1
+#include "wiring.h"

+ 87
- 0
Marlin/Marlin/Gen7/cores/arduino/WInterrupts.c Переглянути файл

1
+/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
3
+/*
4
+  Part of the Wiring project - http://wiring.uniandes.edu.co
5
+
6
+  Copyright (c) 2004-05 Hernando Barragan
7
+
8
+  This library is free software; you can redistribute it and/or
9
+  modify it under the terms of the GNU Lesser General Public
10
+  License as published by the Free Software Foundation; either
11
+  version 2.1 of the License, or (at your option) any later version.
12
+
13
+  This library is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+  Lesser General Public License for more details.
17
+
18
+  You should have received a copy of the GNU Lesser General
19
+  Public License along with this library; if not, write to the
20
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
+  Boston, MA  02111-1307  USA
22
+  
23
+  Modified 24 November 2006 by David A. Mellis
24
+*/
25
+
26
+#include <inttypes.h>
27
+#include <avr/io.h>
28
+#include <avr/interrupt.h>
29
+#include <avr/pgmspace.h>
30
+#include <stdio.h>
31
+
32
+#include "WConstants.h"
33
+#include "wiring_private.h"
34
+
35
+volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
36
+// volatile static voidFuncPtr twiIntFunc;
37
+
38
+void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)
39
+{
40
+	if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
41
+	{
42
+		intFunc[interruptNum] = userFunc;
43
+
44
+		//clear the config for the change settings
45
+		EICRA &= ~(B00000011 << (interruptNum * 2));
46
+
47
+		//set our mode.
48
+		EICRA |= (mode << (interruptNum * 2));
49
+
50
+		// Enable the interrupt.
51
+		EIMSK |= (1 << interruptNum);
52
+	}
53
+}
54
+
55
+void detachInterrupt(uint8_t interruptNum)
56
+{
57
+	if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
58
+	{
59
+		// Disable the interrupt.
60
+		EIMSK &= ~(1 << interruptNum);
61
+
62
+		intFunc[interruptNum] = 0;
63
+	}
64
+}
65
+
66
+ISR(INT0_vect) {
67
+  if(intFunc[EXTERNAL_INT_0])
68
+    intFunc[EXTERNAL_INT_0]();
69
+}
70
+
71
+ISR(INT1_vect) {
72
+  if(intFunc[EXTERNAL_INT_1])
73
+    intFunc[EXTERNAL_INT_1]();
74
+}
75
+
76
+ISR(INT2_vect) {
77
+  if(intFunc[EXTERNAL_INT_2])
78
+    intFunc[EXTERNAL_INT_2]();
79
+}
80
+
81
+/*
82
+SIGNAL(SIG_2WIRE_SERIAL) {
83
+  if(twiIntFunc)
84
+    twiIntFunc();
85
+}
86
+*/
87
+

+ 60
- 0
Marlin/Marlin/Gen7/cores/arduino/WMath.cpp Переглянути файл

1
+/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
3
+/*
4
+  Part of the Wiring project - http://wiring.org.co
5
+  Copyright (c) 2004-06 Hernando Barragan
6
+  Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/
7
+  
8
+  This library is free software; you can redistribute it and/or
9
+  modify it under the terms of the GNU Lesser General Public
10
+  License as published by the Free Software Foundation; either
11
+  version 2.1 of the License, or (at your option) any later version.
12
+
13
+  This library is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+  Lesser General Public License for more details.
17
+
18
+  You should have received a copy of the GNU Lesser General
19
+  Public License along with this library; if not, write to the
20
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
+  Boston, MA  02111-1307  USA
22
+  
23
+  $Id$
24
+*/
25
+
26
+extern "C" {
27
+  #include "stdlib.h"
28
+}
29
+
30
+void randomSeed(unsigned int seed)
31
+{
32
+  if (seed != 0){
33
+    srandom(seed);
34
+  }
35
+}
36
+
37
+long random(long howbig)
38
+{
39
+  if (howbig == 0) {
40
+    return 0;
41
+  }
42
+  return random() % howbig;
43
+}
44
+
45
+long random(long howsmall, long howbig)
46
+{
47
+  if (howsmall >= howbig) {
48
+    return howsmall;
49
+  }
50
+  long diff = howbig - howsmall;
51
+  return random(diff) + howsmall;
52
+}
53
+
54
+long map(long x, long in_min, long in_max, long out_min, long out_max)
55
+{
56
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
57
+}
58
+
59
+unsigned int makeWord(unsigned int w) { return w; }
60
+unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; }

+ 34
- 0
Marlin/Marlin/Gen7/cores/arduino/WProgram.h Переглянути файл

1
+#ifndef WProgram_h
2
+#define WProgram_h
3
+
4
+#include <stdlib.h>
5
+#include <string.h>
6
+#include <math.h>
7
+
8
+#include <avr/interrupt.h>
9
+
10
+#include "wiring.h"
11
+
12
+#ifdef __cplusplus
13
+#include "WCharacter.h"
14
+#include "WString.h"
15
+#include "HardwareSerial.h"
16
+
17
+uint16_t makeWord(uint16_t w);
18
+uint16_t makeWord(byte h, byte l);
19
+
20
+#define word(...) makeWord(__VA_ARGS__)
21
+
22
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
23
+
24
+void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
25
+void noTone(uint8_t _pin);
26
+
27
+// WMath prototypes
28
+long random(long);
29
+long random(long, long);
30
+void randomSeed(unsigned int);
31
+long map(long, long, long, long, long);
32
+#endif
33
+
34
+#endif

+ 443
- 0
Marlin/Marlin/Gen7/cores/arduino/WString.cpp Переглянути файл

1
+/*
2
+  WString.cpp - String library for Wiring & Arduino
3
+  Copyright (c) 2009-10 Hernando Barragan.  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
+#include <stdlib.h>
21
+#include "WProgram.h"
22
+#include "WString.h"
23
+
24
+
25
+String::String( const char *value )
26
+{
27
+  if ( value == NULL )
28
+    value = "";
29
+  getBuffer( _length = strlen( value ) );
30
+  if ( _buffer != NULL )
31
+    strcpy( _buffer, value );
32
+}
33
+
34
+String::String( const String &value )
35
+{
36
+  getBuffer( _length = value._length );
37
+  if ( _buffer != NULL )
38
+    strcpy( _buffer, value._buffer );
39
+}
40
+
41
+String::String( const char value )
42
+{
43
+  _length = 1;
44
+  getBuffer(1);
45
+  if ( _buffer != NULL ) {
46
+    _buffer[0] = value;
47
+    _buffer[1] = 0;
48
+  }
49
+}
50
+
51
+String::String( const unsigned char value )
52
+{
53
+  _length = 1;
54
+  getBuffer(1);
55
+  if ( _buffer != NULL) {
56
+    _buffer[0] = value;
57
+    _buffer[1] = 0;
58
+  }
59
+}
60
+
61
+String::String( const int value, const int base )
62
+{
63
+  char buf[33];   
64
+  itoa((signed long)value, buf, base);
65
+  getBuffer( _length = strlen(buf) );
66
+  if ( _buffer != NULL )
67
+    strcpy( _buffer, buf );
68
+}
69
+
70
+String::String( const unsigned int value, const int base )
71
+{
72
+  char buf[33];   
73
+  ultoa((unsigned long)value, buf, base);
74
+  getBuffer( _length = strlen(buf) );
75
+  if ( _buffer != NULL )
76
+    strcpy( _buffer, buf );
77
+}
78
+
79
+String::String( const long value, const int base )
80
+{
81
+  char buf[33];   
82
+  ltoa(value, buf, base);
83
+  getBuffer( _length = strlen(buf) );
84
+  if ( _buffer != NULL )
85
+    strcpy( _buffer, buf );
86
+}
87
+
88
+String::String( const unsigned long value, const int base )
89
+{
90
+  char buf[33];   
91
+  ultoa(value, buf, 10);
92
+  getBuffer( _length = strlen(buf) );
93
+  if ( _buffer != NULL )
94
+    strcpy( _buffer, buf );
95
+}
96
+
97
+char String::charAt( unsigned int loc ) const
98
+{
99
+  return operator[]( loc );
100
+}
101
+
102
+void String::setCharAt( unsigned int loc, const char aChar ) 
103
+{
104
+  if(_buffer == NULL) return;
105
+  if(_length > loc) {
106
+    _buffer[loc] = aChar;
107
+  }
108
+}
109
+
110
+int String::compareTo( const String &s2 ) const
111
+{
112
+  return strcmp( _buffer, s2._buffer );
113
+}
114
+
115
+const String & String::concat( const String &s2 )
116
+{
117
+  return (*this) += s2;
118
+}
119
+
120
+const String & String::operator=( const String &rhs )
121
+{
122
+  if ( this == &rhs )
123
+    return *this;
124
+
125
+  if ( rhs._length > _length )
126
+  {
127
+    free(_buffer);
128
+    getBuffer( rhs._length );
129
+  }
130
+  
131
+  if ( _buffer != NULL ) {
132
+    _length = rhs._length;
133
+    strcpy( _buffer, rhs._buffer );
134
+  }
135
+  return *this;
136
+}
137
+
138
+//const String & String::operator+=( const char aChar )
139
+//{
140
+//  if ( _length == _capacity )
141
+//    doubleBuffer();
142
+//
143
+//  _buffer[ _length++ ] = aChar;
144
+//  _buffer[ _length ] = '\0';
145
+//  return *this;
146
+//}
147
+
148
+const String & String::operator+=( const String &other )
149
+{
150
+  _length += other._length;
151
+  if ( _length > _capacity )
152
+  {
153
+    char *temp = (char *)realloc(_buffer, _length + 1);
154
+    if ( temp != NULL ) {
155
+      _buffer = temp;
156
+      _capacity = _length;
157
+    } else {
158
+      _length -= other._length;
159
+      return *this;
160
+    }
161
+  }
162
+  strcat( _buffer, other._buffer );
163
+  return *this;
164
+}
165
+
166
+
167
+int String::operator==( const String &rhs ) const
168
+{
169
+  return ( _length == rhs._length && strcmp( _buffer, rhs._buffer ) == 0 );
170
+}
171
+
172
+int String::operator!=( const String &rhs ) const
173
+{
174
+  return ( _length != rhs.length() || strcmp( _buffer, rhs._buffer ) != 0 );
175
+}
176
+
177
+int String::operator<( const String &rhs ) const
178
+{
179
+  return strcmp( _buffer, rhs._buffer ) < 0;
180
+}
181
+
182
+int String::operator>( const String &rhs ) const
183
+{
184
+  return strcmp( _buffer, rhs._buffer ) > 0;
185
+}
186
+
187
+int String::operator<=( const String &rhs ) const
188
+{
189
+  return strcmp( _buffer, rhs._buffer ) <= 0;
190
+}
191
+
192
+int String::operator>=( const String & rhs ) const
193
+{
194
+  return strcmp( _buffer, rhs._buffer ) >= 0;
195
+}
196
+
197
+char & String::operator[]( unsigned int index )
198
+{
199
+  static char dummy_writable_char;
200
+  if (index >= _length || !_buffer) {
201
+    dummy_writable_char = 0;
202
+    return dummy_writable_char;
203
+  }
204
+  return _buffer[ index ];
205
+}
206
+
207
+char String::operator[]( unsigned int index ) const
208
+{
209
+  // need to check for valid index, to do later
210
+  return _buffer[ index ];
211
+}
212
+
213
+boolean String::endsWith( const String &s2 ) const
214
+{
215
+  if ( _length < s2._length )
216
+    return 0;
217
+
218
+  return strcmp( &_buffer[ _length - s2._length], s2._buffer ) == 0;
219
+}
220
+
221
+boolean String::equals( const String &s2 ) const
222
+{
223
+  return ( _length == s2._length && strcmp( _buffer,s2._buffer ) == 0 );
224
+}
225
+
226
+boolean String::equalsIgnoreCase( const String &s2 ) const
227
+{
228
+  if ( this == &s2 )
229
+    return true; //1;
230
+  else if ( _length != s2._length )
231
+    return false; //0;
232
+
233
+  return strcmp(toLowerCase()._buffer, s2.toLowerCase()._buffer) == 0;
234
+}
235
+
236
+String String::replace( char findChar, char replaceChar )
237
+{
238
+  if ( _buffer == NULL ) return *this;
239
+  String theReturn = _buffer;
240
+  char* temp = theReturn._buffer;
241
+  while( (temp = strchr( temp, findChar )) != 0 )
242
+    *temp = replaceChar;
243
+
244
+  return theReturn;
245
+}
246
+
247
+String String::replace( const String& match, const String& replace )
248
+{
249
+  if ( _buffer == NULL ) return *this;
250
+  String temp = _buffer, newString;
251
+
252
+  int loc;
253
+  while ( (loc = temp.indexOf( match )) != -1 )
254
+  {
255
+    newString += temp.substring( 0, loc );
256
+    newString += replace;
257
+    temp = temp.substring( loc + match._length );
258
+  }
259
+  newString += temp;  
260
+  return newString;
261
+}
262
+
263
+int String::indexOf( char temp ) const
264
+{
265
+  return indexOf( temp, 0 );
266
+}
267
+
268
+int String::indexOf( char ch, unsigned int fromIndex ) const
269
+{
270
+  if ( fromIndex >= _length )
271
+    return -1;
272
+
273
+  const char* temp = strchr( &_buffer[fromIndex], ch );
274
+  if ( temp == NULL )
275
+    return -1;
276
+
277
+  return temp - _buffer;
278
+}
279
+
280
+int String::indexOf( const String &s2 ) const
281
+{
282
+  return indexOf( s2, 0 );
283
+}
284
+
285
+int String::indexOf( const String &s2, unsigned int fromIndex ) const
286
+{
287
+  if ( fromIndex >= _length )
288
+    return -1;
289
+
290
+  const char *theFind = strstr( &_buffer[ fromIndex ], s2._buffer );
291
+
292
+  if ( theFind == NULL )
293
+    return -1;
294
+
295
+  return theFind - _buffer; // pointer subtraction
296
+}
297
+
298
+int String::lastIndexOf( char theChar ) const
299
+{
300
+  return lastIndexOf( theChar, _length - 1 );
301
+}
302
+
303
+int String::lastIndexOf( char ch, unsigned int fromIndex ) const
304
+{
305
+  if ( fromIndex >= _length )
306
+    return -1;
307
+
308
+  char tempchar = _buffer[fromIndex + 1];
309
+  _buffer[fromIndex + 1] = '\0';
310
+  char* temp = strrchr( _buffer, ch );
311
+  _buffer[fromIndex + 1] = tempchar;
312
+
313
+  if ( temp == NULL )
314
+    return -1;
315
+
316
+  return temp - _buffer;
317
+}
318
+
319
+int String::lastIndexOf( const String &s2 ) const
320
+{
321
+  return lastIndexOf( s2, _length - s2._length );
322
+}
323
+
324
+int String::lastIndexOf( const String &s2, unsigned int fromIndex ) const
325
+{
326
+  // check for empty strings
327
+  if ( s2._length == 0 || s2._length - 1 > fromIndex || fromIndex >= _length )
328
+    return -1;
329
+
330
+  // matching first character
331
+  char temp = s2[ 0 ];
332
+
333
+  for ( int i = fromIndex; i >= 0; i-- )
334
+  {
335
+    if ( _buffer[ i ] == temp && (*this).substring( i, i + s2._length ).equals( s2 ) )
336
+    return i;
337
+  }
338
+  return -1;
339
+}
340
+
341
+boolean String::startsWith( const String &s2 ) const
342
+{
343
+  if ( _length < s2._length )
344
+    return 0;
345
+
346
+  return startsWith( s2, 0 );
347
+}
348
+
349
+boolean String::startsWith( const String &s2, unsigned int offset ) const
350
+{
351
+  if ( offset > _length - s2._length )
352
+    return 0;
353
+
354
+  return strncmp( &_buffer[offset], s2._buffer, s2._length ) == 0;
355
+}
356
+
357
+String String::substring( unsigned int left ) const
358
+{
359
+  return substring( left, _length );
360
+}
361
+
362
+String String::substring( unsigned int left, unsigned int right ) const
363
+{
364
+  if ( left > right )
365
+  {
366
+    int temp = right;
367
+    right = left;
368
+    left = temp;
369
+  }
370
+
371
+  if ( right > _length )
372
+  {
373
+    right = _length;
374
+  } 
375
+
376
+  char temp = _buffer[ right ];  // save the replaced character
377
+  _buffer[ right ] = '\0';	
378
+  String outPut = ( _buffer + left );  // pointer arithmetic
379
+  _buffer[ right ] = temp;  //restore character
380
+  return outPut;
381
+}
382
+
383
+String String::toLowerCase() const
384
+{
385
+  String temp = _buffer;
386
+
387
+  for ( unsigned int i = 0; i < _length; i++ )
388
+    temp._buffer[ i ] = (char)tolower( temp._buffer[ i ] );
389
+  return temp;
390
+}
391
+
392
+String String::toUpperCase() const
393
+{
394
+  String temp = _buffer;
395
+
396
+  for ( unsigned int i = 0; i < _length; i++ )
397
+    temp._buffer[ i ] = (char)toupper( temp._buffer[ i ] );
398
+  return temp;
399
+}
400
+
401
+String String::trim() const
402
+{
403
+  if ( _buffer == NULL ) return *this;
404
+  String temp = _buffer;
405
+  unsigned int i,j;
406
+
407
+  for ( i = 0; i < _length; i++ )
408
+  {
409
+    if ( !isspace(_buffer[i]) )
410
+      break;
411
+  }
412
+
413
+  for ( j = temp._length - 1; j > i; j-- )
414
+  {
415
+    if ( !isspace(_buffer[j]) )
416
+      break;
417
+  }
418
+
419
+  return temp.substring( i, j + 1);
420
+}
421
+
422
+void String::getBytes(unsigned char *buf, unsigned int bufsize)
423
+{
424
+  if (!bufsize || !buf) return;
425
+  unsigned int len = bufsize - 1;
426
+  if (len > _length) len = _length;
427
+  strncpy((char *)buf, _buffer, len);
428
+  buf[len] = 0;
429
+}
430
+
431
+void String::toCharArray(char *buf, unsigned int bufsize)
432
+{
433
+  if (!bufsize || !buf) return;
434
+  unsigned int len = bufsize - 1;
435
+  if (len > _length) len = _length;
436
+  strncpy(buf, _buffer, len);
437
+  buf[len] = 0;
438
+}
439
+
440
+
441
+long String::toInt() {
442
+  return atol(_buffer);
443
+}

+ 112
- 0
Marlin/Marlin/Gen7/cores/arduino/WString.h Переглянути файл

1
+/*
2
+  WString.h - String library for Wiring & Arduino
3
+  Copyright (c) 2009-10 Hernando Barragan.  All right 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 String_h
21
+#define String_h
22
+
23
+//#include "WProgram.h"
24
+#include <stdlib.h>
25
+#include <string.h>
26
+#include <ctype.h>
27
+
28
+class String
29
+{
30
+  public:
31
+    // constructors
32
+    String( const char *value = "" );
33
+    String( const String &value );
34
+    String( const char );
35
+    String( const unsigned char );
36
+    String( const int, const int base=10);
37
+    String( const unsigned int, const int base=10 );
38
+    String( const long, const int base=10 );
39
+    String( const unsigned long, const int base=10 );
40
+    ~String() { free(_buffer); _length = _capacity = 0;}     //added _length = _capacity = 0;
41
+
42
+    // operators
43
+    const String & operator = ( const String &rhs );
44
+    const String & operator +=( const String &rhs );
45
+    //const String & operator +=( const char );
46
+    int operator ==( const String &rhs ) const;
47
+    int	operator !=( const String &rhs ) const;
48
+    int	operator < ( const String &rhs ) const;
49
+    int	operator > ( const String &rhs ) const;
50
+    int	operator <=( const String &rhs ) const;
51
+    int	operator >=( const String &rhs ) const;
52
+    char operator []( unsigned int index ) const;
53
+    char& operator []( unsigned int index );
54
+    //operator const char *() const { return _buffer; }
55
+    
56
+    // general methods
57
+    char charAt( unsigned int index ) const;
58
+    int	compareTo( const String &anotherString ) const;
59
+    unsigned char endsWith( const String &suffix ) const;
60
+    unsigned char equals( const String &anObject ) const;
61
+    unsigned char equalsIgnoreCase( const String &anotherString ) const;
62
+    int	indexOf( char ch ) const;
63
+    int	indexOf( char ch, unsigned int fromIndex ) const;
64
+    int	indexOf( const String &str ) const;
65
+    int	indexOf( const String &str, unsigned int fromIndex ) const;
66
+    int	lastIndexOf( char ch ) const;
67
+    int	lastIndexOf( char ch, unsigned int fromIndex ) const;
68
+    int	lastIndexOf( const String &str ) const;
69
+    int	lastIndexOf( const String &str, unsigned int fromIndex ) const;
70
+    const unsigned int length( ) const { return _length; }
71
+    void setCharAt(unsigned int index, const char ch);
72
+    unsigned char startsWith( const String &prefix ) const;
73
+    unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
74
+    String substring( unsigned int beginIndex ) const;
75
+    String substring( unsigned int beginIndex, unsigned int endIndex ) const;
76
+    String toLowerCase( ) const;
77
+    String toUpperCase( ) const;
78
+    String trim( ) const;
79
+    void getBytes(unsigned char *buf, unsigned int bufsize);
80
+    void toCharArray(char *buf, unsigned int bufsize);
81
+    long toInt( );
82
+    const String& concat( const String &str );
83
+    String replace( char oldChar, char newChar );
84
+    String replace( const String& match, const String& replace );
85
+    friend String operator + ( String lhs, const String &rhs );
86
+
87
+  protected:
88
+    char *_buffer;	     // the actual char array
89
+    unsigned int _capacity;  // the array length minus one (for the '\0')
90
+    unsigned int _length;    // the String length (not counting the '\0')
91
+
92
+    void getBuffer(unsigned int maxStrLen);
93
+
94
+  private:
95
+
96
+};
97
+
98
+// allocate buffer space
99
+inline void String::getBuffer(unsigned int maxStrLen)
100
+{
101
+  _capacity = maxStrLen;
102
+  _buffer = (char *) malloc(_capacity + 1);
103
+  if (_buffer == NULL) _length = _capacity = 0;
104
+}
105
+
106
+inline String operator+( String lhs, const String &rhs )
107
+{
108
+  return lhs += rhs;
109
+}
110
+
111
+
112
+#endif

+ 515
- 0
Marlin/Marlin/Gen7/cores/arduino/binary.h Переглянути файл

1
+#ifndef Binary_h
2
+#define Binary_h
3
+
4
+#define B0 0
5
+#define B00 0
6
+#define B000 0
7
+#define B0000 0
8
+#define B00000 0
9
+#define B000000 0
10
+#define B0000000 0
11
+#define B00000000 0
12
+#define B1 1
13
+#define B01 1
14
+#define B001 1
15
+#define B0001 1
16
+#define B00001 1
17
+#define B000001 1
18
+#define B0000001 1
19
+#define B00000001 1
20
+#define B10 2
21
+#define B010 2
22
+#define B0010 2
23
+#define B00010 2
24
+#define B000010 2
25
+#define B0000010 2
26
+#define B00000010 2
27
+#define B11 3
28
+#define B011 3
29
+#define B0011 3
30
+#define B00011 3
31
+#define B000011 3
32
+#define B0000011 3
33
+#define B00000011 3
34
+#define B100 4
35
+#define B0100 4
36
+#define B00100 4
37
+#define B000100 4
38
+#define B0000100 4
39
+#define B00000100 4
40
+#define B101 5
41
+#define B0101 5
42
+#define B00101 5
43
+#define B000101 5
44
+#define B0000101 5
45
+#define B00000101 5
46
+#define B110 6
47
+#define B0110 6
48
+#define B00110 6
49
+#define B000110 6
50
+#define B0000110 6
51
+#define B00000110 6
52
+#define B111 7
53
+#define B0111 7
54
+#define B00111 7
55
+#define B000111 7
56
+#define B0000111 7
57
+#define B00000111 7
58
+#define B1000 8
59
+#define B01000 8
60
+#define B001000 8
61
+#define B0001000 8
62
+#define B00001000 8
63
+#define B1001 9
64
+#define B01001 9
65
+#define B001001 9
66
+#define B0001001 9
67
+#define B00001001 9
68
+#define B1010 10
69
+#define B01010 10
70
+#define B001010 10
71
+#define B0001010 10
72
+#define B00001010 10
73
+#define B1011 11
74
+#define B01011 11
75
+#define B001011 11
76
+#define B0001011 11
77
+#define B00001011 11
78
+#define B1100 12
79
+#define B01100 12
80
+#define B001100 12
81
+#define B0001100 12
82
+#define B00001100 12
83
+#define B1101 13
84
+#define B01101 13
85
+#define B001101 13
86
+#define B0001101 13
87
+#define B00001101 13
88
+#define B1110 14
89
+#define B01110 14
90
+#define B001110 14
91
+#define B0001110 14
92
+#define B00001110 14
93
+#define B1111 15
94
+#define B01111 15
95
+#define B001111 15
96
+#define B0001111 15
97
+#define B00001111 15
98
+#define B10000 16
99
+#define B010000 16
100
+#define B0010000 16
101
+#define B00010000 16
102
+#define B10001 17
103
+#define B010001 17
104
+#define B0010001 17
105
+#define B00010001 17
106
+#define B10010 18
107
+#define B010010 18
108
+#define B0010010 18
109
+#define B00010010 18
110
+#define B10011 19
111
+#define B010011 19
112
+#define B0010011 19
113
+#define B00010011 19
114
+#define B10100 20
115
+#define B010100 20
116
+#define B0010100 20
117
+#define B00010100 20
118
+#define B10101 21
119
+#define B010101 21
120
+#define B0010101 21
121
+#define B00010101 21
122
+#define B10110 22
123
+#define B010110 22
124
+#define B0010110 22
125
+#define B00010110 22
126
+#define B10111 23
127
+#define B010111 23
128
+#define B0010111 23
129
+#define B00010111 23
130
+#define B11000 24
131
+#define B011000 24
132
+#define B0011000 24
133
+#define B00011000 24
134
+#define B11001 25
135
+#define B011001 25
136
+#define B0011001 25
137
+#define B00011001 25
138
+#define B11010 26
139
+#define B011010 26
140
+#define B0011010 26
141
+#define B00011010 26
142
+#define B11011 27
143
+#define B011011 27
144
+#define B0011011 27
145
+#define B00011011 27
146
+#define B11100 28
147
+#define B011100 28
148
+#define B0011100 28
149
+#define B00011100 28
150
+#define B11101 29
151
+#define B011101 29
152
+#define B0011101 29
153
+#define B00011101 29
154
+#define B11110 30
155
+#define B011110 30
156
+#define B0011110 30
157
+#define B00011110 30
158
+#define B11111 31
159
+#define B011111 31
160
+#define B0011111 31
161
+#define B00011111 31
162
+#define B100000 32
163
+#define B0100000 32
164
+#define B00100000 32
165
+#define B100001 33
166
+#define B0100001 33
167
+#define B00100001 33
168
+#define B100010 34
169
+#define B0100010 34
170
+#define B00100010 34
171
+#define B100011 35
172
+#define B0100011 35
173
+#define B00100011 35
174
+#define B100100 36
175
+#define B0100100 36
176
+#define B00100100 36
177
+#define B100101 37
178
+#define B0100101 37
179
+#define B00100101 37
180
+#define B100110 38
181
+#define B0100110 38
182
+#define B00100110 38
183
+#define B100111 39
184
+#define B0100111 39
185
+#define B00100111 39
186
+#define B101000 40
187
+#define B0101000 40
188
+#define B00101000 40
189
+#define B101001 41
190
+#define B0101001 41
191
+#define B00101001 41
192
+#define B101010 42
193
+#define B0101010 42
194
+#define B00101010 42
195
+#define B101011 43
196
+#define B0101011 43
197
+#define B00101011 43
198
+#define B101100 44
199
+#define B0101100 44
200
+#define B00101100 44
201
+#define B101101 45
202
+#define B0101101 45
203
+#define B00101101 45
204
+#define B101110 46
205
+#define B0101110 46
206
+#define B00101110 46
207
+#define B101111 47
208
+#define B0101111 47
209
+#define B00101111 47
210
+#define B110000 48
211
+#define B0110000 48
212
+#define B00110000 48
213
+#define B110001 49
214
+#define B0110001 49
215
+#define B00110001 49
216
+#define B110010 50
217
+#define B0110010 50
218
+#define B00110010 50
219
+#define B110011 51
220
+#define B0110011 51
221
+#define B00110011 51
222
+#define B110100 52
223
+#define B0110100 52
224
+#define B00110100 52
225
+#define B110101 53
226
+#define B0110101 53
227
+#define B00110101 53
228
+#define B110110 54
229
+#define B0110110 54
230
+#define B00110110 54
231
+#define B110111 55
232
+#define B0110111 55
233
+#define B00110111 55
234
+#define B111000 56
235
+#define B0111000 56
236
+#define B00111000 56
237
+#define B111001 57
238
+#define B0111001 57
239
+#define B00111001 57
240
+#define B111010 58
241
+#define B0111010 58
242
+#define B00111010 58
243
+#define B111011 59
244
+#define B0111011 59
245
+#define B00111011 59
246
+#define B111100 60
247
+#define B0111100 60
248
+#define B00111100 60
249
+#define B111101 61
250
+#define B0111101 61
251
+#define B00111101 61
252
+#define B111110 62
253
+#define B0111110 62
254
+#define B00111110 62
255
+#define B111111 63
256
+#define B0111111 63
257
+#define B00111111 63
258
+#define B1000000 64
259
+#define B01000000 64
260
+#define B1000001 65
261
+#define B01000001 65
262
+#define B1000010 66
263
+#define B01000010 66
264
+#define B1000011 67
265
+#define B01000011 67
266
+#define B1000100 68
267
+#define B01000100 68
268
+#define B1000101 69
269
+#define B01000101 69
270
+#define B1000110 70
271
+#define B01000110 70
272
+#define B1000111 71
273
+#define B01000111 71
274
+#define B1001000 72
275
+#define B01001000 72
276
+#define B1001001 73
277
+#define B01001001 73
278
+#define B1001010 74
279
+#define B01001010 74
280
+#define B1001011 75
281
+#define B01001011 75
282
+#define B1001100 76
283
+#define B01001100 76
284
+#define B1001101 77
285
+#define B01001101 77
286
+#define B1001110 78
287
+#define B01001110 78
288
+#define B1001111 79
289
+#define B01001111 79
290
+#define B1010000 80
291
+#define B01010000 80
292
+#define B1010001 81
293
+#define B01010001 81
294
+#define B1010010 82
295
+#define B01010010 82
296
+#define B1010011 83
297
+#define B01010011 83
298
+#define B1010100 84
299
+#define B01010100 84
300
+#define B1010101 85
301
+#define B01010101 85
302
+#define B1010110 86
303
+#define B01010110 86
304
+#define B1010111 87
305
+#define B01010111 87
306
+#define B1011000 88
307
+#define B01011000 88
308
+#define B1011001 89
309
+#define B01011001 89
310
+#define B1011010 90
311
+#define B01011010 90
312
+#define B1011011 91
313
+#define B01011011 91
314
+#define B1011100 92
315
+#define B01011100 92
316
+#define B1011101 93
317
+#define B01011101 93
318
+#define B1011110 94
319
+#define B01011110 94
320
+#define B1011111 95
321
+#define B01011111 95
322
+#define B1100000 96
323
+#define B01100000 96
324
+#define B1100001 97
325
+#define B01100001 97
326
+#define B1100010 98
327
+#define B01100010 98
328
+#define B1100011 99
329
+#define B01100011 99
330
+#define B1100100 100
331
+#define B01100100 100
332
+#define B1100101 101
333
+#define B01100101 101
334
+#define B1100110 102
335
+#define B01100110 102
336
+#define B1100111 103
337
+#define B01100111 103
338
+#define B1101000 104
339
+#define B01101000 104
340
+#define B1101001 105
341
+#define B01101001 105
342
+#define B1101010 106
343
+#define B01101010 106
344
+#define B1101011 107
345
+#define B01101011 107
346
+#define B1101100 108
347
+#define B01101100 108
348
+#define B1101101 109
349
+#define B01101101 109
350
+#define B1101110 110
351
+#define B01101110 110
352
+#define B1101111 111
353
+#define B01101111 111
354
+#define B1110000 112
355
+#define B01110000 112
356
+#define B1110001 113
357
+#define B01110001 113
358
+#define B1110010 114
359
+#define B01110010 114
360
+#define B1110011 115
361
+#define B01110011 115
362
+#define B1110100 116
363
+#define B01110100 116
364
+#define B1110101 117
365
+#define B01110101 117
366
+#define B1110110 118
367
+#define B01110110 118
368
+#define B1110111 119
369
+#define B01110111 119
370
+#define B1111000 120
371
+#define B01111000 120
372
+#define B1111001 121
373
+#define B01111001 121
374
+#define B1111010 122
375
+#define B01111010 122
376
+#define B1111011 123
377
+#define B01111011 123
378
+#define B1111100 124
379
+#define B01111100 124
380
+#define B1111101 125
381
+#define B01111101 125
382
+#define B1111110 126
383
+#define B01111110 126
384
+#define B1111111 127
385
+#define B01111111 127
386
+#define B10000000 128
387
+#define B10000001 129
388
+#define B10000010 130
389
+#define B10000011 131
390
+#define B10000100 132
391
+#define B10000101 133
392
+#define B10000110 134
393
+#define B10000111 135
394
+#define B10001000 136
395
+#define B10001001 137
396
+#define B10001010 138
397
+#define B10001011 139
398
+#define B10001100 140
399
+#define B10001101 141
400
+#define B10001110 142
401
+#define B10001111 143
402
+#define B10010000 144
403
+#define B10010001 145
404
+#define B10010010 146
405
+#define B10010011 147
406
+#define B10010100 148
407
+#define B10010101 149
408
+#define B10010110 150
409
+#define B10010111 151
410
+#define B10011000 152
411
+#define B10011001 153
412
+#define B10011010 154
413
+#define B10011011 155
414
+#define B10011100 156
415
+#define B10011101 157
416
+#define B10011110 158
417
+#define B10011111 159
418
+#define B10100000 160
419
+#define B10100001 161
420
+#define B10100010 162
421
+#define B10100011 163
422
+#define B10100100 164
423
+#define B10100101 165
424
+#define B10100110 166
425
+#define B10100111 167
426
+#define B10101000 168
427
+#define B10101001 169
428
+#define B10101010 170
429
+#define B10101011 171
430
+#define B10101100 172
431
+#define B10101101 173
432
+#define B10101110 174
433
+#define B10101111 175
434
+#define B10110000 176
435
+#define B10110001 177
436
+#define B10110010 178
437
+#define B10110011 179
438
+#define B10110100 180
439
+#define B10110101 181
440
+#define B10110110 182
441
+#define B10110111 183
442
+#define B10111000 184
443
+#define B10111001 185
444
+#define B10111010 186
445
+#define B10111011 187
446
+#define B10111100 188
447
+#define B10111101 189
448
+#define B10111110 190
449
+#define B10111111 191
450
+#define B11000000 192
451
+#define B11000001 193
452
+#define B11000010 194
453
+#define B11000011 195
454
+#define B11000100 196
455
+#define B11000101 197
456
+#define B11000110 198
457
+#define B11000111 199
458
+#define B11001000 200
459
+#define B11001001 201
460
+#define B11001010 202
461
+#define B11001011 203
462
+#define B11001100 204
463
+#define B11001101 205
464
+#define B11001110 206
465
+#define B11001111 207
466
+#define B11010000 208
467
+#define B11010001 209
468
+#define B11010010 210
469
+#define B11010011 211
470
+#define B11010100 212
471
+#define B11010101 213
472
+#define B11010110 214
473
+#define B11010111 215
474
+#define B11011000 216
475
+#define B11011001 217
476
+#define B11011010 218
477
+#define B11011011 219
478
+#define B11011100 220
479
+#define B11011101 221
480
+#define B11011110 222
481
+#define B11011111 223
482
+#define B11100000 224
483
+#define B11100001 225
484
+#define B11100010 226
485
+#define B11100011 227
486
+#define B11100100 228
487
+#define B11100101 229
488
+#define B11100110 230
489
+#define B11100111 231
490
+#define B11101000 232
491
+#define B11101001 233
492
+#define B11101010 234
493
+#define B11101011 235
494
+#define B11101100 236
495
+#define B11101101 237
496
+#define B11101110 238
497
+#define B11101111 239
498
+#define B11110000 240
499
+#define B11110001 241
500
+#define B11110010 242
501
+#define B11110011 243
502
+#define B11110100 244
503
+#define B11110101 245
504
+#define B11110110 246
505
+#define B11110111 247
506
+#define B11111000 248
507
+#define B11111001 249
508
+#define B11111010 250
509
+#define B11111011 251
510
+#define B11111100 252
511
+#define B11111101 253
512
+#define B11111110 254
513
+#define B11111111 255
514
+
515
+#endif

+ 14
- 0
Marlin/Marlin/Gen7/cores/arduino/main.cpp Переглянути файл

1
+#include <WProgram.h>
2
+
3
+int main(void)
4
+{
5
+	init();
6
+
7
+	setup();
8
+    
9
+	for (;;)
10
+		loop();
11
+        
12
+	return 0;
13
+}
14
+

+ 12
- 0
Marlin/Marlin/Gen7/cores/arduino/main.cxx Переглянути файл

1
+int main(void)
2
+{
3
+	init();
4
+
5
+	setup();
6
+    
7
+	for (;;)
8
+		loop();
9
+        
10
+	return 0;
11
+}
12
+

+ 200
- 0
Marlin/Marlin/Gen7/cores/arduino/pins_arduino.c Переглянути файл

1
+/*
2
+  pins_arduino.c - pin definitions for the Arduino board
3
+  Part of Arduino / Wiring Lite
4
+
5
+  Copyright (c) 2005 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: pins_arduino.c 254 2007-04-20 23:17:38Z mellis $
23
+*/
24
+
25
+#include <avr/io.h>
26
+#include "wiring_private.h"
27
+#include "pins_arduino.h"
28
+
29
+// On the Sanguino board, digital pins are also used
30
+// for the analog output (software PWM).  Analog input
31
+// pins are a separate set.
32
+
33
+// ATMEL ATMEGA644P / SANGUINO
34
+//
35
+//                   +---\/---+
36
+//  INT0 (D 0) PB0  1|        |40  PA0 (AI 0 / D31)
37
+//  INT1 (D 1) PB1  2|        |39  PA1 (AI 1 / D30)
38
+//  INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D29)
39
+//   PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D28)
40
+//   PWM (D 4) PB4  5|        |36  PA4 (AI 4 / D27)
41
+//  MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D26)
42
+//  MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D25)
43
+//   SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D24)
44
+//             RST  9|        |32  AREF
45
+//             VCC 10|        |31  GND 
46
+//             GND 11|        |30  AVCC
47
+//           XTAL2 12|        |29  PC7 (D 23)
48
+//           XTAL1 13|        |28  PC6 (D 22)
49
+//  RX0 (D 8)  PD0 14|        |27  PC5 (D 21) TDI
50
+//  TX0 (D 9)  PD1 15|        |26  PC4 (D 20) TDO
51
+//  RX1 (D 10) PD2 16|        |25  PC3 (D 19) TMS
52
+//  TX1 (D 11) PD3 17|        |24  PC2 (D 18) TCK
53
+//  PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA
54
+//  PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL
55
+//  PWM (D 14) PD6 20|        |21  PD7 (D 15) PWM
56
+//                   +--------+
57
+//
58
+
59
+#define PA 1
60
+#define PB 2
61
+#define PC 3
62
+#define PD 4
63
+
64
+// these arrays map port names (e.g. port B) to the
65
+// appropriate addresses for various functions (e.g. reading
66
+// and writing)
67
+const uint8_t PROGMEM port_to_mode_PGM[] =
68
+{
69
+	NOT_A_PORT,
70
+        (uint8_t) &DDRA,
71
+	(uint8_t) &DDRB,
72
+	(uint8_t) &DDRC,
73
+	(uint8_t) &DDRD,
74
+};
75
+
76
+const uint8_t PROGMEM port_to_output_PGM[] =
77
+{
78
+	NOT_A_PORT,
79
+	(uint8_t) &PORTA,
80
+	(uint8_t) &PORTB,
81
+	(uint8_t) &PORTC,
82
+	(uint8_t) &PORTD,
83
+};
84
+
85
+const uint8_t PROGMEM port_to_input_PGM[] =
86
+{
87
+	NOT_A_PORT,
88
+	(uint8_t) &PINA,
89
+	(uint8_t) &PINB,
90
+	(uint8_t) &PINC,
91
+	(uint8_t) &PIND,
92
+};
93
+
94
+const uint8_t PROGMEM digital_pin_to_port_PGM[] =
95
+{
96
+	PB, /* 0 */
97
+	PB,
98
+	PB,
99
+	PB,
100
+	PB,
101
+	PB,
102
+	PB,
103
+	PB,
104
+	PD, /* 8 */
105
+	PD,
106
+	PD,
107
+	PD,
108
+	PD,
109
+	PD,
110
+	PD,
111
+	PD,
112
+	PC, /* 16 */
113
+	PC,
114
+	PC,
115
+	PC,
116
+	PC,
117
+	PC,
118
+   	PC,
119
+	PC,
120
+	PA, /* 24 */
121
+	PA,
122
+	PA,
123
+	PA,
124
+	PA,
125
+	PA,
126
+	PA,
127
+	PA  /* 31 */
128
+};
129
+
130
+const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
131
+{
132
+	_BV(0), /* 0, port B */
133
+	_BV(1),
134
+	_BV(2),
135
+	_BV(3),
136
+	_BV(4),
137
+	_BV(5),
138
+	_BV(6),
139
+	_BV(7),
140
+	_BV(0), /* 8, port D */
141
+	_BV(1),
142
+	_BV(2),
143
+	_BV(3),
144
+	_BV(4),
145
+	_BV(5),
146
+	_BV(6),
147
+	_BV(7),
148
+	_BV(0), /* 16, port C */
149
+	_BV(1),
150
+	_BV(2),
151
+	_BV(3),
152
+	_BV(4),
153
+	_BV(5),
154
+	_BV(6),
155
+	_BV(7),
156
+	_BV(7), /* 24, port A */
157
+	_BV(6),
158
+	_BV(5),
159
+	_BV(4),
160
+	_BV(3),
161
+	_BV(2),
162
+	_BV(1),
163
+	_BV(0)
164
+};
165
+
166
+const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
167
+{
168
+	NOT_ON_TIMER, 	/* 0  - PB0 */
169
+	NOT_ON_TIMER, 	/* 1  - PB1 */
170
+	NOT_ON_TIMER, 	/* 2  - PB2 */
171
+	TIMER0A,     	/* 3  - PB3 */
172
+	TIMER0B, 		/* 4  - PB4 */
173
+	NOT_ON_TIMER, 	/* 5  - PB5 */
174
+	NOT_ON_TIMER, 	/* 6  - PB6 */
175
+	NOT_ON_TIMER,	/* 7  - PB7 */
176
+	NOT_ON_TIMER, 	/* 8  - PD0 */
177
+	NOT_ON_TIMER, 	/* 9  - PD1 */
178
+	NOT_ON_TIMER, 	/* 10 - PD2 */
179
+	NOT_ON_TIMER, 	/* 11 - PD3 */
180
+	TIMER1B,     	/* 12 - PD4 */
181
+	TIMER1A,     	/* 13 - PD5 */
182
+	TIMER2B,     	/* 14 - PD6 */
183
+	TIMER2A,     	/* 15 - PD7 */
184
+	NOT_ON_TIMER, 	/* 16 - PC0 */
185
+	NOT_ON_TIMER,   /* 17 - PC1 */
186
+	NOT_ON_TIMER,   /* 18 - PC2 */
187
+	NOT_ON_TIMER,   /* 19 - PC3 */
188
+	NOT_ON_TIMER,   /* 20 - PC4 */
189
+	NOT_ON_TIMER,   /* 21 - PC5 */
190
+	NOT_ON_TIMER,   /* 22 - PC6 */
191
+	NOT_ON_TIMER,   /* 23 - PC7 */
192
+	NOT_ON_TIMER,   /* 24 - PA0 */
193
+	NOT_ON_TIMER,   /* 25 - PA1 */
194
+	NOT_ON_TIMER,   /* 26 - PA2 */
195
+	NOT_ON_TIMER,   /* 27 - PA3 */
196
+	NOT_ON_TIMER,   /* 28 - PA4 */
197
+	NOT_ON_TIMER,   /* 29 - PA5 */
198
+	NOT_ON_TIMER,   /* 30 - PA6 */
199
+	NOT_ON_TIMER   /* 31 - PA7 */
200
+};

+ 65
- 0
Marlin/Marlin/Gen7/cores/arduino/pins_arduino.h Переглянути файл

1
+/*
2
+  pins_arduino.h - Pin definition functions for Arduino
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2007 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
23
+*/
24
+
25
+#ifndef Pins_Arduino_h
26
+#define Pins_Arduino_h
27
+
28
+#include <avr/pgmspace.h>
29
+
30
+#define NOT_A_PIN 0
31
+#define NOT_A_PORT 0
32
+
33
+#define NOT_ON_TIMER 0
34
+#define TIMER0A 1
35
+#define TIMER0B 2
36
+#define TIMER1A 3
37
+#define TIMER1B 4
38
+#define TIMER2  5
39
+#define TIMER2A 6
40
+#define TIMER2B 7
41
+
42
+extern const uint8_t PROGMEM port_to_mode_PGM[];
43
+extern const uint8_t PROGMEM port_to_input_PGM[];
44
+extern const uint8_t PROGMEM port_to_output_PGM[];
45
+
46
+extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
47
+extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
48
+extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
49
+
50
+extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
51
+
52
+// Get the bit location within the hardware port of the given virtual pin.
53
+// This comes from the pins_*.c file for the active board configuration.
54
+// 
55
+// These perform slightly better as macros compared to inline functions
56
+//
57
+#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
58
+#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
59
+#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
60
+#define analogInPinToBit(P) (P)
61
+#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_output_PGM + (P))) )
62
+#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_input_PGM + (P))) )
63
+#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_mode_PGM + (P))) )
64
+
65
+#endif

+ 203
- 0
Marlin/Marlin/Gen7/cores/arduino/wiring.c Переглянути файл

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

+ 133
- 0
Marlin/Marlin/Gen7/cores/arduino/wiring.h Переглянути файл

1
+/*
2
+  wiring.h - Partial implementation of the Wiring API for the ATmega8.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.h 387 2008-03-08 21:30:00Z mellis $
23
+*/
24
+
25
+#ifndef Wiring_h
26
+#define Wiring_h
27
+
28
+#include <avr/io.h>
29
+#include "binary.h"
30
+
31
+#ifdef __cplusplus
32
+extern "C"{
33
+#endif
34
+
35
+#define HIGH 0x1
36
+#define LOW  0x0
37
+
38
+#define INPUT 0x0
39
+#define OUTPUT 0x1
40
+
41
+#define true 0x1
42
+#define false 0x0
43
+
44
+#define PI 3.14159265
45
+#define HALF_PI 1.57079
46
+#define TWO_PI 6.283185
47
+#define DEG_TO_RAD 0.01745329
48
+#define RAD_TO_DEG 57.2957786
49
+
50
+#define SERIAL  0x0
51
+#define DISPLAY 0x1
52
+
53
+#define LSBFIRST 0
54
+#define MSBFIRST 1
55
+
56
+#define CHANGE 1
57
+#define FALLING 2
58
+#define RISING 3
59
+
60
+#define INTERNAL 3
61
+#define DEFAULT 1
62
+#define EXTERNAL 0
63
+
64
+// undefine stdlib's abs if encountered
65
+#ifdef abs
66
+#undef abs
67
+#endif
68
+
69
+#define min(a,b) ((a)<(b)?(a):(b))
70
+#define max(a,b) ((a)>(b)?(a):(b))
71
+#define abs(x) ((x)>0?(x):-(x))
72
+#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
73
+#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
74
+#define radians(deg) ((deg)*DEG_TO_RAD)
75
+#define degrees(rad) ((rad)*RAD_TO_DEG)
76
+#define sq(x) ((x)*(x))
77
+
78
+#define interrupts() sei()
79
+#define noInterrupts() cli()
80
+
81
+#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
82
+#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
83
+#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
84
+
85
+#define lowByte(w) ((w) & 0xff)
86
+#define highByte(w) ((w) >> 8)
87
+
88
+#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
89
+#define bitSet(value, bit) ((value) |= (1UL << (bit)))
90
+#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
91
+#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
92
+
93
+typedef unsigned int word;
94
+
95
+#define bit(b) (1 << (b))
96
+
97
+typedef uint8_t boolean;
98
+typedef uint8_t byte;
99
+
100
+void init(void);
101
+
102
+void pinMode(uint8_t, uint8_t);
103
+void digitalWrite(uint8_t, uint8_t);
104
+int digitalRead(uint8_t);
105
+int analogRead(uint8_t);
106
+void analogReference(uint8_t mode);
107
+void analogWrite(uint8_t, int);
108
+
109
+void beginSerial(uint8_t, long);
110
+void serialWrite(uint8_t, unsigned char);
111
+int serialAvailable(uint8_t);
112
+int serialRead(uint8_t);
113
+void serialFlush(uint8_t);
114
+
115
+unsigned long millis(void);
116
+unsigned long micros(void);
117
+void delay(unsigned long);
118
+void delayMicroseconds(unsigned int us);
119
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
120
+
121
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);
122
+
123
+void attachInterrupt(uint8_t, void (*)(void), int mode);
124
+void detachInterrupt(uint8_t);
125
+
126
+void setup(void);
127
+void loop(void);
128
+
129
+#ifdef __cplusplus
130
+} // extern "C"
131
+#endif
132
+
133
+#endif

+ 116
- 0
Marlin/Marlin/Gen7/cores/arduino/wiring_analog.c Переглянути файл

1
+/*
2
+  wiring_analog.c - analog input and output
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
23
+*/
24
+
25
+#include "wiring_private.h"
26
+#include "pins_arduino.h"
27
+
28
+uint8_t analog_reference = DEFAULT;
29
+
30
+void analogReference(uint8_t mode)
31
+{
32
+	// can't actually set the register here because the default setting
33
+	// will connect AVCC and the AREF pin, which would cause a short if
34
+	// there's something connected to AREF.
35
+	analog_reference = mode;
36
+}
37
+
38
+int analogRead(uint8_t pin)
39
+{
40
+	uint8_t low, high, ch = analogInPinToBit(pin);
41
+
42
+	// set the analog reference (high two bits of ADMUX) and select the
43
+	// channel (low 4 bits).  this also sets ADLAR (left-adjust result)
44
+	// to 0 (the default).
45
+	// the final AND is to clear the pos/neg reference bits
46
+	ADMUX = ((analog_reference << 6) | (pin & 0x0f)) & B11000111;
47
+
48
+	// without a delay, we seem to read from the wrong channel
49
+	//delay(1);
50
+
51
+	// start the conversion
52
+	sbi(ADCSRA, ADSC);
53
+
54
+	// ADSC is cleared when the conversion finishes
55
+	while (bit_is_set(ADCSRA, ADSC));
56
+
57
+	// we have to read ADCL first; doing so locks both ADCL
58
+	// and ADCH until ADCH is read.  reading ADCL second would
59
+	// cause the results of each conversion to be discarded,
60
+	// as ADCL and ADCH would be locked when it completed.
61
+	low = ADCL;
62
+	high = ADCH;
63
+
64
+	// combine the two bytes
65
+	return (high << 8) | low;
66
+}
67
+
68
+// Right now, PWM output only works on the pins with
69
+// hardware support.  These are defined in the appropriate
70
+// pins_*.c file.  For the rest of the pins, we default
71
+// to digital output.
72
+void analogWrite(uint8_t pin, int val)
73
+{
74
+	// We need to make sure the PWM output is enabled for those pins
75
+	// that support it, as we turn it off when digitally reading or
76
+	// writing with them.  Also, make sure the pin is in output mode
77
+	// for consistenty with Wiring, which doesn't require a pinMode
78
+	// call for the analog output pins.
79
+	pinMode(pin, OUTPUT);
80
+	
81
+	if (digitalPinToTimer(pin) == TIMER1A) {
82
+		// connect pwm to pin on timer 1, channel A
83
+		sbi(TCCR1A, COM1A1);
84
+		// set pwm duty
85
+		OCR1A = val;
86
+	} else if (digitalPinToTimer(pin) == TIMER1B) {
87
+		// connect pwm to pin on timer 1, channel B
88
+		sbi(TCCR1A, COM1B1);
89
+		// set pwm duty
90
+		OCR1B = val;
91
+	} else if (digitalPinToTimer(pin) == TIMER0A) {
92
+		// connect pwm to pin on timer 0, channel A
93
+		sbi(TCCR0A, COM0A1);
94
+		// set pwm duty
95
+		OCR0A = val;	
96
+	} else if (digitalPinToTimer(pin) == TIMER0B) {
97
+		// connect pwm to pin on timer 0, channel B
98
+		sbi(TCCR0A, COM0B1);
99
+		// set pwm duty
100
+		OCR0B = val;
101
+	} else if (digitalPinToTimer(pin) == TIMER2A) {
102
+		// connect pwm to pin on timer 2, channel A
103
+		sbi(TCCR2A, COM2A1);
104
+		// set pwm duty
105
+		OCR2A = val;	
106
+	} else if (digitalPinToTimer(pin) == TIMER2B) {
107
+		// connect pwm to pin on timer 2, channel B
108
+		sbi(TCCR2A, COM2B1);
109
+		// set pwm duty
110
+		OCR2B = val;
111
+	} else if (val < 128)
112
+	//fail semi-intelligently
113
+		digitalWrite(pin, LOW);
114
+	else
115
+		digitalWrite(pin, HIGH);
116
+}

+ 95
- 0
Marlin/Marlin/Gen7/cores/arduino/wiring_digital.c Переглянути файл

1
+/*
2
+  wiring_digital.c - digital input and output functions
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
23
+*/
24
+
25
+#include "wiring_private.h"
26
+#include "pins_arduino.h"
27
+
28
+void pinMode(uint8_t pin, uint8_t mode)
29
+{
30
+	uint8_t bit = digitalPinToBitMask(pin);
31
+	uint8_t port = digitalPinToPort(pin);
32
+	volatile uint8_t *reg;
33
+
34
+	if (port == NOT_A_PIN) return;
35
+
36
+	// JWS: can I let the optimizer do this?
37
+	reg = portModeRegister(port);
38
+
39
+	if (mode == INPUT) *reg &= ~bit;
40
+	else *reg |= bit;
41
+}
42
+
43
+// Forcing this inline keeps the callers from having to push their own stuff
44
+// on the stack. It is a good performance win and only takes 1 more byte per
45
+// user than calling. (It will take more bytes on the 168.)
46
+//
47
+// But shouldn't this be moved into pinMode? Seems silly to check and do on
48
+// each digitalread or write.
49
+//
50
+static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
51
+static inline void turnOffPWM(uint8_t timer)
52
+{
53
+	if (timer == TIMER0A) cbi(TCCR0A, COM0A1);
54
+	if (timer == TIMER0B) cbi(TCCR0A, COM0B1);
55
+	if (timer == TIMER1A) cbi(TCCR1A, COM1A1);
56
+	if (timer == TIMER1B) cbi(TCCR1A, COM1B1);
57
+	if (timer == TIMER2A) cbi(TCCR2A, COM2A1);
58
+	if (timer == TIMER2B) cbi(TCCR2A, COM2B1);
59
+}
60
+
61
+void digitalWrite(uint8_t pin, uint8_t val)
62
+{
63
+	uint8_t timer = digitalPinToTimer(pin);
64
+	uint8_t bit = digitalPinToBitMask(pin);
65
+	uint8_t port = digitalPinToPort(pin);
66
+	volatile uint8_t *out;
67
+
68
+	if (port == NOT_A_PIN) return;
69
+
70
+	// If the pin that support PWM output, we need to turn it off
71
+	// before doing a digital write.
72
+	if (timer != NOT_ON_TIMER) turnOffPWM(timer);
73
+
74
+	out = portOutputRegister(port);
75
+
76
+	if (val == LOW) *out &= ~bit;
77
+	else *out |= bit;
78
+}
79
+
80
+int digitalRead(uint8_t pin)
81
+{
82
+	uint8_t timer = digitalPinToTimer(pin);
83
+	uint8_t bit = digitalPinToBitMask(pin);
84
+	uint8_t port = digitalPinToPort(pin);
85
+
86
+	if (port == NOT_A_PIN) return LOW;
87
+
88
+	// If the pin that support PWM output, we need to turn it off
89
+	// before getting a digital reading.
90
+	if (timer != NOT_ON_TIMER) turnOffPWM(timer);
91
+
92
+	if (*portInputRegister(port) & bit) return HIGH;
93
+	
94
+	return LOW;
95
+}

+ 60
- 0
Marlin/Marlin/Gen7/cores/arduino/wiring_private.h Переглянути файл

1
+/*
2
+  wiring_private.h - Internal header file.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
23
+*/
24
+
25
+#ifndef WiringPrivate_h
26
+#define WiringPrivate_h
27
+
28
+#include <avr/io.h>
29
+#include <avr/interrupt.h>
30
+#include <avr/signal.h>
31
+#include <avr/delay.h>
32
+#include <stdio.h>
33
+#include <stdarg.h>
34
+
35
+#include "wiring.h"
36
+
37
+#ifdef __cplusplus
38
+extern "C"{
39
+#endif
40
+
41
+#ifndef cbi
42
+#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
43
+#endif
44
+#ifndef sbi
45
+#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
46
+#endif
47
+
48
+#define EXTERNAL_INT_0 0
49
+#define EXTERNAL_INT_1 1
50
+#define EXTERNAL_INT_2 2
51
+
52
+#define EXTERNAL_NUM_INTERRUPTS 3
53
+
54
+typedef void (*voidFuncPtr)(void);
55
+
56
+#ifdef __cplusplus
57
+} // extern "C"
58
+#endif
59
+
60
+#endif

+ 66
- 0
Marlin/Marlin/Gen7/cores/arduino/wiring_pulse.c Переглянути файл

1
+/*
2
+  wiring_pulse.c - pulseIn() function
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
23
+*/
24
+
25
+#include "wiring_private.h"
26
+#include "pins_arduino.h"
27
+
28
+/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
29
+ * or LOW, the type of pulse to measure.  Works on pulses from 2-3 microseconds
30
+ * to 3 minutes in length, but must be called at least a few dozen microseconds
31
+ * before the start of the pulse. */
32
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
33
+{
34
+	// cache the port and bit of the pin in order to speed up the
35
+	// pulse width measuring loop and achieve finer resolution.  calling
36
+	// digitalRead() instead yields much coarser resolution.
37
+	uint8_t bit = digitalPinToBitMask(pin);
38
+	uint8_t port = digitalPinToPort(pin);
39
+	uint8_t stateMask = (state ? bit : 0);
40
+	unsigned long width = 0; // keep initialization out of time critical area
41
+	
42
+	// convert the timeout from microseconds to a number of times through
43
+	// the initial loop; it takes 16 clock cycles per iteration.
44
+	unsigned long numloops = 0;
45
+	unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
46
+	
47
+	// wait for any previous pulse to end
48
+	while ((*portInputRegister(port) & bit) == stateMask)
49
+		if (numloops++ == maxloops)
50
+			return 0;
51
+	
52
+	// wait for the pulse to start
53
+	while ((*portInputRegister(port) & bit) != stateMask)
54
+		if (numloops++ == maxloops)
55
+			return 0;
56
+	
57
+	// wait for the pulse to stop
58
+	while ((*portInputRegister(port) & bit) == stateMask)
59
+		width++;
60
+
61
+	// convert the reading to microseconds. The loop has been determined
62
+	// to be 10 clock cycles long and have about 16 clocks between the edge
63
+	// and the start of the loop. There will be some error introduced by
64
+	// the interrupt handlers.
65
+	return clockCyclesToMicroseconds(width * 10 + 16); 
66
+}

+ 138
- 0
Marlin/Marlin/Gen7/cores/arduino/wiring_serial.c Переглянути файл

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

+ 40
- 0
Marlin/Marlin/Gen7/cores/arduino/wiring_shift.c Переглянути файл

1
+/*
2
+  wiring_shift.c - shiftOut() function
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
23
+*/
24
+
25
+#include "wiring_private.h"
26
+
27
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val)
28
+{
29
+	int i;
30
+
31
+	for (i = 0; i < 8; i++)  {
32
+		if (bitOrder == LSBFIRST)
33
+			digitalWrite(dataPin, !!(val & (1 << i)));
34
+		else	
35
+			digitalWrite(dataPin, !!(val & (1 << (7 - i))));
36
+			
37
+		digitalWrite(clockPin, HIGH);
38
+		digitalWrite(clockPin, LOW);		
39
+	}
40
+}

BIN
Marlin/Marlin/LCD Menu Tree.pdf Переглянути файл


+ 298
- 0
Marlin/Marlin/Makefile Переглянути файл

1
+# Sprinter Arduino Project Makefile
2
+# 
3
+# Makefile Based on:
4
+# Arduino 0011 Makefile
5
+# Arduino adaptation by mellis, eighthave, oli.keller
6
+#
7
+# This has been tested with Arduino 0022.
8
+# 
9
+# This makefile allows you to build sketches from the command line
10
+# without the Arduino environment (or Java).
11
+#
12
+# Detailed instructions for using the makefile:
13
+#
14
+#  1. Modify the line containg "INSTALL_DIR" to point to the directory that
15
+#     contains the Arduino installation (for example, under Mac OS X, this
16
+#     might be /Applications/arduino-0012).
17
+#
18
+#  2. Modify the line containing "PORT" to refer to the filename
19
+#     representing the USB or serial connection to your Arduino board
20
+#     (e.g. PORT = /dev/tty.USB0).  If the exact name of this file
21
+#     changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*).
22
+#
23
+#  3. Set the line containing "MCU" to match your board's processor. 
24
+#     Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth
25
+#     or Diecimila have the atmega168.  If you're using a LilyPad Arduino,
26
+#     change F_CPU to 8000000. If you are using Gen7 electronics, you
27
+#     probably need to use 20000000. Either way, you must regenerate
28
+#     the speed lookup table with create_speed_lookuptable.py.
29
+#
30
+#  4. Type "make" and press enter to compile/verify your program.
31
+#
32
+#  5. Type "make upload", reset your Arduino board, and press enter to
33
+#     upload your program to the Arduino board.
34
+#
35
+# $Id$
36
+
37
+#For "old" Arduino Mega
38
+#MCU = atmega1280
39
+#For Arduino Mega2560
40
+#MCU = atmega2560
41
+#For Sanguinololu
42
+MCU = atmega644p 
43
+
44
+# Here you select "arduino", "Sanguino", "Gen7", ...
45
+HARDWARE_VARIANT 		= Sanguino
46
+# This defined the board you are compiling for
47
+HARDWARE_MOTHERBOARD	= 91
48
+
49
+# Arduino source install directory
50
+INSTALL_DIR = ../../arduino-0022
51
+
52
+# Arduino containd the main source code for the Arduino
53
+# Libraries, the "hardware variant" are for boards
54
+# that derives from that, and their source are present in
55
+# the main Marlin source directory
56
+ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
57
+
58
+ifeq (${HARDWARE_VARIANT}, arduino)
59
+HARDWARE_SRC= $(ARDUINO)
60
+else
61
+HARDWARE_SRC= $(HARDWARE_VARIANT)/cores/arduino
62
+endif
63
+
64
+# Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py
65
+# if you are setting this to something other than 16MHz
66
+F_CPU = 16000000
67
+
68
+UPLOAD_RATE = 115200
69
+AVRDUDE_PROGRAMMER = arduino
70
+PORT = /dev/arduino
71
+
72
+TARGET = $(notdir $(CURDIR))
73
+
74
+# VPATH tells make to look into these directory for source files,
75
+# there is no need to specify explicit pathnames as long as the
76
+# directory is added here
77
+
78
+VPATH = .
79
+VPATH += applet
80
+VPATH += $(HARDWARE_SRC)
81
+VPATH += $(ARDUINO)
82
+VPATH += $(INSTALL_DIR)/libraries/LiquidCrystal
83
+
84
+############################################################################
85
+# Below here nothing should be changed...
86
+
87
+AVR_TOOLS_PATH = 
88
+SRC =  pins_arduino.c wiring.c \
89
+	wiring_analog.c wiring_digital.c \
90
+	wiring_pulse.c \
91
+	wiring_shift.c WInterrupts.c
92
+CXXSRC = WMath.cpp WString.cpp Print.cpp \
93
+	Marlin.cpp MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp \
94
+	SdFatUtil.cpp SdFile.cpp SdVolume.cpp motion_control.cpp \
95
+	planner.cpp stepper.cpp temperature.cpp cardreader.cpp
96
+#CXXSRC += LiquidCrystal.cpp ultralcd.cpp
97
+#CXXSRC += ultralcd.cpp
98
+FORMAT = ihex
99
+
100
+# Name of this Makefile (used for "make depend").
101
+MAKEFILE = Makefile
102
+
103
+# Debugging format.
104
+# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
105
+# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
106
+DEBUG = stabs
107
+
108
+OPT = s
109
+
110
+# Place -D or -U options here
111
+CDEFS = -DF_CPU=$(F_CPU)
112
+CXXDEFS = -DF_CPU=$(F_CPU)
113
+
114
+# Add all the source directories as include directories too
115
+CINCS = ${addprefix -I ,${VPATH}}
116
+CXXINCS = ${addprefix -I ,${VPATH}}
117
+
118
+# Compiler flag to set the C Standard level.
119
+# c89   - "ANSI" C
120
+# gnu89 - c89 plus GCC extensions
121
+# c99   - ISO C99 standard (not yet fully implemented)
122
+# gnu99 - c99 plus GCC extensions
123
+#CSTANDARD = -std=gnu99
124
+CDEBUG = -g$(DEBUG)
125
+CWARN = -Wall -Wstrict-prototypes
126
+CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct \
127
+	-fshort-enums -w -ffunction-sections -fdata-sections \
128
+	-DARDUINO=22
129
+ifneq (${HARDWARE_MOTHERBOARD},)
130
+CTUNING += -DMOTHERBOARD=${HARDWARE_MOTHERBOARD}
131
+endif
132
+#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
133
+
134
+CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
135
+CXXFLAGS =         $(CDEFS) $(CINCS) -O$(OPT) -Wall    $(CEXTRA) $(CTUNING)
136
+#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
137
+LDFLAGS = -lm
138
+
139
+
140
+# Programming support using avrdude. Settings and variables.
141
+AVRDUDE_PORT = $(PORT)
142
+AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i
143
+AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
144
+	-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
145
+	-b $(UPLOAD_RATE)
146
+
147
+# Program settings
148
+CC = $(AVR_TOOLS_PATH)avr-gcc
149
+CXX = $(AVR_TOOLS_PATH)avr-g++
150
+OBJCOPY = $(AVR_TOOLS_PATH)avr-objcopy
151
+OBJDUMP = $(AVR_TOOLS_PATH)avr-objdump
152
+AR  = $(AVR_TOOLS_PATH)avr-ar
153
+SIZE = $(AVR_TOOLS_PATH)avr-size
154
+NM = $(AVR_TOOLS_PATH)avr-nm
155
+AVRDUDE = avrdude
156
+REMOVE = rm -f
157
+MV = mv -f
158
+
159
+# Define all object files.
160
+OBJ = ${patsubst %.c, applet/%.o, ${SRC}}
161
+OBJ += ${patsubst %.cpp, applet/%.o, ${CXXSRC}}
162
+OBJ += ${patsubst %.S, applet/%.o, ${ASRC}}
163
+
164
+# Define all listing files.
165
+LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
166
+
167
+# Combine all necessary flags and optional flags.
168
+# Add target processor to flags.
169
+ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
170
+ALL_CXXFLAGS = -mmcu=$(MCU) $(CXXFLAGS)
171
+ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS)
172
+
173
+# set V=1 (eg, "make V=1") to print the full commands etc.
174
+ifneq ($V,1)
175
+ Pecho=@echo
176
+ P=@
177
+else
178
+ Pecho=@:
179
+ P=
180
+endif
181
+
182
+# Default target.
183
+all: sizeafter
184
+
185
+build: applet elf hex 
186
+
187
+# Creates the object directory
188
+applet: 
189
+	$P mkdir -p applet
190
+
191
+# the .cpp for Marlin depends on the .pde
192
+#applet/$(TARGET).cpp: $(TARGET).pde
193
+# ..and the .o depends from the .cpp
194
+#applet/%.o: applet/%.cpp
195
+
196
+applet/%.cpp: %.pde $(MAKEFILE)
197
+# Here is the "preprocessing".
198
+# It creates a .cpp file based with the same name as the .pde file.
199
+# On top of the new .cpp file comes the WProgram.h header.
200
+	$(Pecho) "  WR    $@"
201
+	$P echo '#include "WProgram.h"' > $@
202
+	$P echo '#include "$<"' >>$@
203
+	$P echo '#include "$(ARDUINO)/main.cpp"' >> $@
204
+
205
+elf: applet/$(TARGET).elf
206
+hex: applet/$(TARGET).hex
207
+eep: applet/$(TARGET).eep
208
+lss: applet/$(TARGET).lss 
209
+sym: applet/$(TARGET).sym
210
+
211
+# Program the device.  
212
+# Do not try to reset an arduino if it's not one
213
+upload: applet/$(TARGET).hex
214
+ifeq (${AVRDUDE_PROGRAMMER}, arduino)
215
+	stty hup < $(PORT); true
216
+endif
217
+	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
218
+ifeq (${AVRDUDE_PROGRAMMER}, arduino)
219
+	stty -hup < $(PORT); true
220
+endif
221
+
222
+	# Display size of file.
223
+HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
224
+ELFSIZE = $(SIZE) --mcu=$(MCU) -C applet/$(TARGET).elf; \
225
+          $(SIZE)  applet/$(TARGET).elf
226
+sizebefore:
227
+	$P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
228
+
229
+sizeafter: build
230
+	$P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
231
+
232
+
233
+# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
234
+COFFCONVERT=$(OBJCOPY) --debugging \
235
+	--change-section-address .data-0x800000 \
236
+	--change-section-address .bss-0x800000 \
237
+	--change-section-address .noinit-0x800000 \
238
+	--change-section-address .eeprom-0x810000 
239
+
240
+
241
+coff: applet/$(TARGET).elf
242
+	$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
243
+
244
+
245
+extcoff: $(TARGET).elf
246
+	$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
247
+
248
+
249
+.SUFFIXES: .elf .hex .eep .lss .sym
250
+.PRECIOUS: .o
251
+
252
+.elf.hex:
253
+	$(Pecho) "  COPY  $@"
254
+	$P $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
255
+
256
+.elf.eep:
257
+	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
258
+		--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
259
+
260
+# Create extended listing file from ELF output file.
261
+.elf.lss:
262
+	$(OBJDUMP) -h -S $< > $@
263
+
264
+# Create a symbol table from ELF output file.
265
+.elf.sym:
266
+	$(NM) -n $< > $@
267
+
268
+	# Link: create ELF output file from library.
269
+applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a Configuration.h
270
+	$(Pecho) "  CXX   $@"
271
+	$P $(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
272
+
273
+applet/core.a: $(OBJ)
274
+	$P for i in $(OBJ); do echo "  AR    $$i"; $(AR) rcs applet/core.a $$i; done
275
+
276
+applet/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE)
277
+	$(Pecho) "  CC    $@"
278
+	$P $(CC) -MMD -c $(ALL_CFLAGS) $< -o $@
279
+
280
+applet/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
281
+	$(Pecho) "  CXX   $@"
282
+	$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
283
+
284
+
285
+# Target: clean project.
286
+clean:
287
+	$(Pecho) "  RM    applet/*"
288
+	$P $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
289
+		applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \
290
+		$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
291
+	$(Pecho) "  RMDIR applet/"
292
+	$P rm -rf applet
293
+
294
+
295
+.PHONY:	all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter
296
+
297
+# Automaticaly include the dependency files created by gcc
298
+-include ${wildcard applet/*.d}

+ 203
- 0
Marlin/Marlin/Marlin.h Переглянути файл

1
+// Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
2
+// Licence: GPL
3
+
4
+#ifndef MARLIN_H
5
+#define MARLIN_H
6
+
7
+#define  HardwareSerial_h // trick to disable the standard HWserial
8
+
9
+#define  FORCE_INLINE __attribute__((always_inline)) inline
10
+
11
+#include <math.h>
12
+#include <stdio.h>
13
+#include <stdlib.h>
14
+#include <string.h>
15
+#include <inttypes.h>
16
+
17
+#include <util/delay.h>
18
+#include <avr/pgmspace.h>
19
+#include <avr/eeprom.h>
20
+#include  <avr/wdt.h>
21
+#include  <avr/interrupt.h>
22
+
23
+
24
+#include "fastio.h"
25
+#include "Configuration.h"
26
+#include "pins.h"
27
+
28
+#if ARDUINO >= 100 
29
+  #if defined(__AVR_ATmega644P__)
30
+    #include "WProgram.h"
31
+  #else
32
+    #include "Arduino.h"
33
+  #endif
34
+#else
35
+   #include "WProgram.h"
36
+#endif
37
+
38
+#include "MarlinSerial.h"
39
+
40
+#ifndef cbi
41
+#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
42
+#endif
43
+#ifndef sbi
44
+#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
45
+#endif
46
+
47
+#include "WString.h"
48
+
49
+#if MOTHERBOARD == 8  // Teensylu
50
+  #define MYSERIAL Serial
51
+#else
52
+  #define MYSERIAL MSerial
53
+#endif
54
+
55
+//this is a unfinsihed attemp to removes a lot of warning messages, see:
56
+// http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=57011
57
+//typedef char prog_char PROGMEM; 
58
+// //#define PSTR    (s )        ((const PROGMEM char *)(s))
59
+// //# define MYPGM(s) (__extension__({static prog_char __c[] = (s); &__c[0];})) 
60
+// //#define MYPGM(s) ((const prog_char *g PROGMEM=s))
61
+#define MYPGM(s) PSTR(s)
62
+//#define MYPGM(s)  (__extension__({static char __c[] __attribute__((__progmem__)) = (s); &__c[0];}))  //This is the normal behaviour
63
+//#define MYPGM(s)  (__extension__({static prog_char __c[]  = (s); &__c[0];})) //this does not work but hides the warnings
64
+
65
+
66
+#define SERIAL_PROTOCOL(x) MYSERIAL.print(x);
67
+#define SERIAL_PROTOCOL_F(x,y) MYSERIAL.print(x,y);
68
+#define SERIAL_PROTOCOLPGM(x) serialprintPGM(MYPGM(x));
69
+#define SERIAL_PROTOCOLLN(x) {MYSERIAL.print(x);MYSERIAL.write('\n');}
70
+#define SERIAL_PROTOCOLLNPGM(x) {serialprintPGM(MYPGM(x));MYSERIAL.write('\n');}
71
+
72
+
73
+const char errormagic[] PROGMEM ="Error:";
74
+const char echomagic[] PROGMEM ="echo:";
75
+#define SERIAL_ERROR_START serialprintPGM(errormagic);
76
+#define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
77
+#define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
78
+#define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
79
+#define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
80
+
81
+#define SERIAL_ECHO_START serialprintPGM(echomagic);
82
+#define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
83
+#define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
84
+#define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
85
+#define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
86
+
87
+#define SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value)))
88
+
89
+void serial_echopair_P(const char *s_P, float v);
90
+void serial_echopair_P(const char *s_P, double v);
91
+void serial_echopair_P(const char *s_P, unsigned long v);
92
+
93
+
94
+//things to write to serial from Programmemory. saves 400 to 2k of RAM.
95
+#define SerialprintPGM(x) serialprintPGM(MYPGM(x))
96
+FORCE_INLINE void serialprintPGM(const char *str)
97
+{
98
+  char ch=pgm_read_byte(str);
99
+  while(ch)
100
+  {
101
+    MYSERIAL.write(ch);
102
+    ch=pgm_read_byte(++str);
103
+  }
104
+}
105
+
106
+
107
+void get_command();
108
+void process_commands();
109
+
110
+void manage_inactivity();
111
+
112
+#if X_ENABLE_PIN > -1
113
+  #define  enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
114
+  #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)
115
+#else
116
+  #define enable_x() ;
117
+  #define disable_x() ;
118
+#endif
119
+
120
+#if Y_ENABLE_PIN > -1
121
+  #define  enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
122
+  #define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON)
123
+#else
124
+  #define enable_y() ;
125
+  #define disable_y() ;
126
+#endif
127
+
128
+#if Z_ENABLE_PIN > -1
129
+  #ifdef Z_DUAL_STEPPER_DRIVERS
130
+    #define  enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
131
+    #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); }
132
+  #else
133
+    #define  enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
134
+    #define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON)
135
+  #endif
136
+#else
137
+  #define enable_z() ;
138
+  #define disable_z() ;
139
+#endif
140
+
141
+#if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
142
+  #define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON)
143
+  #define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON)
144
+#else
145
+  #define enable_e0()  /* nothing */
146
+  #define disable_e0() /* nothing */
147
+#endif
148
+
149
+#if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
150
+  #define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON)
151
+  #define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON)
152
+#else
153
+  #define enable_e1()  /* nothing */
154
+  #define disable_e1() /* nothing */
155
+#endif
156
+
157
+#if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
158
+  #define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON)
159
+  #define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON)
160
+#else
161
+  #define enable_e2()  /* nothing */
162
+  #define disable_e2() /* nothing */
163
+#endif
164
+
165
+
166
+enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3};
167
+
168
+
169
+void FlushSerialRequestResend();
170
+void ClearToSend();
171
+
172
+void get_coordinates();
173
+void prepare_move();
174
+void kill();
175
+void Stop();
176
+
177
+bool IsStopped();
178
+
179
+void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer.
180
+void prepare_arc_move(char isclockwise);
181
+void clamp_to_software_endstops(float target[3]);
182
+
183
+#ifdef FAST_PWM_FAN
184
+void setPwmFrequency(uint8_t pin, int val);
185
+#endif
186
+
187
+#ifndef CRITICAL_SECTION_START
188
+  #define CRITICAL_SECTION_START  unsigned char _sreg = SREG; cli();
189
+  #define CRITICAL_SECTION_END    SREG = _sreg;
190
+#endif //CRITICAL_SECTION_START
191
+
192
+extern float homing_feedrate[];
193
+extern bool axis_relative_modes[];
194
+extern float current_position[NUM_AXIS] ;
195
+extern float add_homeing[3];
196
+extern float min_pos[3];
197
+extern float max_pos[3];
198
+extern unsigned char FanSpeed;
199
+
200
+// Handling multiple extruders pins
201
+extern uint8_t active_extruder;
202
+
203
+#endif

+ 1832
- 0
Marlin/Marlin/Marlin.pde
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 329
- 0
Marlin/Marlin/MarlinSerial.cpp Переглянути файл

1
+/*
2
+  HardwareSerial.cpp - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right 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
+  Modified 23 November 2006 by David A. Mellis
20
+  Modified 28 September 2010 by Mark Sproul
21
+*/
22
+
23
+#include "Marlin.h"
24
+#include "MarlinSerial.h"
25
+
26
+#if MOTHERBOARD != 8 // !teensylu
27
+// this next line disables the entire HardwareSerial.cpp, 
28
+// this is so I can support Attiny series and any other chip without a uart
29
+#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
30
+
31
+#if defined(UBRRH) || defined(UBRR0H)
32
+  ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
33
+#endif
34
+
35
+FORCE_INLINE void store_char(unsigned char c)
36
+{
37
+  int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
38
+
39
+  // if we should be storing the received character into the location
40
+  // just before the tail (meaning that the head would advance to the
41
+  // current location of the tail), we're about to overflow the buffer
42
+  // and so we don't write the character or advance the head.
43
+  if (i != rx_buffer.tail) {
44
+    rx_buffer.buffer[rx_buffer.head] = c;
45
+    rx_buffer.head = i;
46
+  }
47
+}
48
+
49
+
50
+//#elif defined(SIG_USART_RECV)
51
+#if defined(USART0_RX_vect)
52
+  // fixed by Mark Sproul this is on the 644/644p
53
+  //SIGNAL(SIG_USART_RECV)
54
+  SIGNAL(USART0_RX_vect)
55
+  {
56
+  #if defined(UDR0)
57
+    unsigned char c  =  UDR0;
58
+  #elif defined(UDR)
59
+    unsigned char c  =  UDR;  //  atmega8, atmega32
60
+  #else
61
+    #error UDR not defined
62
+  #endif
63
+    store_char(c);
64
+  }
65
+#endif
66
+
67
+// Constructors ////////////////////////////////////////////////////////////////
68
+
69
+MarlinSerial::MarlinSerial()
70
+{
71
+
72
+}
73
+
74
+// Public Methods //////////////////////////////////////////////////////////////
75
+
76
+void MarlinSerial::begin(long baud)
77
+{
78
+  uint16_t baud_setting;
79
+  bool useU2X0 = true;
80
+
81
+#if F_CPU == 16000000UL
82
+  // hardcoded exception for compatibility with the bootloader shipped
83
+  // with the Duemilanove and previous boards and the firmware on the 8U2
84
+  // on the Uno and Mega 2560.
85
+  if (baud == 57600) {
86
+    useU2X0 = false;
87
+  }
88
+#endif
89
+  
90
+  if (useU2X0) {
91
+    UCSR0A = 1 << U2X0;
92
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
93
+  } else {
94
+    UCSR0A = 0;
95
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
96
+  }
97
+
98
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
99
+  UBRR0H = baud_setting >> 8;
100
+  UBRR0L = baud_setting;
101
+
102
+  sbi(UCSR0B, RXEN0);
103
+  sbi(UCSR0B, TXEN0);
104
+  sbi(UCSR0B, RXCIE0);
105
+}
106
+
107
+void MarlinSerial::end()
108
+{
109
+  cbi(UCSR0B, RXEN0);
110
+  cbi(UCSR0B, TXEN0);
111
+  cbi(UCSR0B, RXCIE0);  
112
+}
113
+
114
+
115
+
116
+int MarlinSerial::peek(void)
117
+{
118
+  if (rx_buffer.head == rx_buffer.tail) {
119
+    return -1;
120
+  } else {
121
+    return rx_buffer.buffer[rx_buffer.tail];
122
+  }
123
+}
124
+
125
+int MarlinSerial::read(void)
126
+{
127
+  // if the head isn't ahead of the tail, we don't have any characters
128
+  if (rx_buffer.head == rx_buffer.tail) {
129
+    return -1;
130
+  } else {
131
+    unsigned char c = rx_buffer.buffer[rx_buffer.tail];
132
+    rx_buffer.tail = (unsigned int)(rx_buffer.tail + 1) % RX_BUFFER_SIZE;
133
+    return c;
134
+  }
135
+}
136
+
137
+void MarlinSerial::flush()
138
+{
139
+  // don't reverse this or there may be problems if the RX interrupt
140
+  // occurs after reading the value of rx_buffer_head but before writing
141
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
142
+  // may be written to rx_buffer_tail, making it appear as if the buffer
143
+  // don't reverse this or there may be problems if the RX interrupt
144
+  // occurs after reading the value of rx_buffer_head but before writing
145
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
146
+  // may be written to rx_buffer_tail, making it appear as if the buffer
147
+  // were full, not empty.
148
+  rx_buffer.head = rx_buffer.tail;
149
+}
150
+
151
+
152
+
153
+
154
+/// imports from print.h
155
+
156
+
157
+
158
+
159
+void MarlinSerial::print(char c, int base)
160
+{
161
+  print((long) c, base);
162
+}
163
+
164
+void MarlinSerial::print(unsigned char b, int base)
165
+{
166
+  print((unsigned long) b, base);
167
+}
168
+
169
+void MarlinSerial::print(int n, int base)
170
+{
171
+  print((long) n, base);
172
+}
173
+
174
+void MarlinSerial::print(unsigned int n, int base)
175
+{
176
+  print((unsigned long) n, base);
177
+}
178
+
179
+void MarlinSerial::print(long n, int base)
180
+{
181
+  if (base == 0) {
182
+    write(n);
183
+  } else if (base == 10) {
184
+    if (n < 0) {
185
+      print('-');
186
+      n = -n;
187
+    }
188
+    printNumber(n, 10);
189
+  } else {
190
+    printNumber(n, base);
191
+  }
192
+}
193
+
194
+void MarlinSerial::print(unsigned long n, int base)
195
+{
196
+  if (base == 0) write(n);
197
+  else printNumber(n, base);
198
+}
199
+
200
+void MarlinSerial::print(double n, int digits)
201
+{
202
+  printFloat(n, digits);
203
+}
204
+
205
+void MarlinSerial::println(void)
206
+{
207
+  print('\r');
208
+  print('\n');  
209
+}
210
+
211
+void MarlinSerial::println(const String &s)
212
+{
213
+  print(s);
214
+  println();
215
+}
216
+
217
+void MarlinSerial::println(const char c[])
218
+{
219
+  print(c);
220
+  println();
221
+}
222
+
223
+void MarlinSerial::println(char c, int base)
224
+{
225
+  print(c, base);
226
+  println();
227
+}
228
+
229
+void MarlinSerial::println(unsigned char b, int base)
230
+{
231
+  print(b, base);
232
+  println();
233
+}
234
+
235
+void MarlinSerial::println(int n, int base)
236
+{
237
+  print(n, base);
238
+  println();
239
+}
240
+
241
+void MarlinSerial::println(unsigned int n, int base)
242
+{
243
+  print(n, base);
244
+  println();
245
+}
246
+
247
+void MarlinSerial::println(long n, int base)
248
+{
249
+  print(n, base);
250
+  println();
251
+}
252
+
253
+void MarlinSerial::println(unsigned long n, int base)
254
+{
255
+  print(n, base);
256
+  println();
257
+}
258
+
259
+void MarlinSerial::println(double n, int digits)
260
+{
261
+  print(n, digits);
262
+  println();
263
+}
264
+
265
+// Private Methods /////////////////////////////////////////////////////////////
266
+
267
+void MarlinSerial::printNumber(unsigned long n, uint8_t base)
268
+{
269
+  unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
270
+  unsigned long i = 0;
271
+
272
+  if (n == 0) {
273
+    print('0');
274
+    return;
275
+  } 
276
+
277
+  while (n > 0) {
278
+    buf[i++] = n % base;
279
+    n /= base;
280
+  }
281
+
282
+  for (; i > 0; i--)
283
+    print((char) (buf[i - 1] < 10 ?
284
+      '0' + buf[i - 1] :
285
+      'A' + buf[i - 1] - 10));
286
+}
287
+
288
+void MarlinSerial::printFloat(double number, uint8_t digits) 
289
+{ 
290
+  // Handle negative numbers
291
+  if (number < 0.0)
292
+  {
293
+     print('-');
294
+     number = -number;
295
+  }
296
+
297
+  // Round correctly so that print(1.999, 2) prints as "2.00"
298
+  double rounding = 0.5;
299
+  for (uint8_t i=0; i<digits; ++i)
300
+    rounding /= 10.0;
301
+  
302
+  number += rounding;
303
+
304
+  // Extract the integer part of the number and print it
305
+  unsigned long int_part = (unsigned long)number;
306
+  double remainder = number - (double)int_part;
307
+  print(int_part);
308
+
309
+  // Print the decimal point, but only if there are digits beyond
310
+  if (digits > 0)
311
+    print("."); 
312
+
313
+  // Extract digits from the remainder one at a time
314
+  while (digits-- > 0)
315
+  {
316
+    remainder *= 10.0;
317
+    int toPrint = int(remainder);
318
+    print(toPrint);
319
+    remainder -= toPrint; 
320
+  } 
321
+}
322
+// Preinstantiate Objects //////////////////////////////////////////////////////
323
+
324
+
325
+MarlinSerial MSerial;
326
+
327
+#endif // whole file
328
+#endif //teensylu
329
+

+ 150
- 0
Marlin/Marlin/MarlinSerial.h Переглянути файл

1
+/*
2
+  HardwareSerial.h - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right 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
+  Modified 28 September 2010 by Mark Sproul
20
+*/
21
+
22
+#ifndef MarlinSerial_h
23
+#define MarlinSerial_h
24
+#include "Marlin.h"
25
+
26
+
27
+#define DEC 10
28
+#define HEX 16
29
+#define OCT 8
30
+#define BIN 2
31
+#define BYTE 0
32
+
33
+
34
+#if MOTHERBOARD != 8 // ! teensylu
35
+// Define constants and variables for buffering incoming serial data.  We're
36
+// using a ring buffer (I think), in which rx_buffer_head is the index of the
37
+// location to which to write the next incoming character and rx_buffer_tail
38
+// is the index of the location from which to read.
39
+#define RX_BUFFER_SIZE 128
40
+
41
+
42
+struct ring_buffer
43
+{
44
+  unsigned char buffer[RX_BUFFER_SIZE];
45
+  int head;
46
+  int tail;
47
+};
48
+
49
+#if defined(UBRRH) || defined(UBRR0H)
50
+  extern ring_buffer rx_buffer;
51
+#endif
52
+
53
+class MarlinSerial //: public Stream
54
+{
55
+
56
+  public:
57
+    MarlinSerial();
58
+    void begin(long);
59
+    void end();
60
+    int peek(void);
61
+    int read(void);
62
+    void flush(void);
63
+    
64
+    FORCE_INLINE int available(void)
65
+    {
66
+      return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
67
+    }
68
+    
69
+    FORCE_INLINE void write(uint8_t c)
70
+    {
71
+      while (!((UCSR0A) & (1 << UDRE0)))
72
+        ;
73
+
74
+      UDR0 = c;
75
+    }
76
+    
77
+    
78
+    FORCE_INLINE void checkRx(void)
79
+    {
80
+      if((UCSR0A & (1<<RXC0)) != 0) {
81
+        unsigned char c  =  UDR0;
82
+        int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
83
+
84
+        // if we should be storing the received character into the location
85
+        // just before the tail (meaning that the head would advance to the
86
+        // current location of the tail), we're about to overflow the buffer
87
+        // and so we don't write the character or advance the head.
88
+        if (i != rx_buffer.tail) {
89
+          rx_buffer.buffer[rx_buffer.head] = c;
90
+          rx_buffer.head = i;
91
+        }
92
+      }
93
+    }
94
+    
95
+    
96
+    private:
97
+    void printNumber(unsigned long, uint8_t);
98
+    void printFloat(double, uint8_t);
99
+    
100
+    
101
+  public:
102
+    
103
+    FORCE_INLINE void write(const char *str)
104
+    {
105
+      while (*str)
106
+        write(*str++);
107
+    }
108
+
109
+
110
+    FORCE_INLINE void write(const uint8_t *buffer, size_t size)
111
+    {
112
+      while (size--)
113
+        write(*buffer++);
114
+    }
115
+
116
+    FORCE_INLINE void print(const String &s)
117
+    {
118
+      for (int i = 0; i < (int)s.length(); i++) {
119
+        write(s[i]);
120
+      }
121
+    }
122
+    
123
+    FORCE_INLINE void print(const char *str)
124
+    {
125
+      write(str);
126
+    }
127
+    void print(char, int = BYTE);
128
+    void print(unsigned char, int = BYTE);
129
+    void print(int, int = DEC);
130
+    void print(unsigned int, int = DEC);
131
+    void print(long, int = DEC);
132
+    void print(unsigned long, int = DEC);
133
+    void print(double, int = 2);
134
+
135
+    void println(const String &s);
136
+    void println(const char[]);
137
+    void println(char, int = BYTE);
138
+    void println(unsigned char, int = BYTE);
139
+    void println(int, int = DEC);
140
+    void println(unsigned int, int = DEC);
141
+    void println(long, int = DEC);
142
+    void println(unsigned long, int = DEC);
143
+    void println(double, int = 2);
144
+    void println(void);
145
+};
146
+
147
+extern MarlinSerial MSerial;
148
+#endif // ! teensylu
149
+
150
+#endif

BIN
Marlin/Marlin/Menu Plans.xlsx Переглянути файл


+ 16
- 0
Marlin/Marlin/Sanguino/boards.txt Переглянути файл

1
+##############################################################
2
+
3
+sanguino.name=Sanguino
4
+sanguino.upload.protocol=stk500
5
+sanguino.upload.maximum_size=63488
6
+sanguino.upload.speed=38400
7
+sanguino.bootloader.low_fuses=0xFF
8
+sanguino.bootloader.high_fuses=0xDC
9
+sanguino.bootloader.extended_fuses=0xFD
10
+sanguino.bootloader.path=atmega644p
11
+sanguino.bootloader.file=ATmegaBOOT_644P.hex
12
+sanguino.bootloader.unlock_bits=0x3F
13
+sanguino.bootloader.lock_bits=0x0F
14
+sanguino.build.mcu=atmega644p
15
+sanguino.build.f_cpu=16000000L
16
+sanguino.build.core=arduino

+ 713
- 0
Marlin/Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT.c Переглянути файл

1
+/**********************************************************/
2
+/* Serial Bootloader for Atmel megaAVR Controllers        */
3
+/*                                                        */
4
+/* tested with ATmega644 and ATmega644P                   */
5
+/* should work with other mega's, see code for details    */
6
+/*                                                        */
7
+/* ATmegaBOOT.c                                           */
8
+/*                                                        */
9
+/* 20090131: Added 324P support from Alex Leone           */
10
+/*           Marius Kintel                                */
11
+/* 20080915: applied ADABoot mods for Sanguino 644P       */
12
+/*           Brian Riley                                  */
13
+/* 20080711: hacked for Sanguino by Zach Smith            */
14
+/*           and Justin Day                               */
15
+/* 20070626: hacked for Arduino Diecimila (which auto-    */
16
+/*           resets when a USB connection is made to it)  */
17
+/*           by D. Mellis                                 */
18
+/* 20060802: hacked for Arduino by D. Cuartielles         */
19
+/*           based on a previous hack by D. Mellis        */
20
+/*           and D. Cuartielles                           */
21
+/*                                                        */
22
+/* Monitor and debug functions were added to the original */
23
+/* code by Dr. Erik Lins, chip45.com. (See below)         */
24
+/*                                                        */
25
+/* Thanks to Karl Pitrich for fixing a bootloader pin     */
26
+/* problem and more informative LED blinking!             */
27
+/*                                                        */
28
+/* For the latest version see:                            */
29
+/* http://www.chip45.com/                                 */
30
+/*                                                        */
31
+/* ------------------------------------------------------ */
32
+/*                                                        */
33
+/* based on stk500boot.c                                  */
34
+/* Copyright (c) 2003, Jason P. Kyle                      */
35
+/* All rights reserved.                                   */
36
+/* see avr1.org for original file and information         */
37
+/*                                                        */
38
+/* This program is free software; you can redistribute it */
39
+/* and/or modify it under the terms of the GNU General    */
40
+/* Public License as published by the Free Software       */
41
+/* Foundation; either version 2 of the License, or        */
42
+/* (at your option) any later version.                    */
43
+/*                                                        */
44
+/* This program is distributed in the hope that it will   */
45
+/* be useful, but WITHOUT ANY WARRANTY; without even the  */
46
+/* implied warranty of MERCHANTABILITY or FITNESS FOR A   */
47
+/* PARTICULAR PURPOSE.  See the GNU General Public        */
48
+/* License for more details.                              */
49
+/*                                                        */
50
+/* You should have received a copy of the GNU General     */
51
+/* Public License along with this program; if not, write  */
52
+/* to the Free Software Foundation, Inc.,                 */
53
+/* 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA */
54
+/*                                                        */
55
+/* Licence can be viewed at                               */
56
+/* http://www.fsf.org/licenses/gpl.txt                    */
57
+/*                                                        */
58
+/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */
59
+/* m8515,m8535. ATmega161 has a very small boot block so  */
60
+/* isn't supported.                                       */
61
+/*                                                        */
62
+/* Tested with m168                                       */
63
+/**********************************************************/
64
+
65
+/* $Id$ */
66
+
67
+
68
+/* some includes */
69
+#include <inttypes.h>
70
+#include <avr/io.h>
71
+#include <avr/pgmspace.h>
72
+#include <avr/interrupt.h>
73
+#include <avr/wdt.h>
74
+#include <avr/boot.h>
75
+
76
+#ifdef ADABOOT
77
+    #define NUM_LED_FLASHES 3
78
+    #define ADABOOT_VER	1
79
+#endif
80
+
81
+
82
+/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
83
+#define MAX_ERROR_COUNT 5
84
+
85
+/* set the UART baud rate */
86
+/* 20080711: hack by Zach Hoeken */
87
+#define BAUD_RATE   38400
88
+
89
+/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
90
+/* never allow AVR Studio to do an update !!!! */
91
+#define HW_VER	 0x02
92
+#define SW_MAJOR 0x01
93
+#define SW_MINOR 0x10
94
+
95
+/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
96
+/* if monitor functions are included, LED goes on after monitor was entered */
97
+#define LED_DDR  DDRB
98
+#define LED_PORT PORTB
99
+#define LED_PIN  PINB
100
+#define LED      PINB0
101
+
102
+/* define various device id's */
103
+/* manufacturer byte is always the same */
104
+#define SIG1	0x1E	// Yep, Atmel is the only manufacturer of AVR micros.  Single source :(
105
+#if defined(__AVR_ATmega644P__)
106
+#define SIG2	0x96
107
+#define SIG3	0x0A
108
+#elif defined(__AVR_ATmega644__)
109
+#define SIG2	0x96
110
+#define SIG3	0x09
111
+#elif defined(__AVR_ATmega324P__)
112
+#define SIG2	0x95
113
+#define SIG3	0x08
114
+#endif
115
+#define PAGE_SIZE		0x080U   //128 words
116
+#define PAGE_SIZE_BYTES	0x100U   //256 bytes
117
+
118
+/* function prototypes */
119
+void putch(char);
120
+char getch(void);
121
+void getNch(uint8_t);
122
+void byte_response(uint8_t);
123
+void nothing_response(void);
124
+char gethex(void);
125
+void puthex(char);
126
+void flash_led(uint8_t);
127
+
128
+/* some variables */
129
+union address_union
130
+{
131
+    uint16_t word;
132
+    uint8_t  byte[2];
133
+} address;
134
+
135
+union length_union
136
+{
137
+    uint16_t word;
138
+    uint8_t  byte[2];
139
+} length;
140
+
141
+struct flags_struct
142
+{
143
+    unsigned eeprom : 1;
144
+    unsigned rampz  : 1;
145
+} flags;
146
+
147
+uint8_t buff[256];
148
+
149
+uint8_t error_count = 0;
150
+uint8_t sreg;
151
+
152
+void (*app_start)(void) = 0x0000;
153
+
154
+/* main program starts here */
155
+int main(void)
156
+{
157
+    uint8_t ch,ch2;
158
+    uint16_t w;
159
+	uint16_t i;
160
+	
161
+    asm volatile("nop\n\t");
162
+
163
+#ifdef ADABOOT		// BBR/LF 10/8/2007 & 9/13/2008
164
+    ch = MCUSR;
165
+    MCUSR = 0;
166
+
167
+    WDTCSR |= _BV(WDCE) | _BV(WDE);
168
+    WDTCSR = 0;
169
+
170
+    // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
171
+    if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
172
+      app_start();  // skip bootloader
173
+#endif
174
+
175
+
176
+	//initialize our serial port.
177
+    UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
178
+    UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
179
+    UCSR0B = (1<<RXEN0) | (1<<TXEN0);
180
+    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
181
+
182
+    /* Enable internal pull-up resistor on pin D0 (RX), in order
183
+    to supress line noise that prevents the bootloader from
184
+    timing out (DAM: 20070509) */
185
+    DDRD &= ~_BV(PIND0);
186
+    PORTD |= _BV(PIND0);
187
+
188
+    /* set LED pin as output */
189
+    LED_DDR |= _BV(LED);
190
+
191
+	    /* flash onboard LED to signal entering of bootloader                   */
192
+	    /* ADABOOT will do two series of flashes. first 4 - signifying ADABOOT  */
193
+	    /* then a pause and another flash series signifying ADABOOT sub-version */
194
+
195
+
196
+	flash_led(NUM_LED_FLASHES);
197
+
198
+	#ifdef	ADABOOT
199
+		flash_led(ADABOOT_VER);		// BBR 9/13/2008
200
+	#endif 
201
+
202
+    /* forever loop */
203
+    for (;;)
204
+	{
205
+		/* get character from UART */
206
+		ch = getch();
207
+
208
+		/* A bunch of if...else if... gives smaller code than switch...case ! */
209
+
210
+		/* Hello is anyone home ? */ 
211
+		if(ch=='0')
212
+		    nothing_response();
213
+
214
+
215
+		/* Request programmer ID */
216
+		/* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry  */
217
+		/* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares.  */
218
+		else if(ch=='1')
219
+		{
220
+		    if (getch() == ' ')
221
+			{
222
+				putch(0x14);
223
+				putch('A');
224
+				putch('V');
225
+				putch('R');
226
+				putch(' ');
227
+				putch('I');
228
+				putch('S');
229
+				putch('P');
230
+				putch(0x10);
231
+		    }
232
+			else
233
+			{
234
+				if (++error_count == MAX_ERROR_COUNT)
235
+				    app_start();
236
+		    }
237
+		}
238
+
239
+
240
+		/* AVR ISP/STK500 board commands  DON'T CARE so default nothing_response */
241
+		else if(ch=='@')
242
+		{
243
+		    ch2 = getch();
244
+		    if (ch2 > 0x85)
245
+				getch();
246
+		    nothing_response();
247
+		}
248
+
249
+
250
+		/* AVR ISP/STK500 board requests */
251
+		else if(ch=='A')
252
+		{
253
+		    ch2 = getch();
254
+		    if(ch2 == 0x80)
255
+				byte_response(HW_VER);		// Hardware version
256
+		    else if(ch2==0x81)
257
+				byte_response(SW_MAJOR);	// Software major version
258
+		    else if(ch2==0x82)
259
+				byte_response(SW_MINOR);	// Software minor version
260
+		    else if(ch2==0x98)
261
+				byte_response(0x03);		// Unknown but seems to be required by avr studio 3.56
262
+		    else
263
+				byte_response(0x00);		// Covers various unnecessary responses we don't care about
264
+		}
265
+
266
+
267
+		/* Device Parameters  DON'T CARE, DEVICE IS FIXED  */
268
+		else if(ch=='B')
269
+		{
270
+		    getNch(20);
271
+		    nothing_response();
272
+		}
273
+
274
+
275
+		/* Parallel programming stuff  DON'T CARE  */
276
+		else if(ch=='E')
277
+		{
278
+		    getNch(5);
279
+		    nothing_response();
280
+		}
281
+
282
+
283
+		/* Enter programming mode  */
284
+		else if(ch=='P')
285
+		{
286
+		    nothing_response();
287
+		}
288
+
289
+
290
+		/* Leave programming mode  */
291
+		else if(ch=='Q')
292
+		{
293
+		    nothing_response();
294
+#ifdef ADABOOT		
295
+			// autoreset via watchdog (sneaky!) BBR/LF 9/13/2008
296
+	  		WDTCSR = _BV(WDE);
297
+	  		while (1); // 16 ms
298
+#endif		
299
+		}
300
+
301
+
302
+		/* Erase device, don't care as we will erase one page at a time anyway.  */
303
+		else if(ch=='R')
304
+		{
305
+		    nothing_response();
306
+		}
307
+
308
+
309
+		/* Set address, little endian. EEPROM in bytes, FLASH in words  */
310
+		/* Perhaps extra address bytes may be added in future to support > 128kB FLASH.  */
311
+		/* This might explain why little endian was used here, big endian used everywhere else.  */
312
+		else if(ch=='U')
313
+		{
314
+		    address.byte[0] = getch();
315
+		    address.byte[1] = getch();
316
+		    nothing_response();
317
+		}
318
+
319
+
320
+		/* Universal SPI programming command, disabled.  Would be used for fuses and lock bits.  */
321
+		else if(ch=='V')
322
+		{
323
+		    getNch(4);
324
+		    byte_response(0x00);
325
+		}
326
+
327
+
328
+		/* Write memory, length is big endian and is in bytes  */
329
+		else if(ch=='d')
330
+		{
331
+		    length.byte[1] = getch();
332
+		    length.byte[0] = getch();
333
+	
334
+		    flags.eeprom = 0;
335
+		    if (getch() == 'E')
336
+				flags.eeprom = 1;
337
+
338
+			for (i=0; i<PAGE_SIZE; i++)
339
+				buff[i] = 0;
340
+		
341
+		    for (w = 0; w < length.word; w++)
342
+			{
343
+				// Store data in buffer, can't keep up with serial data stream whilst programming pages
344
+				buff[w] = getch();
345
+		    }
346
+	
347
+		    if (getch() == ' ')
348
+			{
349
+				if (flags.eeprom)
350
+				{		                
351
+					//Write to EEPROM one byte at a time
352
+				    for(w=0;w<length.word;w++)
353
+					{
354
+						while(EECR & (1<<EEPE));
355
+					
356
+						EEAR = (uint16_t)(void *)address.word;
357
+						EEDR = buff[w];
358
+						EECR |= (1<<EEMPE);
359
+						EECR |= (1<<EEPE);
360
+
361
+						address.word++;
362
+				    }			
363
+				}
364
+				else
365
+				{
366
+					//address * 2 -> byte location
367
+				    address.word = address.word << 1;
368
+			    
369
+					//Even up an odd number of bytes
370
+					if ((length.byte[0] & 0x01))
371
+						length.word++;
372
+				
373
+					// HACKME: EEPE used to be EEWE
374
+				    //Wait for previous EEPROM writes to complete
375
+					//while(bit_is_set(EECR,EEPE));
376
+					while(EECR & (1<<EEPE));
377
+				
378
+				    asm volatile(
379
+						 "clr	r17		\n\t"	//page_word_count
380
+						 "lds	r30,address	\n\t"	//Address of FLASH location (in bytes)
381
+						 "lds	r31,address+1	\n\t"
382
+						 "ldi	r28,lo8(buff)	\n\t"	//Start of buffer array in RAM
383
+						 "ldi	r29,hi8(buff)	\n\t"
384
+						 "lds	r24,length	\n\t"	//Length of data to be written (in bytes)
385
+						 "lds	r25,length+1	\n\t"
386
+						 "length_loop:		\n\t"	//Main loop, repeat for number of words in block							 							 
387
+						 "cpi	r17,0x00	\n\t"	//If page_word_count=0 then erase page
388
+						 "brne	no_page_erase	\n\t"						 
389
+						 "wait_spm1:		\n\t"
390
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
391
+						 "andi	r16,1           \n\t"
392
+						 "cpi	r16,1           \n\t"
393
+						 "breq	wait_spm1       \n\t"
394
+						 "ldi	r16,0x03	\n\t"	//Erase page pointed to by Z
395
+						 "sts	%0,r16		\n\t"
396
+						 "spm			\n\t"							 
397
+						 "wait_spm2:		\n\t"
398
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
399
+						 "andi	r16,1           \n\t"
400
+						 "cpi	r16,1           \n\t"
401
+						 "breq	wait_spm2       \n\t"									 
402
+
403
+						 "ldi	r16,0x11	\n\t"	//Re-enable RWW section
404
+						 "sts	%0,r16		\n\t"						 			 
405
+						 "spm			\n\t"
406
+						 "no_page_erase:		\n\t"							 
407
+						 "ld	r0,Y+		\n\t"	//Write 2 bytes into page buffer
408
+						 "ld	r1,Y+		\n\t"							 
409
+							 
410
+						 "wait_spm3:		\n\t"
411
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
412
+						 "andi	r16,1           \n\t"
413
+						 "cpi	r16,1           \n\t"
414
+						 "breq	wait_spm3       \n\t"
415
+						 "ldi	r16,0x01	\n\t"	//Load r0,r1 into FLASH page buffer
416
+						 "sts	%0,r16		\n\t"
417
+						 "spm			\n\t"
418
+							 
419
+						 "inc	r17		\n\t"	//page_word_count++
420
+						 "cpi r17,%1	        \n\t"
421
+						 "brlo	same_page	\n\t"	//Still same page in FLASH
422
+						 "write_page:		\n\t"
423
+						 "clr	r17		\n\t"	//New page, write current one first
424
+						 "wait_spm4:		\n\t"
425
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
426
+						 "andi	r16,1           \n\t"
427
+						 "cpi	r16,1           \n\t"
428
+						 "breq	wait_spm4       \n\t"						 							 
429
+						 "ldi	r16,0x05	\n\t"	//Write page pointed to by Z
430
+						 "sts	%0,r16		\n\t"
431
+						 "spm			\n\t"
432
+						 "wait_spm5:		\n\t"
433
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
434
+						 "andi	r16,1           \n\t"
435
+						 "cpi	r16,1           \n\t"
436
+						 "breq	wait_spm5       \n\t"									 
437
+						 "ldi	r16,0x11	\n\t"	//Re-enable RWW section
438
+						 "sts	%0,r16		\n\t"						 			 
439
+						 "spm			\n\t"					 		 
440
+						 "same_page:		\n\t"							 
441
+						 "adiw	r30,2		\n\t"	//Next word in FLASH
442
+						 "sbiw	r24,2		\n\t"	//length-2
443
+						 "breq	final_write	\n\t"	//Finished
444
+						 "rjmp	length_loop	\n\t"
445
+						 "final_write:		\n\t"
446
+						 "cpi	r17,0		\n\t"
447
+						 "breq	block_done	\n\t"
448
+						 "adiw	r24,2		\n\t"	//length+2, fool above check on length after short page write
449
+						 "rjmp	write_page	\n\t"
450
+						 "block_done:		\n\t"
451
+						 "clr	__zero_reg__	\n\t"	//restore zero register
452
+						 : "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
453
+
454
+						 );
455
+				}
456
+				putch(0x14);
457
+				putch(0x10);
458
+		    }
459
+			else
460
+			{
461
+				if (++error_count == MAX_ERROR_COUNT)
462
+				    app_start();
463
+		    }		
464
+		}
465
+    
466
+		/* Read memory block mode, length is big endian.  */
467
+		else if(ch=='t')
468
+		{
469
+			length.byte[1] = getch();
470
+			length.byte[0] = getch();
471
+
472
+			if (getch() == 'E')
473
+				flags.eeprom = 1;
474
+			else
475
+			{
476
+				flags.eeprom = 0;
477
+				address.word = address.word << 1;	        // address * 2 -> byte location
478
+			}
479
+
480
+			// Command terminator
481
+			if (getch() == ' ')
482
+			{
483
+				putch(0x14);
484
+				for (w=0; w<length.word; w++)
485
+				{
486
+					// Can handle odd and even lengths okay
487
+				    if (flags.eeprom) 
488
+					{
489
+						// Byte access EEPROM read
490
+						while(EECR & (1<<EEPE));
491
+						EEAR = (uint16_t)(void *)address.word;
492
+						EECR |= (1<<EERE);
493
+						putch(EEDR);
494
+
495
+						address.word++;
496
+				    }
497
+				    else
498
+					{
499
+						if (!flags.rampz)
500
+							putch(pgm_read_byte_near(address.word));
501
+
502
+						address.word++;
503
+				    }
504
+				}
505
+				putch(0x10);
506
+		    }
507
+		}
508
+
509
+
510
+		/* Get device signature bytes  */
511
+		else if(ch=='u')
512
+		{
513
+			if (getch() == ' ')
514
+			{
515
+				putch(0x14);
516
+				putch(SIG1);
517
+				putch(SIG2);
518
+				putch(SIG3);
519
+				putch(0x10);
520
+			}
521
+			else
522
+			{
523
+				if (++error_count == MAX_ERROR_COUNT)
524
+					app_start();
525
+			}
526
+		}
527
+
528
+
529
+		/* Read oscillator calibration byte */
530
+		else if(ch=='v')
531
+			byte_response(0x00);
532
+
533
+		else if (++error_count == MAX_ERROR_COUNT)
534
+		    app_start();
535
+
536
+	}
537
+    /* end of forever loop */
538
+}
539
+
540
+
541
+char gethex(void)
542
+{
543
+    char ah,al;
544
+
545
+    ah = getch();
546
+	putch(ah);
547
+    al = getch();
548
+	putch(al);
549
+    
550
+	if(ah >= 'a')
551
+		ah = ah - 'a' + 0x0a;
552
+	else if(ah >= '0')
553
+		ah -= '0';
554
+    if(al >= 'a')
555
+		al = al - 'a' + 0x0a;
556
+	else if(al >= '0')
557
+		al -= '0';
558
+
559
+    return (ah << 4) + al;
560
+}
561
+
562
+
563
+void puthex(char ch)
564
+{
565
+    char ah,al;
566
+
567
+    ah = (ch & 0xf0) >> 4;
568
+	if(ah >= 0x0a)
569
+		ah = ah - 0x0a + 'a';
570
+	else
571
+		ah += '0';
572
+
573
+    al = (ch & 0x0f);
574
+	if(al >= 0x0a)
575
+		al = al - 0x0a + 'a';
576
+	else
577
+		al += '0';
578
+
579
+    putch(ah);
580
+    putch(al);
581
+}
582
+
583
+
584
+void putch(char ch)
585
+{
586
+    while (!(UCSR0A & _BV(UDRE0)));
587
+    UDR0 = ch;
588
+}
589
+
590
+
591
+
592
+
593
+char getch(void)
594
+{
595
+    uint32_t count = 0;
596
+
597
+#ifdef ADABOOT
598
+	LED_PORT &= ~_BV(LED);          // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
599
+#endif
600
+
601
+    while(!(UCSR0A & _BV(RXC0)))
602
+	{
603
+    	/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/               
604
+    	/* HACKME:: here is a good place to count times*/
605
+    	count++;
606
+    	if (count > MAX_TIME_COUNT)
607
+    		app_start();
608
+     }
609
+
610
+#ifdef ADABOOT
611
+	LED_PORT |= _BV(LED);          // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
612
+#endif
613
+
614
+    return UDR0;
615
+}
616
+
617
+
618
+void getNch(uint8_t count)
619
+{
620
+    uint8_t i;
621
+    for(i=0;i<count;i++)
622
+	{
623
+		while(!(UCSR0A & _BV(RXC0)));
624
+		UDR0;
625
+    }
626
+}
627
+
628
+
629
+void byte_response(uint8_t val)
630
+{
631
+    if (getch() == ' ')
632
+	{
633
+		putch(0x14);
634
+		putch(val);
635
+		putch(0x10);
636
+    }
637
+	else
638
+	{
639
+		if (++error_count == MAX_ERROR_COUNT)
640
+		    app_start();
641
+    }
642
+}
643
+
644
+
645
+void nothing_response(void)
646
+{
647
+    if (getch() == ' ')
648
+	{
649
+		putch(0x14);
650
+		putch(0x10);
651
+    }
652
+	else
653
+	{
654
+		if (++error_count == MAX_ERROR_COUNT)
655
+		    app_start();
656
+    }
657
+}
658
+
659
+#ifdef ADABOOT
660
+
661
+void flash_led(uint8_t count)
662
+{
663
+    /* flash onboard LED count times to signal entering of bootloader */
664
+	/* l needs to be volatile or the delay loops below might get      */
665
+	/* optimized away if compiling with optimizations (DAM).          */
666
+	
667
+    volatile uint32_t l;
668
+
669
+    if (count == 0) {
670
+      count = ADABOOT;
671
+    }
672
+    
673
+
674
+	int8_t i;
675
+    for (i = 0; i < count; ++i) {
676
+		LED_PORT |= _BV(LED);					// LED on
677
+		for(l = 0; l < (F_CPU / 1000); ++l);		// delay NGvalue was 1000 for both loops - BBR
678
+		LED_PORT &= ~_BV(LED);					// LED off
679
+		for(l = 0; l < (F_CPU / 250); ++l);		// delay asymmteric for ADA BOOT BBR 
680
+	}
681
+
682
+	for(l = 0; l < (F_CPU / 100); ++l);		    // pause ADA BOOT BBR 
683
+		
684
+}
685
+
686
+#else
687
+
688
+void flash_led(uint8_t count)
689
+{
690
+    /* flash onboard LED three times to signal entering of bootloader */
691
+	/* l needs to be volatile or the delay loops below might get
692
+	optimized away if compiling with optimizations (DAM). */
693
+    volatile uint32_t l;
694
+
695
+    if (count == 0) {
696
+      count = 3;
697
+    }
698
+    
699
+	int8_t i;
700
+    for (i = 0; i < count; ++i) {
701
+		LED_PORT |= _BV(LED);
702
+		for(l = 0; l < (F_CPU / 1000); ++l);
703
+		LED_PORT &= ~_BV(LED);
704
+		for(l = 0; l < (F_CPU / 1000); ++l); 
705
+	}
706
+		
707
+}
708
+
709
+
710
+#endif
711
+
712
+
713
+/* end of file ATmegaBOOT.c */

+ 121
- 0
Marlin/Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_324P.hex Переглянути файл

1
+:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
2
+:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
3
+:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
4
+:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
5
+:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
6
+:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
7
+:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
8
+:10F870000C945B7C0C945B7C0C945B7C11241FBE11
9
+:10F88000CFEFD8E0DEBFCDBF11E0A0E0B1E0E6E60B
10
+:10F89000FFEF02C005900D92A030B107D9F712E03A
11
+:10F8A000A0E0B1E001C01D92A930B107E1F70E94CC
12
+:10F8B000537D0C94B27F0C94007CCF93DF93CDB733
13
+:10F8C000DEB724970FB6F894DEBF0FBECDBF8823F6
14
+:10F8D00009F481E020E0482F55274115510509F42E
15
+:10F8E0003DC0289A19821A821B821C820BC0898112
16
+:10F8F0009A81AB81BC810196A11DB11D89839A8338
17
+:10F90000AB83BC8389819A81AB81BC8180589E4343
18
+:10F91000A040B04060F3289819821A821B821C8292
19
+:10F920000BC089819A81AB81BC810196A11DB11D5B
20
+:10F9300089839A83AB83BC8389819A81AB81BC81A3
21
+:10F9400080509A4FA040B04060F32F5F822F9927DC
22
+:10F9500087FD9095841795070CF4C3CF19821A82FE
23
+:10F960001B821C8289819A81AB81BC818050914726
24
+:10F97000A240B040A0F489819A81AB81BC810196FC
25
+:10F98000A11DB11D89839A83AB83BC8389819A8130
26
+:10F99000AB81BC8180509147A240B04060F3249677
27
+:10F9A0000FB6F894DEBF0FBECDBFDF91CF910895A3
28
+:10F9B000EF92FF920F931F93EE24FF248701289864
29
+:10F9C0008091C00087FD17C00894E11CF11C011D47
30
+:10F9D000111D81E0E81689E0F8068DE3080780E054
31
+:10F9E000180770F3E0910001F091010109958091F1
32
+:10F9F000C00087FFE9CF289A8091C600992787FD2C
33
+:10FA000090951F910F91FF90EF900895982F8091FE
34
+:10FA1000C00085FFFCCF9093C60008950E94D87C5B
35
+:10FA2000803271F0809102018F5F809302018530F6
36
+:10FA300009F00895E0910001F09101010995089500
37
+:10FA400084E10E94067D80E10E94067D0895CF93A7
38
+:10FA5000C82F0E94D87C803241F0809102018F5FD4
39
+:10FA600080930201853081F40AC084E10E94067D02
40
+:10FA70008C2F0E94067D80E10E94067D05C0E091EA
41
+:10FA80000001F09101010995CF910895282F90E090
42
+:10FA900007C08091C0008823E4F78091C6009F5F73
43
+:10FAA0009217B8F30895CFEFD8E0DEBFCDBF0000C6
44
+:10FAB00094B714BE809160008861809360001092BA
45
+:10FAC000600091FF74C189E18093C4001092C50069
46
+:10FAD00088E18093C10086E08093C2005098589AD4
47
+:10FAE000209A83E00E945D7C81E00E945D7C0E9400
48
+:10FAF000D87C8033B9F18133C1F1803409F456C028
49
+:10FB0000813409F45CC0823409F46EC0853409F490
50
+:10FB100071C0803539F1813509F4F3C0823511F1B6
51
+:10FB2000853509F4D3C0863509F4CBC0843609F491
52
+:10FB300065C0843709F4EBC0853709F4D2C0863735
53
+:10FB400009F44AC0809102018F5F809302018530E1
54
+:10FB500071F6E0910001F091010109950E94D87CB5
55
+:10FB6000803349F60E940E7DC2CF0E94D87CC82FF8
56
+:10FB7000803241F784E10E94067D81E40E94067D87
57
+:10FB800086E50E94067D82E50E94067D8C2F0E94FC
58
+:10FB9000067D89E40E94067D83E50E94067D80E55E
59
+:10FBA0000E94067D80E10E94067DA1CF0E94D87C44
60
+:10FBB0008638C0F20E94D87C0E940E7D98CF0E94A9
61
+:10FBC000D87C803809F407C1813809F400C1823833
62
+:10FBD00009F4F9C0883921F080E00E94277D87CFA1
63
+:10FBE00083E00E94277D83CF84E10E94467D0E94AE
64
+:10FBF0000E7D7DCF85E00E94467DF9CF0E94D87CA6
65
+:10FC0000809306020E94D87C8093050280910802AE
66
+:10FC10008E7F809308020E94D87C853409F44BC003
67
+:10FC2000E5E0F1E0119281E0E438F807D9F3D0F390
68
+:10FC3000C0E0D0E0809105029091060218161906E6
69
+:10FC400078F405E011E00E94D87CF80181938F01DF
70
+:10FC500021968091050290910602C817D90798F362
71
+:10FC60000E94D87C803209F06DCF8091080280FF1D
72
+:10FC7000B6C0C0E0D0E02091050230910602121615
73
+:10FC80001306B8F4E0910301F0910401A5E0B1E09E
74
+:10FC9000F999FECFF2BDE1BD8D9180BDFA9AF99A36
75
+:10FCA00031962196C217D30798F3F0930401E0939D
76
+:10FCB000030184E175CF809108028160809308027E
77
+:10FCC000AFCF84E00E94467D80E087CF0E94D87C41
78
+:10FCD000809303010E94D87C809304010E940E7DD2
79
+:10FCE00006CF0E94D87C803209F02CCF84E10E949C
80
+:10FCF000067D8EE10E94067D85E90E94067D88E0F2
81
+:10FD00004FCF0E940E7D88E080936000FFCF0E945D
82
+:10FD1000D87C809306020E94D87C809305020E94C2
83
+:10FD2000D87C853409F449C0809108028E7F809385
84
+:10FD300008028091030190910401880F991F90930C
85
+:10FD40000401809303010E94D87C803209F0CFCE59
86
+:10FD500084E10E94067DC0E0D0E020910502309150
87
+:10FD600006021216130608F01DCFE0910301F09170
88
+:10FD700004018091080280FF96C0F999FECFF2BD80
89
+:10FD8000E1BDF89A80B50E94067DE0910301F091F3
90
+:10FD900004013196F0930401E093030120910502E0
91
+:10FDA000309106022196C217D30718F3FBCEE091DB
92
+:10FDB0000001F0910101099586CE809108028160D1
93
+:10FDC00080930802C0CF80E10E94277D90CE81E021
94
+:10FDD0000E94277D8CCE82E00E94277D88CE809174
95
+:10FDE000030190910401880F991F9093040180935F
96
+:10FDF00003018091050280FF09C080910502909166
97
+:10FE0000060201969093060280930502F999FECFAF
98
+:10FE10001127E0910301F0910401C5E0D1E0809148
99
+:10FE2000050290910602103091F400915700017084
100
+:10FE30000130D9F303E000935700E8950091570093
101
+:10FE400001700130D9F301E100935700E895099062
102
+:10FE500019900091570001700130D9F301E000932F
103
+:10FE60005700E8951395103898F011270091570026
104
+:10FE700001700130D9F305E000935700E895009137
105
+:10FE8000570001700130D9F301E100935700E89564
106
+:10FE90003296029709F0C7CF103011F00296E5CFE5
107
+:10FEA000112484E17DCE869580FF06C03196F093C3
108
+:10FEB0000401E093030176CF84910E94067D209196
109
+:10FEC000050230910602E0910301F0910401EECFAA
110
+:10FED0001F93CF930E94D87CC82F0E94067D0E945A
111
+:10FEE000D87C182F0E94067DC1362CF0C7551136DC
112
+:10FEF0003CF0175508C0C033D4F3C0531136CCF7CB
113
+:10FF000010330CF01053C295C07FC10F8C2F99276E
114
+:10FF100087FD9095CF911F910895CF93282F992712
115
+:10FF200087FD9095807F907095958795959587959D
116
+:10FF300095958795959587958A303CF0895AC22F7B
117
+:10FF4000CF70CA303CF0C95A06C0805DC22FCF7056
118
+:10FF5000CA30CCF7C05D0E94067D8C2F0E94067DC2
119
+:06FF6000CF910895FFCFD0
120
+:040000030000F80001
121
+:00000001FF

+ 120
- 0
Marlin/Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_644.hex Переглянути файл

1
+:10F800000C94387C0C94557C0C94557C0C94557C51
2
+:10F810000C94557C0C94557C0C94557C0C94557C24
3
+:10F820000C94557C0C94557C0C94557C0C94557C14
4
+:10F830000C94557C0C94557C0C94557C0C94557C04
5
+:10F840000C94557C0C94557C0C94557C0C94557CF4
6
+:10F850000C94557C0C94557C0C94557C0C94557CE4
7
+:10F860000C94557C0C94557C0C94557C0C94557CD4
8
+:10F8700011241FBECFEFD0E1DEBFCDBF11E0A0E06D
9
+:10F88000B1E0EAE5FFEF02C005900D92A030B107AC
10
+:10F89000D9F712E0A0E0B1E001C01D92A930B10794
11
+:10F8A000E1F70E944D7D0C94AC7F0C94007CCF93CB
12
+:10F8B000DF93CDB7DEB724970FB6F894DEBF0FBE47
13
+:10F8C000CDBF882309F481E020E0482F552741155A
14
+:10F8D000510509F43DC0289A19821A821B821C82A4
15
+:10F8E0000BC089819A81AB81BC810196A11DB11D9C
16
+:10F8F00089839A83AB83BC8389819A81AB81BC81E4
17
+:10F9000080589E43A040B04060F3289819821A8224
18
+:10F910001B821C820BC089819A81AB81BC810196BC
19
+:10F92000A11DB11D89839A83AB83BC8389819A8190
20
+:10F93000AB81BC8180509A4FA040B04060F32F5FF4
21
+:10F94000822F992787FD9095841795070CF4C3CFD4
22
+:10F9500019821A821B821C8289819A81AB81BC81A7
23
+:10F9600080509147A240B040A0F489819A81AB8138
24
+:10F97000BC810196A11DB11D89839A83AB83BC8391
25
+:10F9800089819A81AB81BC8180509147A240B0406F
26
+:10F9900060F324960FB6F894DEBF0FBECDBFDF91A3
27
+:10F9A000CF910895EF92FF920F931F93EE24FF24BF
28
+:10F9B000870128988091C00087FD17C00894E11C3A
29
+:10F9C000F11C011D111D81E0E81689E0F8068DE3A8
30
+:10F9D000080780E0180770F3E0910001F091010141
31
+:10F9E00009958091C00087FFE9CF289A8091C600D1
32
+:10F9F000992787FD90951F910F91FF90EF900895A3
33
+:10FA0000982F8091C00085FFFCCF9093C600089589
34
+:10FA10000E94D27C803271F0809102018F5F8093CE
35
+:10FA20000201853009F00895E0910001F091010193
36
+:10FA30000995089584E10E94007D80E10E94007D87
37
+:10FA40000895CF93C82F0E94D27C803241F08091DC
38
+:10FA500002018F5F80930201853081F40AC084E146
39
+:10FA60000E94007D8C2F0E94007D80E10E94007D1D
40
+:10FA700005C0E0910001F09101010995CF91089531
41
+:10FA8000282F90E007C08091C0008823E4F7809180
42
+:10FA9000C6009F5F9217B8F30895CFEFD0E1DEBFA5
43
+:10FAA000CDBF000094B714BE809160008861809340
44
+:10FAB00060001092600091FF74C189E18093C400DE
45
+:10FAC0001092C50088E18093C10086E08093C20057
46
+:10FAD0005098589A209A83E00E94577C81E00E94B7
47
+:10FAE000577C0E94D27C8033B9F18133C1F18034DC
48
+:10FAF00009F456C0813409F45CC0823409F46EC044
49
+:10FB0000853409F471C0803539F1813509F4F3C0C9
50
+:10FB1000823511F1853509F4D3C0863509F4CBC09F
51
+:10FB2000843609F465C0843709F4EBC0853709F4DD
52
+:10FB3000D2C0863709F44AC0809102018F5F80935A
53
+:10FB40000201853071F6E0910001F0910101099503
54
+:10FB50000E94D27C803349F60E94087DC2CF0E9469
55
+:10FB6000D27CC82F803241F784E10E94007D81E47D
56
+:10FB70000E94007D86E50E94007D82E50E94007D56
57
+:10FB80008C2F0E94007D89E40E94007D83E50E9405
58
+:10FB9000007D80E50E94007D80E10E94007DA1CF74
59
+:10FBA0000E94D27C8638C0F20E94D27C0E94087DDE
60
+:10FBB00098CF0E94D27C803809F407C1813809F4BB
61
+:10FBC00000C1823809F4F9C0883921F080E00E9430
62
+:10FBD000217D87CF83E00E94217D83CF84E10E9435
63
+:10FBE000407D0E94087D7DCF85E00E94407DF9CF59
64
+:10FBF0000E94D27C809306020E94D27C80930502F0
65
+:10FC0000809108028E7F809308020E94D27C853406
66
+:10FC100009F44BC0E5E0F1E0119281E0E438F80727
67
+:10FC2000D9F3D0F3C0E0D0E08091050290910602B4
68
+:10FC30001816190678F405E011E00E94D27CF8014C
69
+:10FC400081938F0121968091050290910602C81739
70
+:10FC5000D90798F30E94D27C803209F06DCF809151
71
+:10FC6000080280FFB6C0C0E0D0E0209105023091CC
72
+:10FC7000060212161306B8F4E0910301F091040194
73
+:10FC8000A5E0B1E0F999FECFF2BDE1BD8D9180BD57
74
+:10FC9000FA9AF99A31962196C217D30798F3F093FE
75
+:10FCA0000401E093030184E175CF80910802816033
76
+:10FCB00080930802AFCF84E00E94407D80E087CF30
77
+:10FCC0000E94D27C809303010E94D27C8093040125
78
+:10FCD0000E94087D06CF0E94D27C803209F02CCF92
79
+:10FCE00084E10E94007D8EE10E94007D86E90E94F1
80
+:10FCF000007D89E04FCF0E94087D88E080936000FE
81
+:10FD0000FFCF0E94D27C809306020E94D27C809317
82
+:10FD100005020E94D27C853409F449C08091080212
83
+:10FD20008E7F809308028091030190910401880FD7
84
+:10FD3000991F90930401809303010E94D27C80322A
85
+:10FD400009F0CFCE84E10E94007DC0E0D0E0209198
86
+:10FD50000502309106021216130608F01DCFE0913D
87
+:10FD60000301F09104018091080280FF96C0F99987
88
+:10FD7000FECFF2BDE1BDF89A80B50E94007DE09112
89
+:10FD80000301F09104013196F0930401E093030123
90
+:10FD900020910502309106022196C217D30718F36D
91
+:10FDA000FBCEE0910001F0910101099586CE809192
92
+:10FDB0000802816080930802C0CF80E10E94217D0B
93
+:10FDC00090CE81E00E94217D8CCE82E00E94217D38
94
+:10FDD00088CE8091030190910401880F991F909320
95
+:10FDE0000401809303018091050280FF09C0809186
96
+:10FDF00005029091060201969093060280930502F7
97
+:10FE0000F999FECF1127E0910301F0910401C5E0BB
98
+:10FE1000D1E08091050290910602103091F400919A
99
+:10FE2000570001700130D9F303E000935700E895C3
100
+:10FE30000091570001700130D9F301E100935700A0
101
+:10FE4000E895099019900091570001700130D9F39D
102
+:10FE500001E000935700E8951395103898F01127AA
103
+:10FE60000091570001700130D9F305E0009357006D
104
+:10FE7000E8950091570001700130D9F301E100933A
105
+:10FE80005700E8953296029709F0C7CF103011F06D
106
+:10FE90000296E5CF112484E17DCE869580FF06C0D1
107
+:10FEA0003196F0930401E093030176CF84910E9490
108
+:10FEB000007D2091050230910602E0910301F0914E
109
+:10FEC0000401EECF1F93CF930E94D27CC82F0E94D3
110
+:10FED000007D0E94D27C182F0E94007DC1362CF03C
111
+:10FEE000C75511363CF0175508C0C033D4F3C05382
112
+:10FEF0001136CCF710330CF01053C295C07FC10FF0
113
+:10FF00008C2F992787FD9095CF911F910895CF93BE
114
+:10FF1000282F992787FD9095807F907095958795DC
115
+:10FF20009595879595958795959587958A303CF019
116
+:10FF3000895AC22FCF70CA303CF0C95A06C0805DC2
117
+:10FF4000C22FCF70CA30CCF7C05D0E94007D8C2FCD
118
+:0AFF50000E94007DCF910895FFCFBD
119
+:040000030000F80001
120
+:00000001FF

+ 121
- 0
Marlin/Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_644P.hex Переглянути файл

1
+:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
2
+:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
3
+:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
4
+:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
5
+:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
6
+:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
7
+:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
8
+:10F870000C945B7C0C945B7C0C945B7C11241FBE11
9
+:10F88000CFEFD0E1DEBFCDBF11E0A0E0B1E0E6E612
10
+:10F89000FFEF02C005900D92A030B107D9F712E03A
11
+:10F8A000A0E0B1E001C01D92A930B107E1F70E94CC
12
+:10F8B000537D0C94B27F0C94007CCF93DF93CDB733
13
+:10F8C000DEB724970FB6F894DEBF0FBECDBF8823F6
14
+:10F8D00009F481E020E0482F55274115510509F42E
15
+:10F8E0003DC0289A19821A821B821C820BC0898112
16
+:10F8F0009A81AB81BC810196A11DB11D89839A8338
17
+:10F90000AB83BC8389819A81AB81BC8180589E4343
18
+:10F91000A040B04060F3289819821A821B821C8292
19
+:10F920000BC089819A81AB81BC810196A11DB11D5B
20
+:10F9300089839A83AB83BC8389819A81AB81BC81A3
21
+:10F9400080509A4FA040B04060F32F5F822F9927DC
22
+:10F9500087FD9095841795070CF4C3CF19821A82FE
23
+:10F960001B821C8289819A81AB81BC818050914726
24
+:10F97000A240B040A0F489819A81AB81BC810196FC
25
+:10F98000A11DB11D89839A83AB83BC8389819A8130
26
+:10F99000AB81BC8180509147A240B04060F3249677
27
+:10F9A0000FB6F894DEBF0FBECDBFDF91CF910895A3
28
+:10F9B000EF92FF920F931F93EE24FF248701289864
29
+:10F9C0008091C00087FD17C00894E11CF11C011D47
30
+:10F9D000111D81E0E81689E0F8068DE3080780E054
31
+:10F9E000180770F3E0910001F091010109958091F1
32
+:10F9F000C00087FFE9CF289A8091C600992787FD2C
33
+:10FA000090951F910F91FF90EF900895982F8091FE
34
+:10FA1000C00085FFFCCF9093C60008950E94D87C5B
35
+:10FA2000803271F0809102018F5F809302018530F6
36
+:10FA300009F00895E0910001F09101010995089500
37
+:10FA400084E10E94067D80E10E94067D0895CF93A7
38
+:10FA5000C82F0E94D87C803241F0809102018F5FD4
39
+:10FA600080930201853081F40AC084E10E94067D02
40
+:10FA70008C2F0E94067D80E10E94067D05C0E091EA
41
+:10FA80000001F09101010995CF910895282F90E090
42
+:10FA900007C08091C0008823E4F78091C6009F5F73
43
+:10FAA0009217B8F30895CFEFD0E1DEBFCDBF0000CD
44
+:10FAB00094B714BE809160008861809360001092BA
45
+:10FAC000600091FF74C189E18093C4001092C50069
46
+:10FAD00088E18093C10086E08093C2005098589AD4
47
+:10FAE000209A83E00E945D7C81E00E945D7C0E9400
48
+:10FAF000D87C8033B9F18133C1F1803409F456C028
49
+:10FB0000813409F45CC0823409F46EC0853409F490
50
+:10FB100071C0803539F1813509F4F3C0823511F1B6
51
+:10FB2000853509F4D3C0863509F4CBC0843609F491
52
+:10FB300065C0843709F4EBC0853709F4D2C0863735
53
+:10FB400009F44AC0809102018F5F809302018530E1
54
+:10FB500071F6E0910001F091010109950E94D87CB5
55
+:10FB6000803349F60E940E7DC2CF0E94D87CC82FF8
56
+:10FB7000803241F784E10E94067D81E40E94067D87
57
+:10FB800086E50E94067D82E50E94067D8C2F0E94FC
58
+:10FB9000067D89E40E94067D83E50E94067D80E55E
59
+:10FBA0000E94067D80E10E94067DA1CF0E94D87C44
60
+:10FBB0008638C0F20E94D87C0E940E7D98CF0E94A9
61
+:10FBC000D87C803809F407C1813809F400C1823833
62
+:10FBD00009F4F9C0883921F080E00E94277D87CFA1
63
+:10FBE00083E00E94277D83CF84E10E94467D0E94AE
64
+:10FBF0000E7D7DCF85E00E94467DF9CF0E94D87CA6
65
+:10FC0000809306020E94D87C8093050280910802AE
66
+:10FC10008E7F809308020E94D87C853409F44BC003
67
+:10FC2000E5E0F1E0119281E0E438F807D9F3D0F390
68
+:10FC3000C0E0D0E0809105029091060218161906E6
69
+:10FC400078F405E011E00E94D87CF80181938F01DF
70
+:10FC500021968091050290910602C817D90798F362
71
+:10FC60000E94D87C803209F06DCF8091080280FF1D
72
+:10FC7000B6C0C0E0D0E02091050230910602121615
73
+:10FC80001306B8F4E0910301F0910401A5E0B1E09E
74
+:10FC9000F999FECFF2BDE1BD8D9180BDFA9AF99A36
75
+:10FCA00031962196C217D30798F3F0930401E0939D
76
+:10FCB000030184E175CF809108028160809308027E
77
+:10FCC000AFCF84E00E94467D80E087CF0E94D87C41
78
+:10FCD000809303010E94D87C809304010E940E7DD2
79
+:10FCE00006CF0E94D87C803209F02CCF84E10E949C
80
+:10FCF000067D8EE10E94067D86E90E94067D8AE0EF
81
+:10FD00004FCF0E940E7D88E080936000FFCF0E945D
82
+:10FD1000D87C809306020E94D87C809305020E94C2
83
+:10FD2000D87C853409F449C0809108028E7F809385
84
+:10FD300008028091030190910401880F991F90930C
85
+:10FD40000401809303010E94D87C803209F0CFCE59
86
+:10FD500084E10E94067DC0E0D0E020910502309150
87
+:10FD600006021216130608F01DCFE0910301F09170
88
+:10FD700004018091080280FF96C0F999FECFF2BD80
89
+:10FD8000E1BDF89A80B50E94067DE0910301F091F3
90
+:10FD900004013196F0930401E093030120910502E0
91
+:10FDA000309106022196C217D30718F3FBCEE091DB
92
+:10FDB0000001F0910101099586CE809108028160D1
93
+:10FDC00080930802C0CF80E10E94277D90CE81E021
94
+:10FDD0000E94277D8CCE82E00E94277D88CE809174
95
+:10FDE000030190910401880F991F9093040180935F
96
+:10FDF00003018091050280FF09C080910502909166
97
+:10FE0000060201969093060280930502F999FECFAF
98
+:10FE10001127E0910301F0910401C5E0D1E0809148
99
+:10FE2000050290910602103091F400915700017084
100
+:10FE30000130D9F303E000935700E8950091570093
101
+:10FE400001700130D9F301E100935700E895099062
102
+:10FE500019900091570001700130D9F301E000932F
103
+:10FE60005700E8951395103898F011270091570026
104
+:10FE700001700130D9F305E000935700E895009137
105
+:10FE8000570001700130D9F301E100935700E89564
106
+:10FE90003296029709F0C7CF103011F00296E5CFE5
107
+:10FEA000112484E17DCE869580FF06C03196F093C3
108
+:10FEB0000401E093030176CF84910E94067D209196
109
+:10FEC000050230910602E0910301F0910401EECFAA
110
+:10FED0001F93CF930E94D87CC82F0E94067D0E945A
111
+:10FEE000D87C182F0E94067DC1362CF0C7551136DC
112
+:10FEF0003CF0175508C0C033D4F3C0531136CCF7CB
113
+:10FF000010330CF01053C295C07FC10F8C2F99276E
114
+:10FF100087FD9095CF911F910895CF93282F992712
115
+:10FF200087FD9095807F907095958795959587959D
116
+:10FF300095958795959587958A303CF0895AC22F7B
117
+:10FF4000CF70CA303CF0C95A06C0805DC22FCF7056
118
+:10FF5000CA30CCF7C05D0E94067D8C2F0E94067DC2
119
+:06FF6000CF910895FFCFD0
120
+:040000030000F80001
121
+:00000001FF

+ 56
- 0
Marlin/Marlin/Sanguino/bootloaders/atmega644p/Makefile Переглянути файл

1
+# Makefile for ATmegaBOOT
2
+# E.Lins, 18.7.2005
3
+# $Id$
4
+
5
+
6
+# program name should not be changed...
7
+PROGRAM    = ATmegaBOOT_644P
8
+
9
+# enter the target CPU frequency
10
+AVR_FREQ   = 16000000L
11
+
12
+MCU_TARGET = atmega644p
13
+LDSECTION  = --section-start=.text=0xF800
14
+
15
+OBJ        = $(PROGRAM).o
16
+OPTIMIZE   = -O2
17
+
18
+DEFS       = 
19
+LIBS       = 
20
+
21
+CC         = avr-gcc
22
+
23
+
24
+# Override is only needed by avr-lib build system.
25
+
26
+override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
27
+override LDFLAGS       = -Wl,$(LDSECTION)
28
+#override LDFLAGS       = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
29
+
30
+OBJCOPY        = avr-objcopy
31
+OBJDUMP        = avr-objdump
32
+
33
+all: CFLAGS += '-DMAX_TIME_COUNT=8000000L>>1' -DADABOOT
34
+all: $(PROGRAM).hex
35
+
36
+$(PROGRAM).hex: $(PROGRAM).elf
37
+	$(OBJCOPY) -j .text -j .data -O ihex $< $@
38
+	
39
+$(PROGRAM).elf: $(OBJ)
40
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
41
+	
42
+$(OBJ): ATmegaBOOT.c
43
+	avr-gcc $(CFLAGS) $(LDFLAGS) -c -g -O2 -Wall -mmcu=$(MCU_TARGET) ATmegaBOOT.c -o $(PROGRAM).o
44
+
45
+%.lst: %.elf
46
+	$(OBJDUMP) -h -S $< > $@
47
+
48
+%.srec: %.elf
49
+	$(OBJCOPY) -j .text -j .data -O srec $< $@
50
+
51
+%.bin: %.elf
52
+	$(OBJCOPY) -j .text -j .data -O binary $< $@
53
+
54
+clean:
55
+	rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
56
+	

+ 3
- 0
Marlin/Marlin/Sanguino/bootloaders/atmega644p/README.txt Переглянути файл

1
+Note: This bootloader support ATmega644, ATmega644P and ATmega324P.
2
+To build, set PROGRAM and MCU_TARGET in the Makefile according to your target device.
3
+

+ 135
- 0
Marlin/Marlin/Sanguino/cores/arduino/Copy of wiring.h Переглянути файл

1
+/*
2
+  wiring.h - Partial implementation of the Wiring API for the ATmega8.
3
+  Part of Arduino - http://www.arduino.cc/
4
+
5
+  Copyright (c) 2005-2006 David A. Mellis
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General
18
+  Public License along with this library; if not, write to the
19
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+  Boston, MA  02111-1307  USA
21
+
22
+  $Id$
23
+*/
24
+
25
+#ifndef Wiring_h
26
+#define Wiring_h
27
+
28
+#include <avr/io.h>
29
+#include <stdlib.h>
30
+#include "binary.h"
31
+
32
+#ifdef __cplusplus
33
+extern "C"{
34
+#endif
35
+
36
+#define HIGH 0x1
37
+#define LOW  0x0
38
+
39
+#define INPUT 0x0
40
+#define OUTPUT 0x1
41
+
42
+#define true 0x1
43
+#define false 0x0
44
+
45
+#define PI 3.1415926535897932384626433832795
46
+#define HALF_PI 1.5707963267948966192313216916398
47
+#define TWO_PI 6.283185307179586476925286766559
48
+#define DEG_TO_RAD 0.017453292519943295769236907684886
49
+#define RAD_TO_DEG 57.295779513082320876798154814105
50
+
51
+#define SERIAL  0x0
52
+#define DISPLAY 0x1
53
+
54
+#define LSBFIRST 0
55
+#define MSBFIRST 1
56
+
57
+#define CHANGE 1
58
+#define FALLING 2
59
+#define RISING 3
60
+
61
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
62
+#define INTERNAL1V1 2
63
+#define INTERNAL2V56 3
64
+#else
65
+#define INTERNAL 3
66
+#endif
67
+#define DEFAULT 1
68
+#define EXTERNAL 0
69
+
70
+// undefine stdlib's abs if encountered
71
+#ifdef abs
72
+#undef abs
73
+#endif
74
+
75
+#define min(a,b) ((a)<(b)?(a):(b))
76
+#define max(a,b) ((a)>(b)?(a):(b))
77
+#define abs(x) ((x)>0?(x):-(x))
78
+#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
79
+#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
80
+#define radians(deg) ((deg)*DEG_TO_RAD)
81
+#define degrees(rad) ((rad)*RAD_TO_DEG)
82
+#define sq(x) ((x)*(x))
83
+
84
+#define interrupts() sei()
85
+#define noInterrupts() cli()
86
+
87
+#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
88
+#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
89
+#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
90
+
91
+#define lowByte(w) ((uint8_t) ((w) & 0xff))
92
+#define highByte(w) ((uint8_t) ((w) >> 8))
93
+
94
+#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
95
+#define bitSet(value, bit) ((value) |= (1UL << (bit)))
96
+#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
97
+#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
98
+
99
+
100
+typedef unsigned int word;
101
+
102
+#define bit(b) (1UL << (b))
103
+
104
+typedef uint8_t boolean;
105
+typedef uint8_t byte;
106
+
107
+void init(void);
108
+
109
+void pinMode(uint8_t, uint8_t);
110
+void digitalWrite(uint8_t, uint8_t);
111
+int digitalRead(uint8_t);
112
+int analogRead(uint8_t);
113
+void analogReference(uint8_t mode);
114
+void analogWrite(uint8_t, int);
115
+
116
+unsigned long millis(void);
117
+unsigned long micros(void);
118
+void delay(unsigned long);
119
+void delayMicroseconds(unsigned int us);
120
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
121
+
122
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
123
+uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
124
+
125
+void attachInterrupt(uint8_t, void (*)(void), int mode);
126
+void detachInterrupt(uint8_t);
127
+
128
+void setup(void);
129
+void loop(void);
130
+
131
+#ifdef __cplusplus
132
+} // extern "C"
133
+#endif
134
+
135
+#endif

+ 187
- 0
Marlin/Marlin/Sanguino/cores/arduino/HardwareSerial.cpp Переглянути файл

1
+/*
2
+  HardwareSerial.cpp - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right 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
+  Modified 23 November 2006 by David A. Mellis
20
+  Modified 28 September 2010 by Mark Sproul
21
+*/
22
+
23
+#include <stdlib.h>
24
+#include <stdio.h>
25
+#include <string.h>
26
+#include <inttypes.h>
27
+#include "wiring.h"
28
+#include "wiring_private.h"
29
+
30
+// this next line disables the entire HardwareSerial.cpp, 
31
+// this is so I can support Attiny series and any other chip without a uart
32
+#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
33
+
34
+#include "HardwareSerial.h"
35
+
36
+// Define constants and variables for buffering incoming serial data.  We're
37
+// using a ring buffer (I think), in which rx_buffer_head is the index of the
38
+// location to which to write the next incoming character and rx_buffer_tail
39
+// is the index of the location from which to read.
40
+#define RX_BUFFER_SIZE 128
41
+
42
+struct ring_buffer
43
+{
44
+  unsigned char buffer[RX_BUFFER_SIZE];
45
+  int head;
46
+  int tail;
47
+};
48
+
49
+ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
50
+
51
+inline void store_char(unsigned char c, ring_buffer *rx_buffer)
52
+{
53
+  int i = (unsigned int)(rx_buffer->head + 1) & (RX_BUFFER_SIZE -1);
54
+
55
+  // if we should be storing the received character into the location
56
+  // just before the tail (meaning that the head would advance to the
57
+  // current location of the tail), we're about to overflow the buffer
58
+  // and so we don't write the character or advance the head.
59
+  if (i != rx_buffer->tail) {
60
+    rx_buffer->buffer[rx_buffer->head] = c;
61
+    rx_buffer->head = i;
62
+  }
63
+}
64
+
65
+// fixed by Mark Sproul this is on the 644/644p
66
+//SIGNAL(SIG_USART_RECV)
67
+SIGNAL(USART0_RX_vect)
68
+{
69
+  unsigned char c  =  UDR0;
70
+  store_char(c, &rx_buffer);
71
+}
72
+
73
+
74
+// Constructors ////////////////////////////////////////////////////////////////
75
+
76
+HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
77
+  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
78
+  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
79
+  volatile uint8_t *udr,
80
+  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
81
+{
82
+  _rx_buffer = rx_buffer;
83
+  _ubrrh = ubrrh;
84
+  _ubrrl = ubrrl;
85
+  _ucsra = ucsra;
86
+  _ucsrb = ucsrb;
87
+  _udr = udr;
88
+  _rxen = rxen;
89
+  _txen = txen;
90
+  _rxcie = rxcie;
91
+  _udre = udre;
92
+  _u2x = u2x;
93
+}
94
+
95
+// Public Methods //////////////////////////////////////////////////////////////
96
+
97
+void HardwareSerial::begin(long baud)
98
+{
99
+  uint16_t baud_setting;
100
+  bool use_u2x = true;
101
+
102
+#if F_CPU == 16000000UL
103
+  // hardcoded exception for compatibility with the bootloader shipped
104
+  // with the Duemilanove and previous boards and the firmware on the 8U2
105
+  // on the Uno and Mega 2560.
106
+  if (baud == 57600) {
107
+    use_u2x = false;
108
+  }
109
+#endif
110
+  
111
+  if (use_u2x) {
112
+    *_ucsra = 1 << _u2x;
113
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
114
+  } else {
115
+    *_ucsra = 0;
116
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
117
+  }
118
+
119
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
120
+  *_ubrrh = baud_setting >> 8;
121
+  *_ubrrl = baud_setting;
122
+
123
+  sbi(*_ucsrb, _rxen);
124
+  sbi(*_ucsrb, _txen);
125
+  sbi(*_ucsrb, _rxcie);
126
+}
127
+
128
+void HardwareSerial::end()
129
+{
130
+  cbi(*_ucsrb, _rxen);
131
+  cbi(*_ucsrb, _txen);
132
+  cbi(*_ucsrb, _rxcie);  
133
+}
134
+
135
+int HardwareSerial::available(void)
136
+{
137
+  return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) & (RX_BUFFER_SIZE-1);
138
+}
139
+
140
+int HardwareSerial::peek(void)
141
+{
142
+  if (_rx_buffer->head == _rx_buffer->tail) {
143
+    return -1;
144
+  } else {
145
+    return _rx_buffer->buffer[_rx_buffer->tail];
146
+  }
147
+}
148
+
149
+int HardwareSerial::read(void)
150
+{
151
+  // if the head isn't ahead of the tail, we don't have any characters
152
+  if (_rx_buffer->head == _rx_buffer->tail) {
153
+    return -1;
154
+  } else {
155
+    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
156
+    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) & (RX_BUFFER_SIZE-1);
157
+    return c;
158
+  }
159
+}
160
+
161
+void HardwareSerial::flush()
162
+{
163
+  // don't reverse this or there may be problems if the RX interrupt
164
+  // occurs after reading the value of rx_buffer_head but before writing
165
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
166
+  // may be written to rx_buffer_tail, making it appear as if the buffer
167
+  // don't reverse this or there may be problems if the RX interrupt
168
+  // occurs after reading the value of rx_buffer_head but before writing
169
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
170
+  // may be written to rx_buffer_tail, making it appear as if the buffer
171
+  // were full, not empty.
172
+  _rx_buffer->head = _rx_buffer->tail;
173
+}
174
+
175
+void HardwareSerial::write(uint8_t c)
176
+{
177
+  while (!((*_ucsra) & (1 << _udre)))
178
+    ;
179
+
180
+  *_udr = c;
181
+}
182
+
183
+// Preinstantiate Objects //////////////////////////////////////////////////////
184
+HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
185
+
186
+#endif // whole file
187
+

+ 76
- 0
Marlin/Marlin/Sanguino/cores/arduino/HardwareSerial.h Переглянути файл

1
+/*
2
+  HardwareSerial.h - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right 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
+  Modified 28 September 2010 by Mark Sproul
20
+*/
21
+
22
+#ifndef HardwareSerial_h
23
+#define HardwareSerial_h
24
+
25
+#include <inttypes.h>
26
+
27
+#include "Stream.h"
28
+
29
+struct ring_buffer;
30
+
31
+class HardwareSerial : public Stream
32
+{
33
+  private:
34
+    ring_buffer *_rx_buffer;
35
+    volatile uint8_t *_ubrrh;
36
+    volatile uint8_t *_ubrrl;
37
+    volatile uint8_t *_ucsra;
38
+    volatile uint8_t *_ucsrb;
39
+    volatile uint8_t *_udr;
40
+    uint8_t _rxen;
41
+    uint8_t _txen;
42
+    uint8_t _rxcie;
43
+    uint8_t _udre;
44
+    uint8_t _u2x;
45
+  public:
46
+    HardwareSerial(ring_buffer *rx_buffer,
47
+      volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
48
+      volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
49
+      volatile uint8_t *udr,
50
+      uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
51
+    void begin(long);
52
+    void end();
53
+    virtual int available(void);
54
+    virtual int peek(void);
55
+    virtual int read(void);
56
+    virtual void flush(void);
57
+    virtual void write(uint8_t);
58
+    using Print::write; // pull in write(str) and write(buf, size) from Print
59
+};
60
+
61
+#if defined(UBRRH) || defined(UBRR0H)
62
+  extern HardwareSerial Serial;
63
+#elif defined(USBCON)
64
+  #include "usb_api.h"
65
+#endif
66
+#if defined(UBRR1H)
67
+  extern HardwareSerial Serial1;
68
+#endif
69
+#if defined(UBRR2H)
70
+  extern HardwareSerial Serial2;
71
+#endif
72
+#if defined(UBRR3H)
73
+  extern HardwareSerial Serial3;
74
+#endif
75
+
76
+#endif

+ 220
- 0
Marlin/Marlin/Sanguino/cores/arduino/Print.cpp Переглянути файл

1
+/*
2
+ Print.cpp - Base class that provides print() and println()
3
+ Copyright (c) 2008 David A. Mellis.  All right 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
+ Modified 23 November 2006 by David A. Mellis
20
+ */
21
+
22
+#include <stdlib.h>
23
+#include <stdio.h>
24
+#include <string.h>
25
+#include <math.h>
26
+#include "wiring.h"
27
+
28
+#include "Print.h"
29
+
30
+// Public Methods //////////////////////////////////////////////////////////////
31
+
32
+/* default implementation: may be overridden */
33
+void Print::write(const char *str)
34
+{
35
+  while (*str)
36
+    write(*str++);
37
+}
38
+
39
+/* default implementation: may be overridden */
40
+void Print::write(const uint8_t *buffer, size_t size)
41
+{
42
+  while (size--)
43
+    write(*buffer++);
44
+}
45
+
46
+void Print::print(const String &s)
47
+{
48
+  for (int i = 0; i < s.length(); i++) {
49
+    write(s[i]);
50
+  }
51
+}
52
+
53
+void Print::print(const char str[])
54
+{
55
+  write(str);
56
+}
57
+
58
+void Print::print(char c, int base)
59
+{
60
+  print((long) c, base);
61
+}
62
+
63
+void Print::print(unsigned char b, int base)
64
+{
65
+  print((unsigned long) b, base);
66
+}
67
+
68
+void Print::print(int n, int base)
69
+{
70
+  print((long) n, base);
71
+}
72
+
73
+void Print::print(unsigned int n, int base)
74
+{
75
+  print((unsigned long) n, base);
76
+}
77
+
78
+void Print::print(long n, int base)
79
+{
80
+  if (base == 0) {
81
+    write(n);
82
+  } else if (base == 10) {
83
+    if (n < 0) {
84
+      print('-');
85
+      n = -n;
86
+    }
87
+    printNumber(n, 10);
88
+  } else {
89
+    printNumber(n, base);
90
+  }
91
+}
92
+
93
+void Print::print(unsigned long n, int base)
94
+{
95
+  if (base == 0) write(n);
96
+  else printNumber(n, base);
97
+}
98
+
99
+void Print::print(double n, int digits)
100
+{
101
+  printFloat(n, digits);
102
+}
103
+
104
+void Print::println(void)
105
+{
106
+  print('\r');
107
+  print('\n');  
108
+}
109
+
110
+void Print::println(const String &s)
111
+{
112
+  print(s);
113
+  println();
114
+}
115
+
116
+void Print::println(const char c[])
117
+{
118
+  print(c);
119
+  println();
120
+}
121
+
122
+void Print::println(char c, int base)
123
+{
124
+  print(c, base);
125
+  println();
126
+}
127
+
128
+void Print::println(unsigned char b, int base)
129
+{
130
+  print(b, base);
131
+  println();
132
+}
133
+
134
+void Print::println(int n, int base)
135
+{
136
+  print(n, base);
137
+  println();
138
+}
139
+
140
+void Print::println(unsigned int n, int base)
141
+{
142
+  print(n, base);
143
+  println();
144
+}
145
+
146
+void Print::println(long n, int base)
147
+{
148
+  print(n, base);
149
+  println();
150
+}
151
+
152
+void Print::println(unsigned long n, int base)
153
+{
154
+  print(n, base);
155
+  println();
156
+}
157
+
158
+void Print::println(double n, int digits)
159
+{
160
+  print(n, digits);
161
+  println();
162
+}
163
+
164
+// Private Methods /////////////////////////////////////////////////////////////
165
+
166
+void Print::printNumber(unsigned long n, uint8_t base)
167
+{
168
+  unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
169
+  unsigned long i = 0;
170
+
171
+  if (n == 0) {
172
+    print('0');
173
+    return;
174
+  } 
175
+
176
+  while (n > 0) {
177
+    buf[i++] = n % base;
178
+    n /= base;
179
+  }
180
+
181
+  for (; i > 0; i--)
182
+    print((char) (buf[i - 1] < 10 ?
183
+      '0' + buf[i - 1] :
184
+      'A' + buf[i - 1] - 10));
185
+}
186
+
187
+void Print::printFloat(double number, uint8_t digits) 
188
+{ 
189
+  // Handle negative numbers
190
+  if (number < 0.0)
191
+  {
192
+     print('-');
193
+     number = -number;
194
+  }
195
+
196
+  // Round correctly so that print(1.999, 2) prints as "2.00"
197
+  double rounding = 0.5;
198
+  for (uint8_t i=0; i<digits; ++i)
199
+    rounding /= 10.0;
200
+  
201
+  number += rounding;
202
+
203
+  // Extract the integer part of the number and print it
204
+  unsigned long int_part = (unsigned long)number;
205
+  double remainder = number - (double)int_part;
206
+  print(int_part);
207
+
208
+  // Print the decimal point, but only if there are digits beyond
209
+  if (digits > 0)
210
+    print("."); 
211
+
212
+  // Extract digits from the remainder one at a time
213
+  while (digits-- > 0)
214
+  {
215
+    remainder *= 10.0;
216
+    int toPrint = int(remainder);
217
+    print(toPrint);
218
+    remainder -= toPrint; 
219
+  } 
220
+}

+ 66
- 0
Marlin/Marlin/Sanguino/cores/arduino/Print.h Переглянути файл

1
+/*
2
+  Print.h - Base class that provides print() and println()
3
+  Copyright (c) 2008 David A. Mellis.  All right 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 Print_h
21
+#define Print_h
22
+
23
+#include <inttypes.h>
24
+#include <stdio.h> // for size_t
25
+
26
+#include "WString.h"
27
+
28
+#define DEC 10
29
+#define HEX 16
30
+#define OCT 8
31
+#define BIN 2
32
+#define BYTE 0
33
+
34
+class Print
35
+{
36
+  private:
37
+    void printNumber(unsigned long, uint8_t);
38
+    void printFloat(double, uint8_t);
39
+  public:
40
+    virtual void write(uint8_t) = 0;
41
+    virtual void write(const char *str);
42
+    virtual void write(const uint8_t *buffer, size_t size);
43
+    
44
+    void print(const String &);
45
+    void print(const char[]);
46
+    void print(char, int = BYTE);
47
+    void print(unsigned char, int = BYTE);
48
+    void print(int, int = DEC);
49
+    void print(unsigned int, int = DEC);
50
+    void print(long, int = DEC);
51
+    void print(unsigned long, int = DEC);
52
+    void print(double, int = 2);
53
+
54
+    void println(const String &s);
55
+    void println(const char[]);
56
+    void println(char, int = BYTE);
57
+    void println(unsigned char, int = BYTE);
58
+    void println(int, int = DEC);
59
+    void println(unsigned int, int = DEC);
60
+    void println(long, int = DEC);
61
+    void println(unsigned long, int = DEC);
62
+    void println(double, int = 2);
63
+    void println(void);
64
+};
65
+
66
+#endif

+ 35
- 0
Marlin/Marlin/Sanguino/cores/arduino/Stream.h Переглянути файл

1
+/*
2
+  Stream.h - base class for character-based streams.
3
+  Copyright (c) 2010 David A. Mellis.  All right 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 Stream_h
21
+#define Stream_h
22
+
23
+#include <inttypes.h>
24
+#include "Print.h"
25
+
26
+class Stream : public Print
27
+{
28
+  public:
29
+    virtual int available() = 0;
30
+    virtual int read() = 0;
31
+    virtual int peek() = 0;
32
+    virtual void flush() = 0;
33
+};
34
+
35
+#endif

+ 601
- 0
Marlin/Marlin/Sanguino/cores/arduino/Tone.cpp Переглянути файл

1
+/* Tone.cpp
2
+
3
+  A Tone Generator Library
4
+
5
+  Written by Brett Hagman
6
+
7
+  This library is free software; you can redistribute it and/or
8
+  modify it under the terms of the GNU Lesser General Public
9
+  License as published by the Free Software Foundation; either
10
+  version 2.1 of the License, or (at your option) any later version.
11
+
12
+  This library is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+  Lesser General Public License for more details.
16
+
17
+  You should have received a copy of the GNU Lesser General Public
18
+  License along with this library; if not, write to the Free Software
19
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
+
21
+Version Modified By Date     Comments
22
+------- ----------- -------- --------
23
+0001    B Hagman    09/08/02 Initial coding
24
+0002    B Hagman    09/08/18 Multiple pins
25
+0003    B Hagman    09/08/18 Moved initialization from constructor to begin()
26
+0004    B Hagman    09/09/26 Fixed problems with ATmega8
27
+0005    B Hagman    09/11/23 Scanned prescalars for best fit on 8 bit timers
28
+                    09/11/25 Changed pin toggle method to XOR
29
+                    09/11/25 Fixed timer0 from being excluded
30
+0006    D Mellis    09/12/29 Replaced objects with functions
31
+0007    M Sproul    10/08/29 Changed #ifdefs from cpu to register
32
+*************************************************/
33
+
34
+#include <avr/interrupt.h>
35
+#include <avr/pgmspace.h>
36
+#include "wiring.h"
37
+#include "pins_arduino.h"
38
+
39
+#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
40
+#define TCCR2A TCCR2
41
+#define TCCR2B TCCR2
42
+#define COM2A1 COM21
43
+#define COM2A0 COM20
44
+#define OCR2A OCR2
45
+#define TIMSK2 TIMSK
46
+#define OCIE2A OCIE2
47
+#define TIMER2_COMPA_vect TIMER2_COMP_vect
48
+#define TIMSK1 TIMSK
49
+#endif
50
+
51
+// timerx_toggle_count:
52
+//  > 0 - duration specified
53
+//  = 0 - stopped
54
+//  < 0 - infinitely (until stop() method called, or new play() called)
55
+
56
+#if !defined(__AVR_ATmega8__)
57
+volatile long timer0_toggle_count;
58
+volatile uint8_t *timer0_pin_port;
59
+volatile uint8_t timer0_pin_mask;
60
+#endif
61
+
62
+volatile long timer1_toggle_count;
63
+volatile uint8_t *timer1_pin_port;
64
+volatile uint8_t timer1_pin_mask;
65
+volatile long timer2_toggle_count;
66
+volatile uint8_t *timer2_pin_port;
67
+volatile uint8_t timer2_pin_mask;
68
+
69
+#if defined(TIMSK3)
70
+volatile long timer3_toggle_count;
71
+volatile uint8_t *timer3_pin_port;
72
+volatile uint8_t timer3_pin_mask;
73
+#endif
74
+
75
+#if defined(TIMSK4)
76
+volatile long timer4_toggle_count;
77
+volatile uint8_t *timer4_pin_port;
78
+volatile uint8_t timer4_pin_mask;
79
+#endif
80
+
81
+#if defined(TIMSK5)
82
+volatile long timer5_toggle_count;
83
+volatile uint8_t *timer5_pin_port;
84
+volatile uint8_t timer5_pin_mask;
85
+#endif
86
+
87
+
88
+// MLS: This does not make sense, the 3 options are the same
89
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
90
+
91
+#define AVAILABLE_TONE_PINS 1
92
+
93
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
94
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
95
+
96
+#elif defined(__AVR_ATmega8__)
97
+
98
+#define AVAILABLE_TONE_PINS 1
99
+
100
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ };
101
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
102
+
103
+#else
104
+
105
+#define AVAILABLE_TONE_PINS 1
106
+
107
+// Leave timer 0 to last.
108
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
109
+static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255 */ };
110
+
111
+#endif
112
+
113
+
114
+
115
+static int8_t toneBegin(uint8_t _pin)
116
+{
117
+  int8_t _timer = -1;
118
+
119
+  // if we're already using the pin, the timer should be configured.  
120
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
121
+    if (tone_pins[i] == _pin) {
122
+      return pgm_read_byte(tone_pin_to_timer_PGM + i);
123
+    }
124
+  }
125
+  
126
+  // search for an unused timer.
127
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
128
+    if (tone_pins[i] == 255) {
129
+      tone_pins[i] = _pin;
130
+      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
131
+      break;
132
+    }
133
+  }
134
+  
135
+  if (_timer != -1)
136
+  {
137
+    // Set timer specific stuff
138
+    // All timers in CTC mode
139
+    // 8 bit timers will require changing prescalar values,
140
+    // whereas 16 bit timers are set to either ck/1 or ck/64 prescalar
141
+    switch (_timer)
142
+    {
143
+      #if defined(TCCR0A) && defined(TCCR0B)
144
+      case 0:
145
+        // 8 bit timer
146
+        TCCR0A = 0;
147
+        TCCR0B = 0;
148
+        bitWrite(TCCR0A, WGM01, 1);
149
+        bitWrite(TCCR0B, CS00, 1);
150
+        timer0_pin_port = portOutputRegister(digitalPinToPort(_pin));
151
+        timer0_pin_mask = digitalPinToBitMask(_pin);
152
+        break;
153
+      #endif
154
+
155
+      #if defined(TCCR1A) && defined(TCCR1B) && defined(WGM12)
156
+      case 1:
157
+        // 16 bit timer
158
+        TCCR1A = 0;
159
+        TCCR1B = 0;
160
+        bitWrite(TCCR1B, WGM12, 1);
161
+        bitWrite(TCCR1B, CS10, 1);
162
+        timer1_pin_port = portOutputRegister(digitalPinToPort(_pin));
163
+        timer1_pin_mask = digitalPinToBitMask(_pin);
164
+        break;
165
+      #endif
166
+
167
+      #if defined(TCCR2A) && defined(TCCR2B)
168
+      case 2:
169
+        // 8 bit timer
170
+        TCCR2A = 0;
171
+        TCCR2B = 0;
172
+        bitWrite(TCCR2A, WGM21, 1);
173
+        bitWrite(TCCR2B, CS20, 1);
174
+        timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
175
+        timer2_pin_mask = digitalPinToBitMask(_pin);
176
+        break;
177
+      #endif
178
+
179
+      #if defined(TCCR3A) && defined(TCCR3B) &&  defined(TIMSK3)
180
+      case 3:
181
+        // 16 bit timer
182
+        TCCR3A = 0;
183
+        TCCR3B = 0;
184
+        bitWrite(TCCR3B, WGM32, 1);
185
+        bitWrite(TCCR3B, CS30, 1);
186
+        timer3_pin_port = portOutputRegister(digitalPinToPort(_pin));
187
+        timer3_pin_mask = digitalPinToBitMask(_pin);
188
+        break;
189
+      #endif
190
+
191
+      #if defined(TCCR4A) && defined(TCCR4B) &&  defined(TIMSK4)
192
+      case 4:
193
+        // 16 bit timer
194
+        TCCR4A = 0;
195
+        TCCR4B = 0;
196
+        #if defined(WGM42)
197
+          bitWrite(TCCR4B, WGM42, 1);
198
+        #elif defined(CS43)
199
+          #warning this may not be correct
200
+          // atmega32u4
201
+          bitWrite(TCCR4B, CS43, 1);
202
+        #endif
203
+        bitWrite(TCCR4B, CS40, 1);
204
+        timer4_pin_port = portOutputRegister(digitalPinToPort(_pin));
205
+        timer4_pin_mask = digitalPinToBitMask(_pin);
206
+        break;
207
+      #endif
208
+
209
+      #if defined(TCCR5A) && defined(TCCR5B) &&  defined(TIMSK5)
210
+      case 5:
211
+        // 16 bit timer
212
+        TCCR5A = 0;
213
+        TCCR5B = 0;
214
+        bitWrite(TCCR5B, WGM52, 1);
215
+        bitWrite(TCCR5B, CS50, 1);
216
+        timer5_pin_port = portOutputRegister(digitalPinToPort(_pin));
217
+        timer5_pin_mask = digitalPinToBitMask(_pin);
218
+        break;
219
+      #endif
220
+    }
221
+  }
222
+
223
+  return _timer;
224
+}
225
+
226
+
227
+
228
+// frequency (in hertz) and duration (in milliseconds).
229
+
230
+void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
231
+{
232
+  uint8_t prescalarbits = 0b001;
233
+  long toggle_count = 0;
234
+  uint32_t ocr = 0;
235
+  int8_t _timer;
236
+
237
+  _timer = toneBegin(_pin);
238
+
239
+  if (_timer >= 0)
240
+  {
241
+    // Set the pinMode as OUTPUT
242
+    pinMode(_pin, OUTPUT);
243
+    
244
+    // if we are using an 8 bit timer, scan through prescalars to find the best fit
245
+    if (_timer == 0 || _timer == 2)
246
+    {
247
+      ocr = F_CPU / frequency / 2 - 1;
248
+      prescalarbits = 0b001;  // ck/1: same for both timers
249
+      if (ocr > 255)
250
+      {
251
+        ocr = F_CPU / frequency / 2 / 8 - 1;
252
+        prescalarbits = 0b010;  // ck/8: same for both timers
253
+
254
+        if (_timer == 2 && ocr > 255)
255
+        {
256
+          ocr = F_CPU / frequency / 2 / 32 - 1;
257
+          prescalarbits = 0b011;
258
+        }
259
+
260
+        if (ocr > 255)
261
+        {
262
+          ocr = F_CPU / frequency / 2 / 64 - 1;
263
+          prescalarbits = _timer == 0 ? 0b011 : 0b100;
264
+
265
+          if (_timer == 2 && ocr > 255)
266
+          {
267
+            ocr = F_CPU / frequency / 2 / 128 - 1;
268
+            prescalarbits = 0b101;
269
+          }
270
+
271
+          if (ocr > 255)
272
+          {
273
+            ocr = F_CPU / frequency / 2 / 256 - 1;
274
+            prescalarbits = _timer == 0 ? 0b100 : 0b110;
275
+            if (ocr > 255)
276
+            {
277
+              // can't do any better than /1024
278
+              ocr = F_CPU / frequency / 2 / 1024 - 1;
279
+              prescalarbits = _timer == 0 ? 0b101 : 0b111;
280
+            }
281
+          }
282
+        }
283
+      }
284
+
285
+#if defined(TCCR0B)
286
+      if (_timer == 0)
287
+      {
288
+        TCCR0B = prescalarbits;
289
+      }
290
+      else
291
+#endif
292
+#if defined(TCCR2B)
293
+      {
294
+        TCCR2B = prescalarbits;
295
+      }
296
+#else
297
+      {
298
+        // dummy place holder to make the above ifdefs work
299
+      }
300
+#endif
301
+    }
302
+    else
303
+    {
304
+      // two choices for the 16 bit timers: ck/1 or ck/64
305
+      ocr = F_CPU / frequency / 2 - 1;
306
+
307
+      prescalarbits = 0b001;
308
+      if (ocr > 0xffff)
309
+      {
310
+        ocr = F_CPU / frequency / 2 / 64 - 1;
311
+        prescalarbits = 0b011;
312
+      }
313
+
314
+      if (_timer == 1)
315
+      {
316
+#if defined(TCCR1B)
317
+        TCCR1B = (TCCR1B & 0b11111000) | prescalarbits;
318
+#endif
319
+      }
320
+#if defined(TCCR3B)
321
+      else if (_timer == 3)
322
+        TCCR3B = (TCCR3B & 0b11111000) | prescalarbits;
323
+#endif
324
+#if defined(TCCR4B)
325
+      else if (_timer == 4)
326
+        TCCR4B = (TCCR4B & 0b11111000) | prescalarbits;
327
+#endif
328
+#if defined(TCCR5B)
329
+      else if (_timer == 5)
330
+        TCCR5B = (TCCR5B & 0b11111000) | prescalarbits;
331
+#endif
332
+
333
+    }
334
+    
335
+
336
+    // Calculate the toggle count
337
+    if (duration > 0)
338
+    {
339
+      toggle_count = 2 * frequency * duration / 1000;
340
+    }
341
+    else
342
+    {
343
+      toggle_count = -1;
344
+    }
345
+
346
+    // Set the OCR for the given timer,
347
+    // set the toggle count,
348
+    // then turn on the interrupts
349
+    switch (_timer)
350
+    {
351
+
352
+#if defined(OCR0A) && defined(TIMSK0) && defined(OCIE0A)
353
+      case 0:
354
+        OCR0A = ocr;
355
+        timer0_toggle_count = toggle_count;
356
+        bitWrite(TIMSK0, OCIE0A, 1);
357
+        break;
358
+#endif
359
+
360
+      case 1:
361
+#if defined(OCR1A) && defined(TIMSK1) && defined(OCIE1A)
362
+        OCR1A = ocr;
363
+        timer1_toggle_count = toggle_count;
364
+        bitWrite(TIMSK1, OCIE1A, 1);
365
+#elif defined(OCR1A) && defined(TIMSK) && defined(OCIE1A)
366
+        // this combination is for at least the ATmega32
367
+        OCR1A = ocr;
368
+        timer1_toggle_count = toggle_count;
369
+        bitWrite(TIMSK, OCIE1A, 1);
370
+#endif
371
+        break;
372
+
373
+#if defined(OCR2A) && defined(TIMSK2) && defined(OCIE2A)
374
+      case 2:
375
+        OCR2A = ocr;
376
+        timer2_toggle_count = toggle_count;
377
+        bitWrite(TIMSK2, OCIE2A, 1);
378
+        break;
379
+#endif
380
+
381
+#if defined(TIMSK3)
382
+      case 3:
383
+        OCR3A = ocr;
384
+        timer3_toggle_count = toggle_count;
385
+        bitWrite(TIMSK3, OCIE3A, 1);
386
+        break;
387
+#endif
388
+
389
+#if defined(TIMSK4)
390
+      case 4:
391
+        OCR4A = ocr;
392
+        timer4_toggle_count = toggle_count;
393
+        bitWrite(TIMSK4, OCIE4A, 1);
394
+        break;
395
+#endif
396
+
397
+#if defined(OCR5A) && defined(TIMSK5) && defined(OCIE5A)
398
+      case 5:
399
+        OCR5A = ocr;
400
+        timer5_toggle_count = toggle_count;
401
+        bitWrite(TIMSK5, OCIE5A, 1);
402
+        break;
403
+#endif
404
+
405
+    }
406
+  }
407
+}
408
+
409
+
410
+// XXX: this function only works properly for timer 2 (the only one we use
411
+// currently).  for the others, it should end the tone, but won't restore
412
+// proper PWM functionality for the timer.
413
+void disableTimer(uint8_t _timer)
414
+{
415
+  switch (_timer)
416
+  {
417
+    case 0:
418
+      #if defined(TIMSK0)
419
+        TIMSK0 = 0;
420
+      #elif defined(TIMSK)
421
+        TIMSK = 0; // atmega32
422
+      #endif
423
+      break;
424
+
425
+#if defined(TIMSK1) && defined(OCIE1A)
426
+    case 1:
427
+      bitWrite(TIMSK1, OCIE1A, 0);
428
+      break;
429
+#endif
430
+
431
+    case 2:
432
+      #if defined(TIMSK2) && defined(OCIE2A)
433
+        bitWrite(TIMSK2, OCIE2A, 0); // disable interrupt
434
+      #endif
435
+      #if defined(TCCR2A) && defined(WGM20)
436
+        TCCR2A = (1 << WGM20);
437
+      #endif
438
+      #if defined(TCCR2B) && defined(CS22)
439
+        TCCR2B = (TCCR2B & 0b11111000) | (1 << CS22);
440
+      #endif
441
+      #if defined(OCR2A)
442
+        OCR2A = 0;
443
+      #endif
444
+      break;
445
+
446
+#if defined(TIMSK3)
447
+    case 3:
448
+      TIMSK3 = 0;
449
+      break;
450
+#endif
451
+
452
+#if defined(TIMSK4)
453
+    case 4:
454
+      TIMSK4 = 0;
455
+      break;
456
+#endif
457
+
458
+#if defined(TIMSK5)
459
+    case 5:
460
+      TIMSK5 = 0;
461
+      break;
462
+#endif
463
+  }
464
+}
465
+
466
+
467
+void noTone(uint8_t _pin)
468
+{
469
+  int8_t _timer = -1;
470
+  
471
+  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
472
+    if (tone_pins[i] == _pin) {
473
+      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
474
+      tone_pins[i] = 255;
475
+    }
476
+  }
477
+  
478
+  disableTimer(_timer);
479
+
480
+  digitalWrite(_pin, 0);
481
+}
482
+
483
+#if 0
484
+#if !defined(__AVR_ATmega8__)
485
+ISR(TIMER0_COMPA_vect)
486
+{
487
+  if (timer0_toggle_count != 0)
488
+  {
489
+    // toggle the pin
490
+    *timer0_pin_port ^= timer0_pin_mask;
491
+
492
+    if (timer0_toggle_count > 0)
493
+      timer0_toggle_count--;
494
+  }
495
+  else
496
+  {
497
+    disableTimer(0);
498
+    *timer0_pin_port &= ~(timer0_pin_mask);  // keep pin low after stop
499
+  }
500
+}
501
+#endif
502
+
503
+
504
+ISR(TIMER1_COMPA_vect)
505
+{
506
+  if (timer1_toggle_count != 0)
507
+  {
508
+    // toggle the pin
509
+    *timer1_pin_port ^= timer1_pin_mask;
510
+
511
+    if (timer1_toggle_count > 0)
512
+      timer1_toggle_count--;
513
+  }
514
+  else
515
+  {
516
+    disableTimer(1);
517
+    *timer1_pin_port &= ~(timer1_pin_mask);  // keep pin low after stop
518
+  }
519
+}
520
+#endif
521
+
522
+
523
+ISR(TIMER2_COMPA_vect)
524
+{
525
+
526
+  if (timer2_toggle_count != 0)
527
+  {
528
+    // toggle the pin
529
+    *timer2_pin_port ^= timer2_pin_mask;
530
+
531
+    if (timer2_toggle_count > 0)
532
+      timer2_toggle_count--;
533
+  }
534
+  else
535
+  {
536
+    // need to call noTone() so that the tone_pins[] entry is reset, so the
537
+    // timer gets initialized next time we call tone().
538
+    // XXX: this assumes timer 2 is always the first one used.
539
+    noTone(tone_pins[0]);
540
+//    disableTimer(2);
541
+//    *timer2_pin_port &= ~(timer2_pin_mask);  // keep pin low after stop
542
+  }
543
+}
544
+
545
+
546
+
547
+//#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
548
+#if 0
549
+
550
+ISR(TIMER3_COMPA_vect)
551
+{
552
+  if (timer3_toggle_count != 0)
553
+  {
554
+    // toggle the pin
555
+    *timer3_pin_port ^= timer3_pin_mask;
556
+
557
+    if (timer3_toggle_count > 0)
558
+      timer3_toggle_count--;
559
+  }
560
+  else
561
+  {
562
+    disableTimer(3);
563
+    *timer3_pin_port &= ~(timer3_pin_mask);  // keep pin low after stop
564
+  }
565
+}
566
+
567
+ISR(TIMER4_COMPA_vect)
568
+{
569
+  if (timer4_toggle_count != 0)
570
+  {
571
+    // toggle the pin
572
+    *timer4_pin_port ^= timer4_pin_mask;
573
+
574
+    if (timer4_toggle_count > 0)
575
+      timer4_toggle_count--;
576
+  }
577
+  else
578
+  {
579
+    disableTimer(4);
580
+    *timer4_pin_port &= ~(timer4_pin_mask);  // keep pin low after stop
581
+  }
582
+}
583
+
584
+ISR(TIMER5_COMPA_vect)
585
+{
586
+  if (timer5_toggle_count != 0)
587
+  {
588
+    // toggle the pin
589
+    *timer5_pin_port ^= timer5_pin_mask;
590
+
591
+    if (timer5_toggle_count > 0)
592
+      timer5_toggle_count--;
593
+  }
594
+  else
595
+  {
596
+    disableTimer(5);
597
+    *timer5_pin_port &= ~(timer5_pin_mask);  // keep pin low after stop
598
+  }
599
+}
600
+
601
+#endif

+ 168
- 0
Marlin/Marlin/Sanguino/cores/arduino/WCharacter.h Переглянути файл

1
+/*
2
+ WCharacter.h - Character utility functions for Wiring & Arduino
3
+ Copyright (c) 2010 Hernando Barragan.  All right 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 Character_h
21
+#define Character_h
22
+
23
+#include <ctype.h>
24
+
25
+// WCharacter.h prototypes
26
+inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
27
+inline boolean isAlpha(int c) __attribute__((always_inline));
28
+inline boolean isAscii(int c) __attribute__((always_inline));
29
+inline boolean isWhitespace(int c) __attribute__((always_inline));
30
+inline boolean isControl(int c) __attribute__((always_inline));
31
+inline boolean isDigit(int c) __attribute__((always_inline));
32
+inline boolean isGraph(int c) __attribute__((always_inline));
33
+inline boolean isLowerCase(int c) __attribute__((always_inline));
34
+inline boolean isPrintable(int c) __attribute__((always_inline));
35
+inline boolean isPunct(int c) __attribute__((always_inline));
36
+inline boolean isSpace(int c) __attribute__((always_inline));
37
+inline boolean isUpperCase(int c) __attribute__((always_inline));
38
+inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
39
+inline int toAscii(int c) __attribute__((always_inline));
40
+inline int toLowerCase(int c) __attribute__((always_inline));
41
+inline int toUpperCase(int c)__attribute__((always_inline));
42
+
43
+
44
+// Checks for an alphanumeric character. 
45
+// It is equivalent to (isalpha(c) || isdigit(c)).
46
+inline boolean isAlphaNumeric(int c) 
47
+{
48
+  return ( isalnum(c) == 0 ? false : true);
49
+}
50
+
51
+
52
+// Checks for an alphabetic character. 
53
+// It is equivalent to (isupper(c) || islower(c)).
54
+inline boolean isAlpha(int c)
55
+{
56
+  return ( isalpha(c) == 0 ? false : true);
57
+}
58
+
59
+
60
+// Checks whether c is a 7-bit unsigned char value 
61
+// that fits into the ASCII character set.
62
+inline boolean isAscii(int c)
63
+{
64
+  return ( isascii (c) == 0 ? false : true);
65
+}
66
+
67
+
68
+// Checks for a blank character, that is, a space or a tab.
69
+inline boolean isWhitespace(int c)
70
+{
71
+  return ( isblank (c) == 0 ? false : true);
72
+}
73
+
74
+
75
+// Checks for a control character.
76
+inline boolean isControl(int c)
77
+{
78
+  return ( iscntrl (c) == 0 ? false : true);
79
+}
80
+
81
+
82
+// Checks for a digit (0 through 9).
83
+inline boolean isDigit(int c)
84
+{
85
+  return ( isdigit (c) == 0 ? false : true);
86
+}
87
+
88
+
89
+// Checks for any printable character except space.
90
+inline boolean isGraph(int c)
91
+{
92
+  return ( isgraph (c) == 0 ? false : true);
93
+}
94
+
95
+
96
+// Checks for a lower-case character.
97
+inline boolean isLowerCase(int c)
98
+{
99
+  return (islower (c) == 0 ? false : true);
100
+}
101
+
102
+
103
+// Checks for any printable character including space.
104
+inline boolean isPrintable(int c)
105
+{
106
+  return ( isprint (c) == 0 ? false : true);
107
+}
108
+
109
+
110
+// Checks for any printable character which is not a space 
111
+// or an alphanumeric character.
112
+inline boolean isPunct(int c)
113
+{
114
+  return ( ispunct (c) == 0 ? false : true);
115
+}
116
+
117
+
118
+// Checks for white-space characters. For the avr-libc library, 
119
+// these are: space, formfeed ('\f'), newline ('\n'), carriage 
120
+// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
121
+inline boolean isSpace(int c)
122
+{
123
+  return ( isspace (c) == 0 ? false : true);
124
+}
125
+
126
+
127
+// Checks for an uppercase letter.
128
+inline boolean isUpperCase(int c)
129
+{
130
+  return ( isupper (c) == 0 ? false : true);
131
+}
132
+
133
+
134
+// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 
135
+// 8 9 a b c d e f A B C D E F.
136
+inline boolean isHexadecimalDigit(int c)
137
+{
138
+  return ( isxdigit (c) == 0 ? false : true);
139
+}
140
+
141
+
142
+// Converts c to a 7-bit unsigned char value that fits into the 
143
+// ASCII character set, by clearing the high-order bits.
144
+inline int toAscii(int c)
145
+{
146
+  return toascii (c);
147
+}
148
+
149
+
150
+// Warning:
151
+// Many people will be unhappy if you use this function. 
152
+// This function will convert accented letters into random 
153
+// characters.
154
+
155
+// Converts the letter c to lower case, if possible.
156
+inline int toLowerCase(int c)
157
+{
158
+  return tolower (c);
159
+}
160
+
161
+
162
+// Converts the letter c to upper case, if possible.
163
+inline int toUpperCase(int c)
164
+{
165
+  return toupper (c);
166
+}
167
+
168
+#endif

+ 1
- 0
Marlin/Marlin/Sanguino/cores/arduino/WConstants.h Переглянути файл

1
+#include "wiring.h"

+ 249
- 0
Marlin/Marlin/Sanguino/cores/arduino/WInterrupts.c Переглянути файл

1
+/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
3
+/*
4
+  Part of the Wiring project - http://wiring.uniandes.edu.co
5
+
6
+  Copyright (c) 2004-05 Hernando Barragan
7
+
8
+  This library is free software; you can redistribute it and/or
9
+  modify it under the terms of the GNU Lesser General Public
10
+  License as published by the Free Software Foundation; either
11
+  version 2.1 of the License, or (at your option) any later version.
12
+
13
+  This library is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+  Lesser General Public License for more details.
17
+
18
+  You should have received a copy of the GNU Lesser General
19
+  Public License along with this library; if not, write to the
20
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
+  Boston, MA  02111-1307  USA
22
+  
23
+  Modified 24 November 2006 by David A. Mellis
24
+  Modified 1 August 2010 by Mark Sproul
25
+*/
26
+
27
+#include <inttypes.h>
28
+#include <avr/io.h>
29
+#include <avr/interrupt.h>
30
+#include <avr/pgmspace.h>
31
+#include <stdio.h>
32
+
33
+#include "WConstants.h"
34
+#include "wiring_private.h"
35
+
36
+volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
37
+// volatile static voidFuncPtr twiIntFunc;
38
+
39
+void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
40
+  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
41
+    intFunc[interruptNum] = userFunc;
42
+    
43
+    // Configure the interrupt mode (trigger on low input, any change, rising
44
+    // edge, or falling edge).  The mode constants were chosen to correspond
45
+    // to the configuration bits in the hardware register, so we simply shift
46
+    // the mode into place.
47
+      
48
+    // Enable the interrupt.
49
+      
50
+    switch (interruptNum) {
51
+#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
52
+    case 2:
53
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
54
+      EIMSK |= (1 << INT0);
55
+      break;
56
+    case 3:
57
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
58
+      EIMSK |= (1 << INT1);
59
+      break;
60
+    case 4:
61
+      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
62
+      EIMSK |= (1 << INT2);
63
+      break;
64
+    case 5:
65
+      EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
66
+      EIMSK |= (1 << INT3);
67
+      break;
68
+    case 0:
69
+      EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
70
+      EIMSK |= (1 << INT4);
71
+      break;
72
+    case 1:
73
+      EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
74
+      EIMSK |= (1 << INT5);
75
+      break;
76
+    case 6:
77
+      EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
78
+      EIMSK |= (1 << INT6);
79
+      break;
80
+    case 7:
81
+      EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
82
+      EIMSK |= (1 << INT7);
83
+      break;
84
+#else
85
+    case 0:
86
+    #if defined(EICRA) && defined(ISC00) && defined(EIMSK)
87
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
88
+      EIMSK |= (1 << INT0);
89
+    #elif defined(MCUCR) && defined(ISC00) && defined(GICR)
90
+      MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
91
+      GICR |= (1 << INT0);
92
+    #elif defined(MCUCR) && defined(ISC00) && defined(GIMSK)
93
+      MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
94
+      GIMSK |= (1 << INT0);
95
+    #else
96
+      #error attachInterrupt not finished for this CPU (case 0)
97
+    #endif
98
+      break;
99
+
100
+    case 1:
101
+    #if defined(EICRA) && defined(ISC10) && defined(ISC11) && defined(EIMSK)
102
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
103
+      EIMSK |= (1 << INT1);
104
+    #elif defined(MCUCR) && defined(ISC10) && defined(ISC11) && defined(GICR)
105
+      MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
106
+      GICR |= (1 << INT1);
107
+    #elif defined(MCUCR) && defined(ISC10) && defined(GIMSK) && defined(GIMSK)
108
+      MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
109
+      GIMSK |= (1 << INT1);
110
+    #else
111
+      #warning attachInterrupt may need some more work for this cpu (case 1)
112
+    #endif
113
+      break;
114
+#endif
115
+    }
116
+  }
117
+}
118
+
119
+void detachInterrupt(uint8_t interruptNum) {
120
+  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
121
+    // Disable the interrupt.  (We can't assume that interruptNum is equal
122
+    // to the number of the EIMSK bit to clear, as this isn't true on the 
123
+    // ATmega8.  There, INT0 is 6 and INT1 is 7.)
124
+    switch (interruptNum) {
125
+#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
126
+    case 2:
127
+      EIMSK &= ~(1 << INT0);
128
+      break;
129
+    case 3:
130
+      EIMSK &= ~(1 << INT1);
131
+      break;
132
+    case 4:
133
+      EIMSK &= ~(1 << INT2);
134
+      break;
135
+    case 5:
136
+      EIMSK &= ~(1 << INT3);
137
+      break;
138
+    case 0:
139
+      EIMSK &= ~(1 << INT4);
140
+      break;
141
+    case 1:
142
+      EIMSK &= ~(1 << INT5);
143
+      break;
144
+    case 6:
145
+      EIMSK &= ~(1 << INT6);
146
+      break;
147
+    case 7:
148
+      EIMSK &= ~(1 << INT7);
149
+      break;
150
+#else
151
+    case 0:
152
+    #if defined(EIMSK) && defined(INT0)
153
+      EIMSK &= ~(1 << INT0);
154
+    #elif defined(GICR) && defined(ISC00)
155
+      GICR &= ~(1 << INT0); // atmega32
156
+    #elif defined(GIMSK) && defined(INT0)
157
+      GIMSK &= ~(1 << INT0);
158
+    #else
159
+      #error detachInterrupt not finished for this cpu
160
+    #endif
161
+      break;
162
+
163
+    case 1:
164
+    #if defined(EIMSK) && defined(INT1)
165
+      EIMSK &= ~(1 << INT1);
166
+    #elif defined(GICR) && defined(INT1)
167
+      GICR &= ~(1 << INT1); // atmega32
168
+    #elif defined(GIMSK) && defined(INT1)
169
+      GIMSK &= ~(1 << INT1);
170
+    #else
171
+      #warning detachInterrupt may need some more work for this cpu (case 1)
172
+    #endif
173
+      break;
174
+#endif
175
+    }
176
+      
177
+    intFunc[interruptNum] = 0;
178
+  }
179
+}
180
+
181
+/*
182
+void attachInterruptTwi(void (*userFunc)(void) ) {
183
+  twiIntFunc = userFunc;
184
+}
185
+*/
186
+
187
+#if defined(EICRA) && defined(EICRB)
188
+
189
+SIGNAL(INT0_vect) {
190
+  if(intFunc[EXTERNAL_INT_2])
191
+    intFunc[EXTERNAL_INT_2]();
192
+}
193
+
194
+SIGNAL(INT1_vect) {
195
+  if(intFunc[EXTERNAL_INT_3])
196
+    intFunc[EXTERNAL_INT_3]();
197
+}
198
+
199
+SIGNAL(INT2_vect) {
200
+  if(intFunc[EXTERNAL_INT_4])
201
+    intFunc[EXTERNAL_INT_4]();
202
+}
203
+
204
+SIGNAL(INT3_vect) {
205
+  if(intFunc[EXTERNAL_INT_5])
206
+    intFunc[EXTERNAL_INT_5]();
207
+}
208
+
209
+SIGNAL(INT4_vect) {
210
+  if(intFunc[EXTERNAL_INT_0])
211
+    intFunc[EXTERNAL_INT_0]();
212
+}
213
+
214
+SIGNAL(INT5_vect) {
215
+  if(intFunc[EXTERNAL_INT_1])
216
+    intFunc[EXTERNAL_INT_1]();
217
+}
218
+
219
+SIGNAL(INT6_vect) {
220
+  if(intFunc[EXTERNAL_INT_6])
221
+    intFunc[EXTERNAL_INT_6]();
222
+}
223
+
224
+SIGNAL(INT7_vect) {
225
+  if(intFunc[EXTERNAL_INT_7])
226
+    intFunc[EXTERNAL_INT_7]();
227
+}
228
+
229
+#else
230
+
231
+SIGNAL(INT0_vect) {
232
+  if(intFunc[EXTERNAL_INT_0])
233
+    intFunc[EXTERNAL_INT_0]();
234
+}
235
+
236
+SIGNAL(INT1_vect) {
237
+  if(intFunc[EXTERNAL_INT_1])
238
+    intFunc[EXTERNAL_INT_1]();
239
+}
240
+
241
+#endif
242
+
243
+/*
244
+SIGNAL(SIG_2WIRE_SERIAL) {
245
+  if(twiIntFunc)
246
+    twiIntFunc();
247
+}
248
+*/
249
+

+ 60
- 0
Marlin/Marlin/Sanguino/cores/arduino/WMath.cpp Переглянути файл

1
+/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
3
+/*
4
+  Part of the Wiring project - http://wiring.org.co
5
+  Copyright (c) 2004-06 Hernando Barragan
6
+  Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/
7
+  
8
+  This library is free software; you can redistribute it and/or
9
+  modify it under the terms of the GNU Lesser General Public
10
+  License as published by the Free Software Foundation; either
11
+  version 2.1 of the License, or (at your option) any later version.
12
+
13
+  This library is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+  Lesser General Public License for more details.
17
+
18
+  You should have received a copy of the GNU Lesser General
19
+  Public License along with this library; if not, write to the
20
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
+  Boston, MA  02111-1307  USA
22
+  
23
+  $Id$
24
+*/
25
+
26
+extern "C" {
27
+  #include "stdlib.h"
28
+}
29
+
30
+void randomSeed(unsigned int seed)
31
+{
32
+  if (seed != 0) {
33
+    srandom(seed);
34
+  }
35
+}
36
+
37
+long random(long howbig)
38
+{
39
+  if (howbig == 0) {
40
+    return 0;
41
+  }
42
+  return random() % howbig;
43
+}
44
+
45
+long random(long howsmall, long howbig)
46
+{
47
+  if (howsmall >= howbig) {
48
+    return howsmall;
49
+  }
50
+  long diff = howbig - howsmall;
51
+  return random(diff) + howsmall;
52
+}
53
+
54
+long map(long x, long in_min, long in_max, long out_min, long out_max)
55
+{
56
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
57
+}
58
+
59
+unsigned int makeWord(unsigned int w) { return w; }
60
+unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; }

+ 63
- 0
Marlin/Marlin/Sanguino/cores/arduino/WProgram.h Переглянути файл

1
+#ifndef WProgram_h
2
+#define WProgram_h
3
+
4
+#include <stdlib.h>
5
+#include <string.h>
6
+#include <math.h>
7
+
8
+#include <avr/interrupt.h>
9
+
10
+#include "wiring.h"
11
+
12
+#ifdef __cplusplus
13
+#include "WCharacter.h"
14
+#include "WString.h"
15
+#include "HardwareSerial.h"
16
+
17
+uint16_t makeWord(uint16_t w);
18
+uint16_t makeWord(byte h, byte l);
19
+
20
+#define word(...) makeWord(__VA_ARGS__)
21
+
22
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
23
+
24
+void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
25
+void noTone(uint8_t _pin);
26
+
27
+// WMath prototypes
28
+long random(long);
29
+long random(long, long);
30
+void randomSeed(unsigned int);
31
+long map(long, long, long, long, long);
32
+
33
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
34
+const static uint8_t A0 = 54;
35
+const static uint8_t A1 = 55;
36
+const static uint8_t A2 = 56;
37
+const static uint8_t A3 = 57;
38
+const static uint8_t A4 = 58;
39
+const static uint8_t A5 = 59;
40
+const static uint8_t A6 = 60;
41
+const static uint8_t A7 = 61;
42
+const static uint8_t A8 = 62;
43
+const static uint8_t A9 = 63;
44
+const static uint8_t A10 = 64;
45
+const static uint8_t A11 = 65;
46
+const static uint8_t A12 = 66;
47
+const static uint8_t A13 = 67;
48
+const static uint8_t A14 = 68;
49
+const static uint8_t A15 = 69;
50
+#else
51
+const static uint8_t A0 = 14;
52
+const static uint8_t A1 = 15;
53
+const static uint8_t A2 = 16;
54
+const static uint8_t A3 = 17;
55
+const static uint8_t A4 = 18;
56
+const static uint8_t A5 = 19;
57
+const static uint8_t A6 = 20;
58
+const static uint8_t A7 = 21;
59
+#endif
60
+
61
+#endif
62
+
63
+#endif

+ 443
- 0
Marlin/Marlin/Sanguino/cores/arduino/WString.cpp Переглянути файл

1
+/*
2
+  WString.cpp - String library for Wiring & Arduino
3
+  Copyright (c) 2009-10 Hernando Barragan.  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
+#include <stdlib.h>
21
+#include "WProgram.h"
22
+#include "WString.h"
23
+
24
+
25
+String::String( const char *value )
26
+{
27
+  if ( value == NULL )
28
+    value = "";
29
+  getBuffer( _length = strlen( value ) );
30
+  if ( _buffer != NULL )
31
+    strcpy( _buffer, value );
32
+}
33
+
34
+String::String( const String &value )
35
+{
36
+  getBuffer( _length = value._length );
37
+  if ( _buffer != NULL )
38
+    strcpy( _buffer, value._buffer );
39
+}
40
+
41
+String::String( const char value )
42
+{
43
+  _length = 1;
44
+  getBuffer(1);
45
+  if ( _buffer != NULL ) {
46
+    _buffer[0] = value;
47
+    _buffer[1] = 0;
48
+  }
49
+}
50
+
51
+String::String( const unsigned char value )
52
+{
53
+  _length = 1;
54
+  getBuffer(1);
55
+  if ( _buffer != NULL) {
56
+    _buffer[0] = value;
57
+    _buffer[1] = 0;
58
+  }
59
+}
60
+
61
+String::String( const int value, const int base )
62
+{
63
+  char buf[33];   
64
+  itoa((signed long)value, buf, base);
65
+  getBuffer( _length = strlen(buf) );
66
+  if ( _buffer != NULL )
67
+    strcpy( _buffer, buf );
68
+}
69
+
70
+String::String( const unsigned int value, const int base )
71
+{
72
+  char buf[33];   
73
+  ultoa((unsigned long)value, buf, base);
74
+  getBuffer( _length = strlen(buf) );
75
+  if ( _buffer != NULL )
76
+    strcpy( _buffer, buf );
77
+}
78
+
79
+String::String( const long value, const int base )
80
+{
81
+  char buf[33];   
82
+  ltoa(value, buf, base);
83
+  getBuffer( _length = strlen(buf) );
84
+  if ( _buffer != NULL )
85
+    strcpy( _buffer, buf );
86
+}
87
+
88
+String::String( const unsigned long value, const int base )
89
+{
90
+  char buf[33];   
91
+  ultoa(value, buf, 10);
92
+  getBuffer( _length = strlen(buf) );
93
+  if ( _buffer != NULL )
94
+    strcpy( _buffer, buf );
95
+}
96
+
97
+char String::charAt( unsigned int loc ) const
98
+{
99
+  return operator[]( loc );
100
+}
101
+
102
+void String::setCharAt( unsigned int loc, const char aChar ) 
103
+{
104
+  if(_buffer == NULL) return;
105
+  if(_length > loc) {
106
+    _buffer[loc] = aChar;
107
+  }
108
+}
109
+
110
+int String::compareTo( const String &s2 ) const
111
+{
112
+  return strcmp( _buffer, s2._buffer );
113
+}
114
+
115
+const String & String::concat( const String &s2 )
116
+{
117
+  return (*this) += s2;
118
+}
119
+
120
+const String & String::operator=( const String &rhs )
121
+{
122
+  if ( this == &rhs )
123
+    return *this;
124
+
125
+  if ( rhs._length > _length )
126
+  {
127
+    free(_buffer);
128
+    getBuffer( rhs._length );
129
+  }
130
+  
131
+  if ( _buffer != NULL ) {
132
+    _length = rhs._length;
133
+    strcpy( _buffer, rhs._buffer );
134
+  }
135
+  return *this;
136
+}
137
+
138
+//const String & String::operator+=( const char aChar )
139
+//{
140
+//  if ( _length == _capacity )
141
+//    doubleBuffer();
142
+//
143
+//  _buffer[ _length++ ] = aChar;
144
+//  _buffer[ _length ] = '\0';
145
+//  return *this;
146
+//}
147
+
148
+const String & String::operator+=( const String &other )
149
+{
150
+  _length += other._length;
151
+  if ( _length > _capacity )
152
+  {
153
+    char *temp = (char *)realloc(_buffer, _length + 1);
154
+    if ( temp != NULL ) {
155
+      _buffer = temp;
156
+      _capacity = _length;
157
+    } else {
158
+      _length -= other._length;
159
+      return *this;
160
+    }
161
+  }
162
+  strcat( _buffer, other._buffer );
163
+  return *this;
164
+}
165
+
166
+
167
+int String::operator==( const String &rhs ) const
168
+{
169
+  return ( _length == rhs._length && strcmp( _buffer, rhs._buffer ) == 0 );
170
+}
171
+
172
+int String::operator!=( const String &rhs ) const
173
+{
174
+  return ( _length != rhs.length() || strcmp( _buffer, rhs._buffer ) != 0 );
175
+}
176
+
177
+int String::operator<( const String &rhs ) const
178
+{
179
+  return strcmp( _buffer, rhs._buffer ) < 0;
180
+}
181
+
182
+int String::operator>( const String &rhs ) const
183
+{
184
+  return strcmp( _buffer, rhs._buffer ) > 0;
185
+}
186
+
187
+int String::operator<=( const String &rhs ) const
188
+{
189
+  return strcmp( _buffer, rhs._buffer ) <= 0;
190
+}
191
+
192
+int String::operator>=( const String & rhs ) const
193
+{
194
+  return strcmp( _buffer, rhs._buffer ) >= 0;
195
+}
196
+
197
+char & String::operator[]( unsigned int index )
198
+{
199
+  static char dummy_writable_char;
200
+  if (index >= _length || !_buffer) {
201
+    dummy_writable_char = 0;
202
+    return dummy_writable_char;
203
+  }
204
+  return _buffer[ index ];
205
+}
206
+
207
+char String::operator[]( unsigned int index ) const
208
+{
209
+  // need to check for valid index, to do later
210
+  return _buffer[ index ];
211
+}
212
+
213
+boolean String::endsWith( const String &s2 ) const
214
+{
215
+  if ( _length < s2._length )
216
+    return 0;
217
+
218
+  return strcmp( &_buffer[ _length - s2._length], s2._buffer ) == 0;
219
+}
220
+
221
+boolean String::equals( const String &s2 ) const
222
+{
223
+  return ( _length == s2._length && strcmp( _buffer,s2._buffer ) == 0 );
224
+}
225
+
226
+boolean String::equalsIgnoreCase( const String &s2 ) const
227
+{
228
+  if ( this == &s2 )
229
+    return true; //1;
230
+  else if ( _length != s2._length )
231
+    return false; //0;
232
+
233
+  return strcmp(toLowerCase()._buffer, s2.toLowerCase()._buffer) == 0;
234
+}
235
+
236
+String String::replace( char findChar, char replaceChar )
237
+{
238
+  if ( _buffer == NULL ) return *this;
239
+  String theReturn = _buffer;
240
+  char* temp = theReturn._buffer;
241
+  while( (temp = strchr( temp, findChar )) != 0 )
242
+    *temp = replaceChar;
243
+
244
+  return theReturn;
245
+}
246
+
247
+String String::replace( const String& match, const String& replace )
248
+{
249
+  if ( _buffer == NULL ) return *this;
250
+  String temp = _buffer, newString;
251
+
252
+  int loc;
253
+  while ( (loc = temp.indexOf( match )) != -1 )
254
+  {
255
+    newString += temp.substring( 0, loc );
256
+    newString += replace;
257
+    temp = temp.substring( loc + match._length );
258
+  }
259
+  newString += temp;  
260
+  return newString;
261
+}
262
+
263
+int String::indexOf( char temp ) const
264
+{
265
+  return indexOf( temp, 0 );
266
+}
267
+
268
+int String::indexOf( char ch, unsigned int fromIndex ) const
269
+{
270
+  if ( fromIndex >= _length )
271
+    return -1;
272
+
273
+  const char* temp = strchr( &_buffer[fromIndex], ch );
274
+  if ( temp == NULL )
275
+    return -1;
276
+
277
+  return temp - _buffer;
278
+}
279
+
280
+int String::indexOf( const String &s2 ) const
281
+{
282
+  return indexOf( s2, 0 );
283
+}
284
+
285
+int String::indexOf( const String &s2, unsigned int fromIndex ) const
286
+{
287
+  if ( fromIndex >= _length )
288
+    return -1;
289
+
290
+  const char *theFind = strstr( &_buffer[ fromIndex ], s2._buffer );
291
+
292
+  if ( theFind == NULL )
293
+    return -1;
294
+
295
+  return theFind - _buffer; // pointer subtraction
296
+}
297
+
298
+int String::lastIndexOf( char theChar ) const
299
+{
300
+  return lastIndexOf( theChar, _length - 1 );
301
+}
302
+
303
+int String::lastIndexOf( char ch, unsigned int fromIndex ) const
304
+{
305
+  if ( fromIndex >= _length )
306
+    return -1;
307
+
308
+  char tempchar = _buffer[fromIndex + 1];
309
+  _buffer[fromIndex + 1] = '\0';
310
+  char* temp = strrchr( _buffer, ch );
311
+  _buffer[fromIndex + 1] = tempchar;
312
+
313
+  if ( temp == NULL )
314
+    return -1;
315
+
316
+  return temp - _buffer;
317
+}
318
+
319
+int String::lastIndexOf( const String &s2 ) const
320
+{
321
+  return lastIndexOf( s2, _length - s2._length );
322
+}
323
+
324
+int String::lastIndexOf( const String &s2, unsigned int fromIndex ) const
325
+{
326
+  // check for empty strings
327
+  if ( s2._length == 0 || s2._length - 1 > fromIndex || fromIndex >= _length )
328
+    return -1;
329
+
330
+  // matching first character
331
+  char temp = s2[ 0 ];
332
+
333
+  for ( int i = fromIndex; i >= 0; i-- )
334
+  {
335
+    if ( _buffer[ i ] == temp && (*this).substring( i, i + s2._length ).equals( s2 ) )
336
+    return i;
337
+  }
338
+  return -1;
339
+}
340
+
341
+boolean String::startsWith( const String &s2 ) const
342
+{
343
+  if ( _length < s2._length )
344
+    return 0;
345
+
346
+  return startsWith( s2, 0 );
347
+}
348
+
349
+boolean String::startsWith( const String &s2, unsigned int offset ) const
350
+{
351
+  if ( offset > _length - s2._length )
352
+    return 0;
353
+
354
+  return strncmp( &_buffer[offset], s2._buffer, s2._length ) == 0;
355
+}
356
+
357
+String String::substring( unsigned int left ) const
358
+{
359
+  return substring( left, _length );
360
+}
361
+
362
+String String::substring( unsigned int left, unsigned int right ) const
363
+{
364
+  if ( left > right )
365
+  {
366
+    int temp = right;
367
+    right = left;
368
+    left = temp;
369
+  }
370
+
371
+  if ( right > _length )
372
+  {
373
+    right = _length;
374
+  } 
375
+
376
+  char temp = _buffer[ right ];  // save the replaced character
377
+  _buffer[ right ] = '\0';	
378
+  String outPut = ( _buffer + left );  // pointer arithmetic
379
+  _buffer[ right ] = temp;  //restore character
380
+  return outPut;
381
+}
382
+
383
+String String::toLowerCase() const
384
+{
385
+  String temp = _buffer;
386
+
387
+  for ( unsigned int i = 0; i < _length; i++ )
388
+    temp._buffer[ i ] = (char)tolower( temp._buffer[ i ] );
389
+  return temp;
390
+}
391
+
392
+String String::toUpperCase() const
393
+{
394
+  String temp = _buffer;
395
+
396
+  for ( unsigned int i = 0; i < _length; i++ )
397
+    temp._buffer[ i ] = (char)toupper( temp._buffer[ i ] );
398
+  return temp;
399
+}
400
+
401
+String String::trim() const
402
+{
403
+  if ( _buffer == NULL ) return *this;
404
+  String temp = _buffer;
405
+  unsigned int i,j;
406
+
407
+  for ( i = 0; i < _length; i++ )
408
+  {
409
+    if ( !isspace(_buffer[i]) )
410
+      break;
411
+  }
412
+
413
+  for ( j = temp._length - 1; j > i; j-- )
414
+  {
415
+    if ( !isspace(_buffer[j]) )
416
+      break;
417
+  }
418
+
419
+  return temp.substring( i, j + 1);
420
+}
421
+
422
+void String::getBytes(unsigned char *buf, unsigned int bufsize)
423
+{
424
+  if (!bufsize || !buf) return;
425
+  unsigned int len = bufsize - 1;
426
+  if (len > _length) len = _length;
427
+  strncpy((char *)buf, _buffer, len);
428
+  buf[len] = 0;
429
+}
430
+
431
+void String::toCharArray(char *buf, unsigned int bufsize)
432
+{
433
+  if (!bufsize || !buf) return;
434
+  unsigned int len = bufsize - 1;
435
+  if (len > _length) len = _length;
436
+  strncpy(buf, _buffer, len);
437
+  buf[len] = 0;
438
+}
439
+
440
+
441
+long String::toInt() {
442
+  return atol(_buffer);
443
+}

+ 112
- 0
Marlin/Marlin/Sanguino/cores/arduino/WString.h Переглянути файл

1
+/*
2
+  WString.h - String library for Wiring & Arduino
3
+  Copyright (c) 2009-10 Hernando Barragan.  All right 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 String_h
21
+#define String_h
22
+
23
+//#include "WProgram.h"
24
+#include <stdlib.h>
25
+#include <string.h>
26
+#include <ctype.h>
27
+
28
+class String
29
+{
30
+  public:
31
+    // constructors
32
+    String( const char *value = "" );
33
+    String( const String &value );
34
+    String( const char );
35
+    String( const unsigned char );
36
+    String( const int, const int base=10);
37
+    String( const unsigned int, const int base=10 );
38
+    String( const long, const int base=10 );
39
+    String( const unsigned long, const int base=10 );
40
+    ~String() { free(_buffer); _length = _capacity = 0;}     //added _length = _capacity = 0;
41
+
42
+    // operators
43
+    const String & operator = ( const String &rhs );
44
+    const String & operator +=( const String &rhs );
45
+    //const String & operator +=( const char );
46
+    int operator ==( const String &rhs ) const;
47
+    int	operator !=( const String &rhs ) const;
48
+    int	operator < ( const String &rhs ) const;
49
+    int	operator > ( const String &rhs ) const;
50
+    int	operator <=( const String &rhs ) const;
51
+    int	operator >=( const String &rhs ) const;
52
+    char operator []( unsigned int index ) const;
53
+    char& operator []( unsigned int index );
54
+    //operator const char *() const { return _buffer; }
55
+    
56
+    // general methods
57
+    char charAt( unsigned int index ) const;
58
+    int	compareTo( const String &anotherString ) const;
59
+    unsigned char endsWith( const String &suffix ) const;
60
+    unsigned char equals( const String &anObject ) const;
61
+    unsigned char equalsIgnoreCase( const String &anotherString ) const;
62
+    int	indexOf( char ch ) const;
63
+    int	indexOf( char ch, unsigned int fromIndex ) const;
64
+    int	indexOf( const String &str ) const;
65
+    int	indexOf( const String &str, unsigned int fromIndex ) const;
66
+    int	lastIndexOf( char ch ) const;
67
+    int	lastIndexOf( char ch, unsigned int fromIndex ) const;
68
+    int	lastIndexOf( const String &str ) const;
69
+    int	lastIndexOf( const String &str, unsigned int fromIndex ) const;
70
+    const unsigned int length( ) const { return _length; }
71
+    void setCharAt(unsigned int index, const char ch);
72
+    unsigned char startsWith( const String &prefix ) const;
73
+    unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
74
+    String substring( unsigned int beginIndex ) const;
75
+    String substring( unsigned int beginIndex, unsigned int endIndex ) const;
76
+    String toLowerCase( ) const;
77
+    String toUpperCase( ) const;
78
+    String trim( ) const;
79
+    void getBytes(unsigned char *buf, unsigned int bufsize);
80
+    void toCharArray(char *buf, unsigned int bufsize);
81
+    long toInt( );
82
+    const String& concat( const String &str );
83
+    String replace( char oldChar, char newChar );
84
+    String replace( const String& match, const String& replace );
85
+    friend String operator + ( String lhs, const String &rhs );
86
+
87
+  protected:
88
+    char *_buffer;	     // the actual char array
89
+    unsigned int _capacity;  // the array length minus one (for the '\0')
90
+    unsigned int _length;    // the String length (not counting the '\0')
91
+
92
+    void getBuffer(unsigned int maxStrLen);
93
+
94
+  private:
95
+
96
+};
97
+
98
+// allocate buffer space
99
+inline void String::getBuffer(unsigned int maxStrLen)
100
+{
101
+  _capacity = maxStrLen;
102
+  _buffer = (char *) malloc(_capacity + 1);
103
+  if (_buffer == NULL) _length = _capacity = 0;
104
+}
105
+
106
+inline String operator+( String lhs, const String &rhs )
107
+{
108
+  return lhs += rhs;
109
+}
110
+
111
+
112
+#endif

+ 515
- 0
Marlin/Marlin/Sanguino/cores/arduino/binary.h Переглянути файл

1
+#ifndef Binary_h
2
+#define Binary_h
3
+
4
+#define B0 0
5
+#define B00 0
6
+#define B000 0
7
+#define B0000 0
8
+#define B00000 0
9
+#define B000000 0
10
+#define B0000000 0
11
+#define B00000000 0
12
+#define B1 1
13
+#define B01 1
14
+#define B001 1
15
+#define B0001 1
16
+#define B00001 1
17
+#define B000001 1
18
+#define B0000001 1
19
+#define B00000001 1
20
+#define B10 2
21
+#define B010 2
22
+#define B0010 2
23
+#define B00010 2
24
+#define B000010 2
25
+#define B0000010 2
26
+#define B00000010 2
27
+#define B11 3
28
+#define B011 3
29
+#define B0011 3
30
+#define B00011 3
31
+#define B000011 3
32
+#define B0000011 3
33
+#define B00000011 3
34
+#define B100 4
35
+#define B0100 4
36
+#define B00100 4
37
+#define B000100 4
38
+#define B0000100 4
39
+#define B00000100 4
40
+#define B101 5
41
+#define B0101 5
42
+#define B00101 5
43
+#define B000101 5
44
+#define B0000101 5
45
+#define B00000101 5
46
+#define B110 6
47
+#define B0110 6
48
+#define B00110 6
49
+#define B000110 6
50
+#define B0000110 6
51
+#define B00000110 6
52
+#define B111 7
53
+#define B0111 7
54
+#define B00111 7
55
+#define B000111 7
56
+#define B0000111 7
57
+#define B00000111 7
58
+#define B1000 8
59
+#define B01000 8
60
+#define B001000 8
61
+#define B0001000 8
62
+#define B00001000 8
63
+#define B1001 9
64
+#define B01001 9
65
+#define B001001 9
66
+#define B0001001 9
67
+#define B00001001 9
68
+#define B1010 10
69
+#define B01010 10
70
+#define B001010 10
71
+#define B0001010 10
72
+#define B00001010 10
73
+#define B1011 11
74
+#define B01011 11
75
+#define B001011 11
76
+#define B0001011 11
77
+#define B00001011 11
78
+#define B1100 12
79
+#define B01100 12
80
+#define B001100 12
81
+#define B0001100 12
82
+#define B00001100 12
83
+#define B1101 13
84
+#define B01101 13
85
+#define B001101 13
86
+#define B0001101 13
87
+#define B00001101 13
88
+#define B1110 14
89
+#define B01110 14
90
+#define B001110 14
91
+#define B0001110 14
92
+#define B00001110 14
93
+#define B1111 15
94
+#define B01111 15
95
+#define B001111 15
96
+#define B0001111 15
97
+#define B00001111 15
98
+#define B10000 16
99
+#define B010000 16
100
+#define B0010000 16
101
+#define B00010000 16
102
+#define B10001 17
103
+#define B010001 17
104
+#define B0010001 17
105
+#define B00010001 17
106
+#define B10010 18
107
+#define B010010 18
108
+#define B0010010 18
109
+#define B00010010 18
110
+#define B10011 19
111
+#define B010011 19
112
+#define B0010011 19
113
+#define B00010011 19
114
+#define B10100 20
115
+#define B010100 20
116
+#define B0010100 20
117
+#define B00010100 20
118
+#define B10101 21
119
+#define B010101 21
120
+#define B0010101 21
121
+#define B00010101 21
122
+#define B10110 22
123
+#define B010110 22
124
+#define B0010110 22
125
+#define B00010110 22
126
+#define B10111 23
127
+#define B010111 23
128
+#define B0010111 23
129
+#define B00010111 23
130
+#define B11000 24
131
+#define B011000 24
132
+#define B0011000 24
133
+#define B00011000 24
134
+#define B11001 25
135
+#define B011001 25
136
+#define B0011001 25
137
+#define B00011001 25
138
+#define B11010 26
139
+#define B011010 26
140
+#define B0011010 26
141
+#define B00011010 26
142
+#define B11011 27
143
+#define B011011 27
144
+#define B0011011 27
145
+#define B00011011 27
146
+#define B11100 28
147
+#define B011100 28
148
+#define B0011100 28
149
+#define B00011100 28
150
+#define B11101 29
151
+#define B011101 29
152
+#define B0011101 29
153
+#define B00011101 29
154
+#define B11110 30
155
+#define B011110 30
156
+#define B0011110 30
157
+#define B00011110 30
158
+#define B11111 31
159
+#define B011111 31
160
+#define B0011111 31
161
+#define B00011111 31
162
+#define B100000 32
163
+#define B0100000 32
164
+#define B00100000 32
165
+#define B100001 33
166
+#define B0100001 33
167
+#define B00100001 33
168
+#define B100010 34
169
+#define B0100010 34
170
+#define B00100010 34
171
+#define B100011 35
172
+#define B0100011 35
173
+#define B00100011 35
174
+#define B100100 36
175
+#define B0100100 36
176
+#define B00100100 36
177
+#define B100101 37
178
+#define B0100101 37
179
+#define B00100101 37
180
+#define B100110 38
181
+#define B0100110 38
182
+#define B00100110 38
183
+#define B100111 39
184
+#define B0100111 39
185
+#define B00100111 39
186
+#define B101000 40
187
+#define B0101000 40
188
+#define B00101000 40
189
+#define B101001 41
190
+#define B0101001 41
191
+#define B00101001 41
192
+#define B101010 42
193
+#define B0101010 42
194
+#define B00101010 42
195
+#define B101011 43
196
+#define B0101011 43
197
+#define B00101011 43
198
+#define B101100 44
199
+#define B0101100 44
200
+#define B00101100 44
201
+#define B101101 45
202
+#define B0101101 45
203
+#define B00101101 45
204
+#define B101110 46
205
+#define B0101110 46
206
+#define B00101110 46
207
+#define B101111 47
208
+#define B0101111 47
209
+#define B00101111 47
210
+#define B110000 48
211
+#define B0110000 48
212
+#define B00110000 48
213
+#define B110001 49
214
+#define B0110001 49
215
+#define B00110001 49
216
+#define B110010 50
217
+#define B0110010 50
218
+#define B00110010 50
219
+#define B110011 51
220
+#define B0110011 51
221
+#define B00110011 51
222
+#define B110100 52
223
+#define B0110100 52
224
+#define B00110100 52
225
+#define B110101 53
226
+#define B0110101 53
227
+#define B00110101 53
228
+#define B110110 54
229
+#define B0110110 54
230
+#define B00110110 54
231
+#define B110111 55
232
+#define B0110111 55
233
+#define B00110111 55
234
+#define B111000 56
235
+#define B0111000 56
236
+#define B00111000 56
237
+#define B111001 57
238
+#define B0111001 57
239
+#define B00111001 57
240
+#define B111010 58
241
+#define B0111010 58
242
+#define B00111010 58
243
+#define B111011 59
244
+#define B0111011 59
245
+#define B00111011 59
246
+#define B111100 60
247
+#define B0111100 60
248
+#define B00111100 60
249
+#define B111101 61
250
+#define B0111101 61
251
+#define B00111101 61
252
+#define B111110 62
253
+#define B0111110 62
254
+#define B00111110 62
255
+#define B111111 63
256
+#define B0111111 63
257
+#define B00111111 63
258
+#define B1000000 64
259
+#define B01000000 64
260
+#define B1000001 65
261
+#define B01000001 65
262
+#define B1000010 66
263
+#define B01000010 66
264
+#define B1000011 67
265
+#define B01000011 67
266
+#define B1000100 68
267
+#define B01000100 68
268
+#define B1000101 69
269
+#define B01000101 69
270
+#define B1000110 70
271
+#define B01000110 70
272
+#define B1000111 71
273
+#define B01000111 71
274
+#define B1001000 72
275
+#define B01001000 72
276
+#define B1001001 73
277
+#define B01001001 73
278
+#define B1001010 74
279
+#define B01001010 74
280
+#define B1001011 75
281
+#define B01001011 75
282
+#define B1001100 76
283
+#define B01001100 76
284
+#define B1001101 77
285
+#define B01001101 77
286
+#define B1001110 78
287
+#define B01001110 78
288
+#define B1001111 79
289
+#define B01001111 79
290
+#define B1010000 80
291
+#define B01010000 80
292
+#define B1010001 81
293
+#define B01010001 81
294
+#define B1010010 82
295
+#define B01010010 82
296
+#define B1010011 83
297
+#define B01010011 83
298
+#define B1010100 84
299
+#define B01010100 84
300
+#define B1010101 85
301
+#define B01010101 85
302
+#define B1010110 86
303
+#define B01010110 86
304
+#define B1010111 87
305
+#define B01010111 87
306
+#define B1011000 88
307
+#define B01011000 88
308
+#define B1011001 89
309
+#define B01011001 89
310
+#define B1011010 90
311
+#define B01011010 90
312
+#define B1011011 91
313
+#define B01011011 91
314
+#define B1011100 92
315
+#define B01011100 92
316
+#define B1011101 93
317
+#define B01011101 93
318
+#define B1011110 94
319
+#define B01011110 94
320
+#define B1011111 95
321
+#define B01011111 95
322
+#define B1100000 96
323
+#define B01100000 96
324
+#define B1100001 97
325
+#define B01100001 97
326
+#define B1100010 98
327
+#define B01100010 98
328
+#define B1100011 99
329
+#define B01100011 99
330
+#define B1100100 100
331
+#define B01100100 100
332
+#define B1100101 101
333
+#define B01100101 101
334
+#define B1100110 102
335
+#define B01100110 102
336
+#define B1100111 103
337
+#define B01100111 103
338
+#define B1101000 104
339
+#define B01101000 104
340
+#define B1101001 105
341
+#define B01101001 105
342
+#define B1101010 106
343
+#define B01101010 106
344
+#define B1101011 107
345
+#define B01101011 107
346
+#define B1101100 108
347
+#define B01101100 108
348
+#define B1101101 109
349
+#define B01101101 109
350
+#define B1101110 110
351
+#define B01101110 110
352
+#define B1101111 111
353
+#define B01101111 111
354
+#define B1110000 112
355
+#define B01110000 112
356
+#define B1110001 113
357
+#define B01110001 113
358
+#define B1110010 114
359
+#define B01110010 114
360
+#define B1110011 115
361
+#define B01110011 115
362
+#define B1110100 116
363
+#define B01110100 116
364
+#define B1110101 117
365
+#define B01110101 117
366
+#define B1110110 118
367
+#define B01110110 118
368
+#define B1110111 119
369
+#define B01110111 119
370
+#define B1111000 120
371
+#define B01111000 120
372
+#define B1111001 121
373
+#define B01111001 121
374
+#define B1111010 122
375
+#define B01111010 122
376
+#define B1111011 123
377
+#define B01111011 123
378
+#define B1111100 124
379
+#define B01111100 124
380
+#define B1111101 125
381
+#define B01111101 125
382
+#define B1111110 126
383
+#define B01111110 126
384
+#define B1111111 127
385
+#define B01111111 127
386
+#define B10000000 128
387
+#define B10000001 129
388
+#define B10000010 130
389
+#define B10000011 131
390
+#define B10000100 132
391
+#define B10000101 133
392
+#define B10000110 134
393
+#define B10000111 135
394
+#define B10001000 136
395
+#define B10001001 137
396
+#define B10001010 138
397
+#define B10001011 139
398
+#define B10001100 140
399
+#define B10001101 141
400
+#define B10001110 142
401
+#define B10001111 143
402
+#define B10010000 144
403
+#define B10010001 145
404
+#define B10010010 146
405
+#define B10010011 147
406
+#define B10010100 148
407
+#define B10010101 149
408
+#define B10010110 150
409
+#define B10010111 151
410
+#define B10011000 152
411
+#define B10011001 153
412
+#define B10011010 154
413
+#define B10011011 155
414
+#define B10011100 156
415
+#define B10011101 157
416
+#define B10011110 158
417
+#define B10011111 159
418
+#define B10100000 160
419
+#define B10100001 161
420
+#define B10100010 162
421
+#define B10100011 163
422
+#define B10100100 164
423
+#define B10100101 165
424
+#define B10100110 166
425
+#define B10100111 167
426
+#define B10101000 168
427
+#define B10101001 169
428
+#define B10101010 170
429
+#define B10101011 171
430
+#define B10101100 172
431
+#define B10101101 173
432
+#define B10101110 174
433
+#define B10101111 175
434
+#define B10110000 176
435
+#define B10110001 177
436
+#define B10110010 178
437
+#define B10110011 179
438
+#define B10110100 180
439
+#define B10110101 181
440
+#define B10110110 182
441
+#define B10110111 183
442
+#define B10111000 184
443
+#define B10111001 185
444
+#define B10111010 186
445
+#define B10111011 187
446
+#define B10111100 188
447
+#define B10111101 189
448
+#define B10111110 190
449
+#define B10111111 191
450
+#define B11000000 192
451
+#define B11000001 193
452
+#define B11000010 194
453
+#define B11000011 195
454
+#define B11000100 196
455
+#define B11000101 197
456
+#define B11000110 198
457
+#define B11000111 199
458
+#define B11001000 200
459
+#define B11001001 201
460
+#define B11001010 202
461
+#define B11001011 203
462
+#define B11001100 204
463
+#define B11001101 205
464
+#define B11001110 206
465
+#define B11001111 207
466
+#define B11010000 208
467
+#define B11010001 209
468
+#define B11010010 210
469
+#define B11010011 211
470
+#define B11010100 212
471
+#define B11010101 213
472
+#define B11010110 214
473
+#define B11010111 215
474
+#define B11011000 216
475
+#define B11011001 217
476
+#define B11011010 218
477
+#define B11011011 219
478
+#define B11011100 220
479
+#define B11011101 221
480
+#define B11011110 222
481
+#define B11011111 223
482
+#define B11100000 224
483
+#define B11100001 225
484
+#define B11100010 226
485
+#define B11100011 227
486
+#define B11100100 228
487
+#define B11100101 229
488
+#define B11100110 230
489
+#define B11100111 231
490
+#define B11101000 232
491
+#define B11101001 233
492
+#define B11101010 234
493
+#define B11101011 235
494
+#define B11101100 236
495
+#define B11101101 237
496
+#define B11101110 238
497
+#define B11101111 239
498
+#define B11110000 240
499
+#define B11110001 241
500
+#define B11110010 242
501
+#define B11110011 243
502
+#define B11110100 244
503
+#define B11110101 245
504
+#define B11110110 246
505
+#define B11110111 247
506
+#define B11111000 248
507
+#define B11111001 249
508
+#define B11111010 250
509
+#define B11111011 251
510
+#define B11111100 252
511
+#define B11111101 253
512
+#define B11111110 254
513
+#define B11111111 255
514
+
515
+#endif

+ 0
- 0
Marlin/Marlin/Sanguino/cores/arduino/main.cpp Переглянути файл


Деякі файли не було показано, через те що забагато файлів було змінено

Завантаження…
Відмінити
Зберегти