Pārlūkot izejas kodu

Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1

Conflicts:
	Marlin/ultralcd.h
Bernhard Kubicek 13 gadus atpakaļ
vecāks
revīzija
46f80e82d9
57 mainītis faili ar 9267 papildinājumiem un 3 dzēšanām
  1. 3
    3
      Marlin/Configuration.h
  2. 16
    0
      Marlin/Sanguino/boards.txt
  3. 713
    0
      Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT.c
  4. 121
    0
      Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_324P.hex
  5. 120
    0
      Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_644.hex
  6. 121
    0
      Marlin/Sanguino/bootloaders/atmega644p/ATmegaBOOT_644P.hex
  7. 56
    0
      Marlin/Sanguino/bootloaders/atmega644p/Makefile
  8. 3
    0
      Marlin/Sanguino/bootloaders/atmega644p/README.txt
  9. 303
    0
      Marlin/Sanguino/cores/Copy of arduino/HardwareSerial.cpp
  10. 76
    0
      Marlin/Sanguino/cores/Copy of arduino/HardwareSerial.h
  11. 220
    0
      Marlin/Sanguino/cores/Copy of arduino/Print.cpp
  12. 66
    0
      Marlin/Sanguino/cores/Copy of arduino/Print.h
  13. 515
    0
      Marlin/Sanguino/cores/Copy of arduino/Tone.cpp
  14. 168
    0
      Marlin/Sanguino/cores/Copy of arduino/WCharacter.h
  15. 1
    0
      Marlin/Sanguino/cores/Copy of arduino/WConstants.h
  16. 87
    0
      Marlin/Sanguino/cores/Copy of arduino/WInterrupts.c
  17. 60
    0
      Marlin/Sanguino/cores/Copy of arduino/WMath.cpp
  18. 63
    0
      Marlin/Sanguino/cores/Copy of arduino/WProgram.h
  19. 443
    0
      Marlin/Sanguino/cores/Copy of arduino/WString.cpp
  20. 112
    0
      Marlin/Sanguino/cores/Copy of arduino/WString.h
  21. 515
    0
      Marlin/Sanguino/cores/Copy of arduino/binary.h
  22. 14
    0
      Marlin/Sanguino/cores/Copy of arduino/main.cpp
  23. 200
    0
      Marlin/Sanguino/cores/Copy of arduino/pins_arduino.c
  24. 65
    0
      Marlin/Sanguino/cores/Copy of arduino/pins_arduino.h
  25. 289
    0
      Marlin/Sanguino/cores/Copy of arduino/wiring.c
  26. 135
    0
      Marlin/Sanguino/cores/Copy of arduino/wiring.h
  27. 116
    0
      Marlin/Sanguino/cores/Copy of arduino/wiring_analog.c
  28. 95
    0
      Marlin/Sanguino/cores/Copy of arduino/wiring_digital.c
  29. 60
    0
      Marlin/Sanguino/cores/Copy of arduino/wiring_private.h
  30. 69
    0
      Marlin/Sanguino/cores/Copy of arduino/wiring_pulse.c
  31. 55
    0
      Marlin/Sanguino/cores/Copy of arduino/wiring_shift.c
  32. 135
    0
      Marlin/Sanguino/cores/arduino/Copy of wiring.h
  33. 303
    0
      Marlin/Sanguino/cores/arduino/HardwareSerial.cpp
  34. 76
    0
      Marlin/Sanguino/cores/arduino/HardwareSerial.h
  35. 220
    0
      Marlin/Sanguino/cores/arduino/Print.cpp
  36. 66
    0
      Marlin/Sanguino/cores/arduino/Print.h
  37. 35
    0
      Marlin/Sanguino/cores/arduino/Stream.h
  38. 601
    0
      Marlin/Sanguino/cores/arduino/Tone.cpp
  39. 168
    0
      Marlin/Sanguino/cores/arduino/WCharacter.h
  40. 1
    0
      Marlin/Sanguino/cores/arduino/WConstants.h
  41. 249
    0
      Marlin/Sanguino/cores/arduino/WInterrupts.c
  42. 60
    0
      Marlin/Sanguino/cores/arduino/WMath.cpp
  43. 63
    0
      Marlin/Sanguino/cores/arduino/WProgram.h
  44. 443
    0
      Marlin/Sanguino/cores/arduino/WString.cpp
  45. 112
    0
      Marlin/Sanguino/cores/arduino/WString.h
  46. 515
    0
      Marlin/Sanguino/cores/arduino/binary.h
  47. 14
    0
      Marlin/Sanguino/cores/arduino/main.cpp
  48. 200
    0
      Marlin/Sanguino/cores/arduino/pins_arduino.c
  49. 65
    0
      Marlin/Sanguino/cores/arduino/pins_arduino.h
  50. 289
    0
      Marlin/Sanguino/cores/arduino/wiring.c
  51. 135
    0
      Marlin/Sanguino/cores/arduino/wiring.h
  52. 259
    0
      Marlin/Sanguino/cores/arduino/wiring_analog.c
  53. 166
    0
      Marlin/Sanguino/cores/arduino/wiring_digital.c
  54. 68
    0
      Marlin/Sanguino/cores/arduino/wiring_private.h
  55. 69
    0
      Marlin/Sanguino/cores/arduino/wiring_pulse.c
  56. 55
    0
      Marlin/Sanguino/cores/arduino/wiring_shift.c
  57. 20
    0
      Marlin/Sanguino/programmers.txt

