Browse Source

Merge pull request #2127 from Wackerbarth/Kossel_Pro

Kossel Pro
Scott Lahteine 10 years ago
parent
commit
04a1622172
70 changed files with 12410 additions and 14 deletions
  1. 87
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/boards.txt
  2. 139
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/bootloaders/brainwave/BootloaderHID.hex
  3. 239
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/bootloaders/brainwave/Brainwave-646-LUFA.hex
  4. 247
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/bootloaders/brainwave/BrainwavePro-1286-LUFA.hex
  5. 215
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Arduino.h
  6. 236
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/CDC.cpp
  7. 26
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Client.h
  8. 520
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/HID.cpp
  9. 428
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/HardwareSerial.cpp
  10. 81
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/HardwareSerial.h
  11. 56
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/IPAddress.cpp
  12. 76
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/IPAddress.h
  13. 23
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Platform.h
  14. 263
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Print.cpp
  15. 78
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Print.h
  16. 40
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Printable.h
  17. 9
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Server.h
  18. 270
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Stream.cpp
  19. 96
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Stream.h
  20. 601
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Tone.cpp
  21. 195
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/USBAPI.h
  22. 670
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/USBCore.cpp
  23. 307
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/USBCore.h
  24. 62
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/USBDesc.h
  25. 88
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Udp.h
  26. 168
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/WCharacter.h
  27. 298
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/WInterrupts.c
  28. 60
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/WMath.cpp
  29. 645
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/WString.cpp
  30. 205
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/WString.h
  31. 515
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/binary.h
  32. 20
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/main.cpp
  33. 18
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/new.cpp
  34. 22
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/new.h
  35. 324
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/wiring.c
  36. 282
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/wiring_analog.c
  37. 178
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/wiring_digital.c
  38. 69
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/wiring_private.h
  39. 69
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/wiring_pulse.c
  40. 55
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/wiring_shift.c
  41. 106
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/firmwares/Brainwave.inf
  42. 310
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/LiquidCrystal/LiquidCrystal.cpp
  43. 106
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/LiquidCrystal/LiquidCrystal.h
  44. 37
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/LiquidCrystal/keywords.txt
  45. 66
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/SPI/SPI.cpp
  46. 70
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/SPI/SPI.h
  47. 36
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/SPI/keywords.txt
  48. 303
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/Wire.cpp
  49. 80
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/Wire.h
  50. 87
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino
  51. 39
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino
  52. 32
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/master_reader/master_reader.ino
  53. 31
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/master_writer/master_writer.ino
  54. 38
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino
  55. 32
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/slave_sender/slave_sender.ino
  56. 32
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/keywords.txt
  57. 8
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/library.properties
  58. 527
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/utility/twi.c
  59. 53
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/utility/twi.h
  60. 1
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/platform.local.txt
  61. 111
    1
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/platform.txt
  62. 281
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/variants/brainwave/pins_arduino.h
  63. 278
    0
      ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/variants/brainwavepro/pins_arduino.h
  64. 2
    2
      Marlin/Conditionals.h
  65. 1
    0
      Marlin/Marlin.h
  66. 4
    0
      Marlin/Marlin_main.cpp
  67. 11
    11
      Marlin/SanityCheck.h
  68. 1083
    0
      Marlin/example_configurations/delta/kossel_pro/Configuration.h
  69. 660
    0
      Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h
  70. 5
    0
      Marlin/example_configurations/delta/kossel_pro/readme.md

+ 87
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/boards.txt View File

@@ -1,4 +1,5 @@
1 1
 # See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
2
+# See: http://code.google.com/p/arduino/wiki/Platforms
2 3
 
3 4
 ##############################################################
4 5
 
@@ -70,3 +71,89 @@ sanguino.menu.cpu.atmega1284.bootloader.file=ATmegaBOOT_168_atmega1284p.hex
70 71
 sanguino.menu.cpu.atmega1284m=ATmega1284p 20MHz
71 72
 sanguino.menu.cpu.atmega1284m.bootloader.file=ATmegaBOOT_168_atmega1284p.hex
72 73
 sanguino.menu.cpu.atmega1284m.build.f_cpu=20000000L
74
+
75
+########################################
76
+## Brainwave
77
+########################################
78
+Brainwave.name=Brainwave
79
+
80
+Brainwave.bootloader.tool=avrdude
81
+Brainwave.bootloader.low_fuses=0xFF
82
+Brainwave.bootloader.high_fuses=0x99
83
+Brainwave.bootloader.extended_fuses=0xF0
84
+Brainwave.bootloader.unlock_bits=0x3F
85
+Brainwave.bootloader.lock_bits=0x02F
86
+Brainwave.bootloader.path=brainwave
87
+Brainwave.bootloader.file=Brainwave-646-LUFA.hex
88
+
89
+Brainwave.upload.tool=avrdude
90
+Brainwave.upload.protocol=avr109
91
+Brainwave.upload.maximum_size=61440
92
+Brainwave.upload.speed=115200
93
+Brainwave.upload.disable_flushing=true
94
+
95
+Brainwave.build.mcu=at90usb646
96
+Brainwave.build.f_cpu=16000000L
97
+Brainwave.build.core=brainwave
98
+Brainwave.build.dependency=true
99
+Brainwave.build.variant=brainwave
100
+Brainwave.build.vid=0x16D0
101
+Brainwave.build.pid=0x076B
102
+
103
+########################################
104
+## BrainwavePro
105
+########################################
106
+BrainwavePro.name=Brainwave Pro
107
+
108
+BrainwavePro.bootloader.tool=avrdude
109
+BrainwavePro.bootloader.low_fuses=0xFF
110
+BrainwavePro.bootloader.high_fuses=0x9B
111
+BrainwavePro.bootloader.extended_fuses=0xF0
112
+BrainwavePro.bootloader.unlock_bits=0x3F
113
+BrainwavePro.bootloader.lock_bits=0x02F
114
+BrainwavePro.bootloader.path=brainwave
115
+BrainwavePro.bootloader.file=BrainwavePro-1286-LUFA.hex
116
+
117
+BrainwavePro.upload.tool=avrdude
118
+BrainwavePro.upload.protocol=avr109
119
+BrainwavePro.upload.maximum_size=126976
120
+BrainwavePro.upload.speed=115200
121
+BrainwavePro.upload.disable_flushing=true
122
+
123
+BrainwavePro.build.mcu=at90usb1286
124
+BrainwavePro.build.f_cpu=16000000L
125
+BrainwavePro.build.core=brainwave
126
+BrainwavePro.build.dependency=true
127
+BrainwavePro.build.variant=brainwavepro
128
+BrainwavePro.build.vid=0x16D0
129
+BrainwavePro.build.pid=0x076B
130
+BrainwavePro.build.extra_flags=-DAT90USBxx_TEENSYPP_ASSIGNMENTS -DUSB_VID={build.vid} -DUSB_PID={build.pid}
131
+
132
+########################################
133
+## KosselPro -- BrainwavePro with HID boot
134
+########################################
135
+KosselPro.name=Kossel Pro (HID Bootloader)
136
+
137
+KosselPro.bootloader.tool=avrdude
138
+KosselPro.bootloader.low_fuses=0xFF
139
+KosselPro.bootloader.high_fuses=0x9B
140
+KosselPro.bootloader.extended_fuses=0xF0
141
+KosselPro.bootloader.unlock_bits=0x3F
142
+KosselPro.bootloader.lock_bits=0x02F
143
+KosselPro.bootloader.path=brainwave
144
+KosselPro.bootloader.file=BootloaderHID.hex
145
+
146
+KosselPro.upload.tool=hidloader
147
+KosselPro.upload.protocol=halfkay
148
+KosselPro.upload.maximum_size=126976
149
+KosselPro.upload.speed=115200
150
+KosselPro.upload.disable_flushing=true
151
+
152
+KosselPro.build.mcu=at90usb1286
153
+KosselPro.build.f_cpu=16000000L
154
+KosselPro.build.core=brainwave
155
+KosselPro.build.dependency=true
156
+KosselPro.build.variant=brainwavepro
157
+KosselPro.build.vid=0x16D0
158
+KosselPro.build.pid=0x076B
159
+KosselPro.build.extra_flags=-DAT90USBxx_TEENSYPP_ASSIGNMENTS -DUSB_VID={build.vid} -DUSB_PID={build.pid}

+ 139
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/bootloaders/brainwave/BootloaderHID.hex View File

@@ -0,0 +1,139 @@
1
+:020000021000EC
2
+:10F000004BC0000077C0000075C0000073C0000056
3
+:10F0100071C000006FC000006DC000006BC0000038
4
+:10F0200069C0000067C0000028C2000063C0000083
5
+:10F0300061C000005FC000005DC000005BC0000058
6
+:10F0400059C0000057C0000055C0000053C0000068
7
+:10F0500051C000004FC000004DC000004BC0000078
8
+:10F0600049C0000047C0000045C0000043C0000088
9
+:10F0700041C000003FC000003DC000003BC0000098
10
+:10F0800039C0000037C0000035C0000033C00000A8
11
+:10F0900031C000002FC0000011241FBECFEFD0E20E
12
+:10F0A000DEBFCDBF04B603FE0EC080915401909127
13
+:10F0B000550182349C4D39F410925501109254013F
14
+:10F0C000E0E0F0E0099511E0A0E0B1E0E8E2F8EF5F
15
+:10F0D00001E00BBF02C007900D92AA34B107D9F727
16
+:10F0E00021E0AAE4B1E001C01D92A435B207E1F726
17
+:10F0F00002D098C385CF84B7877F84BF88E10FB6DD
18
+:10F10000F89480936000109260000FBE81E085BF8C
19
+:10F1100082E085BF97D1789480910001882311F017
20
+:10F1200066D3FACF8091E00081608093E00082E4B2
21
+:10F130009CED90935501809354012CE088E190E080
22
+:10F140000FB6F894A895809360000FBE20936000DE
23
+:10F15000FFCF42E361EC81E002C1CF92DF92EF92F8
24
+:10F16000FF921F93CF93DF9380914C018F77813271
25
+:10F1700009F075C080914D01893009F070C080910F
26
+:10F18000E800877F8093E8008091E80082FFFCCF51
27
+:10F190009091F1008091F100492F582F60E070E0CC
28
+:10F1A000B62FA52F942F88274F3F5F4F19F4109249
29
+:10F1B00000013EC023E0FC01A0935B0020935700B8
30
+:10F1C000E89507B600FCFDCF20E030E011E040916B
31
+:10F1D000F2005091F300452B09F437C05091F10033
32
+:10F1E0004091F100C52FD42FA901440F551F6C0188
33
+:10F1F0007D01C40ED51EE11CF11C0E01F601E0924A
34
+:10F200005B0010935700E89511242F5F3F4F203883
35
+:10F210003105E9F625E0FC01A0935B00209357003F
36
+:10F22000E89507B600FCFDCF81E180935700E89593
37
+:10F230008091E8008B778093E800DF91CF911F9158
38
+:10F24000FF90EF90DF90CF909EC04091E8004B7709
39
+:10F250004093E8004091E80042FFFCCFBFCFDF9130
40
+:10F26000CF911F91FF90EF90DF90CF900895913054
41
+:10F2700049F0923061F0913279F489E090E023E135
42
+:10F2800031E00EC082E190E023E231E009C082E289
43
+:10F2900090E021E031E004C085E190E025E331E039
44
+:10F2A000FA01318320830895209152013091530156
45
+:10F2B0002617370748F06115710539F42091E800E9
46
+:10F2C0002E772093E80001C0B901FC0120E0611510
47
+:10F2D000710591F18EB38823E1F18530E1F18091E0
48
+:10F2E000E80083FD3AC08091E80082FF06C080916B
49
+:10F2F000E80082FF24C080E008958091E80080FF4C
50
+:10F30000E6CF8091F2009091F3006115710551F004
51
+:10F310008830910538F421912093F10061507109F2
52
+:10F320000196F3CF21E0089709F020E08091E800F2
53
+:10F330008E778093E800CBCF2111CCCFD8CF8EB37E
54
+:10F34000882339F0853039F08091E80083FFCFCFF2
55
+:10F3500004C082E0089583E0089581E008958F70ED
56
+:10F360008093E900EBEEF0E0808181608083EDEE38
57
+:10F37000F0E010826093EC0040838091EE00881FE3
58
+:10F380008827881F089580914C0187FD05C08091D2
59
+:10F39000E80080FF0DC010C08091E80082FD04C02D
60
+:10F3A0008EB38111F9CF08958091E8008B7707C063
61
+:10F3B0008EB38111ECCF08958091E8008E77809311
62
+:10F3C000E80008950F931F93CF93DF9349D050D057
63
+:10F3D000C8EDD0E088818F778883888180688883B2
64
+:10F3E00088818F7D8883E7EDF0E08081806880836D
65
+:10F3F00019BC1EBA10924A0100EE10E0F80180819B
66
+:10F400008B7F808388818160888342E060E080E038
67
+:10F41000A6DFE1EEF0E080818E7F8083E2EEF0E017
68
+:10F42000808181608083808188608083F801808111
69
+:10F430008E7F8083888180618883DF91CF911F9147
70
+:10F440000F910895E8EDF0E080818F7E8083E7EDF5
71
+:10F45000F0E080818160808381E080934B01B2CFB6
72
+:10F46000E8EDF0E080818C7F80831092E2000895C7
73
+:10F470001092DA001092E10008951F920F920FB6D9
74
+:10F480000F9211240BB60F922F933F934F935F93DC
75
+:10F490006F937F938F939F93AF93BF93EF93FF935C
76
+:10F4A0008091DA0080FF1BC08091D80080FF17C0D8
77
+:10F4B0008091DA008E7F8093DA008091D90080FFFE
78
+:10F4C0000BC084E189BD86E189BD09B400FEFDCF92
79
+:10F4D00081E08EBB8BD103C019BC1EBA87D180914D
80
+:10F4E000E10080FF17C08091E20080FF13C080918F
81
+:10F4F000E2008E7F8093E2008091E2008061809341
82
+:10F50000E2008091D80080628093D80019BC85E029
83
+:10F510008EBB6CD18091E10084FF2EC08091E2000F
84
+:10F5200084FF2AC084E189BD86E189BD09B400FE5B
85
+:10F53000FDCF8091D8008F7D8093D8008091E1002D
86
+:10F540008F7E8093E1008091E2008F7E8093E200C5
87
+:10F550008091E20081608093E20080914A018823DB
88
+:10F5600011F084E007C08091E30087FF02C083E0D0
89
+:10F5700001C081E08EBB3AD18091E10083FF21C0C0
90
+:10F580008091E20083FF1DC08091E100877F80931E
91
+:10F59000E10082E08EBB10924A018091E1008E7FF3
92
+:10F5A0008093E1008091E2008E7F8093E200809161
93
+:10F5B000E20080618093E20042E060E080E0CFDE24
94
+:10F5C00015D1FF91EF91BF91AF919F918F917F9155
95
+:10F5D0006F915F914F913F912F910F900BBE0F90C4
96
+:10F5E0000FBE0F901F9018951F93CF93DF9300D0FD
97
+:10F5F000CDB7DEB7ECE4F1E08091F100819381E0DA
98
+:10F60000E435F807C9F7A9DD8091E80083FFDAC087
99
+:10F6100090914C0180914D01853009F465C030F422
100
+:10F62000813059F168F0833041F1CCC0883009F461
101
+:10F630009CC0893009F4ABC0863009F0C3C075C0E6
102
+:10F64000903881F0923809F0BDC0809150018F70E0
103
+:10F650008093E9009091EB0095FB992790F9109227
104
+:10F66000E90001C090E08091E800877F8093E80086
105
+:10F670009093F1001092F10083C0292F2D7F09F0A3
106
+:10F68000A1C0923009F09EC090914E01911126C008
107
+:10F69000209150012F7009F495C02093E9009091BA
108
+:10F6A000EB0090FF1BC0833021F48091EB0080625F
109
+:10F6B00013C08091EB0080618093EB0081E090E0CB
110
+:10F6C000022E01C0880F0A94EAF78093EA00109294
111
+:10F6D000EA008091EB0088608093EB001092E900D3
112
+:10F6E0008091E800877F4FC091116CC010914E014E
113
+:10F6F0001F778091E3008078812B8093E3008091D5
114
+:10F70000E800877F8093E8003EDE8091E80080FF7C
115
+:10F71000FCCF8091E30080688093E300112311F017
116
+:10F7200083E001C082E08EBB4DC09058923008F05B
117
+:10F7300049C0AE014F5F5F4F6091500180914E0113
118
+:10F7400090914F0194DD009709F43CC02091E800AE
119
+:10F75000277F2093E800BC0189819A81A5DD8091F3
120
+:10F76000E8008B778093E8002DC0903859F58091A0
121
+:10F77000E800877F8093E80080914A018093F10040
122
+:10F780008091E8008E778093E800FDDD1BC0911129
123
+:10F7900019C090914E019230A8F48091E800877FC3
124
+:10F7A0008093E80090934A01EEDD80914A01811137
125
+:10F7B00004C08091E30087FF02C084E001C081E0C3
126
+:10F7C0008EBBC7DC8091E80083FF0AC08091E8000F
127
+:10F7D000877F8093E8008091EB0080628093EB004C
128
+:10F7E0000F900F90DF91CF911F9108950895CF93BF
129
+:10F7F0008EB38823A9F08091E9008F709091EC007E
130
+:10F8000090FF02C090E801C090E0C92FC82B109271
131
+:10F81000E9008091E80083FDE7DECF70C093E90046
132
+:08F82000CF910895F894FFCF89
133
+:10F8280001090222000101008032090400000103DD
134
+:10F8380000000009211101000122150007058103BC
135
+:10F848004000051201100100000008EB03672001C9
136
+:10F85800000000000106DCFF09FBA10109021500F8
137
+:0AF8680025FF75089602019102C009
138
+:040000031000F000F9
139
+:00000001FF

+ 239
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/bootloaders/brainwave/Brainwave-646-LUFA.hex View File

