Browse Source

Added libraries from Arduino 1.0.3 for sanguino build

Yuri Valentini 11 years ago
parent
commit
7d20ec706e
63 changed files with 12042 additions and 7 deletions
  1. 309
    0
      ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal/LiquidCrystal.cpp
  2. 104
    0
      ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal/LiquidCrystal.h
  3. 37
    0
      ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal/keywords.txt
  4. 61
    0
      ArduinoAddons/Arduino_0.xx/libraries/SPI/SPI.cpp
  5. 70
    0
      ArduinoAddons/Arduino_0.xx/libraries/SPI/SPI.h
  6. 36
    0
      ArduinoAddons/Arduino_0.xx/libraries/SPI/keywords.txt
  7. 310
    0
      ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal/LiquidCrystal.cpp
  8. 106
    0
      ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal/LiquidCrystal.h
  9. 37
    0
      ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal/keywords.txt
  10. 66
    0
      ArduinoAddons/Arduino_1.x.x/libraries/SPI/SPI.cpp
  11. 70
    0
      ArduinoAddons/Arduino_1.x.x/libraries/SPI/SPI.h
  12. 36
    0
      ArduinoAddons/Arduino_1.x.x/libraries/SPI/keywords.txt
  13. 63
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/boards.txt
  14. 1071
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/ATmegaBOOT_168.c
  15. 130
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/ATmegaBOOT_168_atmega1284p.hex
  16. 130
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/ATmegaBOOT_168_atmega1284p_8m.hex
  17. 126
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/ATmegaBOOT_168_atmega644p.hex
  18. 254
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/Makefile
  19. 717
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/ATmegaBOOT.c
  20. 388
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/ATmegaBOOT.c.tst
  21. BIN
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/ATmegaBOOT_644P.elf
  22. 110
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/ATmegaBOOT_644P.hex
  23. 56
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/Makefile
  24. 3
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/README.txt
  25. 215
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Arduino.h
  26. 239
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/CDC.cpp
  27. 26
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Client.h
  28. 520
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/HID.cpp
  29. 519
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/HardwareSerial.cpp
  30. 115
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/HardwareSerial.h
  31. 56
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/IPAddress.cpp
  32. 76
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/IPAddress.h
  33. 23
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Platform.h
  34. 268
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Print.cpp
  35. 81
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Print.h
  36. 40
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Printable.h
  37. 9
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Server.h
  38. 270
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Stream.cpp
  39. 96
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Stream.h
  40. 616
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Tone.cpp
  41. 196
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/USBAPI.h
  42. 684
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/USBCore.cpp
  43. 303
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/USBCore.h
  44. 63
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/USBDesc.h
  45. 88
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Udp.h
  46. 168
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WCharacter.h
  47. 322
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WInterrupts.c
  48. 60
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WMath.cpp
  49. 645
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WString.cpp
  50. 205
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WString.h
  51. 515
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/binary.h
  52. 20
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/main.cpp
  53. 18
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/new.cpp
  54. 22
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/new.h
  55. 324
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring.c
  56. 282
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_analog.c
  57. 178
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_digital.c
  58. 71
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_private.h
  59. 69
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_pulse.c
  60. 55
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_shift.c
  61. 285
    0
      ArduinoAddons/Arduino_1.x.x/sanguino/variants/standard/pins_arduino.h
  62. 9
    6
      Marlin/Makefile
  63. 1
    1
      Marlin/Marlin.h

+ 309
- 0
ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal/LiquidCrystal.cpp View File

@@ -0,0 +1,309 @@
1
+#include "LiquidCrystal.h"
2
+
3
+#include <stdio.h>
4
+#include <string.h>
5
+#include <inttypes.h>
6
+#include "WProgram.h"
7
+
8
+// When the display powers up, it is configured as follows:
9
+//
10
+// 1. Display clear
11
+// 2. Function set: 
12
+//    DL = 1; 8-bit interface data 
13
+//    N = 0; 1-line display 
14
+//    F = 0; 5x8 dot character font 
15
+// 3. Display on/off control: 
16
+//    D = 0; Display off 
17
+//    C = 0; Cursor off 
18
+//    B = 0; Blinking off 
19
+// 4. Entry mode set: 
20
+//    I/D = 1; Increment by 1 
21
+//    S = 0; No shift 
22
+//
23
+// Note, however, that resetting the Arduino doesn't reset the LCD, so we
24
+// can't assume that its in that state when a sketch starts (and the
25
+// LiquidCrystal constructor is called).
26
+
27
+LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
28
+			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
29
+			     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
30
+{
31
+  init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);
32
+}
33
+
34
+LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable,
35
+			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
36
+			     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
37
+{
38
+  init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7);
39
+}
40
+
41
+LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
42
+			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
43
+{
44
+  init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0);
45
+}
46
+
47
+LiquidCrystal::LiquidCrystal(uint8_t rs,  uint8_t enable,
48
+			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
49
+{
50
+  init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
51
+}
52
+
53
+void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
54
+			 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
55
+			 uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
56
+{
57
+  _rs_pin = rs;
58
+  _rw_pin = rw;
59
+  _enable_pin = enable;
60
+  
61
+  _data_pins[0] = d0;
62
+  _data_pins[1] = d1;
63
+  _data_pins[2] = d2;
64
+  _data_pins[3] = d3; 
65
+  _data_pins[4] = d4;
66
+  _data_pins[5] = d5;
67
+  _data_pins[6] = d6;
68
+  _data_pins[7] = d7; 
69
+
70
+  pinMode(_rs_pin, OUTPUT);
71
+  // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
72
+  if (_rw_pin != 255) { 
73
+    pinMode(_rw_pin, OUTPUT);
74
+  }
75
+  pinMode(_enable_pin, OUTPUT);
76
+  
77
+  if (fourbitmode)
78
+    _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
79
+  else 
80
+    _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
81
+  
82
+  begin(16, 1);  
83
+}
84
+
85
+void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
86
+  if (lines > 1) {
87
+    _displayfunction |= LCD_2LINE;
88
+  }
89
+  _numlines = lines;
90
+  _currline = 0;
91
+
92
+  // for some 1 line displays you can select a 10 pixel high font
93
+  if ((dotsize != 0) && (lines == 1)) {
94
+    _displayfunction |= LCD_5x10DOTS;
95
+  }
96
+
97
+  // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
98
+  // according to datasheet, we need at least 40ms after power rises above 2.7V
99
+  // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
100
+  delayMicroseconds(50000); 
101
+  // Now we pull both RS and R/W low to begin commands
102
+  digitalWrite(_rs_pin, LOW);
103
+  digitalWrite(_enable_pin, LOW);
104
+  if (_rw_pin != 255) { 
105
+    digitalWrite(_rw_pin, LOW);
106
+  }
107
+  
108
+  //put the LCD into 4 bit or 8 bit mode
109
+  if (! (_displayfunction & LCD_8BITMODE)) {
110
+    // this is according to the hitachi HD44780 datasheet
111
+    // figure 24, pg 46
112
+
113
+    // we start in 8bit mode, try to set 4 bit mode
114
+    write4bits(0x03);
115
+    delayMicroseconds(4500); // wait min 4.1ms
116
+
117
+    // second try
118
+    write4bits(0x03);
119
+    delayMicroseconds(4500); // wait min 4.1ms
120
+    
121
+    // third go!
122
+    write4bits(0x03); 
123
+    delayMicroseconds(150);
124
+
125
+    // finally, set to 4-bit interface
126
+    write4bits(0x02); 
127
+  } else {
128
+    // this is according to the hitachi HD44780 datasheet
129
+    // page 45 figure 23
130
+
131
+    // Send function set command sequence
132
+    command(LCD_FUNCTIONSET | _displayfunction);
133
+    delayMicroseconds(4500);  // wait more than 4.1ms
134
+
135
+    // second try
136
+    command(LCD_FUNCTIONSET | _displayfunction);
137
+    delayMicroseconds(150);
138
+
139
+    // third go
140
+    command(LCD_FUNCTIONSET | _displayfunction);
141
+  }
142
+
143
+  // finally, set # lines, font size, etc.
144
+  command(LCD_FUNCTIONSET | _displayfunction);  
145
+
146
+  // turn the display on with no cursor or blinking default
147
+  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
148
+  display();
149
+
150
+  // clear it off
151
+  clear();
152
+
153
+  // Initialize to default text direction (for romance languages)
154
+  _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
155
+  // set the entry mode
156
+  command(LCD_ENTRYMODESET | _displaymode);
157
+
158
+}
159
+
160
+/********** high level commands, for the user! */
161
+void LiquidCrystal::clear()
162
+{
163
+  command(LCD_CLEARDISPLAY);  // clear display, set cursor position to zero
164
+  delayMicroseconds(2000);  // this command takes a long time!
165
+}
166
+
167
+void LiquidCrystal::home()
168
+{
169
+  command(LCD_RETURNHOME);  // set cursor position to zero
170
+  delayMicroseconds(2000);  // this command takes a long time!
171
+}
172
+
173
+void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
174
+{
175
+  int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
176
+  if ( row > _numlines ) {
177
+    row = _numlines-1;    // we count rows starting w/0
178
+  }
179
+  
180
+  command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
181
+}
182
+
183
+// Turn the display on/off (quickly)
184
+void LiquidCrystal::noDisplay() {
185
+  _displaycontrol &= ~LCD_DISPLAYON;
186
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
187
+}
188
+void LiquidCrystal::display() {
189
+  _displaycontrol |= LCD_DISPLAYON;
190
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
191
+}
192
+
193
+// Turns the underline cursor on/off
194
+void LiquidCrystal::noCursor() {
195
+  _displaycontrol &= ~LCD_CURSORON;
196
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
197
+}
198
+void LiquidCrystal::cursor() {
199
+  _displaycontrol |= LCD_CURSORON;
200
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
201
+}
202
+
203
+// Turn on and off the blinking cursor
204
+void LiquidCrystal::noBlink() {
205
+  _displaycontrol &= ~LCD_BLINKON;
206
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
207
+}
208
+void LiquidCrystal::blink() {
209
+  _displaycontrol |= LCD_BLINKON;
210
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
211
+}
212
+
213
+// These commands scroll the display without changing the RAM
214
+void LiquidCrystal::scrollDisplayLeft(void) {
215
+  command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
216
+}
217
+void LiquidCrystal::scrollDisplayRight(void) {
218
+  command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
219
+}
220
+
221
+// This is for text that flows Left to Right
222
+void LiquidCrystal::leftToRight(void) {
223
+  _displaymode |= LCD_ENTRYLEFT;
224
+  command(LCD_ENTRYMODESET | _displaymode);
225
+}
226
+
227
+// This is for text that flows Right to Left
228
+void LiquidCrystal::rightToLeft(void) {
229
+  _displaymode &= ~LCD_ENTRYLEFT;
230
+  command(LCD_ENTRYMODESET | _displaymode);
231
+}
232
+
233
+// This will 'right justify' text from the cursor
234
+void LiquidCrystal::autoscroll(void) {
235
+  _displaymode |= LCD_ENTRYSHIFTINCREMENT;
236
+  command(LCD_ENTRYMODESET | _displaymode);
237
+}
238
+
239
+// This will 'left justify' text from the cursor
240
+void LiquidCrystal::noAutoscroll(void) {
241
+  _displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
242
+  command(LCD_ENTRYMODESET | _displaymode);
243
+}
244
+
245
+// Allows us to fill the first 8 CGRAM locations
246
+// with custom characters
247
+void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) {
248
+  location &= 0x7; // we only have 8 locations 0-7
249
+  command(LCD_SETCGRAMADDR | (location << 3));
250
+  for (int i=0; i<8; i++) {
251
+    write(charmap[i]);
252
+  }
253
+}
254
+
255
+/*********** mid level commands, for sending data/cmds */
256
+
257
+inline void LiquidCrystal::command(uint8_t value) {
258
+  send(value, LOW);
259
+}
260
+
261
+inline void LiquidCrystal::write(uint8_t value) {
262
+  send(value, HIGH);
263
+}
264
+
265
+/************ low level data pushing commands **********/
266
+
267
+// write either command or data, with automatic 4/8-bit selection
268
+void LiquidCrystal::send(uint8_t value, uint8_t mode) {
269
+  digitalWrite(_rs_pin, mode);
270
+
271
+  // if there is a RW pin indicated, set it low to Write
272
+  if (_rw_pin != 255) { 
273
+    digitalWrite(_rw_pin, LOW);
274
+  }
275
+  
276
+  if (_displayfunction & LCD_8BITMODE) {
277
+    write8bits(value); 
278
+  } else {
279
+    write4bits(value>>4);
280
+    write4bits(value);
281
+  }
282
+}
283
+
284
+void LiquidCrystal::pulseEnable(void) {
285
+  digitalWrite(_enable_pin, LOW);
286
+  delayMicroseconds(1);    
287
+  digitalWrite(_enable_pin, HIGH);
288
+  delayMicroseconds(1);    // enable pulse must be >450ns
289
+  digitalWrite(_enable_pin, LOW);
290
+  delayMicroseconds(100);   // commands need > 37us to settle
291
+}
292
+
293
+void LiquidCrystal::write4bits(uint8_t value) {
294
+  for (int i = 0; i < 4; i++) {
295
+    pinMode(_data_pins[i], OUTPUT);
296
+    digitalWrite(_data_pins[i], (value >> i) & 0x01);
297
+  }
298
+
299
+  pulseEnable();
300
+}
301
+
302
+void LiquidCrystal::write8bits(uint8_t value) {
303
+  for (int i = 0; i < 8; i++) {
304
+    pinMode(_data_pins[i], OUTPUT);
305
+    digitalWrite(_data_pins[i], (value >> i) & 0x01);
306
+  }
307
+  
308
+  pulseEnable();
309
+}

+ 104
- 0
ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal/LiquidCrystal.h View File

@@ -0,0 +1,104 @@
1
+#ifndef LiquidCrystal_h
2
+#define LiquidCrystal_h
3
+
4
+#include <inttypes.h>
5
+#include "Print.h"
6
+
7
+// commands
8
+#define LCD_CLEARDISPLAY 0x01
9
+#define LCD_RETURNHOME 0x02
10
+#define LCD_ENTRYMODESET 0x04
11
+#define LCD_DISPLAYCONTROL 0x08
12
+#define LCD_CURSORSHIFT 0x10
13
+#define LCD_FUNCTIONSET 0x20
14
+#define LCD_SETCGRAMADDR 0x40
15
+#define LCD_SETDDRAMADDR 0x80
16
+
17
+// flags for display entry mode
18
+#define LCD_ENTRYRIGHT 0x00
19
+#define LCD_ENTRYLEFT 0x02
20
+#define LCD_ENTRYSHIFTINCREMENT 0x01
21
+#define LCD_ENTRYSHIFTDECREMENT 0x00
22
+
23
+// flags for display on/off control
24
+#define LCD_DISPLAYON 0x04
25
+#define LCD_DISPLAYOFF 0x00
26
+#define LCD_CURSORON 0x02
27
+#define LCD_CURSOROFF 0x00
28
+#define LCD_BLINKON 0x01
29
+#define LCD_BLINKOFF 0x00
30
+
31
+// flags for display/cursor shift
32
+#define LCD_DISPLAYMOVE 0x08
33
+#define LCD_CURSORMOVE 0x00
34
+#define LCD_MOVERIGHT 0x04
35
+#define LCD_MOVELEFT 0x00
36
+
37
+// flags for function set
38
+#define LCD_8BITMODE 0x10
39
+#define LCD_4BITMODE 0x00
40
+#define LCD_2LINE 0x08
41
+#define LCD_1LINE 0x00
42
+#define LCD_5x10DOTS 0x04
43
+#define LCD_5x8DOTS 0x00
44
+
45
+class LiquidCrystal : public Print {
46
+public:
47
+  LiquidCrystal(uint8_t rs, uint8_t enable,
48
+		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
49
+		uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
50
+  LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
51
+		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
52
+		uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
53
+  LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
54
+		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
55
+  LiquidCrystal(uint8_t rs, uint8_t enable,
56
+		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
57
+
58
+  void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
59
+	    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
60
+	    uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
61
+    
62
+  void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
63
+
64
+  void clear();
65
+  void home();
66
+
67
+  void noDisplay();
68
+  void display();
69
+  void noBlink();
70
+  void blink();
71
+  void noCursor();
72
+  void cursor();
73
+  void scrollDisplayLeft();
74
+  void scrollDisplayRight();
75
+  void leftToRight();
76
+  void rightToLeft();
77
+  void autoscroll();
78
+  void noAutoscroll();
79
+
80
+  void createChar(uint8_t, uint8_t[]);
81
+  void setCursor(uint8_t, uint8_t); 
82
+  virtual void write(uint8_t);
83
+  void command(uint8_t);
84
+private:
85
+  void send(uint8_t, uint8_t);
86
+  void write4bits(uint8_t);
87
+  void write8bits(uint8_t);
88
+  void pulseEnable();
89
+
90
+  uint8_t _rs_pin; // LOW: command.  HIGH: character.
91
+  uint8_t _rw_pin; // LOW: write to LCD.  HIGH: read from LCD.
92
+  uint8_t _enable_pin; // activated by a HIGH pulse.
93
+  uint8_t _data_pins[8];
94
+
95
+  uint8_t _displayfunction;
96
+  uint8_t _displaycontrol;
97
+  uint8_t _displaymode;
98
+
99
+  uint8_t _initialized;
100
+
101
+  uint8_t _numlines,_currline;
102
+};
103
+
104
+#endif

+ 37
- 0
ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal/keywords.txt View File

@@ -0,0 +1,37 @@
1
+#######################################
2
+# Syntax Coloring Map For LiquidCrystal
3
+#######################################
4
+
5
+#######################################
6
+# Datatypes (KEYWORD1)
7
+#######################################
8
+
9
+LiquidCrystal	KEYWORD1
10
+
11
+#######################################
12
+# Methods and Functions (KEYWORD2)
13
+#######################################
14
+
15
+begin	KEYWORD2
16
+clear	KEYWORD2
17
+home	KEYWORD2
18
+print	KEYWORD2
19
+setCursor	KEYWORD2
20
+cursor	KEYWORD2
21
+noCursor	KEYWORD2
22
+blink	KEYWORD2
23
+noBlink	KEYWORD2
24
+display	KEYWORD2
25
+noDisplay	KEYWORD2
26
+autoscroll	KEYWORD2
27
+noAutoscroll	KEYWORD2
28
+leftToRight	KEYWORD2
29
+rightToLeft	KEYWORD2
30
+scrollDisplayLeft	KEYWORD2
31
+scrollDisplayRight	KEYWORD2
32
+createChar	KEYWORD2
33
+
34
+#######################################
35
+# Constants (LITERAL1)
36
+#######################################
37
+

+ 61
- 0
ArduinoAddons/Arduino_0.xx/libraries/SPI/SPI.cpp View File

@@ -0,0 +1,61 @@
1
+/*
2
+ * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
3
+ * SPI Master library for arduino.
4
+ *
5
+ * This file is free software; you can redistribute it and/or modify
6
+ * it under the terms of either the GNU General Public License version 2
7
+ * or the GNU Lesser General Public License version 2.1, both as
8
+ * published by the Free Software Foundation.
9
+ */
10
+
11
+#include "pins_arduino.h"
12
+#include "SPI.h"
13
+
14
+SPIClass SPI;
15
+
16
+void SPIClass::begin() {
17
+  // Set direction register for SCK and MOSI pin.
18
+  // MISO pin automatically overrides to INPUT.
19
+  // When the SS pin is set as OUTPUT, it can be used as
20
+  // a general purpose output port (it doesn't influence
21
+  // SPI operations).
22
+
23
+  pinMode(SCK, OUTPUT);
24
+  pinMode(MOSI, OUTPUT);
25
+  pinMode(SS, OUTPUT);
26
+  
27
+  digitalWrite(SCK, LOW);
28
+  digitalWrite(MOSI, LOW);
29
+  digitalWrite(SS, HIGH);
30
+
31
+  // Warning: if the SS pin ever becomes a LOW INPUT then SPI 
32
+  // automatically switches to Slave, so the data direction of 
33
+  // the SS pin MUST be kept as OUTPUT.
34
+  SPCR |= _BV(MSTR);
35
+  SPCR |= _BV(SPE);
36
+}
37
+
38
+void SPIClass::end() {
39
+  SPCR &= ~_BV(SPE);
40
+}
41
+
42
+void SPIClass::setBitOrder(uint8_t bitOrder)
43
+{
44
+  if(bitOrder == LSBFIRST) {
45
+    SPCR |= _BV(DORD);
46
+  } else {
47
+    SPCR &= ~(_BV(DORD));
48
+  }
49
+}
50
+
51
+void SPIClass::setDataMode(uint8_t mode)
52
+{
53
+  SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
54
+}
55
+
56
+void SPIClass::setClockDivider(uint8_t rate)
57
+{
58
+  SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
59
+  SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
60
+}
61
+

+ 70
- 0
ArduinoAddons/Arduino_0.xx/libraries/SPI/SPI.h View File

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
3
+ * SPI Master library for arduino.
4
+ *
5
+ * This file is free software; you can redistribute it and/or modify
6
+ * it under the terms of either the GNU General Public License version 2
7
+ * or the GNU Lesser General Public License version 2.1, both as
8
+ * published by the Free Software Foundation.
9
+ */
10
+
11
+#ifndef _SPI_H_INCLUDED
12
+#define _SPI_H_INCLUDED
13
+
14
+#include <stdio.h>
15
+#include <WProgram.h>
16
+#include <avr/pgmspace.h>
17
+
18
+#define SPI_CLOCK_DIV4 0x00
19
+#define SPI_CLOCK_DIV16 0x01
20
+#define SPI_CLOCK_DIV64 0x02
21
+#define SPI_CLOCK_DIV128 0x03
22
+#define SPI_CLOCK_DIV2 0x04
23
+#define SPI_CLOCK_DIV8 0x05
24
+#define SPI_CLOCK_DIV32 0x06
25
+#define SPI_CLOCK_DIV64 0x07
26
+
27
+#define SPI_MODE0 0x00
28
+#define SPI_MODE1 0x04
29
+#define SPI_MODE2 0x08
30
+#define SPI_MODE3 0x0C
31
+
32
+#define SPI_MODE_MASK 0x0C  // CPOL = bit 3, CPHA = bit 2 on SPCR
33
+#define SPI_CLOCK_MASK 0x03  // SPR1 = bit 1, SPR0 = bit 0 on SPCR
34
+#define SPI_2XCLOCK_MASK 0x01  // SPI2X = bit 0 on SPSR
35
+
36
+class SPIClass {
37
+public:
38
+  inline static byte transfer(byte _data);
39
+
40
+  // SPI Configuration methods
41
+
42
+  inline static void attachInterrupt();
43
+  inline static void detachInterrupt(); // Default
44
+
45
+  static void begin(); // Default
46
+  static void end();
47
+
48
+  static void setBitOrder(uint8_t);
49
+  static void setDataMode(uint8_t);
50
+  static void setClockDivider(uint8_t);
51
+};
52
+
53
+extern SPIClass SPI;
54
+
55
+byte SPIClass::transfer(byte _data) {
56
+  SPDR = _data;
57
+  while (!(SPSR & _BV(SPIF)))
58
+    ;
59
+  return SPDR;
60
+}
61
+
62
+void SPIClass::attachInterrupt() {
63
+  SPCR |= _BV(SPIE);
64
+}
65
+
66
+void SPIClass::detachInterrupt() {
67
+  SPCR &= ~_BV(SPIE);
68
+}
69
+
70
+#endif

+ 36
- 0
ArduinoAddons/Arduino_0.xx/libraries/SPI/keywords.txt View File

@@ -0,0 +1,36 @@
1
+#######################################
2
+# Syntax Coloring Map SPI
3
+#######################################
4
+
5
+#######################################
6
+# Datatypes (KEYWORD1)
7
+#######################################
8
+
9
+SPI	KEYWORD1
10
+
11
+#######################################
12
+# Methods and Functions (KEYWORD2)
13
+#######################################
14
+begin	KEYWORD2
15
+end	KEYWORD2
16
+transfer	KEYWORD2
17
+setBitOrder	KEYWORD2
18
+setDataMode	KEYWORD2
19
+setClockDivider	KEYWORD2
20
+
21
+
22
+#######################################
23
+# Constants (LITERAL1)
24
+#######################################
25
+SPI_CLOCK_DIV4	LITERAL1
26
+SPI_CLOCK_DIV16	LITERAL1
27
+SPI_CLOCK_DIV64	LITERAL1
28
+SPI_CLOCK_DIV128	LITERAL1
29
+SPI_CLOCK_DIV2	LITERAL1
30
+SPI_CLOCK_DIV8	LITERAL1
31
+SPI_CLOCK_DIV32	LITERAL1
32
+SPI_CLOCK_DIV64	LITERAL1
33
+SPI_MODE0	LITERAL1
34
+SPI_MODE1	LITERAL1
35
+SPI_MODE2	LITERAL1
36
+SPI_MODE3	LITERAL1

+ 310
- 0
ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal/LiquidCrystal.cpp View File

@@ -0,0 +1,310 @@
1
+#include "LiquidCrystal.h"
2
+
3
+#include <stdio.h>
4
+#include <string.h>
5
+#include <inttypes.h>
6
+#include "Arduino.h"
7
+
8
+// When the display powers up, it is configured as follows:
9
+//
10
+// 1. Display clear
11
+// 2. Function set: 
12
+//    DL = 1; 8-bit interface data 
13
+//    N = 0; 1-line display 
14
+//    F = 0; 5x8 dot character font 
15
+// 3. Display on/off control: 
16
+//    D = 0; Display off 
17
+//    C = 0; Cursor off 
18
+//    B = 0; Blinking off 
19
+// 4. Entry mode set: 
20
+//    I/D = 1; Increment by 1 
21
+//    S = 0; No shift 
22
+//
23
+// Note, however, that resetting the Arduino doesn't reset the LCD, so we
24
+// can't assume that its in that state when a sketch starts (and the
25
+// LiquidCrystal constructor is called).
26
+
27
+LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
28
+			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
29
+			     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
30
+{
31
+  init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);
32
+}
33
+
34
+LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable,
35
+			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
36
+			     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
37
+{
38
+  init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7);
39
+}
40
+
41
+LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
42
+			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
43
+{
44
+  init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0);
45
+}
46
+
47
+LiquidCrystal::LiquidCrystal(uint8_t rs,  uint8_t enable,
48
+			     uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
49
+{
50
+  init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
51
+}
52
+
53
+void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
54
+			 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
55
+			 uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
56
+{
57
+  _rs_pin = rs;
58
+  _rw_pin = rw;
59
+  _enable_pin = enable;
60
+  
61
+  _data_pins[0] = d0;
62
+  _data_pins[1] = d1;
63
+  _data_pins[2] = d2;
64
+  _data_pins[3] = d3; 
65
+  _data_pins[4] = d4;
66
+  _data_pins[5] = d5;
67
+  _data_pins[6] = d6;
68
+  _data_pins[7] = d7; 
69
+
70
+  pinMode(_rs_pin, OUTPUT);
71
+  // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
72
+  if (_rw_pin != 255) { 
73
+    pinMode(_rw_pin, OUTPUT);
74
+  }
75
+  pinMode(_enable_pin, OUTPUT);
76
+  
77
+  if (fourbitmode)
78
+    _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
79
+  else 
80
+    _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
81
+  
82
+  begin(16, 1);  
83
+}
84
+
85
+void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
86
+  if (lines > 1) {
87
+    _displayfunction |= LCD_2LINE;
88
+  }
89
+  _numlines = lines;
90
+  _currline = 0;
91
+
92
+  // for some 1 line displays you can select a 10 pixel high font
93
+  if ((dotsize != 0) && (lines == 1)) {
94
+    _displayfunction |= LCD_5x10DOTS;
95
+  }
96
+
97
+  // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
98
+  // according to datasheet, we need at least 40ms after power rises above 2.7V
99
+  // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
100
+  delayMicroseconds(50000); 
101
+  // Now we pull both RS and R/W low to begin commands
102
+  digitalWrite(_rs_pin, LOW);
103
+  digitalWrite(_enable_pin, LOW);
104
+  if (_rw_pin != 255) { 
105
+    digitalWrite(_rw_pin, LOW);
106
+  }
107
+  
108
+  //put the LCD into 4 bit or 8 bit mode
109
+  if (! (_displayfunction & LCD_8BITMODE)) {
110
+    // this is according to the hitachi HD44780 datasheet
111
+    // figure 24, pg 46
112
+
113
+    // we start in 8bit mode, try to set 4 bit mode
114
+    write4bits(0x03);
115
+    delayMicroseconds(4500); // wait min 4.1ms
116
+
117
+    // second try
118
+    write4bits(0x03);
119
+    delayMicroseconds(4500); // wait min 4.1ms
120
+    
121
+    // third go!
122
+    write4bits(0x03); 
123
+    delayMicroseconds(150);
124
+
125
+    // finally, set to 4-bit interface
126
+    write4bits(0x02); 
127
+  } else {
128
+    // this is according to the hitachi HD44780 datasheet
129
+    // page 45 figure 23
130
+
131
+    // Send function set command sequence
132
+    command(LCD_FUNCTIONSET | _displayfunction);
133
+    delayMicroseconds(4500);  // wait more than 4.1ms
134
+
135
+    // second try
136
+    command(LCD_FUNCTIONSET | _displayfunction);
137
+    delayMicroseconds(150);
138
+
139
+    // third go
140
+    command(LCD_FUNCTIONSET | _displayfunction);
141
+  }
142
+
143
+  // finally, set # lines, font size, etc.
144
+  command(LCD_FUNCTIONSET | _displayfunction);  
145
+
146
+  // turn the display on with no cursor or blinking default
147
+  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
148
+  display();
149
+
150
+  // clear it off
151
+  clear();
152
+
153
+  // Initialize to default text direction (for romance languages)
154
+  _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
155
+  // set the entry mode
156
+  command(LCD_ENTRYMODESET | _displaymode);
157
+
158
+}
159
+
160
+/********** high level commands, for the user! */
161
+void LiquidCrystal::clear()
162
+{
163
+  command(LCD_CLEARDISPLAY);  // clear display, set cursor position to zero
164
+  delayMicroseconds(2000);  // this command takes a long time!
165
+}
166
+
167
+void LiquidCrystal::home()
168
+{
169
+  command(LCD_RETURNHOME);  // set cursor position to zero
170
+  delayMicroseconds(2000);  // this command takes a long time!
171
+}
172
+
173
+void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
174
+{
175
+  int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
176
+  if ( row >= _numlines ) {
177
+    row = _numlines-1;    // we count rows starting w/0
178
+  }
179
+  
180
+  command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
181
+}
182
+
183
+// Turn the display on/off (quickly)
184
+void LiquidCrystal::noDisplay() {
185
+  _displaycontrol &= ~LCD_DISPLAYON;
186
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
187
+}
188
+void LiquidCrystal::display() {
189
+  _displaycontrol |= LCD_DISPLAYON;
190
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
191
+}
192
+
193
+// Turns the underline cursor on/off
194
+void LiquidCrystal::noCursor() {
195
+  _displaycontrol &= ~LCD_CURSORON;
196
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
197
+}
198
+void LiquidCrystal::cursor() {
199
+  _displaycontrol |= LCD_CURSORON;
200
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
201
+}
202
+
203
+// Turn on and off the blinking cursor
204
+void LiquidCrystal::noBlink() {
205
+  _displaycontrol &= ~LCD_BLINKON;
206
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
207
+}
208
+void LiquidCrystal::blink() {
209
+  _displaycontrol |= LCD_BLINKON;
210
+  command(LCD_DISPLAYCONTROL | _displaycontrol);
211
+}
212
+
213
+// These commands scroll the display without changing the RAM
214
+void LiquidCrystal::scrollDisplayLeft(void) {
215
+  command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
216
+}
217
+void LiquidCrystal::scrollDisplayRight(void) {
218
+  command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
219
+}
220
+
221
+// This is for text that flows Left to Right
222
+void LiquidCrystal::leftToRight(void) {
223
+  _displaymode |= LCD_ENTRYLEFT;
224
+  command(LCD_ENTRYMODESET | _displaymode);
225
+}
226
+
227
+// This is for text that flows Right to Left
228
+void LiquidCrystal::rightToLeft(void) {
229
+  _displaymode &= ~LCD_ENTRYLEFT;
230
+  command(LCD_ENTRYMODESET | _displaymode);
231
+}
232
+
233
+// This will 'right justify' text from the cursor
234
+void LiquidCrystal::autoscroll(void) {
235
+  _displaymode |= LCD_ENTRYSHIFTINCREMENT;
236
+  command(LCD_ENTRYMODESET | _displaymode);
237
+}
238
+
239
+// This will 'left justify' text from the cursor
240
+void LiquidCrystal::noAutoscroll(void) {
241
+  _displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
242
+  command(LCD_ENTRYMODESET | _displaymode);
243
+}
244
+
245
+// Allows us to fill the first 8 CGRAM locations
246
+// with custom characters
247
+void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) {
248
+  location &= 0x7; // we only have 8 locations 0-7
249
+  command(LCD_SETCGRAMADDR | (location << 3));
250
+  for (int i=0; i<8; i++) {
251
+    write(charmap[i]);
252
+  }
253
+}
254
+
255
+/*********** mid level commands, for sending data/cmds */
256
+
257
+inline void LiquidCrystal::command(uint8_t value) {
258
+  send(value, LOW);
259
+}
260
+
261
+inline size_t LiquidCrystal::write(uint8_t value) {
262
+  send(value, HIGH);
263
+  return 1; // assume sucess
264
+}
265
+
266
+/************ low level data pushing commands **********/
267
+
268
+// write either command or data, with automatic 4/8-bit selection
269
+void LiquidCrystal::send(uint8_t value, uint8_t mode) {
270
+  digitalWrite(_rs_pin, mode);
271
+
272
+  // if there is a RW pin indicated, set it low to Write
273
+  if (_rw_pin != 255) { 
274
+    digitalWrite(_rw_pin, LOW);
275
+  }
276
+  
277
+  if (_displayfunction & LCD_8BITMODE) {
278
+    write8bits(value); 
279
+  } else {
280
+    write4bits(value>>4);
281
+    write4bits(value);
282
+  }
283
+}
284
+
285
+void LiquidCrystal::pulseEnable(void) {
286
+  digitalWrite(_enable_pin, LOW);
287
+  delayMicroseconds(1);    
288
+  digitalWrite(_enable_pin, HIGH);
289
+  delayMicroseconds(1);    // enable pulse must be >450ns
290
+  digitalWrite(_enable_pin, LOW);
291
+  delayMicroseconds(100);   // commands need > 37us to settle
292
+}
293
+
294
+void LiquidCrystal::write4bits(uint8_t value) {
295
+  for (int i = 0; i < 4; i++) {
296
+    pinMode(_data_pins[i], OUTPUT);
297
+    digitalWrite(_data_pins[i], (value >> i) & 0x01);
298
+  }
299
+
300
+  pulseEnable();
301
+}
302
+
303
+void LiquidCrystal::write8bits(uint8_t value) {
304
+  for (int i = 0; i < 8; i++) {
305
+    pinMode(_data_pins[i], OUTPUT);
306
+    digitalWrite(_data_pins[i], (value >> i) & 0x01);
307
+  }
308
+  
309
+  pulseEnable();
310
+}

+ 106
- 0
ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal/LiquidCrystal.h View File

@@ -0,0 +1,106 @@
1
+#ifndef LiquidCrystal_h
2
+#define LiquidCrystal_h
3
+
4
+#include <inttypes.h>
5
+#include "Print.h"
6
+
7
+// commands
8
+#define LCD_CLEARDISPLAY 0x01
9
+#define LCD_RETURNHOME 0x02
10
+#define LCD_ENTRYMODESET 0x04
11
+#define LCD_DISPLAYCONTROL 0x08
12
+#define LCD_CURSORSHIFT 0x10
13
+#define LCD_FUNCTIONSET 0x20
14
+#define LCD_SETCGRAMADDR 0x40
15
+#define LCD_SETDDRAMADDR 0x80
16
+
17
+// flags for display entry mode
18
+#define LCD_ENTRYRIGHT 0x00
19
+#define LCD_ENTRYLEFT 0x02
20
+#define LCD_ENTRYSHIFTINCREMENT 0x01
21
+#define LCD_ENTRYSHIFTDECREMENT 0x00
22
+
23
+// flags for display on/off control
24
+#define LCD_DISPLAYON 0x04
25
+#define LCD_DISPLAYOFF 0x00
26
+#define LCD_CURSORON 0x02
27
+#define LCD_CURSOROFF 0x00
28
+#define LCD_BLINKON 0x01
29
+#define LCD_BLINKOFF 0x00
30
+
31
+// flags for display/cursor shift
32
+#define LCD_DISPLAYMOVE 0x08
33
+#define LCD_CURSORMOVE 0x00
34
+#define LCD_MOVERIGHT 0x04
35
+#define LCD_MOVELEFT 0x00
36
+
37
+// flags for function set
38
+#define LCD_8BITMODE 0x10
39
+#define LCD_4BITMODE 0x00
40
+#define LCD_2LINE 0x08
41
+#define LCD_1LINE 0x00
42
+#define LCD_5x10DOTS 0x04
43
+#define LCD_5x8DOTS 0x00
44
+
45
+class LiquidCrystal : public Print {
46
+public:
47
+  LiquidCrystal(uint8_t rs, uint8_t enable,
48
+		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
49
+		uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
50
+  LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
51
+		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
52
+		uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
53
+  LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
54
+		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
55
+  LiquidCrystal(uint8_t rs, uint8_t enable,
56
+		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
57
+
58
+  void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
59
+	    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
60
+	    uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
61
+    
62
+  void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
63
+
64
+  void clear();
65
+  void home();
66
+
67
+  void noDisplay();
68
+  void display();
69
+  void noBlink();
70
+  void blink();
71
+  void noCursor();
72
+  void cursor();
73
+  void scrollDisplayLeft();
74
+  void scrollDisplayRight();
75
+  void leftToRight();
76
+  void rightToLeft();
77
+  void autoscroll();
78
+  void noAutoscroll();
79
+
80
+  void createChar(uint8_t, uint8_t[]);
81
+  void setCursor(uint8_t, uint8_t); 
82
+  virtual size_t write(uint8_t);
83
+  void command(uint8_t);
84
+  
85
+  using Print::write;
86
+private:
87
+  void send(uint8_t, uint8_t);
88
+  void write4bits(uint8_t);
89
+  void write8bits(uint8_t);
90
+  void pulseEnable();
91
+
92
+  uint8_t _rs_pin; // LOW: command.  HIGH: character.
93
+  uint8_t _rw_pin; // LOW: write to LCD.  HIGH: read from LCD.
94
+  uint8_t _enable_pin; // activated by a HIGH pulse.
95
+  uint8_t _data_pins[8];
96
+
97
+  uint8_t _displayfunction;
98
+  uint8_t _displaycontrol;
99
+  uint8_t _displaymode;
100
+
101
+  uint8_t _initialized;
102
+
103
+  uint8_t _numlines,_currline;
104
+};
105
+
106
+#endif

+ 37
- 0
ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal/keywords.txt View File

@@ -0,0 +1,37 @@
1
+#######################################
2
+# Syntax Coloring Map For LiquidCrystal
3
+#######################################
4
+
5
+#######################################
6
+# Datatypes (KEYWORD1)
7
+#######################################
8
+
9
+LiquidCrystal	KEYWORD1
10
+
11
+#######################################
12
+# Methods and Functions (KEYWORD2)
13
+#######################################
14
+
15
+begin	KEYWORD2
16
+clear	KEYWORD2
17
+home	KEYWORD2
18
+print	KEYWORD2
19
+setCursor	KEYWORD2
20
+cursor	KEYWORD2
21
+noCursor	KEYWORD2
22
+blink	KEYWORD2
23
+noBlink	KEYWORD2
24
+display	KEYWORD2
25
+noDisplay	KEYWORD2
26
+autoscroll	KEYWORD2
27
+noAutoscroll	KEYWORD2
28
+leftToRight	KEYWORD2
29
+rightToLeft	KEYWORD2
30
+scrollDisplayLeft	KEYWORD2
31
+scrollDisplayRight	KEYWORD2
32
+createChar	KEYWORD2
33
+
34
+#######################################
35
+# Constants (LITERAL1)
36
+#######################################
37
+

+ 66
- 0
ArduinoAddons/Arduino_1.x.x/libraries/SPI/SPI.cpp View File

@@ -0,0 +1,66 @@
1
+/*
2
+ * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
3
+ * SPI Master library for arduino.
4
+ *
5
+ * This file is free software; you can redistribute it and/or modify
6
+ * it under the terms of either the GNU General Public License version 2
7
+ * or the GNU Lesser General Public License version 2.1, both as
8
+ * published by the Free Software Foundation.
9
+ */
10
+
11
+#include "pins_arduino.h"
12
+#include "SPI.h"
13
+
14
+SPIClass SPI;
15
+
16
+void SPIClass::begin() {
17
+
18
+  // Set SS to high so a connected chip will be "deselected" by default
19
+  digitalWrite(SS, HIGH);
20
+
21
+  // When the SS pin is set as OUTPUT, it can be used as
22
+  // a general purpose output port (it doesn't influence
23
+  // SPI operations).
24
+  pinMode(SS, OUTPUT);
25
+
26
+  // Warning: if the SS pin ever becomes a LOW INPUT then SPI
27
+  // automatically switches to Slave, so the data direction of
28
+  // the SS pin MUST be kept as OUTPUT.
29
+  SPCR |= _BV(MSTR);
30
+  SPCR |= _BV(SPE);
31
+
32
+  // Set direction register for SCK and MOSI pin.
33
+  // MISO pin automatically overrides to INPUT.
34
+  // By doing this AFTER enabling SPI, we avoid accidentally
35
+  // clocking in a single bit since the lines go directly
36
+  // from "input" to SPI control.  
37
+  // http://code.google.com/p/arduino/issues/detail?id=888
38
+  pinMode(SCK, OUTPUT);
39
+  pinMode(MOSI, OUTPUT);
40
+}
41
+
42
+
43
+void SPIClass::end() {
44
+  SPCR &= ~_BV(SPE);
45
+}
46
+
47
+void SPIClass::setBitOrder(uint8_t bitOrder)
48
+{
49
+  if(bitOrder == LSBFIRST) {
50
+    SPCR |= _BV(DORD);
51
+  } else {
52
+    SPCR &= ~(_BV(DORD));
53
+  }
54
+}
55
+
56
+void SPIClass::setDataMode(uint8_t mode)
57
+{
58
+  SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
59
+}
60
+
61
+void SPIClass::setClockDivider(uint8_t rate)
62
+{
63
+  SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
64
+  SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
65
+}
66
+

+ 70
- 0
ArduinoAddons/Arduino_1.x.x/libraries/SPI/SPI.h View File

@@ -0,0 +1,70 @@
1
+/*
2
+ * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
3
+ * SPI Master library for arduino.
4
+ *
5
+ * This file is free software; you can redistribute it and/or modify
6
+ * it under the terms of either the GNU General Public License version 2
7
+ * or the GNU Lesser General Public License version 2.1, both as
8
+ * published by the Free Software Foundation.
9
+ */
10
+
11
+#ifndef _SPI_H_INCLUDED
12
+#define _SPI_H_INCLUDED
13
+
14
+#include <stdio.h>
15
+#include <Arduino.h>
16
+#include <avr/pgmspace.h>
17
+
18
+#define SPI_CLOCK_DIV4 0x00
19
+#define SPI_CLOCK_DIV16 0x01
20
+#define SPI_CLOCK_DIV64 0x02
21
+#define SPI_CLOCK_DIV128 0x03
22
+#define SPI_CLOCK_DIV2 0x04
23
+#define SPI_CLOCK_DIV8 0x05
24
+#define SPI_CLOCK_DIV32 0x06
25
+//#define SPI_CLOCK_DIV64 0x07
26
+
27
+#define SPI_MODE0 0x00
28
+#define SPI_MODE1 0x04
29
+#define SPI_MODE2 0x08
30
+#define SPI_MODE3 0x0C
31
+
32
+#define SPI_MODE_MASK 0x0C  // CPOL = bit 3, CPHA = bit 2 on SPCR
33
+#define SPI_CLOCK_MASK 0x03  // SPR1 = bit 1, SPR0 = bit 0 on SPCR
34
+#define SPI_2XCLOCK_MASK 0x01  // SPI2X = bit 0 on SPSR
35
+
36
+class SPIClass {
37
+public:
38
+  inline static byte transfer(byte _data);
39
+
40
+  // SPI Configuration methods
41
+
42
+  inline static void attachInterrupt();
43
+  inline static void detachInterrupt(); // Default
44
+
45
+  static void begin(); // Default
46
+  static void end();
47
+
48
+  static void setBitOrder(uint8_t);
49
+  static void setDataMode(uint8_t);
50
+  static void setClockDivider(uint8_t);
51
+};
52
+
53
+extern SPIClass SPI;
54
+
55
+byte SPIClass::transfer(byte _data) {
56
+  SPDR = _data;
57
+  while (!(SPSR & _BV(SPIF)))
58
+    ;
59
+  return SPDR;
60
+}
61
+
62
+void SPIClass::attachInterrupt() {
63
+  SPCR |= _BV(SPIE);
64
+}
65
+
66
+void SPIClass::detachInterrupt() {
67
+  SPCR &= ~_BV(SPIE);
68
+}
69
+
70
+#endif

+ 36
- 0
ArduinoAddons/Arduino_1.x.x/libraries/SPI/keywords.txt View File

@@ -0,0 +1,36 @@
1
+#######################################
2
+# Syntax Coloring Map SPI
3
+#######################################
4
+
5
+#######################################
6
+# Datatypes (KEYWORD1)
7
+#######################################
8
+
9
+SPI	KEYWORD1
10
+
11
+#######################################
12
+# Methods and Functions (KEYWORD2)
13
+#######################################
14
+begin	KEYWORD2
15
+end	KEYWORD2
16
+transfer	KEYWORD2
17
+setBitOrder	KEYWORD2
18
+setDataMode	KEYWORD2
19
+setClockDivider	KEYWORD2
20
+
21
+
22
+#######################################
23
+# Constants (LITERAL1)
24
+#######################################
25
+SPI_CLOCK_DIV4	LITERAL1
26
+SPI_CLOCK_DIV16	LITERAL1
27
+SPI_CLOCK_DIV64	LITERAL1
28
+SPI_CLOCK_DIV128	LITERAL1
29
+SPI_CLOCK_DIV2	LITERAL1
30
+SPI_CLOCK_DIV8	LITERAL1
31
+SPI_CLOCK_DIV32	LITERAL1
32
+SPI_CLOCK_DIV64	LITERAL1
33
+SPI_MODE0	LITERAL1
34
+SPI_MODE1	LITERAL1
35
+SPI_MODE2	LITERAL1
36
+SPI_MODE3	LITERAL1

+ 63
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/boards.txt View File

@@ -0,0 +1,63 @@
1
+############################################################
2
+
3
+atmega644.name=Sanguino W/ ATmega644P
4
+
5
+atmega644.upload.protocol=stk500
6
+atmega644.upload.maximum_size=63488
7
+atmega644.upload.speed=57600
8
+
9
+atmega644.bootloader.low_fuses=0xFF
10
+atmega644.bootloader.high_fuses=0x9A
11
+atmega644.bootloader.extended_fuses=0xFF
12
+atmega644.bootloader.path=atmega
13
+atmega644.bootloader.file=ATmegaBOOT_168_atmega644p.hex
14
+#atmega644.bootloader.file=ATmegaBOOT_644P.hex
15
+atmega644.bootloader.unlock_bits=0x3F
16
+atmega644.bootloader.lock_bits=0x0F
17
+
18
+atmega644.build.mcu=atmega644p
19
+atmega644.build.f_cpu=16000000L
20
+atmega644.build.core=arduino
21
+atmega644.build.variant=standard
22
+##############################################################
23
+
24
+atmega12848m.name=Sanguino W/ ATmega1284p 8mhz
25
+
26
+atmega12848m.upload.protocol=stk500
27
+atmega12848m.upload.maximum_size=131072
28
+atmega12848m.upload.speed=19200
29
+
30
+atmega12848m.bootloader.low_fuses=0xFD
31
+atmega12848m.bootloader.high_fuses=0x9A
32
+atmega12848m.bootloader.extended_fuses=0xFF
33
+atmega12848m.bootloader.path=atmega
34
+atmega12848m.bootloader.file=ATmegaBOOT_168_atmega1284p_8m.hex
35
+atmega12848m.bootloader.unlock_bits=0x3F
36
+atmega12848m.bootloader.lock_bits=0x0F
37
+
38
+atmega12848m.build.mcu=atmega1284p
39
+atmega12848m.build.f_cpu=8000000L
40
+atmega12848m.build.core=arduino
41
+atmega12848m.build.variant=standard
42
+
43
+##############################################################
44
+
45
+atmega1284.name=Sanguino W/ ATmega1284p 16mhz
46
+
47
+atmega1284.upload.protocol=stk500
48
+atmega1284.upload.maximum_size=131072
49
+atmega1284.upload.speed=57600
50
+
51
+atmega1284.bootloader.low_fuses=0xFF
52
+atmega1284.bootloader.high_fuses=0x9A
53
+atmega1284.bootloader.extended_fuses=0xFF
54
+atmega1284.bootloader.path=atmega
55
+atmega1284.bootloader.file=ATmegaBOOT_168_atmega1284p.hex
56
+atmega1284.bootloader.unlock_bits=0x3F
57
+atmega1284.bootloader.lock_bits=0x0F
58
+
59
+atmega1284.build.mcu=atmega1284p
60
+atmega1284.build.f_cpu=16000000L
61
+atmega1284.build.core=arduino
62
+atmega1284.build.variant=standard
63
+#

+ 1071
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/ATmegaBOOT_168.c
File diff suppressed because it is too large
View File


+ 130
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/ATmegaBOOT_168_atmega1284p.hex View File

@@ -0,0 +1,130 @@
1
+:020000021000EC
2
+:10F000000C9446F80C9465F80C9465F80C9465F82B
3
+:10F010000C9465F80C9465F80C9465F80C9465F8FC
4
+:10F020000C9465F80C9465F80C9465F80C9465F8EC
5
+:10F030000C9465F80C9465F80C9465F80C9465F8DC
6
+:10F040000C9465F80C9465F80C9465F80C9465F8CC
7
+:10F050000C9465F80C9465F80C9465F80C9465F8BC
8
+:10F060000C9465F80C9465F80C9465F80C9465F8AC
9
+:10F070000C9465F80C9465F80C9465F80C9465F89C
10
+:10F080000C9465F80C9465F80C9465F811241FBE77
11
+:10F09000CFEFD0E4DEBFCDBF11E0A0E0B1E0E8EDFE
12
+:10F0A000F7EF01E00BBF02C007900D92A230B1074D
13
+:10F0B000D9F712E0A2E0B1E001C01D92AD30B10776
14
+:10F0C000E1F70E947EF90C94EAFB0C9400F8909111
15
+:10F0D0000201913019F0923041F008959091C000F2
16
+:10F0E00095FFFCCF8093C60008959091C80095FFCE
17
+:10F0F000FCCF8093CE0008951F93982F95959595FA
18
+:10F1000095959595905D182F1F701A304CF4105DF1
19
+:10F11000892F0E9467F8812F0E9467F81F91089538
20
+:10F12000195A892F0E9467F8812F0E9467F81F9152
21
+:10F130000895EF92FF920F931F9380910201813007
22
+:10F1400069F1823031F080E01F910F91FF90EF90D4
23
+:10F150000895EE24FF2487018091C80087FD17C021
24
+:10F160000894E11CF11C011D111D81E4E81682E4E4
25
+:10F17000F8068FE0080780E0180770F3E0910401BB
26
+:10F18000F091050109958091C80087FFE9CF809132
27
+:10F19000CE001F910F91FF90EF900895EE24FF2471
28
+:10F1A00087018091C00087FD17C00894E11CF11C05
29
+:10F1B000011D111D81E4E81682E4F8068FE00807BE
30
+:10F1C00080E0180770F3E0910401F09105010995C2
31
+:10F1D0008091C00087FFE9CF8091C6001F910F91F9
32
+:10F1E000FF90EF9008951F930E9499F8182F0E94A6
33
+:10F1F00067F8113634F410330CF01053812F1F913F
34
+:10F2000008951755812F1F9108951F930E94F3F8B9
35
+:10F21000182F0E94F3F81295107F810F1F91089507
36
+:10F2200020910201882339F0213031F0223061F041
37
+:10F2300081508823C9F708959091C00097FFFCCFB3
38
+:10F240009091C6008150F5CF9091C80097FFFCCFF8
39
+:10F250009091CE008150EDCF1F93182F0E9499F806
40
+:10F26000803281F0809103018F5F809303018530AC
41
+:10F2700011F01F910895E0910401F09105010995A5
42
+:10F280001F91089584E10E9467F8812F0E9467F81A
43
+:10F2900080E10E9467F8EDCF0E9499F8803271F00A
44
+:10F2A000809103018F5F80930301853009F00895F9
45
+:10F2B000E0910401F09105010995089584E10E940F
46
+:10F2C00067F880E10E9467F8089515C0289A2FEF2B
47
+:10F2D00031EE44E0215030404040E1F700C00000F2
48
+:10F2E00028982FEF31EE44E0215030404040E1F7C4
49
+:10F2F00000C000008150882349F70895EF92FF92E3
50
+:10F300000F931F93CF93DF93000081E0809302015E
51
+:10F3100080E18093C4001092C5001092C00086E086
52
+:10F320008093C20088E18093C100209A81E00E940E
53
+:10F3300065F90E9499F88033B1F18133B9F18034D5
54
+:10F3400009F454C0813409F45AC0823409F469C004
55
+:10F35000853409F46CC0803531F1823521F1813575
56
+:10F3600011F1853509F469C0863509F471C0843618
57
+:10F3700009F47AC0843709F4E1C0853709F43FC144
58
+:10F38000863709F44AC0809103018F5F809303019F
59
+:10F39000853079F6E0910401F091050109950E940C
60
+:10F3A00099F8803351F60E944CF9C3CF0E9499F826
61
+:10F3B000803249F784E10E9467F881E40E9467F88F
62
+:10F3C00086E50E9467F882E50E9467F880E20E9465
63
+:10F3D00067F889E40E9467F883E50E9467F880E592
64
+:10F3E0000E9467F880E10E9467F8A3CF0E9499F815
65
+:10F3F0008638C8F20E9499F80E944CF99ACF0E9470
66
+:10F4000099F8803809F414C1813809F415C182389B
67
+:10F4100009F416C1883909F407C180E00E942CF96B
68
+:10F4200088CF84E10E9410F90E944CF982CF85E0D8
69
+:10F430000E9410F90E944CF97CCF0E9499F88093A9
70
+:10F4400006010E9499F8809307010E944CF971CF40
71
+:10F450000E9499F8803309F405C183E00E9410F9F5
72
+:10F4600080E00E942CF965CF0E9499F880930902F0
73
+:10F470000E9499F88093080280910C028E7F8093FD
74
+:10F480000C020E9499F8853409F4FDC080910802AD
75
+:10F49000909109020097A1F068E0E62E61E0F62E57
76
+:10F4A00000E010E00E9499F8F70181937F010F5F5F
77
+:10F4B0001F4F80910802909109020817190790F3D5
78
+:10F4C0000E9499F8803209F05ECF80910C0280FF93
79
+:10F4D000ECC08091060190910701880F991F9093CD
80
+:10F4E000070180930601209108023091090221153D
81
+:10F4F0003105E9F048E0E42E41E0F42E00E010E0B0
82
+:10F50000F70161917F010E94DCFB809106019091DF
83
+:10F510000701019690930701809306010F5F1F4F2B
84
+:10F5200020910802309109020217130748F384E181
85
+:10F530000E9467F880E10E9467F8FBCE0E9499F86C
86
+:10F54000809309020E9499F8809308028091060135
87
+:10F550009091070197FDA3C020910C022D7F20936D
88
+:10F560000C02880F991F90930701809306010E9457
89
+:10F5700099F8853409F48DC080910C028E7F8093B8
90
+:10F580000C020E9499F8803209F0D3CE84E10E94E7
91
+:10F5900067F88091080290910902009709F440C031
92
+:10F5A00000E010E0809106019091070116C0FC0177
93
+:10F5B00084910E9467F8809106019091070101965D
94
+:10F5C00090930701809306010F5F1F4F209108025F
95
+:10F5D000309109020217130718F520910C0220FD43
96
+:10F5E00033C021FFE4CFA0E0B0E080509040AF4FA7
97
+:10F5F000BF4FABBFFC0187910E9467F8DCCF0E9430
98
+:10F6000099F8803209F0BFCE84E10E9467F88EE15C
99
+:10F610000E9467F887E90E9467F885E00E9467F812
100
+:10F6200080E10E9467F885CE83E00E942CF981CEAC
101
+:10F6300082E00E942CF97DCE81E00E942CF979CEE7
102
+:10F6400080E10E942CF975CE0E94D4FB0E9467F8DD
103
+:10F650008091060190910701019690930701809394
104
+:10F660000601B2CF0E9499F80E9499F8082F0E94D3
105
+:10F6700099F8002309F48BC0013009F48CC085E0AF
106
+:10F680000E942CF956CE80910C02816080930C026E
107
+:10F69000FDCE80910C02816080930C0272CF20918C
108
+:10F6A0000C02226020930C025CCF8091070187FD41
109
+:10F6B00076C010920B0280E08BBF80910601909182
110
+:10F6C0000701880F991F909307018093060180918D
111
+:10F6D000080280FF09C080910802909109020196FA
112
+:10F6E0009093090280930802F894F999FECF1127AC
113
+:10F6F000E0910601F0910701C8E0D1E08091080295
114
+:10F7000090910902103091F400915700017001307E
115
+:10F71000D9F303E000935700E8950091570001707A
116
+:10F720000130D9F301E100935700E8950990199051
117
+:10F730000091570001700130D9F301E000935700A8
118
+:10F74000E8951395103898F0112700915700017033
119
+:10F750000130D9F305E000935700E8950091570078
120
+:10F7600001700130D9F301E100935700E89532961A
121
+:10F77000029709F0C7CF103011F00296E5CF11249F
122
+:10F7800084E10E9467F880E10E9467F8D2CD8EE1A3
123
+:10F790000E942CF9CECD87E90E942CF9CACDF1E068
124
+:10F7A000F0930B0281E088CFF999FECF92BD81BD25
125
+:10F7B000F89A992780B50895262FF999FECF1FBA98
126
+:10F7C00092BD81BD20BD0FB6F894FA9AF99A0FBE8A
127
+:08F7D00001960895F894FFCFA3
128
+:02F7D8008000AF
129
+:040000031000F000F9
130
+:00000001FF

+ 130
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/ATmegaBOOT_168_atmega1284p_8m.hex View File

@@ -0,0 +1,130 @@
1
+:020000021000EC
2
+:10F000000C9446F80C9465F80C9465F80C9465F82B
3
+:10F010000C9465F80C9465F80C9465F80C9465F8FC
4
+:10F020000C9465F80C9465F80C9465F80C9465F8EC
5
+:10F030000C9465F80C9465F80C9465F80C9465F8DC
6
+:10F040000C9465F80C9465F80C9465F80C9465F8CC
7
+:10F050000C9465F80C9465F80C9465F80C9465F8BC
8
+:10F060000C9465F80C9465F80C9465F80C9465F8AC
9
+:10F070000C9465F80C9465F80C9465F80C9465F89C
10
+:10F080000C9465F80C9465F80C9465F811241FBE77
11
+:10F09000CFEFD0E4DEBFCDBF11E0A0E0B1E0E8EDFE
12
+:10F0A000F7EF01E00BBF02C007900D92A230B1074D
13
+:10F0B000D9F712E0A2E0B1E001C01D92AD30B10776
14
+:10F0C000E1F70E947EF90C94EAFB0C9400F8909111
15
+:10F0D0000201913019F0923041F008959091C000F2
16
+:10F0E00095FFFCCF8093C60008959091C80095FFCE
17
+:10F0F000FCCF8093CE0008951F93982F95959595FA
18
+:10F1000095959595905D182F1F701A304CF4105DF1
19
+:10F11000892F0E9467F8812F0E9467F81F91089538
20
+:10F12000195A892F0E9467F8812F0E9467F81F9152
21
+:10F130000895EF92FF920F931F9380910201813007
22
+:10F1400069F1823031F080E01F910F91FF90EF90D4
23
+:10F150000895EE24FF2487018091C80087FD17C021
24
+:10F160000894E11CF11C011D111D81E2E81681EAE1
25
+:10F17000F80687E0080780E0180770F3E0910401C3
26
+:10F18000F091050109958091C80087FFE9CF809132
27
+:10F19000CE001F910F91FF90EF900895EE24FF2471
28
+:10F1A00087018091C00087FD17C00894E11CF11C05
29
+:10F1B000011D111D81E2E81681EAF80687E00807C3
30
+:10F1C00080E0180770F3E0910401F09105010995C2
31
+:10F1D0008091C00087FFE9CF8091C6001F910F91F9
32
+:10F1E000FF90EF9008951F930E9499F8182F0E94A6
33
+:10F1F00067F8113634F410330CF01053812F1F913F
34
+:10F2000008951755812F1F9108951F930E94F3F8B9
35
+:10F21000182F0E94F3F81295107F810F1F91089507
36
+:10F2200020910201882339F0213031F0223061F041
37
+:10F2300081508823C9F708959091C00097FFFCCFB3
38
+:10F240009091C6008150F5CF9091C80097FFFCCFF8
39
+:10F250009091CE008150EDCF1F93182F0E9499F806
40
+:10F26000803281F0809103018F5F809303018530AC
41
+:10F2700011F01F910895E0910401F09105010995A5
42
+:10F280001F91089584E10E9467F8812F0E9467F81A
43
+:10F2900080E10E9467F8EDCF0E9499F8803271F00A
44
+:10F2A000809103018F5F80930301853009F00895F9
45
+:10F2B000E0910401F09105010995089584E10E940F
46
+:10F2C00067F880E10E9467F8089515C0289A2FEF2B
47
+:10F2D00030E742E0215030404040E1F700C00000FC
48
+:10F2E00028982FEF30E742E0215030404040E1F7CE
49
+:10F2F00000C000008150882349F70895EF92FF92E3
50
+:10F300000F931F93CF93DF93000081E0809302015E
51
+:10F3100089E18093C4001092C5001092C00086E07D
52
+:10F320008093C20088E18093C100209A81E00E940E
53
+:10F3300065F90E9499F88033B1F18133B9F18034D5
54
+:10F3400009F454C0813409F45AC0823409F469C004
55
+:10F35000853409F46CC0803531F1823521F1813575
56
+:10F3600011F1853509F469C0863509F471C0843618
57
+:10F3700009F47AC0843709F4E1C0853709F43FC144
58
+:10F38000863709F44AC0809103018F5F809303019F
59
+:10F39000853079F6E0910401F091050109950E940C
60
+:10F3A00099F8803351F60E944CF9C3CF0E9499F826
61
+:10F3B000803249F784E10E9467F881E40E9467F88F
62
+:10F3C00086E50E9467F882E50E9467F880E20E9465
63
+:10F3D00067F889E40E9467F883E50E9467F880E592
64
+:10F3E0000E9467F880E10E9467F8A3CF0E9499F815
65
+:10F3F0008638C8F20E9499F80E944CF99ACF0E9470
66
+:10F4000099F8803809F414C1813809F415C182389B
67
+:10F4100009F416C1883909F407C180E00E942CF96B
68
+:10F4200088CF84E10E9410F90E944CF982CF85E0D8
69
+:10F430000E9410F90E944CF97CCF0E9499F88093A9
70
+:10F4400006010E9499F8809307010E944CF971CF40
71
+:10F450000E9499F8803309F405C183E00E9410F9F5
72
+:10F4600080E00E942CF965CF0E9499F880930902F0
73
+:10F470000E9499F88093080280910C028E7F8093FD
74
+:10F480000C020E9499F8853409F4FDC080910802AD
75
+:10F49000909109020097A1F068E0E62E61E0F62E57
76
+:10F4A00000E010E00E9499F8F70181937F010F5F5F
77
+:10F4B0001F4F80910802909109020817190790F3D5
78
+:10F4C0000E9499F8803209F05ECF80910C0280FF93
79
+:10F4D000ECC08091060190910701880F991F9093CD
80
+:10F4E000070180930601209108023091090221153D
81
+:10F4F0003105E9F048E0E42E41E0F42E00E010E0B0
82
+:10F50000F70161917F010E94DCFB809106019091DF
83
+:10F510000701019690930701809306010F5F1F4F2B
84
+:10F5200020910802309109020217130748F384E181
85
+:10F530000E9467F880E10E9467F8FBCE0E9499F86C
86
+:10F54000809309020E9499F8809308028091060135
87
+:10F550009091070197FDA3C020910C022D7F20936D
88
+:10F560000C02880F991F90930701809306010E9457
89
+:10F5700099F8853409F48DC080910C028E7F8093B8
90
+:10F580000C020E9499F8803209F0D3CE84E10E94E7
91
+:10F5900067F88091080290910902009709F440C031
92
+:10F5A00000E010E0809106019091070116C0FC0177
93
+:10F5B00084910E9467F8809106019091070101965D
94
+:10F5C00090930701809306010F5F1F4F209108025F
95
+:10F5D000309109020217130718F520910C0220FD43
96
+:10F5E00033C021FFE4CFA0E0B0E080509040AF4FA7
97
+:10F5F000BF4FABBFFC0187910E9467F8DCCF0E9430
98
+:10F6000099F8803209F0BFCE84E10E9467F88EE15C
99
+:10F610000E9467F887E90E9467F885E00E9467F812
100
+:10F6200080E10E9467F885CE83E00E942CF981CEAC
101
+:10F6300082E00E942CF97DCE81E00E942CF979CEE7
102
+:10F6400080E10E942CF975CE0E94D4FB0E9467F8DD
103
+:10F650008091060190910701019690930701809394
104
+:10F660000601B2CF0E9499F80E9499F8082F0E94D3
105
+:10F6700099F8002309F48BC0013009F48CC085E0AF
106
+:10F680000E942CF956CE80910C02816080930C026E
107
+:10F69000FDCE80910C02816080930C0272CF20918C
108
+:10F6A0000C02226020930C025CCF8091070187FD41
109
+:10F6B00076C010920B0280E08BBF80910601909182
110
+:10F6C0000701880F991F909307018093060180918D
111
+:10F6D000080280FF09C080910802909109020196FA
112
+:10F6E0009093090280930802F894F999FECF1127AC
113
+:10F6F000E0910601F0910701C8E0D1E08091080295
114
+:10F7000090910902103091F400915700017001307E
115
+:10F71000D9F303E000935700E8950091570001707A
116
+:10F720000130D9F301E100935700E8950990199051
117
+:10F730000091570001700130D9F301E000935700A8
118
+:10F74000E8951395103898F0112700915700017033
119
+:10F750000130D9F305E000935700E8950091570078
120
+:10F7600001700130D9F301E100935700E89532961A
121
+:10F77000029709F0C7CF103011F00296E5CF11249F
122
+:10F7800084E10E9467F880E10E9467F8D2CD8EE1A3
123
+:10F790000E942CF9CECD87E90E942CF9CACDF1E068
124
+:10F7A000F0930B0281E088CFF999FECF92BD81BD25
125
+:10F7B000F89A992780B50895262FF999FECF1FBA98
126
+:10F7C00092BD81BD20BD0FB6F894FA9AF99A0FBE8A
127
+:08F7D00001960895F894FFCFA3
128
+:02F7D8008000AF
129
+:040000031000F000F9
130
+:00000001FF

+ 126
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/ATmegaBOOT_168_atmega644p.hex View File

@@ -0,0 +1,126 @@
1
+:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
2
+:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
3
+:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
4
+:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
5
+:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
6
+:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
7
+:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
8
+:10F870000C945B7C0C945B7C0C945B7C11241FBE11
9
+:10F88000CFEFD0E1DEBFCDBF11E0A0E0B1E0EAEA0A
10
+:10F89000FFEF02C005900D92A230B107D9F712E038
11
+:10F8A000A2E0B1E001C01D92AD30B107E1F70E94C6
12
+:10F8B000747D0C94D37F0C94007C90910201913064
13
+:10F8C00019F0923041F008959091C00095FFFCCF5F
14
+:10F8D0008093C60008959091C80095FFFCCF809357
15
+:10F8E000CE0008951F93982F95959595959595958C
16
+:10F8F000905D182F1F701A304CF4105D892F0E94F4
17
+:10F900005D7C812F0E945D7C1F910895195A892F7B
18
+:10F910000E945D7C812F0E945D7C1F910895EF9273
19
+:10F92000FF920F931F9380910201813069F1823021
20
+:10F9300031F080E01F910F91FF90EF900895EE2439
21
+:10F94000FF2487018091C80087FD17C00894E11C3F
22
+:10F95000F11C011D111D81E4E81682E4F8068FE018
23
+:10F96000080780E0180770F3E0910401F0910501A9
24
+:10F9700009958091C80087FFE9CF8091CE001F9143
25
+:10F980000F91FF90EF900895EE24FF24870180915E
26
+:10F99000C00087FD17C00894E11CF11C011D111D5A
27
+:10F9A00081E4E81682E4F8068FE0080780E0180793
28
+:10F9B00070F3E0910401F091050109958091C00078
29
+:10F9C00087FFE9CF8091C6001F910F91FF90EF90C4
30
+:10F9D00008951F930E948F7C182F0E945D7C113622
31
+:10F9E00034F410330CF01053812F1F9108951755E4
32
+:10F9F000812F1F9108951F930E94E97C182F0E9468
33
+:10FA0000E97C1295107F810F1F91089520910201CA
34
+:10FA1000882339F0213031F0223061F08150882381
35
+:10FA2000C9F708959091C00097FFFCCF9091C60050
36
+:10FA30008150F5CF9091C80097FFFCCF9091CE00F8
37
+:10FA40008150EDCF1F93182F0E948F7C803281F060
38
+:10FA5000809103018F5F80930301853011F01F9126
39
+:10FA60000895E0910401F091050109951F91089511
40
+:10FA700084E10E945D7C812F0E945D7C80E10E9478
41
+:10FA80005D7CEDCF0E948F7C803271F0809103010C
42
+:10FA90008F5F80930301853009F00895E0910401A0
43
+:10FAA000F09105010995089584E10E945D7C80E153
44
+:10FAB0000E945D7C089515C0289A2FEF31EE44E036
45
+:10FAC000215030404040E1F700C0000028982FEF5F
46
+:10FAD00031EE44E0215030404040E1F700C00000EA
47
+:10FAE0008150882349F70895EF92FF920F931F9357
48
+:10FAF000CF93DF93000081E08093020180E1809347
49
+:10FB0000C4001092C5001092C00086E08093C2002D
50
+:10FB100088E18093C100209A81E00E945B7D0E9471
51
+:10FB20008F7C8033B1F18133B9F1803409F454C052
52
+:10FB3000813409F45AC0823409F469C0853409F467
53
+:10FB40006CC0803531F1823521F1813511F1853577
54
+:10FB500009F469C0863509F471C0843609F47AC0A5
55
+:10FB6000843709F4E1C0853709F439C1863709F4CF
56
+:10FB70004AC0809103018F5F80930301853079F63D
57
+:10FB8000E0910401F091050109950E948F7C80337A
58
+:10FB900051F60E94427DC3CF0E948F7C803249F78C
59
+:10FBA00084E10E945D7C81E40E945D7C86E50E9488
60
+:10FBB0005D7C82E50E945D7C80E20E945D7C89E440
61
+:10FBC0000E945D7C83E50E945D7C80E50E945D7CF7
62
+:10FBD00080E10E945D7CA3CF0E948F7C8638C8F2B2
63
+:10FBE0000E948F7C0E94427D9ACF0E948F7C803839
64
+:10FBF00009F40EC1813809F40FC1823809F410C12B
65
+:10FC0000883909F401C180E00E94227D88CF84E117
66
+:10FC10000E94067D0E94427D82CF85E00E94067D83
67
+:10FC20000E94427D7CCF0E948F7C809306010E94BF
68
+:10FC30008F7C809307010E94427D71CF0E948F7C50
69
+:10FC4000803309F4F1C083E00E94067D80E00E94C9
70
+:10FC5000227D65CF0E948F7C809309020E948F7C59
71
+:10FC60008093080280910C028E7F80930C020E9488
72
+:10FC70008F7C853409F4E9C08091080290910902D3
73
+:10FC80000097A1F068E0E62E61E0F62E00E010E0BB
74
+:10FC90000E948F7CF70181937F010F5F1F4F80913E
75
+:10FCA0000802909109020817190790F30E948F7CAF
76
+:10FCB000803209F05ECF80910C0280FFE5C0809118
77
+:10FCC000060190910701880F991F90930701809377
78
+:10FCD0000601209108023091090221153105E9F051
79
+:10FCE00048E0E42E41E0F42E00E010E0F7016191DD
80
+:10FCF0007F010E94C57F80910601909107010196C6
81
+:10FD000090930701809306010F5F1F4F2091080217
82
+:10FD1000309109020217130748F384E10E945D7CC9
83
+:10FD200080E10E945D7CFBCE0E948F7C8093090263
84
+:10FD30000E948F7C809308028091060190910701B8
85
+:10FD400097FD9CC020910C022D7F20930C02880F00
86
+:10FD5000991F90930701809306010E948F7C853440
87
+:10FD600009F486C080910C028E7F80930C020E9461
88
+:10FD70008F7C803209F0D3CE84E10E945D7C20919B
89
+:10FD800008023091090221153105D1F100E010E09F
90
+:10FD900080910601909107010CC041FF5CC0019663
91
+:10FDA00090930701809306010F5F1F4F02171307FF
92
+:10FDB00038F540910C0240FFF0CF0E94BD7F0E94B9
93
+:10FDC0005D7C809106019091070101969093070157
94
+:10FDD000809306012091080230910902E5CF0E942C
95
+:10FDE0008F7C803209F0C5CE84E10E945D7C8EE17B
96
+:10FDF0000E945D7C86E90E945D7C8AE00E945D7CB9
97
+:10FE000080E10E945D7C8BCE83E00E94227D87CEC4
98
+:10FE100082E00E94227D83CE81E00E94227D7FCEFF
99
+:10FE200080E10E94227D7BCE0E948F7C0E948F7C8D
100
+:10FE3000082F0E948F7C002309F497C0013009F439
101
+:10FE400098C08AE00E94227D6ACE80910C02816077
102
+:10FE500080930C0211CFFC0184910E945D7C209163
103
+:10FE6000080230910902809106019091070197CF15
104
+:10FE700080910C02816080930C0279CF20910C025A
105
+:10FE8000226020930C0263CF80910701880F880BBA
106
+:10FE9000817080930B028091060190910701880F79
107
+:10FEA000991F90930701809306018091080280FFBB
108
+:10FEB00009C080910802909109020196909309026D
109
+:10FEC00080930802F894F999FECF1127E09106017A
110
+:10FED000F0910701C8E0D1E08091080290910902F9
111
+:10FEE000103091F40091570001700130D9F303E014
112
+:10FEF00000935700E8950091570001700130D9F345
113
+:10FF000001E100935700E89509901990009157007E
114
+:10FF100001700130D9F301E000935700E895139583
115
+:10FF2000103898F011270091570001700130D9F373
116
+:10FF300005E000935700E8950091570001700130EB
117
+:10FF4000D9F301E100935700E8953296029709F042
118
+:10FF5000C7CF103011F00296E5CF112484E10E9442
119
+:10FF60005D7C80E10E945D7CDACD8EE10E94227D85
120
+:10FF7000D6CD86E90E94227DD2CDF999FECF92BDE1
121
+:10FF800081BDF89A992780B50895262FF999FECF5B
122
+:10FF90001FBA92BD81BD20BD0FB6F894FA9AF99AA6
123
+:0AFFA0000FBE01960895F894FFCFFC
124
+:02FFAA008000D5
125
+:040000030000F80001
126
+:00000001FF

+ 254
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega/Makefile View File

@@ -0,0 +1,254 @@
1
+# Makefile for ATmegaBOOT
2
+# E.Lins, 18.7.2005
3
+# $Id$
4
+#
5
+# Instructions
6
+#
7
+# To make bootloader .hex file:
8
+# make diecimila
9
+# make lilypad
10
+# make ng
11
+# etc...
12
+#
13
+# To burn bootloader .hex file:
14
+# make diecimila_isp
15
+# make lilypad_isp
16
+# make ng_isp
17
+# etc...
18
+
19
+# program name should not be changed...
20
+PROGRAM    = ATmegaBOOT_168
21
+
22
+# enter the parameters for the avrdude isp tool
23
+ISPTOOL	   = stk500v2
24
+ISPPORT	   = usb
25
+ISPSPEED   = -b 115200
26
+
27
+MCU_TARGET = atmega168
28
+LDSECTION  = --section-start=.text=0x3800
29
+
30
+# the efuse should really be 0xf8; since, however, only the lower
31
+# three bits of that byte are used on the atmega168, avrdude gets
32
+# confused if you specify 1's for the higher bits, see:
33
+# http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/
34
+#
35
+# similarly, the lock bits should be 0xff instead of 0x3f (to
36
+# unlock the bootloader section) and 0xcf instead of 0x0f (to
37
+# lock it), but since the high two bits of the lock byte are
38
+# unused, avrdude would get confused.
39
+
40
+ISPFUSES    = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
41
+-e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
42
+ISPFLASH    = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
43
+-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m
44
+
45
+STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe"
46
+STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \
47
+-lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt
48
+STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt
49
+
50
+
51
+OBJ        = $(PROGRAM).o
52
+OPTIMIZE   = -O2
53
+
54
+DEFS       = 
55
+LIBS       =
56
+
57
+CC         = avr-gcc
58
+
59
+# Override is only needed by avr-lib build system.
60
+
61
+override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
62
+override LDFLAGS       = -Wl,$(LDSECTION)
63
+#override LDFLAGS       = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
64
+
65
+OBJCOPY        = avr-objcopy
66
+OBJDUMP        = avr-objdump
67
+
68
+all:
69
+
70
+lilypad: TARGET = lilypad
71
+lilypad: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3'
72
+lilypad: AVR_FREQ = 8000000L
73
+lilypad: $(PROGRAM)_lilypad.hex
74
+
75
+lilypad_isp: lilypad
76
+lilypad_isp: TARGET = lilypad
77
+lilypad_isp: HFUSE = DD
78
+lilypad_isp: LFUSE = E2
79
+lilypad_isp: EFUSE = 00
80
+lilypad_isp: isp
81
+
82
+lilypad_resonator: TARGET = lilypad_resonator
83
+lilypad_resonator: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=3'
84
+lilypad_resonator: AVR_FREQ = 8000000L
85
+lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex
86
+
87
+lilypad_resonator_isp: lilypad_resonator
88
+lilypad_resonator_isp: TARGET = lilypad_resonator
89
+lilypad_resonator_isp: HFUSE = DD
90
+lilypad_resonator_isp: LFUSE = C6
91
+lilypad_resonator_isp: EFUSE = 00
92
+lilypad_resonator_isp: isp
93
+
94
+pro8: TARGET = pro_8MHz
95
+pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS'
96
+pro8: AVR_FREQ = 8000000L
97
+pro8: $(PROGRAM)_pro_8MHz.hex
98
+
99
+pro8_isp: pro8
100
+pro8_isp: TARGET = pro_8MHz
101
+pro8_isp: HFUSE = DD
102
+pro8_isp: LFUSE = C6
103
+pro8_isp: EFUSE = 00
104
+pro8_isp: isp
105
+
106
+pro16: TARGET = pro_16MHz
107
+pro16: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS'
108
+pro16: AVR_FREQ = 16000000L
109
+pro16: $(PROGRAM)_pro_16MHz.hex
110
+
111
+pro16_isp: pro16
112
+pro16_isp: TARGET = pro_16MHz
113
+pro16_isp: HFUSE = DD
114
+pro16_isp: LFUSE = C6
115
+pro16_isp: EFUSE = 00
116
+pro16_isp: isp
117
+
118
+pro20: TARGET = pro_20mhz
119
+pro20: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS'
120
+pro20: AVR_FREQ = 20000000L
121
+pro20: $(PROGRAM)_pro_20mhz.hex
122
+
123
+pro20_isp: pro20
124
+pro20_isp: TARGET = pro_20mhz
125
+pro20_isp: HFUSE = DD
126
+pro20_isp: LFUSE = C6
127
+pro20_isp: EFUSE = 00
128
+pro20_isp: isp
129
+
130
+diecimila: TARGET = diecimila
131
+diecimila: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1'
132
+diecimila: AVR_FREQ = 16000000L 
133
+diecimila: $(PROGRAM)_diecimila.hex
134
+
135
+diecimila_isp: diecimila
136
+diecimila_isp: TARGET = diecimila
137
+diecimila_isp: HFUSE = DD
138
+diecimila_isp: LFUSE = FF
139
+diecimila_isp: EFUSE = 00
140
+diecimila_isp: isp
141
+
142
+ng: TARGET = ng
143
+ng: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3'
144
+ng: AVR_FREQ = 16000000L
145
+ng: $(PROGRAM)_ng.hex
146
+
147
+ng_isp: ng
148
+ng_isp: TARGET = ng
149
+ng_isp: HFUSE = DD
150
+ng_isp: LFUSE = FF
151
+ng_isp: EFUSE = 00
152
+ng_isp: isp
153
+
154
+atmega328: TARGET = atmega328
155
+atmega328: MCU_TARGET = atmega328p
156
+atmega328: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600
157
+atmega328: AVR_FREQ = 16000000L 
158
+atmega328: LDSECTION  = --section-start=.text=0x7800
159
+atmega328: $(PROGRAM)_atmega328.hex
160
+
161
+atmega328_isp: atmega328
162
+atmega328_isp: TARGET = atmega328
163
+atmega328_isp: MCU_TARGET = atmega328p
164
+atmega328_isp: HFUSE = DA
165
+atmega328_isp: LFUSE = FF
166
+atmega328_isp: EFUSE = 05
167
+atmega328_isp: isp
168
+
169
+atmega328_pro8: TARGET = atmega328_pro_8MHz
170
+atmega328_pro8: MCU_TARGET = atmega328p
171
+atmega328_pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 -DDOUBLE_SPEED
172
+atmega328_pro8: AVR_FREQ = 8000000L 
173
+atmega328_pro8: LDSECTION  = --section-start=.text=0x7800
174
+atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex
175
+
176
+atmega328_pro8_isp: atmega328_pro8
177
+atmega328_pro8_isp: TARGET = atmega328_pro_8MHz
178
+atmega328_pro8_isp: MCU_TARGET = atmega328p
179
+atmega328_pro8_isp: HFUSE = DA
180
+atmega328_pro8_isp: LFUSE = FF
181
+atmega328_pro8_isp: EFUSE = 05
182
+atmega328_pro8_isp: isp
183
+
184
+mega: TARGET = atmega1280
185
+mega: MCU_TARGET = atmega1280
186
+mega: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' -DBAUD_RATE=57600
187
+mega: AVR_FREQ = 16000000L 
188
+mega: LDSECTION  = --section-start=.text=0x1F000
189
+mega: $(PROGRAM)_atmega1280.hex
190
+
191
+mega_isp: mega
192
+mega_isp: TARGET = atmega1280
193
+mega_isp: MCU_TARGET = atmega1280
194
+mega_isp: HFUSE = DA
195
+mega_isp: LFUSE = FF
196
+mega_isp: EFUSE = F5
197
+mega_isp: isp
198
+
199
+atmega1284p: TARGET = atmega1284p
200
+atmega1284p: MCU_TARGET = atmega1284p
201
+atmega1284p: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' '-DBAUD_RATE=57600'
202
+atmega1284p: AVR_FREQ = 16000000L 
203
+atmega1284p: LDSECTION  = --section-start=.text=0x1F000
204
+atmega1284p: $(PROGRAM)_atmega1284p.hex
205
+
206
+atmega1284p_8m: TARGET = atmega1284p
207
+atmega1284p_8m: MCU_TARGET = atmega1284p
208
+atmega1284p_8m: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' '-DBAUD_RATE=19200'
209
+atmega1284p_8m: AVR_FREQ = 8000000L
210
+atmega1284p_8m: LDSECTION  = --section-start=.text=0x1F000
211
+atmega1284p_8m: $(PROGRAM)_atmega1284p_8m.hex
212
+
213
+atmega644p: TARGET = atmega644p
214
+atmega644p: MCU_TARGET = atmega644p
215
+atmega644p: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' '-DBAUD_RATE=57600'
216
+atmega644p: AVR_FREQ = 16000000L
217
+atmega644p: LDSECTION  = --section-start=.text=0xF800
218
+atmega644p: $(PROGRAM)_atmega644p.hex
219
+
220
+
221
+atmega1284p_isp: atmega1284p
222
+atmega1284p_isp: TARGET = atmega1284p
223
+atmega1284p_isp: MCU_TARGET = atmega1284p
224
+atmega1284p_isp: HFUSE = DC
225
+atmega1284p_isp: LFUSE = FF
226
+atmega1284p_isp: EFUSE = FD
227
+atmega1284p_isp: isp
228
+
229
+isp: $(TARGET)
230
+	$(ISPFUSES)
231
+	$(ISPFLASH)
232
+
233
+isp-stk500: $(PROGRAM)_$(TARGET).hex
234
+	$(STK500-1)
235
+	$(STK500-2)
236
+
237
+%.elf: $(OBJ)
238
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
239
+
240
+clean:
241
+	rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
242
+
243
+%.lst: %.elf
244
+	$(OBJDUMP) -h -S $< > $@
245
+
246
+%.hex: %.elf
247
+	$(OBJCOPY) -j .text -j .data -O ihex $< $@
248
+
249
+%.srec: %.elf
250
+	$(OBJCOPY) -j .text -j .data -O srec $< $@
251
+
252
+%.bin: %.elf
253
+	$(OBJCOPY) -j .text -j .data -O binary $< $@
254
+	

+ 717
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/ATmegaBOOT.c View File

@@ -0,0 +1,717 @@
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_ATmega1284P__)
106
+#define SIG2	0x97
107
+#define SIG3	0x05
108
+#elif defined(__AVR_ATmega644P__)
109
+#define SIG2	0x96
110
+#define SIG3	0x0A
111
+#elif defined(__AVR_ATmega644__)
112
+#define SIG2	0x96
113
+#define SIG3	0x09
114
+#elif defined(__AVR_ATmega324P__)
115
+#define SIG2	0x95
116
+#define SIG3	0x08
117
+#endif
118
+
119
+#define PAGE_SIZE		0x080U   //128 words
120
+#define PAGE_SIZE_BYTES	0x100U   //256 bytes
121
+
122
+/* function prototypes */
123
+void putch(char);
124
+char getch(void);
125
+void getNch(uint8_t);
126
+void byte_response(uint8_t);
127
+void nothing_response(void);
128
+char gethex(void);
129
+void puthex(char);
130
+void flash_led(uint8_t);
131
+
132
+/* some variables */
133
+union address_union
134
+{
135
+    uint16_t word;
136
+    uint8_t  byte[2];
137
+} address;
138
+
139
+union length_union
140
+{
141
+    uint16_t word;
142
+    uint8_t  byte[2];
143
+} length;
144
+
145
+struct flags_struct
146
+{
147
+    unsigned eeprom : 1;
148
+    unsigned rampz  : 1;
149
+} flags;
150
+
151
+uint8_t buff[256];
152
+
153
+uint8_t error_count = 0;
154
+uint8_t sreg;
155
+
156
+void (*app_start)(void) = 0x0000;
157
+
158
+/* main program starts here */
159
+int main(void)
160
+{
161
+    uint8_t ch,ch2;
162
+    uint16_t w;
163
+	uint16_t i;
164
+	
165
+    asm volatile("nop\n\t");
166
+
167
+#ifdef ADABOOT		// BBR/LF 10/8/2007 & 9/13/2008
168
+    ch = MCUSR;
169
+    MCUSR = 0;
170
+
171
+    WDTCSR |= _BV(WDCE) | _BV(WDE);
172
+    WDTCSR = 0;
173
+
174
+    // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
175
+    if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
176
+      app_start();  // skip bootloader
177
+#endif
178
+
179
+
180
+	//initialize our serial port.
181
+    UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
182
+    UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
183
+    UCSR0B = (1<<RXEN0) | (1<<TXEN0);
184
+    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
185
+
186
+    /* Enable internal pull-up resistor on pin D0 (RX), in order
187
+    to supress line noise that prevents the bootloader from
188
+    timing out (DAM: 20070509) */
189
+    DDRD &= ~_BV(PIND0);
190
+    PORTD |= _BV(PIND0);
191
+
192
+    /* set LED pin as output */
193
+    LED_DDR |= _BV(LED);
194
+
195
+	    /* flash onboard LED to signal entering of bootloader                   */
196
+	    /* ADABOOT will do two series of flashes. first 4 - signifying ADABOOT  */
197
+	    /* then a pause and another flash series signifying ADABOOT sub-version */
198
+
199
+
200
+	flash_led(NUM_LED_FLASHES);
201
+
202
+	#ifdef	ADABOOT
203
+		flash_led(ADABOOT_VER);		// BBR 9/13/2008
204
+	#endif 
205
+
206
+    /* forever loop */
207
+    for (;;)
208
+	{
209
+		/* get character from UART */
210
+		ch = getch();
211
+
212
+		/* A bunch of if...else if... gives smaller code than switch...case ! */
213
+
214
+		/* Hello is anyone home ? */ 
215
+		if(ch=='0')
216
+		    nothing_response();
217
+
218
+
219
+		/* Request programmer ID */
220
+		/* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry  */
221
+		/* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares.  */
222
+		else if(ch=='1')
223
+		{
224
+		    if (getch() == ' ')
225
+			{
226
+				putch(0x14);
227
+				putch('A');
228
+				putch('V');
229
+				putch('R');
230
+				putch(' ');
231
+				putch('I');
232
+				putch('S');
233
+				putch('P');
234
+				putch(0x10);
235
+		    }
236
+			else
237
+			{
238
+				if (++error_count == MAX_ERROR_COUNT)
239
+				    app_start();
240
+		    }
241
+		}
242
+
243
+
244
+		/* AVR ISP/STK500 board commands  DON'T CARE so default nothing_response */
245
+		else if(ch=='@')
246
+		{
247
+		    ch2 = getch();
248
+		    if (ch2 > 0x85)
249
+				getch();
250
+		    nothing_response();
251
+		}
252
+
253
+
254
+		/* AVR ISP/STK500 board requests */
255
+		else if(ch=='A')
256
+		{
257
+		    ch2 = getch();
258
+		    if(ch2 == 0x80)
259
+				byte_response(HW_VER);		// Hardware version
260
+		    else if(ch2==0x81)
261
+				byte_response(SW_MAJOR);	// Software major version
262
+		    else if(ch2==0x82)
263
+				byte_response(SW_MINOR);	// Software minor version
264
+		    else if(ch2==0x98)
265
+				byte_response(0x03);		// Unknown but seems to be required by avr studio 3.56
266
+		    else
267
+				byte_response(0x00);		// Covers various unnecessary responses we don't care about
268
+		}
269
+
270
+
271
+		/* Device Parameters  DON'T CARE, DEVICE IS FIXED  */
272
+		else if(ch=='B')
273
+		{
274
+		    getNch(20);
275
+		    nothing_response();
276
+		}
277
+
278
+
279
+		/* Parallel programming stuff  DON'T CARE  */
280
+		else if(ch=='E')
281
+		{
282
+		    getNch(5);
283
+		    nothing_response();
284
+		}
285
+
286
+
287
+		/* Enter programming mode  */
288
+		else if(ch=='P')
289
+		{
290
+		    nothing_response();
291
+		}
292
+
293
+
294
+		/* Leave programming mode  */
295
+		else if(ch=='Q')
296
+		{
297
+		    nothing_response();
298
+#ifdef ADABOOT		
299
+			// autoreset via watchdog (sneaky!) BBR/LF 9/13/2008
300
+	  		WDTCSR = _BV(WDE);
301
+	  		while (1); // 16 ms
302
+#endif		
303
+		}
304
+
305
+
306
+		/* Erase device, don't care as we will erase one page at a time anyway.  */
307
+		else if(ch=='R')
308
+		{
309
+		    nothing_response();
310
+		}
311
+
312
+
313
+		/* Set address, little endian. EEPROM in bytes, FLASH in words  */
314
+		/* Perhaps extra address bytes may be added in future to support > 128kB FLASH.  */
315
+		/* This might explain why little endian was used here, big endian used everywhere else.  */
316
+		else if(ch=='U')
317
+		{
318
+		    address.byte[0] = getch();
319
+		    address.byte[1] = getch();
320
+		    nothing_response();
321
+		}
322
+
323
+
324
+		/* Universal SPI programming command, disabled.  Would be used for fuses and lock bits.  */
325
+		else if(ch=='V')
326
+		{
327
+		    getNch(4);
328
+		    byte_response(0x00);
329
+		}
330
+
331
+
332
+		/* Write memory, length is big endian and is in bytes  */
333
+		else if(ch=='d')
334
+		{
335
+		    length.byte[1] = getch();
336
+		    length.byte[0] = getch();
337
+	
338
+		    flags.eeprom = 0;
339
+		    if (getch() == 'E')
340
+				flags.eeprom = 1;
341
+
342
+			for (i=0; i<PAGE_SIZE; i++)
343
+				buff[i] = 0;
344
+		
345
+		    for (w = 0; w < length.word; w++)
346
+			{
347
+				// Store data in buffer, can't keep up with serial data stream whilst programming pages
348
+				buff[w] = getch();
349
+		    }
350
+	
351
+		    if (getch() == ' ')
352
+			{
353
+				if (flags.eeprom)
354
+				{		                
355
+					//Write to EEPROM one byte at a time
356
+				    for(w=0;w<length.word;w++)
357
+					{
358
+						while(EECR & (1<<EEPE));
359
+					
360
+						EEAR = (uint16_t)(void *)address.word;
361
+						EEDR = buff[w];
362
+						EECR |= (1<<EEMPE);
363
+						EECR |= (1<<EEPE);
364
+
365
+						address.word++;
366
+				    }			
367
+				}
368
+				else
369
+				{
370
+					//address * 2 -> byte location
371
+				    address.word = address.word << 1;
372
+			    
373
+					//Even up an odd number of bytes
374
+					if ((length.byte[0] & 0x01))
375
+						length.word++;
376
+				
377
+					// HACKME: EEPE used to be EEWE
378
+				    //Wait for previous EEPROM writes to complete
379
+					//while(bit_is_set(EECR,EEPE));
380
+					while(EECR & (1<<EEPE));
381
+				
382
+				    asm volatile(
383
+						 "clr	r17		\n\t"	//page_word_count
384
+						 "lds	r30,address	\n\t"	//Address of FLASH location (in bytes)
385
+						 "lds	r31,address+1	\n\t"
386
+						 "ldi	r28,lo8(buff)	\n\t"	//Start of buffer array in RAM
387
+						 "ldi	r29,hi8(buff)	\n\t"
388
+						 "lds	r24,length	\n\t"	//Length of data to be written (in bytes)
389
+						 "lds	r25,length+1	\n\t"
390
+						 "length_loop:		\n\t"	//Main loop, repeat for number of words in block							 							 
391
+						 "cpi	r17,0x00	\n\t"	//If page_word_count=0 then erase page
392
+						 "brne	no_page_erase	\n\t"						 
393
+						 "wait_spm1:		\n\t"
394
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
395
+						 "andi	r16,1           \n\t"
396
+						 "cpi	r16,1           \n\t"
397
+						 "breq	wait_spm1       \n\t"
398
+						 "ldi	r16,0x03	\n\t"	//Erase page pointed to by Z
399
+						 "sts	%0,r16		\n\t"
400
+						 "spm			\n\t"							 
401
+						 "wait_spm2:		\n\t"
402
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
403
+						 "andi	r16,1           \n\t"
404
+						 "cpi	r16,1           \n\t"
405
+						 "breq	wait_spm2       \n\t"									 
406
+
407
+						 "ldi	r16,0x11	\n\t"	//Re-enable RWW section
408
+						 "sts	%0,r16		\n\t"						 			 
409
+						 "spm			\n\t"
410
+						 "no_page_erase:		\n\t"							 
411
+						 "ld	r0,Y+		\n\t"	//Write 2 bytes into page buffer
412
+						 "ld	r1,Y+		\n\t"							 
413
+							 
414
+						 "wait_spm3:		\n\t"
415
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
416
+						 "andi	r16,1           \n\t"
417
+						 "cpi	r16,1           \n\t"
418
+						 "breq	wait_spm3       \n\t"
419
+						 "ldi	r16,0x01	\n\t"	//Load r0,r1 into FLASH page buffer
420
+						 "sts	%0,r16		\n\t"
421
+						 "spm			\n\t"
422
+							 
423
+						 "inc	r17		\n\t"	//page_word_count++
424
+						 "cpi r17,%1	        \n\t"
425
+						 "brlo	same_page	\n\t"	//Still same page in FLASH
426
+						 "write_page:		\n\t"
427
+						 "clr	r17		\n\t"	//New page, write current one first
428
+						 "wait_spm4:		\n\t"
429
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
430
+						 "andi	r16,1           \n\t"
431
+						 "cpi	r16,1           \n\t"
432
+						 "breq	wait_spm4       \n\t"						 							 
433
+						 "ldi	r16,0x05	\n\t"	//Write page pointed to by Z
434
+						 "sts	%0,r16		\n\t"
435
+						 "spm			\n\t"
436
+						 "wait_spm5:		\n\t"
437
+						 "lds	r16,%0		\n\t"	//Wait for previous spm to complete
438
+						 "andi	r16,1           \n\t"
439
+						 "cpi	r16,1           \n\t"
440
+						 "breq	wait_spm5       \n\t"									 
441
+						 "ldi	r16,0x11	\n\t"	//Re-enable RWW section
442
+						 "sts	%0,r16		\n\t"						 			 
443
+						 "spm			\n\t"					 		 
444
+						 "same_page:		\n\t"							 
445
+						 "adiw	r30,2		\n\t"	//Next word in FLASH
446
+						 "sbiw	r24,2		\n\t"	//length-2
447
+						 "breq	final_write	\n\t"	//Finished
448
+						 "rjmp	length_loop	\n\t"
449
+						 "final_write:		\n\t"
450
+						 "cpi	r17,0		\n\t"
451
+						 "breq	block_done	\n\t"
452
+						 "adiw	r24,2		\n\t"	//length+2, fool above check on length after short page write
453
+						 "rjmp	write_page	\n\t"
454
+						 "block_done:		\n\t"
455
+						 "clr	__zero_reg__	\n\t"	//restore zero register
456
+						 : "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
457
+
458
+						 );
459
+				}
460
+				putch(0x14);
461
+				putch(0x10);
462
+		    }
463
+			else
464
+			{
465
+				if (++error_count == MAX_ERROR_COUNT)
466
+				    app_start();
467
+		    }		
468
+		}
469
+    
470
+		/* Read memory block mode, length is big endian.  */
471
+		else if(ch=='t')
472
+		{
473
+			length.byte[1] = getch();
474
+			length.byte[0] = getch();
475
+
476
+			if (getch() == 'E')
477
+				flags.eeprom = 1;
478
+			else
479
+			{
480
+				flags.eeprom = 0;
481
+				address.word = address.word << 1;	        // address * 2 -> byte location
482
+			}
483
+
484
+			// Command terminator
485
+			if (getch() == ' ')
486
+			{
487
+				putch(0x14);
488
+				for (w=0; w<length.word; w++)
489
+				{
490
+					// Can handle odd and even lengths okay
491
+				    if (flags.eeprom) 
492
+					{
493
+						// Byte access EEPROM read
494
+						while(EECR & (1<<EEPE));
495
+						EEAR = (uint16_t)(void *)address.word;
496
+						EECR |= (1<<EERE);
497
+						putch(EEDR);
498
+
499
+						address.word++;
500
+				    }
501
+				    else
502
+					{
503
+						if (!flags.rampz)
504
+							putch(pgm_read_byte_near(address.word));
505
+
506
+						address.word++;
507
+				    }
508
+				}
509
+				putch(0x10);
510
+		    }
511
+		}
512
+
513
+
514
+		/* Get device signature bytes  */
515
+		else if(ch=='u')
516
+		{
517
+			if (getch() == ' ')
518
+			{
519
+				putch(0x14);
520
+				putch(SIG1);
521
+				putch(SIG2);
522
+				putch(SIG3);
523
+				putch(0x10);
524
+			}
525
+			else
526
+			{
527
+				if (++error_count == MAX_ERROR_COUNT)
528
+					app_start();
529
+			}
530
+		}
531
+
532
+
533
+		/* Read oscillator calibration byte */
534
+		else if(ch=='v')
535
+			byte_response(0x00);
536
+
537
+		else if (++error_count == MAX_ERROR_COUNT)
538
+		    app_start();
539
+
540
+	}
541
+    /* end of forever loop */
542
+}
543
+
544
+
545
+char gethex(void)
546
+{
547
+    char ah,al;
548
+
549
+    ah = getch();
550
+	putch(ah);
551
+    al = getch();
552
+	putch(al);
553
+    
554
+	if(ah >= 'a')
555
+		ah = ah - 'a' + 0x0a;
556
+	else if(ah >= '0')
557
+		ah -= '0';
558
+    if(al >= 'a')
559
+		al = al - 'a' + 0x0a;
560
+	else if(al >= '0')
561
+		al -= '0';
562
+
563
+    return (ah << 4) + al;
564
+}
565
+
566
+
567
+void puthex(char ch)
568
+{
569
+    char ah,al;
570
+
571
+    ah = (ch & 0xf0) >> 4;
572
+	if(ah >= 0x0a)
573
+		ah = ah - 0x0a + 'a';
574
+	else
575
+		ah += '0';
576
+
577
+    al = (ch & 0x0f);
578
+	if(al >= 0x0a)
579
+		al = al - 0x0a + 'a';
580
+	else
581
+		al += '0';
582
+
583
+    putch(ah);
584
+    putch(al);
585
+}
586
+
587
+
588
+void putch(char ch)
589
+{
590
+    while (!(UCSR0A & _BV(UDRE0)));
591
+    UDR0 = ch;
592
+}
593
+
594
+
595
+
596
+
597
+char getch(void)
598
+{
599
+    uint32_t count = 0;
600
+
601
+#ifdef ADABOOT
602
+	LED_PORT &= ~_BV(LED);          // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
603
+#endif
604
+
605
+    while(!(UCSR0A & _BV(RXC0)))
606
+	{
607
+    	/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/               
608
+    	/* HACKME:: here is a good place to count times*/
609
+    	count++;
610
+    	if (count > MAX_TIME_COUNT)
611
+    		app_start();
612
+     }
613
+
614
+#ifdef ADABOOT
615
+	LED_PORT |= _BV(LED);          // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
616
+#endif
617
+
618
+    return UDR0;
619
+}
620
+
621
+
622
+void getNch(uint8_t count)
623
+{
624
+    uint8_t i;
625
+    for(i=0;i<count;i++)
626
+	{
627
+		while(!(UCSR0A & _BV(RXC0)));
628
+		UDR0;
629
+    }
630
+}
631
+
632
+
633
+void byte_response(uint8_t val)
634
+{
635
+    if (getch() == ' ')
636
+	{
637
+		putch(0x14);
638
+		putch(val);
639
+		putch(0x10);
640
+    }
641
+	else
642
+	{
643
+		if (++error_count == MAX_ERROR_COUNT)
644
+		    app_start();
645
+    }
646
+}
647
+
648
+
649
+void nothing_response(void)
650
+{
651
+    if (getch() == ' ')
652
+	{
653
+		putch(0x14);
654
+		putch(0x10);
655
+    }
656
+	else
657
+	{
658
+		if (++error_count == MAX_ERROR_COUNT)
659
+		    app_start();
660
+    }
661
+}
662
+
663
+#ifdef ADABOOT
664
+
665
+void flash_led(uint8_t count)
666
+{
667
+    /* flash onboard LED count times to signal entering of bootloader */
668
+	/* l needs to be volatile or the delay loops below might get      */
669
+	/* optimized away if compiling with optimizations (DAM).          */
670
+	
671
+    volatile uint32_t l;
672
+
673
+    if (count == 0) {
674
+      count = ADABOOT;
675
+    }
676
+    
677
+
678
+	int8_t i;
679
+    for (i = 0; i < count; ++i) {
680
+		LED_PORT |= _BV(LED);					// LED on
681
+		for(l = 0; l < (F_CPU / 1000); ++l);		// delay NGvalue was 1000 for both loops - BBR
682
+		LED_PORT &= ~_BV(LED);					// LED off
683
+		for(l = 0; l < (F_CPU / 250); ++l);		// delay asymmteric for ADA BOOT BBR 
684
+	}
685
+
686
+	for(l = 0; l < (F_CPU / 100); ++l);		    // pause ADA BOOT BBR 
687
+		
688
+}
689
+
690
+#else
691
+
692
+void flash_led(uint8_t count)
693
+{
694
+    /* flash onboard LED three times to signal entering of bootloader */
695
+	/* l needs to be volatile or the delay loops below might get
696
+	optimized away if compiling with optimizations (DAM). */
697
+    volatile uint32_t l;
698
+
699
+    if (count == 0) {
700
+      count = 3;
701
+    }
702
+    
703
+	int8_t i;
704
+    for (i = 0; i < count; ++i) {
705
+		LED_PORT |= _BV(LED);
706
+		for(l = 0; l < (F_CPU / 1000); ++l);
707
+		LED_PORT &= ~_BV(LED);
708
+		for(l = 0; l < (F_CPU / 1000); ++l); 
709
+	}
710
+		
711
+}
712
+
713
+
714
+#endif
715
+
716
+
717
+/* end of file ATmegaBOOT.c */

+ 388
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/ATmegaBOOT.c.tst View File

@@ -0,0 +1,388 @@
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
+#include <util/delay.h>
76
+
77
+#ifdef ADABOOT
78
+    #define NUM_LED_FLASHES 3
79
+    #define ADABOOT_VER	1
80
+#endif
81
+
82
+
83
+/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
84
+#define MAX_ERROR_COUNT 5
85
+
86
+/* set the UART baud rate */
87
+/* 20080711: hack by Zach Hoeken */
88
+#define BAUD_RATE   38400
89
+
90
+/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
91
+/* never allow AVR Studio to do an update !!!! */
92
+#define HW_VER	 0x02
93
+#define SW_MAJOR 0x01
94
+#define SW_MINOR 0x10
95
+
96
+/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
97
+/* if monitor functions are included, LED goes on after monitor was entered */
98
+#define LED_DDR  DDRB
99
+#define LED_PORT PORTB
100
+#define LED_PIN  PINB
101
+#define LED      PINB0
102
+
103
+/* define various device id's */
104
+/* manufacturer byte is always the same */
105
+#define SIG1	0x1E	// Yep, Atmel is the only manufacturer of AVR micros.  Single source :(
106
+#if defined(__AVR_ATmega1284P__)
107
+#define SIG2	0x97
108
+#define SIG3	0x05
109
+#elif defined(__AVR_ATmega644P__)
110
+#define SIG2	0x96
111
+#define SIG3	0x0A
112
+#elif defined(__AVR_ATmega644__)
113
+#define SIG2	0x96
114
+#define SIG3	0x09
115
+#elif defined(__AVR_ATmega324P__)
116
+#define SIG2	0x95
117
+#define SIG3	0x08
118
+#endif
119
+#define PAGE_SIZE		0x080U   //128 words
120
+#define PAGE_SIZE_BYTES	0x100U   //256 bytes
121
+
122
+/* function prototypes */
123
+void putch(char);
124
+char getch(void);
125
+void getNch(uint8_t);
126
+void byte_response(uint8_t);
127
+void nothing_response(void);
128
+char gethex(void);
129
+void puthex(char);
130
+void flash_led(uint8_t);
131
+
132
+/* some variables */
133
+union address_union
134
+{
135
+    uint16_t word;
136
+    uint8_t  byte[2];
137
+} address;
138
+
139
+union length_union
140
+{
141
+    uint16_t word;
142
+    uint8_t  byte[2];
143
+} length;
144
+
145
+struct flags_struct
146
+{
147
+    unsigned eeprom : 1;
148
+    unsigned rampz  : 1;
149
+} flags;
150
+
151
+uint8_t buff[256];
152
+
153
+uint8_t error_count = 0;
154
+uint8_t sreg;
155
+
156
+void (*app_start)(void) = 0x0000;
157
+
158
+/* main program starts here */
159
+int main(void)
160
+{
161
+    uint8_t ch,ch2;
162
+    uint16_t w;
163
+	uint16_t i;
164
+	
165
+    asm volatile("nop\n\t");
166
+
167
+#ifdef ADABOOT		// BBR/LF 10/8/2007 & 9/13/2008
168
+    ch = MCUSR;
169
+    MCUSR = 0;
170
+
171
+    WDTCSR |= _BV(WDCE) | _BV(WDE);
172
+    WDTCSR = 0;
173
+
174
+    // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
175
+    if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
176
+      app_start();  // skip bootloader
177
+#endif
178
+
179
+
180
+	//initialize our serial port.
181
+    UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
182
+    UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
183
+    UCSR0B = (1<<RXEN0) | (1<<TXEN0);
184
+    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
185
+
186
+    /* Enable internal pull-up resistor on pin D0 (RX), in order
187
+    to supress line noise that prevents the bootloader from
188
+    timing out (DAM: 20070509) */
189
+    DDRD &= ~_BV(PIND0);
190
+    PORTD |= _BV(PIND0);
191
+
192
+    /* set LED pin as output */
193
+    LED_DDR |= _BV(LED);
194
+
195
+	    /* flash onboard LED to signal entering of bootloader                   */
196
+	    /* ADABOOT will do two series of flashes. first 4 - signifying ADABOOT  */
197
+	    /* then a pause and another flash series signifying ADABOOT sub-version */
198
+
199
+
200
+	flash_led(NUM_LED_FLASHES);
201
+
202
+	#ifdef	ADABOOT
203
+		flash_led(ADABOOT_VER);		// BBR 9/13/2008
204
+	#endif 
205
+
206
+    /* forever loop */
207
+    for (;;)
208
+	{
209
+          putch('\r');
210
+          _delay_ms(500);
211
+        }
212
+    /* end of forever loop */
213
+}
214
+
215
+
216
+char gethex(void)
217
+{
218
+    char ah,al;
219
+
220
+    ah = getch();
221
+	putch(ah);
222
+    al = getch();
223
+	putch(al);
224
+    
225
+	if(ah >= 'a')
226
+		ah = ah - 'a' + 0x0a;
227
+	else if(ah >= '0')
228
+		ah -= '0';
229
+    if(al >= 'a')
230
+		al = al - 'a' + 0x0a;
231
+	else if(al >= '0')
232
+		al -= '0';
233
+
234
+    return (ah << 4) + al;
235
+}
236
+
237
+
238
+void puthex(char ch)
239
+{
240
+    char ah,al;
241
+
242
+    ah = (ch & 0xf0) >> 4;
243
+	if(ah >= 0x0a)
244
+		ah = ah - 0x0a + 'a';
245
+	else
246
+		ah += '0';
247
+
248
+    al = (ch & 0x0f);
249
+	if(al >= 0x0a)
250
+		al = al - 0x0a + 'a';
251
+	else
252
+		al += '0';
253
+
254
+    putch(ah);
255
+    putch(al);
256
+}
257
+
258
+
259
+void putch(char ch)
260
+{
261
+    while (!(UCSR0A & _BV(UDRE0)));
262
+    UDR0 = ch;
263
+}
264
+
265
+
266
+
267
+
268
+char getch(void)
269
+{
270
+    uint32_t count = 0;
271
+
272
+#ifdef ADABOOT
273
+	LED_PORT &= ~_BV(LED);          // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
274
+#endif
275
+
276
+    while(!(UCSR0A & _BV(RXC0)))
277
+	{
278
+    	/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/               
279
+    	/* HACKME:: here is a good place to count times*/
280
+    	count++;
281
+    	if (count > MAX_TIME_COUNT)
282
+    		app_start();
283
+     }
284
+
285
+#ifdef ADABOOT
286
+	LED_PORT |= _BV(LED);          // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
287
+#endif
288
+
289
+    return UDR0;
290
+}
291
+
292
+
293
+void getNch(uint8_t count)
294
+{
295
+    uint8_t i;
296
+    for(i=0;i<count;i++)
297
+	{
298
+		while(!(UCSR0A & _BV(RXC0)));
299
+		UDR0;
300
+    }
301
+}
302
+
303
+
304
+void byte_response(uint8_t val)
305
+{
306
+    if (getch() == ' ')
307
+	{
308
+		putch(0x14);
309
+		putch(val);
310
+		putch(0x10);
311
+    }
312
+	else
313
+	{
314
+		if (++error_count == MAX_ERROR_COUNT)
315
+		    app_start();
316
+    }
317
+}
318
+
319
+
320
+void nothing_response(void)
321
+{
322
+    if (getch() == ' ')
323
+	{
324
+		putch(0x14);
325
+		putch(0x10);
326
+    }
327
+	else
328
+	{
329
+		if (++error_count == MAX_ERROR_COUNT)
330
+		    app_start();
331
+    }
332
+}
333
+
334
+#ifdef ADABOOT
335
+
336
+void flash_led(uint8_t count)
337
+{
338
+    /* flash onboard LED count times to signal entering of bootloader */
339
+	/* l needs to be volatile or the delay loops below might get      */
340
+	/* optimized away if compiling with optimizations (DAM).          */
341
+	
342
+    volatile uint32_t l;
343
+
344
+    if (count == 0) {
345
+      count = ADABOOT;
346
+    }
347
+    
348
+
349
+	int8_t i;
350
+    for (i = 0; i < count; ++i) {
351
+		LED_PORT |= _BV(LED);					// LED on
352
+		for(l = 0; l < (F_CPU / 1000); ++l);		// delay NGvalue was 1000 for both loops - BBR
353
+		LED_PORT &= ~_BV(LED);					// LED off
354
+		for(l = 0; l < (F_CPU / 250); ++l);		// delay asymmteric for ADA BOOT BBR 
355
+	}
356
+
357
+	for(l = 0; l < (F_CPU / 100); ++l);		    // pause ADA BOOT BBR 
358
+		
359
+}
360
+
361
+#else
362
+
363
+void flash_led(uint8_t count)
364
+{
365
+    /* flash onboard LED three times to signal entering of bootloader */
366
+	/* l needs to be volatile or the delay loops below might get
367
+	optimized away if compiling with optimizations (DAM). */
368
+    volatile uint32_t l;
369
+
370
+    if (count == 0) {
371
+      count = 3;
372
+    }
373
+    
374
+	int8_t i;
375
+    for (i = 0; i < count; ++i) {
376
+		LED_PORT |= _BV(LED);
377
+		for(l = 0; l < (F_CPU / 1000); ++l);
378
+		LED_PORT &= ~_BV(LED);
379
+		for(l = 0; l < (F_CPU / 1000); ++l); 
380
+	}
381
+		
382
+}
383
+
384
+
385
+#endif
386
+
387
+
388
+/* end of file ATmegaBOOT.c */

BIN
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/ATmegaBOOT_644P.elf View File


+ 110
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/ATmegaBOOT_644P.hex View File

@@ -0,0 +1,110 @@
1
+:020000021000EC
2
+:10F000000C943EF80C9450F80C9450F80C9450F872
3
+:10F010000C9450F80C9450F80C9450F80C9450F850
4
+:10F020000C9450F80C9450F80C9450F80C9450F840
5
+:10F030000C9450F80C9450F80C9450F80C9450F830
6
+:10F040000C9450F80C9450F80C9450F80C9450F820
7
+:10F050000C9450F80C9450F80C9450F80C9450F810
8
+:10F060000C9450F80C9450F80C9450F80C9450F800
9
+:10F070000C9450F80C9450F80C9450F811241FBEC6
10
+:10F08000CFEFD0E1DEBFCDBF12E0A0E0B1E001C024
11
+:10F090001D92A930B107E1F70E9471F90C944FFB62
12
+:10F0A0000C9400F89091C00095FFFCCF8093C600AF
13
+:10F0B00008951F93282F332727FD3095207F307028
14
+:10F0C00094E0359527959A95E1F72A3014F0295A5E
15
+:10F0D00001C0205D182F1F701A3014F0195A01C09A
16
+:10F0E000105D822F0E9452F8812F0E9452F81F91CA
17
+:10F0F0000895EF92FF920F931F932898EE24FF2418
18
+:10F10000870113C00894E11CF11C011D111D81E051
19
+:10F11000E81689E0F8068DE3080780E0180728F074
20
+:10F12000E0910101F091020109958091C00087FFF3
21
+:10F13000E9CF289A8091C6001F910F91FF90EF9020
22
+:10F1400008950F931F930E9479F8082F0E9452F898
23
+:10F150000E9479F8182F0E9452F8013614F00755D2
24
+:10F1600003C000330CF00053113614F0175503C0E0
25
+:10F1700010330CF01053802F8295807F810F1F91E8
26
+:10F180000F91089590E007C02091C00027FFFCCFA9
27
+:10F190002091C6009F5F9817B8F308951F93182F0A
28
+:10F1A0000E9479F8803251F484E10E9452F8812F54
29
+:10F1B0000E9452F880E10E9452F80CC08091000138
30
+:10F1C0008F5F80930001853029F4E0910101F09177
31
+:10F1D000020109951F9108950E9479F8803239F44F
32
+:10F1E00084E10E9452F880E10E9452F808958091D3
33
+:10F1F00000018F5F80930001853029F4E0910101C7
34
+:10F20000F091020109950895DF93CF9300D000D0CB
35
+:10F21000CDB7DEB7882309F481E090E03DC0289A9D
36
+:10F2200019821A821B821C820CC029813A814B816F
37
+:10F230005C812F5F3F4F4F4F5F4F29833A834B8352
38
+:10F240005C8329813A814B815C8120386EE33607EB
39
+:10F2500060E0460760E0560740F3289819821A825A
40
+:10F260001B821C820CC029813A814B815C812F5FFB
41
+:10F270003F4F4F4F5F4F29833A834B835C832981F4
42
+:10F280003A814B815C8120306AEF360760E04607A7
43
+:10F2900060E0560740F39F5F981709F619821A82BB
44
+:10F2A0001B821C820BC089819A81AB81BC81019633
45
+:10F2B000A11DB11D89839A83AB83BC8389819A8107
46
+:10F2C000AB81BC81803021E7920722E0A20720E0D9
47
+:10F2D000B20748F30F900F900F900F90CF91DF91EE
48
+:10F2E0000895CF92DF92EF92FF920F931F93CF93E7
49
+:10F2F000DF93000094B714BE809160008861809312
50
+:10F3000060001092600091FD05C0E0910101F09154
51
+:10F310000201099589E18093C4001092C50088E13B
52
+:10F320008093C10086E08093C2005098589A209A3A
53
+:10F3300083E00E9404F981E00E9404F90E9479F8B8
54
+:10F34000803309F441C08133E1F40E9479F88032BE
55
+:10F3500009F097C184E10E9452F881E40E9452F8BA
56
+:10F3600086E50E9452F882E50E9452F880E20E94EF
57
+:10F3700052F889E40E9452F883E50E9452F880E531
58
+:10F380000BC1803439F40E9479F88638E8F00E9485
59
+:10F3900079F81AC0813499F40E9479F8803811F410
60
+:10F3A00082E06CC1813811F481E068C1823811F4C7
61
+:10F3B00080E164C1883909F060C183E05FC18234B3
62
+:10F3C00031F484E10E94C2F80E94ECF8B7CF853492
63
+:10F3D00011F485E0F7CF8035B9F3813531F40E941F
64
+:10F3E000ECF888E080936000FFCF823569F38535C3
65
+:10F3F00049F40E9479F8809303010E9479F8809380
66
+:10F400000401E2CF863521F484E00E94C2F835C1C0
67
+:10F41000843609F0C7C00E9479F8809306020E94E2
68
+:10F4200079F880930502809108028E7F809308020C
69
+:10F430000E9479F8853429F48091080281608093D4
70
+:10F44000080205E011E0F801119281E0E538F807C3
71
+:10F45000D9F745E0C42E41E0D42EEE24FF2408C0A5
72
+:10F460000E9479F8F60181936F010894E11CF11C68
73
+:10F470008091050290910602E816F90688F30E9431
74
+:10F4800079F8803209F0FDC08091080280FD17C034
75
+:10F4900020C0F999FECF209103013091040132BDC3
76
+:10F4A00021BDF80141918F0140BDFA9AF99A2F5F71
77
+:10F4B0003F4F3093040120930301019602C080E086
78
+:10F4C00090E020910502309106028217930708F31D
79
+:10F4D00062C08091030190910401880F991F90935D
80
+:10F4E0000401809303018091050280FF09C080918F
81
+:10F4F0000502909106020196909306028093050200
82
+:10F50000F999FECF1127E0910301F0910401C5E0C4
83
+:10F51000D1E08091050290910602103091F40091A3
84
+:10F52000570001700130D9F303E000935700E895CC
85
+:10F530000091570001700130D9F301E100935700A9
86
+:10F54000E895099019900091570001700130D9F3A6
87
+:10F5500001E000935700E8951395103898F01127B3
88
+:10F560000091570001700130D9F305E00093570076
89
+:10F57000E8950091570001700130D9F301E1009343
90
+:10F580005700E8953296029709F0C7CF103011F076
91
+:10F590000296E5CF112484E10E9452F880E10E9496
92
+:10F5A00052F8CCCE843709F055C00E9479F8809388
93
+:10F5B00006020E9479F8809305020E9479F89091E2
94
+:10F5C0000802853421F49160909308020DC09E7F5B
95
+:10F5D000909308028091030190910401880F991F74
96
+:10F5E00090930401809303010E9479F8803209F01E
97
+:10F5F000A5CE84E10E9452F800E010E023C0809183
98
+:10F60000080280FF0BC0F999FECF80910301909111
99
+:10F61000040192BD81BDF89A80B507C081FD07C085
100
+:10F62000E0910301F091040184910E9452F88091CD
101
+:10F6300003019091040101969093040180930301CA
102
+:10F640000F5F1F4F8091050290910602081719075E
103
+:10F65000B0F2A4CF853779F40E9479F8803289F42A
104
+:10F6600084E10E9452F88EE10E9452F886E90E94DD
105
+:10F6700052F88AE091CF863721F480E00E94CEF8DC
106
+:10F680005DCE809100018F5F80930001853009F08D
107
+:10F6900055CEE0910101F091020109954FCEF89409
108
+:02F6A000FFCF9A
109
+:040000031000F000F9
110
+:00000001FF

+ 56
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/Makefile View File

@@ -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=0x1F000
14
+
15
+OBJ        = $(PROGRAM).o
16
+OPTIMIZE   = -Os
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 -Os -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
ArduinoAddons/Arduino_1.x.x/sanguino/bootloaders/atmega644p/README.txt View File

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

+ 215
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Arduino.h View File

@@ -0,0 +1,215 @@
1
+#ifndef Arduino_h
2
+#define Arduino_h
3
+
4
+#include <stdlib.h>
5
+#include <string.h>
6
+#include <math.h>
7
+
8
+#include <avr/pgmspace.h>
9
+#include <avr/io.h>
10
+#include <avr/interrupt.h>
11
+
12
+#include "binary.h"
13
+
14
+#ifdef __cplusplus
15
+extern "C"{
16
+#endif
17
+
18
+#define HIGH 0x1
19
+#define LOW  0x0
20
+
21
+#define INPUT 0x0
22
+#define OUTPUT 0x1
23
+#define INPUT_PULLUP 0x2
24
+
25
+#define true 0x1
26
+#define false 0x0
27
+
28
+#define PI 3.1415926535897932384626433832795
29
+#define HALF_PI 1.5707963267948966192313216916398
30
+#define TWO_PI 6.283185307179586476925286766559
31
+#define DEG_TO_RAD 0.017453292519943295769236907684886
32
+#define RAD_TO_DEG 57.295779513082320876798154814105
33
+
34
+#define SERIAL  0x0
35
+#define DISPLAY 0x1
36
+
37
+#define LSBFIRST 0
38
+#define MSBFIRST 1
39
+
40
+#define CHANGE 1
41
+#define FALLING 2
42
+#define RISING 3
43
+
44
+#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
45
+#define DEFAULT 0
46
+#define EXTERNAL 1
47
+#define INTERNAL 2
48
+#else  
49
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
50
+#define INTERNAL1V1 2
51
+#define INTERNAL2V56 3
52
+#else
53
+#define INTERNAL 3
54
+#endif
55
+#define DEFAULT 1
56
+#define EXTERNAL 0
57
+#endif
58
+
59
+// undefine stdlib's abs if encountered
60
+#ifdef abs
61
+#undef abs
62
+#endif
63
+
64
+#define min(a,b) ((a)<(b)?(a):(b))
65
+#define max(a,b) ((a)>(b)?(a):(b))
66
+#define abs(x) ((x)>0?(x):-(x))
67
+#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
68
+#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
69
+#define radians(deg) ((deg)*DEG_TO_RAD)
70
+#define degrees(rad) ((rad)*RAD_TO_DEG)
71
+#define sq(x) ((x)*(x))
72
+
73
+#define interrupts() sei()
74
+#define noInterrupts() cli()
75
+
76
+#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
77
+#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
78
+#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
79
+
80
+#define lowByte(w) ((uint8_t) ((w) & 0xff))
81
+#define highByte(w) ((uint8_t) ((w) >> 8))
82
+
83
+#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
84
+#define bitSet(value, bit) ((value) |= (1UL << (bit)))
85
+#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
86
+#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
87
+
88
+
89
+typedef unsigned int word;
90
+
91
+#define bit(b) (1UL << (b))
92
+
93
+typedef uint8_t boolean;
94
+typedef uint8_t byte;
95
+
96
+void init(void);
97
+
98
+void pinMode(uint8_t, uint8_t);
99
+void digitalWrite(uint8_t, uint8_t);
100
+int digitalRead(uint8_t);
101
+int analogRead(uint8_t);
102
+void analogReference(uint8_t mode);
103
+void analogWrite(uint8_t, int);
104
+
105
+unsigned long millis(void);
106
+unsigned long micros(void);
107
+void delay(unsigned long);
108
+void delayMicroseconds(unsigned int us);
109
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
110
+
111
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
112
+uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
113
+
114
+void attachInterrupt(uint8_t, void (*)(void), int mode);
115
+void detachInterrupt(uint8_t);
116
+
117
+void setup(void);
118
+void loop(void);
119
+
120
+// Get the bit location within the hardware port of the given virtual pin.
121
+// This comes from the pins_*.c file for the active board configuration.
122
+
123
+#define analogInPinToBit(P) (P)
124
+
125
+// On the ATmega1280, the addresses of some of the port registers are
126
+// greater than 255, so we can't store them in uint8_t's.
127
+extern const uint16_t PROGMEM port_to_mode_PGM[];
128
+extern const uint16_t PROGMEM port_to_input_PGM[];
129
+extern const uint16_t PROGMEM port_to_output_PGM[];
130
+
131
+extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
132
+// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
133
+extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
134
+extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
135
+
136
+// Get the bit location within the hardware port of the given virtual pin.
137
+// This comes from the pins_*.c file for the active board configuration.
138
+// 
139
+// These perform slightly better as macros compared to inline functions
140
+//
141
+#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
142
+#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
143
+#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
144
+#define analogInPinToBit(P) (P)
145
+#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
146
+#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
147
+#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
148
+
149
+#define NOT_A_PIN 0
150
+#define NOT_A_PORT 0
151
+
152
+#ifdef ARDUINO_MAIN
153
+#define PA 1
154
+#define PB 2
155
+#define PC 3
156
+#define PD 4
157
+#define PE 5
158
+#define PF 6
159
+#define PG 7
160
+#define PH 8
161
+#define PJ 10
162
+#define PK 11
163
+#define PL 12
164
+#endif
165
+
166
+#define NOT_ON_TIMER 0
167
+#define TIMER0A 1
168
+#define TIMER0B 2
169
+#define TIMER1A 3
170
+#define TIMER1B 4
171
+#define TIMER2  5
172
+#define TIMER2A 6
173
+#define TIMER2B 7
174
+
175
+#define TIMER3A 8
176
+#define TIMER3B 9
177
+#define TIMER3C 10
178
+#define TIMER4A 11
179
+#define TIMER4B 12
180
+#define TIMER4C 13
181
+#define TIMER4D 14	
182
+#define TIMER5A 15
183
+#define TIMER5B 16
184
+#define TIMER5C 17
185
+
186
+#ifdef __cplusplus
187
+} // extern "C"
188
+#endif
189
+
190
+#ifdef __cplusplus
191
+#include "WCharacter.h"
192
+#include "WString.h"
193
+#include "HardwareSerial.h"
194
+
195
+uint16_t makeWord(uint16_t w);
196
+uint16_t makeWord(byte h, byte l);
197
+
198
+#define word(...) makeWord(__VA_ARGS__)
199
+
200
+unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
201
+
202
+void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
203
+void noTone(uint8_t _pin);
204
+
205
+// WMath prototypes
206
+long random(long);
207
+long random(long, long);
208
+void randomSeed(unsigned int);
209
+long map(long, long, long, long, long);
210
+
211
+#endif
212
+
213
+#include "pins_arduino.h"
214
+
215
+#endif

+ 239
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/CDC.cpp View File

@@ -0,0 +1,239 @@
1
+
2
+
3
+/* Copyright (c) 2011, Peter Barrett  
4
+**  
5
+** Permission to use, copy, modify, and/or distribute this software for  
6
+** any purpose with or without fee is hereby granted, provided that the  
7
+** above copyright notice and this permission notice appear in all copies.  
8
+** 
9
+** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL  
10
+** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED  
11
+** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR  
12
+** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES  
13
+** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,  
14
+** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  
15
+** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS  
16
+** SOFTWARE.  
17
+*/
18
+
19
+#include "Platform.h"
20
+#include "USBAPI.h"
21
+#include <avr/wdt.h>
22
+
23
+#if defined(USBCON)
24
+#ifdef CDC_ENABLED
25
+
26
+#if (RAMEND < 1000)
27
+#define SERIAL_BUFFER_SIZE 16
28
+#else
29
+#define SERIAL_BUFFER_SIZE 64
30
+#endif
31
+
32
+struct ring_buffer
33
+{
34
+	unsigned char buffer[SERIAL_BUFFER_SIZE];
35
+	volatile int head;
36
+	volatile int tail;
37
+};
38
+
39
+ring_buffer cdc_rx_buffer = { { 0 }, 0, 0};
40
+
41
+typedef struct
42
+{
43
+	u32	dwDTERate;
44
+	u8	bCharFormat;
45
+	u8 	bParityType;
46
+	u8 	bDataBits;
47
+	u8	lineState;
48
+} LineInfo;
49
+
50
+static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
51
+
52
+#define WEAK __attribute__ ((weak))
53
+
54
+extern const CDCDescriptor _cdcInterface PROGMEM;
55
+const CDCDescriptor _cdcInterface =
56
+{
57
+	D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1),
58
+
59
+	//	CDC communication interface
60
+	D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
61
+	D_CDCCS(CDC_HEADER,0x10,0x01),								// Header (1.10 bcd)
62
+	D_CDCCS(CDC_CALL_MANAGEMENT,1,1),							// Device handles call management (not)
63
+	D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,6),				// SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
64
+	D_CDCCS(CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE),	// Communication interface is master, data interface is slave 0
65
+	D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x40),
66
+
67
+	//	CDC data interface
68
+	D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0),
69
+	D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,0x40,0),
70
+	D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0)
71
+};
72
+
73
+int WEAK CDC_GetInterface(u8* interfaceNum)
74
+{
75
+	interfaceNum[0] += 2;	// uses 2
76
+	return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
77
+}
78
+
79
+bool WEAK CDC_Setup(Setup& setup)
80
+{
81
+	u8 r = setup.bRequest;
82
+	u8 requestType = setup.bmRequestType;
83
+
84
+	if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
85
+	{
86
+		if (CDC_GET_LINE_CODING == r)
87
+		{
88
+			USB_SendControl(0,(void*)&_usbLineInfo,7);
89
+			return true;
90
+		}
91
+	}
92
+
93
+	if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
94
+	{
95
+		if (CDC_SET_LINE_CODING == r)
96
+		{
97
+			USB_RecvControl((void*)&_usbLineInfo,7);
98
+			return true;
99
+		}
100
+
101
+		if (CDC_SET_CONTROL_LINE_STATE == r)
102
+		{
103
+			_usbLineInfo.lineState = setup.wValueL;
104
+
105
+			// auto-reset into the bootloader is triggered when the port, already 
106
+			// open at 1200 bps, is closed.  this is the signal to start the watchdog
107
+			// with a relatively long period so it can finish housekeeping tasks
108
+			// like servicing endpoints before the sketch ends
109
+			if (1200 == _usbLineInfo.dwDTERate) {
110
+				// We check DTR state to determine if host port is open (bit 0 of lineState).
111
+				if ((_usbLineInfo.lineState & 0x01) == 0) {
112
+					*(uint16_t *)0x0800 = 0x7777;
113
+					wdt_enable(WDTO_120MS);
114
+				} else {
115
+					// Most OSs do some intermediate steps when configuring ports and DTR can
116
+					// twiggle more than once before stabilizing.
117
+					// To avoid spurious resets we set the watchdog to 250ms and eventually
118
+					// cancel if DTR goes back high.
119
+	
120
+					wdt_disable();
121
+					wdt_reset();
122
+					*(uint16_t *)0x0800 = 0x0;
123
+				}
124
+			}
125
+			return true;
126
+		}
127
+	}
128
+	return false;
129
+}
130
+
131
+
132
+int _serialPeek = -1;
133
+void Serial_::begin(uint16_t baud_count)
134
+{
135
+}
136
+
137
+void Serial_::end(void)
138
+{
139
+}
140
+
141
+void Serial_::accept(void) 
142
+{
143
+	ring_buffer *buffer = &cdc_rx_buffer;
144
+	int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
145
+	
146
+	// if we should be storing the received character into the location
147
+	// just before the tail (meaning that the head would advance to the
148
+	// current location of the tail), we're about to overflow the buffer
149
+	// and so we don't write the character or advance the head.
150
+
151
+	// while we have room to store a byte
152
+	while (i != buffer->tail) {
153
+		int c = USB_Recv(CDC_RX);
154
+		if (c == -1)
155
+			break;	// no more data
156
+		buffer->buffer[buffer->head] = c;
157
+		buffer->head = i;
158
+
159
+		i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
160
+	}
161
+}
162
+
163
+int Serial_::available(void)
164
+{
165
+	ring_buffer *buffer = &cdc_rx_buffer;
166
+	return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE;
167
+}
168
+
169
+int Serial_::peek(void)
170
+{
171
+	ring_buffer *buffer = &cdc_rx_buffer;
172
+	if (buffer->head == buffer->tail) {
173
+		return -1;
174
+	} else {
175
+		return buffer->buffer[buffer->tail];
176
+	}
177
+}
178
+
179
+int Serial_::read(void)
180
+{
181
+	ring_buffer *buffer = &cdc_rx_buffer;
182
+	// if the head isn't ahead of the tail, we don't have any characters
183
+	if (buffer->head == buffer->tail) {
184
+		return -1;
185
+	} else {
186
+		unsigned char c = buffer->buffer[buffer->tail];
187
+		buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
188
+		return c;
189
+	}	
190
+}
191
+
192
+void Serial_::flush(void)
193
+{
194
+	USB_Flush(CDC_TX);
195
+}
196
+
197
+size_t Serial_::write(uint8_t c)
198
+{
199
+	/* only try to send bytes if the high-level CDC connection itself 
200
+	 is open (not just the pipe) - the OS should set lineState when the port
201
+	 is opened and clear lineState when the port is closed.
202
+	 bytes sent before the user opens the connection or after
203
+	 the connection is closed are lost - just like with a UART. */
204
+	
205
+	// TODO - ZE - check behavior on different OSes and test what happens if an
206
+	// open connection isn't broken cleanly (cable is yanked out, host dies
207
+	// or locks up, or host virtual serial port hangs)
208
+	if (_usbLineInfo.lineState > 0)	{
209
+		int r = USB_Send(CDC_TX,&c,1);
210
+		if (r > 0) {
211
+			return r;
212
+		} else {
213
+			setWriteError();
214
+			return 0;
215
+		}
216
+	}
217
+	setWriteError();
218
+	return 0;
219
+}
220
+
221
+// This operator is a convenient way for a sketch to check whether the
222
+// port has actually been configured and opened by the host (as opposed
223
+// to just being connected to the host).  It can be used, for example, in 
224
+// setup() before printing to ensure that an application on the host is
225
+// actually ready to receive and display the data.
226
+// We add a short delay before returning to fix a bug observed by Federico
227
+// where the port is configured (lineState != 0) but not quite opened.
228
+Serial_::operator bool() {
229
+	bool result = false;
230
+	if (_usbLineInfo.lineState > 0) 
231
+		result = true;
232
+	delay(10);
233
+	return result;
234
+}
235
+
236
+Serial_ Serial;
237
+
238
+#endif
239
+#endif /* if defined(USBCON) */

+ 26
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Client.h View File

@@ -0,0 +1,26 @@
1
+#ifndef client_h
2
+#define client_h
3
+#include "Print.h"
4
+#include "Stream.h"
5
+#include "IPAddress.h"
6
+
7
+class Client : public Stream {
8
+
9
+public:
10
+  virtual int connect(IPAddress ip, uint16_t port) =0;
11
+  virtual int connect(const char *host, uint16_t port) =0;
12
+  virtual size_t write(uint8_t) =0;
13
+  virtual size_t write(const uint8_t *buf, size_t size) =0;
14
+  virtual int available() = 0;
15
+  virtual int read() = 0;
16
+  virtual int read(uint8_t *buf, size_t size) = 0;
17
+  virtual int peek() = 0;
18
+  virtual void flush() = 0;
19
+  virtual void stop() = 0;
20
+  virtual uint8_t connected() = 0;
21
+  virtual operator bool() = 0;
22
+protected:
23
+  uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
24
+};
25
+
26
+#endif

+ 520
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/HID.cpp View File

@@ -0,0 +1,520 @@
1
+
2
+
3
+/* Copyright (c) 2011, Peter Barrett  
4
+**  
5
+** Permission to use, copy, modify, and/or distribute this software for  
6
+** any purpose with or without fee is hereby granted, provided that the  
7
+** above copyright notice and this permission notice appear in all copies.  
8
+** 
9
+** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL  
10
+** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED  
11
+** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR  
12
+** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES  
13
+** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,  
14
+** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  
15
+** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS  
16
+** SOFTWARE.  
17
+*/
18
+
19
+#include "Platform.h"
20
+#include "USBAPI.h"
21
+#include "USBDesc.h"
22
+
23
+#if defined(USBCON)
24
+#ifdef HID_ENABLED
25
+
26
+//#define RAWHID_ENABLED
27
+
28
+//	Singletons for mouse and keyboard
29
+
30
+Mouse_ Mouse;
31
+Keyboard_ Keyboard;
32
+
33
+//================================================================================
34
+//================================================================================
35
+
36
+//	HID report descriptor
37
+
38
+#define LSB(_x) ((_x) & 0xFF)
39
+#define MSB(_x) ((_x) >> 8)
40
+
41
+#define RAWHID_USAGE_PAGE	0xFFC0
42
+#define RAWHID_USAGE		0x0C00
43
+#define RAWHID_TX_SIZE 64
44
+#define RAWHID_RX_SIZE 64
45
+
46
+extern const u8 _hidReportDescriptor[] PROGMEM;
47
+const u8 _hidReportDescriptor[] = {
48
+	
49
+	//	Mouse
50
+    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)	// 54
51
+    0x09, 0x02,                    // USAGE (Mouse)
52
+    0xa1, 0x01,                    // COLLECTION (Application)
53
+    0x09, 0x01,                    //   USAGE (Pointer)
54
+    0xa1, 0x00,                    //   COLLECTION (Physical)
55
+    0x85, 0x01,                    //     REPORT_ID (1)
56
+    0x05, 0x09,                    //     USAGE_PAGE (Button)
57
+    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
58
+    0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
59
+    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
60
+    0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
61
+    0x95, 0x03,                    //     REPORT_COUNT (3)
62
+    0x75, 0x01,                    //     REPORT_SIZE (1)
63
+    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
64
+    0x95, 0x01,                    //     REPORT_COUNT (1)
65
+    0x75, 0x05,                    //     REPORT_SIZE (5)
66
+    0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
67
+    0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
68
+    0x09, 0x30,                    //     USAGE (X)
69
+    0x09, 0x31,                    //     USAGE (Y)
70
+    0x09, 0x38,                    //     USAGE (Wheel)
71
+    0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
72
+    0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
73
+    0x75, 0x08,                    //     REPORT_SIZE (8)
74
+    0x95, 0x03,                    //     REPORT_COUNT (3)
75
+    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
76
+    0xc0,                          //   END_COLLECTION
77
+    0xc0,                          // END_COLLECTION
78
+
79
+	//	Keyboard
80
+    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)	// 47
81
+    0x09, 0x06,                    // USAGE (Keyboard)
82
+    0xa1, 0x01,                    // COLLECTION (Application)
83
+    0x85, 0x02,                    //   REPORT_ID (2)
84
+    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
85
+   
86
+	0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
87
+    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
88
+    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
89
+    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
90
+    0x75, 0x01,                    //   REPORT_SIZE (1)
91
+    
92
+	0x95, 0x08,                    //   REPORT_COUNT (8)
93
+    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
94
+    0x95, 0x01,                    //   REPORT_COUNT (1)
95
+    0x75, 0x08,                    //   REPORT_SIZE (8)
96
+    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
97
+    
98
+	0x95, 0x06,                    //   REPORT_COUNT (6)
99
+    0x75, 0x08,                    //   REPORT_SIZE (8)
100
+    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
101
+    0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
102
+    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
103
+    
104
+	0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
105
+    0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
106
+    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
107
+    0xc0,                          // END_COLLECTION
108
+
109
+#if RAWHID_ENABLED
110
+	//	RAW HID
111
+	0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),	// 30
112
+	0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
113
+
114
+	0xA1, 0x01,				// Collection 0x01
115
+    0x85, 0x03,             // REPORT_ID (3)
116
+	0x75, 0x08,				// report size = 8 bits
117
+	0x15, 0x00,				// logical minimum = 0
118
+	0x26, 0xFF, 0x00,		// logical maximum = 255
119
+
120
+	0x95, 64,				// report count TX
121
+	0x09, 0x01,				// usage
122
+	0x81, 0x02,				// Input (array)
123
+
124
+	0x95, 64,				// report count RX
125
+	0x09, 0x02,				// usage
126
+	0x91, 0x02,				// Output (array)
127
+	0xC0					// end collection
128
+#endif
129
+};
130
+
131
+extern const HIDDescriptor _hidInterface PROGMEM;
132
+const HIDDescriptor _hidInterface =
133
+{
134
+	D_INTERFACE(HID_INTERFACE,1,3,0,0),
135
+	D_HIDREPORT(sizeof(_hidReportDescriptor)),
136
+	D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01)
137
+};
138
+
139
+//================================================================================
140
+//================================================================================
141
+//	Driver
142
+
143
+u8 _hid_protocol = 1;
144
+u8 _hid_idle = 1;
145
+
146
+#define WEAK __attribute__ ((weak))
147
+
148
+int WEAK HID_GetInterface(u8* interfaceNum)
149
+{
150
+	interfaceNum[0] += 1;	// uses 1
151
+	return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface));
152
+}
153
+
154
+int WEAK HID_GetDescriptor(int i)
155
+{
156
+	return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor));
157
+}
158
+
159
+void WEAK HID_SendReport(u8 id, const void* data, int len)
160
+{
161
+	USB_Send(HID_TX, &id, 1);
162
+	USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
163
+}
164
+
165
+bool WEAK HID_Setup(Setup& setup)
166
+{
167
+	u8 r = setup.bRequest;
168
+	u8 requestType = setup.bmRequestType;
169
+	if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
170
+	{
171
+		if (HID_GET_REPORT == r)
172
+		{
173
+			//HID_GetReport();
174
+			return true;
175
+		}
176
+		if (HID_GET_PROTOCOL == r)
177
+		{
178
+			//Send8(_hid_protocol);	// TODO
179
+			return true;
180
+		}
181
+	}
182
+	
183
+	if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
184
+	{
185
+		if (HID_SET_PROTOCOL == r)
186
+		{
187
+			_hid_protocol = setup.wValueL;
188
+			return true;
189
+		}
190
+
191
+		if (HID_SET_IDLE == r)
192
+		{
193
+			_hid_idle = setup.wValueL;
194
+			return true;
195
+		}
196
+	}
197
+	return false;
198
+}
199
+
200
+//================================================================================
201
+//================================================================================
202
+//	Mouse
203
+
204
+Mouse_::Mouse_(void) : _buttons(0)
205
+{
206
+}
207
+
208
+void Mouse_::begin(void) 
209
+{
210
+}
211
+
212
+void Mouse_::end(void) 
213
+{
214
+}
215
+
216
+void Mouse_::click(uint8_t b)
217
+{
218
+	_buttons = b;
219
+	move(0,0,0);
220
+	_buttons = 0;
221
+	move(0,0,0);
222
+}
223
+
224
+void Mouse_::move(signed char x, signed char y, signed char wheel)
225
+{
226
+	u8 m[4];
227
+	m[0] = _buttons;
228
+	m[1] = x;
229
+	m[2] = y;
230
+	m[3] = wheel;
231
+	HID_SendReport(1,m,4);
232
+}
233
+
234
+void Mouse_::buttons(uint8_t b)
235
+{
236
+	if (b != _buttons)
237
+	{
238
+		_buttons = b;
239
+		move(0,0,0);
240
+	}
241
+}
242
+
243
+void Mouse_::press(uint8_t b) 
244
+{
245
+	buttons(_buttons | b);
246
+}
247
+
248
+void Mouse_::release(uint8_t b)
249
+{
250
+	buttons(_buttons & ~b);
251
+}
252
+
253
+bool Mouse_::isPressed(uint8_t b)
254
+{
255
+	if ((b & _buttons) > 0) 
256
+		return true;
257
+	return false;
258
+}
259
+
260
+//================================================================================
261
+//================================================================================
262
+//	Keyboard
263
+
264
+Keyboard_::Keyboard_(void) 
265
+{
266
+}
267
+
268
+void Keyboard_::begin(void) 
269
+{
270
+}
271
+
272
+void Keyboard_::end(void) 
273
+{
274
+}
275
+
276
+void Keyboard_::sendReport(KeyReport* keys)
277
+{
278
+	HID_SendReport(2,keys,sizeof(KeyReport));
279
+}
280
+
281
+extern
282
+const uint8_t _asciimap[128] PROGMEM;
283
+
284
+#define SHIFT 0x80
285
+const uint8_t _asciimap[128] =
286
+{
287
+	0x00,             // NUL
288
+	0x00,             // SOH
289
+	0x00,             // STX
290
+	0x00,             // ETX
291
+	0x00,             // EOT
292
+	0x00,             // ENQ
293
+	0x00,             // ACK  
294
+	0x00,             // BEL
295
+	0x2a,			// BS	Backspace
296
+	0x2b,			// TAB	Tab
297
+	0x28,			// LF	Enter
298
+	0x00,             // VT 
299
+	0x00,             // FF 
300
+	0x00,             // CR 
301
+	0x00,             // SO 
302
+	0x00,             // SI 
303
+	0x00,             // DEL
304
+	0x00,             // DC1
305
+	0x00,             // DC2
306
+	0x00,             // DC3
307
+	0x00,             // DC4
308
+	0x00,             // NAK
309
+	0x00,             // SYN
310
+	0x00,             // ETB
311
+	0x00,             // CAN
312
+	0x00,             // EM 
313
+	0x00,             // SUB
314
+	0x00,             // ESC
315
+	0x00,             // FS 
316
+	0x00,             // GS 
317
+	0x00,             // RS 
318
+	0x00,             // US 
319
+
320
+	0x2c,		   //  ' '
321
+	0x1e|SHIFT,	   // !
322
+	0x34|SHIFT,	   // "
323
+	0x20|SHIFT,    // #
324
+	0x21|SHIFT,    // $
325
+	0x22|SHIFT,    // %
326
+	0x24|SHIFT,    // &
327
+	0x34,          // '
328
+	0x26|SHIFT,    // (
329
+	0x27|SHIFT,    // )
330
+	0x25|SHIFT,    // *
331
+	0x2e|SHIFT,    // +
332
+	0x36,          // ,
333
+	0x2d,          // -
334
+	0x37,          // .
335
+	0x38,          // /
336
+	0x27,          // 0
337
+	0x1e,          // 1
338
+	0x1f,          // 2
339
+	0x20,          // 3
340
+	0x21,          // 4
341
+	0x22,          // 5
342
+	0x23,          // 6
343
+	0x24,          // 7
344
+	0x25,          // 8
345
+	0x26,          // 9
346
+	0x33|SHIFT,      // :
347
+	0x33,          // ;
348
+	0x36|SHIFT,      // <
349
+	0x2e,          // =
350
+	0x37|SHIFT,      // >
351
+	0x38|SHIFT,      // ?
352
+	0x1f|SHIFT,      // @
353
+	0x04|SHIFT,      // A
354
+	0x05|SHIFT,      // B
355
+	0x06|SHIFT,      // C
356
+	0x07|SHIFT,      // D
357
+	0x08|SHIFT,      // E
358
+	0x09|SHIFT,      // F
359
+	0x0a|SHIFT,      // G
360
+	0x0b|SHIFT,      // H
361
+	0x0c|SHIFT,      // I
362
+	0x0d|SHIFT,      // J
363
+	0x0e|SHIFT,      // K
364
+	0x0f|SHIFT,      // L
365
+	0x10|SHIFT,      // M
366
+	0x11|SHIFT,      // N
367
+	0x12|SHIFT,      // O
368
+	0x13|SHIFT,      // P
369
+	0x14|SHIFT,      // Q
370
+	0x15|SHIFT,      // R
371
+	0x16|SHIFT,      // S
372
+	0x17|SHIFT,      // T
373
+	0x18|SHIFT,      // U
374
+	0x19|SHIFT,      // V
375
+	0x1a|SHIFT,      // W
376
+	0x1b|SHIFT,      // X
377
+	0x1c|SHIFT,      // Y
378
+	0x1d|SHIFT,      // Z
379
+	0x2f,          // [
380
+	0x31,          // bslash
381
+	0x30,          // ]
382
+	0x23|SHIFT,    // ^
383
+	0x2d|SHIFT,    // _
384
+	0x35,          // `
385
+	0x04,          // a
386
+	0x05,          // b
387
+	0x06,          // c
388
+	0x07,          // d
389
+	0x08,          // e
390
+	0x09,          // f
391
+	0x0a,          // g
392
+	0x0b,          // h
393
+	0x0c,          // i
394
+	0x0d,          // j
395
+	0x0e,          // k
396
+	0x0f,          // l
397
+	0x10,          // m
398
+	0x11,          // n
399
+	0x12,          // o
400
+	0x13,          // p
401
+	0x14,          // q
402
+	0x15,          // r
403
+	0x16,          // s
404
+	0x17,          // t
405
+	0x18,          // u
406
+	0x19,          // v
407
+	0x1a,          // w
408
+	0x1b,          // x
409
+	0x1c,          // y
410
+	0x1d,          // z
411
+	0x2f|SHIFT,    // 
412
+	0x31|SHIFT,    // |
413
+	0x30|SHIFT,    // }
414
+	0x35|SHIFT,    // ~
415
+	0				// DEL
416
+};
417
+
418
+uint8_t USBPutChar(uint8_t c);
419
+
420
+// press() adds the specified key (printing, non-printing, or modifier)
421
+// to the persistent key report and sends the report.  Because of the way 
422
+// USB HID works, the host acts like the key remains pressed until we 
423
+// call release(), releaseAll(), or otherwise clear the report and resend.
424
+size_t Keyboard_::press(uint8_t k) 
425
+{
426
+	uint8_t i;
427
+	if (k >= 136) {			// it's a non-printing key (not a modifier)
428
+		k = k - 136;
429
+	} else if (k >= 128) {	// it's a modifier key
430
+		_keyReport.modifiers |= (1<<(k-128));
431
+		k = 0;
432
+	} else {				// it's a printing key
433
+		k = pgm_read_byte(_asciimap + k);
434
+		if (!k) {
435
+			setWriteError();
436
+			return 0;
437
+		}
438
+		if (k & 0x80) {						// it's a capital letter or other character reached with shift
439
+			_keyReport.modifiers |= 0x02;	// the left shift modifier
440
+			k &= 0x7F;
441
+		}
442
+	}
443
+	
444
+	// Add k to the key report only if it's not already present
445
+	// and if there is an empty slot.
446
+	if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && 
447
+		_keyReport.keys[2] != k && _keyReport.keys[3] != k &&
448
+		_keyReport.keys[4] != k && _keyReport.keys[5] != k) {
449
+		
450
+		for (i=0; i<6; i++) {
451
+			if (_keyReport.keys[i] == 0x00) {
452
+				_keyReport.keys[i] = k;
453
+				break;
454
+			}
455
+		}
456
+		if (i == 6) {
457
+			setWriteError();
458
+			return 0;
459
+		}	
460
+	}
461
+	sendReport(&_keyReport);
462
+	return 1;
463
+}
464
+
465
+// release() takes the specified key out of the persistent key report and
466
+// sends the report.  This tells the OS the key is no longer pressed and that
467
+// it shouldn't be repeated any more.
468
+size_t Keyboard_::release(uint8_t k) 
469
+{
470
+	uint8_t i;
471
+	if (k >= 136) {			// it's a non-printing key (not a modifier)
472
+		k = k - 136;
473
+	} else if (k >= 128) {	// it's a modifier key
474
+		_keyReport.modifiers &= ~(1<<(k-128));
475
+		k = 0;
476
+	} else {				// it's a printing key
477
+		k = pgm_read_byte(_asciimap + k);
478
+		if (!k) {
479
+			return 0;
480
+		}
481
+		if (k & 0x80) {							// it's a capital letter or other character reached with shift
482
+			_keyReport.modifiers &= ~(0x02);	// the left shift modifier
483
+			k &= 0x7F;
484
+		}
485
+	}
486
+	
487
+	// Test the key report to see if k is present.  Clear it if it exists.
488
+	// Check all positions in case the key is present more than once (which it shouldn't be)
489
+	for (i=0; i<6; i++) {
490
+		if (0 != k && _keyReport.keys[i] == k) {
491
+			_keyReport.keys[i] = 0x00;
492
+		}
493
+	}
494
+
495
+	sendReport(&_keyReport);
496
+	return 1;
497
+}
498
+
499
+void Keyboard_::releaseAll(void)
500
+{
501
+	_keyReport.keys[0] = 0;
502
+	_keyReport.keys[1] = 0;	
503
+	_keyReport.keys[2] = 0;
504
+	_keyReport.keys[3] = 0;	
505
+	_keyReport.keys[4] = 0;
506
+	_keyReport.keys[5] = 0;	
507
+	_keyReport.modifiers = 0;
508
+	sendReport(&_keyReport);
509
+}
510
+
511
+size_t Keyboard_::write(uint8_t c)
512
+{	
513
+	uint8_t p = press(c);		// Keydown
514
+	uint8_t r = release(c);		// Keyup
515
+	return (p);					// just return the result of press() since release() almost always returns 1
516
+}
517
+
518
+#endif
519
+
520
+#endif /* if defined(USBCON) */

+ 519
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/HardwareSerial.cpp View File

@@ -0,0 +1,519 @@
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
+  Modified 14 August 2012 by Alarus
22
+*/
23
+
24
+#include <stdlib.h>
25
+#include <stdio.h>
26
+#include <string.h>
27
+#include <inttypes.h>
28
+#include "Arduino.h"
29
+#include "wiring_private.h"
30
+
31
+// this next line disables the entire HardwareSerial.cpp, 
32
+// this is so I can support Attiny series and any other chip without a uart
33
+#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
34
+
35
+#include "HardwareSerial.h"
36
+
37
+/*
38
+ * on ATmega8, the uart and its bits are not numbered, so there is no "TXC0"
39
+ * definition.
40
+ */
41
+#if !defined(TXC0)
42
+#if defined(TXC)
43
+#define TXC0 TXC
44
+#elif defined(TXC1)
45
+// Some devices have uart1 but no uart0
46
+#define TXC0 TXC1
47
+#else
48
+#error TXC0 not definable in HardwareSerial.h
49
+#endif
50
+#endif
51
+
52
+// Define constants and variables for buffering incoming serial data.  We're
53
+// using a ring buffer (I think), in which head is the index of the location
54
+// to which to write the next incoming character and tail is the index of the
55
+// location from which to read.
56
+#if (RAMEND < 1000)
57
+  #define SERIAL_BUFFER_SIZE 16
58
+#else
59
+  #define SERIAL_BUFFER_SIZE 64
60
+#endif
61
+
62
+struct ring_buffer
63
+{
64
+  unsigned char buffer[SERIAL_BUFFER_SIZE];
65
+  volatile unsigned int head;
66
+  volatile unsigned int tail;
67
+};
68
+
69
+#if defined(USBCON)
70
+  ring_buffer rx_buffer = { { 0 }, 0, 0};
71
+  ring_buffer tx_buffer = { { 0 }, 0, 0};
72
+#endif
73
+#if defined(UBRRH) || defined(UBRR0H)
74
+  ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
75
+  ring_buffer tx_buffer  =  { { 0 }, 0, 0 };
76
+#endif
77
+#if defined(UBRR1H)
78
+  ring_buffer rx_buffer1  =  { { 0 }, 0, 0 };
79
+  ring_buffer tx_buffer1  =  { { 0 }, 0, 0 };
80
+#endif
81
+#if defined(UBRR2H)
82
+  ring_buffer rx_buffer2  =  { { 0 }, 0, 0 };
83
+  ring_buffer tx_buffer2  =  { { 0 }, 0, 0 };
84
+#endif
85
+#if defined(UBRR3H)
86
+  ring_buffer rx_buffer3  =  { { 0 }, 0, 0 };
87
+  ring_buffer tx_buffer3  =  { { 0 }, 0, 0 };
88
+#endif
89
+
90
+inline void store_char(unsigned char c, ring_buffer *buffer)
91
+{
92
+  int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;
93
+
94
+  // if we should be storing the received character into the location
95
+  // just before the tail (meaning that the head would advance to the
96
+  // current location of the tail), we're about to overflow the buffer
97
+  // and so we don't write the character or advance the head.
98
+  if (i != buffer->tail) {
99
+    buffer->buffer[buffer->head] = c;
100
+    buffer->head = i;
101
+  }
102
+}
103
+
104
+#if !defined(USART0_RX_vect) && defined(USART1_RX_vect)
105
+// do nothing - on the 32u4 the first USART is USART1
106
+#else
107
+#if !defined(USART_RX_vect) && !defined(SIG_USART0_RECV) && \
108
+    !defined(SIG_UART0_RECV) && !defined(USART0_RX_vect) && \
109
+	!defined(SIG_UART_RECV)
110
+  #error "Don't know what the Data Received vector is called for the first UART"
111
+#else
112
+  void serialEvent() __attribute__((weak));
113
+  void serialEvent() {}
114
+  #define serialEvent_implemented
115
+#if defined(USART_RX_vect)
116
+  SIGNAL(USART_RX_vect)
117
+#elif defined(SIG_USART0_RECV)
118
+  SIGNAL(SIG_USART0_RECV)
119
+#elif defined(SIG_UART0_RECV)
120
+  SIGNAL(SIG_UART0_RECV)
121
+#elif defined(USART0_RX_vect)
122
+  SIGNAL(USART0_RX_vect)
123
+#elif defined(SIG_UART_RECV)
124
+  SIGNAL(SIG_UART_RECV)
125
+#endif
126
+  {
127
+  #if defined(UDR0)
128
+    if (bit_is_clear(UCSR0A, UPE0)) {
129
+      unsigned char c = UDR0;
130
+      store_char(c, &rx_buffer);
131
+    } else {
132
+      unsigned char c = UDR0;
133
+    };
134
+  #elif defined(UDR)
135
+    if (bit_is_clear(UCSRA, PE)) {
136
+      unsigned char c = UDR;
137
+      store_char(c, &rx_buffer);
138
+    } else {
139
+      unsigned char c = UDR;
140
+    };
141
+  #else
142
+    #error UDR not defined
143
+  #endif
144
+  }
145
+#endif
146
+#endif
147
+
148
+#if defined(USART1_RX_vect)
149
+  void serialEvent1() __attribute__((weak));
150
+  void serialEvent1() {}
151
+  #define serialEvent1_implemented
152
+  SIGNAL(USART1_RX_vect)
153
+  {
154
+    if (bit_is_clear(UCSR1A, UPE1)) {
155
+      unsigned char c = UDR1;
156
+      store_char(c, &rx_buffer1);
157
+    } else {
158
+      unsigned char c = UDR1;
159
+    };
160
+  }
161
+#elif defined(SIG_USART1_RECV)
162
+  #error SIG_USART1_RECV
163
+#endif
164
+
165
+#if defined(USART2_RX_vect) && defined(UDR2)
166
+  void serialEvent2() __attribute__((weak));
167
+  void serialEvent2() {}
168
+  #define serialEvent2_implemented
169
+  SIGNAL(USART2_RX_vect)
170
+  {
171
+    if (bit_is_clear(UCSR2A, UPE2)) {
172
+      unsigned char c = UDR2;
173
+      store_char(c, &rx_buffer2);
174
+    } else {
175
+      unsigned char c = UDR2;
176
+    };
177
+  }
178
+#elif defined(SIG_USART2_RECV)
179
+  #error SIG_USART2_RECV
180
+#endif
181
+
182
+#if defined(USART3_RX_vect) && defined(UDR3)
183
+  void serialEvent3() __attribute__((weak));
184
+  void serialEvent3() {}
185
+  #define serialEvent3_implemented
186
+  SIGNAL(USART3_RX_vect)
187
+  {
188
+    if (bit_is_clear(UCSR3A, UPE3)) {
189
+      unsigned char c = UDR3;
190
+      store_char(c, &rx_buffer3);
191
+    } else {
192
+      unsigned char c = UDR3;
193
+    };
194
+  }
195
+#elif defined(SIG_USART3_RECV)
196
+  #error SIG_USART3_RECV
197
+#endif
198
+
199
+void serialEventRun(void)
200
+{
201
+#ifdef serialEvent_implemented
202
+  if (Serial.available()) serialEvent();
203
+#endif
204
+#ifdef serialEvent1_implemented
205
+  if (Serial1.available()) serialEvent1();
206
+#endif
207
+#ifdef serialEvent2_implemented
208
+  if (Serial2.available()) serialEvent2();
209
+#endif
210
+#ifdef serialEvent3_implemented
211
+  if (Serial3.available()) serialEvent3();
212
+#endif
213
+}
214
+
215
+
216
+#if !defined(USART0_UDRE_vect) && defined(USART1_UDRE_vect)
217
+// do nothing - on the 32u4 the first USART is USART1
218
+#else
219
+#if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect)
220
+  #error "Don't know what the Data Register Empty vector is called for the first UART"
221
+#else
222
+#if defined(UART0_UDRE_vect)
223
+ISR(UART0_UDRE_vect)
224
+#elif defined(UART_UDRE_vect)
225
+ISR(UART_UDRE_vect)
226
+#elif defined(USART0_UDRE_vect)
227
+ISR(USART0_UDRE_vect)
228
+#elif defined(USART_UDRE_vect)
229
+ISR(USART_UDRE_vect)
230
+#endif
231
+{
232
+  if (tx_buffer.head == tx_buffer.tail) {
233
+	// Buffer empty, so disable interrupts
234
+#if defined(UCSR0B)
235
+    cbi(UCSR0B, UDRIE0);
236
+#else
237
+    cbi(UCSRB, UDRIE);
238
+#endif
239
+  }
240
+  else {
241
+    // There is more data in the output buffer. Send the next byte
242
+    unsigned char c = tx_buffer.buffer[tx_buffer.tail];
243
+    tx_buffer.tail = (tx_buffer.tail + 1) % SERIAL_BUFFER_SIZE;
244
+	
245
+  #if defined(UDR0)
246
+    UDR0 = c;
247
+  #elif defined(UDR)
248
+    UDR = c;
249
+  #else
250
+    #error UDR not defined
251
+  #endif
252
+  }
253
+}
254
+#endif
255
+#endif
256
+
257
+#ifdef USART1_UDRE_vect
258
+ISR(USART1_UDRE_vect)
259
+{
260
+  if (tx_buffer1.head == tx_buffer1.tail) {
261
+	// Buffer empty, so disable interrupts
262
+    cbi(UCSR1B, UDRIE1);
263
+  }
264
+  else {
265
+    // There is more data in the output buffer. Send the next byte
266
+    unsigned char c = tx_buffer1.buffer[tx_buffer1.tail];
267
+    tx_buffer1.tail = (tx_buffer1.tail + 1) % SERIAL_BUFFER_SIZE;
268
+	
269
+    UDR1 = c;
270
+  }
271
+}
272
+#endif
273
+
274
+#ifdef USART2_UDRE_vect
275
+ISR(USART2_UDRE_vect)
276
+{
277
+  if (tx_buffer2.head == tx_buffer2.tail) {
278
+	// Buffer empty, so disable interrupts
279
+    cbi(UCSR2B, UDRIE2);
280
+  }
281
+  else {
282
+    // There is more data in the output buffer. Send the next byte
283
+    unsigned char c = tx_buffer2.buffer[tx_buffer2.tail];
284
+    tx_buffer2.tail = (tx_buffer2.tail + 1) % SERIAL_BUFFER_SIZE;
285
+	
286
+    UDR2 = c;
287
+  }
288
+}
289
+#endif
290
+
291
+#ifdef USART3_UDRE_vect
292
+ISR(USART3_UDRE_vect)
293
+{
294
+  if (tx_buffer3.head == tx_buffer3.tail) {
295
+	// Buffer empty, so disable interrupts
296
+    cbi(UCSR3B, UDRIE3);
297
+  }
298
+  else {
299
+    // There is more data in the output buffer. Send the next byte
300
+    unsigned char c = tx_buffer3.buffer[tx_buffer3.tail];
301
+    tx_buffer3.tail = (tx_buffer3.tail + 1) % SERIAL_BUFFER_SIZE;
302
+	
303
+    UDR3 = c;
304
+  }
305
+}
306
+#endif
307
+
308
+
309
+// Constructors ////////////////////////////////////////////////////////////////
310
+
311
+HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
312
+  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
313
+  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
314
+  volatile uint8_t *ucsrc, volatile uint8_t *udr,
315
+  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x)
316
+{
317
+  _rx_buffer = rx_buffer;
318
+  _tx_buffer = tx_buffer;
319
+  _ubrrh = ubrrh;
320
+  _ubrrl = ubrrl;
321
+  _ucsra = ucsra;
322
+  _ucsrb = ucsrb;
323
+  _ucsrc = ucsrc;
324
+  _udr = udr;
325
+  _rxen = rxen;
326
+  _txen = txen;
327
+  _rxcie = rxcie;
328
+  _udrie = udrie;
329
+  _u2x = u2x;
330
+}
331
+
332
+// Public Methods //////////////////////////////////////////////////////////////
333
+
334
+void HardwareSerial::begin(unsigned long baud)
335
+{
336
+  uint16_t baud_setting;
337
+  bool use_u2x = true;
338
+
339
+#if F_CPU == 16000000UL
340
+  // hardcoded exception for compatibility with the bootloader shipped
341
+  // with the Duemilanove and previous boards and the firmware on the 8U2
342
+  // on the Uno and Mega 2560.
343
+  if (baud == 57600) {
344
+    use_u2x = false;
345
+  }
346
+#endif
347
+
348
+try_again:
349
+  
350
+  if (use_u2x) {
351
+    *_ucsra = 1 << _u2x;
352
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
353
+  } else {
354
+    *_ucsra = 0;
355
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
356
+  }
357
+  
358
+  if ((baud_setting > 4095) && use_u2x)
359
+  {
360
+    use_u2x = false;
361
+    goto try_again;
362
+  }
363
+
364
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
365
+  *_ubrrh = baud_setting >> 8;
366
+  *_ubrrl = baud_setting;
367
+
368
+  transmitting = false;
369
+
370
+  sbi(*_ucsrb, _rxen);
371
+  sbi(*_ucsrb, _txen);
372
+  sbi(*_ucsrb, _rxcie);
373
+  cbi(*_ucsrb, _udrie);
374
+}
375
+
376
+void HardwareSerial::begin(unsigned long baud, byte config)
377
+{
378
+  uint16_t baud_setting;
379
+  uint8_t current_config;
380
+  bool use_u2x = true;
381
+
382
+#if F_CPU == 16000000UL
383
+  // hardcoded exception for compatibility with the bootloader shipped
384
+  // with the Duemilanove and previous boards and the firmware on the 8U2
385
+  // on the Uno and Mega 2560.
386
+  if (baud == 57600) {
387
+    use_u2x = false;
388
+  }
389
+#endif
390
+
391
+try_again:
392
+  
393
+  if (use_u2x) {
394
+    *_ucsra = 1 << _u2x;
395
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
396
+  } else {
397
+    *_ucsra = 0;
398
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
399
+  }
400
+  
401
+  if ((baud_setting > 4095) && use_u2x)
402
+  {
403
+    use_u2x = false;
404
+    goto try_again;
405
+  }
406
+
407
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
408
+  *_ubrrh = baud_setting >> 8;
409
+  *_ubrrl = baud_setting;
410
+
411
+  //set the data bits, parity, and stop bits
412
+#if defined(__AVR_ATmega8__)
413
+  config |= 0x80; // select UCSRC register (shared with UBRRH)
414
+#endif
415
+  *_ucsrc = config;
416
+  
417
+  sbi(*_ucsrb, _rxen);
418
+  sbi(*_ucsrb, _txen);
419
+  sbi(*_ucsrb, _rxcie);
420
+  cbi(*_ucsrb, _udrie);
421
+}
422
+
423
+void HardwareSerial::end()
424
+{
425
+  // wait for transmission of outgoing data
426
+  while (_tx_buffer->head != _tx_buffer->tail)
427
+    ;
428
+
429
+  cbi(*_ucsrb, _rxen);
430
+  cbi(*_ucsrb, _txen);
431
+  cbi(*_ucsrb, _rxcie);  
432
+  cbi(*_ucsrb, _udrie);
433
+  
434
+  // clear any received data
435
+  _rx_buffer->head = _rx_buffer->tail;
436
+}
437
+
438
+int HardwareSerial::available(void)
439
+{
440
+  return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE;
441
+}
442
+
443
+int HardwareSerial::peek(void)
444
+{
445
+  if (_rx_buffer->head == _rx_buffer->tail) {
446
+    return -1;
447
+  } else {
448
+    return _rx_buffer->buffer[_rx_buffer->tail];
449
+  }
450
+}
451
+
452
+int HardwareSerial::read(void)
453
+{
454
+  // if the head isn't ahead of the tail, we don't have any characters
455
+  if (_rx_buffer->head == _rx_buffer->tail) {
456
+    return -1;
457
+  } else {
458
+    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
459
+    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
460
+    return c;
461
+  }
462
+}
463
+
464
+void HardwareSerial::flush()
465
+{
466
+  // UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT
467
+  while (transmitting && ! (*_ucsra & _BV(TXC0)));
468
+  transmitting = false;
469
+}
470
+
471
+size_t HardwareSerial::write(uint8_t c)
472
+{
473
+  int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;
474
+	
475
+  // If the output buffer is full, there's nothing for it other than to 
476
+  // wait for the interrupt handler to empty it a bit
477
+  // ???: return 0 here instead?
478
+  while (i == _tx_buffer->tail)
479
+    ;
480
+	
481
+  _tx_buffer->buffer[_tx_buffer->head] = c;
482
+  _tx_buffer->head = i;
483
+	
484
+  sbi(*_ucsrb, _udrie);
485
+  // clear the TXC bit -- "can be cleared by writing a one to its bit location"
486
+  transmitting = true;
487
+  sbi(*_ucsra, TXC0);
488
+  
489
+  return 1;
490
+}
491
+
492
+HardwareSerial::operator bool() {
493
+	return true;
494
+}
495
+
496
+// Preinstantiate Objects //////////////////////////////////////////////////////
497
+
498
+#if defined(UBRRH) && defined(UBRRL)
499
+  HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X);
500
+#elif defined(UBRR0H) && defined(UBRR0L)
501
+  HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0);
502
+#elif defined(USBCON)
503
+  // do nothing - Serial object and buffers are initialized in CDC code
504
+#else
505
+  #error no serial port defined  (port 0)
506
+#endif
507
+
508
+#if defined(UBRR1H)
509
+  HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1);
510
+#endif
511
+#if defined(UBRR2H)
512
+  HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2);
513
+#endif
514
+#if defined(UBRR3H)
515
+  HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
516
+#endif
517
+
518
+#endif // whole file
519
+

+ 115
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/HardwareSerial.h View File

@@ -0,0 +1,115 @@
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
+  Modified 14 August 2012 by Alarus
21
+*/
22
+
23
+#ifndef HardwareSerial_h
24
+#define HardwareSerial_h
25
+
26
+#include <inttypes.h>
27
+
28
+#include "Stream.h"
29
+
30
+struct ring_buffer;
31
+
32
+class HardwareSerial : public Stream
33
+{
34
+  private:
35
+    ring_buffer *_rx_buffer;
36
+    ring_buffer *_tx_buffer;
37
+    volatile uint8_t *_ubrrh;
38
+    volatile uint8_t *_ubrrl;
39
+    volatile uint8_t *_ucsra;
40
+    volatile uint8_t *_ucsrb;
41
+    volatile uint8_t *_ucsrc;
42
+    volatile uint8_t *_udr;
43
+    uint8_t _rxen;
44
+    uint8_t _txen;
45
+    uint8_t _rxcie;
46
+    uint8_t _udrie;
47
+    uint8_t _u2x;
48
+    bool transmitting;
49
+  public:
50
+    HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
51
+      volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
52
+      volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
53
+      volatile uint8_t *ucsrc, volatile uint8_t *udr,
54
+      uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
55
+    void begin(unsigned long);
56
+    void begin(unsigned long, uint8_t);
57
+    void end();
58
+    virtual int available(void);
59
+    virtual int peek(void);
60
+    virtual int read(void);
61
+    virtual void flush(void);
62
+    virtual size_t write(uint8_t);
63
+    inline size_t write(unsigned long n) { return write((uint8_t)n); }
64
+    inline size_t write(long n) { return write((uint8_t)n); }
65
+    inline size_t write(unsigned int n) { return write((uint8_t)n); }
66
+    inline size_t write(int n) { return write((uint8_t)n); }
67
+    using Print::write; // pull in write(str) and write(buf, size) from Print
68
+    operator bool();
69
+};
70
+
71
+// Define config for Serial.begin(baud, config);
72
+#define SERIAL_5N1 0x00
73
+#define SERIAL_6N1 0x02
74
+#define SERIAL_7N1 0x04
75
+#define SERIAL_8N1 0x06
76
+#define SERIAL_5N2 0x08
77
+#define SERIAL_6N2 0x0A
78
+#define SERIAL_7N2 0x0C
79
+#define SERIAL_8N2 0x0E
80
+#define SERIAL_5E1 0x20
81
+#define SERIAL_6E1 0x22
82
+#define SERIAL_7E1 0x24
83
+#define SERIAL_8E1 0x26
84
+#define SERIAL_5E2 0x28
85
+#define SERIAL_6E2 0x2A
86
+#define SERIAL_7E2 0x2C
87
+#define SERIAL_8E2 0x2E
88
+#define SERIAL_5O1 0x30
89
+#define SERIAL_6O1 0x32
90
+#define SERIAL_7O1 0x34
91
+#define SERIAL_8O1 0x36
92
+#define SERIAL_5O2 0x38
93
+#define SERIAL_6O2 0x3A
94
+#define SERIAL_7O2 0x3C
95
+#define SERIAL_8O2 0x3E
96
+
97
+#if defined(UBRRH) || defined(UBRR0H)
98
+  extern HardwareSerial Serial;
99
+#elif defined(USBCON)
100
+  #include "USBAPI.h"
101
+//  extern HardwareSerial Serial_;  
102
+#endif
103
+#if defined(UBRR1H)
104
+  extern HardwareSerial Serial1;
105
+#endif
106
+#if defined(UBRR2H)
107
+  extern HardwareSerial Serial2;
108
+#endif
109
+#if defined(UBRR3H)
110
+  extern HardwareSerial Serial3;
111
+#endif
112
+
113
+extern void serialEventRun(void) __attribute__((weak));
114
+
115
+#endif

+ 56
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/IPAddress.cpp View File

@@ -0,0 +1,56 @@
1
+
2
+#include <Arduino.h>
3
+#include <IPAddress.h>
4
+
5
+IPAddress::IPAddress()
6
+{
7
+    memset(_address, 0, sizeof(_address));
8
+}
9
+
10
+IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
11
+{
12
+    _address[0] = first_octet;
13
+    _address[1] = second_octet;
14
+    _address[2] = third_octet;
15
+    _address[3] = fourth_octet;
16
+}
17
+
18
+IPAddress::IPAddress(uint32_t address)
19
+{
20
+    memcpy(_address, &address, sizeof(_address));
21
+}
22
+
23
+IPAddress::IPAddress(const uint8_t *address)
24
+{
25
+    memcpy(_address, address, sizeof(_address));
26
+}
27
+
28
+IPAddress& IPAddress::operator=(const uint8_t *address)
29
+{
30
+    memcpy(_address, address, sizeof(_address));
31
+    return *this;
32
+}
33
+
34
+IPAddress& IPAddress::operator=(uint32_t address)
35
+{
36
+    memcpy(_address, (const uint8_t *)&address, sizeof(_address));
37
+    return *this;
38
+}
39
+
40
+bool IPAddress::operator==(const uint8_t* addr)
41
+{
42
+    return memcmp(addr, _address, sizeof(_address)) == 0;
43
+}
44
+
45
+size_t IPAddress::printTo(Print& p) const
46
+{
47
+    size_t n = 0;
48
+    for (int i =0; i < 3; i++)
49
+    {
50
+        n += p.print(_address[i], DEC);
51
+        n += p.print('.');
52
+    }
53
+    n += p.print(_address[3], DEC);
54
+    return n;
55
+}
56
+

+ 76
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/IPAddress.h View File

@@ -0,0 +1,76 @@
1
+/*
2
+ *
3
+ * MIT License:
4
+ * Copyright (c) 2011 Adrian McEwen
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ *
23
+ * adrianm@mcqn.com 1/1/2011
24
+ */
25
+
26
+#ifndef IPAddress_h
27
+#define IPAddress_h
28
+
29
+#include <Printable.h>
30
+
31
+// A class to make it easier to handle and pass around IP addresses
32
+
33
+class IPAddress : public Printable {
34
+private:
35
+    uint8_t _address[4];  // IPv4 address
36
+    // Access the raw byte array containing the address.  Because this returns a pointer
37
+    // to the internal structure rather than a copy of the address this function should only
38
+    // be used when you know that the usage of the returned uint8_t* will be transient and not
39
+    // stored.
40
+    uint8_t* raw_address() { return _address; };
41
+
42
+public:
43
+    // Constructors
44
+    IPAddress();
45
+    IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
46
+    IPAddress(uint32_t address);
47
+    IPAddress(const uint8_t *address);
48
+
49
+    // Overloaded cast operator to allow IPAddress objects to be used where a pointer
50
+    // to a four-byte uint8_t array is expected
51
+    operator uint32_t() { return *((uint32_t*)_address); };
52
+    bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
53
+    bool operator==(const uint8_t* addr);
54
+
55
+    // Overloaded index operator to allow getting and setting individual octets of the address
56
+    uint8_t operator[](int index) const { return _address[index]; };
57
+    uint8_t& operator[](int index) { return _address[index]; };
58
+
59
+    // Overloaded copy operators to allow initialisation of IPAddress objects from other types
60
+    IPAddress& operator=(const uint8_t *address);
61
+    IPAddress& operator=(uint32_t address);
62
+
63
+    virtual size_t printTo(Print& p) const;
64
+
65
+    friend class EthernetClass;
66
+    friend class UDP;
67
+    friend class Client;
68
+    friend class Server;
69
+    friend class DhcpClass;
70
+    friend class DNSClient;
71
+};
72
+
73
+const IPAddress INADDR_NONE(0,0,0,0);
74
+
75
+
76
+#endif

+ 23
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Platform.h View File

@@ -0,0 +1,23 @@
1
+
2
+#ifndef __PLATFORM_H__
3
+#define __PLATFORM_H__
4
+
5
+#include <inttypes.h>
6
+#include <avr/pgmspace.h>
7
+#include <avr/eeprom.h>
8
+#include <avr/interrupt.h>
9
+#include <util/delay.h>
10
+
11
+typedef unsigned char u8;
12
+typedef unsigned short u16;
13
+typedef unsigned long u32;
14
+
15
+#include "Arduino.h"
16
+
17
+#if defined(USBCON)
18
+	#include "USBDesc.h"
19
+	#include "USBCore.h"
20
+	#include "USBAPI.h"
21
+#endif /* if defined(USBCON) */
22
+
23
+#endif

+ 268
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Print.cpp View File

@@ -0,0 +1,268 @@
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 "Arduino.h"
27
+
28
+#include "Print.h"
29
+
30
+// Public Methods //////////////////////////////////////////////////////////////
31
+
32
+/* default implementation: may be overridden */
33
+size_t Print::write(const uint8_t *buffer, size_t size)
34
+{
35
+  size_t n = 0;
36
+  while (size--) {
37
+    n += write(*buffer++);
38
+  }
39
+  return n;
40
+}
41
+
42
+size_t Print::print(const __FlashStringHelper *ifsh)
43
+{
44
+  const char PROGMEM *p = (const char PROGMEM *)ifsh;
45
+  size_t n = 0;
46
+  while (1) {
47
+    unsigned char c = pgm_read_byte(p++);
48
+    if (c == 0) break;
49
+    n += write(c);
50
+  }
51
+  return n;
52
+}
53
+
54
+size_t Print::print(const String &s)
55
+{
56
+  size_t n = 0;
57
+  for (uint16_t i = 0; i < s.length(); i++) {
58
+    n += write(s[i]);
59
+  }
60
+  return n;
61
+}
62
+
63
+size_t Print::print(const char str[])
64
+{
65
+  return write(str);
66
+}
67
+
68
+size_t Print::print(char c)
69
+{
70
+  return write(c);
71
+}
72
+
73
+size_t Print::print(unsigned char b, int base)
74
+{
75
+  return print((unsigned long) b, base);
76
+}
77
+
78
+size_t Print::print(int n, int base)
79
+{
80
+  return print((long) n, base);
81
+}
82
+
83
+size_t Print::print(unsigned int n, int base)
84
+{
85
+  return print((unsigned long) n, base);
86
+}
87
+
88
+size_t Print::print(long n, int base)
89
+{
90
+  if (base == 0) {
91
+    return write(n);
92
+  } else if (base == 10) {
93
+    if (n < 0) {
94
+      int t = print('-');
95
+      n = -n;
96
+      return printNumber(n, 10) + t;
97
+    }
98
+    return printNumber(n, 10);
99
+  } else {
100
+    return printNumber(n, base);
101
+  }
102
+}
103
+
104
+size_t Print::print(unsigned long n, int base)
105
+{
106
+  if (base == 0) return write(n);
107
+  else return printNumber(n, base);
108
+}
109
+
110
+size_t Print::print(double n, int digits)
111
+{
112
+  return printFloat(n, digits);
113
+}
114
+
115
+size_t Print::println(const __FlashStringHelper *ifsh)
116
+{
117
+  size_t n = print(ifsh);
118
+  n += println();
119
+  return n;
120
+}
121
+
122
+size_t Print::print(const Printable& x)
123
+{
124
+  return x.printTo(*this);
125
+}
126
+
127
+size_t Print::println(void)
128
+{
129
+  size_t n = print('\r');
130
+  n += print('\n');
131
+  return n;
132
+}
133
+
134
+size_t Print::println(const String &s)
135
+{
136
+  size_t n = print(s);
137
+  n += println();
138
+  return n;
139
+}
140
+
141
+size_t Print::println(const char c[])
142
+{
143
+  size_t n = print(c);
144
+  n += println();
145
+  return n;
146
+}
147
+
148
+size_t Print::println(char c)
149
+{
150
+  size_t n = print(c);
151
+  n += println();
152
+  return n;
153
+}
154
+
155
+size_t Print::println(unsigned char b, int base)
156
+{
157
+  size_t n = print(b, base);
158
+  n += println();
159
+  return n;
160
+}
161
+
162
+size_t Print::println(int num, int base)
163
+{
164
+  size_t n = print(num, base);
165
+  n += println();
166
+  return n;
167
+}
168
+
169
+size_t Print::println(unsigned int num, int base)
170
+{
171
+  size_t n = print(num, base);
172
+  n += println();
173
+  return n;
174
+}
175
+
176
+size_t Print::println(long num, int base)
177
+{
178
+  size_t n = print(num, base);
179
+  n += println();
180
+  return n;
181
+}
182
+
183
+size_t Print::println(unsigned long num, int base)
184
+{
185
+  size_t n = print(num, base);
186
+  n += println();
187
+  return n;
188
+}
189
+
190
+size_t Print::println(double num, int digits)
191
+{
192
+  size_t n = print(num, digits);
193
+  n += println();
194
+  return n;
195
+}
196
+
197
+size_t Print::println(const Printable& x)
198
+{
199
+  size_t n = print(x);
200
+  n += println();
201
+  return n;
202
+}
203
+
204
+// Private Methods /////////////////////////////////////////////////////////////
205
+
206
+size_t Print::printNumber(unsigned long n, uint8_t base) {
207
+  char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
208
+  char *str = &buf[sizeof(buf) - 1];
209
+
210
+  *str = '\0';
211
+
212
+  // prevent crash if called with base == 1
213
+  if (base < 2) base = 10;
214
+
215
+  do {
216
+    unsigned long m = n;
217
+    n /= base;
218
+    char c = m - base * n;
219
+    *--str = c < 10 ? c + '0' : c + 'A' - 10;
220
+  } while(n);
221
+
222
+  return write(str);
223
+}
224
+
225
+size_t Print::printFloat(double number, uint8_t digits) 
226
+{ 
227
+  size_t n = 0;
228
+  
229
+  if (isnan(number)) return print("nan");
230
+  if (isinf(number)) return print("inf");
231
+  if (number > 4294967040.0) return print ("ovf");  // constant determined empirically
232
+  if (number <-4294967040.0) return print ("ovf");  // constant determined empirically
233
+  
234
+  // Handle negative numbers
235
+  if (number < 0.0)
236
+  {
237
+     n += print('-');
238
+     number = -number;
239
+  }
240
+
241
+  // Round correctly so that print(1.999, 2) prints as "2.00"
242
+  double rounding = 0.5;
243
+  for (uint8_t i=0; i<digits; ++i)
244
+    rounding /= 10.0;
245
+  
246
+  number += rounding;
247
+
248
+  // Extract the integer part of the number and print it
249
+  unsigned long int_part = (unsigned long)number;
250
+  double remainder = number - (double)int_part;
251
+  n += print(int_part);
252
+
253
+  // Print the decimal point, but only if there are digits beyond
254
+  if (digits > 0) {
255
+    n += print("."); 
256
+  }
257
+
258
+  // Extract digits from the remainder one at a time
259
+  while (digits-- > 0)
260
+  {
261
+    remainder *= 10.0;
262
+    int toPrint = int(remainder);
263
+    n += print(toPrint);
264
+    remainder -= toPrint; 
265
+  } 
266
+  
267
+  return n;
268
+}

+ 81
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Print.h View File

@@ -0,0 +1,81 @@
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
+#include "Printable.h"
28
+
29
+#define DEC 10
30
+#define HEX 16
31
+#define OCT 8
32
+#define BIN 2
33
+
34
+class Print
35
+{
36
+  private:
37
+    int write_error;
38
+    size_t printNumber(unsigned long, uint8_t);
39
+    size_t printFloat(double, uint8_t);
40
+  protected:
41
+    void setWriteError(int err = 1) { write_error = err; }
42
+  public:
43
+    Print() : write_error(0) {}
44
+  
45
+    int getWriteError() { return write_error; }
46
+    void clearWriteError() { setWriteError(0); }
47
+  
48
+    virtual size_t write(uint8_t) = 0;
49
+    size_t write(const char *str) {
50
+      if (str == NULL) return 0;
51
+      return write((const uint8_t *)str, strlen(str));
52
+    }
53
+    virtual size_t write(const uint8_t *buffer, size_t size);
54
+    
55
+    size_t print(const __FlashStringHelper *);
56
+    size_t print(const String &);
57
+    size_t print(const char[]);
58
+    size_t print(char);
59
+    size_t print(unsigned char, int = DEC);
60
+    size_t print(int, int = DEC);
61
+    size_t print(unsigned int, int = DEC);
62
+    size_t print(long, int = DEC);
63
+    size_t print(unsigned long, int = DEC);
64
+    size_t print(double, int = 2);
65
+    size_t print(const Printable&);
66
+
67
+    size_t println(const __FlashStringHelper *);
68
+    size_t println(const String &s);
69
+    size_t println(const char[]);
70
+    size_t println(char);
71
+    size_t println(unsigned char, int = DEC);
72
+    size_t println(int, int = DEC);
73
+    size_t println(unsigned int, int = DEC);
74
+    size_t println(long, int = DEC);
75
+    size_t println(unsigned long, int = DEC);
76
+    size_t println(double, int = 2);
77
+    size_t println(const Printable&);
78
+    size_t println(void);
79
+};
80
+
81
+#endif

+ 40
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Printable.h View File

@@ -0,0 +1,40 @@
1
+/*
2
+  Printable.h - Interface class that allows printing of complex types
3
+  Copyright (c) 2011 Adrian McEwen.  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 Printable_h
21
+#define Printable_h
22
+
23
+#include <new.h>
24
+
25
+class Print;
26
+
27
+/** The Printable class provides a way for new classes to allow themselves to be printed.
28
+    By deriving from Printable and implementing the printTo method, it will then be possible
29
+    for users to print out instances of this class by passing them into the usual
30
+    Print::print and Print::println methods.
31
+*/
32
+
33
+class Printable
34
+{
35
+  public:
36
+    virtual size_t printTo(Print& p) const = 0;
37
+};
38
+
39
+#endif
40
+

+ 9
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Server.h View File

@@ -0,0 +1,9 @@
1
+#ifndef server_h
2
+#define server_h
3
+
4
+class Server : public Print {
5
+public:
6
+  virtual void begin() =0;
7
+};
8
+
9
+#endif

+ 270
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Stream.cpp View File

@@ -0,0 +1,270 @@
1
+/*
2
+ Stream.cpp - adds parsing methods to Stream class
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
+ Created July 2011
20
+ parsing functions based on TextFinder library by Michael Margolis
21
+ */
22
+
23
+#include "Arduino.h"
24
+#include "Stream.h"
25
+
26
+#define PARSE_TIMEOUT 1000  // default number of milli-seconds to wait
27
+#define NO_SKIP_CHAR  1  // a magic char not found in a valid ASCII numeric field
28
+
29
+// private method to read stream with timeout
30
+int Stream::timedRead()
31
+{
32
+  int c;
33
+  _startMillis = millis();
34
+  do {
35
+    c = read();
36
+    if (c >= 0) return c;
37
+  } while(millis() - _startMillis < _timeout);
38
+  return -1;     // -1 indicates timeout
39
+}
40
+
41
+// private method to peek stream with timeout
42
+int Stream::timedPeek()
43
+{
44
+  int c;
45
+  _startMillis = millis();
46
+  do {
47
+    c = peek();
48
+    if (c >= 0) return c;
49
+  } while(millis() - _startMillis < _timeout);
50
+  return -1;     // -1 indicates timeout
51
+}
52
+
53
+// returns peek of the next digit in the stream or -1 if timeout
54
+// discards non-numeric characters
55
+int Stream::peekNextDigit()
56
+{
57
+  int c;
58
+  while (1) {
59
+    c = timedPeek();
60
+    if (c < 0) return c;  // timeout
61
+    if (c == '-') return c;
62
+    if (c >= '0' && c <= '9') return c;
63
+    read();  // discard non-numeric
64
+  }
65
+}
66
+
67
+// Public Methods
68
+//////////////////////////////////////////////////////////////
69
+
70
+void Stream::setTimeout(unsigned long timeout)  // sets the maximum number of milliseconds to wait
71
+{
72
+  _timeout = timeout;
73
+}
74
+
75
+ // find returns true if the target string is found
76
+bool  Stream::find(char *target)
77
+{
78
+  return findUntil(target, NULL);
79
+}
80
+
81
+// reads data from the stream until the target string of given length is found
82
+// returns true if target string is found, false if timed out
83
+bool Stream::find(char *target, size_t length)
84
+{
85
+  return findUntil(target, length, NULL, 0);
86
+}
87
+
88
+// as find but search ends if the terminator string is found
89
+bool  Stream::findUntil(char *target, char *terminator)
90
+{
91
+  return findUntil(target, strlen(target), terminator, strlen(terminator));
92
+}
93
+
94
+// reads data from the stream until the target string of the given length is found
95
+// search terminated if the terminator string is found
96
+// returns true if target string is found, false if terminated or timed out
97
+bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen)
98
+{
99
+  size_t index = 0;  // maximum target string length is 64k bytes!
100
+  size_t termIndex = 0;
101
+  int c;
102
+  
103
+  if( *target == 0)
104
+    return true;   // return true if target is a null string
105
+  while( (c = timedRead()) > 0){
106
+    
107
+    if(c != target[index])
108
+      index = 0; // reset index if any char does not match
109
+    
110
+    if( c == target[index]){
111
+      //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
112
+      if(++index >= targetLen){ // return true if all chars in the target match
113
+        return true;
114
+      }
115
+    }
116
+    
117
+    if(termLen > 0 && c == terminator[termIndex]){
118
+      if(++termIndex >= termLen)
119
+        return false;       // return false if terminate string found before target string
120
+    }
121
+    else
122
+      termIndex = 0;
123
+  }
124
+  return false;
125
+}
126
+
127
+
128
+// returns the first valid (long) integer value from the current position.
129
+// initial characters that are not digits (or the minus sign) are skipped
130
+// function is terminated by the first character that is not a digit.
131
+long Stream::parseInt()
132
+{
133
+  return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
134
+}
135
+
136
+// as above but a given skipChar is ignored
137
+// this allows format characters (typically commas) in values to be ignored
138
+long Stream::parseInt(char skipChar)
139
+{
140
+  boolean isNegative = false;
141
+  long value = 0;
142
+  int c;
143
+
144
+  c = peekNextDigit();
145
+  // ignore non numeric leading characters
146
+  if(c < 0)
147
+    return 0; // zero returned if timeout
148
+
149
+  do{
150
+    if(c == skipChar)
151
+      ; // ignore this charactor
152
+    else if(c == '-')
153
+      isNegative = true;
154
+    else if(c >= '0' && c <= '9')        // is c a digit?
155
+      value = value * 10 + c - '0';
156
+    read();  // consume the character we got with peek
157
+    c = timedPeek();
158
+  }
159
+  while( (c >= '0' && c <= '9') || c == skipChar );
160
+
161
+  if(isNegative)
162
+    value = -value;
163
+  return value;
164
+}
165
+
166
+
167
+// as parseInt but returns a floating point value
168
+float Stream::parseFloat()
169
+{
170
+  return parseFloat(NO_SKIP_CHAR);
171
+}
172
+
173
+// as above but the given skipChar is ignored
174
+// this allows format characters (typically commas) in values to be ignored
175
+float Stream::parseFloat(char skipChar){
176
+  boolean isNegative = false;
177
+  boolean isFraction = false;
178
+  long value = 0;
179
+  char c;
180
+  float fraction = 1.0;
181
+
182
+  c = peekNextDigit();
183
+    // ignore non numeric leading characters
184
+  if(c < 0)
185
+    return 0; // zero returned if timeout
186
+
187
+  do{
188
+    if(c == skipChar)
189
+      ; // ignore
190
+    else if(c == '-')
191
+      isNegative = true;
192
+    else if (c == '.')
193
+      isFraction = true;
194
+    else if(c >= '0' && c <= '9')  {      // is c a digit?
195
+      value = value * 10 + c - '0';
196
+      if(isFraction)
197
+         fraction *= 0.1;
198
+    }
199
+    read();  // consume the character we got with peek
200
+    c = timedPeek();
201
+  }
202
+  while( (c >= '0' && c <= '9')  || c == '.' || c == skipChar );
203
+
204
+  if(isNegative)
205
+    value = -value;
206
+  if(isFraction)
207
+    return value * fraction;
208
+  else
209
+    return value;
210
+}
211
+
212
+// read characters from stream into buffer
213
+// terminates if length characters have been read, or timeout (see setTimeout)
214
+// returns the number of characters placed in the buffer
215
+// the buffer is NOT null terminated.
216
+//
217
+size_t Stream::readBytes(char *buffer, size_t length)
218
+{
219
+  size_t count = 0;
220
+  while (count < length) {
221
+    int c = timedRead();
222
+    if (c < 0) break;
223
+    *buffer++ = (char)c;
224
+    count++;
225
+  }
226
+  return count;
227
+}
228
+
229
+
230
+// as readBytes with terminator character
231
+// terminates if length characters have been read, timeout, or if the terminator character  detected
232
+// returns the number of characters placed in the buffer (0 means no valid data found)
233
+
234
+size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
235
+{
236
+  if (length < 1) return 0;
237
+  size_t index = 0;
238
+  while (index < length) {
239
+    int c = timedRead();
240
+    if (c < 0 || c == terminator) break;
241
+    *buffer++ = (char)c;
242
+    index++;
243
+  }
244
+  return index; // return number of characters, not including null terminator
245
+}
246
+
247
+String Stream::readString()
248
+{
249
+  String ret;
250
+  int c = timedRead();
251
+  while (c >= 0)
252
+  {
253
+    ret += (char)c;
254
+    c = timedRead();
255
+  }
256
+  return ret;
257
+}
258
+
259
+String Stream::readStringUntil(char terminator)
260
+{
261
+  String ret;
262
+  int c = timedRead();
263
+  while (c >= 0 && c != terminator)
264
+  {
265
+    ret += (char)c;
266
+    c = timedRead();
267
+  }
268
+  return ret;
269
+}
270
+

+ 96
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Stream.h View File

@@ -0,0 +1,96 @@
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
+  parsing functions based on TextFinder library by Michael Margolis
20
+*/
21
+
22
+#ifndef Stream_h
23
+#define Stream_h
24
+
25
+#include <inttypes.h>
26
+#include "Print.h"
27
+
28
+// compatability macros for testing
29
+/*
30
+#define   getInt()            parseInt()
31
+#define   getInt(skipChar)    parseInt(skipchar)
32
+#define   getFloat()          parseFloat()
33
+#define   getFloat(skipChar)  parseFloat(skipChar)
34
+#define   getString( pre_string, post_string, buffer, length)
35
+readBytesBetween( pre_string, terminator, buffer, length)
36
+*/
37
+
38
+class Stream : public Print
39
+{
40
+  private:
41
+    unsigned long _timeout;      // number of milliseconds to wait for the next char before aborting timed read
42
+    unsigned long _startMillis;  // used for timeout measurement
43
+    int timedRead();    // private method to read stream with timeout
44
+    int timedPeek();    // private method to peek stream with timeout
45
+    int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout
46
+
47
+  public:
48
+    virtual int available() = 0;
49
+    virtual int read() = 0;
50
+    virtual int peek() = 0;
51
+    virtual void flush() = 0;
52
+
53
+    Stream() {_timeout=1000;}
54
+
55
+// parsing methods
56
+
57
+  void setTimeout(unsigned long timeout);  // sets maximum milliseconds to wait for stream data, default is 1 second
58
+
59
+  bool find(char *target);   // reads data from the stream until the target string is found
60
+  // returns true if target string is found, false if timed out (see setTimeout)
61
+
62
+  bool find(char *target, size_t length);   // reads data from the stream until the target string of given length is found
63
+  // returns true if target string is found, false if timed out
64
+
65
+  bool findUntil(char *target, char *terminator);   // as find but search ends if the terminator string is found
66
+
67
+  bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen);   // as above but search ends if the terminate string is found
68
+
69
+
70
+  long parseInt(); // returns the first valid (long) integer value from the current position.
71
+  // initial characters that are not digits (or the minus sign) are skipped
72
+  // integer is terminated by the first character that is not a digit.
73
+
74
+  float parseFloat();               // float version of parseInt
75
+
76
+  size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
77
+  // terminates if length characters have been read or timeout (see setTimeout)
78
+  // returns the number of characters placed in the buffer (0 means no valid data found)
79
+
80
+  size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
81
+  // terminates if length characters have been read, timeout, or if the terminator character  detected
82
+  // returns the number of characters placed in the buffer (0 means no valid data found)
83
+
84
+  // Arduino String functions to be added here
85
+  String readString();
86
+  String readStringUntil(char terminator);
87
+
88
+  protected:
89
+  long parseInt(char skipChar); // as above but the given skipChar is ignored
90
+  // as above but the given skipChar is ignored
91
+  // this allows format characters (typically commas) in values to be ignored
92
+
93
+  float parseFloat(char skipChar);  // as above but the given skipChar is ignored
94
+};
95
+
96
+#endif

+ 616
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Tone.cpp View File

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

+ 196
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/USBAPI.h View File

@@ -0,0 +1,196 @@
1
+
2
+
3
+#ifndef __USBAPI__
4
+#define __USBAPI__
5
+
6
+#if defined(USBCON)
7
+
8
+//================================================================================
9
+//================================================================================
10
+//	USB
11
+
12
+class USBDevice_
13
+{
14
+public:
15
+	USBDevice_();
16
+	bool configured();
17
+
18
+	void attach();
19
+	void detach();	// Serial port goes down too...
20
+	void poll();
21
+};
22
+extern USBDevice_ USBDevice;
23
+
24
+//================================================================================
25
+//================================================================================
26
+//	Serial over CDC (Serial1 is the physical port)
27
+
28
+class Serial_ : public Stream
29
+{
30
+private:
31
+	ring_buffer *_cdc_rx_buffer;
32
+public:
33
+	void begin(uint16_t baud_count);
34
+	void end(void);
35
+
36
+	virtual int available(void);
37
+	virtual void accept(void);
38
+	virtual int peek(void);
39
+	virtual int read(void);
40
+	virtual void flush(void);
41
+	virtual size_t write(uint8_t);
42
+	using Print::write; // pull in write(str) and write(buf, size) from Print
43
+	operator bool();
44
+};
45
+extern Serial_ Serial;
46
+
47
+//================================================================================
48
+//================================================================================
49
+//	Mouse
50
+
51
+#define MOUSE_LEFT 1
52
+#define MOUSE_RIGHT 2
53
+#define MOUSE_MIDDLE 4
54
+#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
55
+
56
+class Mouse_
57
+{
58
+private:
59
+	uint8_t _buttons;
60
+	void buttons(uint8_t b);
61
+public:
62
+	Mouse_(void);
63
+	void begin(void);
64
+	void end(void);
65
+	void click(uint8_t b = MOUSE_LEFT);
66
+	void move(signed char x, signed char y, signed char wheel = 0);	
67
+	void press(uint8_t b = MOUSE_LEFT);		// press LEFT by default
68
+	void release(uint8_t b = MOUSE_LEFT);	// release LEFT by default
69
+	bool isPressed(uint8_t b = MOUSE_LEFT);	// check LEFT by default
70
+};
71
+extern Mouse_ Mouse;
72
+
73
+//================================================================================
74
+//================================================================================
75
+//	Keyboard
76
+
77
+#define KEY_LEFT_CTRL		0x80
78
+#define KEY_LEFT_SHIFT		0x81
79
+#define KEY_LEFT_ALT		0x82
80
+#define KEY_LEFT_GUI		0x83
81
+#define KEY_RIGHT_CTRL		0x84
82
+#define KEY_RIGHT_SHIFT		0x85
83
+#define KEY_RIGHT_ALT		0x86
84
+#define KEY_RIGHT_GUI		0x87
85
+
86
+#define KEY_UP_ARROW		0xDA
87
+#define KEY_DOWN_ARROW		0xD9
88
+#define KEY_LEFT_ARROW		0xD8
89
+#define KEY_RIGHT_ARROW		0xD7
90
+#define KEY_BACKSPACE		0xB2
91
+#define KEY_TAB				0xB3
92
+#define KEY_RETURN			0xB0
93
+#define KEY_ESC				0xB1
94
+#define KEY_INSERT			0xD1
95
+#define KEY_DELETE			0xD4
96
+#define KEY_PAGE_UP			0xD3
97
+#define KEY_PAGE_DOWN		0xD6
98
+#define KEY_HOME			0xD2
99
+#define KEY_END				0xD5
100
+#define KEY_CAPS_LOCK		0xC1
101
+#define KEY_F1				0xC2
102
+#define KEY_F2				0xC3
103
+#define KEY_F3				0xC4
104
+#define KEY_F4				0xC5
105
+#define KEY_F5				0xC6
106
+#define KEY_F6				0xC7
107
+#define KEY_F7				0xC8
108
+#define KEY_F8				0xC9
109
+#define KEY_F9				0xCA
110
+#define KEY_F10				0xCB
111
+#define KEY_F11				0xCC
112
+#define KEY_F12				0xCD
113
+
114
+//	Low level key report: up to 6 keys and shift, ctrl etc at once
115
+typedef struct
116
+{
117
+	uint8_t modifiers;
118
+	uint8_t reserved;
119
+	uint8_t keys[6];
120
+} KeyReport;
121
+
122
+class Keyboard_ : public Print
123
+{
124
+private:
125
+	KeyReport _keyReport;
126
+	void sendReport(KeyReport* keys);
127
+public:
128
+	Keyboard_(void);
129
+	void begin(void);
130
+	void end(void);
131
+	virtual size_t write(uint8_t k);
132
+	virtual size_t press(uint8_t k);
133
+	virtual size_t release(uint8_t k);
134
+	virtual void releaseAll(void);
135
+};
136
+extern Keyboard_ Keyboard;
137
+
138
+//================================================================================
139
+//================================================================================
140
+//	Low level API
141
+
142
+typedef struct
143
+{
144
+	uint8_t bmRequestType;
145
+	uint8_t bRequest;
146
+	uint8_t wValueL;
147
+	uint8_t wValueH;
148
+	uint16_t wIndex;
149
+	uint16_t wLength;
150
+} Setup;
151
+
152
+//================================================================================
153
+//================================================================================
154
+//	HID 'Driver'
155
+
156
+int		HID_GetInterface(uint8_t* interfaceNum);
157
+int		HID_GetDescriptor(int i);
158
+bool	HID_Setup(Setup& setup);
159
+void	HID_SendReport(uint8_t id, const void* data, int len);
160
+
161
+//================================================================================
162
+//================================================================================
163
+//	MSC 'Driver'
164
+
165
+int		MSC_GetInterface(uint8_t* interfaceNum);
166
+int		MSC_GetDescriptor(int i);
167
+bool	MSC_Setup(Setup& setup);
168
+bool	MSC_Data(uint8_t rx,uint8_t tx);
169
+
170
+//================================================================================
171
+//================================================================================
172
+//	CSC 'Driver'
173
+
174
+int		CDC_GetInterface(uint8_t* interfaceNum);
175
+int		CDC_GetDescriptor(int i);
176
+bool	CDC_Setup(Setup& setup);
177
+
178
+//================================================================================
179
+//================================================================================
180
+
181
+#define TRANSFER_PGM		0x80
182
+#define TRANSFER_RELEASE	0x40
183
+#define TRANSFER_ZERO		0x20
184
+
185
+int USB_SendControl(uint8_t flags, const void* d, int len);
186
+int USB_RecvControl(void* d, int len);
187
+
188
+uint8_t	USB_Available(uint8_t ep);
189
+int USB_Send(uint8_t ep, const void* data, int len);	// blocking
190
+int USB_Recv(uint8_t ep, void* data, int len);		// non-blocking
191
+int USB_Recv(uint8_t ep);							// non-blocking
192
+void USB_Flush(uint8_t ep);
193
+
194
+#endif
195
+
196
+#endif /* if defined(USBCON) */

+ 684
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/USBCore.cpp View File

@@ -0,0 +1,684 @@
1
+
2
+
3
+/* Copyright (c) 2010, Peter Barrett  
4
+**  
5
+** Permission to use, copy, modify, and/or distribute this software for  
6
+** any purpose with or without fee is hereby granted, provided that the  
7
+** above copyright notice and this permission notice appear in all copies.  
8
+** 
9
+** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL  
10
+** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED  
11
+** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR  
12
+** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES  
13
+** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,  
14
+** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  
15
+** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS  
16
+** SOFTWARE.  
17
+*/
18
+
19
+#include "Platform.h"
20
+#include "USBAPI.h"
21
+#include "USBDesc.h"
22
+
23
+#if defined(USBCON)
24
+
25
+#define EP_TYPE_CONTROL				0x00
26
+#define EP_TYPE_BULK_IN				0x81
27
+#define EP_TYPE_BULK_OUT			0x80
28
+#define EP_TYPE_INTERRUPT_IN		0xC1
29
+#define EP_TYPE_INTERRUPT_OUT		0xC0
30
+#define EP_TYPE_ISOCHRONOUS_IN		0x41
31
+#define EP_TYPE_ISOCHRONOUS_OUT		0x40
32
+
33
+/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
34
+#define TX_RX_LED_PULSE_MS 100
35
+volatile u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
36
+volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
37
+
38
+//==================================================================
39
+//==================================================================
40
+
41
+extern const u16 STRING_LANGUAGE[] PROGMEM;
42
+extern const u16 STRING_IPRODUCT[] PROGMEM;
43
+extern const u16 STRING_IMANUFACTURER[] PROGMEM;
44
+extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM;
45
+extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
46
+
47
+const u16 STRING_LANGUAGE[2] = {
48
+	(3<<8) | (2+2),
49
+	0x0409	// English
50
+};
51
+
52
+const u16 STRING_IPRODUCT[17] = {
53
+	(3<<8) | (2+2*16),
54
+#if USB_PID == 0x8036	
55
+	'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o'
56
+#elif USB_PID == 0x8037
57
+	'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ',' ',' '
58
+#elif USB_PID == 0x803C
59
+	'A','r','d','u','i','n','o',' ','E','s','p','l','o','r','a',' '
60
+#elif USB_PID == 0x9208
61
+	'L','i','l','y','P','a','d','U','S','B',' ',' ',' ',' ',' ',' '
62
+#else
63
+	'U','S','B',' ','I','O',' ','B','o','a','r','d',' ',' ',' ',' '
64
+#endif
65
+};
66
+
67
+const u16 STRING_IMANUFACTURER[12] = {
68
+	(3<<8) | (2+2*11),
69
+#if USB_VID == 0x2341
70
+	'A','r','d','u','i','n','o',' ','L','L','C'
71
+#elif USB_VID == 0x1b4f
72
+	'S','p','a','r','k','F','u','n',' ',' ',' '
73
+#else
74
+	'U','n','k','n','o','w','n',' ',' ',' ',' '
75
+#endif
76
+};
77
+
78
+#ifdef CDC_ENABLED
79
+#define DEVICE_CLASS 0x02
80
+#else
81
+#define DEVICE_CLASS 0x00
82
+#endif
83
+
84
+//	DEVICE DESCRIPTOR
85
+const DeviceDescriptor USB_DeviceDescriptor =
86
+	D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
87
+
88
+const DeviceDescriptor USB_DeviceDescriptorA =
89
+	D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
90
+
91
+//==================================================================
92
+//==================================================================
93
+
94
+volatile u8 _usbConfiguration = 0;
95
+
96
+static inline void WaitIN(void)
97
+{
98
+	while (!(UEINTX & (1<<TXINI)));
99
+}
100
+
101
+static inline void ClearIN(void)
102
+{
103
+	UEINTX = ~(1<<TXINI);
104
+}
105
+
106
+static inline void WaitOUT(void)
107
+{
108
+	while (!(UEINTX & (1<<RXOUTI)))
109
+		;
110
+}
111
+
112
+static inline u8 WaitForINOrOUT()
113
+{
114
+	while (!(UEINTX & ((1<<TXINI)|(1<<RXOUTI))))
115
+		;
116
+	return (UEINTX & (1<<RXOUTI)) == 0;
117
+}
118
+
119
+static inline void ClearOUT(void)
120
+{
121
+	UEINTX = ~(1<<RXOUTI);
122
+}
123
+
124
+void Recv(volatile u8* data, u8 count)
125
+{
126
+	while (count--)
127
+		*data++ = UEDATX;
128
+	
129
+	RXLED1;					// light the RX LED
130
+	RxLEDPulse = TX_RX_LED_PULSE_MS;	
131
+}
132
+
133
+static inline u8 Recv8()
134
+{
135
+	RXLED1;					// light the RX LED
136
+	RxLEDPulse = TX_RX_LED_PULSE_MS;
137
+
138
+	return UEDATX;	
139
+}
140
+
141
+static inline void Send8(u8 d)
142
+{
143
+	UEDATX = d;
144
+}
145
+
146
+static inline void SetEP(u8 ep)
147
+{
148
+	UENUM = ep;
149
+}
150
+
151
+static inline u8 FifoByteCount()
152
+{
153
+	return UEBCLX;
154
+}
155
+
156
+static inline u8 ReceivedSetupInt()
157
+{
158
+	return UEINTX & (1<<RXSTPI);
159
+}
160
+
161
+static inline void ClearSetupInt()
162
+{
163
+	UEINTX = ~((1<<RXSTPI) | (1<<RXOUTI) | (1<<TXINI));
164
+}
165
+
166
+static inline void Stall()
167
+{
168
+	UECONX = (1<<STALLRQ) | (1<<EPEN);
169
+}
170
+
171
+static inline u8 ReadWriteAllowed()
172
+{
173
+	return UEINTX & (1<<RWAL);
174
+}
175
+
176
+static inline u8 Stalled()
177
+{
178
+	return UEINTX & (1<<STALLEDI);
179
+}
180
+
181
+static inline u8 FifoFree()
182
+{
183
+	return UEINTX & (1<<FIFOCON);
184
+}
185
+
186
+static inline void ReleaseRX()
187
+{
188
+	UEINTX = 0x6B;	// FIFOCON=0 NAKINI=1 RWAL=1 NAKOUTI=0 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=1
189
+}
190
+
191
+static inline void ReleaseTX()
192
+{
193
+	UEINTX = 0x3A;	// FIFOCON=0 NAKINI=0 RWAL=1 NAKOUTI=1 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=0
194
+}
195
+
196
+static inline u8 FrameNumber()
197
+{
198
+	return UDFNUML;
199
+}
200
+
201
+//==================================================================
202
+//==================================================================
203
+
204
+u8 USBGetConfiguration(void)
205
+{
206
+	return _usbConfiguration;
207
+}
208
+
209
+#define USB_RECV_TIMEOUT
210
+class LockEP
211
+{
212
+	u8 _sreg;
213
+public:
214
+	LockEP(u8 ep) : _sreg(SREG)
215
+	{
216
+		cli();
217
+		SetEP(ep & 7);
218
+	}
219
+	~LockEP()
220
+	{
221
+		SREG = _sreg;
222
+	}
223
+};
224
+
225
+//	Number of bytes, assumes a rx endpoint
226
+u8 USB_Available(u8 ep)
227
+{
228
+	LockEP lock(ep);
229
+	return FifoByteCount();
230
+}
231
+
232
+//	Non Blocking receive
233
+//	Return number of bytes read
234
+int USB_Recv(u8 ep, void* d, int len)
235
+{
236
+	if (!_usbConfiguration || len < 0)
237
+		return -1;
238
+	
239
+	LockEP lock(ep);
240
+	u8 n = FifoByteCount();
241
+	len = min(n,len);
242
+	n = len;
243
+	u8* dst = (u8*)d;
244
+	while (n--)
245
+		*dst++ = Recv8();
246
+	if (len && !FifoByteCount())	// release empty buffer
247
+		ReleaseRX();
248
+	
249
+	return len;
250
+}
251
+
252
+//	Recv 1 byte if ready
253
+int USB_Recv(u8 ep)
254
+{
255
+	u8 c;
256
+	if (USB_Recv(ep,&c,1) != 1)
257
+		return -1;
258
+	return c;
259
+}
260
+
261
+//	Space in send EP
262
+u8 USB_SendSpace(u8 ep)
263
+{
264
+	LockEP lock(ep);
265
+	if (!ReadWriteAllowed())
266
+		return 0;
267
+	return 64 - FifoByteCount();
268
+}
269
+
270
+//	Blocking Send of data to an endpoint
271
+int USB_Send(u8 ep, const void* d, int len)
272
+{
273
+	if (!_usbConfiguration)
274
+		return -1;
275
+
276
+	int r = len;
277
+	const u8* data = (const u8*)d;
278
+	u8 zero = ep & TRANSFER_ZERO;
279
+	u8 timeout = 250;		// 250ms timeout on send? TODO
280
+	while (len)
281
+	{
282
+		u8 n = USB_SendSpace(ep);
283
+		if (n == 0)
284
+		{
285
+			if (!(--timeout))
286
+				return -1;
287
+			delay(1);
288
+			continue;
289
+		}
290
+
291
+		if (n > len)
292
+			n = len;
293
+		len -= n;
294
+		{
295
+			LockEP lock(ep);
296
+			if (ep & TRANSFER_ZERO)
297
+			{
298
+				while (n--)
299
+					Send8(0);
300
+			}
301
+			else if (ep & TRANSFER_PGM)
302
+			{
303
+				while (n--)
304
+					Send8(pgm_read_byte(data++));
305
+			}
306
+			else
307
+			{
308
+				while (n--)
309
+					Send8(*data++);
310
+			}
311
+			if (!ReadWriteAllowed() || ((len == 0) && (ep & TRANSFER_RELEASE)))	// Release full buffer
312
+				ReleaseTX();
313
+		}
314
+	}
315
+	TXLED1;					// light the TX LED
316
+	TxLEDPulse = TX_RX_LED_PULSE_MS;
317
+	return r;
318
+}
319
+
320
+extern const u8 _initEndpoints[] PROGMEM;
321
+const u8 _initEndpoints[] = 
322
+{
323
+	0,
324
+	
325
+#ifdef CDC_ENABLED
326
+	EP_TYPE_INTERRUPT_IN,		// CDC_ENDPOINT_ACM
327
+	EP_TYPE_BULK_OUT,			// CDC_ENDPOINT_OUT
328
+	EP_TYPE_BULK_IN,			// CDC_ENDPOINT_IN
329
+#endif
330
+
331
+#ifdef HID_ENABLED
332
+	EP_TYPE_INTERRUPT_IN		// HID_ENDPOINT_INT
333
+#endif
334
+};
335
+
336
+#define EP_SINGLE_64 0x32	// EP0
337
+#define EP_DOUBLE_64 0x36	// Other endpoints
338
+
339
+static
340
+void InitEP(u8 index, u8 type, u8 size)
341
+{
342
+	UENUM = index;
343
+	UECONX = 1;
344
+	UECFG0X = type;
345
+	UECFG1X = size;
346
+}
347
+
348
+static
349
+void InitEndpoints()
350
+{
351
+	for (u8 i = 1; i < sizeof(_initEndpoints); i++)
352
+	{
353
+		UENUM = i;
354
+		UECONX = 1;
355
+		UECFG0X = pgm_read_byte(_initEndpoints+i);
356
+		UECFG1X = EP_DOUBLE_64;
357
+	}
358
+	UERST = 0x7E;	// And reset them
359
+	UERST = 0;
360
+}
361
+
362
+//	Handle CLASS_INTERFACE requests
363
+static
364
+bool ClassInterfaceRequest(Setup& setup)
365
+{
366
+	u8 i = setup.wIndex;
367
+
368
+#ifdef CDC_ENABLED
369
+	if (CDC_ACM_INTERFACE == i)
370
+		return CDC_Setup(setup);
371
+#endif
372
+
373
+#ifdef HID_ENABLED
374
+	if (HID_INTERFACE == i)
375
+		return HID_Setup(setup);
376
+#endif
377
+	return false;
378
+}
379
+
380
+int _cmark;
381
+int _cend;
382
+void InitControl(int end)
383
+{
384
+	SetEP(0);
385
+	_cmark = 0;
386
+	_cend = end;
387
+}
388
+
389
+static
390
+bool SendControl(u8 d)
391
+{
392
+	if (_cmark < _cend)
393
+	{
394
+		if (!WaitForINOrOUT())
395
+			return false;
396
+		Send8(d);
397
+		if (!((_cmark + 1) & 0x3F))
398
+			ClearIN();	// Fifo is full, release this packet
399
+	}
400
+	_cmark++;
401
+	return true;
402
+};
403
+
404
+//	Clipped by _cmark/_cend
405
+int USB_SendControl(u8 flags, const void* d, int len)
406
+{
407
+	int sent = len;
408
+	const u8* data = (const u8*)d;
409
+	bool pgm = flags & TRANSFER_PGM;
410
+	while (len--)
411
+	{
412
+		u8 c = pgm ? pgm_read_byte(data++) : *data++;
413
+		if (!SendControl(c))
414
+			return -1;
415
+	}
416
+	return sent;
417
+}
418
+
419
+//	Does not timeout or cross fifo boundaries
420
+//	Will only work for transfers <= 64 bytes
421
+//	TODO
422
+int USB_RecvControl(void* d, int len)
423
+{
424
+	WaitOUT();
425
+	Recv((u8*)d,len);
426
+	ClearOUT();
427
+	return len;
428
+}
429
+
430
+int SendInterfaces()
431
+{
432
+	int total = 0;
433
+	u8 interfaces = 0;
434
+
435
+#ifdef CDC_ENABLED
436
+	total = CDC_GetInterface(&interfaces);
437
+#endif
438
+
439
+#ifdef HID_ENABLED
440
+	total += HID_GetInterface(&interfaces);
441
+#endif
442
+
443
+	return interfaces;
444
+}
445
+
446
+//	Construct a dynamic configuration descriptor
447
+//	This really needs dynamic endpoint allocation etc
448
+//	TODO
449
+static
450
+bool SendConfiguration(int maxlen)
451
+{
452
+	//	Count and measure interfaces
453
+	InitControl(0);	
454
+	int interfaces = SendInterfaces();
455
+	ConfigDescriptor config = D_CONFIG(_cmark + sizeof(ConfigDescriptor),interfaces);
456
+
457
+	//	Now send them
458
+	InitControl(maxlen);
459
+	USB_SendControl(0,&config,sizeof(ConfigDescriptor));
460
+	SendInterfaces();
461
+	return true;
462
+}
463
+
464
+u8 _cdcComposite = 0;
465
+
466
+static
467
+bool SendDescriptor(Setup& setup)
468
+{
469
+	u8 t = setup.wValueH;
470
+	if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
471
+		return SendConfiguration(setup.wLength);
472
+
473
+	InitControl(setup.wLength);
474
+#ifdef HID_ENABLED
475
+	if (HID_REPORT_DESCRIPTOR_TYPE == t)
476
+		return HID_GetDescriptor(t);
477
+#endif
478
+
479
+	u8 desc_length = 0;
480
+	const u8* desc_addr = 0;
481
+	if (USB_DEVICE_DESCRIPTOR_TYPE == t)
482
+	{
483
+		if (setup.wLength == 8)
484
+			_cdcComposite = 1;
485
+		desc_addr = _cdcComposite ?  (const u8*)&USB_DeviceDescriptorA : (const u8*)&USB_DeviceDescriptor;
486
+	}
487
+	else if (USB_STRING_DESCRIPTOR_TYPE == t)
488
+	{
489
+		if (setup.wValueL == 0)
490
+			desc_addr = (const u8*)&STRING_LANGUAGE;
491
+		else if (setup.wValueL == IPRODUCT) 
492
+			desc_addr = (const u8*)&STRING_IPRODUCT;
493
+		else if (setup.wValueL == IMANUFACTURER)
494
+			desc_addr = (const u8*)&STRING_IMANUFACTURER;
495
+		else
496
+			return false;
497
+	}
498
+
499
+	if (desc_addr == 0)
500
+		return false;
501
+	if (desc_length == 0)
502
+		desc_length = pgm_read_byte(desc_addr);
503
+
504
+	USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
505
+	return true;
506
+}
507
+
508
+//	Endpoint 0 interrupt
509
+ISR(USB_COM_vect)
510
+{
511
+    SetEP(0);
512
+	if (!ReceivedSetupInt())
513
+		return;
514
+
515
+	Setup setup;
516
+	Recv((u8*)&setup,8);
517
+	ClearSetupInt();
518
+
519
+	u8 requestType = setup.bmRequestType;
520
+	if (requestType & REQUEST_DEVICETOHOST)
521
+		WaitIN();
522
+	else
523
+		ClearIN();
524
+
525
+    bool ok = true;
526
+	if (REQUEST_STANDARD == (requestType & REQUEST_TYPE))
527
+	{
528
+		//	Standard Requests
529
+		u8 r = setup.bRequest;
530
+		if (GET_STATUS == r)
531
+		{
532
+			Send8(0);		// TODO
533
+			Send8(0);
534
+		}
535
+		else if (CLEAR_FEATURE == r)
536
+		{
537
+		}
538
+		else if (SET_FEATURE == r)
539
+		{
540
+		}
541
+		else if (SET_ADDRESS == r)
542
+		{
543
+			WaitIN();
544
+			UDADDR = setup.wValueL | (1<<ADDEN);
545
+		}
546
+		else if (GET_DESCRIPTOR == r)
547
+		{
548
+			ok = SendDescriptor(setup);
549
+		}
550
+		else if (SET_DESCRIPTOR == r)
551
+		{
552
+			ok = false;
553
+		}
554
+		else if (GET_CONFIGURATION == r)
555
+		{
556
+			Send8(1);
557
+		}
558
+		else if (SET_CONFIGURATION == r)
559
+		{
560
+			if (REQUEST_DEVICE == (requestType & REQUEST_RECIPIENT))
561
+			{
562
+				InitEndpoints();
563
+				_usbConfiguration = setup.wValueL;
564
+			} else
565
+				ok = false;
566
+		}
567
+		else if (GET_INTERFACE == r)
568
+		{
569
+		}
570
+		else if (SET_INTERFACE == r)
571
+		{
572
+		}
573
+	}
574
+	else
575
+	{
576
+		InitControl(setup.wLength);		//	Max length of transfer
577
+		ok = ClassInterfaceRequest(setup);
578
+	}
579
+
580
+	if (ok)
581
+		ClearIN();
582
+	else
583
+	{
584
+		Stall();
585
+	}
586
+}
587
+
588
+void USB_Flush(u8 ep)
589
+{
590
+	SetEP(ep);
591
+	if (FifoByteCount())
592
+		ReleaseTX();
593
+}
594
+
595
+//	General interrupt
596
+ISR(USB_GEN_vect)
597
+{
598
+	u8 udint = UDINT;
599
+	UDINT = 0;
600
+
601
+	//	End of Reset
602
+	if (udint & (1<<EORSTI))
603
+	{
604
+		InitEP(0,EP_TYPE_CONTROL,EP_SINGLE_64);	// init ep0
605
+		_usbConfiguration = 0;			// not configured yet
606
+		UEIENX = 1 << RXSTPE;			// Enable interrupts for ep0
607
+	}
608
+
609
+	//	Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too
610
+	if (udint & (1<<SOFI))
611
+	{
612
+#ifdef CDC_ENABLED
613
+		USB_Flush(CDC_TX);				// Send a tx frame if found
614
+		if (USB_Available(CDC_RX))	// Handle received bytes (if any)
615
+			Serial.accept();
616
+#endif
617
+		
618
+		// check whether the one-shot period has elapsed.  if so, turn off the LED
619
+		if (TxLEDPulse && !(--TxLEDPulse))
620
+			TXLED0;
621
+		if (RxLEDPulse && !(--RxLEDPulse))
622
+			RXLED0;
623
+	}
624
+}
625
+
626
+//	VBUS or counting frames
627
+//	Any frame counting?
628
+u8 USBConnected()
629
+{
630
+	u8 f = UDFNUML;
631
+	delay(3);
632
+	return f != UDFNUML;
633
+}
634
+
635
+//=======================================================================
636
+//=======================================================================
637
+
638
+USBDevice_ USBDevice;
639
+
640
+USBDevice_::USBDevice_()
641
+{
642
+}
643
+
644
+void USBDevice_::attach()
645
+{
646
+	_usbConfiguration = 0;
647
+	UHWCON = 0x01;						// power internal reg
648
+	USBCON = (1<<USBE)|(1<<FRZCLK);		// clock frozen, usb enabled
649
+#if F_CPU == 16000000UL
650
+	PLLCSR = 0x12;						// Need 16 MHz xtal
651
+#elif F_CPU == 8000000UL
652
+	PLLCSR = 0x02;						// Need 8 MHz xtal
653
+#endif
654
+	while (!(PLLCSR & (1<<PLOCK)))		// wait for lock pll
655
+		;
656
+
657
+	// Some tests on specific versions of macosx (10.7.3), reported some
658
+	// strange behaviuors when the board is reset using the serial
659
+	// port touch at 1200 bps. This delay fixes this behaviour.
660
+	delay(1);
661
+
662
+	USBCON = ((1<<USBE)|(1<<OTGPADE));	// start USB clock
663
+	UDIEN = (1<<EORSTE)|(1<<SOFE);		// Enable interrupts for EOR (End of Reset) and SOF (start of frame)
664
+	UDCON = 0;							// enable attach resistor
665
+	
666
+	TX_RX_LED_INIT;
667
+}
668
+
669
+void USBDevice_::detach()
670
+{
671
+}
672
+
673
+//	Check for interrupts
674
+//	TODO: VBUS detection
675
+bool USBDevice_::configured()
676
+{
677
+	return _usbConfiguration;
678
+}
679
+
680
+void USBDevice_::poll()
681
+{
682
+}
683
+
684
+#endif /* if defined(USBCON) */

+ 303
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/USBCore.h View File

@@ -0,0 +1,303 @@
1
+
2
+// Copyright (c) 2010, Peter Barrett 
3
+/*
4
+** Permission to use, copy, modify, and/or distribute this software for  
5
+** any purpose with or without fee is hereby granted, provided that the  
6
+** above copyright notice and this permission notice appear in all copies.  
7
+**  
8
+** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL  
9
+** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED  
10
+** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR  
11
+** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES  
12
+** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,  
13
+** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  
14
+** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS  
15
+** SOFTWARE.  
16
+*/
17
+
18
+#ifndef __USBCORE_H__
19
+#define __USBCORE_H__
20
+
21
+//	Standard requests
22
+#define GET_STATUS			0
23
+#define CLEAR_FEATURE		1
24
+#define SET_FEATURE			3
25
+#define SET_ADDRESS			5
26
+#define GET_DESCRIPTOR		6
27
+#define SET_DESCRIPTOR		7
28
+#define GET_CONFIGURATION	8
29
+#define SET_CONFIGURATION	9
30
+#define GET_INTERFACE		10
31
+#define SET_INTERFACE		11
32
+
33
+
34
+// bmRequestType
35
+#define REQUEST_HOSTTODEVICE	0x00
36
+#define REQUEST_DEVICETOHOST	0x80
37
+#define REQUEST_DIRECTION		0x80
38
+
39
+#define REQUEST_STANDARD		0x00
40
+#define REQUEST_CLASS			0x20
41
+#define REQUEST_VENDOR			0x40
42
+#define REQUEST_TYPE			0x60
43
+
44
+#define REQUEST_DEVICE			0x00
45
+#define REQUEST_INTERFACE		0x01
46
+#define REQUEST_ENDPOINT		0x02
47
+#define REQUEST_OTHER			0x03
48
+#define REQUEST_RECIPIENT		0x03
49
+
50
+#define REQUEST_DEVICETOHOST_CLASS_INTERFACE  (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE)
51
+#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE  (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE)
52
+
53
+//	Class requests
54
+
55
+#define CDC_SET_LINE_CODING			0x20
56
+#define CDC_GET_LINE_CODING			0x21
57
+#define CDC_SET_CONTROL_LINE_STATE	0x22
58
+
59
+#define MSC_RESET					0xFF
60
+#define MSC_GET_MAX_LUN				0xFE
61
+
62
+#define HID_GET_REPORT				0x01
63
+#define HID_GET_IDLE				0x02
64
+#define HID_GET_PROTOCOL			0x03
65
+#define HID_SET_REPORT				0x09
66
+#define HID_SET_IDLE				0x0A
67
+#define HID_SET_PROTOCOL			0x0B
68
+
69
+//	Descriptors
70
+
71
+#define USB_DEVICE_DESC_SIZE 18
72
+#define USB_CONFIGUARTION_DESC_SIZE 9
73
+#define USB_INTERFACE_DESC_SIZE 9
74
+#define USB_ENDPOINT_DESC_SIZE 7
75
+
76
+#define USB_DEVICE_DESCRIPTOR_TYPE             1
77
+#define USB_CONFIGURATION_DESCRIPTOR_TYPE      2
78
+#define USB_STRING_DESCRIPTOR_TYPE             3
79
+#define USB_INTERFACE_DESCRIPTOR_TYPE          4
80
+#define USB_ENDPOINT_DESCRIPTOR_TYPE           5
81
+
82
+#define USB_DEVICE_CLASS_COMMUNICATIONS        0x02
83
+#define USB_DEVICE_CLASS_HUMAN_INTERFACE       0x03
84
+#define USB_DEVICE_CLASS_STORAGE               0x08
85
+#define USB_DEVICE_CLASS_VENDOR_SPECIFIC       0xFF
86
+
87
+#define USB_CONFIG_POWERED_MASK                0x40
88
+#define USB_CONFIG_BUS_POWERED                 0x80
89
+#define USB_CONFIG_SELF_POWERED                0xC0
90
+#define USB_CONFIG_REMOTE_WAKEUP               0x20
91
+
92
+// bMaxPower in Configuration Descriptor
93
+#define USB_CONFIG_POWER_MA(mA)                ((mA)/2)
94
+
95
+// bEndpointAddress in Endpoint Descriptor
96
+#define USB_ENDPOINT_DIRECTION_MASK            0x80
97
+#define USB_ENDPOINT_OUT(addr)                 ((addr) | 0x00)
98
+#define USB_ENDPOINT_IN(addr)                  ((addr) | 0x80)
99
+
100
+#define USB_ENDPOINT_TYPE_MASK                 0x03
101
+#define USB_ENDPOINT_TYPE_CONTROL              0x00
102
+#define USB_ENDPOINT_TYPE_ISOCHRONOUS          0x01
103
+#define USB_ENDPOINT_TYPE_BULK                 0x02
104
+#define USB_ENDPOINT_TYPE_INTERRUPT            0x03
105
+
106
+#define TOBYTES(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
107
+
108
+#define CDC_V1_10                               0x0110
109
+#define CDC_COMMUNICATION_INTERFACE_CLASS       0x02
110
+
111
+#define CDC_CALL_MANAGEMENT                     0x01
112
+#define CDC_ABSTRACT_CONTROL_MODEL              0x02
113
+#define CDC_HEADER                              0x00
114
+#define CDC_ABSTRACT_CONTROL_MANAGEMENT         0x02
115
+#define CDC_UNION                               0x06
116
+#define CDC_CS_INTERFACE                        0x24
117
+#define CDC_CS_ENDPOINT                         0x25
118
+#define CDC_DATA_INTERFACE_CLASS                0x0A
119
+
120
+#define MSC_SUBCLASS_SCSI						0x06 
121
+#define MSC_PROTOCOL_BULK_ONLY					0x50 
122
+
123
+#define HID_HID_DESCRIPTOR_TYPE					0x21
124
+#define HID_REPORT_DESCRIPTOR_TYPE				0x22
125
+#define HID_PHYSICAL_DESCRIPTOR_TYPE			0x23
126
+
127
+
128
+//	Device
129
+typedef struct {
130
+	u8 len;				// 18
131
+	u8 dtype;			// 1 USB_DEVICE_DESCRIPTOR_TYPE
132
+	u16 usbVersion;		// 0x200
133
+	u8	deviceClass;
134
+	u8	deviceSubClass;
135
+	u8	deviceProtocol;
136
+	u8	packetSize0;	// Packet 0
137
+	u16	idVendor;
138
+	u16	idProduct;
139
+	u16	deviceVersion;	// 0x100
140
+	u8	iManufacturer;
141
+	u8	iProduct;
142
+	u8	iSerialNumber;
143
+	u8	bNumConfigurations;
144
+} DeviceDescriptor;
145
+
146
+//	Config
147
+typedef struct {
148
+	u8	len;			// 9
149
+	u8	dtype;			// 2
150
+	u16 clen;			// total length
151
+	u8	numInterfaces;
152
+	u8	config;
153
+	u8	iconfig;
154
+	u8	attributes;
155
+	u8	maxPower;
156
+} ConfigDescriptor;
157
+
158
+//	String
159
+
160
+//	Interface
161
+typedef struct
162
+{
163
+	u8 len;		// 9
164
+	u8 dtype;	// 4
165
+	u8 number;
166
+	u8 alternate;
167
+	u8 numEndpoints;
168
+	u8 interfaceClass;
169
+	u8 interfaceSubClass;
170
+	u8 protocol;
171
+	u8 iInterface;
172
+} InterfaceDescriptor;
173
+
174
+//	Endpoint
175
+typedef struct
176
+{
177
+	u8 len;		// 7
178
+	u8 dtype;	// 5
179
+	u8 addr;
180
+	u8 attr;
181
+	u16 packetSize;
182
+	u8 interval;
183
+} EndpointDescriptor;
184
+
185
+// Interface Association Descriptor
186
+// Used to bind 2 interfaces together in CDC compostite device
187
+typedef struct
188
+{
189
+	u8 len;				// 8
190
+	u8 dtype;			// 11
191
+	u8 firstInterface;
192
+	u8 interfaceCount;
193
+	u8 functionClass;
194
+	u8 funtionSubClass;
195
+	u8 functionProtocol;
196
+	u8 iInterface;
197
+} IADDescriptor;
198
+
199
+//	CDC CS interface descriptor
200
+typedef struct
201
+{
202
+	u8 len;		// 5
203
+	u8 dtype;	// 0x24
204
+	u8 subtype;
205
+	u8 d0;
206
+	u8 d1;
207
+} CDCCSInterfaceDescriptor;
208
+
209
+typedef struct
210
+{
211
+	u8 len;		// 4
212
+	u8 dtype;	// 0x24
213
+	u8 subtype;
214
+	u8 d0;
215
+} CDCCSInterfaceDescriptor4;
216
+
217
+typedef struct 
218
+{
219
+    u8	len;
220
+    u8 	dtype;		// 0x24
221
+    u8 	subtype;	// 1
222
+    u8 	bmCapabilities;
223
+    u8 	bDataInterface;
224
+} CMFunctionalDescriptor;
225
+	
226
+typedef struct 
227
+{
228
+    u8	len;
229
+    u8 	dtype;		// 0x24
230
+    u8 	subtype;	// 1
231
+    u8 	bmCapabilities;
232
+} ACMFunctionalDescriptor;
233
+
234
+typedef struct 
235
+{
236
+	//	IAD
237
+	IADDescriptor				iad;	// Only needed on compound device
238
+
239
+	//	Control
240
+	InterfaceDescriptor			cif;	// 
241
+	CDCCSInterfaceDescriptor	header;
242
+	CMFunctionalDescriptor		callManagement;			// Call Management
243
+	ACMFunctionalDescriptor		controlManagement;		// ACM
244
+	CDCCSInterfaceDescriptor	functionalDescriptor;	// CDC_UNION
245
+	EndpointDescriptor			cifin;
246
+
247
+	//	Data
248
+	InterfaceDescriptor			dif;
249
+	EndpointDescriptor			in;
250
+	EndpointDescriptor			out;
251
+} CDCDescriptor;
252
+
253
+typedef struct 
254
+{
255
+	InterfaceDescriptor			msc;
256
+	EndpointDescriptor			in;
257
+	EndpointDescriptor			out;
258
+} MSCDescriptor;
259
+
260
+typedef struct
261
+{
262
+	u8 len;			// 9
263
+	u8 dtype;		// 0x21
264
+	u8 addr;
265
+	u8	versionL;	// 0x101
266
+	u8	versionH;	// 0x101
267
+	u8	country;
268
+	u8	desctype;	// 0x22 report
269
+	u8	descLenL;
270
+	u8	descLenH;
271
+} HIDDescDescriptor;
272
+
273
+typedef struct 
274
+{
275
+	InterfaceDescriptor			hid;
276
+	HIDDescDescriptor			desc;
277
+	EndpointDescriptor			in;
278
+} HIDDescriptor;
279
+
280
+
281
+#define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
282
+	{ 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
283
+
284
+#define D_CONFIG(_totalLength,_interfaces) \
285
+	{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(500) }
286
+
287
+#define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
288
+	{ 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }
289
+
290
+#define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \
291
+	{ 7, 5, _addr,_attr,_packetSize, _interval }
292
+
293
+#define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \
294
+	{ 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 }
295
+
296
+#define D_HIDREPORT(_descriptorLength) \
297
+	{ 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 }
298
+
299
+#define D_CDCCS(_subtype,_d0,_d1)	{ 5, 0x24, _subtype, _d0, _d1 }
300
+#define D_CDCCS4(_subtype,_d0)		{ 4, 0x24, _subtype, _d0 }
301
+
302
+
303
+#endif

+ 63
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/USBDesc.h View File

@@ -0,0 +1,63 @@
1
+
2
+
3
+/* Copyright (c) 2011, Peter Barrett  
4
+**  
5
+** Permission to use, copy, modify, and/or distribute this software for  
6
+** any purpose with or without fee is hereby granted, provided that the  
7
+** above copyright notice and this permission notice appear in all copies.  
8
+** 
9
+** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL  
10
+** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED  
11
+** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR  
12
+** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES  
13
+** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,  
14
+** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  
15
+** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS  
16
+** SOFTWARE.  
17
+*/
18
+
19
+#define CDC_ENABLED
20
+#define HID_ENABLED
21
+
22
+
23
+#ifdef CDC_ENABLED
24
+#define CDC_INTERFACE_COUNT	2
25
+#define CDC_ENPOINT_COUNT	3
26
+#else
27
+#define CDC_INTERFACE_COUNT	0
28
+#define CDC_ENPOINT_COUNT	0
29
+#endif
30
+
31
+#ifdef HID_ENABLED
32
+#define HID_INTERFACE_COUNT	1
33
+#define HID_ENPOINT_COUNT	1
34
+#else
35
+#define HID_INTERFACE_COUNT	0
36
+#define HID_ENPOINT_COUNT	0
37
+#endif
38
+
39
+#define CDC_ACM_INTERFACE	0	// CDC ACM
40
+#define CDC_DATA_INTERFACE	1	// CDC Data
41
+#define CDC_FIRST_ENDPOINT	1
42
+#define CDC_ENDPOINT_ACM	(CDC_FIRST_ENDPOINT)							// CDC First
43
+#define CDC_ENDPOINT_OUT	(CDC_FIRST_ENDPOINT+1)
44
+#define CDC_ENDPOINT_IN		(CDC_FIRST_ENDPOINT+2)
45
+
46
+#define HID_INTERFACE		(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT)		// HID Interface
47
+#define HID_FIRST_ENDPOINT	(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT)
48
+#define HID_ENDPOINT_INT	(HID_FIRST_ENDPOINT)
49
+
50
+#define INTERFACE_COUNT		(MSC_INTERFACE + MSC_INTERFACE_COUNT)
51
+
52
+#ifdef CDC_ENABLED
53
+#define CDC_RX CDC_ENDPOINT_OUT
54
+#define CDC_TX CDC_ENDPOINT_IN
55
+#endif
56
+
57
+#ifdef HID_ENABLED
58
+#define HID_TX HID_ENDPOINT_INT
59
+#endif
60
+
61
+#define IMANUFACTURER	1
62
+#define IPRODUCT		2
63
+

+ 88
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/Udp.h View File

@@ -0,0 +1,88 @@
1
+/*
2
+ *  Udp.cpp: Library to send/receive UDP packets.
3
+ *
4
+ * NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
5
+ * 1) UDP does not guarantee the order in which assembled UDP packets are received. This
6
+ * might not happen often in practice, but in larger network topologies, a UDP
7
+ * packet can be received out of sequence. 
8
+ * 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
9
+ * aware of it. Again, this may not be a concern in practice on small local networks.
10
+ * For more information, see http://www.cafeaulait.org/course/week12/35.html
11
+ *
12
+ * MIT License:
13
+ * Copyright (c) 2008 Bjoern Hartmann
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ * of this software and associated documentation files (the "Software"), to deal
16
+ * in the Software without restriction, including without limitation the rights
17
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ * copies of the Software, and to permit persons to whom the Software is
19
+ * furnished to do so, subject to the following conditions:
20
+ * 
21
+ * The above copyright notice and this permission notice shall be included in
22
+ * all copies or substantial portions of the Software.
23
+ * 
24
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
+ * THE SOFTWARE.
31
+ *
32
+ * bjoern@cs.stanford.edu 12/30/2008
33
+ */
34
+
35
+#ifndef udp_h
36
+#define udp_h
37
+
38
+#include <Stream.h>
39
+#include <IPAddress.h>
40
+
41
+class UDP : public Stream {
42
+
43
+public:
44
+  virtual uint8_t begin(uint16_t) =0;	// initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
45
+  virtual void stop() =0;  // Finish with the UDP socket
46
+
47
+  // Sending UDP packets
48
+  
49
+  // Start building up a packet to send to the remote host specific in ip and port
50
+  // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
51
+  virtual int beginPacket(IPAddress ip, uint16_t port) =0;
52
+  // Start building up a packet to send to the remote host specific in host and port
53
+  // Returns 1 if successful, 0 if there was a problem resolving the hostname or port
54
+  virtual int beginPacket(const char *host, uint16_t port) =0;
55
+  // Finish off this packet and send it
56
+  // Returns 1 if the packet was sent successfully, 0 if there was an error
57
+  virtual int endPacket() =0;
58
+  // Write a single byte into the packet
59
+  virtual size_t write(uint8_t) =0;
60
+  // Write size bytes from buffer into the packet
61
+  virtual size_t write(const uint8_t *buffer, size_t size) =0;
62
+
63
+  // Start processing the next available incoming packet
64
+  // Returns the size of the packet in bytes, or 0 if no packets are available
65
+  virtual int parsePacket() =0;
66
+  // Number of bytes remaining in the current packet
67
+  virtual int available() =0;
68
+  // Read a single byte from the current packet
69
+  virtual int read() =0;
70
+  // Read up to len bytes from the current packet and place them into buffer
71
+  // Returns the number of bytes read, or 0 if none are available
72
+  virtual int read(unsigned char* buffer, size_t len) =0;
73
+  // Read up to len characters from the current packet and place them into buffer
74
+  // Returns the number of characters read, or 0 if none are available
75
+  virtual int read(char* buffer, size_t len) =0;
76
+  // Return the next byte from the current packet without moving on to the next byte
77
+  virtual int peek() =0;
78
+  virtual void flush() =0;	// Finish reading the current packet
79
+
80
+  // Return the IP address of the host who sent the current incoming packet
81
+  virtual IPAddress remoteIP() =0;
82
+  // Return the port of the host who sent the current incoming packet
83
+  virtual uint16_t remotePort() =0;
84
+protected:
85
+  uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
86
+};
87
+
88
+#endif

+ 168
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WCharacter.h View File

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

+ 322
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WInterrupts.c View File

@@ -0,0 +1,322 @@
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 "wiring_private.h"
34
+
35
+static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
36
+// volatile static voidFuncPtr twiIntFunc;
37
+
38
+void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
39
+  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
40
+    intFunc[interruptNum] = userFunc;
41
+    
42
+    // Configure the interrupt mode (trigger on low input, any change, rising
43
+    // edge, or falling edge).  The mode constants were chosen to correspond
44
+    // to the configuration bits in the hardware register, so we simply shift
45
+    // the mode into place.
46
+      
47
+    // Enable the interrupt.
48
+      
49
+    switch (interruptNum) {
50
+#if defined(__AVR_ATmega32U4__)
51
+	// I hate doing this, but the register assignment differs between the 1280/2560
52
+	// and the 32U4.  Since avrlib defines registers PCMSK1 and PCMSK2 that aren't 
53
+	// even present on the 32U4 this is the only way to distinguish between them.
54
+	case 0:
55
+		EICRA = (EICRA & ~((1<<ISC00) | (1<<ISC01))) | (mode << ISC00);
56
+		EIMSK |= (1<<INT0);
57
+		break;
58
+	case 1:
59
+		EICRA = (EICRA & ~((1<<ISC10) | (1<<ISC11))) | (mode << ISC10);
60
+		EIMSK |= (1<<INT1);
61
+		break;	
62
+    case 2:
63
+        EICRA = (EICRA & ~((1<<ISC20) | (1<<ISC21))) | (mode << ISC20);
64
+        EIMSK |= (1<<INT2);
65
+        break;
66
+    case 3:
67
+        EICRA = (EICRA & ~((1<<ISC30) | (1<<ISC31))) | (mode << ISC30);
68
+        EIMSK |= (1<<INT3);
69
+        break;
70
+#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
71
+    case 2:
72
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
73
+      EIMSK |= (1 << INT0);
74
+      break;
75
+    case 3:
76
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
77
+      EIMSK |= (1 << INT1);
78
+      break;
79
+    case 4:
80
+      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
81
+      EIMSK |= (1 << INT2);
82
+      break;
83
+    case 5:
84
+      EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
85
+      EIMSK |= (1 << INT3);
86
+      break;
87
+    case 0:
88
+      EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
89
+      EIMSK |= (1 << INT4);
90
+      break;
91
+    case 1:
92
+      EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
93
+      EIMSK |= (1 << INT5);
94
+      break;
95
+    case 6:
96
+      EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
97
+      EIMSK |= (1 << INT6);
98
+      break;
99
+    case 7:
100
+      EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
101
+      EIMSK |= (1 << INT7);
102
+      break;
103
+#else		
104
+    case 0:
105
+    #if defined(EICRA) && defined(ISC00) && defined(EIMSK)
106
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
107
+      EIMSK |= (1 << INT0);
108
+    #elif defined(MCUCR) && defined(ISC00) && defined(GICR)
109
+      MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
110
+      GICR |= (1 << INT0);
111
+    #elif defined(MCUCR) && defined(ISC00) && defined(GIMSK)
112
+      MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
113
+      GIMSK |= (1 << INT0);
114
+    #else
115
+      #error attachInterrupt not finished for this CPU (case 0)
116
+    #endif
117
+      break;
118
+
119
+    case 1:
120
+    #if defined(EICRA) && defined(ISC10) && defined(ISC11) && defined(EIMSK)
121
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
122
+      EIMSK |= (1 << INT1);
123
+    #elif defined(MCUCR) && defined(ISC10) && defined(ISC11) && defined(GICR)
124
+      MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
125
+      GICR |= (1 << INT1);
126
+    #elif defined(MCUCR) && defined(ISC10) && defined(GIMSK) && defined(GIMSK)
127
+      MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
128
+      GIMSK |= (1 << INT1);
129
+    #else
130
+      #warning attachInterrupt may need some more work for this cpu (case 1)
131
+    #endif
132
+      break;
133
+    
134
+    case 2:
135
+    #if defined(EICRA) && defined(ISC20) && defined(ISC21) && defined(EIMSK)
136
+      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
137
+      EIMSK |= (1 << INT2);
138
+    #elif defined(MCUCR) && defined(ISC20) && defined(ISC21) && defined(GICR)
139
+      MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
140
+      GICR |= (1 << INT2);
141
+    #elif defined(MCUCR) && defined(ISC20) && defined(GIMSK) && defined(GIMSK)
142
+      MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
143
+      GIMSK |= (1 << INT2);
144
+    #endif
145
+      break;
146
+#endif
147
+    }
148
+  }
149
+}
150
+
151
+void detachInterrupt(uint8_t interruptNum) {
152
+  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
153
+    // Disable the interrupt.  (We can't assume that interruptNum is equal
154
+    // to the number of the EIMSK bit to clear, as this isn't true on the 
155
+    // ATmega8.  There, INT0 is 6 and INT1 is 7.)
156
+    switch (interruptNum) {
157
+#if defined(__AVR_ATmega32U4__)
158
+    case 0:
159
+        EIMSK &= ~(1<<INT0);
160
+        break;
161
+    case 1:
162
+        EIMSK &= ~(1<<INT1);
163
+        break;
164
+    case 2:
165
+        EIMSK &= ~(1<<INT2);
166
+        break;
167
+    case 3:
168
+        EIMSK &= ~(1<<INT3);
169
+        break;		
170
+#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
171
+    case 2:
172
+      EIMSK &= ~(1 << INT0);
173
+      break;
174
+    case 3:
175
+      EIMSK &= ~(1 << INT1);
176
+      break;
177
+    case 4:
178
+      EIMSK &= ~(1 << INT2);
179
+      break;
180
+    case 5:
181
+      EIMSK &= ~(1 << INT3);
182
+      break;
183
+    case 0:
184
+      EIMSK &= ~(1 << INT4);
185
+      break;
186
+    case 1:
187
+      EIMSK &= ~(1 << INT5);
188
+      break;
189
+    case 6:
190
+      EIMSK &= ~(1 << INT6);
191
+      break;
192
+    case 7:
193
+      EIMSK &= ~(1 << INT7);
194
+      break;
195
+#else
196
+    case 0:
197
+    #if defined(EIMSK) && defined(INT0)
198
+      EIMSK &= ~(1 << INT0);
199
+    #elif defined(GICR) && defined(ISC00)
200
+      GICR &= ~(1 << INT0); // atmega32
201
+    #elif defined(GIMSK) && defined(INT0)
202
+      GIMSK &= ~(1 << INT0);
203
+    #else
204
+      #error detachInterrupt not finished for this cpu
205
+    #endif
206
+      break;
207
+
208
+    case 1:
209
+    #if defined(EIMSK) && defined(INT1)
210
+      EIMSK &= ~(1 << INT1);
211
+    #elif defined(GICR) && defined(INT1)
212
+      GICR &= ~(1 << INT1); // atmega32
213
+    #elif defined(GIMSK) && defined(INT1)
214
+      GIMSK &= ~(1 << INT1);
215
+    #else
216
+      #warning detachInterrupt may need some more work for this cpu (case 1)
217
+    #endif
218
+      break;
219
+#endif
220
+    }
221
+      
222
+    intFunc[interruptNum] = 0;
223
+  }
224
+}
225
+
226
+/*
227
+void attachInterruptTwi(void (*userFunc)(void) ) {
228
+  twiIntFunc = userFunc;
229
+}
230
+*/
231
+
232
+#if defined(__AVR_ATmega32U4__)
233
+SIGNAL(INT0_vect) {
234
+	if(intFunc[EXTERNAL_INT_0])
235
+		intFunc[EXTERNAL_INT_0]();
236
+}
237
+
238
+SIGNAL(INT1_vect) {
239
+	if(intFunc[EXTERNAL_INT_1])
240
+		intFunc[EXTERNAL_INT_1]();
241
+}
242
+
243
+SIGNAL(INT2_vect) {
244
+    if(intFunc[EXTERNAL_INT_2])
245
+		intFunc[EXTERNAL_INT_2]();
246
+}
247
+
248
+SIGNAL(INT3_vect) {
249
+    if(intFunc[EXTERNAL_INT_3])
250
+		intFunc[EXTERNAL_INT_3]();
251
+}
252
+
253
+#elif defined(EICRA) && defined(EICRB)
254
+
255
+SIGNAL(INT0_vect) {
256
+  if(intFunc[EXTERNAL_INT_2])
257
+    intFunc[EXTERNAL_INT_2]();
258
+}
259
+
260
+SIGNAL(INT1_vect) {
261
+  if(intFunc[EXTERNAL_INT_3])
262
+    intFunc[EXTERNAL_INT_3]();
263
+}
264
+
265
+SIGNAL(INT2_vect) {
266
+  if(intFunc[EXTERNAL_INT_4])
267
+    intFunc[EXTERNAL_INT_4]();
268
+}
269
+
270
+SIGNAL(INT3_vect) {
271
+  if(intFunc[EXTERNAL_INT_5])
272
+    intFunc[EXTERNAL_INT_5]();
273
+}
274
+
275
+SIGNAL(INT4_vect) {
276
+  if(intFunc[EXTERNAL_INT_0])
277
+    intFunc[EXTERNAL_INT_0]();
278
+}
279
+
280
+SIGNAL(INT5_vect) {
281
+  if(intFunc[EXTERNAL_INT_1])
282
+    intFunc[EXTERNAL_INT_1]();
283
+}
284
+
285
+SIGNAL(INT6_vect) {
286
+  if(intFunc[EXTERNAL_INT_6])
287
+    intFunc[EXTERNAL_INT_6]();
288
+}
289
+
290
+SIGNAL(INT7_vect) {
291
+  if(intFunc[EXTERNAL_INT_7])
292
+    intFunc[EXTERNAL_INT_7]();
293
+}
294
+
295
+#else
296
+
297
+SIGNAL(INT0_vect) {
298
+  if(intFunc[EXTERNAL_INT_0])
299
+    intFunc[EXTERNAL_INT_0]();
300
+}
301
+
302
+SIGNAL(INT1_vect) {
303
+  if(intFunc[EXTERNAL_INT_1])
304
+    intFunc[EXTERNAL_INT_1]();
305
+}
306
+
307
+#if defined(EICRA) && defined(ISC20)
308
+SIGNAL(INT2_vect) {
309
+  if(intFunc[EXTERNAL_INT_2])
310
+    intFunc[EXTERNAL_INT_2]();
311
+}
312
+#endif
313
+
314
+#endif
315
+
316
+/*
317
+SIGNAL(SIG_2WIRE_SERIAL) {
318
+  if(twiIntFunc)
319
+    twiIntFunc();
320
+}
321
+*/
322
+

+ 60
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WMath.cpp View File

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

+ 645
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WString.cpp View File

@@ -0,0 +1,645 @@
1
+/*
2
+  WString.cpp - String library for Wiring & Arduino
3
+  ...mostly rewritten by Paul Stoffregen...
4
+  Copyright (c) 2009-10 Hernando Barragan.  All rights reserved.
5
+  Copyright 2011, Paul Stoffregen, paul@pjrc.com
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
+
22
+#include "WString.h"
23
+
24
+
25
+/*********************************************/
26
+/*  Constructors                             */
27
+/*********************************************/
28
+
29
+String::String(const char *cstr)
30
+{
31
+	init();
32
+	if (cstr) copy(cstr, strlen(cstr));
33
+}
34
+
35
+String::String(const String &value)
36
+{
37
+	init();
38
+	*this = value;
39
+}
40
+
41
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
42
+String::String(String &&rval)
43
+{
44
+	init();
45
+	move(rval);
46
+}
47
+String::String(StringSumHelper &&rval)
48
+{
49
+	init();
50
+	move(rval);
51
+}
52
+#endif
53
+
54
+String::String(char c)
55
+{
56
+	init();
57
+	char buf[2];
58
+	buf[0] = c;
59
+	buf[1] = 0;
60
+	*this = buf;
61
+}
62
+
63
+String::String(unsigned char value, unsigned char base)
64
+{
65
+	init();
66
+	char buf[9];
67
+	utoa(value, buf, base);
68
+	*this = buf;
69
+}
70
+
71
+String::String(int value, unsigned char base)
72
+{
73
+	init();
74
+	char buf[18];
75
+	itoa(value, buf, base);
76
+	*this = buf;
77
+}
78
+
79
+String::String(unsigned int value, unsigned char base)
80
+{
81
+	init();
82
+	char buf[17];
83
+	utoa(value, buf, base);
84
+	*this = buf;
85
+}
86
+
87
+String::String(long value, unsigned char base)
88
+{
89
+	init();
90
+	char buf[34];
91
+	ltoa(value, buf, base);
92
+	*this = buf;
93
+}
94
+
95
+String::String(unsigned long value, unsigned char base)
96
+{
97
+	init();
98
+	char buf[33];
99
+	ultoa(value, buf, base);
100
+	*this = buf;
101
+}
102
+
103
+String::~String()
104
+{
105
+	free(buffer);
106
+}
107
+
108
+/*********************************************/
109
+/*  Memory Management                        */
110
+/*********************************************/
111
+
112
+inline void String::init(void)
113
+{
114
+	buffer = NULL;
115
+	capacity = 0;
116
+	len = 0;
117
+	flags = 0;
118
+}
119
+
120
+void String::invalidate(void)
121
+{
122
+	if (buffer) free(buffer);
123
+	buffer = NULL;
124
+	capacity = len = 0;
125
+}
126
+
127
+unsigned char String::reserve(unsigned int size)
128
+{
129
+	if (buffer && capacity >= size) return 1;
130
+	if (changeBuffer(size)) {
131
+		if (len == 0) buffer[0] = 0;
132
+		return 1;
133
+	}
134
+	return 0;
135
+}
136
+
137
+unsigned char String::changeBuffer(unsigned int maxStrLen)
138
+{
139
+	char *newbuffer = (char *)realloc(buffer, maxStrLen + 1);
140
+	if (newbuffer) {
141
+		buffer = newbuffer;
142
+		capacity = maxStrLen;
143
+		return 1;
144
+	}
145
+	return 0;
146
+}
147
+
148
+/*********************************************/
149
+/*  Copy and Move                            */
150
+/*********************************************/
151
+
152
+String & String::copy(const char *cstr, unsigned int length)
153
+{
154
+	if (!reserve(length)) {
155
+		invalidate();
156
+		return *this;
157
+	}
158
+	len = length;
159
+	strcpy(buffer, cstr);
160
+	return *this;
161
+}
162
+
163
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
164
+void String::move(String &rhs)
165
+{
166
+	if (buffer) {
167
+		if (capacity >= rhs.len) {
168
+			strcpy(buffer, rhs.buffer);
169
+			len = rhs.len;
170
+			rhs.len = 0;
171
+			return;
172
+		} else {
173
+			free(buffer);
174
+		}
175
+	}
176
+	buffer = rhs.buffer;
177
+	capacity = rhs.capacity;
178
+	len = rhs.len;
179
+	rhs.buffer = NULL;
180
+	rhs.capacity = 0;
181
+	rhs.len = 0;
182
+}
183
+#endif
184
+
185
+String & String::operator = (const String &rhs)
186
+{
187
+	if (this == &rhs) return *this;
188
+	
189
+	if (rhs.buffer) copy(rhs.buffer, rhs.len);
190
+	else invalidate();
191
+	
192
+	return *this;
193
+}
194
+
195
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
196
+String & String::operator = (String &&rval)
197
+{
198
+	if (this != &rval) move(rval);
199
+	return *this;
200
+}
201
+
202
+String & String::operator = (StringSumHelper &&rval)
203
+{
204
+	if (this != &rval) move(rval);
205
+	return *this;
206
+}
207
+#endif
208
+
209
+String & String::operator = (const char *cstr)
210
+{
211
+	if (cstr) copy(cstr, strlen(cstr));
212
+	else invalidate();
213
+	
214
+	return *this;
215
+}
216
+
217
+/*********************************************/
218
+/*  concat                                   */
219
+/*********************************************/
220
+
221
+unsigned char String::concat(const String &s)
222
+{
223
+	return concat(s.buffer, s.len);
224
+}
225
+
226
+unsigned char String::concat(const char *cstr, unsigned int length)
227
+{
228
+	unsigned int newlen = len + length;
229
+	if (!cstr) return 0;
230
+	if (length == 0) return 1;
231
+	if (!reserve(newlen)) return 0;
232
+	strcpy(buffer + len, cstr);
233
+	len = newlen;
234
+	return 1;
235
+}
236
+
237
+unsigned char String::concat(const char *cstr)
238
+{
239
+	if (!cstr) return 0;
240
+	return concat(cstr, strlen(cstr));
241
+}
242
+
243
+unsigned char String::concat(char c)
244
+{
245
+	char buf[2];
246
+	buf[0] = c;
247
+	buf[1] = 0;
248
+	return concat(buf, 1);
249
+}
250
+
251
+unsigned char String::concat(unsigned char num)
252
+{
253
+	char buf[4];
254
+	itoa(num, buf, 10);
255
+	return concat(buf, strlen(buf));
256
+}
257
+
258
+unsigned char String::concat(int num)
259
+{
260
+	char buf[7];
261
+	itoa(num, buf, 10);
262
+	return concat(buf, strlen(buf));
263
+}
264
+
265
+unsigned char String::concat(unsigned int num)
266
+{
267
+	char buf[6];
268
+	utoa(num, buf, 10);
269
+	return concat(buf, strlen(buf));
270
+}
271
+
272
+unsigned char String::concat(long num)
273
+{
274
+	char buf[12];
275
+	ltoa(num, buf, 10);
276
+	return concat(buf, strlen(buf));
277
+}
278
+
279
+unsigned char String::concat(unsigned long num)
280
+{
281
+	char buf[11];
282
+	ultoa(num, buf, 10);
283
+	return concat(buf, strlen(buf));
284
+}
285
+
286
+/*********************************************/
287
+/*  Concatenate                              */
288
+/*********************************************/
289
+
290
+StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs)
291
+{
292
+	StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
293
+	if (!a.concat(rhs.buffer, rhs.len)) a.invalidate();
294
+	return a;
295
+}
296
+
297
+StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr)
298
+{
299
+	StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
300
+	if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate();
301
+	return a;
302
+}
303
+
304
+StringSumHelper & operator + (const StringSumHelper &lhs, char c)
305
+{
306
+	StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
307
+	if (!a.concat(c)) a.invalidate();
308
+	return a;
309
+}
310
+
311
+StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num)
312
+{
313
+	StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
314
+	if (!a.concat(num)) a.invalidate();
315
+	return a;
316
+}
317
+
318
+StringSumHelper & operator + (const StringSumHelper &lhs, int num)
319
+{
320
+	StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
321
+	if (!a.concat(num)) a.invalidate();
322
+	return a;
323
+}
324
+
325
+StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num)
326
+{
327
+	StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
328
+	if (!a.concat(num)) a.invalidate();
329
+	return a;
330
+}
331
+
332
+StringSumHelper & operator + (const StringSumHelper &lhs, long num)
333
+{
334
+	StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
335
+	if (!a.concat(num)) a.invalidate();
336
+	return a;
337
+}
338
+
339
+StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num)
340
+{
341
+	StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
342
+	if (!a.concat(num)) a.invalidate();
343
+	return a;
344
+}
345
+
346
+/*********************************************/
347
+/*  Comparison                               */
348
+/*********************************************/
349
+
350
+int String::compareTo(const String &s) const
351
+{
352
+	if (!buffer || !s.buffer) {
353
+		if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer;
354
+		if (buffer && len > 0) return *(unsigned char *)buffer;
355
+		return 0;
356
+	}
357
+	return strcmp(buffer, s.buffer);
358
+}
359
+
360
+unsigned char String::equals(const String &s2) const
361
+{
362
+	return (len == s2.len && compareTo(s2) == 0);
363
+}
364
+
365
+unsigned char String::equals(const char *cstr) const
366
+{
367
+	if (len == 0) return (cstr == NULL || *cstr == 0);
368
+	if (cstr == NULL) return buffer[0] == 0;
369
+	return strcmp(buffer, cstr) == 0;
370
+}
371
+
372
+unsigned char String::operator<(const String &rhs) const
373
+{
374
+	return compareTo(rhs) < 0;
375
+}
376
+
377
+unsigned char String::operator>(const String &rhs) const
378
+{
379
+	return compareTo(rhs) > 0;
380
+}
381
+
382
+unsigned char String::operator<=(const String &rhs) const
383
+{
384
+	return compareTo(rhs) <= 0;
385
+}
386
+
387
+unsigned char String::operator>=(const String &rhs) const
388
+{
389
+	return compareTo(rhs) >= 0;
390
+}
391
+
392
+unsigned char String::equalsIgnoreCase( const String &s2 ) const
393
+{
394
+	if (this == &s2) return 1;
395
+	if (len != s2.len) return 0;
396
+	if (len == 0) return 1;
397
+	const char *p1 = buffer;
398
+	const char *p2 = s2.buffer;
399
+	while (*p1) {
400
+		if (tolower(*p1++) != tolower(*p2++)) return 0;
401
+	} 
402
+	return 1;
403
+}
404
+
405
+unsigned char String::startsWith( const String &s2 ) const
406
+{
407
+	if (len < s2.len) return 0;
408
+	return startsWith(s2, 0);
409
+}
410
+
411
+unsigned char String::startsWith( const String &s2, unsigned int offset ) const
412
+{
413
+	if (offset > len - s2.len || !buffer || !s2.buffer) return 0;
414
+	return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0;
415
+}
416
+
417
+unsigned char String::endsWith( const String &s2 ) const
418
+{
419
+	if ( len < s2.len || !buffer || !s2.buffer) return 0;
420
+	return strcmp(&buffer[len - s2.len], s2.buffer) == 0;
421
+}
422
+
423
+/*********************************************/
424
+/*  Character Access                         */
425
+/*********************************************/
426
+
427
+char String::charAt(unsigned int loc) const
428
+{
429
+	return operator[](loc);
430
+}
431
+
432
+void String::setCharAt(unsigned int loc, char c) 
433
+{
434
+	if (loc < len) buffer[loc] = c;
435
+}
436
+
437
+char & String::operator[](unsigned int index)
438
+{
439
+	static char dummy_writable_char;
440
+	if (index >= len || !buffer) {
441
+		dummy_writable_char = 0;
442
+		return dummy_writable_char;
443
+	}
444
+	return buffer[index];
445
+}
446
+
447
+char String::operator[]( unsigned int index ) const
448
+{
449
+	if (index >= len || !buffer) return 0;
450
+	return buffer[index];
451
+}
452
+
453
+void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const
454
+{
455
+	if (!bufsize || !buf) return;
456
+	if (index >= len) {
457
+		buf[0] = 0;
458
+		return;
459
+	}
460
+	unsigned int n = bufsize - 1;
461
+	if (n > len - index) n = len - index;
462
+	strncpy((char *)buf, buffer + index, n);
463
+	buf[n] = 0;
464
+}
465
+
466
+/*********************************************/
467
+/*  Search                                   */
468
+/*********************************************/
469
+
470
+int String::indexOf(char c) const
471
+{
472
+	return indexOf(c, 0);
473
+}
474
+
475
+int String::indexOf( char ch, unsigned int fromIndex ) const
476
+{
477
+	if (fromIndex >= len) return -1;
478
+	const char* temp = strchr(buffer + fromIndex, ch);
479
+	if (temp == NULL) return -1;
480
+	return temp - buffer;
481
+}
482
+
483
+int String::indexOf(const String &s2) const
484
+{
485
+	return indexOf(s2, 0);
486
+}
487
+
488
+int String::indexOf(const String &s2, unsigned int fromIndex) const
489
+{
490
+	if (fromIndex >= len) return -1;
491
+	const char *found = strstr(buffer + fromIndex, s2.buffer);
492
+	if (found == NULL) return -1;
493
+	return found - buffer;
494
+}
495
+
496
+int String::lastIndexOf( char theChar ) const
497
+{
498
+	return lastIndexOf(theChar, len - 1);
499
+}
500
+
501
+int String::lastIndexOf(char ch, unsigned int fromIndex) const
502
+{
503
+	if (fromIndex >= len) return -1;
504
+	char tempchar = buffer[fromIndex + 1];
505
+	buffer[fromIndex + 1] = '\0';
506
+	char* temp = strrchr( buffer, ch );
507
+	buffer[fromIndex + 1] = tempchar;
508
+	if (temp == NULL) return -1;
509
+	return temp - buffer;
510
+}
511
+
512
+int String::lastIndexOf(const String &s2) const
513
+{
514
+	return lastIndexOf(s2, len - s2.len);
515
+}
516
+
517
+int String::lastIndexOf(const String &s2, unsigned int fromIndex) const
518
+{
519
+  	if (s2.len == 0 || len == 0 || s2.len > len) return -1;
520
+	if (fromIndex >= len) fromIndex = len - 1;
521
+	int found = -1;
522
+	for (char *p = buffer; p <= buffer + fromIndex; p++) {
523
+		p = strstr(p, s2.buffer);
524
+		if (!p) break;
525
+		if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer;
526
+	}
527
+	return found;
528
+}
529
+
530
+String String::substring( unsigned int left ) const
531
+{
532
+	return substring(left, len);
533
+}
534
+
535
+String String::substring(unsigned int left, unsigned int right) const
536
+{
537
+	if (left > right) {
538
+		unsigned int temp = right;
539
+		right = left;
540
+		left = temp;
541
+	}
542
+	String out;
543
+	if (left > len) return out;
544
+	if (right > len) right = len;
545
+	char temp = buffer[right];  // save the replaced character
546
+	buffer[right] = '\0';	
547
+	out = buffer + left;  // pointer arithmetic
548
+	buffer[right] = temp;  //restore character
549
+	return out;
550
+}
551
+
552
+/*********************************************/
553
+/*  Modification                             */
554
+/*********************************************/
555
+
556
+void String::replace(char find, char replace)
557
+{
558
+	if (!buffer) return;
559
+	for (char *p = buffer; *p; p++) {
560
+		if (*p == find) *p = replace;
561
+	}
562
+}
563
+
564
+void String::replace(const String& find, const String& replace)
565
+{
566
+	if (len == 0 || find.len == 0) return;
567
+	int diff = replace.len - find.len;
568
+	char *readFrom = buffer;
569
+	char *foundAt;
570
+	if (diff == 0) {
571
+		while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
572
+			memcpy(foundAt, replace.buffer, replace.len);
573
+			readFrom = foundAt + replace.len;
574
+		}
575
+	} else if (diff < 0) {
576
+		char *writeTo = buffer;
577
+		while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
578
+			unsigned int n = foundAt - readFrom;
579
+			memcpy(writeTo, readFrom, n);
580
+			writeTo += n;
581
+			memcpy(writeTo, replace.buffer, replace.len);
582
+			writeTo += replace.len;
583
+			readFrom = foundAt + find.len;
584
+			len += diff;
585
+		}
586
+		strcpy(writeTo, readFrom);
587
+	} else {
588
+		unsigned int size = len; // compute size needed for result
589
+		while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
590
+			readFrom = foundAt + find.len;
591
+			size += diff;
592
+		}
593
+		if (size == len) return;
594
+		if (size > capacity && !changeBuffer(size)) return; // XXX: tell user!
595
+		int index = len - 1;
596
+		while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) {
597
+			readFrom = buffer + index + find.len;
598
+			memmove(readFrom + diff, readFrom, len - (readFrom - buffer));
599
+			len += diff;
600
+			buffer[len] = 0;
601
+			memcpy(buffer + index, replace.buffer, replace.len);
602
+			index--;
603
+		}
604
+	}
605
+}
606
+
607
+void String::toLowerCase(void)
608
+{
609
+	if (!buffer) return;
610
+	for (char *p = buffer; *p; p++) {
611
+		*p = tolower(*p);
612
+	}
613
+}
614
+
615
+void String::toUpperCase(void)
616
+{
617
+	if (!buffer) return;
618
+	for (char *p = buffer; *p; p++) {
619
+		*p = toupper(*p);
620
+	}
621
+}
622
+
623
+void String::trim(void)
624
+{
625
+	if (!buffer || len == 0) return;
626
+	char *begin = buffer;
627
+	while (isspace(*begin)) begin++;
628
+	char *end = buffer + len - 1;
629
+	while (isspace(*end) && end >= begin) end--;
630
+	len = end + 1 - begin;
631
+	if (begin > buffer) memcpy(buffer, begin, len);
632
+	buffer[len] = 0;
633
+}
634
+
635
+/*********************************************/
636
+/*  Parsing / Conversion                     */
637
+/*********************************************/
638
+
639
+long String::toInt(void) const
640
+{
641
+	if (buffer) return atol(buffer);
642
+	return 0;
643
+}
644
+
645
+

+ 205
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/WString.h View File

@@ -0,0 +1,205 @@
1
+/*
2
+  WString.h - String library for Wiring & Arduino
3
+  ...mostly rewritten by Paul Stoffregen...
4
+  Copyright (c) 2009-10 Hernando Barragan.  All right reserved.
5
+  Copyright 2011, Paul Stoffregen, paul@pjrc.com
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
+
22
+#ifndef String_class_h
23
+#define String_class_h
24
+#ifdef __cplusplus
25
+
26
+#include <stdlib.h>
27
+#include <string.h>
28
+#include <ctype.h>
29
+#include <avr/pgmspace.h>
30
+
31
+// When compiling programs with this class, the following gcc parameters
32
+// dramatically increase performance and memory (RAM) efficiency, typically
33
+// with little or no increase in code size.
34
+//     -felide-constructors
35
+//     -std=c++0x
36
+
37
+class __FlashStringHelper;
38
+#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
39
+
40
+// An inherited class for holding the result of a concatenation.  These
41
+// result objects are assumed to be writable by subsequent concatenations.
42
+class StringSumHelper;
43
+
44
+// The string class
45
+class String
46
+{
47
+	// use a function pointer to allow for "if (s)" without the
48
+	// complications of an operator bool(). for more information, see:
49
+	// http://www.artima.com/cppsource/safebool.html
50
+	typedef void (String::*StringIfHelperType)() const;
51
+	void StringIfHelper() const {}
52
+
53
+public:
54
+	// constructors
55
+	// creates a copy of the initial value.
56
+	// if the initial value is null or invalid, or if memory allocation
57
+	// fails, the string will be marked as invalid (i.e. "if (s)" will
58
+	// be false).
59
+	String(const char *cstr = "");
60
+	String(const String &str);
61
+	#ifdef __GXX_EXPERIMENTAL_CXX0X__
62
+	String(String &&rval);
63
+	String(StringSumHelper &&rval);
64
+	#endif
65
+	explicit String(char c);
66
+	explicit String(unsigned char, unsigned char base=10);
67
+	explicit String(int, unsigned char base=10);
68
+	explicit String(unsigned int, unsigned char base=10);
69
+	explicit String(long, unsigned char base=10);
70
+	explicit String(unsigned long, unsigned char base=10);
71
+	~String(void);
72
+
73
+	// memory management
74
+	// return true on success, false on failure (in which case, the string
75
+	// is left unchanged).  reserve(0), if successful, will validate an
76
+	// invalid string (i.e., "if (s)" will be true afterwards)
77
+	unsigned char reserve(unsigned int size);
78
+	inline unsigned int length(void) const {return len;}
79
+
80
+	// creates a copy of the assigned value.  if the value is null or
81
+	// invalid, or if the memory allocation fails, the string will be 
82
+	// marked as invalid ("if (s)" will be false).
83
+	String & operator = (const String &rhs);
84
+	String & operator = (const char *cstr);
85
+	#ifdef __GXX_EXPERIMENTAL_CXX0X__
86
+	String & operator = (String &&rval);
87
+	String & operator = (StringSumHelper &&rval);
88
+	#endif
89
+
90
+	// concatenate (works w/ built-in types)
91
+	
92
+	// returns true on success, false on failure (in which case, the string
93
+	// is left unchanged).  if the argument is null or invalid, the 
94
+	// concatenation is considered unsucessful.  
95
+	unsigned char concat(const String &str);
96
+	unsigned char concat(const char *cstr);
97
+	unsigned char concat(char c);
98
+	unsigned char concat(unsigned char c);
99
+	unsigned char concat(int num);
100
+	unsigned char concat(unsigned int num);
101
+	unsigned char concat(long num);
102
+	unsigned char concat(unsigned long num);
103
+	
104
+	// if there's not enough memory for the concatenated value, the string
105
+	// will be left unchanged (but this isn't signalled in any way)
106
+	String & operator += (const String &rhs)	{concat(rhs); return (*this);}
107
+	String & operator += (const char *cstr)		{concat(cstr); return (*this);}
108
+	String & operator += (char c)			{concat(c); return (*this);}
109
+	String & operator += (unsigned char num)		{concat(num); return (*this);}
110
+	String & operator += (int num)			{concat(num); return (*this);}
111
+	String & operator += (unsigned int num)		{concat(num); return (*this);}
112
+	String & operator += (long num)			{concat(num); return (*this);}
113
+	String & operator += (unsigned long num)	{concat(num); return (*this);}
114
+
115
+	friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
116
+	friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
117
+	friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
118
+	friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
119
+	friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
120
+	friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
121
+	friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
122
+	friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
123
+
124
+	// comparison (only works w/ Strings and "strings")
125
+	operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
126
+	int compareTo(const String &s) const;
127
+	unsigned char equals(const String &s) const;
128
+	unsigned char equals(const char *cstr) const;
129
+	unsigned char operator == (const String &rhs) const {return equals(rhs);}
130
+	unsigned char operator == (const char *cstr) const {return equals(cstr);}
131
+	unsigned char operator != (const String &rhs) const {return !equals(rhs);}
132
+	unsigned char operator != (const char *cstr) const {return !equals(cstr);}
133
+	unsigned char operator <  (const String &rhs) const;
134
+	unsigned char operator >  (const String &rhs) const;
135
+	unsigned char operator <= (const String &rhs) const;
136
+	unsigned char operator >= (const String &rhs) const;
137
+	unsigned char equalsIgnoreCase(const String &s) const;
138
+	unsigned char startsWith( const String &prefix) const;
139
+	unsigned char startsWith(const String &prefix, unsigned int offset) const;
140
+	unsigned char endsWith(const String &suffix) const;
141
+
142
+	// character acccess
143
+	char charAt(unsigned int index) const;
144
+	void setCharAt(unsigned int index, char c);
145
+	char operator [] (unsigned int index) const;
146
+	char& operator [] (unsigned int index);
147
+	void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
148
+	void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
149
+		{getBytes((unsigned char *)buf, bufsize, index);}
150
+
151
+	// search
152
+	int indexOf( char ch ) const;
153
+	int indexOf( char ch, unsigned int fromIndex ) const;
154
+	int indexOf( const String &str ) const;
155
+	int indexOf( const String &str, unsigned int fromIndex ) const;
156
+	int lastIndexOf( char ch ) const;
157
+	int lastIndexOf( char ch, unsigned int fromIndex ) const;
158
+	int lastIndexOf( const String &str ) const;
159
+	int lastIndexOf( const String &str, unsigned int fromIndex ) const;
160
+	String substring( unsigned int beginIndex ) const;
161
+	String substring( unsigned int beginIndex, unsigned int endIndex ) const;
162
+
163
+	// modification
164
+	void replace(char find, char replace);
165
+	void replace(const String& find, const String& replace);
166
+	void toLowerCase(void);
167
+	void toUpperCase(void);
168
+	void trim(void);
169
+
170
+	// parsing/conversion
171
+	long toInt(void) const;
172
+
173
+protected:
174
+	char *buffer;	        // the actual char array
175
+	unsigned int capacity;  // the array length minus one (for the '\0')
176
+	unsigned int len;       // the String length (not counting the '\0')
177
+	unsigned char flags;    // unused, for future features
178
+protected:
179
+	void init(void);
180
+	void invalidate(void);
181
+	unsigned char changeBuffer(unsigned int maxStrLen);
182
+	unsigned char concat(const char *cstr, unsigned int length);
183
+
184
+	// copy and move
185
+	String & copy(const char *cstr, unsigned int length);
186
+	#ifdef __GXX_EXPERIMENTAL_CXX0X__
187
+	void move(String &rhs);
188
+	#endif
189
+};
190
+
191
+class StringSumHelper : public String
192
+{
193
+public:
194
+	StringSumHelper(const String &s) : String(s) {}
195
+	StringSumHelper(const char *p) : String(p) {}
196
+	StringSumHelper(char c) : String(c) {}
197
+	StringSumHelper(unsigned char num) : String(num) {}
198
+	StringSumHelper(int num) : String(num) {}
199
+	StringSumHelper(unsigned int num) : String(num) {}
200
+	StringSumHelper(long num) : String(num) {}
201
+	StringSumHelper(unsigned long num) : String(num) {}
202
+};
203
+
204
+#endif  // __cplusplus
205
+#endif  // String_class_h

+ 515
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/binary.h View File

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

+ 20
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/main.cpp View File

@@ -0,0 +1,20 @@
1
+#include <Arduino.h>
2
+
3
+int main(void)
4
+{
5
+	init();
6
+
7
+#if defined(USBCON)
8
+	USBDevice.attach();
9
+#endif
10
+	
11
+	setup();
12
+    
13
+	for (;;) {
14
+		loop();
15
+		if (serialEventRun) serialEventRun();
16
+	}
17
+        
18
+	return 0;
19
+}
20
+

+ 18
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/new.cpp View File

@@ -0,0 +1,18 @@
1
+#include <new.h>
2
+
3
+void * operator new(size_t size)
4
+{
5
+  return malloc(size);
6
+}
7
+
8
+void operator delete(void * ptr)
9
+{
10
+  free(ptr);
11
+} 
12
+
13
+int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);};
14
+void __cxa_guard_release (__guard *g) {*(char *)g = 1;};
15
+void __cxa_guard_abort (__guard *) {}; 
16
+
17
+void __cxa_pure_virtual(void) {};
18
+

+ 22
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/new.h View File

@@ -0,0 +1,22 @@
1
+/* Header to define new/delete operators as they aren't provided by avr-gcc by default
2
+   Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453 
3
+ */
4
+
5
+#ifndef NEW_H
6
+#define NEW_H
7
+
8
+#include <stdlib.h>
9
+
10
+void * operator new(size_t size);
11
+void operator delete(void * ptr); 
12
+
13
+__extension__ typedef int __guard __attribute__((mode (__DI__)));
14
+
15
+extern "C" int __cxa_guard_acquire(__guard *);
16
+extern "C" void __cxa_guard_release (__guard *);
17
+extern "C" void __cxa_guard_abort (__guard *); 
18
+
19
+extern "C" void __cxa_pure_virtual(void);
20
+
21
+#endif
22
+

+ 324
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring.c View File

@@ -0,0 +1,324 @@
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
+#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
45
+SIGNAL(TIM0_OVF_vect)
46
+#else
47
+SIGNAL(TIMER0_OVF_vect)
48
+#endif
49
+{
50
+	// copy these to local variables so they can be stored in registers
51
+	// (volatile variables must be read from memory on every access)
52
+	unsigned long m = timer0_millis;
53
+	unsigned char f = timer0_fract;
54
+
55
+	m += MILLIS_INC;
56
+	f += FRACT_INC;
57
+	if (f >= FRACT_MAX) {
58
+		f -= FRACT_MAX;
59
+		m += 1;
60
+	}
61
+
62
+	timer0_fract = f;
63
+	timer0_millis = m;
64
+	timer0_overflow_count++;
65
+}
66
+
67
+unsigned long millis()
68
+{
69
+	unsigned long m;
70
+	uint8_t oldSREG = SREG;
71
+
72
+	// disable interrupts while we read timer0_millis or we might get an
73
+	// inconsistent value (e.g. in the middle of a write to timer0_millis)
74
+	cli();
75
+	m = timer0_millis;
76
+	SREG = oldSREG;
77
+
78
+	return m;
79
+}
80
+
81
+unsigned long micros() {
82
+	unsigned long m;
83
+	uint8_t oldSREG = SREG, t;
84
+	
85
+	cli();
86
+	m = timer0_overflow_count;
87
+#if defined(TCNT0)
88
+	t = TCNT0;
89
+#elif defined(TCNT0L)
90
+	t = TCNT0L;
91
+#else
92
+	#error TIMER 0 not defined
93
+#endif
94
+
95
+  
96
+#ifdef TIFR0
97
+	if ((TIFR0 & _BV(TOV0)) && (t < 255))
98
+		m++;
99
+#else
100
+	if ((TIFR & _BV(TOV0)) && (t < 255))
101
+		m++;
102
+#endif
103
+
104
+	SREG = oldSREG;
105
+	
106
+	return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
107
+}
108
+
109
+void delay(unsigned long ms)
110
+{
111
+	uint16_t start = (uint16_t)micros();
112
+
113
+	while (ms > 0) {
114
+		if (((uint16_t)micros() - start) >= 1000) {
115
+			ms--;
116
+			start += 1000;
117
+		}
118
+	}
119
+}
120
+
121
+/* Delay for the given number of microseconds.  Assumes a 8 or 16 MHz clock. */
122
+void delayMicroseconds(unsigned int us)
123
+{
124
+	// calling avrlib's delay_us() function with low values (e.g. 1 or
125
+	// 2 microseconds) gives delays longer than desired.
126
+	//delay_us(us);
127
+#if F_CPU >= 20000000L
128
+	// for the 20 MHz clock on rare Arduino boards
129
+
130
+	// for a one-microsecond delay, simply wait 2 cycle and return. The overhead
131
+	// of the function call yields a delay of exactly a one microsecond.
132
+	__asm__ __volatile__ (
133
+		"nop" "\n\t"
134
+		"nop"); //just waiting 2 cycle
135
+	if (--us == 0)
136
+		return;
137
+
138
+	// the following loop takes a 1/5 of a microsecond (4 cycles)
139
+	// per iteration, so execute it five times for each microsecond of
140
+	// delay requested.
141
+	us = (us<<2) + us; // x5 us
142
+
143
+	// account for the time taken in the preceeding commands.
144
+	us -= 2;
145
+
146
+#elif F_CPU >= 16000000L
147
+	// for the 16 MHz clock on most Arduino boards
148
+
149
+	// for a one-microsecond delay, simply return.  the overhead
150
+	// of the function call yields a delay of approximately 1 1/8 us.
151
+	if (--us == 0)
152
+		return;
153
+
154
+	// the following loop takes a quarter of a microsecond (4 cycles)
155
+	// per iteration, so execute it four times for each microsecond of
156
+	// delay requested.
157
+	us <<= 2;
158
+
159
+	// account for the time taken in the preceeding commands.
160
+	us -= 2;
161
+#else
162
+	// for the 8 MHz internal clock on the ATmega168
163
+
164
+	// for a one- or two-microsecond delay, simply return.  the overhead of
165
+	// the function calls takes more than two microseconds.  can't just
166
+	// subtract two, since us is unsigned; we'd overflow.
167
+	if (--us == 0)
168
+		return;
169
+	if (--us == 0)
170
+		return;
171
+
172
+	// the following loop takes half of a microsecond (4 cycles)
173
+	// per iteration, so execute it twice for each microsecond of
174
+	// delay requested.
175
+	us <<= 1;
176
+    
177
+	// partially compensate for the time taken by the preceeding commands.
178
+	// we can't subtract any more than this or we'd overflow w/ small delays.
179
+	us--;
180
+#endif
181
+
182
+	// busy wait
183
+	__asm__ __volatile__ (
184
+		"1: sbiw %0,1" "\n\t" // 2 cycles
185
+		"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
186
+	);
187
+}
188
+
189
+void init()
190
+{
191
+	// this needs to be called before setup() or some functions won't
192
+	// work there
193
+	sei();
194
+	
195
+	// on the ATmega168, timer 0 is also used for fast hardware pwm
196
+	// (using phase-correct PWM would mean that timer 0 overflowed half as often
197
+	// resulting in different millis() behavior on the ATmega8 and ATmega168)
198
+#if defined(TCCR0A) && defined(WGM01)
199
+	sbi(TCCR0A, WGM01);
200
+	sbi(TCCR0A, WGM00);
201
+#endif  
202
+
203
+	// set timer 0 prescale factor to 64
204
+#if defined(__AVR_ATmega128__)
205
+	// CPU specific: different values for the ATmega128
206
+	sbi(TCCR0, CS02);
207
+#elif defined(TCCR0) && defined(CS01) && defined(CS00)
208
+	// this combination is for the standard atmega8
209
+	sbi(TCCR0, CS01);
210
+	sbi(TCCR0, CS00);
211
+#elif defined(TCCR0B) && defined(CS01) && defined(CS00)
212
+	// this combination is for the standard 168/328/1280/2560
213
+	sbi(TCCR0B, CS01);
214
+	sbi(TCCR0B, CS00);
215
+#elif defined(TCCR0A) && defined(CS01) && defined(CS00)
216
+	// this combination is for the __AVR_ATmega645__ series
217
+	sbi(TCCR0A, CS01);
218
+	sbi(TCCR0A, CS00);
219
+#else
220
+	#error Timer 0 prescale factor 64 not set correctly
221
+#endif
222
+
223
+	// enable timer 0 overflow interrupt
224
+#if defined(TIMSK) && defined(TOIE0)
225
+	sbi(TIMSK, TOIE0);
226
+#elif defined(TIMSK0) && defined(TOIE0)
227
+	sbi(TIMSK0, TOIE0);
228
+#else
229
+	#error	Timer 0 overflow interrupt not set correctly
230
+#endif
231
+
232
+	// timers 1 and 2 are used for phase-correct hardware pwm
233
+	// this is better for motors as it ensures an even waveform
234
+	// note, however, that fast pwm mode can achieve a frequency of up
235
+	// 8 MHz (with a 16 MHz clock) at 50% duty cycle
236
+
237
+#if defined(TCCR1B) && defined(CS11) && defined(CS10)
238
+	TCCR1B = 0;
239
+
240
+	// set timer 1 prescale factor to 64
241
+	sbi(TCCR1B, CS11);
242
+#if F_CPU >= 8000000L
243
+	sbi(TCCR1B, CS10);
244
+#endif
245
+#elif defined(TCCR1) && defined(CS11) && defined(CS10)
246
+	sbi(TCCR1, CS11);
247
+#if F_CPU >= 8000000L
248
+	sbi(TCCR1, CS10);
249
+#endif
250
+#endif
251
+	// put timer 1 in 8-bit phase correct pwm mode
252
+#if defined(TCCR1A) && defined(WGM10)
253
+	sbi(TCCR1A, WGM10);
254
+#elif defined(TCCR1)
255
+	#warning this needs to be finished
256
+#endif
257
+
258
+	// set timer 2 prescale factor to 64
259
+#if defined(TCCR2) && defined(CS22)
260
+	sbi(TCCR2, CS22);
261
+#elif defined(TCCR2B) && defined(CS22)
262
+	sbi(TCCR2B, CS22);
263
+#else
264
+	#warning Timer 2 not finished (may not be present on this CPU)
265
+#endif
266
+
267
+	// configure timer 2 for phase correct pwm (8-bit)
268
+#if defined(TCCR2) && defined(WGM20)
269
+	sbi(TCCR2, WGM20);
270
+#elif defined(TCCR2A) && defined(WGM20)
271
+	sbi(TCCR2A, WGM20);
272
+#else
273
+	#warning Timer 2 not finished (may not be present on this CPU)
274
+#endif
275
+
276
+#if defined(TCCR3B) && defined(CS31) && defined(WGM30)
277
+	sbi(TCCR3B, CS31);		// set timer 3 prescale factor to 64
278
+	sbi(TCCR3B, CS30);
279
+	sbi(TCCR3A, WGM30);		// put timer 3 in 8-bit phase correct pwm mode
280
+#endif
281
+
282
+#if defined(TCCR4A) && defined(TCCR4B) && defined(TCCR4D) /* beginning of timer4 block for 32U4 and similar */
283
+	sbi(TCCR4B, CS42);		// set timer4 prescale factor to 64
284
+	sbi(TCCR4B, CS41);
285
+	sbi(TCCR4B, CS40);
286
+	sbi(TCCR4D, WGM40);		// put timer 4 in phase- and frequency-correct PWM mode	
287
+	sbi(TCCR4A, PWM4A);		// enable PWM mode for comparator OCR4A
288
+	sbi(TCCR4C, PWM4D);		// enable PWM mode for comparator OCR4D
289
+#else /* beginning of timer4 block for ATMEGA1280 and ATMEGA2560 */
290
+#if defined(TCCR4B) && defined(CS41) && defined(WGM40)
291
+	sbi(TCCR4B, CS41);		// set timer 4 prescale factor to 64
292
+	sbi(TCCR4B, CS40);
293
+	sbi(TCCR4A, WGM40);		// put timer 4 in 8-bit phase correct pwm mode
294
+#endif
295
+#endif /* end timer4 block for ATMEGA1280/2560 and similar */	
296
+
297
+#if defined(TCCR5B) && defined(CS51) && defined(WGM50)
298
+	sbi(TCCR5B, CS51);		// set timer 5 prescale factor to 64
299
+	sbi(TCCR5B, CS50);
300
+	sbi(TCCR5A, WGM50);		// put timer 5 in 8-bit phase correct pwm mode
301
+#endif
302
+
303
+#if defined(ADCSRA)
304
+	// set a2d prescale factor to 128
305
+	// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
306
+	// XXX: this will not work properly for other clock speeds, and
307
+	// this code should use F_CPU to determine the prescale factor.
308
+	sbi(ADCSRA, ADPS2);
309
+	sbi(ADCSRA, ADPS1);
310
+	sbi(ADCSRA, ADPS0);
311
+
312
+	// enable a2d conversions
313
+	sbi(ADCSRA, ADEN);
314
+#endif
315
+
316
+	// the bootloader connects pins 0 and 1 to the USART; disconnect them
317
+	// here so they can be used as normal digital i/o; they will be
318
+	// reconnected in Serial.begin()
319
+#if defined(UCSRB)
320
+	UCSRB = 0;
321
+#elif defined(UCSR0B)
322
+	UCSR0B = 0;
323
+#endif
324
+}

+ 282
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_analog.c View File

@@ -0,0 +1,282 @@
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
+#elif defined(__AVR_ATmega32U4__)
47
+	if (pin >= 18) pin -= 18; // allow for channel or pin numbers
48
+#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
49
+	if (pin >= 24) pin -= 24; // allow for channel or pin numbers
50
+#else
51
+	if (pin >= 14) pin -= 14; // allow for channel or pin numbers
52
+#endif
53
+	
54
+#if defined(__AVR_ATmega32U4__)
55
+	pin = analogPinToChannel(pin);
56
+	ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
57
+#elif defined(ADCSRB) && defined(MUX5)
58
+	// the MUX5 bit of ADCSRB selects whether we're reading from channels
59
+	// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
60
+	ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
61
+#endif
62
+  
63
+	// set the analog reference (high two bits of ADMUX) and select the
64
+	// channel (low 4 bits).  this also sets ADLAR (left-adjust result)
65
+	// to 0 (the default).
66
+#if defined(ADMUX)
67
+	ADMUX = (analog_reference << 6) | (pin & 0x07);
68
+#endif
69
+
70
+	// without a delay, we seem to read from the wrong channel
71
+	//delay(1);
72
+
73
+#if defined(ADCSRA) && defined(ADCL)
74
+	// start the conversion
75
+	sbi(ADCSRA, ADSC);
76
+
77
+	// ADSC is cleared when the conversion finishes
78
+	while (bit_is_set(ADCSRA, ADSC));
79
+
80
+	// we have to read ADCL first; doing so locks both ADCL
81
+	// and ADCH until ADCH is read.  reading ADCL second would
82
+	// cause the results of each conversion to be discarded,
83
+	// as ADCL and ADCH would be locked when it completed.
84
+	low  = ADCL;
85
+	high = ADCH;
86
+#else
87
+	// we dont have an ADC, return 0
88
+	low  = 0;
89
+	high = 0;
90
+#endif
91
+
92
+	// combine the two bytes
93
+	return (high << 8) | low;
94
+}
95
+
96
+// Right now, PWM output only works on the pins with
97
+// hardware support.  These are defined in the appropriate
98
+// pins_*.c file.  For the rest of the pins, we default
99
+// to digital output.
100
+void analogWrite(uint8_t pin, int val)
101
+{
102
+	// We need to make sure the PWM output is enabled for those pins
103
+	// that support it, as we turn it off when digitally reading or
104
+	// writing with them.  Also, make sure the pin is in output mode
105
+	// for consistenty with Wiring, which doesn't require a pinMode
106
+	// call for the analog output pins.
107
+	pinMode(pin, OUTPUT);
108
+	if (val == 0)
109
+	{
110
+		digitalWrite(pin, LOW);
111
+	}
112
+	else if (val == 255)
113
+	{
114
+		digitalWrite(pin, HIGH);
115
+	}
116
+	else
117
+	{
118
+		switch(digitalPinToTimer(pin))
119
+		{
120
+			// XXX fix needed for atmega8
121
+			#if defined(TCCR0) && defined(COM00) && !defined(__AVR_ATmega8__)
122
+			case TIMER0A:
123
+				// connect pwm to pin on timer 0
124
+				sbi(TCCR0, COM00);
125
+				OCR0 = val; // set pwm duty
126
+				break;
127
+			#endif
128
+
129
+			#if defined(TCCR0A) && defined(COM0A1)
130
+			case TIMER0A:
131
+				// connect pwm to pin on timer 0, channel A
132
+				sbi(TCCR0A, COM0A1);
133
+				OCR0A = val; // set pwm duty
134
+				break;
135
+			#endif
136
+
137
+			#if defined(TCCR0A) && defined(COM0B1)
138
+			case TIMER0B:
139
+				// connect pwm to pin on timer 0, channel B
140
+				sbi(TCCR0A, COM0B1);
141
+				OCR0B = val; // set pwm duty
142
+				break;
143
+			#endif
144
+
145
+			#if defined(TCCR1A) && defined(COM1A1)
146
+			case TIMER1A:
147
+				// connect pwm to pin on timer 1, channel A
148
+				sbi(TCCR1A, COM1A1);
149
+				OCR1A = val; // set pwm duty
150
+				break;
151
+			#endif
152
+
153
+			#if defined(TCCR1A) && defined(COM1B1)
154
+			case TIMER1B:
155
+				// connect pwm to pin on timer 1, channel B
156
+				sbi(TCCR1A, COM1B1);
157
+				OCR1B = val; // set pwm duty
158
+				break;
159
+			#endif
160
+
161
+			#if defined(TCCR2) && defined(COM21)
162
+			case TIMER2:
163
+				// connect pwm to pin on timer 2
164
+				sbi(TCCR2, COM21);
165
+				OCR2 = val; // set pwm duty
166
+				break;
167
+			#endif
168
+
169
+			#if defined(TCCR2A) && defined(COM2A1)
170
+			case TIMER2A:
171
+				// connect pwm to pin on timer 2, channel A
172
+				sbi(TCCR2A, COM2A1);
173
+				OCR2A = val; // set pwm duty
174
+				break;
175
+			#endif
176
+
177
+			#if defined(TCCR2A) && defined(COM2B1)
178
+			case TIMER2B:
179
+				// connect pwm to pin on timer 2, channel B
180
+				sbi(TCCR2A, COM2B1);
181
+				OCR2B = val; // set pwm duty
182
+				break;
183
+			#endif
184
+
185
+			#if defined(TCCR3A) && defined(COM3A1)
186
+			case TIMER3A:
187
+				// connect pwm to pin on timer 3, channel A
188
+				sbi(TCCR3A, COM3A1);
189
+				OCR3A = val; // set pwm duty
190
+				break;
191
+			#endif
192
+
193
+			#if defined(TCCR3A) && defined(COM3B1)
194
+			case TIMER3B:
195
+				// connect pwm to pin on timer 3, channel B
196
+				sbi(TCCR3A, COM3B1);
197
+				OCR3B = val; // set pwm duty
198
+				break;
199
+			#endif
200
+
201
+			#if defined(TCCR3A) && defined(COM3C1)
202
+			case TIMER3C:
203
+				// connect pwm to pin on timer 3, channel C
204
+				sbi(TCCR3A, COM3C1);
205
+				OCR3C = val; // set pwm duty
206
+				break;
207
+			#endif
208
+
209
+			#if defined(TCCR4A)
210
+			case TIMER4A:
211
+				//connect pwm to pin on timer 4, channel A
212
+				sbi(TCCR4A, COM4A1);
213
+				#if defined(COM4A0)		// only used on 32U4
214
+				cbi(TCCR4A, COM4A0);
215
+				#endif
216
+				OCR4A = val;	// set pwm duty
217
+				break;
218
+			#endif
219
+			
220
+			#if defined(TCCR4A) && defined(COM4B1)
221
+			case TIMER4B:
222
+				// connect pwm to pin on timer 4, channel B
223
+				sbi(TCCR4A, COM4B1);
224
+				OCR4B = val; // set pwm duty
225
+				break;
226
+			#endif
227
+
228
+			#if defined(TCCR4A) && defined(COM4C1)
229
+			case TIMER4C:
230
+				// connect pwm to pin on timer 4, channel C
231
+				sbi(TCCR4A, COM4C1);
232
+				OCR4C = val; // set pwm duty
233
+				break;
234
+			#endif
235
+				
236
+			#if defined(TCCR4C) && defined(COM4D1)
237
+			case TIMER4D:				
238
+				// connect pwm to pin on timer 4, channel D
239
+				sbi(TCCR4C, COM4D1);
240
+				#if defined(COM4D0)		// only used on 32U4
241
+				cbi(TCCR4C, COM4D0);
242
+				#endif
243
+				OCR4D = val;	// set pwm duty
244
+				break;
245
+			#endif
246
+
247
+							
248
+			#if defined(TCCR5A) && defined(COM5A1)
249
+			case TIMER5A:
250
+				// connect pwm to pin on timer 5, channel A
251
+				sbi(TCCR5A, COM5A1);
252
+				OCR5A = val; // set pwm duty
253
+				break;
254
+			#endif
255
+
256
+			#if defined(TCCR5A) && defined(COM5B1)
257
+			case TIMER5B:
258
+				// connect pwm to pin on timer 5, channel B
259
+				sbi(TCCR5A, COM5B1);
260
+				OCR5B = val; // set pwm duty
261
+				break;
262
+			#endif
263
+
264
+			#if defined(TCCR5A) && defined(COM5C1)
265
+			case TIMER5C:
266
+				// connect pwm to pin on timer 5, channel C
267
+				sbi(TCCR5A, COM5C1);
268
+				OCR5C = val; // set pwm duty
269
+				break;
270
+			#endif
271
+
272
+			case NOT_ON_TIMER:
273
+			default:
274
+				if (val < 128) {
275
+					digitalWrite(pin, LOW);
276
+				} else {
277
+					digitalWrite(pin, HIGH);
278
+				}
279
+		}
280
+	}
281
+}
282
+

+ 178
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_digital.c View File

@@ -0,0 +1,178 @@
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
+#define ARDUINO_MAIN
28
+#include "wiring_private.h"
29
+#include "pins_arduino.h"
30
+
31
+void pinMode(uint8_t pin, uint8_t mode)
32
+{
33
+	uint8_t bit = digitalPinToBitMask(pin);
34
+	uint8_t port = digitalPinToPort(pin);
35
+	volatile uint8_t *reg, *out;
36
+
37
+	if (port == NOT_A_PIN) return;
38
+
39
+	// JWS: can I let the optimizer do this?
40
+	reg = portModeRegister(port);
41
+	out = portOutputRegister(port);
42
+
43
+	if (mode == INPUT) { 
44
+		uint8_t oldSREG = SREG;
45
+                cli();
46
+		*reg &= ~bit;
47
+		*out &= ~bit;
48
+		SREG = oldSREG;
49
+	} else if (mode == INPUT_PULLUP) {
50
+		uint8_t oldSREG = SREG;
51
+                cli();
52
+		*reg &= ~bit;
53
+		*out |= bit;
54
+		SREG = oldSREG;
55
+	} else {
56
+		uint8_t oldSREG = SREG;
57
+                cli();
58
+		*reg |= bit;
59
+		SREG = oldSREG;
60
+	}
61
+}
62
+
63
+// Forcing this inline keeps the callers from having to push their own stuff
64
+// on the stack. It is a good performance win and only takes 1 more byte per
65
+// user than calling. (It will take more bytes on the 168.)
66
+//
67
+// But shouldn't this be moved into pinMode? Seems silly to check and do on
68
+// each digitalread or write.
69
+//
70
+// Mark Sproul:
71
+// - Removed inline. Save 170 bytes on atmega1280
72
+// - changed to a switch statment; added 32 bytes but much easier to read and maintain.
73
+// - Added more #ifdefs, now compiles for atmega645
74
+//
75
+//static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
76
+//static inline void turnOffPWM(uint8_t timer)
77
+static void turnOffPWM(uint8_t timer)
78
+{
79
+	switch (timer)
80
+	{
81
+		#if defined(TCCR1A) && defined(COM1A1)
82
+		case TIMER1A:   cbi(TCCR1A, COM1A1);    break;
83
+		#endif
84
+		#if defined(TCCR1A) && defined(COM1B1)
85
+		case TIMER1B:   cbi(TCCR1A, COM1B1);    break;
86
+		#endif
87
+		
88
+		#if defined(TCCR2) && defined(COM21)
89
+		case  TIMER2:   cbi(TCCR2, COM21);      break;
90
+		#endif
91
+		
92
+		#if defined(TCCR0A) && defined(COM0A1)
93
+		case  TIMER0A:  cbi(TCCR0A, COM0A1);    break;
94
+		#endif
95
+		
96
+		#if defined(TIMER0B) && defined(COM0B1)
97
+		case  TIMER0B:  cbi(TCCR0A, COM0B1);    break;
98
+		#endif
99
+		#if defined(TCCR2A) && defined(COM2A1)
100
+		case  TIMER2A:  cbi(TCCR2A, COM2A1);    break;
101
+		#endif
102
+		#if defined(TCCR2A) && defined(COM2B1)
103
+		case  TIMER2B:  cbi(TCCR2A, COM2B1);    break;
104
+		#endif
105
+		
106
+		#if defined(TCCR3A) && defined(COM3A1)
107
+		case  TIMER3A:  cbi(TCCR3A, COM3A1);    break;
108
+		#endif
109
+		#if defined(TCCR3A) && defined(COM3B1)
110
+		case  TIMER3B:  cbi(TCCR3A, COM3B1);    break;
111
+		#endif
112
+		#if defined(TCCR3A) && defined(COM3C1)
113
+		case  TIMER3C:  cbi(TCCR3A, COM3C1);    break;
114
+		#endif
115
+
116
+		#if defined(TCCR4A) && defined(COM4A1)
117
+		case  TIMER4A:  cbi(TCCR4A, COM4A1);    break;
118
+		#endif					
119
+		#if defined(TCCR4A) && defined(COM4B1)
120
+		case  TIMER4B:  cbi(TCCR4A, COM4B1);    break;
121
+		#endif
122
+		#if defined(TCCR4A) && defined(COM4C1)
123
+		case  TIMER4C:  cbi(TCCR4A, COM4C1);    break;
124
+		#endif			
125
+		#if defined(TCCR4C) && defined(COM4D1)
126
+		case TIMER4D:	cbi(TCCR4C, COM4D1);	break;
127
+		#endif			
128
+			
129
+		#if defined(TCCR5A)
130
+		case  TIMER5A:  cbi(TCCR5A, COM5A1);    break;
131
+		case  TIMER5B:  cbi(TCCR5A, COM5B1);    break;
132
+		case  TIMER5C:  cbi(TCCR5A, COM5C1);    break;
133
+		#endif
134
+	}
135
+}
136
+
137
+void digitalWrite(uint8_t pin, uint8_t val)
138
+{
139
+	uint8_t timer = digitalPinToTimer(pin);
140
+	uint8_t bit = digitalPinToBitMask(pin);
141
+	uint8_t port = digitalPinToPort(pin);
142
+	volatile uint8_t *out;
143
+
144
+	if (port == NOT_A_PIN) return;
145
+
146
+	// If the pin that support PWM output, we need to turn it off
147
+	// before doing a digital write.
148
+	if (timer != NOT_ON_TIMER) turnOffPWM(timer);
149
+
150
+	out = portOutputRegister(port);
151
+
152
+	uint8_t oldSREG = SREG;
153
+	cli();
154
+
155
+	if (val == LOW) {
156
+		*out &= ~bit;
157
+	} else {
158
+		*out |= bit;
159
+	}
160
+
161
+	SREG = oldSREG;
162
+}
163
+
164
+int digitalRead(uint8_t pin)
165
+{
166
+	uint8_t timer = digitalPinToTimer(pin);
167
+	uint8_t bit = digitalPinToBitMask(pin);
168
+	uint8_t port = digitalPinToPort(pin);
169
+
170
+	if (port == NOT_A_PIN) return LOW;
171
+
172
+	// If the pin that support PWM output, we need to turn it off
173
+	// before getting a digital reading.
174
+	if (timer != NOT_ON_TIMER) turnOffPWM(timer);
175
+
176
+	if (*portInputRegister(port) & bit) return HIGH;
177
+	return LOW;
178
+}

+ 71
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_private.h View File

@@ -0,0 +1,71 @@
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 <stdio.h>
31
+#include <stdarg.h>
32
+
33
+#include "Arduino.h"
34
+
35
+#ifdef __cplusplus
36
+extern "C"{
37
+#endif
38
+
39
+#ifndef cbi
40
+#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
41
+#endif
42
+#ifndef sbi
43
+#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
44
+#endif
45
+
46
+#define EXTERNAL_INT_0 0
47
+#define EXTERNAL_INT_1 1
48
+#define EXTERNAL_INT_2 2
49
+#define EXTERNAL_INT_3 3
50
+#define EXTERNAL_INT_4 4
51
+#define EXTERNAL_INT_5 5
52
+#define EXTERNAL_INT_6 6
53
+#define EXTERNAL_INT_7 7
54
+
55
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
56
+#define EXTERNAL_NUM_INTERRUPTS 8
57
+#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
58
+#define EXTERNAL_NUM_INTERRUPTS 3
59
+#elif defined(__AVR_ATmega32U4__)
60
+#define EXTERNAL_NUM_INTERRUPTS 4
61
+#else
62
+#define EXTERNAL_NUM_INTERRUPTS 2
63
+#endif
64
+
65
+typedef void (*voidFuncPtr)(void);
66
+
67
+#ifdef __cplusplus
68
+} // extern "C"
69
+#endif
70
+
71
+#endif

+ 69
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_pulse.c View File

@@ -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
ArduinoAddons/Arduino_1.x.x/sanguino/cores/arduino/wiring_shift.c View File

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

+ 285
- 0
ArduinoAddons/Arduino_1.x.x/sanguino/variants/standard/pins_arduino.h View File

@@ -0,0 +1,285 @@
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
+  Changelog
25
+  -----------
26
+  11/25/11  - ryan@ryanmsutton.com - Add pins for Sanguino 644P and 1284P
27
+  07/15/12  - ryan@ryanmsutton.com - Updated for arduino0101
28
+*/
29
+
30
+#ifndef Pins_Arduino_h
31
+#define Pins_Arduino_h
32
+
33
+#include <avr/pgmspace.h>
34
+
35
+#define NOT_A_PIN 0
36
+#define NOT_A_PORT 0
37
+
38
+#define NOT_ON_TIMER 0
39
+#define TIMER0A 1
40
+#define TIMER0B 2
41
+#define TIMER1A 3
42
+#define TIMER1B 4
43
+#define TIMER2  5
44
+#define TIMER2A 6
45
+#define TIMER2B 7
46
+
47
+#define TIMER3A 8
48
+#define TIMER3B 9
49
+#define TIMER3C 10
50
+#define TIMER4A 11
51
+#define TIMER4B 12
52
+#define TIMER4C 13
53
+#define TIMER5A 14
54
+#define TIMER5B 15
55
+#define TIMER5C 16
56
+
57
+const static uint8_t SS   = 4;
58
+const static uint8_t MOSI = 5;
59
+const static uint8_t MISO = 6;
60
+const static uint8_t SCK  = 7;
61
+
62
+static const uint8_t SDA = 17;
63
+static const uint8_t SCL = 16;
64
+static const uint8_t LED_BUILTIN = 13;
65
+
66
+static const uint8_t A0 = 31;
67
+static const uint8_t A1 = 30;
68
+static const uint8_t A2 = 29;
69
+static const uint8_t A3 = 28;
70
+static const uint8_t A4 = 27;
71
+static const uint8_t A5 = 26;
72
+static const uint8_t A6 = 25;
73
+static const uint8_t A7 = 24;
74
+
75
+// On the ATmega1280, the addresses of some of the port registers are
76
+// greater than 255, so we can't store them in uint8_t's.
77
+// extern const uint16_t PROGMEM port_to_mode_PGM[];
78
+// extern const uint16_t PROGMEM port_to_input_PGM[];
79
+// extern const uint16_t PROGMEM port_to_output_PGM[];
80
+
81
+// extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
82
+// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
83
+// extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
84
+// extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
85
+
86
+// ATMEL ATMEGA644P / SANGUINO
87
+//
88
+//                   +---\/---+
89
+//  INT0 (D 0) PB0  1|        |40  PA0 (AI 0 / D31)
90
+//  INT1 (D 1) PB1  2|        |39  PA1 (AI 1 / D30)
91
+//  INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D29)
92
+//   PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D28)
93
+//   PWM (D 4) PB4  5|        |36  PA4 (AI 4 / D27)
94
+//  MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D26)
95
+//  MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D25)
96
+//   SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D24)
97
+//             RST  9|        |32  AREF
98
+//             VCC 10|        |31  GND 
99
+//             GND 11|        |30  AVCC
100
+//           XTAL2 12|        |29  PC7 (D 23)
101
+//           XTAL1 13|        |28  PC6 (D 22)
102
+//  RX0 (D 8)  PD0 14|        |27  PC5 (D 21) TDI
103
+//  TX0 (D 9)  PD1 15|        |26  PC4 (D 20) TDO
104
+//  RX1 (D 10) PD2 16|        |25  PC3 (D 19) TMS
105
+//  TX1 (D 11) PD3 17|        |24  PC2 (D 18) TCK
106
+//  PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA
107
+//  PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL
108
+//  PWM (D 14) PD6 20|        |21  PD7 (D 15) PWM
109
+//                   +--------+
110
+//
111
+#define NUM_DIGITAL_PINS            24
112
+#define NUM_ANALOG_INPUTS           8
113
+#define analogInputToDigitalPin(p)  ((p < 7) ? (p) + 24 : -1)
114
+
115
+#define digitalPinHasPWM(p)         ((p) == 3 || (p) == 4 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 )
116
+
117
+#define digitalPinToPCICR(p)    ( (((p) >= 0) && ((p) <= 31)) ? (&PCICR) : ((uint8_t *)0) )
118
+
119
+#define digitalPinToPCICRbit(p) ( (((p) >= 24) && ((p) <= 31)) ? 0 : \
120
+                                ( (((p) >=  0) && ((p) <=  7)) ? 1 : \
121
+                                ( (((p) >= 16) && ((p) <= 23)) ? 2 : \
122
+                                ( (((p) >=  8) && ((p) <= 15)) ? 3 : \
123
+                                0 ) ) ) )
124
+
125
+#define digitalPinToPCMSK(p)    ( (((p) >= 24) && ((p) <= 31)) ? (&PCMSK0) : \
126
+                                ( (((p) >=  0) && ((p) <=  7)) ? (&PCMSK1) : \
127
+                                ( (((p) >= 16) && ((p) <= 23)) ? (&PCMSK2) : \
128
+                                ( (((p) >=  8) && ((p) <= 15)) ? (&PCMSK3) : \
129
+                                ((uint8_t *)0) ) ) ) )
130
+
131
+
132
+#define digitalPinToPCMSKbit(p) ( (((p) >= 24) && ((p) <= 31)) ? (31 - (p)) : \
133
+                                ( (((p) >=  0) && ((p) <=  7)) ? (p) : \
134
+                                ( (((p) >= 16) && ((p) <= 23)) ? ((p) - 16) : \
135
+                                ( (((p) >=  8) && ((p) <= 15)) ? ((p) - 8) : \
136
+                                0 ) ) ) )
137
+
138
+#define PA 1
139
+#define PB 2
140
+#define PC 3
141
+#define PD 4
142
+#define PE 5
143
+#define PF 6
144
+#define PG 7
145
+#define PH 8
146
+#define PJ 10
147
+#define PK 11
148
+#define PL 12
149
+
150
+#ifdef ARDUINO_MAIN
151
+// these arrays map port names (e.g. port B) to the
152
+// appropriate addresses for various functions (e.g. reading
153
+// and writing)
154
+const uint16_t PROGMEM port_to_mode_PGM[] =
155
+{
156
+        NOT_A_PORT,
157
+        (uint16_t) &DDRA,
158
+        (uint16_t) &DDRB,
159
+        (uint16_t) &DDRC,
160
+        (uint16_t) &DDRD,
161
+};
162
+
163
+const uint16_t PROGMEM port_to_output_PGM[] =
164
+{
165
+        NOT_A_PORT,
166
+        (uint16_t) &PORTA,
167
+        (uint16_t) &PORTB,
168
+        (uint16_t) &PORTC,
169
+        (uint16_t) &PORTD,
170
+};
171
+const uint16_t PROGMEM port_to_input_PGM[] =
172
+{
173
+        NOT_A_PORT,
174
+        (uint16_t) &PINA,
175
+        (uint16_t) &PINB,
176
+        (uint16_t) &PINC,
177
+        (uint16_t) &PIND,
178
+};
179
+const uint8_t PROGMEM digital_pin_to_port_PGM[] =
180
+{
181
+        PB, /* 0 */
182
+        PB,
183
+        PB,
184
+        PB,
185
+        PB,
186
+        PB,
187
+        PB,
188
+        PB,
189
+        PD, /* 8 */
190
+        PD,
191
+        PD,
192
+        PD,
193
+        PD,
194
+        PD,
195
+        PD,
196
+        PD,
197
+        PC, /* 16 */
198
+        PC,
199
+        PC,
200
+        PC,
201
+        PC,
202
+        PC,
203
+        PC,
204
+        PC,
205
+        PA, /* 24 */
206
+        PA,
207
+        PA,
208
+        PA,
209
+        PA,
210
+        PA,
211
+        PA,
212
+        PA  /* 31 */
213
+};
214
+const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
215
+{
216
+        _BV(0), /* 0, port B */
217
+        _BV(1),
218
+        _BV(2),
219
+        _BV(3),
220
+        _BV(4),
221
+        _BV(5),
222
+        _BV(6),
223
+        _BV(7),
224
+        _BV(0), /* 8, port D */
225
+        _BV(1),
226
+        _BV(2),
227
+        _BV(3),
228
+        _BV(4),
229
+        _BV(5),
230
+        _BV(6),
231
+        _BV(7),
232
+        _BV(0), /* 16, port C */
233
+        _BV(1),
234
+        _BV(2),
235
+        _BV(3),
236
+        _BV(4),
237
+        _BV(5),
238
+        _BV(6),
239
+        _BV(7),
240
+        _BV(7), /* 24, port A */
241
+        _BV(6),
242
+        _BV(5),
243
+        _BV(4),
244
+        _BV(3),
245
+        _BV(2),
246
+        _BV(1),
247
+        _BV(0)
248
+};
249
+const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
250
+{
251
+        NOT_ON_TIMER,   /* 0  - PB0 */
252
+        NOT_ON_TIMER,   /* 1  - PB1 */
253
+        NOT_ON_TIMER,   /* 2  - PB2 */
254
+        TIMER0A,        /* 3  - PB3 */
255
+        TIMER0B,                /* 4  - PB4 */
256
+        NOT_ON_TIMER,   /* 5  - PB5 */
257
+        NOT_ON_TIMER,   /* 6  - PB6 */
258
+        NOT_ON_TIMER,   /* 7  - PB7 */
259
+        NOT_ON_TIMER,   /* 8  - PD0 */
260
+        NOT_ON_TIMER,   /* 9  - PD1 */
261
+        NOT_ON_TIMER,   /* 10 - PD2 */
262
+        NOT_ON_TIMER,   /* 11 - PD3 */
263
+        TIMER1B,        /* 12 - PD4 */
264
+        TIMER1A,        /* 13 - PD5 */
265
+        TIMER2B,        /* 14 - PD6 */
266
+        TIMER2A,        /* 15 - PD7 */
267
+        NOT_ON_TIMER,   /* 16 - PC0 */
268
+        NOT_ON_TIMER,   /* 17 - PC1 */
269
+        NOT_ON_TIMER,   /* 18 - PC2 */
270
+        NOT_ON_TIMER,   /* 19 - PC3 */
271
+        NOT_ON_TIMER,   /* 20 - PC4 */
272
+        NOT_ON_TIMER,   /* 21 - PC5 */
273
+        NOT_ON_TIMER,   /* 22 - PC6 */
274
+        NOT_ON_TIMER,   /* 23 - PC7 */
275
+        NOT_ON_TIMER,   /* 24 - PA0 */
276
+        NOT_ON_TIMER,   /* 25 - PA1 */
277
+        NOT_ON_TIMER,   /* 26 - PA2 */
278
+        NOT_ON_TIMER,   /* 27 - PA3 */
279
+        NOT_ON_TIMER,   /* 28 - PA4 */
280
+        NOT_ON_TIMER,   /* 29 - PA5 */
281
+        NOT_ON_TIMER,   /* 30 - PA6 */
282
+        NOT_ON_TIMER   /* 31 - PA7 */
283
+};
284
+#endif
285
+#endif

+ 9
- 6
Marlin/Makefile View File

@@ -171,15 +171,15 @@ F_CPU ?= 16000000
171 171
 # that derives from that, and their source are present in
172 172
 # the main Marlin source directory
173 173
 ifeq ($(HARDWARE_VARIANT), arduino)
174
-HARDWARE_SRC = $(ARDUINO_INSTALL_DIR)/hardware/arduino/cores/arduino
174
+HARDWARE_DIR = $(ARDUINO_INSTALL_DIR)/hardware
175 175
 else
176 176
 ifeq ($(shell [ $(ARDUINO_VERSION) -ge 100 ] && echo true), true)
177
-HARDWARE_SRC = ../ArduinoAddons/Arduino_1.x.x/$(HARDWARE_VARIANT)/cores/arduino
177
+HARDWARE_DIR = ../ArduinoAddons/Arduino_1.x.x
178 178
 else
179
-HARDWARE_SRC = ../ArduinoAddons/Arduino_0.xx/$(HARDWARE_VARIANT)/cores/arduino
179
+HARDWARE_DIR = ../ArduinoAddons/Arduino_0.xx
180 180
 endif
181 181
 endif
182
-
182
+HARDWARE_SRC = $(HARDWARE_DIR)/$(HARDWARE_VARIANT)/cores/arduino
183 183
 
184 184
 TARGET = $(notdir $(CURDIR))
185 185
 
@@ -190,11 +190,14 @@ TARGET = $(notdir $(CURDIR))
190 190
 VPATH = .
191 191
 VPATH += $(BUILD_DIR)
192 192
 VPATH += $(HARDWARE_SRC)
193
-VPATH += ../ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal
194
-VPATH += ../ArduinoAddons/Arduino_0.xx/libraries/SPI
193
+VPATH += $(HARDWARE_DIR)/libraries/LiquidCrystal
194
+VPATH += $(HARDWARE_DIR)/libraries/SPI
195 195
 ifeq ($(HARDWARE_VARIANT), arduino)
196 196
 HARDWARE_SUB_VARIANT ?= mega
197 197
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/arduino/variants/$(HARDWARE_SUB_VARIANT)
198
+else
199
+HARDWARE_SUB_VARIANT ?= standard
200
+VPATH += $(HARDWARE_DIR)/$(HARDWARE_VARIANT)/variants/$(HARDWARE_SUB_VARIANT)
198 201
 endif
199 202
 SRC = wiring.c \
200 203
 	wiring_analog.c wiring_digital.c \

+ 1
- 1
Marlin/Marlin.h View File

@@ -26,7 +26,7 @@
26 26
 #define  HardwareSerial_h // trick to disable the standard HWserial
27 27
 #endif
28 28
 
29
-#if (ARDUINO >= 100) && !defined(__AVR_ATmega644P__)
29
+#if (ARDUINO >= 100)
30 30
 # include "Arduino.h"
31 31
 #else
32 32
 # include "WProgram.h"

Loading…
Cancel
Save