+ 3
- 3
Marlin/Configuration.h Parādīt failu

@@ -4,8 +4,8 @@
4 4
 
5 5
 
6 6
 // This determines the communication speed of the printer
7
-//#define BAUDRATE 250000
8
-#define BAUDRATE 115200
7
+#define BAUDRATE 250000
8
+//#define BAUDRATE 115200
9 9
 //#define BAUDRATE 230400
10 10
 
11 11
 
@@ -277,7 +277,7 @@ const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the
277 277
 
278 278
 #define ULTIPANEL
279 279
 #ifdef ULTIPANEL
280
-  #define NEWPANEL  //enable this if you have a click-encoder panel
280
+//  #define NEWPANEL  //enable this if you have a click-encoder panel
281 281
   #define SDSUPPORT
282 282
   #define ULTRA_LCD
283 283
   #define LCD_WIDTH 20

+ 16
- 0
Marlin/Sanguino/boards.txt Parādīt failu

@@ -0,0 +1,16 @@
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/Sanguino/bootloaders/atmega644p/ATmegaBOOT.c Parādīt failu

@@ -0,0 +1,713 @@
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/Sanguino/bootloaders/atmega644p/ATmegaBOOT_324P.hex Parādīt failu

@@ -0,0 +1,121 @@
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/Sanguino/bootloaders/atmega644p/ATmegaBOOT_644.hex Parādīt failu

@@ -0,0 +1,120 @@
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/Sanguino/bootloaders/atmega644p/ATmegaBOOT_644P.hex Parādīt failu

@@ -0,0 +1,121 @@
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/Sanguino/bootloaders/atmega644p/Makefile Parādīt failu

@@ -0,0 +1,56 @@
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/Sanguino/bootloaders/atmega644p/README.txt Parādīt failu

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

+ 303
- 0
Marlin/Sanguino/cores/Copy of arduino/HardwareSerial.cpp Parādīt failu