@@ -0,0 +1,239 @@
1
+:020000021000EC
2
+:10F000004BC0000064C0000062C0000060C000008F
3
+:10F010005EC000005CC000005AC0000058C0000084
4
+:10F0200056C0000054C000006FC4000050C0000073
5
+:10F030004EC000004CC000004AC0000048C00000A4
6
+:10F0400046C0000044C0000042C0000040C00000B4
7
+:10F050003EC000003CC000003AC0000038C00000C4
8
+:10F0600036C0000034C0000032C0000030C00000D4
9
+:10F070002EC000002CC000002AC0000028C00000E4
10
+:10F0800026C0000024C0000022C0000020C00000F4
11
+:10F090001EC000001CC0000011241FBECFEFD0E135
12
+:10F0A000DEBFCDBF11E0A0E0B1E0E2E2FEEF02C0C2
13
+:10F0B00005900D92AC38B107D9F711E0ACE8B1E09A
14
+:10F0C00001C01D92AD39B107E1F7FCD2A8C698CFB7
15
+:10F0D00084E08093E9000DC08091E8008B778093F5
16
+:10F0E000E80003C08EB3882359F08091E80082FFC6
17
+:10F0F000F9CF8091E80085FFEFCF8091F10008956E
18
+:10F1000080E0089593E09093E9009091E80095FDE8
19
+:10F110000DC09091E8009E779093E80003C09EB3E5
20
+:10F12000992331F09091E80090FFF9CF8093F1009E
21
+:10F13000089584B7877F84BF88E10FB6F8948093E1
22
+:10F140006000109260000FBE90E080E80FB6F89467
23
+:10F1500080936100909361000FBE81E085BF82E0E3
24
+:10F1600085BFBCC382E061EC42E03ED383E061E84E
25
+:10F1700042E13AD384E060E842E136C380919601EF
26
+:10F180008032B1F0813239F580919501813A19F5DB
27
+:10F190008091E800877F8093E80088E091E067E055
28
+:10F1A00070E07BD58091E8008B778093E80008952C
29
+:10F1B00080919501813279F48091E800877F809376
30
+:10F1C000E80088E091E067E070E0C2D58091E80057
31
+:10F1D0008E778093E80008952F923F924F925F922E
32
+:10F1E0006F927F929F92AF92BF92CF92DF92EF92F7
33
+:10F1F000FF920F931F93DF93CF930F92CDB7DEB79C
34
+:10F2000084E08093E9008091E80082FF48C2109278
35
+:10F210008C015EDF182F8C3409F4EEC1803509F4BF
36
+:10F22000EBC1843529F0853429F410920F01E4C133
37
+:10F230004FDFE2C1843711F484E448C0813611F411
38
+:10F2400089E503C28134F1F443DF382F330F20E026
39
+:10F2500079010027F7FC0095102FE0928F01F092C2
40
+:10F260009001009391011093920132DF90E0880F9A
41
+:10F27000991FAA2797FDA095BA2F8E299F29A02B09
42
+:10F28000B12BB2C1803711F483E5DFC1833559F466
43
+:10F2900000E011E0F80181918F0134DFF1E00730E7
44
+:10F2A0001F07C1F7D3C1863521F481E32BDF80E34B
45
+:10F2B000CCC1833731F482E825DF86E923DF8EE194
46
+:10F2C000C4C1823631F489E51DDF81E01BDF80E0B7
47
+:10F2D000BCC18536F9F480E090E0DC0133E025E044
48
+:10F2E000FC0130935700E89507B600FCFDCF209352
49
+:10F2F0005700E89507B600FCFDCF8F5F9E4FAF4FDC
50
+:10F30000BF4F8F3E40EF940741E0A40740E0B407B1
51
+:10F3100039F772C18C3651F4DBDE809599E0E1E07B
52
+:10F32000F0E0082E90935700E89566C1823719F4F3
53
+:10F33000E1E0F0E00EC0863419F4E0E0F0E009C04E
54
+:10F340008E3419F4E3E0F0E004C0813539F4E2E0F2
55
+:10F35000F0E089E080935700849177C1833471F4A1
56
+:10F3600000918F0110919001B3DE90E021E0F8014F
57
+:10F370000C0120935700E89511243EC1833679F49F
58
+:10F3800000918F01109190010160A2DE90E021E0D8
59
+:10F39000F8010C0120935700E89511241AC18D360D
60
+:10F3A00061F4E0918F01F091900185E08093570026
61
+:10F3B000E89507B600FCFDCF1FC1823419F08736EF
62
+:10F3C00009F0E9C085DEE82E83DE082F81DEB82E45
63
+:10F3D0008554823008F038C13E2D20E0202E3324A1
64
+:10F3E000222A332A173609F054C081E1809357004E
65
+:10F3F000E89510E001E048C0FB2DF63409F5E12F57
66
+:10F40000F0E080918F0190919001E82BF92B84918D
67
+:10F4100079DE112399F080918F0190919001A09154
68
+:10F420009101B09192010296A11DB11D80938F01AF
69
+:10F4300090939001A0939101B0939201102721C065
70
+:10F4400080918F0190919001A0919101B0919201D2
71
+:10F45000B695A79597958795CCD454DE80918F016A
72
+:10F4600090919001A0919101B09192010296A11DFD
73
+:10F47000B11D80938F0190939001A0939101B0935F
74
+:10F4800092010894210831082114310409F0B4CF05
75
+:10F49000DDC040908F01509090016090910170907C
76
+:10F4A00092012B2D263409F061C083E0F201809394
77
+:10F4B0005700E89507B600FCFDCF58C0FB2DF63489
78
+:10F4C00061F5222331F1E0908F01F090900100DE90
79
+:10F4D000D82ECC248A2D90E08C299D29F7010C018F
80
+:10F4E00090925700E895112480918F01909190019E
81
+:10F4F000A0919101B09192010296A11DB11D80933E
82
+:10F500008F0190939001A0939101B093920120E01C
83
+:10F5100029C0DEDDA82E21E025C0E0908F01F0900B
84
+:10F520009001009191011091920116950795F79421
85
+:10F53000E7942983CDDD682FC70163D480918F01C3
86
+:10F5400090919001A0919101B09192010296A11D1C
87
+:10F55000B11D80938F0190939001A0939101B0937E
88
+:10F560009201298108942108310804C0AA2420E0CE
89
+:10F57000992493942114310409F0A0CFFB2DF63483
90
+:10F5800009F03AC085E0F20180935700E89507B68C
91
+:10F5900000FCFDCF31C0823551F4E0918F01F09134
92
+:10F5A000900105911491812FADDD802F4EC08434E0
93
+:10F5B00029F5E0908F01F090900100919101109158
94
+:10F5C000920116950795F794E79482DD682FC7019D
95
+:10F5D00018D480918F0190919001A0919101B091E8
96
+:10F5E00092010296A11DB11D80938F01909390010D
97
+:10F5F000A0939101B09392018DE027C0843611F55C
98
+:10F6000080918F0190919001A0919101B091920110
99
+:10F61000B695A79597958795ECD374DD80918F016A
100
+:10F6200090919001A0919101B09192010296A11D3B
101
+:10F63000B11D80938F0190939001A0939101B0939D
102
+:10F64000920104C08B3111F08FE35CDD83E0809385
103
+:10F65000E9009091E8008091E8008E778093E800BF
104
+:10F6600095FF04C010C08EB38823C9F08091E800D4
105
+:10F6700080FFF9CF8091E8008E778093E80003C087
106
+:10F680008EB3882361F08091E80080FFF9CF84E099
107
+:10F690008093E9008091E8008B778093E8000F90D9
108
+:10F6A000CF91DF911F910F91FF90EF90DF90CF905E
109
+:10F6B000BF90AF909F907F906F905F904F903F90E2
110
+:10F6C0002F900895EF92FF920F931F93DF93CF93A4
111
+:10F6D0000F92CDB7DEB784B714BE909160009861E9
112
+:10F6E000909360001092600010928C0190E0FC01F9
113
+:10F6F000E270F07081FD0BC0859194912FEF8F3FE8
114
+:10F70000920729F0E0918D01F0918E01099511DDAC
115
+:10F710006F9A779A789481E010E000E0E0E0F0E002
116
+:10F72000E590F49025C0898357DD51D30F5F89811F
117
+:10F73000002311F4180F779A011709F477981F3FE7
118
+:10F7400059F0112351F4813041F080918C018F5F89
119
+:10F7500080938C0181E001C08FEF90918C019530F6
120
+:10F7600038F09FEFE9169FEFF90611F010920F01A4
121
+:10F7700090910F019923B9F68091E0008160809308
122
+:10F78000E0002CE088E190E00FB6F894A895809313
123
+:10F7900060000FBE20936000FFCF923049F093309D
124
+:10F7A00061F09130C1F020E030E080E090E017C0DF
125
+:10F7B0002EE330E082E291E012C0882331F4209100
126
+:10F7C000600130E080E691E00AC02091640130E001
127
+:10F7D00084E691E004C022E130E080E191E0FA01AA
128
+:10F7E00091838083C90108958093E900EBEEF0E0F6
129
+:10F7F000808181608083EDEEF0E010826093EC0008
130
+:10F8000040838091EE00881F8827881F089580918B
131
+:10F81000950187FF11C003C08EB38823B1F080919A
132
+:10F82000E80082FFF9CF8091E8008B778093E800B1
133
+:10F8300008958EB3882349F08091E80080FFF9CFC6
134
+:10F840008091E8008E778093E800089550D057D0DB
135
+:10F850008091D800982F9F779093D80080688093EC
136
+:10F86000D80088E189BD89B5826089BD09B400FEF0
137
+:10F87000FDCF8091D8008F7D8093D8008091D700F4
138
+:10F8800080688093D7001EBA109293018091E000A7
139
+:10F890008B7F8093E0008091D80081608093D800B6
140
+:10F8A00080E060E042E0A0DF8091E1008E7F809305
141
+:10F8B000E1008091E20081608093E2008091E200AB
142
+:10F8C00088608093E2008091E0008E7F8093E0006A
143
+:10F8D0008091D80080618093D8000895E7EDF0E032
144
+:10F8E00080818160808381E080939401AFCFE8EDD7
145
+:10F8F000F0E080818C7F80831092E2000895109266
146
+:10F90000DA001092E10008951F920F920FB60F9245
147
+:10F9100011242F933F934F935F936F937F938F9314
148
+:10F920009F93AF93BF93EF93FF938091DA0080FF93
149
+:10F9300013C08091D80080FF0FC08091DA008E7FC5
150
+:10F940008093DA008091D90080FF04C081E08EBBF3
151
+:10F95000A3D102C01EBAA0D18091E10080FF1CC0DB
152
+:10F960008091E20080FF18C08091E1008E7F80933B
153
+:10F97000E1008091E2008E7F8093E2008091E200BE
154
+:10F9800080618093E2008091D80080628093D800EB
155
+:10F9900019BC85E08EBB80D18091E10084FF2DC031
156
+:10F9A0008091E20084FF29C088E189BD89B5826029
157
+:10F9B00089BD09B400FEFDCF8091D8008F7D809372
158
+:10F9C000D8008091E1008F7E8093E1008091E20079
159
+:10F9D0008F7E8093E2008091E20081608093E2005C
160
+:10F9E00080919301882321F48091E30087FF02C076
161
+:10F9F00084E001C081E08EBB4FD18091E10083FFA4
162
+:10FA000021C08091E20083FF1DC08091E100877FCB
163
+:10FA10008093E10082E08EBB109293018091E1001F
164
+:10FA20008E7F8093E1008091E2008E7F8093E200E0
165
+:10FA30008091E20080618093E20080E060E042E03B
166
+:10FA4000D3DE2AD18091E10082FF0AC08091E200DA
167
+:10FA500082FF06C08091E1008B7F8093E1001CD182
168
+:10FA6000FF91EF91BF91AF919F918F917F916F9196
169
+:10FA70005F914F913F912F910F900FBE0F901F906C
170
+:10FA800018950F931F93DF93CF9300D0CDB7DEB7B8
171
+:10FA9000E5E9F1E08091F100819381E0ED39F8072B
172
+:10FAA000C9F78091950190919601953009F46BC04A
173
+:10FAB000963040F4913061F1913070F0933009F05C
174
+:10FAC000D5C026C0983009F4A3C0993009F4B2C05B
175
+:10FAD000963009F0CBC07CC0803809F4C8C08238A9
176
+:10FAE00009F0C4C08091990187708093E9009091DA
177
+:10FAF000EB001092E9008091E800877F8093E80096
178
+:10FB000081E095FF80E08093F1001092F1008BC0BE
179
+:10FB1000882319F0823009F0A9C08F71823009F072
180
+:10FB2000A6C080919701882341F520919901277003
181
+:10FB300009F49DC02093E9008091EB0080FF1DC077
182
+:10FB400080919601833021F48091EB00806213C094
183
+:10FB50008091EB0080618093EB0081E090E002C037
184
+:10FB6000880F991F2A95E2F78093EA001092EA0025
185
+:10FB70008091EB0088608093EB001092E900809107
186
+:10FB8000E800877F53C0882309F070C01091970167
187
+:10FB90001F770FB7F8948091E800877F8093E80083
188
+:10FBA00036DE8091E80080FFFCCF112311F083E066
189
+:10FBB00001C082E08EBB8091E3008078812B80932E
190
+:10FBC000E3008091E30080688093E3000FBF4FC0A3
191
+:10FBD0008058823008F04AC0809197019091980136
192
+:10FBE00060919901AE014F5F5F4FD7DDBC01009777
193
+:10FBF00009F43DC08091E800877F8093E800898107
194
+:10FC00009A814BD08091E8008B778093E8002FC0D9
195
+:10FC1000803861F58091E800877F8093E8008091CB
196
+:10FC200093018093F1008091E8008E778093E80043
197
+:10FC3000EEDD1DC08823D1F4909197019230B8F485
198
+:10FC40008091E800877F8093E80090939301DFDD47
199
+:10FC500080919301882321F48091E30087FF02C003
200
+:10FC600084E001C081E08EBB7DDA01C087DA80913B
201
+:10FC7000E80083FF0AC08091EB0080628093EB0074
202
+:10FC80008091E800877F8093E8000F900F90CF91DC
203
+:10FC9000DF911F910F9108950895282F392FF901B1
204
+:10FCA00080919B0190919C018617970718F4BC01E5
205
+:10FCB00020E035C061157105D9F78091E8008E7795
206
+:10FCC0008093E800F5CF8EB38823F1F18530C1F140
207
+:10FCD0008091E80083FD36C08091E80082FD2AC053
208
+:10FCE0008091E80080FF1BC08091F2009091F300AA
209
+:10FCF00006C021912093F10061507040019661157A
210
+:10FD0000710519F088309105A0F321E08830910544
211
+:10FD100009F020E08091E8008E778093E80061157B
212
+:10FD2000710589F6222379F605C08EB3882361F028
213
+:10FD3000853061F08091E80082FFF7CF80E0089580
214
+:10FD400083E0089581E0089582E0089583E00895B6
215
+:10FD50006115710529F51FC02EB32223A1F12530AD
216
+:10FD600071F12091E80023FD2CC02091E80022FFD2
217
+:10FD7000F3CFE82FF92F07C08091F1008193CF01D5
218
+:10FD80006150704041F0CF012091F2003091F300BA
219
+:10FD90002115310589F72091E8002B772093E800A1
220
+:10FDA00061157105C9F605C08EB3882361F08530F1
221
+:10FDB00061F08091E80080FFF7CF80E0089583E054
222
+:10FDC000089581E0089582E0089583E008951F93E7
223
+:10FDD0008EB3882361F01091E90017701092E9004A
224
+:10FDE0008091E80083FF01C04CDE1093E9001F9171
225
+:10FDF0000895F999FECF92BD81BDF89A992780B5F3
226
+:10FE00000895262FF999FECF1FBA92BD81BD20BD5E
227
+:10FE10000FB6F894FA9AF99A0FBE01960895F894DD
228
+:02FE2000FFCF12
229
+:10FE22004C554641434443000000000000000801D5
230
+:10FE320012011001020000089A23010001000001D2
231
+:10FE4200000109023E0002010080320904000001A3
232
+:10FE52000202010005240010010424020405240604
233
+:10FE620000010705820308000209040100020A00DA
234
+:10FE720000000705040210000007058302100000BD
235
+:10FE820004030904260341005600520020004300E7
236
+:10FE920044004300200042006F006F0074006C00B9
237
+:0CFEA2006F006100640065007200000049
238
+:040000031000F000F9
239
+:00000001FF

+ 247
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/bootloaders/brainwave/BrainwavePro-1286-LUFA.hex View File

@@ -0,0 +1,247 @@
1
+:020000021000EC
2
+:10F000004BC0000066C0000064C0000062C0000089
3
+:10F0100060C000005EC000005CC000005AC000007C
4
+:10F0200058C0000056C00000ACC4000052C0000030
5
+:10F0300050C000004EC000004CC000004AC000009C
6
+:10F0400048C0000046C0000044C0000042C00000AC
7
+:10F0500040C000003EC000003CC000003AC00000BC
8
+:10F0600038C0000036C0000034C0000032C00000CC
9
+:10F0700030C000002EC000002CC000002AC00000DC
10
+:10F0800028C0000026C0000024C0000022C00000EC
11
+:10F0900020C000001EC0000011241FBECFEFD0E230
12
+:10F0A000DEBFCDBF11E0A0E0B1E0E4EAFEEF01E099
13
+:10F0B0000BBF02C007900D92AC38B107D9F711E031
14
+:10F0C000ACE8B1E001C01D92AD39B107E1F72FD333
15
+:10F0D000E7C696CF84E08093E9000DC08091E800F8
16
+:10F0E0008B778093E80003C08EB3882359F080911A
17
+:10F0F000E80082FFF9CF8091E80085FFEFCF809193
18
+:10F10000F100089580E0089593E09093E9009091D4
19
+:10F11000E80095FD0DC09091E8009E779093E8007F
20
+:10F1200003C09EB3992331F09091E80090FFF9CF8E
21
+:10F130008093F100089584B7877F84BF88E10FB67C
22
+:10F14000F89480936000109260000FBE90E080E819
23
+:10F150000FB6F89480936100909361000FBE81E038
24
+:10F1600085BF82E085BFF7C382E061EC42E079D3DE
25
+:10F1700083E061E842E175D384E060E842E171C375
26
+:10F18000809196018032B1F0813239F580919501FC
27
+:10F19000813A19F58091E800877F8093E80088E044
28
+:10F1A00091E067E070E0BAD58091E8008B778093BA
29
+:10F1B000E800089580919501813279F48091E8000A
30
+:10F1C000877F8093E80088E091E067E070E001D6F7
31
+:10F1D0008091E8008E778093E80008952F923F9207
32
+:10F1E0005F926F927F928F929F92AF92BF92CF92D7
33
+:10F1F000DF92EF92FF920F931F93DF93CF930F92C3
34
+:10F20000CDB7DEB784E08093E9008091E80082FF0B
35
+:10F210007BC210928C015EDF182F8C3409F421C25E
36
+:10F22000803509F41EC2843529F0853429F4109202
37
+:10F230000F0117C24FDF15C2843711F484E448C0B0
38
+:10F24000813611F489E536C28134F1F443DF382F79
39
+:10F25000330F20E079010027F7FC0095102FE09292
40
+:10F260008F01F0929001009391011093920132DF8F
41
+:10F2700090E0880F991FAA2797FDA095BA2F8E2995
42
+:10F280009F29A02BB12BE5C1803711F483E512C271
43
+:10F29000833559F400E011E0D8018D918D0134DF00
44
+:10F2A000B1E007301B07C1F706C2863521F481E3C0
45
+:10F2B0002BDF80E3FFC1833731F482E825DF87E964
46
+:10F2C00023DF8EE1F7C1823631F489E51DDF81E06D
47
+:10F2D0001BDF80E0EFC1853621F580E090E0DC01A6
48
+:10F2E00033E025E0FC01A0935B0030935700E895E4
49
+:10F2F00007B600FCFDCFFC01A0935B0020935700F4
50
+:10F30000E89507B600FCFDCF8F5F9E4FAF4FBF4F14
51
+:10F310008F3EE0EF9E07E1E0AE07E0E0BE0711F7A9
52
+:10F32000A0C18C3651F4D6DE809599E0E1E0F0E0A2
53
+:10F33000082E90935700E89594C1823719F4E1E0C4
54
+:10F34000F0E00EC0863419F4E0E0F0E009C08E343D
55
+:10F3500019F4E3E0F0E004C0813539F4E2E0F0E0D4
56
+:10F3600089E0809357008491A5C18334A1F4E09093
57
+:10F370008F01F09090010091910110919201AADE0D
58
+:10F3800090E021E00C01F70100935B00209357000F
59
+:10F39000E895112466C18336E1F4E0908F01F09086
60
+:10F3A0009001009191011091920181E090E0A0E024
61
+:10F3B000B0E0E82AF92A0A2B1B2B8CDE90E021E032
62
+:10F3C0000C01F70100935B0020935700E89511248E
63
+:10F3D00035C18D3699F480918F0190919001A09163
64
+:10F3E0009101B091920125E0FC01A0935B00209374
65
+:10F3F0005700E89507B600FCFDCF33C1823419F001
66
+:10F40000873609F0F7C066DEE82E64DE082F62DE7C
67
+:10F41000982E8554823008F04CC13E2D20E0202EDD
68
+:10F420003324222A332A173609F058C081E1809309
69
+:10F430005700E89510E001E04CC020918F01309119
70
+:10F4400090014091910150919201992D963419F5B6
71
+:10F45000812F90E0A0E0B0E0822B932BA42BB52B62
72
+:10F46000ABBFFC01879150DE112399F080918F0191
73
+:10F4700090919001A0919101B09192010296A11DED
74
+:10F48000B11D80938F0190939001A0939101B0934F
75
+:10F49000920110271BC0DA01C901B695A79597956F
76
+:10F4A0008795E8D431DE80918F0190919001A091F1
77
+:10F4B0009101B09192010296A11DB11D80938F011F
78
+:10F4C00090939001A0939101B09392010894210828
79
+:10F4D00031082114310409F0B0CFEDC0A0908F01A4
80
+:10F4E000B0909001C0909101D0909201A92DA634C6
81
+:10F4F00009F069C083E0F501C0925B00809357007A
82
+:10F50000E89507B600FCFDCF5EC0B92DB63491F585
83
+:10F51000222361F1E0908F01F09090010091910120
84
+:10F5200010919201D7DD782E6624282D30E026290F
85
+:10F5300037290901F70100935B0050925700E895C5
86
+:10F54000112480918F0190919001A0919101B0912F
87
+:10F5500092010296A11DB11D80938F01909390019D
88
+:10F56000A0939101B093920120E029C0B3DD882ED1
89
+:10F5700021E025C0E0908F01F09090010091910171
90
+:10F580001091920116950795F794E7942983A2DDCF
91
+:10F59000682FC70177D480918F0190919001A0913D
92
+:10F5A0009101B09192010296A11DB11D80938F012E
93
+:10F5B00090939001A0939101B093920129810894B6
94
+:10F5C0002108310804C0882420E0552453942114D4
95
+:10F5D000310409F09ACFE92DE63409F042C085E004
96
+:10F5E000F501C0925B0080935700E89507B600FCD8
97
+:10F5F000FDCF37C0823581F480918F0190919001C9
98
+:10F60000A0919101B0919201ABBFFC0107911691BD
99
+:10F61000812F7ADD802F4EC0843429F5E0908F0150
100
+:10F62000F09090010091910110919201169507952B
101
+:10F63000F794E7944FDD682FC70124D480918F01A0
102
+:10F6400090919001A0919101B09192010296A11D1B
103
+:10F65000B11D80938F0190939001A0939101B0937D
104
+:10F6600092018DE027C0843611F580918F01909131
105
+:10F670009001A0919101B0919201B695A7959795AF
106
+:10F680008795F8D341DD80918F0190919001A091F1
107
+:10F690009101B09192010296A11DB11D80938F013D
108
+:10F6A00090939001A0939101B093920104C08B318B
109
+:10F6B00011F08FE329DD83E08093E9009091E80069
110
+:10F6C0008091E8008E778093E80095FF04C010C019
111
+:10F6D0008EB38823C9F08091E80080FFF9CF809134
112
+:10F6E000E8008E778093E80003C08EB3882361F032
113
+:10F6F0008091E80080FFF9CF84E08093E900809159
114
+:10F70000E8008B778093E8000F90CF91DF911F91F5
115
+:10F710000F91FF90EF90DF90CF90BF90AF909F90B0
116
+:10F720008F907F906F905F903F902F900895EF9211
117
+:10F73000FF920F931F93DF93CF930F92CDB7DEB756
118
+:10F7400084B714BE9091600098619093600010920D
119
+:10F75000600010928C0190E0FC01E270F07081FD7D
120
+:10F760000BC0859194912FEF8F3F920729F0E09184
121
+:10F770008D01F0918E010995209A289A6F9A779AB7
122
+:10F780006D9A759A3B9A439AD6DC6F9A779A7894D9
123
+:10F7900081E010E000E0E0E0F0E0E590F49025C0CA
124
+:10F7A00089831CDD55D30F5F8981002311F4180F65
125
+:10F7B000779A011709F477981F3F59F0112351F4F4
126
+:10F7C000813041F080918C018F5F80938C0181E0CA
127
+:10F7D00001C08FEF90918C01923338F09FEFE916C2
128
+:10F7E0009FEFF90611F010920F0190910F019923EC
129
+:10F7F000B9F68091E00081608093E0002CE088E120
130
+:10F8000090E00FB6F894A895809360000FBE209307
131
+:10F810006000FFCF923049F0933061F09130C1F039
132
+:10F8200020E030E080E090E017C02EE330E082E29C
133
+:10F8300091E012C0882331F42091600130E080E62D
134
+:10F8400091E00AC02091640130E084E691E004C0B8
135
+:10F8500022E130E080E191E0FA0191838083C901E7
136
+:10F8600008958093E900EBEEF0E080818160808371
137
+:10F87000EDEEF0E010826093EC0040838091EE00AA
138
+:10F88000881F8827881F08958091950187FF11C0E0
139
+:10F8900003C08EB38823B1F08091E80082FFF9CFD6
140
+:10F8A0008091E8008B778093E80008958EB38823D9
141
+:10F8B00049F08091E80080FFF9CF8091E8008E77D1
142
+:10F8C0008093E800089550D057D08091D800982FA9
143
+:10F8D0009F779093D80080688093D80084E189BD99
144
+:10F8E00089B5826089BD09B400FEFDCF8091D80042
145
+:10F8F0008F7D8093D8008091D70080688093D70057
146
+:10F900001EBA109293018091E0008B7F8093E000FB
147
+:10F910008091D80081608093D80080E060E042E070
148
+:10F92000A0DF8091E1008E7F8093E1008091E20072
149
+:10F9300081608093E2008091E20088608093E20021
150
+:10F940008091E0008E7F8093E0008091D8008061FC
151
+:10F950008093D8000895E7EDF0E080818160808396
152
+:10F9600081E080939401AFCFE8EDF0E080818C7F5F
153
+:10F9700080831092E20008951092DA001092E10064
154
+:10F9800008951F920F920FB60F920BB60F9211248B
155
+:10F990002F933F934F935F936F937F938F939F9397
156
+:10F9A000AF93BF93EF93FF938091DA0080FF13C072
157
+:10F9B0008091D80080FF0FC08091DA008E7F809305
158
+:10F9C000DA008091D90080FF04C081E08EBBA5D110
159
+:10F9D00002C01EBAA2D18091E10080FF1CC08091BC
160
+:10F9E000E20080FF18C08091E1008E7F8093E100EB
161
+:10F9F0008091E2008E7F8093E2008091E20080613E
162
+:10FA00008093E2008091D80080628093D80019BC76
163
+:10FA100085E08EBB82D18091E10084FF2DC0809172
164
+:10FA2000E20084FF29C084E189BD89B5826089BD77
165
+:10FA300009B400FEFDCF8091D8008F7D8093D8005F
166
+:10FA40008091E1008F7E8093E1008091E2008F7EC3
167
+:10FA50008093E2008091E20081608093E2008091D7
168
+:10FA60009301882321F48091E30087FF02C084E0A2
169
+:10FA700001C081E08EBB51D18091E10083FF21C0A4
170
+:10FA80008091E20083FF1DC08091E100877F809319
171
+:10FA9000E10082E08EBB109293018091E1008E7FA5
172
+:10FAA0008093E1008091E2008E7F8093E20080915C
173
+:10FAB000E20080618093E20080E060E042E0D1DE1D
174
+:10FAC0002CD18091E10082FF0AC08091E20082FF88
175
+:10FAD00006C08091E1008B7F8093E1001ED1FF91F1
176
+:10FAE000EF91BF91AF919F918F917F916F915F91B6
177
+:10FAF0004F913F912F910F900BBE0F900FBE0F9023
178
+:10FB00001F9018950F931F93DF93CF9300D0CDB71D
179
+:10FB1000DEB7E5E9F1E08091F100819381E0ED3914
180
+:10FB2000F807C9F78091950190919601953009F4F5
181
+:10FB30006BC0963040F4913061F1913070F09330A9
182
+:10FB400009F0D5C026C0983009F4A3C0993009F453
183
+:10FB5000B2C0963009F0CBC07CC0803809F4C8C070
184
+:10FB6000823809F0C4C08091990187708093E900C0
185
+:10FB70009091EB001092E9008091E800877F8093DC
186
+:10FB8000E80081E095FF80E08093F1001092F100A1
187
+:10FB90008BC0882319F0823009F0A9C08F718230A0
188
+:10FBA00009F0A6C080919701882341F52091990121
189
+:10FBB000277009F49DC02093E9008091EB0080FF3D
190
+:10FBC0001DC080919601833021F48091EB0080620A
191
+:10FBD00013C08091EB0080618093EB0081E090E0A6
192
+:10FBE00002C0880F991F2A95E2F78093EA001092CD
193
+:10FBF000EA008091EB0088608093EB001092E900AE
194
+:10FC00008091E800877F53C0882309F070C010916D
195
+:10FC100097011F770FB7F8948091E800877F809352
196
+:10FC2000E80032DE8091E80080FFFCCF112311F064
197
+:10FC300083E001C082E08EBB8091E3008078812B5D
198
+:10FC40008093E3008091E30080688093E3000FBF1E
199
+:10FC50004FC08058823008F04AC08091970190913F
200
+:10FC6000980160919901AE014F5F5F4FD3DDBC01F8
201
+:10FC7000009709F43DC08091E800877F8093E800F9
202
+:10FC800089819A814BD08091E8008B778093E8003E
203
+:10FC90002FC0803861F58091E800877F8093E8006D
204
+:10FCA000809193018093F1008091E8008E7780939A
205
+:10FCB000E800EADD1DC08823D1F4909197019230CD
206
+:10FCC000B8F48091E800877F8093E80090939301D7
207
+:10FCD000DBDD80919301882321F48091E30087FF8D
208
+:10FCE00002C084E001C081E08EBB3EDA01C048DA88
209
+:10FCF0008091E80083FF0AC08091EB0080628093CE
210
+:10FD0000EB008091E800877F8093E8000F900F90D0
211
+:10FD1000CF91DF911F910F9108950895282F392FCA
212
+:10FD2000F90180919B0190919C018617970718F427
213
+:10FD3000BC0120E035C061157105D9F78091E8005C
214
+:10FD40008E778093E800F5CF8EB38823F1F185306C
215
+:10FD5000C1F18091E80083FD36C08091E80082FD0A
216
+:10FD60002AC08091E80080FF1BC08091F200909132
217
+:10FD7000F30006C021912093F1006150704001967C
218
+:10FD80006115710519F088309105A0F321E08830E4
219
+:10FD9000910509F020E08091E8008E778093E800DB
220
+:10FDA0006115710589F6222379F605C08EB3882383
221
+:10FDB00061F0853061F08091E80082FFF7CF80E04C
222
+:10FDC000089583E0089581E0089582E0089583E036
223
+:10FDD00008956115710529F51FC02EB32223A1F1E5
224
+:10FDE000253071F12091E80023FD2CC02091E8001E
225
+:10FDF00022FFF3CFE82FF92F07C08091F100819304
226
+:10FE0000CF016150704041F0CF012091F20030915C
227
+:10FE1000F3002115310589F72091E8002B77209315
228
+:10FE2000E80061157105C9F605C08EB3882361F03D
229
+:10FE3000853061F08091E80080FFF7CF80E0089581
230
+:10FE400083E0089581E0089582E0089583E00895B5
231
+:10FE50001F938EB3882361F01091E9001770109200
232
+:10FE6000E9008091E80083FF01C04CDE1093E900B7
233
+:10FE70001F910895F999FECF92BD81BDF89A9927F7
234
+:10FE800080B50895262FF999FECF1FBA92BD81BD86
235
+:10FE900020BD0FB6F894FA9AF99A0FBE019608950C
236
+:04FEA000F894FFCF04
237
+:10FEA4004C55464143444300000000000000080153
238
+:10FEB40012011001020000089A2301000100000150
239
+:10FEC400000109023E000201008032090400000121
240
+:10FED4000202010005240010010424020405240682
241
+:10FEE40000010705820308000209040100020A0058
242
+:10FEF400000007050402100000070583021000003B
243
+:10FF04000403090426034100560052002000430064
244
+:10FF140044004300200042006F006F0074006C0036
245
+:0CFF24006F0061006400650072000000C6
246
+:040000031000F000F9
247
+:00000001FF

