Bläddra i källkod

added arduino ide GEN7 support Files

Christian Thalhammer 12 år sedan
förälder
incheckning
25cd8af536
32 ändrade filer med 4404 tillägg och 0 borttagningar
  1. 101
    0
      Marlin/Gen7/boards.txt
  2. 113
    0
      Marlin/Gen7/bootloaders/Gen7/bootloader-1284P-16MHz.hex
  3. 75
    0
      Marlin/Gen7/bootloaders/Gen7/bootloader-644-16MHz.hex
  4. 75
    0
      Marlin/Gen7/bootloaders/Gen7/bootloader-644-20MHz.hex
  5. 75
    0
      Marlin/Gen7/bootloaders/Gen7/bootloader-644P-16MHz.hex
  6. 75
    0
      Marlin/Gen7/bootloaders/Gen7/bootloader-644P-20MHz.hex
  7. 239
    0
      Marlin/Gen7/cores/arduino/HardwareSerial.cpp
  8. 69
    0
      Marlin/Gen7/cores/arduino/HardwareSerial.h
  9. 243
    0
      Marlin/Gen7/cores/arduino/Makefile
  10. 203
    0
      Marlin/Gen7/cores/arduino/Print.cpp
  11. 59
    0
      Marlin/Gen7/cores/arduino/Print.h
  12. 515
    0
      Marlin/Gen7/cores/arduino/Tone.cpp
  13. 168
    0
      Marlin/Gen7/cores/arduino/WCharacter.h
  14. 1
    0
      Marlin/Gen7/cores/arduino/WConstants.h
  15. 87
    0
      Marlin/Gen7/cores/arduino/WInterrupts.c
  16. 60
    0
      Marlin/Gen7/cores/arduino/WMath.cpp
  17. 34
    0
      Marlin/Gen7/cores/arduino/WProgram.h
  18. 443
    0
      Marlin/Gen7/cores/arduino/WString.cpp
  19. 112
    0
      Marlin/Gen7/cores/arduino/WString.h
  20. 515
    0
      Marlin/Gen7/cores/arduino/binary.h
  21. 14
    0
      Marlin/Gen7/cores/arduino/main.cpp
  22. 12
    0
      Marlin/Gen7/cores/arduino/main.cxx
  23. 200
    0
      Marlin/Gen7/cores/arduino/pins_arduino.c
  24. 65
    0
      Marlin/Gen7/cores/arduino/pins_arduino.h
  25. 203
    0
      Marlin/Gen7/cores/arduino/wiring.c
  26. 133
    0
      Marlin/Gen7/cores/arduino/wiring.h
  27. 116
    0
      Marlin/Gen7/cores/arduino/wiring_analog.c
  28. 95
    0
      Marlin/Gen7/cores/arduino/wiring_digital.c
  29. 60
    0
      Marlin/Gen7/cores/arduino/wiring_private.h
  30. 66
    0
      Marlin/Gen7/cores/arduino/wiring_pulse.c
  31. 138
    0
      Marlin/Gen7/cores/arduino/wiring_serial.c
  32. 40
    0
      Marlin/Gen7/cores/arduino/wiring_shift.c

+ 101
- 0
Marlin/Gen7/boards.txt Visa fil

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

+ 113
- 0
Marlin/Gen7/bootloaders/Gen7/bootloader-1284P-16MHz.hex Visa fil

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

+ 75
- 0
Marlin/Gen7/bootloaders/Gen7/bootloader-644-16MHz.hex Visa fil

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

+ 75
- 0
Marlin/Gen7/bootloaders/Gen7/bootloader-644-20MHz.hex Visa fil

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

+ 75
- 0
Marlin/Gen7/bootloaders/Gen7/bootloader-644P-16MHz.hex Visa fil

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

+ 75
- 0
Marlin/Gen7/bootloaders/Gen7/bootloader-644P-20MHz.hex Visa fil

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

+ 239
- 0
Marlin/Gen7/cores/arduino/HardwareSerial.cpp Visa fil

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

+ 69
- 0
Marlin/Gen7/cores/arduino/HardwareSerial.h Visa fil

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

+ 243
- 0
Marlin/Gen7/cores/arduino/Makefile Visa fil

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

+ 203
- 0
Marlin/Gen7/cores/arduino/Print.cpp Visa fil