@@ -0,0 +1,303 @@
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
+#if (RAMEND < 1000)
41
+  #define RX_BUFFER_SIZE 32
42
+#else
43
+  #define RX_BUFFER_SIZE 128
44
+#endif
45
+
46
+struct ring_buffer
47
+{
48
+  unsigned char buffer[RX_BUFFER_SIZE];
49
+  int head;
50
+  int tail;
51
+};
52
+
53
+#if defined(UBRRH) || defined(UBRR0H)
54
+  ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
55
+#endif
56
+#if defined(UBRR1H)
57
+  ring_buffer rx_buffer1  =  { { 0 }, 0, 0 };
58
+#endif
59
+#if defined(UBRR2H)
60
+  ring_buffer rx_buffer2  =  { { 0 }, 0, 0 };
61
+#endif
62
+#if defined(UBRR3H)
63
+  ring_buffer rx_buffer3  =  { { 0 }, 0, 0 };
64
+#endif
65
+
66
+inline void store_char(unsigned char c, ring_buffer *rx_buffer)
67
+{
68
+  int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE;
69
+
70
+  // if we should be storing the received character into the location
71
+  // just before the tail (meaning that the head would advance to the
72
+  // current location of the tail), we're about to overflow the buffer
73
+  // and so we don't write the character or advance the head.
74
+  if (i != rx_buffer->tail) {
75
+    rx_buffer->buffer[rx_buffer->head] = c;
76
+    rx_buffer->head = i;
77
+  }
78
+}
79
+
80
+#if defined(USART_RX_vect)
81
+  SIGNAL(USART_RX_vect)
82
+  {
83
+  #if defined(UDR0)
84
+    unsigned char c  =  UDR0;
85
+  #elif defined(UDR)
86
+    unsigned char c  =  UDR;  //  atmega8535
87
+  #else
88
+    #error UDR not defined
89
+  #endif
90
+    store_char(c, &rx_buffer);
91
+  }
92
+#elif defined(SIG_USART0_RECV) && defined(UDR0)
93
+  SIGNAL(SIG_USART0_RECV)
94
+  {
95
+    unsigned char c  =  UDR0;
96
+    store_char(c, &rx_buffer);
97
+  }
98
+#elif defined(SIG_UART0_RECV) && defined(UDR0)
99
+  SIGNAL(SIG_UART0_RECV)
100
+  {
101
+    unsigned char c  =  UDR0;
102
+    store_char(c, &rx_buffer);
103
+  }
104
+//#elif defined(SIG_USART_RECV)
105
+#elif defined(USART0_RX_vect)
106
+  // fixed by Mark Sproul this is on the 644/644p
107
+  //SIGNAL(SIG_USART_RECV)
108
+  SIGNAL(USART0_RX_vect)
109
+  {
110
+  #if defined(UDR0)
111
+    unsigned char c  =  UDR0;
112
+  #elif defined(UDR)
113
+    unsigned char c  =  UDR;  //  atmega8, atmega32
114
+  #else
115
+    #error UDR not defined
116
+  #endif
117
+    store_char(c, &rx_buffer);
118
+  }
119
+#elif defined(SIG_UART_RECV)
120
+  // this is for atmega8
121
+  SIGNAL(SIG_UART_RECV)
122
+  {
123
+  #if defined(UDR0)
124
+    unsigned char c  =  UDR0;  //  atmega645
125
+  #elif defined(UDR)
126
+    unsigned char c  =  UDR;  //  atmega8
127
+  #endif
128
+    store_char(c, &rx_buffer);
129
+  }
130
+#elif defined(USBCON)
131
+  #warning No interrupt handler for usart 0
132
+  #warning Serial(0) is on USB interface
133
+#else
134
+  #error No interrupt handler for usart 0
135
+#endif
136
+
137
+//#if defined(SIG_USART1_RECV)
138
+#if defined(USART1_RX_vect)
139
+  //SIGNAL(SIG_USART1_RECV)
140
+  SIGNAL(USART1_RX_vect)
141
+  {
142
+    unsigned char c = UDR1;
143
+    store_char(c, &rx_buffer1);
144
+  }
145
+#elif defined(SIG_USART1_RECV)
146
+  #error SIG_USART1_RECV
147
+#endif
148
+
149
+#if defined(USART2_RX_vect) && defined(UDR2)
150
+  SIGNAL(USART2_RX_vect)
151
+  {
152
+    unsigned char c = UDR2;
153
+    store_char(c, &rx_buffer2);
154
+  }
155
+#elif defined(SIG_USART2_RECV)
156
+  #error SIG_USART2_RECV
157
+#endif
158
+
159
+#if defined(USART3_RX_vect) && defined(UDR3)
160
+  SIGNAL(USART3_RX_vect)
161
+  {
162
+    unsigned char c = UDR3;
163
+    store_char(c, &rx_buffer3);
164
+  }
165
+#elif defined(SIG_USART3_RECV)
166
+  #error SIG_USART3_RECV
167
+#endif
168
+
169
+
170
+
171
+// Constructors ////////////////////////////////////////////////////////////////
172
+
173
+HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
174
+  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
175
+  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
176
+  volatile uint8_t *udr,
177
+  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
178
+{
179
+  _rx_buffer = rx_buffer;
180
+  _ubrrh = ubrrh;
181
+  _ubrrl = ubrrl;
182
+  _ucsra = ucsra;
183
+  _ucsrb = ucsrb;
184
+  _udr = udr;
185
+  _rxen = rxen;
186
+  _txen = txen;
187
+  _rxcie = rxcie;
188
+  _udre = udre;
189
+  _u2x = u2x;
190
+}
191
+
192
+// Public Methods //////////////////////////////////////////////////////////////
193
+
194
+void HardwareSerial::begin(long baud)
195
+{
196
+  uint16_t baud_setting;
197
+  bool use_u2x = true;
198
+
199
+#if F_CPU == 16000000UL
200
+  // hardcoded exception for compatibility with the bootloader shipped
201
+  // with the Duemilanove and previous boards and the firmware on the 8U2
202
+  // on the Uno and Mega 2560.
203
+  if (baud == 57600) {
204
+    use_u2x = false;
205
+  }
206
+#endif
207
+  
208
+  if (use_u2x) {
209
+    *_ucsra = 1 << _u2x;
210
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
211
+  } else {
212
+    *_ucsra = 0;
213
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
214
+  }
215
+
216
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
217
+  *_ubrrh = baud_setting >> 8;
218
+  *_ubrrl = baud_setting;
219
+
220
+  sbi(*_ucsrb, _rxen);
221
+  sbi(*_ucsrb, _txen);
222
+  sbi(*_ucsrb, _rxcie);
223
+}
224
+
225
+void HardwareSerial::end()
226
+{
227
+  cbi(*_ucsrb, _rxen);
228
+  cbi(*_ucsrb, _txen);
229
+  cbi(*_ucsrb, _rxcie);  
230
+}
231
+
232
+int HardwareSerial::available(void)
233
+{
234
+  return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
235
+}
236
+
237
+int HardwareSerial::peek(void)
238
+{
239
+  if (_rx_buffer->head == _rx_buffer->tail) {
240
+    return -1;
241
+  } else {
242
+    return _rx_buffer->buffer[_rx_buffer->tail];
243
+  }
244
+}
245
+
246
+int HardwareSerial::read(void)
247
+{
248
+  // if the head isn't ahead of the tail, we don't have any characters
249
+  if (_rx_buffer->head == _rx_buffer->tail) {
250
+    return -1;
251
+  } else {
252
+    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
253
+    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
254
+    return c;
255
+  }
256
+}
257
+
258
+void HardwareSerial::flush()
259
+{
260
+  // don't reverse this or there may be problems if the RX interrupt
261
+  // occurs after reading the value of rx_buffer_head but before writing
262
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
263
+  // may be written to rx_buffer_tail, making it appear as if the buffer
264
+  // don't reverse this or there may be problems if the RX interrupt
265
+  // occurs after reading the value of rx_buffer_head but before writing
266
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
267
+  // may be written to rx_buffer_tail, making it appear as if the buffer
268
+  // were full, not empty.
269
+  _rx_buffer->head = _rx_buffer->tail;
270
+}
271
+
272
+void HardwareSerial::write(uint8_t c)
273
+{
274
+  while (!((*_ucsra) & (1 << _udre)))
275
+    ;
276
+
277
+  *_udr = c;
278
+}
279
+
280
+// Preinstantiate Objects //////////////////////////////////////////////////////
281
+
282
+#if defined(UBRRH) && defined(UBRRL)
283
+  HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X);
284
+#elif defined(UBRR0H) && defined(UBRR0L)
285
+  HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
286
+#elif defined(USBCON)
287
+  #warning no serial port defined  (port 0)
288
+#else
289
+  #error no serial port defined  (port 0)
290
+#endif
291
+
292
+#if defined(UBRR1H)
293
+  HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
294
+#endif
295
+#if defined(UBRR2H)
296
+  HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
297
+#endif
298
+#if defined(UBRR3H)
299
+  HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
300
+#endif
301
+
302
+#endif // whole file
303
+