+ 215
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/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__) 
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

+ 236
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/CDC.cpp View File

@@ -0,0 +1,236 @@
1
+/* Copyright (c) 2011, Peter Barrett  
2
+**  
3
+** Permission to use, copy, modify, and/or distribute this software for  
4
+** any purpose with or without fee is hereby granted, provided that the  
5
+** above copyright notice and this permission notice appear in all copies.  
6
+** 
7
+** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL  
8
+** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED  
9
+** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR  
10
+** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES  
11
+** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,  
12
+** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  
13
+** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS  
14
+** SOFTWARE.  
15
+*/
16
+
17
+#include "Platform.h"
18
+#include "USBAPI.h"
19
+#include <avr/wdt.h>
20
+
21
+#if defined(USBCON)
22
+#ifdef CDC_ENABLED
23
+
24
+#if (RAMEND < 1000)
25
+#define SERIAL_BUFFER_SIZE 16
26
+#else
27
+// Use a 128 byte buffer like Arduinos of old for maximum
28
+// compatibility. -Hubbe 20120929
29
+#define SERIAL_BUFFER_SIZE 128
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 c = USB_Recv(CDC_RX); 
145
+	int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
146
+	
147
+	// if we should be storing the received character into the location
148
+	// just before the tail (meaning that the head would advance to the
149
+	// current location of the tail), we're about to overflow the buffer
150
+	// and so we don't write the character or advance the head.
151
+	if (i != buffer->tail) {
152
+		buffer->buffer[buffer->head] = c;
153
+		buffer->head = i;
154
+	}
155
+}
156
+
157
+int Serial_::available(void)
158
+{
159
+	ring_buffer *buffer = &cdc_rx_buffer;
160
+	return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE;
161
+}
162
+
163
+int Serial_::peek(void)
164
+{
165
+	ring_buffer *buffer = &cdc_rx_buffer;
166
+	if (buffer->head == buffer->tail) {
167
+		return -1;
168
+	} else {
169
+		return buffer->buffer[buffer->tail];
170
+	}
171
+}
172
+
173
+int Serial_::read(void)
174
+{
175
+	ring_buffer *buffer = &cdc_rx_buffer;
176
+	// if the head isn't ahead of the tail, we don't have any characters
177
+	if (buffer->head == buffer->tail) {
178
+		return -1;
179
+	} else {
180
+		unsigned char c = buffer->buffer[buffer->tail];
181
+		buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
182
+		return c;
183
+	}	
184
+}
185
+
186
+void Serial_::flush(void)
187
+{
188
+	USB_Flush(CDC_TX);
189
+}
190
+
191
+size_t Serial_::write(uint8_t c)
192
+{
193
+	/* only try to send bytes if the high-level CDC connection itself 
194
+	 is open (not just the pipe) - the OS should set lineState when the port
195
+	 is opened and clear lineState when the port is closed.
196
+	 bytes sent before the user opens the connection or after
197
+	 the connection is closed are lost - just like with a UART. */
198
+	
199
+	// TODO - ZE - check behavior on different OSes and test what happens if an
200
+	// open connection isn't broken cleanly (cable is yanked out, host dies
201
+	// or locks up, or host virtual serial port hangs)
202
+
203
+  /* Actually, let's ignore the line state for now since repetierHost
204
+     doens't work if we don't ignore it. -Hubbe 20120929 */
205
+  /* if (_usbLineInfo.lineState > 0)	*/ {
206
+		int r = USB_Send(CDC_TX,&c,1);
207
+		if (r > 0) {
208
+			return r;
209
+		} else {
210
+			setWriteError();
211
+			return 0;
212
+		}
213
+	}
214
+	setWriteError();
215
+	return 0;
216
+}
217
+
218
+// This operator is a convenient way for a sketch to check whether the
219
+// port has actually been configured and opened by the host (as opposed
220
+// to just being connected to the host).  It can be used, for example, in 
221
+// setup() before printing to ensure that an application on the host is
222
+// actually ready to receive and display the data.
223
+// We add a short delay before returning to fix a bug observed by Federico
224
+// where the port is configured (lineState != 0) but not quite opened.
225
+Serial_::operator bool() {
226
+	bool result = false;
227
+	if (_usbLineInfo.lineState > 0) 
228
+		result = true;
229
+	delay(10);
230
+	return result;
231
+}
232
+
233
+Serial_ Serial;
234
+
235
+#endif
236
+#endif /* if defined(USBCON) */

+ 26
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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) */

+ 428
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/HardwareSerial.cpp View File

@@ -0,0 +1,428 @@
1
+/*
2
+  HardwareSerial.cpp - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
4
+
5
+  This library is free software; you can redistribute it and/or
6
+  modify it under the terms of the GNU Lesser General Public
7
+  License as published by the Free Software Foundation; either
8
+  version 2.1 of the License, or (at your option) any later version.
9
+
10
+  This library is distributed in the hope that it will be useful,
11
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+  Lesser General Public License for more details.
14
+
15
+  You should have received a copy of the GNU Lesser General Public
16
+  License along with this library; if not, write to the Free Software
17
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+  
19
+  Modified 23 November 2006 by David A. Mellis
20
+  Modified 28 September 2010 by Mark Sproul
21
+*/
22
+
23
+#include <stdlib.h>
24
+#include <stdio.h>
25
+#include <string.h>
26
+#include <inttypes.h>
27
+#include "Arduino.h"
28
+#include "wiring_private.h"
29
+
30
+// this next line disables the entire HardwareSerial.cpp, 
31
+// this is so I can support Attiny series and any other chip without a uart
32
+#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
33
+
34
+#include "HardwareSerial.h"
35
+
36
+// Define constants and variables for buffering incoming serial data.  We're
37
+// using a ring buffer (I think), in which head is the index of the location
38
+// to which to write the next incoming character and tail is the index of the
39
+// location from which to read.
40
+#if (RAMEND < 1000)
41
+  #define SERIAL_BUFFER_SIZE 16
42
+#else
43
+  #define SERIAL_BUFFER_SIZE 64
44
+#endif
45
+
46
+struct ring_buffer
47
+{
48
+  unsigned char buffer[SERIAL_BUFFER_SIZE];
49
+  volatile unsigned int head;
50
+  volatile unsigned int tail;
51
+};
52
+
53
+#if defined(USBCON)
54
+  ring_buffer rx_buffer = { { 0 }, 0, 0};
55
+  ring_buffer tx_buffer = { { 0 }, 0, 0};
56
+#endif
57
+#if defined(UBRRH) || defined(UBRR0H)
58
+  ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
59
+  ring_buffer tx_buffer  =  { { 0 }, 0, 0 };
60
+#endif
61
+#if defined(UBRR1H)
62
+  ring_buffer rx_buffer1  =  { { 0 }, 0, 0 };
63
+  ring_buffer tx_buffer1  =  { { 0 }, 0, 0 };
64
+#endif
65
+#if defined(UBRR2H)
66
+  ring_buffer rx_buffer2  =  { { 0 }, 0, 0 };
67
+  ring_buffer tx_buffer2  =  { { 0 }, 0, 0 };
68
+#endif
69
+#if defined(UBRR3H)
70
+  ring_buffer rx_buffer3  =  { { 0 }, 0, 0 };
71
+  ring_buffer tx_buffer3  =  { { 0 }, 0, 0 };
72
+#endif
73
+
74
+inline void store_char(unsigned char c, ring_buffer *buffer)
75
+{
76
+  int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;
77
+
78
+  // if we should be storing the received character into the location
79
+  // just before the tail (meaning that the head would advance to the
80
+  // current location of the tail), we're about to overflow the buffer
81
+  // and so we don't write the character or advance the head.
82
+  if (i != buffer->tail) {
83
+    buffer->buffer[buffer->head] = c;
84
+    buffer->head = i;
85
+  }
86
+}
87
+
88
+#if !defined(USART0_RX_vect) && defined(USART1_RX_vect)
89
+// do nothing - on the 32u4 the first USART is USART1
90
+#else
91
+#if !defined(USART_RX_vect) && !defined(SIG_USART0_RECV) && \
92
+    !defined(SIG_UART0_RECV) && !defined(USART0_RX_vect) && \
93
+	!defined(SIG_UART_RECV)
94
+  #error "Don't know what the Data Received vector is called for the first UART"
95
+#else
96
+  void serialEvent() __attribute__((weak));
97
+  void serialEvent() {}
98
+  #define serialEvent_implemented
99
+#if defined(USART_RX_vect)
100
+  SIGNAL(USART_RX_vect)
101
+#elif defined(SIG_USART0_RECV)
102
+  SIGNAL(SIG_USART0_RECV)
103
+#elif defined(SIG_UART0_RECV)
104
+  SIGNAL(SIG_UART0_RECV)
105
+#elif defined(USART0_RX_vect)
106
+  SIGNAL(USART0_RX_vect)
107
+#elif defined(SIG_UART_RECV)
108
+  SIGNAL(SIG_UART_RECV)
109
+#endif
110
+  {
111
+  #if defined(UDR0)
112
+    unsigned char c  =  UDR0;
113
+  #elif defined(UDR)
114
+    unsigned char c  =  UDR;
115
+  #else
116
+    #error UDR not defined
117
+  #endif
118
+    store_char(c, &rx_buffer);
119
+  }
120
+#endif
121
+#endif
122
+
123
+#if defined(USART1_RX_vect)
124
+  void serialEvent1() __attribute__((weak));
125
+  void serialEvent1() {}
126
+  #define serialEvent1_implemented
127
+  SIGNAL(USART1_RX_vect)
128
+  {
129
+    unsigned char c = UDR1;
130
+    store_char(c, &rx_buffer1);
131
+  }
132
+#elif defined(SIG_USART1_RECV)
133
+  #error SIG_USART1_RECV
134
+#endif
135
+
136
+#if defined(USART2_RX_vect) && defined(UDR2)
137
+  void serialEvent2() __attribute__((weak));
138
+  void serialEvent2() {}
139
+  #define serialEvent2_implemented
140
+  SIGNAL(USART2_RX_vect)
141
+  {
142
+    unsigned char c = UDR2;
143
+    store_char(c, &rx_buffer2);
144
+  }
145
+#elif defined(SIG_USART2_RECV)
146
+  #error SIG_USART2_RECV
147
+#endif
148
+
149
+#if defined(USART3_RX_vect) && defined(UDR3)
150
+  void serialEvent3() __attribute__((weak));
151
+  void serialEvent3() {}
152
+  #define serialEvent3_implemented
153
+  SIGNAL(USART3_RX_vect)
154
+  {
155
+    unsigned char c = UDR3;
156
+    store_char(c, &rx_buffer3);
157
+  }
158
+#elif defined(SIG_USART3_RECV)
159
+  #error SIG_USART3_RECV
160
+#endif
161
+
162
+void serialEventRun(void)
163
+{
164
+#ifdef serialEvent_implemented
165
+  if (Serial.available()) serialEvent();
166
+#endif
167
+#ifdef serialEvent1_implemented
168
+  if (Serial1.available()) serialEvent1();
169
+#endif
170
+#ifdef serialEvent2_implemented
171
+  if (Serial2.available()) serialEvent2();
172
+#endif
173
+#ifdef serialEvent3_implemented
174
+  if (Serial3.available()) serialEvent3();
175
+#endif
176
+}
177
+
178
+
179
+#if !defined(USART0_UDRE_vect) && defined(USART1_UDRE_vect)
180
+// do nothing - on the 32u4 the first USART is USART1
181
+#else
182
+#if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect)
183
+  #error "Don't know what the Data Register Empty vector is called for the first UART"
184
+#else
185
+#if defined(UART0_UDRE_vect)
186
+ISR(UART0_UDRE_vect)
187
+#elif defined(UART_UDRE_vect)
188
+ISR(UART_UDRE_vect)
189
+#elif defined(USART0_UDRE_vect)
190
+ISR(USART0_UDRE_vect)
191
+#elif defined(USART_UDRE_vect)
192
+ISR(USART_UDRE_vect)
193
+#endif
194
+{
195
+  if (tx_buffer.head == tx_buffer.tail) {
196
+	// Buffer empty, so disable interrupts
197
+#if defined(UCSR0B)
198
+    cbi(UCSR0B, UDRIE0);
199
+#else
200
+    cbi(UCSRB, UDRIE);
201
+#endif
202
+  }
203
+  else {
204
+    // There is more data in the output buffer. Send the next byte
205
+    unsigned char c = tx_buffer.buffer[tx_buffer.tail];
206
+    tx_buffer.tail = (tx_buffer.tail + 1) % SERIAL_BUFFER_SIZE;
207
+	
208
+  #if defined(UDR0)
209
+    UDR0 = c;
210
+  #elif defined(UDR)
211
+    UDR = c;
212
+  #else
213
+    #error UDR not defined
214
+  #endif
215
+  }
216
+}
217
+#endif
218
+#endif
219
+
220
+#ifdef USART1_UDRE_vect
221
+ISR(USART1_UDRE_vect)
222
+{
223
+  if (tx_buffer1.head == tx_buffer1.tail) {
224
+	// Buffer empty, so disable interrupts
225
+    cbi(UCSR1B, UDRIE1);
226
+  }
227
+  else {
228
+    // There is more data in the output buffer. Send the next byte
229
+    unsigned char c = tx_buffer1.buffer[tx_buffer1.tail];
230
+    tx_buffer1.tail = (tx_buffer1.tail + 1) % SERIAL_BUFFER_SIZE;
231
+	
232
+    UDR1 = c;
233
+  }
234
+}
235
+#endif
236
+
237
+#ifdef USART2_UDRE_vect
238
+ISR(USART2_UDRE_vect)
239
+{
240
+  if (tx_buffer2.head == tx_buffer2.tail) {
241
+	// Buffer empty, so disable interrupts
242
+    cbi(UCSR2B, UDRIE2);
243
+  }
244
+  else {
245
+    // There is more data in the output buffer. Send the next byte
246
+    unsigned char c = tx_buffer2.buffer[tx_buffer2.tail];
247
+    tx_buffer2.tail = (tx_buffer2.tail + 1) % SERIAL_BUFFER_SIZE;
248
+	
249
+    UDR2 = c;
250
+  }
251
+}
252
+#endif
253
+
254
+#ifdef USART3_UDRE_vect
255
+ISR(USART3_UDRE_vect)
256
+{
257
+  if (tx_buffer3.head == tx_buffer3.tail) {
258
+	// Buffer empty, so disable interrupts
259
+    cbi(UCSR3B, UDRIE3);
260
+  }
261
+  else {
262
+    // There is more data in the output buffer. Send the next byte
263
+    unsigned char c = tx_buffer3.buffer[tx_buffer3.tail];
264
+    tx_buffer3.tail = (tx_buffer3.tail + 1) % SERIAL_BUFFER_SIZE;
265
+	
266
+    UDR3 = c;
267
+  }
268
+}
269
+#endif
270
+
271
+
272
+// Constructors ////////////////////////////////////////////////////////////////
273
+
274
+HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
275
+  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
276
+  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
277
+  volatile uint8_t *udr,
278
+  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x)
279
+{
280
+  _rx_buffer = rx_buffer;
281
+  _tx_buffer = tx_buffer;
282
+  _ubrrh = ubrrh;
283
+  _ubrrl = ubrrl;
284
+  _ucsra = ucsra;
285
+  _ucsrb = ucsrb;
286
+  _udr = udr;
287
+  _rxen = rxen;
288
+  _txen = txen;
289
+  _rxcie = rxcie;
290
+  _udrie = udrie;
291
+  _u2x = u2x;
292
+}
293
+
294
+// Public Methods //////////////////////////////////////////////////////////////
295
+
296
+void HardwareSerial::begin(unsigned long baud)
297
+{
298
+  uint16_t baud_setting;
299
+  bool use_u2x = true;
300
+
301
+#if F_CPU == 16000000UL
302
+  // hardcoded exception for compatibility with the bootloader shipped
303
+  // with the Duemilanove and previous boards and the firmware on the 8U2
304
+  // on the Uno and Mega 2560.
305
+  if (baud == 57600) {
306
+    use_u2x = false;
307
+  }
308
+#endif
309
+
310
+try_again:
311
+  
312
+  if (use_u2x) {
313
+    *_ucsra = 1 << _u2x;
314
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
315
+  } else {
316
+    *_ucsra = 0;
317
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
318
+  }
319
+  
320
+  if ((baud_setting > 4095) && use_u2x)
321
+  {
322
+    use_u2x = false;
323
+    goto try_again;
324
+  }
325
+
326
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
327
+  *_ubrrh = baud_setting >> 8;
328
+  *_ubrrl = baud_setting;
329
+
330
+  sbi(*_ucsrb, _rxen);
331
+  sbi(*_ucsrb, _txen);
332
+  sbi(*_ucsrb, _rxcie);
333
+  cbi(*_ucsrb, _udrie);
334
+}
335
+
336
+void HardwareSerial::end()
337
+{
338
+  // wait for transmission of outgoing data
339
+  while (_tx_buffer->head != _tx_buffer->tail)
340
+    ;
341
+
342
+  cbi(*_ucsrb, _rxen);
343
+  cbi(*_ucsrb, _txen);
344
+  cbi(*_ucsrb, _rxcie);  
345
+  cbi(*_ucsrb, _udrie);
346
+  
347
+  // clear any received data
348
+  _rx_buffer->head = _rx_buffer->tail;
349
+}
350
+
351
+int HardwareSerial::available(void)
352
+{
353
+  return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE;
354
+}
355
+
356
+int HardwareSerial::peek(void)
357
+{
358
+  if (_rx_buffer->head == _rx_buffer->tail) {
359
+    return -1;
360
+  } else {
361
+    return _rx_buffer->buffer[_rx_buffer->tail];
362
+  }
363
+}
364
+
365
+int HardwareSerial::read(void)
366
+{
367
+  // if the head isn't ahead of the tail, we don't have any characters
368
+  if (_rx_buffer->head == _rx_buffer->tail) {
369
+    return -1;
370
+  } else {
371
+    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
372
+    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
373
+    return c;
374
+  }
375
+}
376
+
377
+void HardwareSerial::flush()
378
+{
379
+  while (_tx_buffer->head != _tx_buffer->tail)
380
+    ;
381
+}
382
+
383
+size_t HardwareSerial::write(uint8_t c)
384
+{
385
+  int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;
386
+	
387
+  // If the output buffer is full, there's nothing for it other than to 
388
+  // wait for the interrupt handler to empty it a bit
389
+  // ???: return 0 here instead?
390
+  while (i == _tx_buffer->tail)
391
+    ;
392
+	
393
+  _tx_buffer->buffer[_tx_buffer->head] = c;
394
+  _tx_buffer->head = i;
395
+	
396
+  sbi(*_ucsrb, _udrie);
397
+  
398
+  return 1;
399
+}
400
+
401
+HardwareSerial::operator bool() {
402
+	return true;
403
+}
404
+
405
+// Preinstantiate Objects //////////////////////////////////////////////////////
406
+
407
+#if defined(UBRRH) && defined(UBRRL)
408
+  HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X);
409
+#elif defined(UBRR0H) && defined(UBRR0L)
410
+  HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0);
411
+#elif defined(USBCON)
412
+  // do nothing - Serial object and buffers are initialized in CDC code
413
+#else
414
+  #error no serial port defined  (port 0)
415
+#endif
416
+
417
+#if defined(UBRR1H)
418
+  HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1);
419
+#endif
420
+#if defined(UBRR2H)
421
+  HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2);
422
+#endif
423
+#if defined(UBRR3H)
424
+  HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
425
+#endif
426
+
427
+#endif // whole file
428
+

+ 81
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/HardwareSerial.h View File

@@ -0,0 +1,81 @@
1
+/*
2
+  HardwareSerial.h - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
4
+
5
+  This library is free software; you can redistribute it and/or
6
+  modify it under the terms of the GNU Lesser General Public
7
+  License as published by the Free Software Foundation; either
8
+  version 2.1 of the License, or (at your option) any later version.
9
+
10
+  This library is distributed in the hope that it will be useful,
11
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+  Lesser General Public License for more details.
14
+
15
+  You should have received a copy of the GNU Lesser General Public
16
+  License along with this library; if not, write to the Free Software
17
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+
19
+  Modified 28 September 2010 by Mark Sproul
20
+*/
21
+
22
+#ifndef HardwareSerial_h
23
+#define HardwareSerial_h
24
+
25
+#include <inttypes.h>
26
+
27
+#include "Stream.h"
28
+
29
+struct ring_buffer;
30
+
31
+class HardwareSerial : public Stream
32
+{
33
+  private:
34
+    ring_buffer *_rx_buffer;
35
+    ring_buffer *_tx_buffer;
36
+    volatile uint8_t *_ubrrh;
37
+    volatile uint8_t *_ubrrl;
38
+    volatile uint8_t *_ucsra;
39
+    volatile uint8_t *_ucsrb;
40
+    volatile uint8_t *_udr;
41
+    uint8_t _rxen;
42
+    uint8_t _txen;
43
+    uint8_t _rxcie;
44
+    uint8_t _udrie;
45
+    uint8_t _u2x;
46
+  public:
47
+    HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
48
+      volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
49
+      volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
50
+      volatile uint8_t *udr,
51
+      uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
52
+    void begin(unsigned long);
53
+    void end();
54
+    virtual int available(void);
55
+    virtual int peek(void);
56
+    virtual int read(void);
57
+    virtual void flush(void);
58
+    virtual size_t write(uint8_t);
59
+    using Print::write; // pull in write(str) and write(buf, size) from Print
60
+    operator bool();
61
+};
62
+
63
+#if defined(UBRRH) || defined(UBRR0H)
64
+  extern HardwareSerial Serial;
65
+#elif defined(USBCON)
66
+  #include "USBAPI.h"
67
+//  extern HardwareSerial Serial_;  
68
+#endif
69
+#if defined(UBRR1H)
70
+  extern HardwareSerial Serial1;
71
+#endif
72
+#if defined(UBRR2H)
73
+  extern HardwareSerial Serial2;
74
+#endif
75
+#if defined(UBRR3H)
76
+  extern HardwareSerial Serial3;
77
+#endif
78
+
79
+extern void serialEventRun(void) __attribute__((weak));
80
+
81
+#endif

+ 56
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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

+ 263
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Print.cpp View File

@@ -0,0 +1,263 @@
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
+  // Handle negative numbers
230
+  if (number < 0.0)
231
+  {
232
+     n += print('-');
233
+     number = -number;
234
+  }
235
+
236
+  // Round correctly so that print(1.999, 2) prints as "2.00"
237
+  double rounding = 0.5;
238
+  for (uint8_t i=0; i<digits; ++i)
239
+    rounding /= 10.0;
240
+  
241
+  number += rounding;
242
+
243
+  // Extract the integer part of the number and print it
244
+  unsigned long int_part = (unsigned long)number;
245
+  double remainder = number - (double)int_part;
246
+  n += print(int_part);
247
+
248
+  // Print the decimal point, but only if there are digits beyond
249
+  if (digits > 0) {
250
+    n += print("."); 
251
+  }
252
+
253
+  // Extract digits from the remainder one at a time
254
+  while (digits-- > 0)
255
+  {
256
+    remainder *= 10.0;
257
+    int toPrint = int(remainder);
258
+    n += print(toPrint);
259
+    remainder -= toPrint; 
260
+  } 
261
+  
262
+  return n;
263
+}