@@ -0,0 +1,203 @@
1
+/*
2
+ Print.cpp - Base class that provides print() and println()
3
+ Copyright (c) 2008 David A. Mellis.  All right reserved.
4
+ 
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+ 
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ Lesser General Public License for more details.
14
+ 
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+ 
19
+ Modified 23 November 2006 by David A. Mellis
20
+ */
21
+
22
+#include <stdio.h>
23
+#include <string.h>
24
+#include <inttypes.h>
25
+#include <math.h>
26
+#include "wiring.h"
27
+
28
+#include "Print.h"
29
+
30
+// Public Methods //////////////////////////////////////////////////////////////
31
+
32
+void Print::print(uint8_t b)
33
+{
34
+  this->write(b);
35
+}
36
+
37
+void Print::print(char c)
38
+{
39
+  print((byte) c);
40
+}
41
+
42
+void Print::print(const char c[])
43
+{
44
+  while (*c)
45
+    print(*c++);
46
+}
47
+
48
+void Print::print(int n)
49
+{
50
+  print((long) n);
51
+}
52
+
53
+void Print::print(unsigned int n)
54
+{
55
+  print((unsigned long) n);
56
+}
57
+
58
+void Print::print(long n)
59
+{
60
+  if (n < 0) {
61
+    print('-');
62
+    n = -n;
63
+  }
64
+  printNumber(n, 10);
65
+}
66
+
67
+void Print::print(unsigned long n)
68
+{
69
+  printNumber(n, 10);
70
+}
71
+
72
+void Print::print(long n, int base)
73
+{
74
+  if (base == 0)
75
+    print((char) n);
76
+  else if (base == 10)
77
+    print(n);
78
+  else
79
+    printNumber(n, base);
80
+}
81
+
82
+void Print::print(double n)
83
+{
84
+  printFloat(n, 2);
85
+}
86
+
87
+void Print::println(void)
88
+{
89
+  print('\r');
90
+  print('\n');  
91
+}
92
+
93
+void Print::println(char c)
94
+{
95
+  print(c);
96
+  println();  
97
+}
98
+
99
+void Print::println(const char c[])
100
+{
101
+  print(c);
102
+  println();
103
+}
104
+
105
+void Print::println(uint8_t b)
106
+{
107
+  print(b);
108
+  println();
109
+}
110
+
111
+void Print::println(int n)
112
+{
113
+  print(n);
114
+  println();
115
+}
116
+
117
+void Print::println(unsigned int n)
118
+{
119
+  print(n);
120
+  println();
121
+}
122
+
123
+void Print::println(long n)
124
+{
125
+  print(n);
126
+  println();  
127
+}
128
+
129
+void Print::println(unsigned long n)
130
+{
131
+  print(n);
132
+  println();  
133
+}
134
+
135
+void Print::println(long n, int base)
136
+{
137
+  print(n, base);
138
+  println();
139
+}
140
+
141
+void Print::println(double n)
142
+{
143
+  print(n);
144
+  println();
145
+}
146
+
147
+// Private Methods /////////////////////////////////////////////////////////////
148
+
149
+void Print::printNumber(unsigned long n, uint8_t base)
150
+{
151
+  unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
152
+  unsigned long i = 0;
153
+
154
+  if (n == 0) {
155
+    print('0');
156
+    return;
157
+  } 
158
+
159
+  while (n > 0) {
160
+    buf[i++] = n % base;
161
+    n /= base;
162
+  }
163
+
164
+  for (; i > 0; i--)
165
+    print((char) (buf[i - 1] < 10 ?
166
+      '0' + buf[i - 1] :
167
+      'A' + buf[i - 1] - 10));
168
+}
169
+
170
+void Print::printFloat(double number, uint8_t digits) 
171
+{ 
172
+  // Handle negative numbers
173
+  if (number < 0.0)
174
+  {
175
+     print('-');
176
+     number = -number;
177
+  }
178
+
179
+  // Round correctly so that print(1.999, 2) prints as "2.00"
180
+  double rounding = 0.5;
181
+  for (uint8_t i=0; i<digits; ++i)
182
+    rounding /= 10.0;
183
+  
184
+  number += rounding;
185
+
186
+  // Extract the integer part of the number and print it
187
+  unsigned long int_part = (unsigned long)number;
188
+  double remainder = number - (double)int_part;
189
+  print(int_part);
190
+
191
+  // Print the decimal point, but only if there are digits beyond
192
+  if (digits > 0)
193
+    print("."); 
194
+
195
+  // Extract digits from the remainder one at a time
196
+  while (digits-- > 0)
197
+  {
198
+    remainder *= 10.0;
199
+    int toPrint = int(remainder);
200
+    print(toPrint);
201
+    remainder -= toPrint; 
202
+  } 
203
+}