+ 76
- 0
Marlin/Sanguino/cores/Copy of arduino/HardwareSerial.h Parādīt failu

@@ -0,0 +1,76 @@
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/Sanguino/cores/Copy of arduino/Print.cpp Parādīt failu

@@ -0,0 +1,220 @@
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/Sanguino/cores/Copy of arduino/Print.h Parādīt failu

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

+ 515
- 0
Marlin/Sanguino/cores/Copy of arduino/Tone.cpp Parādīt failu

@@ -0,0 +1,515 @@
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/Sanguino/cores/Copy of arduino/WCharacter.h Parādīt failu

@@ -0,0 +1,168 @@
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/Sanguino/cores/Copy of arduino/WConstants.h Parādīt failu

@@ -0,0 +1 @@
1
+#include "wiring.h"

+ 87
- 0
Marlin/Sanguino/cores/Copy of arduino/WInterrupts.c Parādīt failu

@@ -0,0 +1,87 @@
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/Sanguino/cores/Copy of arduino/WMath.cpp Parādīt failu

@@ -0,0 +1,60 @@
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/Sanguino/cores/Copy of arduino/WProgram.h Parādīt failu

@@ -0,0 +1,63 @@
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/Sanguino/cores/Copy of arduino/WString.cpp Parādīt failu