+ 78
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Print.h View File

@@ -0,0 +1,78 @@
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) { return write((const uint8_t *)str, strlen(str)); }
50
+    virtual size_t write(const uint8_t *buffer, size_t size);
51
+    
52
+    size_t print(const __FlashStringHelper *);
53
+    size_t print(const String &);
54
+    size_t print(const char[]);
55
+    size_t print(char);
56
+    size_t print(unsigned char, int = DEC);
57
+    size_t print(int, int = DEC);
58
+    size_t print(unsigned int, int = DEC);
59
+    size_t print(long, int = DEC);
60
+    size_t print(unsigned long, int = DEC);
61
+    size_t print(double, int = 2);
62
+    size_t print(const Printable&);
63
+
64
+    size_t println(const __FlashStringHelper *);
65
+    size_t println(const String &s);
66
+    size_t println(const char[]);
67
+    size_t println(char);
68
+    size_t println(unsigned char, int = DEC);
69
+    size_t println(int, int = DEC);
70
+    size_t println(unsigned int, int = DEC);
71
+    size_t println(long, int = DEC);
72
+    size_t println(unsigned long, int = DEC);
73
+    size_t println(double, int = 2);
74
+    size_t println(const Printable&);
75
+    size_t println(void);
76
+};
77
+
78
+#endif

+ 40
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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

+ 601
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/Tone.cpp View File

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

+ 195
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/USBAPI.h View File

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

+ 670
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/USBCore.cpp View File

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

+ 307
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/USBCore.h View File

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

+ 62
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/USBDesc.h View File

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

+ 88
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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

+ 298
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/WInterrupts.c View File

@@ -0,0 +1,298 @@
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
+#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
63
+    case 2:
64
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
65
+      EIMSK |= (1 << INT0);
66
+      break;
67
+    case 3:
68
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
69
+      EIMSK |= (1 << INT1);
70
+      break;
71
+    case 4:
72
+      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
73
+      EIMSK |= (1 << INT2);
74
+      break;
75
+    case 5:
76
+      EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
77
+      EIMSK |= (1 << INT3);
78
+      break;
79
+    case 0:
80
+      EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
81
+      EIMSK |= (1 << INT4);
82
+      break;
83
+    case 1:
84
+      EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
85
+      EIMSK |= (1 << INT5);
86
+      break;
87
+    case 6:
88
+      EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
89
+      EIMSK |= (1 << INT6);
90
+      break;
91
+    case 7:
92
+      EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
93
+      EIMSK |= (1 << INT7);
94
+      break;
95
+#else		
96
+    case 0:
97
+    #if defined(EICRA) && defined(ISC00) && defined(EIMSK)
98
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
99
+      EIMSK |= (1 << INT0);
100
+    #elif defined(MCUCR) && defined(ISC00) && defined(GICR)
101
+      MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
102
+      GICR |= (1 << INT0);
103
+    #elif defined(MCUCR) && defined(ISC00) && defined(GIMSK)
104
+      MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
105
+      GIMSK |= (1 << INT0);
106
+    #else
107
+      #error attachInterrupt not finished for this CPU (case 0)
108
+    #endif
109
+      break;
110
+
111
+    case 1:
112
+    #if defined(EICRA) && defined(ISC10) && defined(ISC11) && defined(EIMSK)
113
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
114
+      EIMSK |= (1 << INT1);
115
+    #elif defined(MCUCR) && defined(ISC10) && defined(ISC11) && defined(GICR)
116
+      MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
117
+      GICR |= (1 << INT1);
118
+    #elif defined(MCUCR) && defined(ISC10) && defined(GIMSK) && defined(GIMSK)
119
+      MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
120
+      GIMSK |= (1 << INT1);
121
+    #else
122
+      #warning attachInterrupt may need some more work for this cpu (case 1)
123
+    #endif
124
+      break;
125
+    
126
+    case 2:
127
+    #if defined(EICRA) && defined(ISC20) && defined(ISC21) && defined(EIMSK)
128
+      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
129
+      EIMSK |= (1 << INT2);
130
+    #elif defined(MCUCR) && defined(ISC20) && defined(ISC21) && defined(GICR)
131
+      MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
132
+      GICR |= (1 << INT2);
133
+    #elif defined(MCUCR) && defined(ISC20) && defined(GIMSK) && defined(GIMSK)
134
+      MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
135
+      GIMSK |= (1 << INT2);
136
+    #endif
137
+      break;
138
+#endif
139
+    }
140
+  }
141
+}
142
+
143
+void detachInterrupt(uint8_t interruptNum) {
144
+  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
145
+    // Disable the interrupt.  (We can't assume that interruptNum is equal
146
+    // to the number of the EIMSK bit to clear, as this isn't true on the 
147
+    // ATmega8.  There, INT0 is 6 and INT1 is 7.)
148
+    switch (interruptNum) {
149
+#if defined(__AVR_ATmega32U4__)
150
+	case 0:
151
+		EIMSK &= ~(1<<INT0);
152
+		break;
153
+	case 1:
154
+		EIMSK &= ~(1<<INT1);
155
+		break;		
156
+#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
157
+    case 2:
158
+      EIMSK &= ~(1 << INT0);
159
+      break;
160
+    case 3:
161
+      EIMSK &= ~(1 << INT1);
162
+      break;
163
+    case 4:
164
+      EIMSK &= ~(1 << INT2);
165
+      break;
166
+    case 5:
167
+      EIMSK &= ~(1 << INT3);
168
+      break;
169
+    case 0:
170
+      EIMSK &= ~(1 << INT4);
171
+      break;
172
+    case 1:
173
+      EIMSK &= ~(1 << INT5);
174
+      break;
175
+    case 6:
176
+      EIMSK &= ~(1 << INT6);
177
+      break;
178
+    case 7:
179
+      EIMSK &= ~(1 << INT7);
180
+      break;
181
+#else
182
+    case 0:
183
+    #if defined(EIMSK) && defined(INT0)
184
+      EIMSK &= ~(1 << INT0);
185
+    #elif defined(GICR) && defined(ISC00)
186
+      GICR &= ~(1 << INT0); // atmega32
187
+    #elif defined(GIMSK) && defined(INT0)
188
+      GIMSK &= ~(1 << INT0);
189
+    #else
190
+      #error detachInterrupt not finished for this cpu
191
+    #endif
192
+      break;
193
+
194
+    case 1:
195
+    #if defined(EIMSK) && defined(INT1)
196
+      EIMSK &= ~(1 << INT1);
197
+    #elif defined(GICR) && defined(INT1)
198
+      GICR &= ~(1 << INT1); // atmega32
199
+    #elif defined(GIMSK) && defined(INT1)
200
+      GIMSK &= ~(1 << INT1);
201
+    #else
202
+      #warning detachInterrupt may need some more work for this cpu (case 1)
203
+    #endif
204
+      break;
205
+#endif
206
+    }
207
+      
208
+    intFunc[interruptNum] = 0;
209
+  }
210
+}
211
+
212
+/*
213
+void attachInterruptTwi(void (*userFunc)(void) ) {
214
+  twiIntFunc = userFunc;
215
+}
216
+*/
217
+
218
+#if defined(__AVR_ATmega32U4__)
219
+SIGNAL(INT0_vect) {
220
+	if(intFunc[EXTERNAL_INT_0])
221
+		intFunc[EXTERNAL_INT_0]();
222
+}
223
+
224
+SIGNAL(INT1_vect) {
225
+	if(intFunc[EXTERNAL_INT_1])
226
+		intFunc[EXTERNAL_INT_1]();
227
+}
228
+
229
+#elif defined(EICRA) && defined(EICRB)
230
+
231
+SIGNAL(INT0_vect) {
232
+  if(intFunc[EXTERNAL_INT_2])
233
+    intFunc[EXTERNAL_INT_2]();
234
+}
235
+
236
+SIGNAL(INT1_vect) {
237
+  if(intFunc[EXTERNAL_INT_3])
238
+    intFunc[EXTERNAL_INT_3]();
239
+}
240
+
241
+SIGNAL(INT2_vect) {
242
+  if(intFunc[EXTERNAL_INT_4])
243
+    intFunc[EXTERNAL_INT_4]();
244
+}
245
+
246
+SIGNAL(INT3_vect) {
247
+  if(intFunc[EXTERNAL_INT_5])
248
+    intFunc[EXTERNAL_INT_5]();
249
+}
250
+
251
+SIGNAL(INT4_vect) {
252
+  if(intFunc[EXTERNAL_INT_0])
253
+    intFunc[EXTERNAL_INT_0]();
254
+}
255
+
256
+SIGNAL(INT5_vect) {
257
+  if(intFunc[EXTERNAL_INT_1])
258
+    intFunc[EXTERNAL_INT_1]();
259
+}
260
+
261
+SIGNAL(INT6_vect) {
262
+  if(intFunc[EXTERNAL_INT_6])
263
+    intFunc[EXTERNAL_INT_6]();
264
+}
265
+
266
+SIGNAL(INT7_vect) {
267
+  if(intFunc[EXTERNAL_INT_7])
268
+    intFunc[EXTERNAL_INT_7]();
269
+}
270
+
271
+#else
272
+
273
+SIGNAL(INT0_vect) {
274
+  if(intFunc[EXTERNAL_INT_0])
275
+    intFunc[EXTERNAL_INT_0]();
276
+}
277
+
278
+SIGNAL(INT1_vect) {
279
+  if(intFunc[EXTERNAL_INT_1])
280
+    intFunc[EXTERNAL_INT_1]();
281
+}
282
+
283
+#if defined(EICRA) && defined(ISC20)
284
+SIGNAL(INT2_vect) {
285
+  if(intFunc[EXTERNAL_INT_2])
286
+    intFunc[EXTERNAL_INT_2]();
287
+}
288
+#endif
289
+
290
+#endif
291
+
292
+/*
293
+SIGNAL(SIG_2WIRE_SERIAL) {
294
+  if(twiIntFunc)
295
+    twiIntFunc();
296
+}
297
+*/
298
+

+ 60
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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<__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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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_ATmega1284__)
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.5.x/hardware/marlin/avr/cores/brainwave/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
+}

+ 69
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/wiring_private.h View File

@@ -0,0 +1,69 @@
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__) 
58
+#define EXTERNAL_NUM_INTERRUPTS 3
59
+#else
60
+#define EXTERNAL_NUM_INTERRUPTS 2
61
+#endif
62
+
63
+typedef void (*voidFuncPtr)(void);
64
+
65
+#ifdef __cplusplus
66
+} // extern "C"
67
+#endif
68
+
69
+#endif

+ 69
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/cores/brainwave/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.5.x/hardware/marlin/avr/cores/brainwave/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
+}

+ 106
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/firmwares/Brainwave.inf View File

@@ -0,0 +1,106 @@
1
+;************************************************************
2
+; Windows USB CDC ACM Setup File
3
+; Copyright (c) 2000 Microsoft Corporation
4
+
5
+
6
+[Version]
7
+Signature="$Windows NT$"
8
+Class=Ports
9
+ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
10
+Provider=%MFGNAME%
11
+LayoutFile=layout.inf
12
+CatalogFile=%MFGFILENAME%.cat
13
+DriverVer=11/15/2007,5.1.2600.0
14
+
15
+[Manufacturer]
16
+%MFGNAME%=DeviceList, NTamd64
17
+
18
+[DestinationDirs]
19
+DefaultDestDir=12
20
+
21
+
22
+;------------------------------------------------------------------------------
23
+;  Windows 2000/XP/Vista-32bit Sections
24
+;------------------------------------------------------------------------------
25
+
26
+[DriverInstall.nt]
27
+include=mdmcpq.inf
28
+CopyFiles=DriverCopyFiles.nt
29
+AddReg=DriverInstall.nt.AddReg
30
+
31
+[DriverCopyFiles.nt]
32
+usbser.sys,,,0x20
33
+
34
+[DriverInstall.nt.AddReg]
35
+HKR,,DevLoader,,*ntkern
36
+HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
37
+HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
38
+
39
+[DriverInstall.nt.Services]
40
+AddService=usbser, 0x00000002, DriverService.nt
41
+
42
+[DriverService.nt]
43
+DisplayName=%SERVICE%
44
+ServiceType=1
45
+StartType=3
46
+ErrorControl=1
47
+ServiceBinary=%12%\%DRIVERFILENAME%.sys
48
+
49
+;------------------------------------------------------------------------------
50
+;  Vista-64bit Sections
51
+;------------------------------------------------------------------------------
52
+
53
+[DriverInstall.NTamd64]
54
+include=mdmcpq.inf
55
+CopyFiles=DriverCopyFiles.NTamd64
56
+AddReg=DriverInstall.NTamd64.AddReg
57
+
58
+[DriverCopyFiles.NTamd64]
59
+%DRIVERFILENAME%.sys,,,0x20
60
+
61
+[DriverInstall.NTamd64.AddReg]
62
+HKR,,DevLoader,,*ntkern
63
+HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
64
+HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
65
+
66
+[DriverInstall.NTamd64.Services]
67
+AddService=usbser, 0x00000002, DriverService.NTamd64
68
+
69
+[DriverService.NTamd64]
70
+DisplayName=%SERVICE%
71
+ServiceType=1
72
+StartType=3
73
+ErrorControl=1
74
+ServiceBinary=%12%\%DRIVERFILENAME%.sys
75
+
76
+
77
+;------------------------------------------------------------------------------
78
+;  Vendor and Product ID Definitions
79
+;------------------------------------------------------------------------------
80
+; When developing your USB device, the VID and PID used in the PC side
81
+; application program and the firmware on the microcontroller must match.
82
+; Modify the below line to use your VID and PID.  Use the format as shown below.
83
+; Note: One INF file can be used for multiple devices with different VID and PIDs.
84
+; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line.
85
+;------------------------------------------------------------------------------
86
+[SourceDisksFiles]
87
+[SourceDisksNames]
88
+[DeviceList]
89
+%DESCRIPTION%=DriverInstall, USB\VID_16D0&PID_076B
90
+
91
+[DeviceList.NTamd64]
92
+%DESCRIPTION%=DriverInstall, USB\VID_16D0&PID_204A
93
+
94
+
95
+;------------------------------------------------------------------------------
96
+;  String Definitions
97
+;------------------------------------------------------------------------------
98
+;Modify these strings to customize your device
99
+;------------------------------------------------------------------------------
100
+[Strings]
101
+MFGFILENAME="CDC_vista"
102
+DRIVERFILENAME ="usbser"
103
+MFGNAME="Metrix Create Space"
104
+INSTDISK="Brainwave Driver Installer"
105
+DESCRIPTION="Communications Port"
106
+SERVICE="USB RS-232 Emulation Driver"

+ 310
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/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 it's 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.5.x/hardware/marlin/avr/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.5.x/hardware/marlin/avr/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.5.x/hardware/marlin/avr/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.5.x/hardware/marlin/avr/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.5.x/hardware/marlin/avr/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

+ 303
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/Wire.cpp View File

@@ -0,0 +1,303 @@
1
+/*
2
+  TwoWire.cpp - TWI/I2C library for Wiring & Arduino
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 2012 by Todd Krein (todd@krein.org) to implement repeated starts
20
+*/
21
+
22
+extern "C" {
23
+  #include <stdlib.h>
24
+  #include <string.h>
25
+  #include <inttypes.h>
26
+  #include "twi.h"
27
+}
28
+
29
+#include "Wire.h"
30
+
31
+// Initialize Class Variables //////////////////////////////////////////////////
32
+
33
+uint8_t TwoWire::rxBuffer[BUFFER_LENGTH];
34
+uint8_t TwoWire::rxBufferIndex = 0;
35
+uint8_t TwoWire::rxBufferLength = 0;
36
+
37
+uint8_t TwoWire::txAddress = 0;
38
+uint8_t TwoWire::txBuffer[BUFFER_LENGTH];
39
+uint8_t TwoWire::txBufferIndex = 0;
40
+uint8_t TwoWire::txBufferLength = 0;
41
+
42
+uint8_t TwoWire::transmitting = 0;
43
+void (*TwoWire::user_onRequest)(void);
44
+void (*TwoWire::user_onReceive)(int);
45
+
46
+// Constructors ////////////////////////////////////////////////////////////////
47
+
48
+TwoWire::TwoWire()
49
+{
50
+}
51
+
52
+// Public Methods //////////////////////////////////////////////////////////////
53
+
54
+void TwoWire::begin(void)
55
+{
56
+  rxBufferIndex = 0;
57
+  rxBufferLength = 0;
58
+
59
+  txBufferIndex = 0;
60
+  txBufferLength = 0;
61
+
62
+  twi_init();
63
+}
64
+
65
+void TwoWire::begin(uint8_t address)
66
+{
67
+  twi_setAddress(address);
68
+  twi_attachSlaveTxEvent(onRequestService);
69
+  twi_attachSlaveRxEvent(onReceiveService);
70
+  begin();
71
+}
72
+
73
+void TwoWire::begin(int address)
74
+{
75
+  begin((uint8_t)address);
76
+}
77
+
78
+void TwoWire::setClock(uint32_t frequency)
79
+{
80
+  TWBR = ((F_CPU / frequency) - 16) / 2;
81
+}
82
+
83
+uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)
84
+{
85
+  // clamp to buffer length
86
+  if(quantity > BUFFER_LENGTH){
87
+    quantity = BUFFER_LENGTH;
88
+  }
89
+  // perform blocking read into buffer
90
+  uint8_t read = twi_readFrom(address, rxBuffer, quantity, sendStop);
91
+  // set rx buffer iterator vars
92
+  rxBufferIndex = 0;
93
+  rxBufferLength = read;
94
+
95
+  return read;
96
+}
97
+
98
+uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity)
99
+{
100
+  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
101
+}
102
+
103
+uint8_t TwoWire::requestFrom(int address, int quantity)
104
+{
105
+  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
106
+}
107
+
108
+uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop)
109
+{
110
+  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)sendStop);
111
+}
112
+
113
+void TwoWire::beginTransmission(uint8_t address)
114
+{
115
+  // indicate that we are transmitting
116
+  transmitting = 1;
117
+  // set address of targeted slave
118
+  txAddress = address;
119
+  // reset tx buffer iterator vars
120
+  txBufferIndex = 0;
121
+  txBufferLength = 0;
122
+}
123
+
124
+void TwoWire::beginTransmission(int address)
125
+{
126
+  beginTransmission((uint8_t)address);
127
+}
128
+
129
+//
130
+//	Originally, 'endTransmission' was an f(void) function.
131
+//	It has been modified to take one parameter indicating
132
+//	whether or not a STOP should be performed on the bus.
133
+//	Calling endTransmission(false) allows a sketch to 
134
+//	perform a repeated start. 
135
+//
136
+//	WARNING: Nothing in the library keeps track of whether
137
+//	the bus tenure has been properly ended with a STOP. It
138
+//	is very possible to leave the bus in a hung state if
139
+//	no call to endTransmission(true) is made. Some I2C
140
+//	devices will behave oddly if they do not see a STOP.
141
+//
142
+uint8_t TwoWire::endTransmission(uint8_t sendStop)
143
+{
144
+  // transmit buffer (blocking)
145
+  int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1, sendStop);
146
+  // reset tx buffer iterator vars
147
+  txBufferIndex = 0;
148
+  txBufferLength = 0;
149
+  // indicate that we are done transmitting
150
+  transmitting = 0;
151
+  return ret;
152
+}
153
+
154
+//	This provides backwards compatibility with the original
155
+//	definition, and expected behaviour, of endTransmission
156
+//
157
+uint8_t TwoWire::endTransmission(void)
158
+{
159
+  return endTransmission(true);
160
+}
161
+
162
+// must be called in:
163
+// slave tx event callback
164
+// or after beginTransmission(address)
165
+size_t TwoWire::write(uint8_t data)
166
+{
167
+  if(transmitting){
168
+  // in master transmitter mode
169
+    // don't bother if buffer is full
170
+    if(txBufferLength >= BUFFER_LENGTH){
171
+      setWriteError();
172
+      return 0;
173
+    }
174
+    // put byte in tx buffer
175
+    txBuffer[txBufferIndex] = data;
176
+    ++txBufferIndex;
177
+    // update amount in buffer   
178
+    txBufferLength = txBufferIndex;
179
+  }else{
180
+  // in slave send mode
181
+    // reply to master
182
+    twi_transmit(&data, 1);
183
+  }
184
+  return 1;
185
+}
186
+
187
+// must be called in:
188
+// slave tx event callback
189
+// or after beginTransmission(address)
190
+size_t TwoWire::write(const uint8_t *data, size_t quantity)
191
+{
192
+  if(transmitting){
193
+  // in master transmitter mode
194
+    for(size_t i = 0; i < quantity; ++i){
195
+      write(data[i]);
196
+    }
197
+  }else{
198
+  // in slave send mode
199
+    // reply to master
200
+    twi_transmit(data, quantity);
201
+  }
202
+  return quantity;
203
+}
204
+
205
+// must be called in:
206
+// slave rx event callback
207
+// or after requestFrom(address, numBytes)
208
+int TwoWire::available(void)
209
+{
210
+  return rxBufferLength - rxBufferIndex;
211
+}
212
+
213
+// must be called in:
214
+// slave rx event callback
215
+// or after requestFrom(address, numBytes)
216
+int TwoWire::read(void)
217
+{
218
+  int value = -1;
219
+  
220
+  // get each successive byte on each call
221
+  if(rxBufferIndex < rxBufferLength){
222
+    value = rxBuffer[rxBufferIndex];
223
+    ++rxBufferIndex;
224
+  }
225
+
226
+  return value;
227
+}
228
+
229
+// must be called in:
230
+// slave rx event callback
231
+// or after requestFrom(address, numBytes)
232
+int TwoWire::peek(void)
233
+{
234
+  int value = -1;
235
+  
236
+  if(rxBufferIndex < rxBufferLength){
237
+    value = rxBuffer[rxBufferIndex];
238
+  }
239
+
240
+  return value;
241
+}
242
+
243
+void TwoWire::flush(void)
244
+{
245
+  // XXX: to be implemented.
246
+}
247
+
248
+// behind the scenes function that is called when data is received
249
+void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
250
+{
251
+  // don't bother if user hasn't registered a callback
252
+  if(!user_onReceive){
253
+    return;
254
+  }
255
+  // don't bother if rx buffer is in use by a master requestFrom() op
256
+  // i know this drops data, but it allows for slight stupidity
257
+  // meaning, they may not have read all the master requestFrom() data yet
258
+  if(rxBufferIndex < rxBufferLength){
259
+    return;
260
+  }
261
+  // copy twi rx buffer into local read buffer
262
+  // this enables new reads to happen in parallel
263
+  for(uint8_t i = 0; i < numBytes; ++i){
264
+    rxBuffer[i] = inBytes[i];    
265
+  }
266
+  // set rx iterator vars
267
+  rxBufferIndex = 0;
268
+  rxBufferLength = numBytes;
269
+  // alert user program
270
+  user_onReceive(numBytes);
271
+}
272
+
273
+// behind the scenes function that is called when data is requested
274
+void TwoWire::onRequestService(void)
275
+{
276
+  // don't bother if user hasn't registered a callback
277
+  if(!user_onRequest){
278
+    return;
279
+  }
280
+  // reset tx buffer iterator vars
281
+  // !!! this will kill any pending pre-master sendTo() activity
282
+  txBufferIndex = 0;
283
+  txBufferLength = 0;
284
+  // alert user program
285
+  user_onRequest();
286
+}
287
+
288
+// sets function called on slave write
289
+void TwoWire::onReceive( void (*function)(int) )
290
+{
291
+  user_onReceive = function;
292
+}
293
+
294
+// sets function called on slave read
295
+void TwoWire::onRequest( void (*function)(void) )
296
+{
297
+  user_onRequest = function;
298
+}
299
+
300
+// Preinstantiate Objects //////////////////////////////////////////////////////
301
+
302
+TwoWire Wire = TwoWire();
303
+

+ 80
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/Wire.h View File