+ 59
- 0
Marlin/Gen7/cores/arduino/Print.h Visa fil

@@ -0,0 +1,59 @@
1
+/*
2
+  Print.h - Base class that provides print() and println()
3
+  Copyright (c) 2008 David A. Mellis.  All right reserved.
4
+
5
+  This library is free software; you can redistribute it and/or
6
+  modify it under the terms of the GNU Lesser General Public
7
+  License as published by the Free Software Foundation; either
8
+  version 2.1 of the License, or (at your option) any later version.
9
+
10
+  This library is distributed in the hope that it will be useful,
11
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+  Lesser General Public License for more details.
14
+
15
+  You should have received a copy of the GNU Lesser General Public
16
+  License along with this library; if not, write to the Free Software
17
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+*/
19
+
20
+#ifndef Print_h
21
+#define Print_h
22
+
23
+#include <inttypes.h>
24
+
25
+#define DEC 10
26
+#define HEX 16
27
+#define OCT 8
28
+#define BIN 2
29
+#define BYTE 0
30
+
31
+class Print
32
+{
33
+  private:
34
+    void printNumber(unsigned long, uint8_t);
35
+    void printFloat(double, uint8_t);
36
+  public:
37
+    virtual void write(uint8_t);
38
+    void print(char);
39
+    void print(const char[]);
40
+    void print(uint8_t);
41
+    void print(int);
42
+    void print(unsigned int);
43
+    void print(long);
44
+    void print(unsigned long);
45
+    void print(long, int);
46
+    void print(double);
47
+    void println(void);
48
+    void println(char);
49
+    void println(const char[]);
50
+    void println(uint8_t);
51
+    void println(int);
52
+    void println(unsigned int);
53
+    void println(long);
54
+    void println(unsigned long);
55
+    void println(long, int);
56
+    void println(double);
57
+};
58
+
59
+#endif

+ 515
- 0
Marlin/Gen7/cores/arduino/Tone.cpp Visa fil

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

+ 168
- 0
Marlin/Gen7/cores/arduino/WCharacter.h Visa fil

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

+ 1
- 0
Marlin/Gen7/cores/arduino/WConstants.h Visa fil

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

+ 87
- 0
Marlin/Gen7/cores/arduino/WInterrupts.c Visa fil

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

+ 60
- 0
Marlin/Gen7/cores/arduino/WMath.cpp Visa fil

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

+ 34
- 0
Marlin/Gen7/cores/arduino/WProgram.h Visa fil

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

+ 443
- 0
Marlin/Gen7/cores/arduino/WString.cpp Visa fil

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

+ 112
- 0
Marlin/Gen7/cores/arduino/WString.h Visa fil