@@ -0,0 +1,443 @@
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/Sanguino/cores/Copy of arduino/WString.h Parādīt failu

@@ -0,0 +1,112 @@
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/Sanguino/cores/Copy of arduino/binary.h Parādīt failu

@@ -0,0 +1,515 @@
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/Sanguino/cores/Copy of arduino/main.cpp Parādīt failu

@@ -0,0 +1,14 @@
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/Sanguino/cores/Copy of arduino/pins_arduino.c Parādīt failu

@@ -0,0 +1,200 @@
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
+    &DDRA,
71
+	&DDRB,
72
+	&DDRC,
73
+	&DDRD,
74
+};
75
+
76
+const uint8_t PROGMEM port_to_output_PGM[] =
77
+{
78
+	NOT_A_PORT,
79
+	&PORTA,
80
+	&PORTB,
81
+	&PORTC,
82
+	&PORTD,
83
+};
84
+
85
+const uint8_t PROGMEM port_to_input_PGM[] =
86
+{
87
+	NOT_A_PORT,
88
+	&PINA,
89
+	&PINB,
90
+	&PINC,
91
+	&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/Sanguino/cores/Copy of arduino/pins_arduino.h Parādīt failu

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

+ 289
- 0
Marlin/Sanguino/cores/Copy of arduino/wiring.c Parādīt failu

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

+ 135
- 0
Marlin/Sanguino/cores/Copy of arduino/wiring.h Parādīt failu

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

+ 116
- 0
Marlin/Sanguino/cores/Copy of arduino/wiring_analog.c Parādīt failu

@@ -0,0 +1,116 @@
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/Sanguino/cores/Copy of arduino/wiring_digital.c Parādīt failu

@@ -0,0 +1,95 @@
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/Sanguino/cores/Copy of arduino/wiring_private.h Parādīt failu

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

+ 69
- 0
Marlin/Sanguino/cores/Copy of arduino/wiring_pulse.c Parādīt failu

@@ -0,0 +1,69 @@
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/Sanguino/cores/Copy of arduino/wiring_shift.c Parādīt failu

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

+ 135
- 0
Marlin/Sanguino/cores/arduino/Copy of wiring.h Parādīt failu

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

+ 303
- 0
Marlin/Sanguino/cores/arduino/HardwareSerial.cpp Parādīt failu

@@ -0,0 +1,303 @@
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
+#if (RAMEND < 1000)
41
+  #define RX_BUFFER_SIZE 32
42
+#else
43
+  #define RX_BUFFER_SIZE 128
44
+#endif
45
+
46
+struct ring_buffer
47
+{
48
+  unsigned char buffer[RX_BUFFER_SIZE];
49
+  int head;
50
+  int tail;
51
+};
52
+
53
+#if defined(UBRRH) || defined(UBRR0H)
54
+  ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
55
+#endif
56
+#if defined(UBRR1H)
57
+  ring_buffer rx_buffer1  =  { { 0 }, 0, 0 };
58
+#endif
59
+#if defined(UBRR2H)
60
+  ring_buffer rx_buffer2  =  { { 0 }, 0, 0 };
61
+#endif
62
+#if defined(UBRR3H)
63
+  ring_buffer rx_buffer3  =  { { 0 }, 0, 0 };
64
+#endif
65
+
66
+inline void store_char(unsigned char c, ring_buffer *rx_buffer)
67
+{
68
+  int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE;
69
+
70
+  // if we should be storing the received character into the location
71
+  // just before the tail (meaning that the head would advance to the
72
+  // current location of the tail), we're about to overflow the buffer
73
+  // and so we don't write the character or advance the head.
74
+  if (i != rx_buffer->tail) {
75
+    rx_buffer->buffer[rx_buffer->head] = c;
76
+    rx_buffer->head = i;
77
+  }
78
+}
79
+
80
+#if defined(USART_RX_vect)
81
+  SIGNAL(USART_RX_vect)
82
+  {
83
+  #if defined(UDR0)
84
+    unsigned char c  =  UDR0;
85
+  #elif defined(UDR)
86
+    unsigned char c  =  UDR;  //  atmega8535
87
+  #else
88
+    #error UDR not defined
89
+  #endif
90
+    store_char(c, &rx_buffer);
91
+  }
92
+#elif defined(SIG_USART0_RECV) && defined(UDR0)
93
+  SIGNAL(SIG_USART0_RECV)
94
+  {
95
+    unsigned char c  =  UDR0;
96
+    store_char(c, &rx_buffer);
97
+  }
98
+#elif defined(SIG_UART0_RECV) && defined(UDR0)
99
+  SIGNAL(SIG_UART0_RECV)
100
+  {
101
+    unsigned char c  =  UDR0;
102
+    store_char(c, &rx_buffer);
103
+  }
104
+//#elif defined(SIG_USART_RECV)
105
+#elif defined(USART0_RX_vect)
106
+  // fixed by Mark Sproul this is on the 644/644p
107
+  //SIGNAL(SIG_USART_RECV)
108
+  SIGNAL(USART0_RX_vect)
109
+  {
110
+  #if defined(UDR0)
111
+    unsigned char c  =  UDR0;
112
+  #elif defined(UDR)
113
+    unsigned char c  =  UDR;  //  atmega8, atmega32
114
+  #else
115
+    #error UDR not defined
116
+  #endif
117
+    store_char(c, &rx_buffer);
118
+  }
119
+#elif defined(SIG_UART_RECV)
120
+  // this is for atmega8
121
+  SIGNAL(SIG_UART_RECV)
122
+  {
123
+  #if defined(UDR0)
124
+    unsigned char c  =  UDR0;  //  atmega645
125
+  #elif defined(UDR)
126
+    unsigned char c  =  UDR;  //  atmega8
127
+  #endif
128
+    store_char(c, &rx_buffer);
129
+  }
130
+#elif defined(USBCON)
131
+  #warning No interrupt handler for usart 0
132
+  #warning Serial(0) is on USB interface
133
+#else
134
+  #error No interrupt handler for usart 0
135
+#endif
136
+
137
+//#if defined(SIG_USART1_RECV)
138
+#if defined(USART1_RX_vect)
139
+  //SIGNAL(SIG_USART1_RECV)
140
+  SIGNAL(USART1_RX_vect)
141
+  {
142
+    unsigned char c = UDR1;
143
+    store_char(c, &rx_buffer1);
144
+  }
145
+#elif defined(SIG_USART1_RECV)
146
+  #error SIG_USART1_RECV
147
+#endif
148
+
149
+#if defined(USART2_RX_vect) && defined(UDR2)
150
+  SIGNAL(USART2_RX_vect)
151
+  {
152
+    unsigned char c = UDR2;
153
+    store_char(c, &rx_buffer2);
154
+  }
155
+#elif defined(SIG_USART2_RECV)
156
+  #error SIG_USART2_RECV
157
+#endif
158
+
159
+#if defined(USART3_RX_vect) && defined(UDR3)
160
+  SIGNAL(USART3_RX_vect)
161
+  {
162
+    unsigned char c = UDR3;
163
+    store_char(c, &rx_buffer3);
164
+  }
165
+#elif defined(SIG_USART3_RECV)
166
+  #error SIG_USART3_RECV
167
+#endif
168
+
169
+
170
+
171
+// Constructors ////////////////////////////////////////////////////////////////
172
+
173
+HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
174
+  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
175
+  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
176
+  volatile uint8_t *udr,
177
+  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
178
+{
179
+  _rx_buffer = rx_buffer;
180
+  _ubrrh = ubrrh;
181
+  _ubrrl = ubrrl;
182
+  _ucsra = ucsra;
183
+  _ucsrb = ucsrb;
184
+  _udr = udr;
185
+  _rxen = rxen;
186
+  _txen = txen;
187
+  _rxcie = rxcie;
188
+  _udre = udre;
189
+  _u2x = u2x;
190
+}
191
+
192
+// Public Methods //////////////////////////////////////////////////////////////
193
+
194
+void HardwareSerial::begin(long baud)
195
+{
196
+  uint16_t baud_setting;
197
+  bool use_u2x = true;
198
+
199
+#if F_CPU == 16000000UL
200
+  // hardcoded exception for compatibility with the bootloader shipped
201
+  // with the Duemilanove and previous boards and the firmware on the 8U2
202
+  // on the Uno and Mega 2560.
203
+  if (baud == 57600) {
204
+    use_u2x = false;
205
+  }
206
+#endif
207
+  
208
+  if (use_u2x) {
209
+    *_ucsra = 1 << _u2x;
210
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
211
+  } else {
212
+    *_ucsra = 0;
213
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
214
+  }
215
+
216
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
217
+  *_ubrrh = baud_setting >> 8;
218
+  *_ubrrl = baud_setting;
219
+
220
+  sbi(*_ucsrb, _rxen);
221
+  sbi(*_ucsrb, _txen);
222
+  sbi(*_ucsrb, _rxcie);
223
+}
224
+
225
+void HardwareSerial::end()
226
+{
227
+  cbi(*_ucsrb, _rxen);
228
+  cbi(*_ucsrb, _txen);
229
+  cbi(*_ucsrb, _rxcie);  
230
+}
231
+
232
+int HardwareSerial::available(void)
233
+{
234
+  return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
235
+}
236
+
237
+int HardwareSerial::peek(void)
238
+{
239
+  if (_rx_buffer->head == _rx_buffer->tail) {
240
+    return -1;
241
+  } else {
242
+    return _rx_buffer->buffer[_rx_buffer->tail];
243
+  }
244
+}
245
+
246
+int HardwareSerial::read(void)
247
+{
248
+  // if the head isn't ahead of the tail, we don't have any characters
249
+  if (_rx_buffer->head == _rx_buffer->tail) {
250
+    return -1;
251
+  } else {
252
+    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
253
+    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
254
+    return c;
255
+  }
256
+}
257
+
258
+void HardwareSerial::flush()
259
+{
260
+  // don't reverse this or there may be problems if the RX interrupt
261
+  // occurs after reading the value of rx_buffer_head but before writing
262
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
263
+  // may be written to rx_buffer_tail, making it appear as if the buffer
264
+  // don't reverse this or there may be problems if the RX interrupt
265
+  // occurs after reading the value of rx_buffer_head but before writing
266
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
267
+  // may be written to rx_buffer_tail, making it appear as if the buffer
268
+  // were full, not empty.
269
+  _rx_buffer->head = _rx_buffer->tail;
270
+}
271
+
272
+void HardwareSerial::write(uint8_t c)
273
+{
274
+  while (!((*_ucsra) & (1 << _udre)))
275
+    ;
276
+
277
+  *_udr = c;
278
+}
279
+
280
+// Preinstantiate Objects //////////////////////////////////////////////////////
281
+
282
+#if defined(UBRRH) && defined(UBRRL)
283
+  HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X);
284
+#elif defined(UBRR0H) && defined(UBRR0L)
285
+  HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
286
+#elif defined(USBCON)
287
+  #warning no serial port defined  (port 0)
288
+#else
289
+  #error no serial port defined  (port 0)
290
+#endif
291
+
292
+#if defined(UBRR1H)
293
+  HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
294
+#endif
295
+#if defined(UBRR2H)
296
+  HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
297
+#endif
298
+#if defined(UBRR3H)
299
+  HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
300
+#endif
301
+
302
+#endif // whole file
303
+