@@ -0,0 +1,80 @@
1
+/*
2
+  TwoWire.h - TWI/I2C library for Arduino & 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 2012 by Todd Krein (todd@krein.org) to implement repeated starts
20
+*/
21
+
22
+#ifndef TwoWire_h
23
+#define TwoWire_h
24
+
25
+#include <inttypes.h>
26
+#include "Stream.h"
27
+
28
+#define BUFFER_LENGTH 32
29
+
30
+class TwoWire : public Stream
31
+{
32
+  private:
33
+    static uint8_t rxBuffer[];
34
+    static uint8_t rxBufferIndex;
35
+    static uint8_t rxBufferLength;
36
+
37
+    static uint8_t txAddress;
38
+    static uint8_t txBuffer[];
39
+    static uint8_t txBufferIndex;
40
+    static uint8_t txBufferLength;
41
+
42
+    static uint8_t transmitting;
43
+    static void (*user_onRequest)(void);
44
+    static void (*user_onReceive)(int);
45
+    static void onRequestService(void);
46
+    static void onReceiveService(uint8_t*, int);
47
+  public:
48
+    TwoWire();
49
+    void begin();
50
+    void begin(uint8_t);
51
+    void begin(int);
52
+    void setClock(uint32_t);
53
+    void beginTransmission(uint8_t);
54
+    void beginTransmission(int);
55
+    uint8_t endTransmission(void);
56
+    uint8_t endTransmission(uint8_t);
57
+    uint8_t requestFrom(uint8_t, uint8_t);
58
+    uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
59
+    uint8_t requestFrom(int, int);
60
+    uint8_t requestFrom(int, int, int);
61
+    virtual size_t write(uint8_t);
62
+    virtual size_t write(const uint8_t *, size_t);
63
+    virtual int available(void);
64
+    virtual int read(void);
65
+    virtual int peek(void);
66
+    virtual void flush(void);
67
+    void onReceive( void (*)(int) );
68
+    void onRequest( void (*)(void) );
69
+
70
+    inline size_t write(unsigned long n) { return write((uint8_t)n); }
71
+    inline size_t write(long n) { return write((uint8_t)n); }
72
+    inline size_t write(unsigned int n) { return write((uint8_t)n); }
73
+    inline size_t write(int n) { return write((uint8_t)n); }
74
+    using Print::write;
75
+};
76
+
77
+extern TwoWire Wire;
78
+
79
+#endif
80
+

+ 87
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino View File

@@ -0,0 +1,87 @@
1
+// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder
2
+// by Nicholas Zambetti <http://www.zambetti.com>
3
+// and James Tichenor <http://www.jamestichenor.net>
4
+
5
+// Demonstrates use of the Wire library reading data from the
6
+// Devantech Utrasonic Rangers SFR08 and SFR10
7
+
8
+// Created 29 April 2006
9
+
10
+// This example code is in the public domain.
11
+
12
+
13
+#include <Wire.h>
14
+
15
+void setup()
16
+{
17
+  Wire.begin();                // join i2c bus (address optional for master)
18
+  Serial.begin(9600);          // start serial communication at 9600bps
19
+}
20
+
21
+int reading = 0;
22
+
23
+void loop()
24
+{
25
+  // step 1: instruct sensor to read echoes
26
+  Wire.beginTransmission(112); // transmit to device #112 (0x70)
27
+  // the address specified in the datasheet is 224 (0xE0)
28
+  // but i2c adressing uses the high 7 bits so it's 112
29
+  Wire.write(byte(0x00));      // sets register pointer to the command register (0x00)
30
+  Wire.write(byte(0x50));      // command sensor to measure in "inches" (0x50)
31
+  // use 0x51 for centimeters
32
+  // use 0x52 for ping microseconds
33
+  Wire.endTransmission();      // stop transmitting
34
+
35
+  // step 2: wait for readings to happen
36
+  delay(70);                   // datasheet suggests at least 65 milliseconds
37
+
38
+  // step 3: instruct sensor to return a particular echo reading
39
+  Wire.beginTransmission(112); // transmit to device #112
40
+  Wire.write(byte(0x02));      // sets register pointer to echo #1 register (0x02)
41
+  Wire.endTransmission();      // stop transmitting
42
+
43
+  // step 4: request reading from sensor
44
+  Wire.requestFrom(112, 2);    // request 2 bytes from slave device #112
45
+
46
+  // step 5: receive reading from sensor
47
+  if (2 <= Wire.available())   // if two bytes were received
48
+  {
49
+    reading = Wire.read();  // receive high byte (overwrites previous reading)
50
+    reading = reading << 8;    // shift high byte to be high 8 bits
51
+    reading |= Wire.read(); // receive low byte as lower 8 bits
52
+    Serial.println(reading);   // print the reading
53
+  }
54
+
55
+  delay(250);                  // wait a bit since people have to read the output :)
56
+}
57
+
58
+
59
+/*
60
+
61
+// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08)
62
+// usage: changeAddress(0x70, 0xE6);
63
+
64
+void changeAddress(byte oldAddress, byte newAddress)
65
+{
66
+  Wire.beginTransmission(oldAddress);
67
+  Wire.write(byte(0x00));
68
+  Wire.write(byte(0xA0));
69
+  Wire.endTransmission();
70
+
71
+  Wire.beginTransmission(oldAddress);
72
+  Wire.write(byte(0x00));
73
+  Wire.write(byte(0xAA));
74
+  Wire.endTransmission();
75
+
76
+  Wire.beginTransmission(oldAddress);
77
+  Wire.write(byte(0x00));
78
+  Wire.write(byte(0xA5));
79
+  Wire.endTransmission();
80
+
81
+  Wire.beginTransmission(oldAddress);
82
+  Wire.write(byte(0x00));
83
+  Wire.write(newAddress);
84
+  Wire.endTransmission();
85
+}
86
+
87
+*/

+ 39
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino View File

@@ -0,0 +1,39 @@
1
+// I2C Digital Potentiometer
2
+// by Nicholas Zambetti <http://www.zambetti.com>
3
+// and Shawn Bonkowski <http://people.interaction-ivrea.it/s.bonkowski/>
4
+
5
+// Demonstrates use of the Wire library
6
+// Controls AD5171 digital potentiometer via I2C/TWI
7
+
8
+// Created 31 March 2006
9
+
10
+// This example code is in the public domain.
11
+
12
+// This example code is in the public domain.
13
+
14
+
15
+#include <Wire.h>
16
+
17
+void setup()
18
+{
19
+  Wire.begin(); // join i2c bus (address optional for master)
20
+}
21
+
22
+byte val = 0;
23
+
24
+void loop()
25
+{
26
+  Wire.beginTransmission(44); // transmit to device #44 (0x2c)
27
+  // device address is specified in datasheet
28
+  Wire.write(byte(0x00));            // sends instruction byte
29
+  Wire.write(val);             // sends potentiometer value byte
30
+  Wire.endTransmission();     // stop transmitting
31
+
32
+  val++;        // increment value
33
+  if (val == 64) // if reached 64th position (max)
34
+  {
35
+    val = 0;    // start over from lowest value
36
+  }
37
+  delay(500);
38
+}
39
+

+ 32
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/master_reader/master_reader.ino View File

@@ -0,0 +1,32 @@
1
+// Wire Master Reader
2
+// by Nicholas Zambetti <http://www.zambetti.com>
3
+
4
+// Demonstrates use of the Wire library
5
+// Reads data from an I2C/TWI slave device
6
+// Refer to the "Wire Slave Sender" example for use with this
7
+
8
+// Created 29 March 2006
9
+
10
+// This example code is in the public domain.
11
+
12
+
13
+#include <Wire.h>
14
+
15
+void setup()
16
+{
17
+  Wire.begin();        // join i2c bus (address optional for master)
18
+  Serial.begin(9600);  // start serial for output
19
+}
20
+
21
+void loop()
22
+{
23
+  Wire.requestFrom(2, 6);    // request 6 bytes from slave device #2
24
+
25
+  while (Wire.available())   // slave may send less than requested
26
+  {
27
+    char c = Wire.read(); // receive a byte as character
28
+    Serial.print(c);         // print the character
29
+  }
30
+
31
+  delay(500);
32
+}

+ 31
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/master_writer/master_writer.ino View File

@@ -0,0 +1,31 @@
1
+// Wire Master Writer
2
+// by Nicholas Zambetti <http://www.zambetti.com>
3
+
4
+// Demonstrates use of the Wire library
5
+// Writes data to an I2C/TWI slave device
6
+// Refer to the "Wire Slave Receiver" example for use with this
7
+
8
+// Created 29 March 2006
9
+
10
+// This example code is in the public domain.
11
+
12
+
13
+#include <Wire.h>
14
+
15
+void setup()
16
+{
17
+  Wire.begin(); // join i2c bus (address optional for master)
18
+}
19
+
20
+byte x = 0;
21
+
22
+void loop()
23
+{
24
+  Wire.beginTransmission(4); // transmit to device #4
25
+  Wire.write("x is ");        // sends five bytes
26
+  Wire.write(x);              // sends one byte
27
+  Wire.endTransmission();    // stop transmitting
28
+
29
+  x++;
30
+  delay(500);
31
+}

+ 38
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino View File

@@ -0,0 +1,38 @@
1
+// Wire Slave Receiver
2
+// by Nicholas Zambetti <http://www.zambetti.com>
3
+
4
+// Demonstrates use of the Wire library
5
+// Receives data as an I2C/TWI slave device
6
+// Refer to the "Wire Master Writer" example for use with this
7
+
8
+// Created 29 March 2006
9
+
10
+// This example code is in the public domain.
11
+
12
+
13
+#include <Wire.h>
14
+
15
+void setup()
16
+{
17
+  Wire.begin(4);                // join i2c bus with address #4
18
+  Wire.onReceive(receiveEvent); // register event
19
+  Serial.begin(9600);           // start serial for output
20
+}
21
+
22
+void loop()
23
+{
24
+  delay(100);
25
+}
26
+
27
+// function that executes whenever data is received from master
28
+// this function is registered as an event, see setup()
29
+void receiveEvent(int howMany)
30
+{
31
+  while (1 < Wire.available()) // loop through all but the last
32
+  {
33
+    char c = Wire.read(); // receive byte as a character
34
+    Serial.print(c);         // print the character
35
+  }
36
+  int x = Wire.read();    // receive byte as an integer
37
+  Serial.println(x);         // print the integer
38
+}

+ 32
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/examples/slave_sender/slave_sender.ino View File

@@ -0,0 +1,32 @@
1
+// Wire Slave Sender
2
+// by Nicholas Zambetti <http://www.zambetti.com>
3
+
4
+// Demonstrates use of the Wire library
5
+// Sends data as an I2C/TWI slave device
6
+// Refer to the "Wire Master Reader" example for use with this
7
+
8
+// Created 29 March 2006
9
+
10
+// This example code is in the public domain.
11
+
12
+
13
+#include <Wire.h>
14
+
15
+void setup()
16
+{
17
+  Wire.begin(2);                // join i2c bus with address #2
18
+  Wire.onRequest(requestEvent); // register event
19
+}
20
+
21
+void loop()
22
+{
23
+  delay(100);
24
+}
25
+
26
+// function that executes whenever data is requested by master
27
+// this function is registered as an event, see setup()
28
+void requestEvent()
29
+{
30
+  Wire.write("hello "); // respond with message of 6 bytes
31
+  // as expected by master
32
+}

+ 32
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/keywords.txt View File

@@ -0,0 +1,32 @@
1
+#######################################
2
+# Syntax Coloring Map For Wire
3
+#######################################
4
+
5
+#######################################
6
+# Datatypes (KEYWORD1)
7
+#######################################
8
+
9
+#######################################
10
+# Methods and Functions (KEYWORD2)
11
+#######################################
12
+
13
+begin	KEYWORD2
14
+setClock	KEYWORD2
15
+beginTransmission	KEYWORD2
16
+endTransmission	KEYWORD2
17
+requestFrom	KEYWORD2
18
+send	KEYWORD2
19
+receive	KEYWORD2
20
+onReceive	KEYWORD2
21
+onRequest	KEYWORD2
22
+
23
+#######################################
24
+# Instances (KEYWORD2)
25
+#######################################
26
+
27
+Wire	KEYWORD2
28
+
29
+#######################################
30
+# Constants (LITERAL1)
31
+#######################################
32
+

+ 8
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/library.properties View File

@@ -0,0 +1,8 @@
1
+name=Wire
2
+version=1.0
3
+author=Arduino
4
+maintainer=Arduino <info@arduino.cc>
5
+sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. For all Arduino boards, BUT Arduino DUE. 
6
+paragraph=
7
+url=http://arduino.cc/en/Reference/Wire
8
+architectures=avr

+ 527
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/utility/twi.c View File

@@ -0,0 +1,527 @@
1
+/*
2
+  twi.c - TWI/I2C library for Wiring & Arduino
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 2012 by Todd Krein (todd@krein.org) to implement repeated starts
20
+*/
21
+
22
+#include <math.h>
23
+#include <stdlib.h>
24
+#include <inttypes.h>
25
+#include <avr/io.h>
26
+#include <avr/interrupt.h>
27
+#include <compat/twi.h>
28
+#include "Arduino.h" // for digitalWrite
29
+
30
+#ifndef cbi
31
+#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
32
+#endif
33
+
34
+#ifndef sbi
35
+#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
36
+#endif
37
+
38
+#include "pins_arduino.h"
39
+#include "twi.h"
40
+
41
+static volatile uint8_t twi_state;
42
+static volatile uint8_t twi_slarw;
43
+static volatile uint8_t twi_sendStop;			// should the transaction end with a stop
44
+static volatile uint8_t twi_inRepStart;			// in the middle of a repeated start
45
+
46
+static void (*twi_onSlaveTransmit)(void);
47
+static void (*twi_onSlaveReceive)(uint8_t*, int);
48
+
49
+static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH];
50
+static volatile uint8_t twi_masterBufferIndex;
51
+static volatile uint8_t twi_masterBufferLength;
52
+
53
+static uint8_t twi_txBuffer[TWI_BUFFER_LENGTH];
54
+static volatile uint8_t twi_txBufferIndex;
55
+static volatile uint8_t twi_txBufferLength;
56
+
57
+static uint8_t twi_rxBuffer[TWI_BUFFER_LENGTH];
58
+static volatile uint8_t twi_rxBufferIndex;
59
+
60
+static volatile uint8_t twi_error;
61
+
62
+/* 
63
+ * Function twi_init
64
+ * Desc     readys twi pins and sets twi bitrate
65
+ * Input    none
66
+ * Output   none
67
+ */
68
+void twi_init(void)
69
+{
70
+  // initialize state
71
+  twi_state = TWI_READY;
72
+  twi_sendStop = true;		// default value
73
+  twi_inRepStart = false;
74
+  
75
+  // activate internal pullups for twi.
76
+  digitalWrite(SDA, 1);
77
+  digitalWrite(SCL, 1);
78
+
79
+  // initialize twi prescaler and bit rate
80
+  cbi(TWSR, TWPS0);
81
+  cbi(TWSR, TWPS1);
82
+  TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
83
+
84
+  /* twi bit rate formula from atmega128 manual pg 204
85
+  SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
86
+  note: TWBR should be 10 or higher for master mode
87
+  It is 72 for a 16mhz Wiring board with 100kHz TWI */
88
+
89
+  // enable twi module, acks, and twi interrupt
90
+  TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);
91
+}
92
+
93
+/* 
94
+ * Function twi_slaveInit
95
+ * Desc     sets slave address and enables interrupt
96
+ * Input    none
97
+ * Output   none
98
+ */
99
+void twi_setAddress(uint8_t address)
100
+{
101
+  // set twi slave address (skip over TWGCE bit)
102
+  TWAR = address << 1;
103
+}
104
+
105
+/* 
106
+ * Function twi_readFrom
107
+ * Desc     attempts to become twi bus master and read a
108
+ *          series of bytes from a device on the bus
109
+ * Input    address: 7bit i2c device address
110
+ *          data: pointer to byte array
111
+ *          length: number of bytes to read into array
112
+ *          sendStop: Boolean indicating whether to send a stop at the end
113
+ * Output   number of bytes read
114
+ */
115
+uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sendStop)
116
+{
117
+  uint8_t i;
118
+
119
+  // ensure data will fit into buffer
120
+  if(TWI_BUFFER_LENGTH < length){
121
+    return 0;
122
+  }
123
+
124
+  // wait until twi is ready, become master receiver
125
+  while(TWI_READY != twi_state){
126
+    continue;
127
+  }
128
+  twi_state = TWI_MRX;
129
+  twi_sendStop = sendStop;
130
+  // reset error state (0xFF.. no error occured)
131
+  twi_error = 0xFF;
132
+
133
+  // initialize buffer iteration vars
134
+  twi_masterBufferIndex = 0;
135
+  twi_masterBufferLength = length-1;  // This is not intuitive, read on...
136
+  // On receive, the previously configured ACK/NACK setting is transmitted in
137
+  // response to the received byte before the interrupt is signalled. 
138
+  // Therefor we must actually set NACK when the _next_ to last byte is
139
+  // received, causing that NACK to be sent in response to receiving the last
140
+  // expected byte of data.
141
+
142
+  // build sla+w, slave device address + w bit
143
+  twi_slarw = TW_READ;
144
+  twi_slarw |= address << 1;
145
+
146
+  if (true == twi_inRepStart) {
147
+    // if we're in the repeated start state, then we've already sent the start,
148
+    // (@@@ we hope), and the TWI statemachine is just waiting for the address byte.
149
+    // We need to remove ourselves from the repeated start state before we enable interrupts,
150
+    // since the ISR is ASYNC, and we could get confused if we hit the ISR before cleaning
151
+    // up. Also, don't enable the START interrupt. There may be one pending from the 
152
+    // repeated start that we sent outselves, and that would really confuse things.
153
+    twi_inRepStart = false;			// remember, we're dealing with an ASYNC ISR
154
+    TWDR = twi_slarw;
155
+    TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE);	// enable INTs, but not START
156
+  }
157
+  else
158
+    // send start condition
159
+    TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);
160
+
161
+  // wait for read operation to complete
162
+  while(TWI_MRX == twi_state){
163
+    continue;
164
+  }
165
+
166
+  if (twi_masterBufferIndex < length)
167
+    length = twi_masterBufferIndex;
168
+
169
+  // copy twi buffer to data
170
+  for(i = 0; i < length; ++i){
171
+    data[i] = twi_masterBuffer[i];
172
+  }
173
+	
174
+  return length;
175
+}
176
+
177
+/* 
178
+ * Function twi_writeTo
179
+ * Desc     attempts to become twi bus master and write a
180
+ *          series of bytes to a device on the bus
181
+ * Input    address: 7bit i2c device address
182
+ *          data: pointer to byte array
183
+ *          length: number of bytes in array
184
+ *          wait: boolean indicating to wait for write or not
185
+ *          sendStop: boolean indicating whether or not to send a stop at the end
186
+ * Output   0 .. success
187
+ *          1 .. length to long for buffer
188
+ *          2 .. address send, NACK received
189
+ *          3 .. data send, NACK received
190
+ *          4 .. other twi error (lost bus arbitration, bus error, ..)
191
+ */
192
+uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait, uint8_t sendStop)
193
+{
194
+  uint8_t i;
195
+
196
+  // ensure data will fit into buffer
197
+  if(TWI_BUFFER_LENGTH < length){
198
+    return 1;
199
+  }
200
+
201
+  // wait until twi is ready, become master transmitter
202
+  while(TWI_READY != twi_state){
203
+    continue;
204
+  }
205
+  twi_state = TWI_MTX;
206
+  twi_sendStop = sendStop;
207
+  // reset error state (0xFF.. no error occured)
208
+  twi_error = 0xFF;
209
+
210
+  // initialize buffer iteration vars
211
+  twi_masterBufferIndex = 0;
212
+  twi_masterBufferLength = length;
213
+  
214
+  // copy data to twi buffer
215
+  for(i = 0; i < length; ++i){
216
+    twi_masterBuffer[i] = data[i];
217
+  }
218
+  
219
+  // build sla+w, slave device address + w bit
220
+  twi_slarw = TW_WRITE;
221
+  twi_slarw |= address << 1;
222
+  
223
+  // if we're in a repeated start, then we've already sent the START
224
+  // in the ISR. Don't do it again.
225
+  //
226
+  if (true == twi_inRepStart) {
227
+    // if we're in the repeated start state, then we've already sent the start,
228
+    // (@@@ we hope), and the TWI statemachine is just waiting for the address byte.
229
+    // We need to remove ourselves from the repeated start state before we enable interrupts,
230
+    // since the ISR is ASYNC, and we could get confused if we hit the ISR before cleaning
231
+    // up. Also, don't enable the START interrupt. There may be one pending from the 
232
+    // repeated start that we sent outselves, and that would really confuse things.
233
+    twi_inRepStart = false;			// remember, we're dealing with an ASYNC ISR
234
+    TWDR = twi_slarw;				
235
+    TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE);	// enable INTs, but not START
236
+  }
237
+  else
238
+    // send start condition
239
+    TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE) | _BV(TWSTA);	// enable INTs
240
+
241
+  // wait for write operation to complete
242
+  while(wait && (TWI_MTX == twi_state)){
243
+    continue;
244
+  }
245
+  
246
+  if (twi_error == 0xFF)
247
+    return 0;	// success
248
+  else if (twi_error == TW_MT_SLA_NACK)
249
+    return 2;	// error: address send, nack received
250
+  else if (twi_error == TW_MT_DATA_NACK)
251
+    return 3;	// error: data send, nack received
252
+  else
253
+    return 4;	// other twi error
254
+}
255
+
256
+/* 
257
+ * Function twi_transmit
258
+ * Desc     fills slave tx buffer with data
259
+ *          must be called in slave tx event callback
260
+ * Input    data: pointer to byte array
261
+ *          length: number of bytes in array
262
+ * Output   1 length too long for buffer
263
+ *          2 not slave transmitter
264
+ *          0 ok
265
+ */
266
+uint8_t twi_transmit(const uint8_t* data, uint8_t length)
267
+{
268
+  uint8_t i;
269
+
270
+  // ensure data will fit into buffer
271
+  if(TWI_BUFFER_LENGTH < length){
272
+    return 1;
273
+  }
274
+  
275
+  // ensure we are currently a slave transmitter
276
+  if(TWI_STX != twi_state){
277
+    return 2;
278
+  }
279
+  
280
+  // set length and copy data into tx buffer
281
+  twi_txBufferLength = length;
282
+  for(i = 0; i < length; ++i){
283
+    twi_txBuffer[i] = data[i];
284
+  }
285
+  
286
+  return 0;
287
+}
288
+
289
+/* 
290
+ * Function twi_attachSlaveRxEvent
291
+ * Desc     sets function called before a slave read operation
292
+ * Input    function: callback function to use
293
+ * Output   none
294
+ */
295
+void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) )
296
+{
297
+  twi_onSlaveReceive = function;
298
+}
299
+
300
+/* 
301
+ * Function twi_attachSlaveTxEvent
302
+ * Desc     sets function called before a slave write operation
303
+ * Input    function: callback function to use
304
+ * Output   none
305
+ */
306
+void twi_attachSlaveTxEvent( void (*function)(void) )
307
+{
308
+  twi_onSlaveTransmit = function;
309
+}
310
+
311
+/* 
312
+ * Function twi_reply
313
+ * Desc     sends byte or readys receive line
314
+ * Input    ack: byte indicating to ack or to nack
315
+ * Output   none
316
+ */
317
+void twi_reply(uint8_t ack)
318
+{
319
+  // transmit master read ready signal, with or without ack
320
+  if(ack){
321
+    TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);
322
+  }else{
323
+	  TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT);
324
+  }
325
+}
326
+
327
+/* 
328
+ * Function twi_stop
329
+ * Desc     relinquishes bus master status
330
+ * Input    none
331
+ * Output   none
332
+ */
333
+void twi_stop(void)
334
+{
335
+  // send stop condition
336
+  TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);
337
+
338
+  // wait for stop condition to be exectued on bus
339
+  // TWINT is not set after a stop condition!
340
+  while(TWCR & _BV(TWSTO)){
341
+    continue;
342
+  }
343
+
344
+  // update twi state
345
+  twi_state = TWI_READY;
346
+}
347
+
348
+/* 
349
+ * Function twi_releaseBus
350
+ * Desc     releases bus control
351
+ * Input    none
352
+ * Output   none
353
+ */
354
+void twi_releaseBus(void)
355
+{
356
+  // release bus
357
+  TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);
358
+
359
+  // update twi state
360
+  twi_state = TWI_READY;
361
+}
362
+
363
+ISR(TWI_vect)
364
+{
365
+  switch(TW_STATUS){
366
+    // All Master
367
+    case TW_START:     // sent start condition
368
+    case TW_REP_START: // sent repeated start condition
369
+      // copy device address and r/w bit to output register and ack
370
+      TWDR = twi_slarw;
371
+      twi_reply(1);
372
+      break;
373
+
374
+    // Master Transmitter
375
+    case TW_MT_SLA_ACK:  // slave receiver acked address
376
+    case TW_MT_DATA_ACK: // slave receiver acked data
377
+      // if there is data to send, send it, otherwise stop 
378
+      if(twi_masterBufferIndex < twi_masterBufferLength){
379
+        // copy data to output register and ack
380
+        TWDR = twi_masterBuffer[twi_masterBufferIndex++];
381
+        twi_reply(1);
382
+      }else{
383
+	if (twi_sendStop)
384
+          twi_stop();
385
+	else {
386
+	  twi_inRepStart = true;	// we're gonna send the START
387
+	  // don't enable the interrupt. We'll generate the start, but we 
388
+	  // avoid handling the interrupt until we're in the next transaction,
389
+	  // at the point where we would normally issue the start.
390
+	  TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
391
+	  twi_state = TWI_READY;
392
+	}
393
+      }
394
+      break;
395
+    case TW_MT_SLA_NACK:  // address sent, nack received
396
+      twi_error = TW_MT_SLA_NACK;
397
+      twi_stop();
398
+      break;
399
+    case TW_MT_DATA_NACK: // data sent, nack received
400
+      twi_error = TW_MT_DATA_NACK;
401
+      twi_stop();
402
+      break;
403
+    case TW_MT_ARB_LOST: // lost bus arbitration
404
+      twi_error = TW_MT_ARB_LOST;
405
+      twi_releaseBus();
406
+      break;
407
+
408
+    // Master Receiver
409
+    case TW_MR_DATA_ACK: // data received, ack sent
410
+      // put byte into buffer
411
+      twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
412
+    case TW_MR_SLA_ACK:  // address sent, ack received
413
+      // ack if more bytes are expected, otherwise nack
414
+      if(twi_masterBufferIndex < twi_masterBufferLength){
415
+        twi_reply(1);
416
+      }else{
417
+        twi_reply(0);
418
+      }
419
+      break;
420
+    case TW_MR_DATA_NACK: // data received, nack sent
421
+      // put final byte into buffer
422
+      twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
423
+	if (twi_sendStop)
424
+          twi_stop();
425
+	else {
426
+	  twi_inRepStart = true;	// we're gonna send the START
427
+	  // don't enable the interrupt. We'll generate the start, but we 
428
+	  // avoid handling the interrupt until we're in the next transaction,
429
+	  // at the point where we would normally issue the start.
430
+	  TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
431
+	  twi_state = TWI_READY;
432
+	}    
433
+	break;
434
+    case TW_MR_SLA_NACK: // address sent, nack received
435
+      twi_stop();
436
+      break;
437
+    // TW_MR_ARB_LOST handled by TW_MT_ARB_LOST case
438
+
439
+    // Slave Receiver
440
+    case TW_SR_SLA_ACK:   // addressed, returned ack
441
+    case TW_SR_GCALL_ACK: // addressed generally, returned ack
442
+    case TW_SR_ARB_LOST_SLA_ACK:   // lost arbitration, returned ack
443
+    case TW_SR_ARB_LOST_GCALL_ACK: // lost arbitration, returned ack
444
+      // enter slave receiver mode
445
+      twi_state = TWI_SRX;
446
+      // indicate that rx buffer can be overwritten and ack
447
+      twi_rxBufferIndex = 0;
448
+      twi_reply(1);
449
+      break;
450
+    case TW_SR_DATA_ACK:       // data received, returned ack
451
+    case TW_SR_GCALL_DATA_ACK: // data received generally, returned ack
452
+      // if there is still room in the rx buffer
453
+      if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){
454
+        // put byte in buffer and ack
455
+        twi_rxBuffer[twi_rxBufferIndex++] = TWDR;
456
+        twi_reply(1);
457
+      }else{
458
+        // otherwise nack
459
+        twi_reply(0);
460
+      }
461
+      break;
462
+    case TW_SR_STOP: // stop or repeated start condition received
463
+      // put a null char after data if there's room
464
+      if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){
465
+        twi_rxBuffer[twi_rxBufferIndex] = '\0';
466
+      }
467
+      // sends ack and stops interface for clock stretching
468
+      twi_stop();
469
+      // callback to user defined callback
470
+      twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex);
471
+      // since we submit rx buffer to "wire" library, we can reset it
472
+      twi_rxBufferIndex = 0;
473
+      // ack future responses and leave slave receiver state
474
+      twi_releaseBus();
475
+      break;
476
+    case TW_SR_DATA_NACK:       // data received, returned nack
477
+    case TW_SR_GCALL_DATA_NACK: // data received generally, returned nack
478
+      // nack back at master
479
+      twi_reply(0);
480
+      break;
481
+    
482
+    // Slave Transmitter
483
+    case TW_ST_SLA_ACK:          // addressed, returned ack
484
+    case TW_ST_ARB_LOST_SLA_ACK: // arbitration lost, returned ack
485
+      // enter slave transmitter mode
486
+      twi_state = TWI_STX;
487
+      // ready the tx buffer index for iteration
488
+      twi_txBufferIndex = 0;
489
+      // set tx buffer length to be zero, to verify if user changes it
490
+      twi_txBufferLength = 0;
491
+      // request for txBuffer to be filled and length to be set
492
+      // note: user must call twi_transmit(bytes, length) to do this
493
+      twi_onSlaveTransmit();
494
+      // if they didn't change buffer & length, initialize it
495
+      if(0 == twi_txBufferLength){
496
+        twi_txBufferLength = 1;
497
+        twi_txBuffer[0] = 0x00;
498
+      }
499
+      // transmit first byte from buffer, fall
500
+    case TW_ST_DATA_ACK: // byte sent, ack returned
501
+      // copy data to output register
502
+      TWDR = twi_txBuffer[twi_txBufferIndex++];
503
+      // if there is more to send, ack, otherwise nack
504
+      if(twi_txBufferIndex < twi_txBufferLength){
505
+        twi_reply(1);
506
+      }else{
507
+        twi_reply(0);
508
+      }
509
+      break;
510
+    case TW_ST_DATA_NACK: // received nack, we are done 
511
+    case TW_ST_LAST_DATA: // received ack, but we are done already!
512
+      // ack future responses
513
+      twi_reply(1);
514
+      // leave slave receiver state
515
+      twi_state = TWI_READY;
516
+      break;
517
+
518
+    // All
519
+    case TW_NO_INFO:   // no state information
520
+      break;
521
+    case TW_BUS_ERROR: // bus error, illegal stop/start
522
+      twi_error = TW_BUS_ERROR;
523
+      twi_stop();
524
+      break;
525
+  }
526
+}
527
+