@@ -0,0 +1,112 @@
1
+/*
2
+  WString.h - String library for Wiring & Arduino
3
+  Copyright (c) 2009-10 Hernando Barragan.  All right reserved.
4
+
5
+  This library is free software; you can redistribute it and/or
6
+  modify it under the terms of the GNU Lesser General Public
7
+  License as published by the Free Software Foundation; either
8
+  version 2.1 of the License, or (at your option) any later version.
9
+
10
+  This library is distributed in the hope that it will be useful,
11
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+  Lesser General Public License for more details.
14
+
15
+  You should have received a copy of the GNU Lesser General Public
16
+  License along with this library; if not, write to the Free Software
17
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+*/
19
+
20
+#ifndef String_h
21
+#define String_h
22
+
23
+//#include "WProgram.h"
24
+#include <stdlib.h>
25
+#include <string.h>
26
+#include <ctype.h>
27
+
28
+class String
29
+{
30
+  public:
31
+    // constructors
32
+    String( const char *value = "" );
33
+    String( const String &value );
34
+    String( const char );
35
+    String( const unsigned char );
36
+    String( const int, const int base=10);
37
+    String( const unsigned int, const int base=10 );
38
+    String( const long, const int base=10 );
39
+    String( const unsigned long, const int base=10 );
40
+    ~String() { free(_buffer); _length = _capacity = 0;}     //added _length = _capacity = 0;
41
+
42
+    // operators
43
+    const String & operator = ( const String &rhs );
44
+    const String & operator +=( const String &rhs );
45
+    //const String & operator +=( const char );
46
+    int operator ==( const String &rhs ) const;
47
+    int	operator !=( const String &rhs ) const;
48
+    int	operator < ( const String &rhs ) const;
49
+    int	operator > ( const String &rhs ) const;
50
+    int	operator <=( const String &rhs ) const;
51
+    int	operator >=( const String &rhs ) const;
52
+    char operator []( unsigned int index ) const;
53
+    char& operator []( unsigned int index );
54
+    //operator const char *() const { return _buffer; }
55
+    
56
+    // general methods
57
+    char charAt( unsigned int index ) const;
58
+    int	compareTo( const String &anotherString ) const;
59
+    unsigned char endsWith( const String &suffix ) const;
60
+    unsigned char equals( const String &anObject ) const;
61
+    unsigned char equalsIgnoreCase( const String &anotherString ) const;
62
+    int	indexOf( char ch ) const;
63
+    int	indexOf( char ch, unsigned int fromIndex ) const;
64
+    int	indexOf( const String &str ) const;
65
+    int	indexOf( const String &str, unsigned int fromIndex ) const;
66
+    int	lastIndexOf( char ch ) const;
67
+    int	lastIndexOf( char ch, unsigned int fromIndex ) const;
68
+    int	lastIndexOf( const String &str ) const;
69
+    int	lastIndexOf( const String &str, unsigned int fromIndex ) const;
70
+    const unsigned int length( ) const { return _length; }
71
+    void setCharAt(unsigned int index, const char ch);
72
+    unsigned char startsWith( const String &prefix ) const;
73
+    unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
74
+    String substring( unsigned int beginIndex ) const;
75
+    String substring( unsigned int beginIndex, unsigned int endIndex ) const;
76
+    String toLowerCase( ) const;
77
+    String toUpperCase( ) const;
78
+    String trim( ) const;
79
+    void getBytes(unsigned char *buf, unsigned int bufsize);
80
+    void toCharArray(char *buf, unsigned int bufsize);
81
+    long toInt( );
82
+    const String& concat( const String &str );
83
+    String replace( char oldChar, char newChar );
84
+    String replace( const String& match, const String& replace );
85
+    friend String operator + ( String lhs, const String &rhs );
86
+
87
+  protected:
88
+    char *_buffer;	     // the actual char array
89
+    unsigned int _capacity;  // the array length minus one (for the '\0')
90
+    unsigned int _length;    // the String length (not counting the '\0')
91
+
92
+    void getBuffer(unsigned int maxStrLen);
93
+
94
+  private:
95
+
96
+};
97
+
98
+// allocate buffer space
99
+inline void String::getBuffer(unsigned int maxStrLen)
100
+{
101
+  _capacity = maxStrLen;
102
+  _buffer = (char *) malloc(_capacity + 1);
103
+  if (_buffer == NULL) _length = _capacity = 0;
104
+}
105
+
106
+inline String operator+( String lhs, const String &rhs )
107
+{
108
+  return lhs += rhs;
109
+}
110
+
111
+
112
+#endif

+ 515
- 0
Marlin/Gen7/cores/arduino/binary.h Visa fil

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

+ 14
- 0
Marlin/Gen7/cores/arduino/main.cpp Visa fil

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

+ 12
- 0
Marlin/Gen7/cores/arduino/main.cxx Visa fil

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

+ 200
- 0
Marlin/Gen7/cores/arduino/pins_arduino.c Visa fil

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

+ 65
- 0
Marlin/Gen7/cores/arduino/pins_arduino.h Visa fil

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

+ 203
- 0
Marlin/Gen7/cores/arduino/wiring.c Visa fil

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

+ 133
- 0
Marlin/Gen7/cores/arduino/wiring.h Visa fil

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

+ 116
- 0
Marlin/Gen7/cores/arduino/wiring_analog.c Visa fil

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

+ 95
- 0
Marlin/Gen7/cores/arduino/wiring_digital.c Visa fil

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

+ 60
- 0
Marlin/Gen7/cores/arduino/wiring_private.h Visa fil

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

+ 66
- 0
Marlin/Gen7/cores/arduino/wiring_pulse.c Visa fil

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

+ 138
- 0
Marlin/Gen7/cores/arduino/wiring_serial.c Visa fil

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

+ 40
- 0
Marlin/Gen7/cores/arduino/wiring_shift.c Visa fil

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

Laddar…
Avbryt
Spara