+ 76
- 0
Marlin/Sanguino/cores/arduino/HardwareSerial.h Parādīt failu

@@ -0,0 +1,76 @@
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/Sanguino/cores/arduino/Print.cpp Parādīt failu

@@ -0,0 +1,220 @@
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/Sanguino/cores/arduino/Print.h Parādīt failu

@@ -0,0 +1,66 @@
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/Sanguino/cores/arduino/Stream.h Parādīt failu

@@ -0,0 +1,35 @@
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/Sanguino/cores/arduino/Tone.cpp Parādīt failu

@@ -0,0 +1,601 @@
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/Sanguino/cores/arduino/WCharacter.h Parādīt failu

@@ -0,0 +1,168 @@
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/Sanguino/cores/arduino/WConstants.h Parādīt failu

@@ -0,0 +1 @@
1
+#include "wiring.h"

+ 249
- 0
Marlin/Sanguino/cores/arduino/WInterrupts.c Parādīt failu

@@ -0,0 +1,249 @@
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/Sanguino/cores/arduino/WMath.cpp Parādīt failu

@@ -0,0 +1,60 @@
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/Sanguino/cores/arduino/WProgram.h Parādīt failu

@@ -0,0 +1,63 @@
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/Sanguino/cores/arduino/WString.cpp Parādīt failu