+ 53
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/libraries/Wire/utility/twi.h View File

@@ -0,0 +1,53 @@
1
+/*
2
+  twi.h - TWI/I2C library for Wiring & Arduino
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
4
+
5
+  This library is free software; you can redistribute it and/or
6
+  modify it under the terms of the GNU Lesser General Public
7
+  License as published by the Free Software Foundation; either
8
+  version 2.1 of the License, or (at your option) any later version.
9
+
10
+  This library is distributed in the hope that it will be useful,
11
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+  Lesser General Public License for more details.
14
+
15
+  You should have received a copy of the GNU Lesser General Public
16
+  License along with this library; if not, write to the Free Software
17
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+*/
19
+
20
+#ifndef twi_h
21
+#define twi_h
22
+
23
+  #include <inttypes.h>
24
+
25
+  //#define ATMEGA8
26
+
27
+  #ifndef TWI_FREQ
28
+  #define TWI_FREQ 100000L
29
+  #endif
30
+
31
+  #ifndef TWI_BUFFER_LENGTH
32
+  #define TWI_BUFFER_LENGTH 32
33
+  #endif
34
+
35
+  #define TWI_READY 0
36
+  #define TWI_MRX   1
37
+  #define TWI_MTX   2
38
+  #define TWI_SRX   3
39
+  #define TWI_STX   4
40
+  
41
+  void twi_init(void);
42
+  void twi_setAddress(uint8_t);
43
+  uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t);
44
+  uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t);
45
+  uint8_t twi_transmit(const uint8_t*, uint8_t);
46
+  void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) );
47
+  void twi_attachSlaveTxEvent( void (*)(void) );
48
+  void twi_reply(uint8_t);
49
+  void twi_stop(void);
50
+  void twi_releaseBus(void);
51
+
52
+#endif
53
+

+ 1
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/platform.local.txt View File

@@ -1 +1,2 @@
1 1
 compiler.cpp.extra_flags=-DHAS_AUTOMATIC_VERSIONING
2
+recipe.hooks.prebuild.pattern=/usr/local/bin/generate_version_header_for_marlin {build.source.path} {build.path}/_Version.h

+ 111
- 1
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/platform.txt View File

@@ -1,5 +1,5 @@
1 1
 
2
-# Marlin AVR Core and platform.
2
+# Arduino AVR Core and platform.
3 3
 # ------------------------------
4 4
 
5 5
 # For more info:
@@ -7,3 +7,113 @@
7 7
 
8 8
 name=Marlin AVR Boards
9 9
 version=1.5.6
10
+
11
+# AVR compile variables
12
+# ---------------------
13
+
14
+# Default "compiler.path" is correct, change only if you want to overidde the initial value
15
+compiler.path={runtime.ide.path}/hardware/tools/avr/bin/
16
+compiler.c.cmd=avr-gcc
17
+compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD
18
+# -w flag added to avoid printing a wrong warning http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
19
+# This is fixed in gcc 4.8.3 and will be removed as soon as we update the toolchain
20
+compiler.c.elf.flags=-w -Os -Wl,--gc-sections
21
+compiler.c.elf.cmd=avr-gcc
22
+compiler.S.flags=-c -g -x assembler-with-cpp
23
+compiler.cpp.cmd=avr-g++
24
+compiler.cpp.flags=-c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
25
+compiler.ar.cmd=avr-ar
26
+compiler.ar.flags=rcs
27
+compiler.objcopy.cmd=avr-objcopy
28
+compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
29
+compiler.elf2hex.flags=-O ihex -R .eeprom
30
+compiler.elf2hex.cmd=avr-objcopy
31
+compiler.ldflags=
32
+compiler.size.cmd=avr-size
33
+
34
+# This can be overriden in boards.txt
35
+build.extra_flags=
36
+
37
+# These can be overridden in platform.local.txt
38
+compiler.c.extra_flags=
39
+compiler.c.elf.extra_flags=
40
+compiler.S.extra_flags=
41
+compiler.cpp.extra_flags=
42
+compiler.ar.extra_flags=
43
+compiler.objcopy.eep.extra_flags=
44
+compiler.elf2hex.extra_flags=
45
+
46
+# AVR compile patterns
47
+# --------------------
48
+
49
+## Compile c files
50
+recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
51
+
52
+## Compile c++ files
53
+recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {compiler.cpp.extra_flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
54
+
55
+## Compile S files
56
+recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
57
+
58
+## Create archives
59
+recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}"
60
+
61
+## Combine gc-sections, archives, and objects
62
+recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm
63
+
64
+## Create eeprom
65
+recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep"
66
+
67
+## Create hex
68
+recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
69
+
70
+## Compute size
71
+recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
72
+recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*
73
+recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).*
74
+recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
75
+
76
+
77
+# AVR Uploader/Programmers tools
78
+# ------------------------------
79
+
80
+tools.avrdude.cmd.path={runtime.ide.path}/hardware/tools/avr/bin/avrdude
81
+tools.avrdude.config.path={runtime.ide.path}/hardware/tools/avr/etc/avrdude.conf
82
+
83
+tools.avrdude.upload.params.verbose=-v
84
+tools.avrdude.upload.params.quiet=-q -q
85
+tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"
86
+
87
+tools.avrdude.program.params.verbose=-v
88
+tools.avrdude.program.params.quiet=-q -q
89
+tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i"
90
+
91
+tools.avrdude.erase.params.verbose=-v
92
+tools.avrdude.erase.params.quiet=-q -q
93
+tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m
94
+
95
+tools.avrdude.bootloader.params.verbose=-v
96
+tools.avrdude.bootloader.params.quiet=-q -q
97
+tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.path}/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m
98
+
99
+tools.hidloader.cmd.path=/usr/local/bin/HIDUploader
100
+
101
+tools.hidloader.upload.params.verbose=-v
102
+tools.hidloader.upload.params.quiet=
103
+tools.hidloader.upload.pattern="{cmd.path}" --upload -mmcu={build.mcu} {upload.verbose} -w "{build.path}/{build.project_name}.hex"
104
+tools.nativehid.program.params.verbose=-v
105
+tools.nativehid.program.params.quiet=-q -q
106
+
107
+tools.hidloader.program.params.verbose=-v
108
+tools.hidloader.program.params.quiet=-q -q
109
+tools.hidloader.program.pattern="{cmd.path}" -mmcu={build.mcu} {upload.verbose} -w "{build.path}/{build.project_name}.hex"
110
+
111
+tools.hidloader.erase.params.verbose=-v
112
+tools.hidloader.erase.params.quiet=-q -q
113
+tools.hidloader.erase.pattern="{cmd.path}" --erase "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m
114
+
115
+# USB Default Flags
116
+# Default blank usb manufacturer will be filled it at compile time
117
+# - from numeric vendor ID, set to Unknown otherwise
118
+build.usb_manufacturer=
119
+build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'

+ 281
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/variants/brainwave/pins_arduino.h View File

@@ -0,0 +1,281 @@
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
+  Modified 2012 by Fredrik Hubinette
7
+
8
+  This library is free software; you can redistribute it and/or
9
+  modify it under the terms of the GNU Lesser General Public
10
+  License as published by the Free Software Foundation; either
11
+  version 2.1 of the License, or (at your option) any later version.
12
+
13
+  This library is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+  Lesser General Public License for more details.
17
+
18
+  You should have received a copy of the GNU Lesser General
19
+  Public License along with this library; if not, write to the
20
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
+  Boston, MA  02111-1307  USA
22
+
23
+  $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
24
+*/
25
+
26
+#ifndef Pins_Arduino_h
27
+#define Pins_Arduino_h
28
+
29
+#include <avr/pgmspace.h>
30
+
31
+#define NUM_DIGITAL_PINS            48
32
+#define NUM_ANALOG_INPUTS           8
33
+
34
+#define TX_RX_LED_INIT		DDRE |= (1<<7)
35
+#define TXLED0			0
36
+#define TXLED1			0
37
+#define RXLED0			PORTE |= (1<<7)
38
+#define RXLED1			PORTE &= ~(1<<7)
39
+
40
+static const uint8_t SDA = 0;
41
+static const uint8_t SCL = 1;
42
+
43
+// Map SPI port to 'new' pins D14..D17
44
+static const uint8_t SS   = 20;
45
+static const uint8_t MOSI = 22;
46
+static const uint8_t MISO = 23;
47
+static const uint8_t SCK  = 21;
48
+
49
+// Mapping of analog pins as digital I/O
50
+// A6-A11 share with digital pins
51
+static const uint8_t A0 = 38;   // F0
52
+static const uint8_t A1 = 39;   // F1
53
+static const uint8_t A2 = 40;   // F2
54
+static const uint8_t A3 = 41;   // F3
55
+static const uint8_t A4 = 42;   // F4
56
+static const uint8_t A5 = 43;   // F5
57
+static const uint8_t A6 = 44;	// F6
58
+static const uint8_t A7 = 45;	// F7
59
+
60
+#define analogInputToDigitalPin(p)  ((p < 16) ? (p) + 54 : -1)
61
+
62
+// Pins below still needs to be configured - Hubbe.
63
+
64
+#define digitalPinToPCICR(p)    ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
65
+#define digitalPinToPCICRbit(p) 0
66
+#define digitalPinToPCMSK(p)    ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
67
+#define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
68
+
69
+
70
+#define digitalPinHasPWM(p)         ((p) == 12 || (p) == 13 || (p) == 14 || (p) == 20 || (p) == 21 || (p) == 22)
71
+
72
+//	__AVR_ATmega32U4__ has an unusual mapping of pins to channels
73
+extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
74
+#define analogPinToChannel(P)  ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
75
+
76
+#ifdef ARDUINO_MAIN
77
+
78
+
79
+// these arrays map port names (e.g. port B) to the
80
+// appropriate addresses for various functions (e.g. reading
81
+// and writing)
82
+// Note PA == 1, PB == 2, etc. (GAH!)
83
+const uint16_t PROGMEM port_to_mode_PGM[] = {
84
+  NOT_A_PORT,
85
+  (uint16_t) &DDRA,
86
+  (uint16_t) &DDRB,
87
+  (uint16_t) &DDRC,
88
+  (uint16_t) &DDRD,
89
+  (uint16_t) &DDRE,
90
+};
91
+
92
+const uint16_t PROGMEM port_to_output_PGM[] = {
93
+  NOT_A_PORT,
94
+  (uint16_t) &PORTA,
95
+  (uint16_t) &PORTB,
96
+  (uint16_t) &PORTC,
97
+  (uint16_t) &PORTD,
98
+  (uint16_t) &PORTE,
99
+};
100
+
101
+const uint16_t PROGMEM port_to_input_PGM[] = {
102
+  NOT_A_PORT,
103
+  (uint16_t) &PINA,
104
+  (uint16_t) &PINB,
105
+  (uint16_t) &PINC,
106
+  (uint16_t) &PIND,
107
+  (uint16_t) &PINE,
108
+};
109
+
110
+const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
111
+  PA, // 0
112
+  PA,
113
+  PA,
114
+  PA,
115
+  PA,
116
+  PA,
117
+  PA,
118
+  PA,
119
+  PB, // 8
120
+  PB,
121
+  PB,
122
+  PB,
123
+  PB,
124
+  PB,
125
+  PB,
126
+  PB,
127
+  PC, // 16
128
+  PC,
129
+  PC,
130
+  PC,
131
+  PC,
132
+  PC,
133
+  PC,
134
+  PC,
135
+  PD, // 24
136
+  PD,
137
+  PD,
138
+  PD,
139
+  PD,
140
+  PD,
141
+  PD,
142
+  PD,
143
+  PE, // 32
144
+  PE,
145
+  PE,
146
+  PE,
147
+  PE,
148
+  PE,
149
+  PE,
150
+  PE, // 39 - PE7
151
+  PF, // 40 - A0 - PF0
152
+  PF,
153
+  PF,
154
+  PF,
155
+  PF,
156
+  PF,
157
+  PF,
158
+  PF, // 47 - A7 - PF7
159
+};
160
+
161
+const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
162
+  _BV(0), // PA0
163
+  _BV(1),
164
+  _BV(2),
165
+  _BV(3),
166
+  _BV(4),
167
+  _BV(5),
168
+  _BV(6),
169
+  _BV(7),
170
+  _BV(0), // PB0
171
+  _BV(1),
172
+  _BV(2),
173
+  _BV(3),
174
+  _BV(4),
175
+  _BV(5),
176
+  _BV(6),
177
+  _BV(7),
178
+  _BV(0), // PC0
179
+  _BV(1),
180
+  _BV(2),
181
+  _BV(3),
182
+  _BV(4),
183
+  _BV(5),
184
+  _BV(6),
185
+  _BV(7),
186
+  _BV(0), // PD0
187
+  _BV(1),
188
+  _BV(2),
189
+  _BV(3),
190
+  _BV(4),
191
+  _BV(5),
192
+  _BV(6),
193
+  _BV(7),
194
+  _BV(0), // PE0
195
+  _BV(1),
196
+  _BV(2),
197
+  _BV(3),
198
+  _BV(4),
199
+  _BV(5),
200
+  _BV(6),
201
+  _BV(7),
202
+  _BV(0), // PF0
203
+  _BV(1),
204
+  _BV(2),
205
+  _BV(3),
206
+  _BV(4),
207
+  _BV(5),
208
+  _BV(6),
209
+  _BV(7),
210
+};
211
+
212
+
213
+// TODO(unrepentantgeek) complete this map of PWM capable pins
214
+const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
215
+  NOT_ON_TIMER, //  0 - PA0
216
+  NOT_ON_TIMER, //  1 - PA1
217
+  NOT_ON_TIMER, //  2 - PA2
218
+  NOT_ON_TIMER, //  3 - PA3
219
+  NOT_ON_TIMER, //  4 - PA4
220
+  NOT_ON_TIMER, //  5 - PA5
221
+  NOT_ON_TIMER, //  6 - PA6
222
+  NOT_ON_TIMER, //  7 - PA7
223
+  NOT_ON_TIMER, //  8 - PB0
224
+  NOT_ON_TIMER, //  9 - PB1
225
+  NOT_ON_TIMER, // 10 - PB2
226
+  NOT_ON_TIMER, // 11 - PB3
227
+  TIMER2A,      // 12 - PB4
228
+  TIMER1A,      // 13 - PB5
229
+  TIMER1B,      // 14 - PB6
230
+  NOT_ON_TIMER, // 15 - PB7
231
+  NOT_ON_TIMER, // 16 - PC0
232
+  NOT_ON_TIMER, // 17 - PC1
233
+  NOT_ON_TIMER, // 18 - PC2
234
+  NOT_ON_TIMER, // 19 - PC3
235
+  TIMER3C,      // 20 - PC4
236
+  TIMER3B,      // 21 - PC5
237
+  TIMER3A,      // 22 - PC6
238
+  NOT_ON_TIMER, // 23 - PC7
239
+  NOT_ON_TIMER, // 24 - PD0
240
+  NOT_ON_TIMER, // 25 - PD1
241
+  NOT_ON_TIMER, // 26 - PD2
242
+  NOT_ON_TIMER, // 27 - PD3
243
+  NOT_ON_TIMER, // 28 - PD4
244
+  NOT_ON_TIMER, // 29 - PD5
245
+  NOT_ON_TIMER, // 30 - PD6
246
+  NOT_ON_TIMER, // 31 - PD7
247
+  NOT_ON_TIMER, // 32 - PE0
248
+  NOT_ON_TIMER, // 33 - PE1
249
+  NOT_ON_TIMER, // 34 - PE2
250
+  NOT_ON_TIMER, // 35 - PE3
251
+  NOT_ON_TIMER, // 36 - PE4
252
+  NOT_ON_TIMER, // 37 - PE5
253
+  NOT_ON_TIMER, // 38 - PE6
254
+  NOT_ON_TIMER, // 39 - PE7
255
+  NOT_ON_TIMER, // 40 - A0 - PF0
256
+  NOT_ON_TIMER, // 41 - A1 - PF1
257
+  NOT_ON_TIMER, // 42 - A2 - PF2
258
+  NOT_ON_TIMER, // 43 - A3 - PF3
259
+  NOT_ON_TIMER, // 44 - A4 - PF4
260
+  NOT_ON_TIMER, // 45 - A5 - PF5
261
+  NOT_ON_TIMER, // 46 - A6 - PF6
262
+  NOT_ON_TIMER, // 47 - A7 - PF7
263
+};
264
+
265
+const uint8_t PROGMEM analog_pin_to_channel_PGM[12] = {
266
+	7,	// A0				PF7					ADC7
267
+	6,	// A1				PF6					ADC6
268
+	5,	// A2				PF5					ADC5
269
+	4,	// A3				PF4					ADC4
270
+	1,	// A4				PF1					ADC1
271
+	0,	// A5				PF0					ADC0
272
+	8,	// A6		D4		PD4					ADC8
273
+	10,	// A7		D6		PD7					ADC10
274
+	11,	// A8		D8		PB4					ADC11
275
+	12,	// A9		D9		PB5					ADC12
276
+	13,	// A10		D10		PB6					ADC13
277
+	9	// A11		D12		PD6					ADC9
278
+};
279
+
280
+#endif /* ARDUINO_MAIN */
281
+#endif /* Pins_Arduino_h */

+ 278
- 0
ArduinoAddons/Arduino_1.5.x/hardware/marlin/avr/variants/brainwavepro/pins_arduino.h View File