@@ -0,0 +1,443 @@
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/Sanguino/cores/arduino/WString.h Parādīt failu

@@ -0,0 +1,112 @@
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/Sanguino/cores/arduino/binary.h Parādīt failu

@@ -0,0 +1,515 @@
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/Sanguino/cores/arduino/main.cpp Parādīt failu

@@ -0,0 +1,14 @@
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/Sanguino/cores/arduino/pins_arduino.c Parādīt failu

@@ -0,0 +1,200 @@
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
+    &DDRA,
71
+	&DDRB,
72
+	&DDRC,
73
+	&DDRD,
74
+};
75
+
76
+const uint8_t PROGMEM port_to_output_PGM[] =
77
+{
78
+	NOT_A_PORT,
79
+	&PORTA,
80
+	&PORTB,
81
+	&PORTC,
82
+	&PORTD,
83
+};
84
+
85
+const uint8_t PROGMEM port_to_input_PGM[] =
86
+{
87
+	NOT_A_PORT,
88
+	&PINA,
89
+	&PINB,
90
+	&PINC,
91
+	&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/Sanguino/cores/arduino/pins_arduino.h Parādīt failu

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

+ 289
- 0
Marlin/Sanguino/cores/arduino/wiring.c Parādīt failu

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

+ 135
- 0
Marlin/Sanguino/cores/arduino/wiring.h Parādīt failu

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

+ 259
- 0
Marlin/Sanguino/cores/arduino/wiring_analog.c Parādīt failu

@@ -0,0 +1,259 @@
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/Sanguino/cores/arduino/wiring_digital.c Parādīt failu

@@ -0,0 +1,166 @@
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/Sanguino/cores/arduino/wiring_private.h Parādīt failu

@@ -0,0 +1,68 @@
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/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/Sanguino/cores/arduino/wiring_pulse.c Parādīt failu

@@ -0,0 +1,69 @@
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/Sanguino/cores/arduino/wiring_shift.c Parādīt failu

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

+ 20
- 0
Marlin/Sanguino/programmers.txt Parādīt failu

@@ -0,0 +1,20 @@
1
+avrisp.name=AVR ISP
2
+avrisp.communication=serial
3
+avrisp.protocol=stk500v1
4
+
5
+avrispmkii.name=AVRISP mkII
6
+avrispmkii.communication=usb
7
+avrispmkii.protocol=stk500v2
8
+
9
+usbtinyisp.name=USBtinyISP
10
+usbtinyisp.protocol=usbtiny
11
+
12
+parallel.name=Parallel Programmer
13
+parallel.protocol=dapa
14
+parallel.force=true
15
+# parallel.delay=200
16
+
17
+arduinoisp.name=Arduino as ISP
18
+arduinoisp.communication=serial
19
+arduinoisp.protocol=stk500v1
20
+arduinoisp.speed=19200

Notiek ielāde…
Atcelt
Saglabāt