@@ -0,0 +1,278 @@
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
+  Modified 2012 by Fredrik Hubinette
7
+  Modified 2014-2015 by Matthew Wilson
8
+
9
+  This library is free software; you can redistribute it and/or
10
+  modify it under the terms of the GNU Lesser General Public
11
+  License as published by the Free Software Foundation; either
12
+  version 2.1 of the License, or (at your option) any later version.
13
+
14
+  This library is distributed in the hope that it will be useful,
15
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
+  Lesser General Public License for more details.
18
+
19
+  You should have received a copy of the GNU Lesser General
20
+  Public License along with this library; if not, write to the
21
+  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
+  Boston, MA  02111-1307  USA
23
+
24
+  $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
25
+*/
26
+
27
+#ifndef Pins_Arduino_h
28
+#define Pins_Arduino_h
29
+
30
+#include <avr/pgmspace.h>
31
+
32
+#define NUM_DIGITAL_PINS            48
33
+#define NUM_ANALOG_INPUTS           8
34
+
35
+// PE7 is our status LED
36
+#define TX_RX_LED_INIT		DDRE |= (1<<7)
37
+#define TXLED0			0
38
+#define TXLED1			0
39
+#define RXLED0			PORTE |= (1<<7)
40
+#define RXLED1			PORTE &= ~(1<<7)
41
+
42
+static const uint8_t SDA = 1;
43
+static const uint8_t SCL = 0;
44
+
45
+// Map SPI port to 'new' pins D14..D17
46
+static const uint8_t SS   = 20;
47
+static const uint8_t MOSI = 22;
48
+static const uint8_t MISO = 23;
49
+static const uint8_t SCK  = 21;
50
+
51
+// Mapping of analog pins as digital I/O
52
+// A6-A11 share with digital pins
53
+static const uint8_t A0 = 38;   // F0
54
+static const uint8_t A1 = 39;   // F1
55
+static const uint8_t A2 = 40;   // F2
56
+static const uint8_t A3 = 41;   // F3
57
+static const uint8_t A4 = 42;   // F4
58
+static const uint8_t A5 = 43;   // F5
59
+static const uint8_t A6 = 44;	// F6
60
+static const uint8_t A7 = 45;	// F7
61
+
62
+#define analogInputToDigitalPin(p)  ((p < 8) ? (p) + 38 : -1)
63
+
64
+// Pins below still needs to be configured - Hubbe.
65
+
66
+#define digitalPinToPCICR(p)    ((((p) >= 0 && (p) <= 3) || ((p) >= 18 && (p) <= 19) || ((p) >= 36 && (p) <= 37)) ? (&PCICR) : ((uint8_t *)0))
67
+#define digitalPinToPCICRbit(p) 0
68
+#define digitalPinToPCMSK(p)    ((((p) >= 0 && (p) <= 3) || ((p) >= 18 && (p) <= 19) || ((p) >= 36 && (p) <= 37)) ? (&PCMSK0) : ((uint8_t *)0))
69
+#define digitalPinToPCMSKbit(p) ( ((p) >= 0 && (p) <= 3) ? (p) : ((p) == 18 ? 6 : ((p) == 19 ? 7 : ((p) == 36 ? 4 : ((p) == 37 ? 5 : (-1))))))
70
+
71
+#define digitalPinHasPWM(p)     ((p) == 0 || (p) == 1 || (p) == 14 || (p) == 15 || (p) == 16 || (p) == 24 || (p) == 25 || (p) == 26 || (p) == 27)
72
+
73
+//	__AVR_ATmega32U4__ has an unusual mapping of pins to channels
74
+extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
75
+#define analogPinToChannel(P)  ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
76
+
77
+#ifdef ARDUINO_MAIN
78
+
79
+
80
+// these arrays map port names (e.g. port B) to the
81
+// appropriate addresses for various functions (e.g. reading
82
+// and writing)
83
+// Note PA == 1, PB == 2, etc. (GAH!)
84
+const uint16_t PROGMEM port_to_mode_PGM[] = {
85
+  NOT_A_PORT,
86
+  (uint16_t) &DDRA,
87
+  (uint16_t) &DDRB,
88
+  (uint16_t) &DDRC,
89
+  (uint16_t) &DDRD,
90
+  (uint16_t) &DDRE,
91
+};
92
+
93
+const uint16_t PROGMEM port_to_output_PGM[] = {
94
+  NOT_A_PORT,
95
+  (uint16_t) &PORTA,
96
+  (uint16_t) &PORTB,
97
+  (uint16_t) &PORTC,
98
+  (uint16_t) &PORTD,
99
+  (uint16_t) &PORTE,
100
+};
101
+
102
+const uint16_t PROGMEM port_to_input_PGM[] = {
103
+  NOT_A_PORT,
104
+  (uint16_t) &PINA,
105
+  (uint16_t) &PINB,
106
+  (uint16_t) &PINC,
107
+  (uint16_t) &PIND,
108
+  (uint16_t) &PINE,
109
+};
110
+
111
+const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
112
+  PD, // 0  - PD0 - INT0 - PWM
113
+  PD, // 1  - PD1 - INT1 - PWM
114
+  PD, // 2  - PD2 - INT2 - RX
115
+  PD, // 3  - PD3 - INT3 - TX
116
+  PD, // 4  - PD4
117
+  PD, // 5  - PD5
118
+  PD, // 6  - PD6
119
+  PD, // 7  - PD7
120
+  PE, // 8  - PE0
121
+  PE, // 9  - PE1
122
+  PC, // 10 - PC0
123
+  PC, // 11 - PC1
124
+  PC, // 12 - PC2
125
+  PC, // 13 - PC3
126
+  PC, // 14 - PC4 - PWM
127
+  PC, // 15 - PC5 - PWM
128
+  PC, // 16 - PC6 - PWM
129
+  PC, // 17 - PC7
130
+  PE, // 18 - PE6 - INT6
131
+  PE, // 19 - PE7 - INT7
132
+  PB, // 20 - PB0
133
+  PB, // 21 - PB1
134
+  PB, // 22 - PB2
135
+  PB, // 23 - PB3
136
+  PB, // 24 - PB4 - PWM
137
+  PB, // 25 - PB5 - PWM
138
+  PB, // 26 - PB6 - PWM
139
+  PB, // 27 - PB7 - PWM
140
+  PA, // 28 - PA0
141
+  PA, // 29 - PA1
142
+  PA, // 30 - PA2
143
+  PA, // 31 - PA3
144
+  PA, // 32 - PA4
145
+  PA, // 33 - PA5
146
+  PA, // 34 - PA6
147
+  PA, // 35 - PA7
148
+  PE, // 36 - PE4 - INT4
149
+  PE, // 37 - PE5 - INT5
150
+  PF, // 38 - PF0 - A0
151
+  PF, // 39 - PF1 - A1
152
+  PF, // 40 - PF2 - A2
153
+  PF, // 41 - PF3 - A3
154
+  PF, // 42 - PF4 - A4
155
+  PF, // 43 - PF5 - A5
156
+  PF, // 44 - PF6 - A6
157
+  PF, // 45 - PF7 - A7
158
+  PE, // 46 - PE2 (not defined in teensy)
159
+  PE, // 47 - PE3 (not defined in teensy)
160
+};
161
+
162
+const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
163
+  _BV(0), // 0  - PD0 - INT0 - PWM
164
+  _BV(1), // 1  - PD1 - INT1 - PWM
165
+  _BV(2), // 2  - PD2 - INT2 - RX
166
+  _BV(3), // 3  - PD3 - INT3 - TX
167
+  _BV(4), // 4  - PD4
168
+  _BV(5), // 5  - PD5
169
+  _BV(6), // 6  - PD6
170
+  _BV(7), // 7  - PD7
171
+  _BV(0), // 8  - PE0
172
+  _BV(1), // 9  - PE1
173
+  _BV(0), // 10 - PC0
174
+  _BV(1), // 11 - PC1
175
+  _BV(2), // 12 - PC2
176
+  _BV(3), // 13 - PC3
177
+  _BV(4), // 14 - PC4 - PWM
178
+  _BV(5), // 15 - PC5 - PWM
179
+  _BV(6), // 16 - PC6 - PWM
180
+  _BV(7), // 17 - PC7
181
+  _BV(6), // 18 - PE6 - INT6
182
+  _BV(7), // 19 - PE7 - INT7
183
+  _BV(0), // 20 - PB0
184
+  _BV(1), // 21 - PB1
185
+  _BV(2), // 22 - PB2
186
+  _BV(3), // 23 - PB3
187
+  _BV(4), // 24 - PB4 - PWM
188
+  _BV(5), // 25 - PB5 - PWM
189
+  _BV(6), // 26 - PB6 - PWM
190
+  _BV(7), // 27 - PB7 - PWM
191
+  _BV(0), // 28 - PA0
192
+  _BV(1), // 29 - PA1
193
+  _BV(2), // 30 - PA2
194
+  _BV(3), // 31 - PA3
195
+  _BV(4), // 32 - PA4
196
+  _BV(5), // 33 - PA5
197
+  _BV(6), // 34 - PA6
198
+  _BV(7), // 35 - PA7
199
+  _BV(4), // 36 - PE4 - INT4
200
+  _BV(5), // 37 - PE5 - INT5
201
+  _BV(0), // 38 - PF0 - A0
202
+  _BV(1), // 39 - PF1 - A1
203
+  _BV(2), // 40 - PF2 - A2
204
+  _BV(3), // 41 - PF3 - A3
205
+  _BV(4), // 42 - PF4 - A4
206
+  _BV(5), // 43 - PF5 - A5
207
+  _BV(6), // 44 - PF6 - A6
208
+  _BV(7), // 45 - PF7 - A7
209
+  _BV(2), // 46 - PE2 (not defined in teensy)
210
+  _BV(3), // 47 - PE3 (not defined in teensy)
211
+};
212
+
213
+
214
+// TODO(unrepentantgeek) complete this map of PWM capable pins
215
+const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
216
+  TIMER0A,      // 0  - PD0 - INT0 - PWM
217
+  TIMER2B,      // 1  - PD1 - INT1 - PWM
218
+  NOT_ON_TIMER, // 2  - PD2 - INT2 - RX
219
+  NOT_ON_TIMER, // 3  - PD3 - INT3 - TX
220
+  NOT_ON_TIMER, // 4  - PD4
221
+  NOT_ON_TIMER, // 5  - PD5
222
+  NOT_ON_TIMER, // 6  - PD6
223
+  NOT_ON_TIMER, // 7  - PD7
224
+  NOT_ON_TIMER, // 8  - PE0
225
+  NOT_ON_TIMER, // 9  - PE1
226
+  NOT_ON_TIMER, // 10 - PC0
227
+  NOT_ON_TIMER, // 11 - PC1
228
+  NOT_ON_TIMER, // 12 - PC2
229
+  NOT_ON_TIMER, // 13 - PC3
230
+  TIMER3C,      // 14 - PC4 - PWM
231
+  TIMER3B,      // 15 - PC5 - PWM
232
+  TIMER3A,      // 16 - PC6 - PWM
233
+  NOT_ON_TIMER, // 17 - PC7
234
+  NOT_ON_TIMER, // 18 - PE6 - INT6
235
+  NOT_ON_TIMER, // 19 - PE7 - INT7
236
+  NOT_ON_TIMER, // 20 - PB0
237
+  NOT_ON_TIMER, // 21 - PB1
238
+  NOT_ON_TIMER, // 22 - PB2
239
+  NOT_ON_TIMER, // 23 - PB3
240
+  TIMER2A,      // 24 - PB4 - PWM
241
+  TIMER1A,      // 25 - PB5 - PWM
242
+  TIMER1B,      // 26 - PB6 - PWM
243
+  NOT_ON_TIMER, // 27 - PB7 - PWM  // This should be on TIMER1C
244
+  NOT_ON_TIMER, // 28 - PA0
245
+  NOT_ON_TIMER, // 29 - PA1
246
+  NOT_ON_TIMER, // 30 - PA2
247
+  NOT_ON_TIMER, // 31 - PA3
248
+  NOT_ON_TIMER, // 32 - PA4
249
+  NOT_ON_TIMER, // 33 - PA5
250
+  NOT_ON_TIMER, // 34 - PA6
251
+  NOT_ON_TIMER, // 35 - PA7
252
+  NOT_ON_TIMER, // 36 - PE4 - INT4
253
+  NOT_ON_TIMER, // 37 - PE5 - INT5
254
+  NOT_ON_TIMER, // 38 - PF0 - A0
255
+  NOT_ON_TIMER, // 39 - PF1 - A1
256
+  NOT_ON_TIMER, // 40 - PF2 - A2
257
+  NOT_ON_TIMER, // 41 - PF3 - A3
258
+  NOT_ON_TIMER, // 42 - PF4 - A4
259
+  NOT_ON_TIMER, // 43 - PF5 - A5
260
+  NOT_ON_TIMER, // 44 - PF6 - A6
261
+  NOT_ON_TIMER, // 45 - PF7 - A7
262
+  NOT_ON_TIMER, // 46 - PE2 (not defined in teensy)
263
+  NOT_ON_TIMER, // 47 - PE3 (not defined in teensy)
264
+};
265
+
266
+const uint8_t PROGMEM analog_pin_to_channel_PGM[8] = {
267
+	0,	// A0		PF0	ADC0
268
+	1,	// A1		PF1	ADC1
269
+	2,	// A2		PF2	ADC2
270
+	3,	// A3		PF3	ADC3
271
+	4,	// A4		PF4	ADC4
272
+	5,	// A5		PF5	ADC5
273
+	6,	// A6	  	PD6	ADC6
274
+	7,	// A7		PD7	ADC7
275
+};
276
+
277
+#endif /* ARDUINO_MAIN */
278
+#endif /* Pins_Arduino_h */

+ 2
- 2
Marlin/Conditionals.h View File

@@ -205,6 +205,8 @@
205 205
 
206 206
   #define CONDITIONALS_H
207 207
 
208
+  #include "pins.h"
209
+
208 210
   #ifndef AT90USB
209 211
     #define HardwareSerial_h // trick to disable the standard HWserial
210 212
   #endif
@@ -215,8 +217,6 @@
215 217
     #include "WProgram.h"
216 218
   #endif
217 219
 
218
-  #include "pins.h"
219
-
220 220
   /**
221 221
    * ENDSTOPPULLUPS
222 222
    */

+ 1
- 0
Marlin/Marlin.h View File

@@ -20,6 +20,7 @@
20 20
 
21 21
 #include "fastio.h"
22 22
 #include "Configuration.h"
23
+#include "pins.h"
23 24
 
24 25
 #ifndef SANITYCHECK_H
25 26
   #error Your Configuration.h and Configuration_adv.h files are outdated!

+ 4
- 0
Marlin/Marlin_main.cpp View File

@@ -213,6 +213,10 @@
213 213
  * M365 - SCARA calibration: Scaling factor, X, Y, Z axis
214 214
  * ************* SCARA End ***************
215 215
  *
216
+ * ************ Custom codes - This can change to suit future G-code regulations
217
+ * M851 - Set probe's Z offset (mm above extruder -- The value will always be negative)
218
+
219
+
216 220
  * M928 - Start SD logging (M928 filename.g) - ended by M29
217 221
  * M999 - Restart after being stopped by error
218 222
  *

+ 11
- 11
Marlin/SanityCheck.h View File

@@ -152,18 +152,18 @@
152 152
      * Check if Probe_Offset * Grid Points is greater than Probing Range
153 153
      */
154 154
     #ifdef AUTO_BED_LEVELING_GRID
155
-
156
-      // Make sure probing points are reachable
157
-      #if LEFT_PROBE_BED_POSITION < MIN_PROBE_X
158
-        #error "The given LEFT_PROBE_BED_POSITION can't be reached by the probe."
159
-      #elif RIGHT_PROBE_BED_POSITION > MAX_PROBE_X
160
-        #error "The given RIGHT_PROBE_BED_POSITION can't be reached by the probe."
161
-      #elif FRONT_PROBE_BED_POSITION < MIN_PROBE_Y
162
-        #error "The given FRONT_PROBE_BED_POSITION can't be reached by the probe."
163
-      #elif BACK_PROBE_BED_POSITION > MAX_PROBE_Y
164
-        #error "The given BACK_PROBE_BED_POSITION can't be reached by the probe."
155
+      #ifndef DELTA_PROBABLE_RADIUS
156
+        // Make sure probing points are reachable
157
+        #if LEFT_PROBE_BED_POSITION < MIN_PROBE_X
158
+          #error "The given LEFT_PROBE_BED_POSITION can't be reached by the probe."
159
+        #elif RIGHT_PROBE_BED_POSITION > MAX_PROBE_X
160
+          #error "The given RIGHT_PROBE_BED_POSITION can't be reached by the probe."
161
+        #elif FRONT_PROBE_BED_POSITION < MIN_PROBE_Y
162
+          #error "The given FRONT_PROBE_BED_POSITION can't be reached by the probe."
163
+        #elif BACK_PROBE_BED_POSITION > MAX_PROBE_Y
164
+          #error "The given BACK_PROBE_BED_POSITION can't be reached by the probe."
165
+        #endif
165 166
       #endif
166
-
167 167
       #define PROBE_SIZE_X (X_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1))
168 168
       #define PROBE_SIZE_Y (Y_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1))
169 169
       #define PROBE_AREA_WIDTH (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION)

+ 1083
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration.h
File diff suppressed because it is too large
View File


+ 660
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h View File

@@ -0,0 +1,660 @@
1
+// Example configuration file for OpenBeam Kossel Pro
2
+// tested on 2015-05-19 by @Wackerbarth
3
+// using Arduino 1.6.5 (Mac)
4
+
5
+#ifndef CONFIGURATION_ADV_H
6
+#define CONFIGURATION_ADV_H
7
+
8
+#include "Conditionals.h"
9
+
10
+// @section temperature
11
+
12
+//===========================================================================
13
+//=============================Thermal Settings  ============================
14
+//===========================================================================
15
+
16
+#ifdef BED_LIMIT_SWITCHING
17
+  #define BED_HYSTERESIS 2 //only disable heating if T>target+BED_HYSTERESIS and enable heating if T>target-BED_HYSTERESIS
18
+#endif
19
+#define BED_CHECK_INTERVAL 5000 //ms between checks in bang-bang control
20
+
21
+/**
22
+ * Heating Sanity Check
23
+ *
24
+ * Whenever an M104 or M109 increases the target temperature this will wait for WATCH_TEMP_PERIOD milliseconds,
25
+ * and if the temperature hasn't increased by WATCH_TEMP_INCREASE degrees, the machine is halted, requiring a
26
+ * hard reset. This test restarts with any M104/M109, but only if the current temperature is below the target
27
+ * by at least 2 * WATCH_TEMP_INCREASE degrees celsius.
28
+ */
29
+#ifdef THERMAL_RUNAWAY_PROTECTION_HOTENDS
30
+  #define THERMAL_RUNAWAY_PROTECTION_PERIOD 40        // Seconds
31
+  #define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 4     // Degrees Celsius
32
+
33
+  /**
34
+   * Whenever an M104 or M109 increases the target temperature the firmware will wait for the
35
+   * WATCH_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_TEMP_INCREASE
36
+   * degrees, the machine is halted, requiring a hard reset. This test restarts with any M104/M109,
37
+   * but only if the current temperature is far enough below the target for a reliable test.
38
+   */
39
+  #define WATCH_TEMP_PERIOD 16                // Seconds
40
+  #define WATCH_TEMP_INCREASE 4               // Degrees Celsius
41
+#endif
42
+
43
+#ifdef THERMAL_RUNAWAY_PROTECTION_BED
44
+  #define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 20    // Seconds
45
+  #define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius
46
+#endif
47
+
48
+#ifdef PIDTEMP
49
+  // this adds an experimental additional term to the heating power, proportional to the extrusion speed.
50
+  // if Kc is chosen well, the additional required power due to increased melting should be compensated.
51
+  #define PID_ADD_EXTRUSION_RATE
52
+  #ifdef PID_ADD_EXTRUSION_RATE
53
+    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+  #endif
55
+#endif
56
+
57
+
58
+//automatic temperature: The hot end target temperature is calculated by all the buffered lines of gcode.
59
+//The maximum buffered steps/sec of the extruder motor are called "se".
60
+//You enter the autotemp mode by a M109 S<mintemp> B<maxtemp> F<factor>
61
+// the target temperature is set to mintemp+factor*se[steps/sec] and limited by mintemp and maxtemp
62
+// you exit the value by any M109 without F*
63
+// Also, if the temperature is set to a value <mintemp, it is not changed by autotemp.
64
+// on an Ultimaker, some initial testing worked with M109 S215 B260 F1 in the start.gcode
65
+#define AUTOTEMP
66
+#ifdef AUTOTEMP
67
+  #define AUTOTEMP_OLDWEIGHT 0.98
68
+#endif
69
+
70
+//Show Temperature ADC value
71
+//The M105 command return, besides traditional information, the ADC value read from temperature sensors.
72
+//#define SHOW_TEMP_ADC_VALUES
73
+
74
+// @section extruder
75
+
76
+//  extruder run-out prevention.
77
+//if the machine is idle, and the temperature over MINTEMP, every couple of SECONDS some filament is extruded
78
+//#define EXTRUDER_RUNOUT_PREVENT
79
+#define EXTRUDER_RUNOUT_MINTEMP 190
80
+#define EXTRUDER_RUNOUT_SECONDS 30.
81
+#define EXTRUDER_RUNOUT_ESTEPS 14. //mm filament
82
+#define EXTRUDER_RUNOUT_SPEED 1500.  //extrusion speed
83
+#define EXTRUDER_RUNOUT_EXTRUDE 100
84
+
85
+// @section temperature
86
+
87
+//These defines help to calibrate the AD595 sensor in case you get wrong temperature measurements.
88
+//The measured temperature is defined as "actualTemp = (measuredTemp * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET"
89
+#define TEMP_SENSOR_AD595_OFFSET 0.0
90
+#define TEMP_SENSOR_AD595_GAIN   1.0
91
+
92
+//This is for controlling a fan to cool down the stepper drivers
93
+//it will turn on when any driver is enabled
94
+//and turn off after the set amount of seconds from last driver being disabled again
95
+#define CONTROLLERFAN_PIN -1 //Pin used for the fan to cool controller (-1 to disable)
96
+#define CONTROLLERFAN_SECS 60 //How many seconds, after all motors were disabled, the fan should run
97
+#define CONTROLLERFAN_SPEED 255  // == full speed
98
+
99
+// When first starting the main fan, run it at full speed for the
100
+// given number of milliseconds.  This gets the fan spinning reliably
101
+// before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu)
102
+//#define FAN_KICKSTART_TIME 100
103
+
104
+// @section extruder
105
+
106
+// Extruder cooling fans
107
+// Configure fan pin outputs to automatically turn on/off when the associated
108
+// extruder temperature is above/below EXTRUDER_AUTO_FAN_TEMPERATURE.
109
+// Multiple extruders can be assigned to the same pin in which case
110
+// the fan will turn on when any selected extruder is above the threshold.
111
+#define EXTRUDER_0_AUTO_FAN_PIN -1
112
+#define EXTRUDER_1_AUTO_FAN_PIN -1
113
+#define EXTRUDER_2_AUTO_FAN_PIN -1
114
+#define EXTRUDER_3_AUTO_FAN_PIN -1
115
+#define EXTRUDER_AUTO_FAN_TEMPERATURE 50
116
+#define EXTRUDER_AUTO_FAN_SPEED   255  // == full speed
117
+
118
+
119
+//===========================================================================
120
+//=============================Mechanical Settings===========================
121
+//===========================================================================
122
+
123
+// @section homing
124
+
125
+#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
126
+
127
+// @section extras
128
+
129
+//// AUTOSET LOCATIONS OF LIMIT SWITCHES
130
+//// Added by ZetaPhoenix 09-15-2012
131
+#ifdef MANUAL_HOME_POSITIONS  // Use manual limit switch locations
132
+  #define X_HOME_POS MANUAL_X_HOME_POS
133
+  #define Y_HOME_POS MANUAL_Y_HOME_POS
134
+  #define Z_HOME_POS MANUAL_Z_HOME_POS
135
+#else //Set min/max homing switch positions based upon homing direction and min/max travel limits
136
+  //X axis
137
+  #if X_HOME_DIR == -1
138
+    #ifdef BED_CENTER_AT_0_0
139
+      #define X_HOME_POS X_MAX_LENGTH * -0.5
140
+    #else
141
+      #define X_HOME_POS X_MIN_POS
142
+    #endif //BED_CENTER_AT_0_0
143
+  #else
144
+    #ifdef BED_CENTER_AT_0_0
145
+      #define X_HOME_POS X_MAX_LENGTH * 0.5
146
+    #else
147
+      #define X_HOME_POS X_MAX_POS
148
+    #endif //BED_CENTER_AT_0_0
149
+  #endif //X_HOME_DIR == -1
150
+
151
+  //Y axis
152
+  #if Y_HOME_DIR == -1
153
+    #ifdef BED_CENTER_AT_0_0
154
+      #define Y_HOME_POS Y_MAX_LENGTH * -0.5
155
+    #else
156
+      #define Y_HOME_POS Y_MIN_POS
157
+    #endif //BED_CENTER_AT_0_0
158
+  #else
159
+    #ifdef BED_CENTER_AT_0_0
160
+      #define Y_HOME_POS Y_MAX_LENGTH * 0.5
161
+    #else
162
+      #define Y_HOME_POS Y_MAX_POS
163
+    #endif //BED_CENTER_AT_0_0
164
+  #endif //Y_HOME_DIR == -1
165
+
166
+  // Z axis
167
+  #if Z_HOME_DIR == -1 //BED_CENTER_AT_0_0 not used
168
+    #define Z_HOME_POS Z_MIN_POS
169
+  #else
170
+    #define Z_HOME_POS Z_MAX_POS
171
+  #endif //Z_HOME_DIR == -1
172
+#endif //End auto min/max positions
173
+//END AUTOSET LOCATIONS OF LIMIT SWITCHES -ZP
174
+
175
+
176
+//#define Z_LATE_ENABLE // Enable Z the last moment. Needed if your Z driver overheats.
177
+
178
+// A single Z stepper driver is usually used to drive 2 stepper motors.
179
+// Uncomment this define to utilize a separate stepper driver for each Z axis motor.
180
+// Only a few motherboards support this, like RAMPS, which have dual extruder support (the 2nd, often unused, extruder driver is used
181
+// to control the 2nd Z axis stepper motor). The pins are currently only defined for a RAMPS motherboards.
182
+// On a RAMPS (or other 5 driver) motherboard, using this feature will limit you to using 1 extruder.
183
+//#define Z_DUAL_STEPPER_DRIVERS
184
+
185
+#ifdef Z_DUAL_STEPPER_DRIVERS
186
+  #undef EXTRUDERS
187
+  #define EXTRUDERS 1
188
+#endif
189
+
190
+// Same again but for Y Axis.
191
+//#define Y_DUAL_STEPPER_DRIVERS
192
+
193
+// Define if the two Y drives need to rotate in opposite directions
194
+#define INVERT_Y2_VS_Y_DIR true
195
+
196
+#ifdef Y_DUAL_STEPPER_DRIVERS
197
+  #undef EXTRUDERS
198
+  #define EXTRUDERS 1
199
+#endif
200
+
201
+#if defined (Z_DUAL_STEPPER_DRIVERS) && defined (Y_DUAL_STEPPER_DRIVERS)
202
+  #error "You cannot have dual drivers for both Y and Z"
203
+#endif
204
+
205
+// Enable this for dual x-carriage printers.
206
+// A dual x-carriage design has the advantage that the inactive extruder can be parked which
207
+// prevents hot-end ooze contaminating the print. It also reduces the weight of each x-carriage
208
+// allowing faster printing speeds.
209
+//#define DUAL_X_CARRIAGE
210
+#ifdef DUAL_X_CARRIAGE
211
+  // Configuration for second X-carriage
212
+  // Note: the first x-carriage is defined as the x-carriage which homes to the minimum endstop;
213
+  // the second x-carriage always homes to the maximum endstop.
214
+  #define X2_MIN_POS 80     // set minimum to ensure second x-carriage doesn't hit the parked first X-carriage
215
+  #define X2_MAX_POS 353    // set maximum to the distance between toolheads when both heads are homed
216
+  #define X2_HOME_DIR 1     // the second X-carriage always homes to the maximum endstop position
217
+  #define X2_HOME_POS X2_MAX_POS // default home position is the maximum carriage position
218
+      // However: In this mode the EXTRUDER_OFFSET_X value for the second extruder provides a software
219
+      // override for X2_HOME_POS. This also allow recalibration of the distance between the two endstops
220
+      // without modifying the firmware (through the "M218 T1 X???" command).
221
+      // Remember: you should set the second extruder x-offset to 0 in your slicer.
222
+
223
+  // Pins for second x-carriage stepper driver (defined here to avoid further complicating pins.h)
224
+  #define X2_ENABLE_PIN 29
225
+  #define X2_STEP_PIN 25
226
+  #define X2_DIR_PIN 23
227
+
228
+  // There are a few selectable movement modes for dual x-carriages using M605 S<mode>
229
+  //    Mode 0: Full control. The slicer has full control over both x-carriages and can achieve optimal travel results
230
+  //                           as long as it supports dual x-carriages. (M605 S0)
231
+  //    Mode 1: Auto-park mode. The firmware will automatically park and unpark the x-carriages on tool changes so
232
+  //                           that additional slicer support is not required. (M605 S1)
233
+  //    Mode 2: Duplication mode. The firmware will transparently make the second x-carriage and extruder copy all
234
+  //                           actions of the first x-carriage. This allows the printer to print 2 arbitrary items at
235
+  //                           once. (2nd extruder x offset and temp offset are set using: M605 S2 [Xnnn] [Rmmm])
236
+
237
+  // This is the default power-up mode which can be later using M605.
238
+  #define DEFAULT_DUAL_X_CARRIAGE_MODE 0
239
+
240
+  // Default settings in "Auto-park Mode"
241
+  #define TOOLCHANGE_PARK_ZLIFT   0.2      // the distance to raise Z axis when parking an extruder
242
+  #define TOOLCHANGE_UNPARK_ZLIFT 1        // the distance to raise Z axis when unparking an extruder
243
+
244
+  // Default x offset in duplication mode (typically set to half print bed width)
245
+  #define DEFAULT_DUPLICATION_X_OFFSET 100
246
+
247
+#endif //DUAL_X_CARRIAGE
248
+
249
+// @section homing
250
+
251
+//homing hits the endstop, then retracts by this distance, before it tries to slowly bump again:
252
+#define X_HOME_BUMP_MM 5
253
+#define Y_HOME_BUMP_MM 5
254
+#define Z_HOME_BUMP_MM 5 // deltas need the same for all three axis
255
+#define HOMING_BUMP_DIVISOR {10, 10, 20}  // Re-Bump Speed Divisor (Divides the Homing Feedrate)
256
+//#define QUICK_HOME  //if this is defined, if both x and y are to be homed, a diagonal move will be performed initially.
257
+
258
+// When G28 is called, this option will make Y home before X
259
+// #define HOME_Y_BEFORE_X
260
+
261
+// @section machine
262
+
263
+#define AXIS_RELATIVE_MODES {false, false, false, false}
264
+
265
+// @section machine
266
+
267
+#ifdef CONFIG_STEPPERS_TOSHIBA
268
+#define MAX_STEP_FREQUENCY 10000 // Max step frequency for Toshiba Stepper Controllers
269
+#else
270
+#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
271
+#endif
272
+//By default pololu step drivers require an active high signal. However, some high power drivers require an active low signal as step.
273
+#define INVERT_X_STEP_PIN false
274
+#define INVERT_Y_STEP_PIN false
275
+#define INVERT_Z_STEP_PIN false
276
+#define INVERT_E_STEP_PIN false
277
+
278
+// Default stepper release if idle. Set to 0 to deactivate.
279
+#define DEFAULT_STEPPER_DEACTIVE_TIME 60
280
+
281
+#define DEFAULT_MINIMUMFEEDRATE       0.0     // minimum feedrate
282
+#define DEFAULT_MINTRAVELFEEDRATE     0.0
283
+
284
+// @section lcd
285
+
286
+#ifdef ULTIPANEL
287
+  #define MANUAL_FEEDRATE {50*60, 50*60, 4*60, 60} // Feedrates for manual moves along X, Y, Z, E from panel
288
+  #define ULTIPANEL_FEEDMULTIPLY  // Comment to disable setting feedrate multiplier via encoder
289
+#endif
290
+
291
+// @section extras
292
+
293
+// minimum time in microseconds that a movement needs to take if the buffer is emptied.
294
+#define DEFAULT_MINSEGMENTTIME        20000
295
+
296
+// If defined the movements slow down when the look ahead buffer is only half full
297
+// (don't use SLOWDOWN with DELTA because DELTA generates hundreds of segments per second)
298
+//#define SLOWDOWN
299
+
300
+// Frequency limit
301
+// See nophead's blog for more info
302
+// Not working O
303
+//#define XY_FREQUENCY_LIMIT  15
304
+
305
+// Minimum planner junction speed. Sets the default minimum speed the planner plans for at the end
306
+// of the buffer and all stops. This should not be much greater than zero and should only be changed
307
+// if unwanted behavior is observed on a user's machine when running at very slow speeds.
308
+#define MINIMUM_PLANNER_SPEED 0.05// (mm/sec)
309
+
310
+// MS1 MS2 Stepper Driver Microstepping mode table
311
+#define MICROSTEP1 LOW,LOW
312
+#define MICROSTEP2 HIGH,LOW
313
+#define MICROSTEP4 LOW,HIGH
314
+#define MICROSTEP8 HIGH,HIGH
315
+#define MICROSTEP16 HIGH,HIGH
316
+
317
+// Microstep setting (Only functional when stepper driver microstep pins are connected to MCU.
318
+#define MICROSTEP_MODES {16,16,16,16,16} // [1,2,4,8,16]
319
+
320
+// Motor Current setting (Only functional when motor driver current ref pins are connected to a digital trimpot on supported boards)
321
+#define DIGIPOT_MOTOR_CURRENT {135,135,135,135,135} // Values 0-255 (RAMBO 135 = ~0.75A, 185 = ~1A)
322
+
323
+// uncomment to enable an I2C based DIGIPOT like on the Azteeg X3 Pro
324
+//#define DIGIPOT_I2C
325
+// Number of channels available for I2C digipot, For Azteeg X3 Pro we have 8
326
+#define DIGIPOT_I2C_NUM_CHANNELS 8
327
+// actual motor currents in Amps, need as many here as DIGIPOT_I2C_NUM_CHANNELS
328
+#define DIGIPOT_I2C_MOTOR_CURRENTS {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}
329
+
330
+//===========================================================================
331
+//=============================Additional Features===========================
332
+//===========================================================================
333
+
334
+//#define CHDK 4        //Pin for triggering CHDK to take a picture see how to use it here http://captain-slow.dk/2014/03/09/3d-printing-timelapses/
335
+#define CHDK_DELAY 50 //How long in ms the pin should stay HIGH before going LOW again
336
+
337
+// @section lcd
338
+
339
+#ifdef SDSUPPORT
340
+
341
+  // If you are using a RAMPS board or cheap E-bay purchased boards that do not detect when an SD card is inserted
342
+  // You can get round this by connecting a push button or single throw switch to the pin defined as SDCARDCARDDETECT
343
+  // in the pins.h file.  When using a push button pulling the pin to ground this will need inverted.  This setting should
344
+  // be commented out otherwise
345
+  #define SDCARDDETECTINVERTED
346
+
347
+  #define SD_FINISHED_STEPPERRELEASE true  //if sd support and the file is finished: disable steppers?
348
+  #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place.
349
+
350
+  #define SDCARD_RATHERRECENTFIRST  //reverse file order of sd card menu display. Its sorted practically after the file system block order.
351
+  // if a file is deleted, it frees a block. hence, the order is not purely chronological. To still have auto0.g accessible, there is again the option to do that.
352
+  // using:
353
+  //#define MENU_ADDAUTOSTART
354
+
355
+  // Show a progress bar on HD44780 LCDs for SD printing
356
+  //#define LCD_PROGRESS_BAR
357
+
358
+  #ifdef LCD_PROGRESS_BAR
359
+    // Amount of time (ms) to show the bar
360
+    #define PROGRESS_BAR_BAR_TIME 2000
361
+    // Amount of time (ms) to show the status message
362
+    #define PROGRESS_BAR_MSG_TIME 3000
363
+    // Amount of time (ms) to retain the status message (0=forever)
364
+    #define PROGRESS_MSG_EXPIRE   0
365
+    // Enable this to show messages for MSG_TIME then hide them
366
+    //#define PROGRESS_MSG_ONCE
367
+  #endif
368
+
369
+#endif // SDSUPPORT
370
+
371
+// for dogm lcd displays you can choose some additional fonts:
372
+#ifdef DOGLCD
373
+  // save 3120 bytes of PROGMEM by commenting out #define USE_BIG_EDIT_FONT
374
+  // we don't have a big font for Cyrillic, Kana
375
+  //#define USE_BIG_EDIT_FONT
376
+ 
377
+  // If you have spare 2300Byte of progmem and want to use a 
378
+  // smaller font on the Info-screen uncomment the next line.
379
+  //#define USE_SMALL_INFOFONT
380
+#endif // DOGLCD
381
+
382
+// @section more
383
+
384
+// The hardware watchdog should reset the microcontroller disabling all outputs, in case the firmware gets stuck and doesn't do temperature regulation.
385
+//#define USE_WATCHDOG
386
+
387
+#ifdef USE_WATCHDOG
388
+// If you have a watchdog reboot in an ArduinoMega2560 then the device will hang forever, as a watchdog reset will leave the watchdog on.
389
+// The "WATCHDOG_RESET_MANUAL" goes around this by not using the hardware reset.
390
+//  However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled.
391
+//#define WATCHDOG_RESET_MANUAL
392
+#endif
393
+
394
+// Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled.
395
+//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
396
+
397
+// @section lcd
398
+
399
+// Babystepping enables the user to control the axis in tiny amounts, independently from the normal printing process
400
+// it can e.g. be used to change z-positions in the print startup phase in real-time
401
+// does not respect endstops!
402
+//#define BABYSTEPPING
403
+#ifdef BABYSTEPPING
404
+  #define BABYSTEP_XY  //not only z, but also XY in the menu. more clutter, more functions
405
+  #define BABYSTEP_INVERT_Z false  //true for inverse movements in Z
406
+  #define BABYSTEP_Z_MULTIPLICATOR 2 //faster z movements
407
+
408
+// @section extruder
409
+  #ifdef COREXY
410
+    #error BABYSTEPPING not implemented for COREXY yet.
411
+  #endif
412
+
413
+  #ifdef DELTA
414
+    #ifdef BABYSTEP_XY
415
+      #error BABYSTEPPING only implemented for Z axis on deltabots.
416
+    #endif
417
+  #endif
418
+#endif
419
+
420
+// extruder advance constant (s2/mm3)
421
+//
422
+// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K * cubic mm per second ^ 2
423
+//
424
+// Hooke's law says:    force = k * distance
425
+// Bernoulli's principle says:  v ^ 2 / 2 + g . h + pressure / density = constant
426
+// so: v ^ 2 is proportional to number of steps we advance the extruder
427
+//#define ADVANCE
428
+
429
+#ifdef ADVANCE
430
+  #define EXTRUDER_ADVANCE_K .0
431
+
432
+  #define D_FILAMENT 2.85
433
+  #define STEPS_MM_E 836
434
+  #define EXTRUSION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
435
+  #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUSION_AREA)
436
+
437
+// @section extras
438
+#endif // ADVANCE
439
+
440
+// Arc interpretation settings:
441
+#define MM_PER_ARC_SEGMENT 1
442
+#define N_ARC_CORRECTION 25
443
+
444
+const unsigned int dropsegments=5; //everything with less than this number of steps will be ignored as move and joined with the next movement
445
+
446
+#ifdef ULTIPANEL
447
+ #undef SDCARDDETECTINVERTED
448
+#endif
449
+
450
+// Power Signal Control Definitions
451
+// By default use ATX definition
452
+#ifndef POWER_SUPPLY
453
+  #define POWER_SUPPLY 1
454
+#endif
455
+// 1 = ATX
456
+#if (POWER_SUPPLY == 1)
457
+  #define PS_ON_AWAKE  LOW
458
+  #define PS_ON_ASLEEP HIGH
459
+#endif
460
+// 2 = X-Box 360 203W
461
+#if (POWER_SUPPLY == 2)
462
+  #define PS_ON_AWAKE  HIGH
463
+  #define PS_ON_ASLEEP LOW
464
+#endif
465
+
466
+// Control heater 0 and heater 1 in parallel.
467
+//#define HEATERS_PARALLEL
468
+
469
+//===========================================================================
470
+//================================= Buffers =================================
471
+//===========================================================================
472
+
473
+// @section hidden
474
+
475
+// The number of linear motions that can be in the plan at any give time.
476
+// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ring-buffering.
477
+#if defined SDSUPPORT
478
+  #define BLOCK_BUFFER_SIZE 16   // SD,LCD,Buttons take more memory, block buffer needs to be smaller
479
+#else
480
+  #define BLOCK_BUFFER_SIZE 64 // maximize block buffer
481
+#endif
482
+
483
+// @section more
484
+
485
+//The ASCII buffer for receiving from the serial:
486
+#define MAX_CMD_SIZE 96
487
+#define BUFSIZE 4
488
+
489
+// Bad Serial-connections can miss a received command by sending an 'ok'
490
+// Therefore some clients abort after 30 seconds in a timeout.
491
+// Some other clients start sending commands while receiving a 'wait'.
492
+// This "wait" is only sent when the buffer is empty. 1 second is a good value here.
493
+//#define NO_TIMEOUTS 1000 // Milliseconds
494
+
495
+// Some clients will have this feature soon. This could make the NO_TIMEOUTS unnecessary.
496
+//#define ADVANCED_OK
497
+
498
+// @section fwretract
499
+
500
+// Firmware based and LCD controlled retract
501
+// M207 and M208 can be used to define parameters for the retraction.
502
+// The retraction can be called by the slicer using G10 and G11
503
+// until then, intended retractions can be detected by moves that only extrude and the direction.
504
+// the moves are than replaced by the firmware controlled ones.
505
+
506
+// #define FWRETRACT  //ONLY PARTIALLY TESTED
507
+#ifdef FWRETRACT
508
+  #define MIN_RETRACT 0.1                //minimum extruded mm to accept a automatic gcode retraction attempt
509
+  #define RETRACT_LENGTH 3               //default retract length (positive mm)
510
+  #define RETRACT_LENGTH_SWAP 13         //default swap retract length (positive mm), for extruder change
511
+  #define RETRACT_FEEDRATE 45            //default feedrate for retracting (mm/s)
512
+  #define RETRACT_ZLIFT 0                //default retract Z-lift
513
+  #define RETRACT_RECOVER_LENGTH 0       //default additional recover length (mm, added to retract length when recovering)
514
+  #define RETRACT_RECOVER_LENGTH_SWAP 0  //default additional swap recover length (mm, added to retract length when recovering from extruder change)
515
+  #define RETRACT_RECOVER_FEEDRATE 8     //default feedrate for recovering from retraction (mm/s)
516
+#endif
517
+
518
+// Add support for experimental filament exchange support M600; requires display
519
+#ifdef ULTIPANEL
520
+  #define FILAMENTCHANGEENABLE
521
+  #ifdef FILAMENTCHANGEENABLE
522
+    #define FILAMENTCHANGE_XPOS 3
523
+    #define FILAMENTCHANGE_YPOS 3
524
+    #define FILAMENTCHANGE_ZADD 10
525
+    #define FILAMENTCHANGE_FIRSTRETRACT -2
526
+    #define FILAMENTCHANGE_FINALRETRACT -100
527
+  #endif
528
+#endif
529
+
530
+/******************************************************************************\
531
+ * enable this section if you have TMC26X motor drivers. 
532
+ * you need to import the TMC26XStepper library into the arduino IDE for this
533
+ ******************************************************************************/
534
+
535
+// @section tmc
536
+
537
+//#define HAVE_TMCDRIVER
538
+#ifdef HAVE_TMCDRIVER
539
+
540
+//  #define X_IS_TMC
541
+  #define X_MAX_CURRENT 1000  //in mA
542
+  #define X_SENSE_RESISTOR 91 //in mOhms
543
+  #define X_MICROSTEPS 16     //number of microsteps
544
+  
545
+//  #define X2_IS_TMC
546
+  #define X2_MAX_CURRENT 1000  //in mA
547
+  #define X2_SENSE_RESISTOR 91 //in mOhms
548
+  #define X2_MICROSTEPS 16     //number of microsteps
549
+  
550
+//  #define Y_IS_TMC
551
+  #define Y_MAX_CURRENT 1000  //in mA
552
+  #define Y_SENSE_RESISTOR 91 //in mOhms
553
+  #define Y_MICROSTEPS 16     //number of microsteps
554
+  
555
+//  #define Y2_IS_TMC
556
+  #define Y2_MAX_CURRENT 1000  //in mA
557
+  #define Y2_SENSE_RESISTOR 91 //in mOhms
558
+  #define Y2_MICROSTEPS 16     //number of microsteps 
559
+  
560
+//  #define Z_IS_TMC
561
+  #define Z_MAX_CURRENT 1000  //in mA
562
+  #define Z_SENSE_RESISTOR 91 //in mOhms
563
+  #define Z_MICROSTEPS 16     //number of microsteps
564
+  
565
+//  #define Z2_IS_TMC
566
+  #define Z2_MAX_CURRENT 1000  //in mA
567
+  #define Z2_SENSE_RESISTOR 91 //in mOhms
568
+  #define Z2_MICROSTEPS 16     //number of microsteps
569
+  
570
+//  #define E0_IS_TMC
571
+  #define E0_MAX_CURRENT 1000  //in mA
572
+  #define E0_SENSE_RESISTOR 91 //in mOhms
573
+  #define E0_MICROSTEPS 16     //number of microsteps
574
+  
575
+//  #define E1_IS_TMC
576
+  #define E1_MAX_CURRENT 1000  //in mA
577
+  #define E1_SENSE_RESISTOR 91 //in mOhms
578
+  #define E1_MICROSTEPS 16     //number of microsteps 
579
+  
580
+//  #define E2_IS_TMC
581
+  #define E2_MAX_CURRENT 1000  //in mA
582
+  #define E2_SENSE_RESISTOR 91 //in mOhms
583
+  #define E2_MICROSTEPS 16     //number of microsteps 
584
+  
585
+//  #define E3_IS_TMC
586
+  #define E3_MAX_CURRENT 1000  //in mA
587
+  #define E3_SENSE_RESISTOR 91 //in mOhms
588
+  #define E3_MICROSTEPS 16     //number of microsteps   
589
+
590
+#endif
591
+
592
+#ifdef FILAMENTCHANGEENABLE
593
+  #ifdef EXTRUDER_RUNOUT_PREVENT
594
+    #error EXTRUDER_RUNOUT_PREVENT currently incompatible with FILAMENTCHANGE
595
+  #endif
596
+#endif
597
+
598
+//===========================================================================
599
+//=============================  Define Defines  ============================
600
+//===========================================================================
601
+#if EXTRUDERS > 1 && defined TEMP_SENSOR_1_AS_REDUNDANT
602
+  #error "You cannot use TEMP_SENSOR_1_AS_REDUNDANT if EXTRUDERS > 1"
603
+#endif
604
+
605
+#if EXTRUDERS > 1 && defined HEATERS_PARALLEL
606
+  #error "You cannot use HEATERS_PARALLEL if EXTRUDERS > 1"
607
+#endif
608
+
609
+#if TEMP_SENSOR_0 > 0
610
+  #define THERMISTORHEATER_0 TEMP_SENSOR_0
611
+  #define HEATER_0_USES_THERMISTOR
612
+#endif
613
+#if TEMP_SENSOR_1 > 0
614
+  #define THERMISTORHEATER_1 TEMP_SENSOR_1
615
+  #define HEATER_1_USES_THERMISTOR
616
+#endif
617
+#if TEMP_SENSOR_2 > 0
618
+  #define THERMISTORHEATER_2 TEMP_SENSOR_2
619
+  #define HEATER_2_USES_THERMISTOR
620
+#endif
621
+#if TEMP_SENSOR_BED > 0
622
+  #define THERMISTORBED TEMP_SENSOR_BED
623
+  #define BED_USES_THERMISTOR
624
+#endif
625
+#if TEMP_SENSOR_0 == -1
626
+  #define HEATER_0_USES_AD595
627
+#endif
628
+#if TEMP_SENSOR_1 == -1
629
+  #define HEATER_1_USES_AD595
630
+#endif
631
+#if TEMP_SENSOR_2 == -1
632
+  #define HEATER_2_USES_AD595
633
+#endif
634
+#if TEMP_SENSOR_BED == -1
635
+  #define BED_USES_AD595
636
+#endif
637
+#if TEMP_SENSOR_0 == -2
638
+  #define HEATER_0_USES_MAX6675
639
+#endif
640
+#if TEMP_SENSOR_0 == 0
641
+  #undef HEATER_0_MINTEMP
642
+  #undef HEATER_0_MAXTEMP
643
+#endif
644
+#if TEMP_SENSOR_1 == 0
645
+  #undef HEATER_1_MINTEMP
646
+  #undef HEATER_1_MAXTEMP
647
+#endif
648
+#if TEMP_SENSOR_2 == 0
649
+  #undef HEATER_2_MINTEMP
650
+  #undef HEATER_2_MAXTEMP
651
+#endif
652
+#if TEMP_SENSOR_BED == 0
653
+  #undef BED_MINTEMP
654
+  #undef BED_MAXTEMP
655
+#endif
656
+
657
+#include "Conditionals.h"
658
+#include "SanityCheck.h"
659
+
660
+#endif //CONFIGURATION_ADV_H

+ 5
- 0
Marlin/example_configurations/delta/kossel_pro/readme.md View File

@@ -0,0 +1,5 @@
1
+# Example Configuration for OpenBeam Kossel Pro [BRAINWAVE_PRO](http://www.openbeamusa.com/3d-printers/kossel/)
2
+* Configuration files for the **Openbeam Kossel Pro** as delivered in their KickStarter distribution
3
+
4
+I [@Wackerbarth](https://github.com/Wackerbarth) tested this version on my Kossel Pro and Arduino 1.6.5 for Mac.
5
+This configuration is a transition to merge Terence Tam's configuration with up-to-date Marlin source and a current Arduino IDE

Loading…
Cancel
Save