├── hardware ├── tiny │ ├── boards.txt │ ├── bootloaders │ │ └── empty │ │ │ ├── empty2313at1.hex │ │ │ ├── empty2313at8.hex │ │ │ ├── empty24at16.hex │ │ │ ├── empty25at1.hex │ │ │ ├── empty25at8.hex │ │ │ ├── empty4313at1.hex │ │ │ ├── empty4313at8.hex │ │ │ ├── empty44at1.hex │ │ │ ├── empty44at8.hex │ │ │ ├── empty45at1.hex │ │ │ ├── empty45at8.hex │ │ │ ├── empty84at1.hex │ │ │ ├── empty84at16.hex │ │ │ ├── empty84at8.hex │ │ │ ├── empty85at1.hex │ │ │ ├── empty85at16.hex │ │ │ └── empty85at8.hex │ └── cores │ │ ├── empty │ │ ├── Arduino.h │ │ ├── WProgram.h │ │ └── main.cpp │ │ └── tiny │ │ ├── Arduino.h │ │ ├── HardwareSerial.cpp │ │ ├── HardwareSerial.h │ │ ├── Print.cpp │ │ ├── Print.h │ │ ├── PwmTimer.h │ │ ├── Stream.h │ │ ├── TinyDebugSerial.cpp │ │ ├── TinyDebugSerial.h │ │ ├── TinyDebugSerial115200.cpp │ │ ├── TinyDebugSerial38400.cpp │ │ ├── TinyDebugSerial9600.cpp │ │ ├── TinyDebugSerialErrors.cpp │ │ ├── Tone.cpp │ │ ├── ToneTimer.h │ │ ├── UserTimer.h │ │ ├── WCharacter.h │ │ ├── WConstants.h │ │ ├── WInterrupts.c │ │ ├── WMath.cpp │ │ ├── WProgram.h │ │ ├── WString.cpp │ │ ├── WString.h │ │ ├── binary.h │ │ ├── core_adc.h │ │ ├── core_build_options.h │ │ ├── core_macros.h │ │ ├── core_pins.h │ │ ├── core_timers.h │ │ ├── main.cpp │ │ ├── pins_arduino.c │ │ ├── pins_arduino.h │ │ ├── wiring.c │ │ ├── wiring.h │ │ ├── wiring_analog.c │ │ ├── wiring_digital.c │ │ ├── wiring_private.h │ │ ├── wiring_pulse.c │ │ └── wiring_shift.c └── tools │ └── avr │ └── avr │ └── include │ └── avr │ └── eeprom.h ├── libraries ├── PinChangeInterrupt │ ├── PinChangeInterrupt.cpp │ ├── PinChangeInterrupt.h │ ├── keywords.txt │ ├── license.txt │ └── readme.txt ├── PinChangeInterruptSimple │ ├── PinChangeInterruptSimple.cpp │ ├── PinChangeInterruptSimple.h │ ├── keywords.txt │ ├── license.txt │ └── readme.txt └── TinyTuner │ ├── TinyTuner.cpp │ ├── TinyTuner.h │ ├── examples │ ├── Interactive_to_Serial │ │ └── Interactive_to_Serial.pde │ ├── Interactive_to_Serial_with_Details │ │ └── Interactive_to_Serial_with_Details.pde │ ├── Interactive_with_NewSoftSerial │ │ └── Interactive_with_NewSoftSerial.pde │ ├── Read_from_EEPROM │ │ └── Read_from_EEPROM.pde │ └── Save_to_EEPROM │ │ ├── Save_to_EEPROM.pde │ │ └── s2eLed.h │ ├── keywords.txt │ ├── license.txt │ └── readme.txt ├── license.txt └── readme.txt /hardware/tiny/bootloaders/empty/empty2313at1.hex: -------------------------------------------------------------------------------- 1 | :1000000012C02AC029C028C027C026C02CC024C0C6 2 | :1000100023C022C021C020C01FC01EC01DC01CC0E4 3 | :100020001BC01AC019C011241FBECFEDCDBF10E0F8 4 | :10003000A0E6B0E0ECE4F1E002C005900D92A0363D 5 | :10004000B107D9F710E0A0E6B0E001C01D92A936D3 6 | :10005000B107E1F704D078C0D3CF0895089557D001 7 | :10006000FCDFFCDFFECF1F920F920FB60F92112420 8 | :100070002F933F934F935F936F937F938F939F93B0 9 | :10008000AF93BF932091640030916500409166006A 10 | :100090005091670070916800DA01C9010296A11DB4 11 | :1000A000B11D672F6A5F6D3730F06D57DA01C901F6 12 | :1000B0000396A11DB11D6093680080936400909326 13 | :1000C0006500A0936600B0936700809160009091F6 14 | :1000D0006100A0916200B09163000196A11DB11D65 15 | :1000E0008093600090936100A0936200B0936300DE 16 | :1000F000BF91AF919F918F917F916F915F914F9140 17 | :100100003F912F910F900FBE0F901F9018957894EC 18 | :1001100080B7836080BF83B7877F83BF83B7887FC3 19 | :10012000826083BF89B7826089BF8EB5887F8EBDAC 20 | :100130008FB58C7F81608FBD8EB5877E8EBD8EB56D 21 | :0C014000887F82608EBD0895F894FFCF88 22 | :00000001FF 23 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty2313at8.hex: -------------------------------------------------------------------------------- 1 | :1000000012C02AC029C028C027C026C02CC024C0C6 2 | :1000100023C022C021C020C01FC01EC01DC01CC0E4 3 | :100020001BC01AC019C011241FBECFEDCDBF10E0F8 4 | :10003000A0E6B0E0ECE4F1E002C005900D92A0363D 5 | :10004000B107D9F710E0A0E6B0E001C01D92A936D3 6 | :10005000B107E1F704D078C0D3CF0895089557D001 7 | :10006000FCDFFCDFFECF1F920F920FB60F92112420 8 | :100070002F933F934F935F936F937F938F939F93B0 9 | :10008000AF93BF932091640030916500409166006A 10 | :100090005091670070916800DA01C9010296A11DB4 11 | :1000A000B11D672F6A5F6D3730F06D57DA01C901F6 12 | :1000B0000396A11DB11D6093680080936400909326 13 | :1000C0006500A0936600B0936700809160009091F6 14 | :1000D0006100A0916200B09163000196A11DB11D65 15 | :1000E0008093600090936100A0936200B0936300DE 16 | :1000F000BF91AF919F918F917F916F915F914F9140 17 | :100100003F912F910F900FBE0F901F9018957894EC 18 | :1001100080B7836080BF83B7877F83BF83B7887FC3 19 | :10012000836083BF89B7826089BF8EB5887F8EBDAB 20 | :100130008FB58C7F81608FBD8EB5877E8EBD8EB56D 21 | :0C014000887F83608EBD0895F894FFCF87 22 | :00000001FF 23 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty24at16.hex: -------------------------------------------------------------------------------- 1 | :1000000010C015C014C013C012C011C010C00FC062 2 | :100010000EC00DC00CC00BC00AC009C008C007C08C 3 | :1000200006C011241FBECFEDCDBF02D002C0E8CF65 4 | :06003000FFCFF894FFCFA2 5 | :00000001FF 6 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty25at1.hex: -------------------------------------------------------------------------------- 1 | :100000000EC026C025C024C02AC022C021C020C0E6 2 | :100010001FC01EC01DC01CC01BC01AC019C01124A7 3 | :100020001FBECFEDCDBF10E0A0E6B0E0E8E5F1E007 4 | :1000300002C005900D92A036B107D9F710E0A0E6F6 5 | :10004000B0E001C01D92A936B107E1F704D082C02B 6 | :10005000D7CF0895089557D0FCDFFCDFFECF1F9265 7 | :100060000F920FB60F9211242F933F934F935F93EC 8 | :100070006F937F938F939F93AF93BF93209164006F 9 | :100080003091650040916600509167007091680062 10 | :10009000DA01C9010296A11DB11D672F6A5F6D3794 11 | :1000A00030F06D57DA01C9010396A11DB11D6093AF 12 | :1000B00068008093640090936500A0936600B093FD 13 | :1000C00067008091600090916100A0916200B09102 14 | :1000D00063000196A11DB11D8093600090936100A3 15 | :1000E000A0936200B0936300BF91AF919F918F91F5 16 | :1000F0007F916F915F914F913F912F910F900FBE24 17 | :100100000F901F901895789480B7806880BF80B753 18 | :10011000806480BF8CB580648CBD8FEF8DBD80B74F 19 | :10012000807F846080BF89B7846089BF83B7887F00 20 | :1001300083BF8AB58C7F81608ABD83B7877F83BF89 21 | :1001400083B7887F826083BF86B1887F836086B9EA 22 | :08015000379A0895F894FFCFDF 23 | :00000001FF 24 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty25at8.hex: -------------------------------------------------------------------------------- 1 | :100000000EC026C025C024C02AC022C021C020C0E6 2 | :100010001FC01EC01DC01CC01BC01AC019C01124A7 3 | :100020001FBECFEDCDBF10E0A0E6B0E0E8E5F1E007 4 | :1000300002C005900D92A036B107D9F710E0A0E6F6 5 | :10004000B0E001C01D92A936B107E1F704D082C02B 6 | :10005000D7CF0895089557D0FCDFFCDFFECF1F9265 7 | :100060000F920FB60F9211242F933F934F935F93EC 8 | :100070006F937F938F939F93AF93BF93209164006F 9 | :100080003091650040916600509167007091680062 10 | :10009000DA01C9010296A11DB11D672F6A5F6D3794 11 | :1000A00030F06D57DA01C9010396A11DB11D6093AF 12 | :1000B00068008093640090936500A0936600B093FD 13 | :1000C00067008091600090916100A0916200B09102 14 | :1000D00063000196A11DB11D8093600090936100A3 15 | :1000E000A0936200B0936300BF91AF919F918F91F5 16 | :1000F0007F916F915F914F913F912F910F900FBE24 17 | :100100000F901F901895789480B7806880BF80B753 18 | :10011000806480BF8CB580648CBD8FEF8DBD80B74F 19 | :10012000807F876080BF89B7846089BF83B7887FFD 20 | :1001300083BF8AB58C7F81608ABD83B7877F83BF89 21 | :1001400083B7887F836083BF86B1887F866086B9E6 22 | :08015000379A0895F894FFCFDF 23 | :00000001FF 24 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty4313at1.hex: -------------------------------------------------------------------------------- 1 | :1000000014C01BC01AC019C018C017C016C015C034 2 | :1000100014C013C012C011C010C00FC00EC00DC05C 3 | :100020000CC00BC00AC009C008C011241FBECFE518 4 | :10003000D1E0DEBFCDBF02D002C0E2CFFFCFF89447 5 | :02004000FFCFF0 6 | :00000001FF 7 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty4313at8.hex: -------------------------------------------------------------------------------- 1 | :1000000014C01BC01AC019C018C017C016C015C034 2 | :1000100014C013C012C011C010C00FC00EC00DC05C 3 | :100020000CC00BC00AC009C008C011241FBECFE518 4 | :10003000D1E0DEBFCDBF02D002C0E2CFFFCFF89447 5 | :02004000FFCFF0 6 | :00000001FF 7 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty44at1.hex: -------------------------------------------------------------------------------- 1 | :1000000010C017C016C015C014C013C012C011C054 2 | :1000100010C00FC00EC00DC00CC00BC00AC009C07C 3 | :1000200008C011241FBECFE5D1E0DEBFCDBF02D096 4 | :0A00300002C0E6CFFFCFF894FFCF27 5 | :00000001FF 6 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty44at8.hex: -------------------------------------------------------------------------------- 1 | :1000000010C017C016C015C014C013C012C011C054 2 | :1000100010C00FC00EC00DC00CC00BC00AC009C07C 3 | :1000200008C011241FBECFE5D1E0DEBFCDBF02D096 4 | :0A00300002C0E6CFFFCFF894FFCF27 5 | :00000001FF 6 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty45at1.hex: -------------------------------------------------------------------------------- 1 | :100000000EC028C027C026C02CC024C023C022C0D8 2 | :1000100021C020C01FC01EC01DC01CC01BC0112499 3 | :100020001FBECFE5D1E0DEBFCDBF10E0A0E6B0E05F 4 | :10003000E2E5F1E002C005900D92A036B107D9F7D4 5 | :1000400010E0A0E6B0E001C01D92A936B107E1F7CB 6 | :1000500004D07DC0D5CF0895089557D0FCDFFCDFD4 7 | :10006000FECF1F920F920FB60F9211242F933F9342 8 | :100070004F935F936F937F938F939F93AF93BF93B0 9 | :1000800020916400309165004091660050916700B6 10 | :1000900070916800DA01C9010296A11DB11D672F98 11 | :1000A0006A5F6D3730F06D57DA01C9010396A11D03 12 | :1000B000B11D609368008093640090936500A093E5 13 | :1000C0006600B09367008091600090916100A091FC 14 | :1000D0006200B09163000196A11DB11D8093600084 15 | :1000E00090936100A0936200B0936300BF91AF91C1 16 | :1000F0009F918F917F916F915F914F913F912F9140 17 | :100100000F900FBE0F901F901895789480B780685D 18 | :1001100080BF80B7806480BF8CB580648CBD8FEF5A 19 | :100120008DBD80B7807F846080BF89B7846089BFC0 20 | :1001300083B7887F83BF8AB58C7F81608ABD83B790 21 | :10014000877F83BF83B7887F826083BF0895F894D9 22 | :02015000FFCFDF 23 | :00000001FF 24 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty45at8.hex: -------------------------------------------------------------------------------- 1 | :100000000EC028C027C026C02CC024C023C022C0D8 2 | :1000100021C020C01FC01EC01DC01CC01BC0112499 3 | :100020001FBECFE5D1E0DEBFCDBF10E0A0E6B0E05F 4 | :10003000E2E5F1E002C005900D92A036B107D9F7D4 5 | :1000400010E0A0E6B0E001C01D92A936B107E1F7CB 6 | :1000500004D07DC0D5CF0895089557D0FCDFFCDFD4 7 | :10006000FECF1F920F920FB60F9211242F933F9342 8 | :100070004F935F936F937F938F939F93AF93BF93B0 9 | :1000800020916400309165004091660050916700B6 10 | :1000900070916800DA01C9010296A11DB11D672F98 11 | :1000A0006A5F6D3730F06D57DA01C9010396A11D03 12 | :1000B000B11D609368008093640090936500A093E5 13 | :1000C0006600B09367008091600090916100A091FC 14 | :1000D0006200B09163000196A11DB11D8093600084 15 | :1000E00090936100A0936200B0936300BF91AF91C1 16 | :1000F0009F918F917F916F915F914F913F912F9140 17 | :100100000F900FBE0F901F901895789480B780685D 18 | :1001100080BF80B7806480BF8CB580648CBD8FEF5A 19 | :100120008DBD80B7807F876080BF89B7846089BFBD 20 | :1001300083B7887F83BF8AB58C7F81608ABD83B790 21 | :10014000877F83BF83B7887F836083BF0895F894D8 22 | :02015000FFCFDF 23 | :00000001FF 24 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty84at1.hex: -------------------------------------------------------------------------------- 1 | :1000000010C02AC029C028C027C026C025C024C0CF 2 | :1000100023C022C021C027C01FC01EC01DC01CC0DD 3 | :100020001BC011241FBECFE5D2E0DEBFCDBF10E064 4 | :10003000A0E6B0E0ECE4F1E002C005900D92A0363D 5 | :10004000B107D9F710E0A0E6B0E001C01D92A936D3 6 | :10005000B107E1F704D078C0D3CF0895089557D001 7 | :10006000FCDFFCDFFECF1F920F920FB60F92112420 8 | :100070002F933F934F935F936F937F938F939F93B0 9 | :10008000AF93BF932091640030916500409166006A 10 | :100090005091670070916800DA01C9014096A11D76 11 | :1000A000B11D672F605D6D3730F06D57DA01C90102 12 | :1000B0004196A11DB11D60936800809364009093E8 13 | :1000C0006500A0936600B0936700809160009091F6 14 | :1000D0006100A0916200B09163000196A11DB11D65 15 | :1000E0008093600090936100A0936200B0936300DE 16 | :1000F000BF91AF919F918F917F916F915F914F9140 17 | :100100003F912F910F900FBE0F901F9018957894EC 18 | :1001100080B7826080BF80B7816080BF83B7826014 19 | :1001200083BF83B7816083BF89B7816089BF8EB584 20 | :1001300082608EBD8EB581608EBD8FB581608FBDB2 21 | :0C014000319A309A379A0895F894FFCF56 22 | :00000001FF 23 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty84at16.hex: -------------------------------------------------------------------------------- 1 | :1000000010C01FC01EC01DC01CC01BC01AC019C01C 2 | :1000100018C017C016C01CC014C013C012C011C035 3 | :1000200010C011241FBECFE5D2E0DEBFCDBF10E06F 4 | :10003000A0E6B0E001C01D92A936B107E1F704D0F7 5 | :1000400063C0DECF089508954CD0FCDFFCDFFECF07 6 | :100050001F920F920FB60F9211242F933F938F93FD 7 | :100060009F93AF93BF938091640090916500A0919E 8 | :100070006600B091670030916800232F2D5F2D3707 9 | :1000800028F02D570296A11DB11D03C00196A11D98 10 | :10009000B11D209368008093640090936500A09345 11 | :1000A0006600B09367008091600090916100A0911C 12 | :1000B0006200B09163000196A11DB11D80936000A4 13 | :1000C00090936100A0936200B0936300BF91AF91E1 14 | :1000D0009F918F913F912F910F900FBE0F901F9086 15 | :1000E0001895789480B7836080BF83B7877F83BF7C 16 | :1000F00083B7887F836083BF89B7816089BF86B1FA 17 | :0C010000876086B9379A0895F894FFCF05 18 | :00000001FF 19 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty84at8.hex: -------------------------------------------------------------------------------- 1 | :1000000010C02AC029C028C027C026C025C024C0CF 2 | :1000100023C022C021C027C01FC01EC01DC01CC0DD 3 | :100020001BC011241FBECFE5D2E0DEBFCDBF10E064 4 | :10003000A0E6B0E0ECE4F1E002C005900D92A0363D 5 | :10004000B107D9F710E0A0E6B0E001C01D92A936D3 6 | :10005000B107E1F704D078C0D3CF0895089557D001 7 | :10006000FCDFFCDFFECF1F920F920FB60F92112420 8 | :100070002F933F934F935F936F937F938F939F93B0 9 | :10008000AF93BF932091640030916500409166006A 10 | :100090005091670070916800DA01C9010296A11DB4 11 | :1000A000B11D672F6A5F6D3730F06D57DA01C901F6 12 | :1000B0000396A11DB11D6093680080936400909326 13 | :1000C0006500A0936600B0936700809160009091F6 14 | :1000D0006100A0916200B09163000196A11DB11D65 15 | :1000E0008093600090936100A0936200B0936300DE 16 | :1000F000BF91AF919F918F917F916F915F914F9140 17 | :100100003F912F910F900FBE0F901F9018957894EC 18 | :1001100080B7826080BF80B7816080BF83B7826014 19 | :1001200083BF83B7816083BF89B7816089BF8EB584 20 | :1001300082608EBD8EB581608EBD8FB581608FBDB2 21 | :0C014000329A319A379A0895F894FFCF54 22 | :00000001FF 23 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty85at1.hex: -------------------------------------------------------------------------------- 1 | :100000000EC028C027C026C025C02BC023C022C0D8 2 | :1000100021C020C01FC01EC01DC01CC01BC0112499 3 | :100020001FBECFE5D2E0DEBFCDBF10E0A0E6B0E05E 4 | :10003000E8E4F1E002C005900D92A036B107D9F7CF 5 | :1000400010E0A0E6B0E001C01D92A936B107E1F7CB 6 | :1000500004D078C0D5CF0895089557D0FCDFFCDFD9 7 | :10006000FECF1F920F920FB60F9211242F933F9342 8 | :100070004F935F936F937F938F939F93AF93BF93B0 9 | :1000800020916400309165004091660050916700B6 10 | :1000900070916800DA01C9014096A11DB11D672F5A 11 | :1000A000605D6D3730F06D57DA01C9014196A11DD1 12 | :1000B000B11D609368008093640090936500A093E5 13 | :1000C0006600B09367008091600090916100A091FC 14 | :1000D0006200B09163000196A11DB11D8093600084 15 | :1000E00090936100A0936200B0936300BF91AF91C1 16 | :1000F0009F918F917F916F915F914F913F912F9140 17 | :100100000F900FBE0F901F90189578948AB582605B 18 | :100110008ABD8AB581608ABD83B7826083BF83B799 19 | :10012000816083BF89B7826089BF80B7826080BFEA 20 | :1001300080B7816080BF80B7806480BF319A309A79 21 | :08014000379A0895F894FFCFEF 22 | :00000001FF 23 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty85at16.hex: -------------------------------------------------------------------------------- 1 | :100000000EC01DC01CC01BC021C019C018C017C025 2 | :1000100016C015C014C013C012C011C010C01124E6 3 | :100020001FBECFE5D2E0DEBFCDBF10E0A0E6B0E05E 4 | :1000300001C01D92A936B107E1F704D064C0E0CF3A 5 | :10004000089508954CD0FCDFFCDFFECF1F920F9285 6 | :100050000FB60F9211242F933F938F939F93AF93DB 7 | :10006000BF938091640090916500A0916600B0916B 8 | :10007000670030916800232F2D5F2D3728F02D5712 9 | :100080000296A11DB11D03C00196A11DB11D2093B3 10 | :1000900068008093640090936500A0936600B0931D 11 | :1000A00067008091600090916100A0916200B09122 12 | :1000B00063000196A11DB11D8093600090936100C3 13 | :1000C000A0936200B0936300BF91AF919F918F9115 14 | :1000D0003F912F910F900FBE0F901F90189578941D 15 | :1000E00080B7806880BF80B7806480BF8CB5806433 16 | :1000F0008CBD8FEF8DBD80B7807F876080BF89B753 17 | :0A010000846089BF0895F894FFCFD2 18 | :00000001FF 19 | -------------------------------------------------------------------------------- /hardware/tiny/bootloaders/empty/empty85at8.hex: -------------------------------------------------------------------------------- 1 | :100000000EC028C027C026C025C02BC023C022C0D8 2 | :1000100021C020C01FC01EC01DC01CC01BC0112499 3 | :100020001FBECFE5D2E0DEBFCDBF10E0A0E6B0E05E 4 | :10003000E8E4F1E002C005900D92A036B107D9F7CF 5 | :1000400010E0A0E6B0E001C01D92A936B107E1F7CB 6 | :1000500004D078C0D5CF0895089557D0FCDFFCDFD9 7 | :10006000FECF1F920F920FB60F9211242F933F9342 8 | :100070004F935F936F937F938F939F93AF93BF93B0 9 | :1000800020916400309165004091660050916700B6 10 | :1000900070916800DA01C9010296A11DB11D672F98 11 | :1000A0006A5F6D3730F06D57DA01C9010396A11D03 12 | :1000B000B11D609368008093640090936500A093E5 13 | :1000C0006600B09367008091600090916100A091FC 14 | :1000D0006200B09163000196A11DB11D8093600084 15 | :1000E00090936100A0936200B0936300BF91AF91C1 16 | :1000F0009F918F917F916F915F914F913F912F9140 17 | :100100000F900FBE0F901F90189578948AB582605B 18 | :100110008ABD8AB581608ABD83B7826083BF83B799 19 | :10012000816083BF89B7826089BF80B7826080BFEA 20 | :1001300080B7816080BF80B7806480BF329A319A77 21 | :08014000379A0895F894FFCFEF 22 | :00000001FF 23 | -------------------------------------------------------------------------------- /hardware/tiny/cores/empty/Arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Arduino_h 2 | #define Arduino_h 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /hardware/tiny/cores/empty/WProgram.h: -------------------------------------------------------------------------------- 1 | #ifndef WProgram_h 2 | #define WProgram_h 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /hardware/tiny/cores/empty/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | set PATH=%PATH%;C:\Arduino\arduino-1.0\hardware\tools\avr\bin 3 | set PATH=%PATH%;C:\arduino\arduino-1.0\hardware\tools\avr\etc 4 | 5 | cd %TEMP% 6 | dir *.hex /s 7 | 8 | cd C:\Users\BRIANC~1.001\AppData\Local\Temp\build5703187254703185841.tmp 9 | 10 | avr-objdump.exe -S sketch_sep22a.cpp.elf > C:\Temp\dump.cpp & C:\Temp\dump.cpp 11 | */ 12 | 13 | int main(void) 14 | { 15 | for (;;); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/Arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Arduino_h 2 | #define Arduino_h 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/HardwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.cpp - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | Modified 28 September 2010 by Mark Sproul 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "core_build_options.h" 29 | #include "wiring.h" 30 | #include "wiring_private.h" 31 | 32 | // this next line disables the entire HardwareSerial.cpp, 33 | // this is so I can support Attiny series and any other chip without a uart 34 | #if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H) 35 | 36 | #include "HardwareSerial.h" 37 | 38 | // Define constants and variables for buffering incoming serial data. We're 39 | // using a ring buffer (I think), in which rx_buffer_head is the index of the 40 | // location to which to write the next incoming character and rx_buffer_tail 41 | // is the index of the location from which to read. 42 | #if (RAMEND < 1000) 43 | #define RX_BUFFER_SIZE 32 44 | #else 45 | #define RX_BUFFER_SIZE 128 46 | #endif 47 | 48 | struct ring_buffer 49 | { 50 | unsigned char buffer[RX_BUFFER_SIZE]; 51 | int head; 52 | int tail; 53 | }; 54 | 55 | #if defined(UBRRH) || defined(UBRR0H) 56 | ring_buffer rx_buffer = { { 0 }, 0, 0 }; 57 | #endif 58 | #if defined(UBRR1H) 59 | ring_buffer rx_buffer1 = { { 0 }, 0, 0 }; 60 | #endif 61 | #if defined(UBRR2H) 62 | ring_buffer rx_buffer2 = { { 0 }, 0, 0 }; 63 | #endif 64 | #if defined(UBRR3H) 65 | ring_buffer rx_buffer3 = { { 0 }, 0, 0 }; 66 | #endif 67 | 68 | inline void store_char(unsigned char c, ring_buffer *rx_buffer) 69 | { 70 | int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE; 71 | 72 | // if we should be storing the received character into the location 73 | // just before the tail (meaning that the head would advance to the 74 | // current location of the tail), we're about to overflow the buffer 75 | // and so we don't write the character or advance the head. 76 | if (i != rx_buffer->tail) { 77 | rx_buffer->buffer[rx_buffer->head] = c; 78 | rx_buffer->head = i; 79 | } 80 | } 81 | 82 | #if defined(USART_RX_vect) 83 | SIGNAL(USART_RX_vect) 84 | { 85 | #if defined(UDR0) 86 | unsigned char c = UDR0; 87 | #elif defined(UDR) 88 | unsigned char c = UDR; // atmega8535 89 | #else 90 | #error UDR not defined 91 | #endif 92 | store_char(c, &rx_buffer); 93 | } 94 | #elif defined(SIG_USART0_RECV) && defined(UDR0) 95 | SIGNAL(SIG_USART0_RECV) 96 | { 97 | unsigned char c = UDR0; 98 | store_char(c, &rx_buffer); 99 | } 100 | #elif defined(SIG_UART0_RECV) && defined(UDR0) 101 | SIGNAL(SIG_UART0_RECV) 102 | { 103 | unsigned char c = UDR0; 104 | store_char(c, &rx_buffer); 105 | } 106 | //#elif defined(SIG_USART_RECV) 107 | #elif defined(USART0_RX_vect) 108 | // fixed by Mark Sproul this is on the 644/644p 109 | //SIGNAL(SIG_USART_RECV) 110 | SIGNAL(USART0_RX_vect) 111 | { 112 | #if defined(UDR0) 113 | unsigned char c = UDR0; 114 | #elif defined(UDR) 115 | unsigned char c = UDR; // atmega8, atmega32 116 | #else 117 | #error UDR not defined 118 | #endif 119 | store_char(c, &rx_buffer); 120 | } 121 | #elif defined(SIG_UART_RECV) 122 | // this is for atmega8 123 | SIGNAL(SIG_UART_RECV) 124 | { 125 | #if defined(UDR0) 126 | unsigned char c = UDR0; // atmega645 127 | #elif defined(UDR) 128 | unsigned char c = UDR; // atmega8 129 | #endif 130 | store_char(c, &rx_buffer); 131 | } 132 | #elif defined(USBCON) 133 | #warning No interrupt handler for usart 0 134 | #warning Serial(0) is on USB interface 135 | #else 136 | #error No interrupt handler for usart 0 137 | #endif 138 | 139 | //#if defined(SIG_USART1_RECV) 140 | #if defined(USART1_RX_vect) 141 | //SIGNAL(SIG_USART1_RECV) 142 | SIGNAL(USART1_RX_vect) 143 | { 144 | unsigned char c = UDR1; 145 | store_char(c, &rx_buffer1); 146 | } 147 | #elif defined(SIG_USART1_RECV) 148 | #error SIG_USART1_RECV 149 | #endif 150 | 151 | #if defined(USART2_RX_vect) && defined(UDR2) 152 | SIGNAL(USART2_RX_vect) 153 | { 154 | unsigned char c = UDR2; 155 | store_char(c, &rx_buffer2); 156 | } 157 | #elif defined(SIG_USART2_RECV) 158 | #error SIG_USART2_RECV 159 | #endif 160 | 161 | #if defined(USART3_RX_vect) && defined(UDR3) 162 | SIGNAL(USART3_RX_vect) 163 | { 164 | unsigned char c = UDR3; 165 | store_char(c, &rx_buffer3); 166 | } 167 | #elif defined(SIG_USART3_RECV) 168 | #error SIG_USART3_RECV 169 | #endif 170 | 171 | 172 | 173 | // Constructors //////////////////////////////////////////////////////////////// 174 | 175 | HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, 176 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 177 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 178 | volatile uint8_t *udr, 179 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x) 180 | { 181 | _rx_buffer = rx_buffer; 182 | _ubrrh = ubrrh; 183 | _ubrrl = ubrrl; 184 | _ucsra = ucsra; 185 | _ucsrb = ucsrb; 186 | _udr = udr; 187 | _rxen = rxen; 188 | _txen = txen; 189 | _rxcie = rxcie; 190 | _udre = udre; 191 | _u2x = u2x; 192 | } 193 | 194 | // Public Methods ////////////////////////////////////////////////////////////// 195 | 196 | void HardwareSerial::begin(long baud) 197 | { 198 | uint16_t baud_setting; 199 | bool use_u2x = true; 200 | 201 | #if F_CPU == 16000000UL 202 | // hardcoded exception for compatibility with the bootloader shipped 203 | // with the Duemilanove and previous boards and the firmware on the 8U2 204 | // on the Uno and Mega 2560. 205 | if (baud == 57600) { 206 | use_u2x = false; 207 | } 208 | #endif 209 | 210 | if (use_u2x) { 211 | *_ucsra = 1 << _u2x; 212 | baud_setting = (F_CPU / 4 / baud - 1) / 2; 213 | } else { 214 | *_ucsra = 0; 215 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 216 | } 217 | 218 | // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) 219 | *_ubrrh = baud_setting >> 8; 220 | *_ubrrl = baud_setting; 221 | 222 | sbi(*_ucsrb, _rxen); 223 | sbi(*_ucsrb, _txen); 224 | sbi(*_ucsrb, _rxcie); 225 | } 226 | 227 | void HardwareSerial::end() 228 | { 229 | cbi(*_ucsrb, _rxen); 230 | cbi(*_ucsrb, _txen); 231 | cbi(*_ucsrb, _rxcie); 232 | } 233 | 234 | int HardwareSerial::available(void) 235 | { 236 | return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE; 237 | } 238 | 239 | int HardwareSerial::peek(void) 240 | { 241 | if (_rx_buffer->head == _rx_buffer->tail) { 242 | return -1; 243 | } else { 244 | return _rx_buffer->buffer[_rx_buffer->tail]; 245 | } 246 | } 247 | 248 | int HardwareSerial::read(void) 249 | { 250 | // if the head isn't ahead of the tail, we don't have any characters 251 | if (_rx_buffer->head == _rx_buffer->tail) { 252 | return -1; 253 | } else { 254 | unsigned char c = _rx_buffer->buffer[_rx_buffer->tail]; 255 | _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % RX_BUFFER_SIZE; 256 | return c; 257 | } 258 | } 259 | 260 | void HardwareSerial::flush() 261 | { 262 | // don't reverse this or there may be problems if the RX interrupt 263 | // occurs after reading the value of rx_buffer_head but before writing 264 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 265 | // may be written to rx_buffer_tail, making it appear as if the buffer 266 | // don't reverse this or there may be problems if the RX interrupt 267 | // occurs after reading the value of rx_buffer_head but before writing 268 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 269 | // may be written to rx_buffer_tail, making it appear as if the buffer 270 | // were full, not empty. 271 | _rx_buffer->head = _rx_buffer->tail; 272 | } 273 | 274 | size_t HardwareSerial::write(uint8_t c) 275 | { 276 | while (!((*_ucsra) & (1 << _udre))) 277 | ; 278 | 279 | *_udr = c; 280 | 281 | return( 1 ); 282 | } 283 | 284 | // Preinstantiate Objects ////////////////////////////////////////////////////// 285 | 286 | #if ! DEFAULT_TO_TINY_DEBUG_SERIAL 287 | #if defined(UBRRH) && defined(UBRRL) 288 | HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X); 289 | #elif defined(UBRR0H) && defined(UBRR0L) 290 | HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0); 291 | #elif defined(USBCON) 292 | #warning no serial port defined (port 0) 293 | #else 294 | #error no serial port defined (port 0) 295 | #endif 296 | #endif 297 | 298 | #if defined(UBRR1H) 299 | HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1); 300 | #endif 301 | #if defined(UBRR2H) 302 | HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2); 303 | #endif 304 | #if defined(UBRR3H) 305 | HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3); 306 | #endif 307 | 308 | #endif // whole file 309 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 28 September 2010 by Mark Sproul 20 | */ 21 | 22 | #ifndef HardwareSerial_h 23 | #define HardwareSerial_h 24 | 25 | #include 26 | 27 | #include "core_build_options.h" 28 | #include "Stream.h" 29 | 30 | struct ring_buffer; 31 | 32 | class HardwareSerial : public Stream 33 | { 34 | private: 35 | ring_buffer *_rx_buffer; 36 | volatile uint8_t *_ubrrh; 37 | volatile uint8_t *_ubrrl; 38 | volatile uint8_t *_ucsra; 39 | volatile uint8_t *_ucsrb; 40 | volatile uint8_t *_udr; 41 | uint8_t _rxen; 42 | uint8_t _txen; 43 | uint8_t _rxcie; 44 | uint8_t _udre; 45 | uint8_t _u2x; 46 | public: 47 | HardwareSerial(ring_buffer *rx_buffer, 48 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 49 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 50 | volatile uint8_t *udr, 51 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x); 52 | void begin(long); 53 | void end(); 54 | virtual int available(void); 55 | virtual int peek(void); 56 | virtual int read(void); 57 | virtual void flush(void); 58 | virtual size_t write(uint8_t); 59 | using Print::write; // pull in write(str) and write(buf, size) from Print 60 | }; 61 | 62 | #if (defined(UBRRH) || defined(UBRR0H)) && ! DEFAULT_TO_TINY_DEBUG_SERIAL 63 | extern HardwareSerial Serial; 64 | #elif defined(USBCON) 65 | #include "usb_api.h" 66 | #endif 67 | #if defined(UBRR1H) 68 | extern HardwareSerial Serial1; 69 | #endif 70 | #if defined(UBRR2H) 71 | extern HardwareSerial Serial2; 72 | #endif 73 | #if defined(UBRR3H) 74 | extern HardwareSerial Serial3; 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/Print.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Print.cpp - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "wiring.h" 28 | #include "Print.h" 29 | 30 | // Public Methods ////////////////////////////////////////////////////////////// 31 | 32 | /* default implementation: may be overridden */ 33 | void Print::write(const char *str) 34 | { 35 | while (*str) 36 | write(*str++); 37 | } 38 | 39 | /* default implementation: may be overridden */ 40 | void Print::write(const uint8_t *buffer, size_t size) 41 | { 42 | while (size--) 43 | write(*buffer++); 44 | } 45 | 46 | void Print::print(const String &s) 47 | { 48 | for (int i = 0; i < s.length(); i++) { 49 | write(s[i]); 50 | } 51 | } 52 | 53 | void Print::print(const char str[]) 54 | { 55 | write(str); 56 | } 57 | 58 | void Print::print(char c, int base) 59 | { 60 | print((long) c, base); 61 | } 62 | 63 | void Print::print(unsigned char b, int base) 64 | { 65 | print((unsigned long) b, base); 66 | } 67 | 68 | void Print::print(int n, int base) 69 | { 70 | print((long) n, base); 71 | } 72 | 73 | void Print::print(unsigned int n, int base) 74 | { 75 | print((unsigned long) n, base); 76 | } 77 | 78 | void Print::print(long n, int base) 79 | { 80 | if (base == 0) { 81 | write(n); 82 | } else if (base == 10) { 83 | if (n < 0) { 84 | print('-'); 85 | n = -n; 86 | } 87 | printNumber(n, 10); 88 | } else { 89 | printNumber(n, base); 90 | } 91 | } 92 | 93 | void Print::print(unsigned long n, int base) 94 | { 95 | if (base == 0) write(n); 96 | else printNumber(n, base); 97 | } 98 | 99 | void Print::print(double n, int digits) 100 | { 101 | printFloat(n, digits); 102 | } 103 | 104 | int Print::print( fstr_t* s ) 105 | { 106 | int rv; 107 | char ch; 108 | 109 | rv = 0; 110 | ch = pgm_read_byte( s ); 111 | while ( ch != 0 ) 112 | { 113 | write( ch ); 114 | ++s; 115 | ++rv; 116 | ch = pgm_read_byte( s ); 117 | } 118 | return( rv ); 119 | } 120 | 121 | int Print::println(void) 122 | { 123 | print('\r'); 124 | print('\n'); 125 | return( 2 ); 126 | } 127 | 128 | void Print::println(const String &s) 129 | { 130 | print(s); 131 | println(); 132 | } 133 | 134 | void Print::println(const char c[]) 135 | { 136 | print(c); 137 | println(); 138 | } 139 | 140 | void Print::println(char c, int base) 141 | { 142 | print(c, base); 143 | println(); 144 | } 145 | 146 | void Print::println(unsigned char b, int base) 147 | { 148 | print(b, base); 149 | println(); 150 | } 151 | 152 | void Print::println(int n, int base) 153 | { 154 | print(n, base); 155 | println(); 156 | } 157 | 158 | void Print::println(unsigned int n, int base) 159 | { 160 | print(n, base); 161 | println(); 162 | } 163 | 164 | void Print::println(long n, int base) 165 | { 166 | print(n, base); 167 | println(); 168 | } 169 | 170 | void Print::println(unsigned long n, int base) 171 | { 172 | print(n, base); 173 | println(); 174 | } 175 | 176 | void Print::println(double n, int digits) 177 | { 178 | print(n, digits); 179 | println(); 180 | } 181 | 182 | int Print::println( fstr_t* s ) 183 | { 184 | int rv; 185 | 186 | rv = print( s ); 187 | rv += println(); 188 | return( rv ); 189 | } 190 | 191 | // Private Methods ///////////////////////////////////////////////////////////// 192 | 193 | void Print::printNumber(unsigned long n, uint8_t base) 194 | { 195 | unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 196 | unsigned long i = 0; 197 | 198 | if (n == 0) { 199 | print('0'); 200 | return; 201 | } 202 | 203 | while (n > 0) { 204 | buf[i++] = n % base; 205 | n /= base; 206 | } 207 | 208 | for (; i > 0; i--) 209 | print((char) (buf[i - 1] < 10 ? 210 | '0' + buf[i - 1] : 211 | 'A' + buf[i - 1] - 10)); 212 | } 213 | 214 | void Print::printFloat(double number, uint8_t digits) 215 | { 216 | // Handle negative numbers 217 | if (number < 0.0) 218 | { 219 | print('-'); 220 | number = -number; 221 | } 222 | 223 | // Round correctly so that print(1.999, 2) prints as "2.00" 224 | double rounding = 0.5; 225 | for (uint8_t i=0; i 0) 237 | print("."); 238 | 239 | // Extract digits from the remainder one at a time 240 | while (digits-- > 0) 241 | { 242 | remainder *= 10.0; 243 | int toPrint = int(remainder); 244 | print(toPrint); 245 | remainder -= toPrint; 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 20-11-2010 by B.Cook ... 20 | 21 | http://arduiniana.org/libraries/flash/ 22 | Printable support thanks to Mikal Hart 23 | */ 24 | 25 | #ifndef Print_h 26 | #define Print_h 27 | 28 | #include 29 | #include // for size_t 30 | #include 31 | 32 | #include "WString.h" 33 | 34 | #define DEC 10 35 | #define HEX 16 36 | #define OCT 8 37 | #define BIN 2 38 | #define BYTE 0 39 | 40 | #define ARDUINO_CORE_PRINTABLE_SUPPORT 41 | 42 | class Print; 43 | 44 | /* Printable...*/ 45 | 46 | class _Printable 47 | { 48 | public: 49 | virtual void print(Print &stream) const = 0; 50 | }; 51 | 52 | /* ...Printable */ 53 | 54 | typedef struct 55 | { 56 | char c; 57 | } 58 | fstr_t; 59 | 60 | /* rmv: Use the macro below in preparation for the next Arduino release. 61 | # define FSTR(s) ((fstr_t*)PSTR(s)) 62 | */ 63 | # define F(s) ((fstr_t*)PSTR(s)) 64 | 65 | class Print 66 | { 67 | private: 68 | void printNumber(unsigned long, uint8_t); 69 | void printFloat(double, uint8_t); 70 | protected: 71 | void setWriteError(int err = 1) { /*write_error = err;*/ } 72 | public: 73 | virtual size_t write(uint8_t) = 0; 74 | virtual void write(const char *str); 75 | virtual void write(const uint8_t *buffer, size_t size); 76 | 77 | void print(const String &); 78 | void print(const char[]); 79 | void print(char, int = BYTE); 80 | void print(unsigned char, int = BYTE); 81 | void print(int, int = DEC); 82 | void print(unsigned int, int = DEC); 83 | void print(long, int = DEC); 84 | void print(unsigned long, int = DEC); 85 | void print(double, int = 2); 86 | int print( fstr_t* ); 87 | 88 | void println(const String &s); 89 | void println(const char[]); 90 | void println(char, int = BYTE); 91 | void println(unsigned char, int = BYTE); 92 | void println(int, int = DEC); 93 | void println(unsigned int, int = DEC); 94 | void println(long, int = DEC); 95 | void println(unsigned long, int = DEC); 96 | void println(double, int = 2); 97 | int println( fstr_t* ); 98 | int println(void); 99 | public: 100 | /* Printable...*/ 101 | void println(const _Printable &obj) 102 | { obj.print(*this); println(); } 103 | void print(const _Printable &obj) 104 | { obj.print(*this); }; 105 | /* ...Printable */ 106 | }; 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/PwmTimer.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | PwmTimer.h - Veneer for the PWM timers. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #ifndef PwmTimer_h 25 | #define PwmTimer_h 26 | 27 | #include "core_pins.h" 28 | #include "core_timers.h" 29 | 30 | #define PwmTimer3_(t,f,c) TIMER_PASTE_CHANNEL_A( Timer, t, f, c ) 31 | #define PwmTimer2_(t,f) TIMER_PASTE_A( Timer, t, f ) 32 | 33 | #if CORE_PWM_COUNT >= 1 34 | #define Pwm0_SetCompareOutputMode PwmTimer3_( CORE_PWM0_TIMER, SetCompareOutputMode, CORE_PWM0_CHANNEL ) 35 | #define Pwm0_Disconnected PwmTimer2_( CORE_PWM0_TIMER, Disconnected ) 36 | #define Pwm0_Clear PwmTimer2_( CORE_PWM0_TIMER, Clear ) 37 | #define Pwm0_SetOutputCompareMatch PwmTimer3_( CORE_PWM0_TIMER, SetOutputCompareMatch, CORE_PWM0_CHANNEL ) 38 | #endif 39 | 40 | #if CORE_PWM_COUNT >= 2 41 | #define Pwm1_SetCompareOutputMode PwmTimer3_( CORE_PWM1_TIMER, SetCompareOutputMode, CORE_PWM1_CHANNEL ) 42 | #define Pwm1_Disconnected PwmTimer2_( CORE_PWM1_TIMER, Disconnected ) 43 | #define Pwm1_Clear PwmTimer2_( CORE_PWM1_TIMER, Clear ) 44 | #define Pwm1_SetOutputCompareMatch PwmTimer3_( CORE_PWM1_TIMER, SetOutputCompareMatch, CORE_PWM1_CHANNEL ) 45 | #endif 46 | 47 | #if CORE_PWM_COUNT >= 3 48 | #define Pwm2_SetCompareOutputMode PwmTimer3_( CORE_PWM2_TIMER, SetCompareOutputMode, CORE_PWM2_CHANNEL ) 49 | #define Pwm2_Disconnected PwmTimer2_( CORE_PWM2_TIMER, Disconnected ) 50 | #define Pwm2_Clear PwmTimer2_( CORE_PWM2_TIMER, Clear ) 51 | #define Pwm2_SetOutputCompareMatch PwmTimer3_( CORE_PWM2_TIMER, SetOutputCompareMatch, CORE_PWM2_CHANNEL ) 52 | #endif 53 | 54 | #if CORE_PWM_COUNT >= 4 55 | #define Pwm3_SetCompareOutputMode PwmTimer3_( CORE_PWM3_TIMER, SetCompareOutputMode, CORE_PWM3_CHANNEL ) 56 | #define Pwm3_Disconnected PwmTimer2_( CORE_PWM3_TIMER, Disconnected ) 57 | #define Pwm3_Clear PwmTimer2_( CORE_PWM3_TIMER, Clear ) 58 | #define Pwm3_SetOutputCompareMatch PwmTimer3_( CORE_PWM3_TIMER, SetOutputCompareMatch, CORE_PWM3_CHANNEL ) 59 | #endif 60 | 61 | #if CORE_PWM_COUNT >= 5 62 | #error Only 4 pins PWM are supported. Add more macro defintions. 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.h - base class for character-based streams. 3 | Copyright (c) 2010 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Stream_h 21 | #define Stream_h 22 | 23 | #include 24 | #include "Print.h" 25 | 26 | class Stream : public Print 27 | { 28 | public: 29 | virtual int available() = 0; 30 | virtual int read() = 0; 31 | virtual int peek() = 0; 32 | virtual void flush() = 0; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/TinyDebugSerial.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | TinyDebugSerial.cpp - Tiny write-only software serial. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #include "core_build_options.h" 25 | #include "TinyDebugSerial.h" 26 | 27 | static TinyDebugSerialWriter stub; 28 | 29 | void TinyDebugSerial::useStub( void ) 30 | { 31 | _writer = &stub; 32 | _writer->init(); 33 | } 34 | 35 | TinyDebugSerial::TinyDebugSerial( void ) 36 | { 37 | useStub(); 38 | } 39 | 40 | #if defined( DEFAULT_TO_TINY_DEBUG_SERIAL ) && DEFAULT_TO_TINY_DEBUG_SERIAL 41 | TinyDebugSerial Serial; 42 | #endif 43 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/TinyDebugSerial115200.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | TinyDebugSerial.cpp - Tiny write-only software serial. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #include "TinyDebugSerial.h" 25 | 26 | TinyDebugSerialWriter_115200 tdsw115200; 27 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/TinyDebugSerial38400.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | TinyDebugSerial.cpp - Tiny write-only software serial. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #include "TinyDebugSerial.h" 25 | 26 | TinyDebugSerialWriter_38400 tdsw38400; 27 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/TinyDebugSerial9600.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | TinyDebugSerial.cpp - Tiny write-only software serial. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #include "TinyDebugSerial.h" 25 | 26 | TinyDebugSerialWriter_9600 tdsw9600; 27 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/TinyDebugSerialErrors.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | TinyDebugSerial.cpp - Tiny write-only software serial. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #include "TinyDebugSerial.h" 25 | 26 | void TinyDebugSerialWriterInternalBug( void ) { } 27 | void TinyDebugSerialBadBaud( void ) { } 28 | void TinyDebugSerialBaudMustBeConstant( void ) { } 29 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/ToneTimer.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | ToneTimer.h - Veneer for the Tone Timer. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #ifndef ToneTimer_h 25 | #define ToneTimer_h 26 | 27 | #include "core_build_options.h" 28 | #include "core_timers.h" 29 | 30 | #define tonetimer_(t) TIMER_PASTE_A( timer, TIMER_TO_USE_FOR_TONE, t ) 31 | #define ToneTimer_(f) TIMER_PASTE_A( Timer, TIMER_TO_USE_FOR_TONE, f ) 32 | #define TONETIMER_(c) TIMER_PASTE_A( TIMER, TIMER_TO_USE_FOR_TONE, c ) 33 | 34 | #define ToneTimer_SetToPowerup ToneTimer_(SetToPowerup) 35 | #define ToneTimer_SetWaveformGenerationMode ToneTimer_(SetWaveformGenerationMode) 36 | #define ToneTimer_OutputComparePinA ToneTimer_(OutputComparePinA) 37 | #define ToneTimer_OutputComparePinB ToneTimer_(OutputComparePinB) 38 | #define ToneTimer_SetCompareOutputModeA ToneTimer_(SetCompareOutputModeA) 39 | #define ToneTimer_SetCompareOutputModeB ToneTimer_(SetCompareOutputModeB) 40 | #define ToneTimer_DisconnectOutputs ToneTimer_(DisconnectOutputs) 41 | #define ToneTimer_ClockSelect ToneTimer_(ClockSelect) 42 | #define ToneTimer_SetCount ToneTimer_(SetCount) 43 | #define TONETIMER_NUMBER_PRESCALERS TONETIMER_(NUMBER_PRESCALERS) 44 | #define ToneTimer_SetOutputCompareMatchAndClear ToneTimer_(SetOutputCompareMatchAndClear) 45 | #define ToneTimer_InterruptsOff ToneTimer_(InterruptsOff) 46 | #define ToneTimer_EnableOutputCompareInterruptA ToneTimer_(EnableOutputCompareInterruptA) 47 | #define TONETIMER_COMPA_vect TONETIMER_(COMPA_vect) 48 | #define TONETIMER_SUPPORTS_PHASE_CORRECT_PWM TONETIMER_(SUPPORTS_PHASE_CORRECT_PWM) 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/UserTimer.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | UserTimer.h - Veneer for the User Timer (same timer as the one used for 4 | Tone) 5 | 6 | Copyright 2010 Rowdy Dog Software. 7 | 8 | This file is part of Arduino-Tiny. 9 | 10 | Arduino-Tiny is free software: you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or (at your 13 | option) any later version. 14 | 15 | Arduino-Tiny is distributed in the hope that it will be useful, but 16 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public License 21 | along with Arduino-Tiny. If not, see . 22 | 23 | ==============================================================================*/ 24 | 25 | #ifndef UserTimer_h 26 | #define UserTimer_h 27 | 28 | #include "core_build_options.h" 29 | #include "core_timers.h" 30 | 31 | 32 | /*============================================================================= 33 | Assume there are only two timers. One for millis and one for everything 34 | else. 35 | =============================================================================*/ 36 | 37 | #if TIMER_TO_USE_FOR_MILLIS == 0 38 | #define TIMER_TO_USE_FOR_USER 1 39 | #elif TIMER_TO_USE_FOR_MILLIS == 1 40 | #define TIMER_TO_USE_FOR_USER 0 41 | #else 42 | #error Unexpected condition in UserTimer.h. 43 | #endif 44 | 45 | 46 | /*============================================================================= 47 | Macros to help generate the macros below 48 | =============================================================================*/ 49 | 50 | #define usertimer_(t) TIMER_PASTE_A( timer, TIMER_TO_USE_FOR_USER, t ) 51 | #define UserTimer_(f) TIMER_PASTE_A( Timer, TIMER_TO_USE_FOR_USER, f ) 52 | #define USERTIMER_(c) TIMER_PASTE_A( TIMER, TIMER_TO_USE_FOR_USER, c ) 53 | 54 | 55 | /*============================================================================= 56 | Macros to provide a veneer over the data-types, functions, and constants in 57 | core_timers.h 58 | =============================================================================*/ 59 | 60 | #define UserTimer_SetToPowerup UserTimer_(SetToPowerup) 61 | #define UserTimer_InterruptsOff UserTimer_(InterruptsOff) 62 | #define UserTimer_ClockSelect UserTimer_(ClockSelect) 63 | #define UserTimer_SetWaveformGenerationMode UserTimer_(SetWaveformGenerationMode) 64 | #define UserTimer_SetCompareOutputModeA UserTimer_(SetCompareOutputModeA) 65 | #define UserTimer_SetCompareOutputModeB UserTimer_(SetCompareOutputModeB) 66 | #define UserTimer_SetOutputCompareMatchAndClear UserTimer_(SetOutputCompareMatchAndClear) 67 | #define UserTimer_EnableOutputCompareInterruptA UserTimer_(EnableOutputCompareInterruptA) 68 | #define UserTimer_EnableOverflowInterrupt UserTimer_(EnableOverflowInterrupt) 69 | #define UserTimer_GetCount UserTimer_(GetCount) 70 | #define UserTimer_SetCount UserTimer_(SetCount) 71 | #define UserTimer_IsOverflowSet UserTimer_(IsOverflowSet) 72 | 73 | #define USERTIMER_OVF_vect USERTIMER_(OVF_vect) 74 | #define USERTIMER_COMPA_vect USERTIMER_(COMPA_vect) 75 | #define USERTIMER_COMPB_vect USERTIMER_(COMPB_vect) 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/WCharacter.h: -------------------------------------------------------------------------------- 1 | /* 2 | WCharacter.h - Character utility functions for Wiring & Arduino 3 | Copyright (c) 2010 Hernando Barragan. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Character_h 21 | #define Character_h 22 | 23 | #include 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 -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/WConstants.h: -------------------------------------------------------------------------------- 1 | #include "wiring.h" 2 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/WInterrupts.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.uniandes.edu.co 5 | 6 | Copyright (c) 2004-05 Hernando Barragan 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | Modified 24 November 2006 by David A. Mellis 24 | 25 | Modified 28-08-2009 for attiny84 R.Wiersma 26 | Modified 09-10-2009 for attiny45 A.Saporetti 27 | Modified 20-11-2010 - B.Cook - Correct a minor bug in attachInterrupt 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "WConstants.h" 37 | #include "wiring_private.h" 38 | 39 | volatile static voidFuncPtr intFunc[NUMBER_EXTERNAL_INTERRUPTS]; 40 | 41 | #if defined( MCUCR ) && ! defined( EICRA ) 42 | #define EICRA MCUCR 43 | #endif 44 | 45 | #if defined( GIMSK ) && ! defined( EIMSK ) 46 | #define EIMSK GIMSK 47 | #endif 48 | 49 | void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) 50 | { 51 | if ( interruptNum < NUMBER_EXTERNAL_INTERRUPTS ) 52 | { 53 | /* 54 | If attachInterrupt is called in succession for the same 55 | interruptNum but a different userFunc then the following line 56 | is not safe. Changing intFunc is not atomic. 57 | intFunc[interruptNum] = userFunc; 58 | */ 59 | { 60 | // save interrupt flag 61 | uint8_t SaveSREG = SREG; 62 | // disable interrupts 63 | cli(); 64 | // access the shared data 65 | intFunc[interruptNum] = userFunc; 66 | // restore the interrupt flag 67 | SREG = SaveSREG; 68 | } 69 | 70 | // Configure the interrupt mode (trigger on low input, any change, rising 71 | // edge, or falling edge). The mode constants were chosen to correspond 72 | // to the configuration bits in the hardware register, so we simply shift 73 | // the mode into place. 74 | 75 | // Enable the interrupt. 76 | 77 | switch ( interruptNum ) 78 | { 79 | #if NUMBER_EXTERNAL_INTERRUPTS >= 1 80 | case EXTERNAL_INTERRUPT_0: 81 | EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 82 | EIMSK |= (1 << INT0); 83 | break; 84 | #endif 85 | 86 | #if NUMBER_EXTERNAL_INTERRUPTS >= 2 87 | case EXTERNAL_INTERRUPT_1: 88 | EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 89 | EIMSK |= (1 << INT1); 90 | break; 91 | #endif 92 | 93 | #if NUMBER_EXTERNAL_INTERRUPTS > 2 94 | #error Add handlers for the additional interrupts. 95 | #endif 96 | } 97 | } 98 | } 99 | 100 | void detachInterrupt(uint8_t interruptNum) 101 | { 102 | if ( interruptNum < NUMBER_EXTERNAL_INTERRUPTS ) 103 | { 104 | // Disable the interrupt. (We can't assume that interruptNum is equal 105 | // to the number of the EIMSK bit to clear, as this isn't true on the 106 | // ATmega8. There, INT0 is 6 and INT1 is 7.) 107 | 108 | switch (interruptNum) 109 | { 110 | #if NUMBER_EXTERNAL_INTERRUPTS >= 1 111 | case EXTERNAL_INTERRUPT_0: 112 | EIMSK &= ~(1 << INT0); 113 | break;; 114 | #endif 115 | 116 | #if NUMBER_EXTERNAL_INTERRUPTS >= 2 117 | case EXTERNAL_INTERRUPT_1: 118 | EIMSK &= ~(1 << INT1); 119 | break;; 120 | #endif 121 | 122 | #if NUMBER_EXTERNAL_INTERRUPTS > 2 123 | #error Add handlers for the additional interrupts. 124 | #endif 125 | } 126 | intFunc[interruptNum] = 0; 127 | } 128 | } 129 | 130 | #if NUMBER_EXTERNAL_INTERRUPTS >= 1 131 | ISR(EXTERNAL_INTERRUPT_0_vect) 132 | { 133 | if(intFunc[EXTERNAL_INTERRUPT_0]) 134 | intFunc[EXTERNAL_INTERRUPT_0](); 135 | } 136 | #endif 137 | 138 | #if NUMBER_EXTERNAL_INTERRUPTS >= 2 139 | ISR(EXTERNAL_INTERRUPT_1_vect) 140 | { 141 | if(intFunc[EXTERNAL_INTERRUPT_1]) 142 | intFunc[EXTERNAL_INTERRUPT_1](); 143 | } 144 | #endif 145 | 146 | #if NUMBER_EXTERNAL_INTERRUPTS > 2 147 | #error Add handlers for the additional interrupts. 148 | #endif 149 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | $Id$ 24 | */ 25 | 26 | extern "C" { 27 | #include "stdlib.h" 28 | } 29 | 30 | void randomSeed(unsigned int seed) 31 | { 32 | if (seed != 0) { 33 | srandom(seed); 34 | } 35 | } 36 | 37 | long random(long howbig) 38 | { 39 | if (howbig == 0) { 40 | return 0; 41 | } 42 | return random() % howbig; 43 | } 44 | 45 | long random(long howsmall, long howbig) 46 | { 47 | if (howsmall >= howbig) { 48 | return howsmall; 49 | } 50 | long diff = howbig - howsmall; 51 | return random(diff) + howsmall; 52 | } 53 | 54 | long map(long x, long in_min, long in_max, long out_min, long out_max) 55 | { 56 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 57 | } 58 | 59 | unsigned int makeWord(unsigned int w) { return w; } 60 | unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/WProgram.h: -------------------------------------------------------------------------------- 1 | #ifndef WProgram_h 2 | #define WProgram_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "core_build_options.h" 11 | #include "core_pins.h" 12 | #include "wiring.h" 13 | #include "pins_arduino.h" 14 | 15 | #ifdef __cplusplus 16 | #include "WCharacter.h" 17 | #include "WString.h" 18 | #include "TinyDebugSerial.h" 19 | #include "HardwareSerial.h" 20 | 21 | uint16_t makeWord(uint16_t w); 22 | uint16_t makeWord(byte h, byte l); 23 | 24 | #define word(...) makeWord(__VA_ARGS__) 25 | 26 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); 27 | 28 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); 29 | void noTone(uint8_t _pin = 255); 30 | 31 | // WMath prototypes 32 | long random(long); 33 | long random(long, long); 34 | void randomSeed(unsigned int); 35 | long map(long, long, long, long, long); 36 | 37 | /* 38 | fix? On the Mega processors, the analogs are also "extended" digital pins. 39 | To (sort of) work the same way with this core, the following constants 40 | would have to be valid arguments to digitalRead, digitalWrite, and pinMode 41 | ("the digitals"). Which means the digitals would have to check for pins 42 | over A0 and then subtract A0. The current plan is to wait until someone 43 | wants this feature. 44 | */ 45 | #if CORE_ANALOG_COUNT >= 1 46 | const static uint8_t A0 = CORE_ANALOG_FIRST + 0; 47 | #endif 48 | 49 | #if CORE_ANALOG_COUNT >= 2 50 | const static uint8_t A1 = CORE_ANALOG_FIRST + 1; 51 | #endif 52 | 53 | #if CORE_ANALOG_COUNT >= 3 54 | const static uint8_t A2 = CORE_ANALOG_FIRST + 2; 55 | #endif 56 | 57 | #if CORE_ANALOG_COUNT >= 4 58 | const static uint8_t A3 = CORE_ANALOG_FIRST + 3; 59 | #endif 60 | 61 | #if CORE_ANALOG_COUNT >= 5 62 | const static uint8_t A4 = CORE_ANALOG_FIRST + 4; 63 | #endif 64 | 65 | #if CORE_ANALOG_COUNT >= 6 66 | const static uint8_t A5 = CORE_ANALOG_FIRST + 5; 67 | #endif 68 | 69 | #if CORE_ANALOG_COUNT >= 7 70 | const static uint8_t A6 = CORE_ANALOG_FIRST + 6; 71 | #endif 72 | 73 | #if CORE_ANALOG_COUNT >= 8 74 | const static uint8_t A7 = CORE_ANALOG_FIRST + 7; 75 | #endif 76 | 77 | #if CORE_ANALOG_COUNT >= 9 78 | #error Update the A* definitions for the selected processor. 79 | #endif 80 | 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/WString.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | WString.cpp - String library for Wiring & Arduino 3 | Copyright (c) 2009-10 Hernando Barragan. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 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 | } 444 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/WString.h: -------------------------------------------------------------------------------- 1 | /* 2 | WString.h - String library for Wiring & Arduino 3 | Copyright (c) 2009-10 Hernando Barragan. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef String_h 21 | #define String_h 22 | 23 | //#include "WProgram.h" 24 | #include 25 | #include 26 | #include 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 113 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef Binary_h 2 | #define Binary_h 3 | 4 | #define B0 0 5 | #define B00 0 6 | #define B000 0 7 | #define B0000 0 8 | #define B00000 0 9 | #define B000000 0 10 | #define B0000000 0 11 | #define B00000000 0 12 | #define B1 1 13 | #define B01 1 14 | #define B001 1 15 | #define B0001 1 16 | #define B00001 1 17 | #define B000001 1 18 | #define B0000001 1 19 | #define B00000001 1 20 | #define B10 2 21 | #define B010 2 22 | #define B0010 2 23 | #define B00010 2 24 | #define B000010 2 25 | #define B0000010 2 26 | #define B00000010 2 27 | #define B11 3 28 | #define B011 3 29 | #define B0011 3 30 | #define B00011 3 31 | #define B000011 3 32 | #define B0000011 3 33 | #define B00000011 3 34 | #define B100 4 35 | #define B0100 4 36 | #define B00100 4 37 | #define B000100 4 38 | #define B0000100 4 39 | #define B00000100 4 40 | #define B101 5 41 | #define B0101 5 42 | #define B00101 5 43 | #define B000101 5 44 | #define B0000101 5 45 | #define B00000101 5 46 | #define B110 6 47 | #define B0110 6 48 | #define B00110 6 49 | #define B000110 6 50 | #define B0000110 6 51 | #define B00000110 6 52 | #define B111 7 53 | #define B0111 7 54 | #define B00111 7 55 | #define B000111 7 56 | #define B0000111 7 57 | #define B00000111 7 58 | #define B1000 8 59 | #define B01000 8 60 | #define B001000 8 61 | #define B0001000 8 62 | #define B00001000 8 63 | #define B1001 9 64 | #define B01001 9 65 | #define B001001 9 66 | #define B0001001 9 67 | #define B00001001 9 68 | #define B1010 10 69 | #define B01010 10 70 | #define B001010 10 71 | #define B0001010 10 72 | #define B00001010 10 73 | #define B1011 11 74 | #define B01011 11 75 | #define B001011 11 76 | #define B0001011 11 77 | #define B00001011 11 78 | #define B1100 12 79 | #define B01100 12 80 | #define B001100 12 81 | #define B0001100 12 82 | #define B00001100 12 83 | #define B1101 13 84 | #define B01101 13 85 | #define B001101 13 86 | #define B0001101 13 87 | #define B00001101 13 88 | #define B1110 14 89 | #define B01110 14 90 | #define B001110 14 91 | #define B0001110 14 92 | #define B00001110 14 93 | #define B1111 15 94 | #define B01111 15 95 | #define B001111 15 96 | #define B0001111 15 97 | #define B00001111 15 98 | #define B10000 16 99 | #define B010000 16 100 | #define B0010000 16 101 | #define B00010000 16 102 | #define B10001 17 103 | #define B010001 17 104 | #define B0010001 17 105 | #define B00010001 17 106 | #define B10010 18 107 | #define B010010 18 108 | #define B0010010 18 109 | #define B00010010 18 110 | #define B10011 19 111 | #define B010011 19 112 | #define B0010011 19 113 | #define B00010011 19 114 | #define B10100 20 115 | #define B010100 20 116 | #define B0010100 20 117 | #define B00010100 20 118 | #define B10101 21 119 | #define B010101 21 120 | #define B0010101 21 121 | #define B00010101 21 122 | #define B10110 22 123 | #define B010110 22 124 | #define B0010110 22 125 | #define B00010110 22 126 | #define B10111 23 127 | #define B010111 23 128 | #define B0010111 23 129 | #define B00010111 23 130 | #define B11000 24 131 | #define B011000 24 132 | #define B0011000 24 133 | #define B00011000 24 134 | #define B11001 25 135 | #define B011001 25 136 | #define B0011001 25 137 | #define B00011001 25 138 | #define B11010 26 139 | #define B011010 26 140 | #define B0011010 26 141 | #define B00011010 26 142 | #define B11011 27 143 | #define B011011 27 144 | #define B0011011 27 145 | #define B00011011 27 146 | #define B11100 28 147 | #define B011100 28 148 | #define B0011100 28 149 | #define B00011100 28 150 | #define B11101 29 151 | #define B011101 29 152 | #define B0011101 29 153 | #define B00011101 29 154 | #define B11110 30 155 | #define B011110 30 156 | #define B0011110 30 157 | #define B00011110 30 158 | #define B11111 31 159 | #define B011111 31 160 | #define B0011111 31 161 | #define B00011111 31 162 | #define B100000 32 163 | #define B0100000 32 164 | #define B00100000 32 165 | #define B100001 33 166 | #define B0100001 33 167 | #define B00100001 33 168 | #define B100010 34 169 | #define B0100010 34 170 | #define B00100010 34 171 | #define B100011 35 172 | #define B0100011 35 173 | #define B00100011 35 174 | #define B100100 36 175 | #define B0100100 36 176 | #define B00100100 36 177 | #define B100101 37 178 | #define B0100101 37 179 | #define B00100101 37 180 | #define B100110 38 181 | #define B0100110 38 182 | #define B00100110 38 183 | #define B100111 39 184 | #define B0100111 39 185 | #define B00100111 39 186 | #define B101000 40 187 | #define B0101000 40 188 | #define B00101000 40 189 | #define B101001 41 190 | #define B0101001 41 191 | #define B00101001 41 192 | #define B101010 42 193 | #define B0101010 42 194 | #define B00101010 42 195 | #define B101011 43 196 | #define B0101011 43 197 | #define B00101011 43 198 | #define B101100 44 199 | #define B0101100 44 200 | #define B00101100 44 201 | #define B101101 45 202 | #define B0101101 45 203 | #define B00101101 45 204 | #define B101110 46 205 | #define B0101110 46 206 | #define B00101110 46 207 | #define B101111 47 208 | #define B0101111 47 209 | #define B00101111 47 210 | #define B110000 48 211 | #define B0110000 48 212 | #define B00110000 48 213 | #define B110001 49 214 | #define B0110001 49 215 | #define B00110001 49 216 | #define B110010 50 217 | #define B0110010 50 218 | #define B00110010 50 219 | #define B110011 51 220 | #define B0110011 51 221 | #define B00110011 51 222 | #define B110100 52 223 | #define B0110100 52 224 | #define B00110100 52 225 | #define B110101 53 226 | #define B0110101 53 227 | #define B00110101 53 228 | #define B110110 54 229 | #define B0110110 54 230 | #define B00110110 54 231 | #define B110111 55 232 | #define B0110111 55 233 | #define B00110111 55 234 | #define B111000 56 235 | #define B0111000 56 236 | #define B00111000 56 237 | #define B111001 57 238 | #define B0111001 57 239 | #define B00111001 57 240 | #define B111010 58 241 | #define B0111010 58 242 | #define B00111010 58 243 | #define B111011 59 244 | #define B0111011 59 245 | #define B00111011 59 246 | #define B111100 60 247 | #define B0111100 60 248 | #define B00111100 60 249 | #define B111101 61 250 | #define B0111101 61 251 | #define B00111101 61 252 | #define B111110 62 253 | #define B0111110 62 254 | #define B00111110 62 255 | #define B111111 63 256 | #define B0111111 63 257 | #define B00111111 63 258 | #define B1000000 64 259 | #define B01000000 64 260 | #define B1000001 65 261 | #define B01000001 65 262 | #define B1000010 66 263 | #define B01000010 66 264 | #define B1000011 67 265 | #define B01000011 67 266 | #define B1000100 68 267 | #define B01000100 68 268 | #define B1000101 69 269 | #define B01000101 69 270 | #define B1000110 70 271 | #define B01000110 70 272 | #define B1000111 71 273 | #define B01000111 71 274 | #define B1001000 72 275 | #define B01001000 72 276 | #define B1001001 73 277 | #define B01001001 73 278 | #define B1001010 74 279 | #define B01001010 74 280 | #define B1001011 75 281 | #define B01001011 75 282 | #define B1001100 76 283 | #define B01001100 76 284 | #define B1001101 77 285 | #define B01001101 77 286 | #define B1001110 78 287 | #define B01001110 78 288 | #define B1001111 79 289 | #define B01001111 79 290 | #define B1010000 80 291 | #define B01010000 80 292 | #define B1010001 81 293 | #define B01010001 81 294 | #define B1010010 82 295 | #define B01010010 82 296 | #define B1010011 83 297 | #define B01010011 83 298 | #define B1010100 84 299 | #define B01010100 84 300 | #define B1010101 85 301 | #define B01010101 85 302 | #define B1010110 86 303 | #define B01010110 86 304 | #define B1010111 87 305 | #define B01010111 87 306 | #define B1011000 88 307 | #define B01011000 88 308 | #define B1011001 89 309 | #define B01011001 89 310 | #define B1011010 90 311 | #define B01011010 90 312 | #define B1011011 91 313 | #define B01011011 91 314 | #define B1011100 92 315 | #define B01011100 92 316 | #define B1011101 93 317 | #define B01011101 93 318 | #define B1011110 94 319 | #define B01011110 94 320 | #define B1011111 95 321 | #define B01011111 95 322 | #define B1100000 96 323 | #define B01100000 96 324 | #define B1100001 97 325 | #define B01100001 97 326 | #define B1100010 98 327 | #define B01100010 98 328 | #define B1100011 99 329 | #define B01100011 99 330 | #define B1100100 100 331 | #define B01100100 100 332 | #define B1100101 101 333 | #define B01100101 101 334 | #define B1100110 102 335 | #define B01100110 102 336 | #define B1100111 103 337 | #define B01100111 103 338 | #define B1101000 104 339 | #define B01101000 104 340 | #define B1101001 105 341 | #define B01101001 105 342 | #define B1101010 106 343 | #define B01101010 106 344 | #define B1101011 107 345 | #define B01101011 107 346 | #define B1101100 108 347 | #define B01101100 108 348 | #define B1101101 109 349 | #define B01101101 109 350 | #define B1101110 110 351 | #define B01101110 110 352 | #define B1101111 111 353 | #define B01101111 111 354 | #define B1110000 112 355 | #define B01110000 112 356 | #define B1110001 113 357 | #define B01110001 113 358 | #define B1110010 114 359 | #define B01110010 114 360 | #define B1110011 115 361 | #define B01110011 115 362 | #define B1110100 116 363 | #define B01110100 116 364 | #define B1110101 117 365 | #define B01110101 117 366 | #define B1110110 118 367 | #define B01110110 118 368 | #define B1110111 119 369 | #define B01110111 119 370 | #define B1111000 120 371 | #define B01111000 120 372 | #define B1111001 121 373 | #define B01111001 121 374 | #define B1111010 122 375 | #define B01111010 122 376 | #define B1111011 123 377 | #define B01111011 123 378 | #define B1111100 124 379 | #define B01111100 124 380 | #define B1111101 125 381 | #define B01111101 125 382 | #define B1111110 126 383 | #define B01111110 126 384 | #define B1111111 127 385 | #define B01111111 127 386 | #define B10000000 128 387 | #define B10000001 129 388 | #define B10000010 130 389 | #define B10000011 131 390 | #define B10000100 132 391 | #define B10000101 133 392 | #define B10000110 134 393 | #define B10000111 135 394 | #define B10001000 136 395 | #define B10001001 137 396 | #define B10001010 138 397 | #define B10001011 139 398 | #define B10001100 140 399 | #define B10001101 141 400 | #define B10001110 142 401 | #define B10001111 143 402 | #define B10010000 144 403 | #define B10010001 145 404 | #define B10010010 146 405 | #define B10010011 147 406 | #define B10010100 148 407 | #define B10010101 149 408 | #define B10010110 150 409 | #define B10010111 151 410 | #define B10011000 152 411 | #define B10011001 153 412 | #define B10011010 154 413 | #define B10011011 155 414 | #define B10011100 156 415 | #define B10011101 157 416 | #define B10011110 158 417 | #define B10011111 159 418 | #define B10100000 160 419 | #define B10100001 161 420 | #define B10100010 162 421 | #define B10100011 163 422 | #define B10100100 164 423 | #define B10100101 165 424 | #define B10100110 166 425 | #define B10100111 167 426 | #define B10101000 168 427 | #define B10101001 169 428 | #define B10101010 170 429 | #define B10101011 171 430 | #define B10101100 172 431 | #define B10101101 173 432 | #define B10101110 174 433 | #define B10101111 175 434 | #define B10110000 176 435 | #define B10110001 177 436 | #define B10110010 178 437 | #define B10110011 179 438 | #define B10110100 180 439 | #define B10110101 181 440 | #define B10110110 182 441 | #define B10110111 183 442 | #define B10111000 184 443 | #define B10111001 185 444 | #define B10111010 186 445 | #define B10111011 187 446 | #define B10111100 188 447 | #define B10111101 189 448 | #define B10111110 190 449 | #define B10111111 191 450 | #define B11000000 192 451 | #define B11000001 193 452 | #define B11000010 194 453 | #define B11000011 195 454 | #define B11000100 196 455 | #define B11000101 197 456 | #define B11000110 198 457 | #define B11000111 199 458 | #define B11001000 200 459 | #define B11001001 201 460 | #define B11001010 202 461 | #define B11001011 203 462 | #define B11001100 204 463 | #define B11001101 205 464 | #define B11001110 206 465 | #define B11001111 207 466 | #define B11010000 208 467 | #define B11010001 209 468 | #define B11010010 210 469 | #define B11010011 211 470 | #define B11010100 212 471 | #define B11010101 213 472 | #define B11010110 214 473 | #define B11010111 215 474 | #define B11011000 216 475 | #define B11011001 217 476 | #define B11011010 218 477 | #define B11011011 219 478 | #define B11011100 220 479 | #define B11011101 221 480 | #define B11011110 222 481 | #define B11011111 223 482 | #define B11100000 224 483 | #define B11100001 225 484 | #define B11100010 226 485 | #define B11100011 227 486 | #define B11100100 228 487 | #define B11100101 229 488 | #define B11100110 230 489 | #define B11100111 231 490 | #define B11101000 232 491 | #define B11101001 233 492 | #define B11101010 234 493 | #define B11101011 235 494 | #define B11101100 236 495 | #define B11101101 237 496 | #define B11101110 238 497 | #define B11101111 239 498 | #define B11110000 240 499 | #define B11110001 241 500 | #define B11110010 242 501 | #define B11110011 243 502 | #define B11110100 244 503 | #define B11110101 245 504 | #define B11110110 246 505 | #define B11110111 247 506 | #define B11111000 248 507 | #define B11111001 249 508 | #define B11111010 250 509 | #define B11111011 251 510 | #define B11111100 252 511 | #define B11111101 253 512 | #define B11111110 254 513 | #define B11111111 255 514 | 515 | #endif 516 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/core_adc.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | core_adc.h - Veneer for the analog-to-digital converter. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #ifndef core_adc_h 25 | #define core_adc_h 26 | 27 | #include 28 | #include 29 | 30 | #include "core_build_options.h" 31 | #include "core_macros.h" 32 | 33 | 34 | /*============================================================================= 35 | Some common things 36 | =============================================================================*/ 37 | 38 | #if defined( __AVR_ATtinyX4__ ) || defined( __AVR_ATtinyX5__ ) 39 | 40 | /* 41 | From the '84 and '85 datasheets... By default, the successive approximation 42 | circuitry requires an input clock frequency between 50 kHz and 200 kHz to 43 | get maximum resolution. 44 | */ 45 | #if F_CPU == 16000000 46 | // 16 MHz / 128 = 125 KHz 47 | #define ADC_ARDUINO_PRESCALER ADC_Prescaler_Value_128 48 | #elif F_CPU == 8000000 49 | // 8 MHz / 64 = 125 KHz 50 | #define ADC_ARDUINO_PRESCALER ADC_Prescaler_Value_64 51 | #elif F_CPU == 1000000 52 | // 1 MHz / 8 = 125 KHz 53 | #define ADC_ARDUINO_PRESCALER ADC_Prescaler_Value_8 54 | #else 55 | #error Add an entry for the selected processor speed. 56 | #endif 57 | 58 | typedef enum 59 | { 60 | ADC_Prescaler_Value_2 = B001, 61 | ADC_Prescaler_Value_4 = B010, 62 | ADC_Prescaler_Value_8 = B011, 63 | ADC_Prescaler_Value_16 = B100, 64 | ADC_Prescaler_Value_32 = B101, 65 | ADC_Prescaler_Value_64 = B110, 66 | ADC_Prescaler_Value_128 = B111, 67 | ADC_Prescaler_Index_1 = B001, 68 | ADC_Prescaler_Index_2 = B010, 69 | ADC_Prescaler_Index_3 = B011, 70 | ADC_Prescaler_Index_4 = B100, 71 | ADC_Prescaler_Index_5 = B101, 72 | ADC_Prescaler_Index_6 = B110, 73 | ADC_Prescaler_Index_7 = B111 74 | } 75 | adc_ps_t; 76 | 77 | __attribute__((always_inline)) static inline void ADC_PrescalerSelect( adc_ps_t ps ) 78 | { 79 | ADCSRA = (ADCSRA & ~MASK3(ADPS2,ADPS1,ADPS0)) | (ps << ADPS0); 80 | } 81 | 82 | __attribute__((always_inline)) static inline void ADC_Enable( void ) 83 | { 84 | ADCSRA |= MASK1( ADEN ); 85 | } 86 | 87 | #endif 88 | 89 | 90 | /*============================================================================= 91 | Veneer for the ATtiny84 ADC 92 | =============================================================================*/ 93 | 94 | #if defined( __AVR_ATtinyX4__ ) 95 | 96 | typedef enum 97 | { 98 | ADC_Reference_VCC = B00, 99 | ADC_Reference_External = B01, 100 | ADC_Reference_Internal_1p1 = B10, 101 | ADC_Reference_Reserved_1 = B11 102 | } 103 | adc_vr_t; 104 | 105 | __attribute__((always_inline)) static inline void ADC_SetVoltageReference( adc_vr_t vr ) 106 | { 107 | ADMUX = (ADMUX & ~MASK2(REFS1,REFS0)) | (((vr & B11) >> 0) << REFS0); 108 | } 109 | 110 | typedef enum 111 | { 112 | ADC_Input_ADC0 = B000000, 113 | ADC_Input_ADC1 = B000001, 114 | ADC_Input_ADC2 = B000010, 115 | ADC_Input_ADC3 = B000011, 116 | ADC_Input_ADC4 = B000100, 117 | ADC_Input_ADC5 = B000101, 118 | ADC_Input_ADC6 = B000110, 119 | ADC_Input_ADC7 = B000111, 120 | 121 | ADC_Input_GND = B100000, // 0V (AGND) 122 | ADC_Input_1p1 = B100001, // 1.1V (I Ref) 123 | ADC_Input_ADC8 = B100010, // For temperature sensor. 124 | 125 | ADC_Input_Pos0_Neg0_20x = B100011, // For offset calibration, only. 126 | ADC_Input_Pos0_Neg1_1x = B001000, 127 | ADC_Input_Pos0_Neg1_20x = B001001, 128 | ADC_Input_Pos0_Neg3_1x = B001010, 129 | ADC_Input_Pos0_Neg3_20x = B001011, 130 | ADC_Input_Pos1_Neg0_1x = B101000, 131 | ADC_Input_Pos1_Neg0_20x = B101001, 132 | ADC_Input_Pos1_Neg2_1x = B001100, 133 | ADC_Input_Pos1_Neg2_20x = B001101, 134 | ADC_Input_Pos1_Neg3_1x = B001110, 135 | ADC_Input_Pos1_Neg3_20x = B001111, 136 | ADC_Input_Pos2_Neg1_1x = B101100, 137 | ADC_Input_Pos2_Neg1_20x = B101101, 138 | ADC_Input_Pos2_Neg3_1x = B010000, 139 | ADC_Input_Pos2_Neg3_20x = B010001, 140 | ADC_Input_Pos3_Neg0_1x = B101010, 141 | ADC_Input_Pos3_Neg0_20x = B101011, 142 | ADC_Input_Pos3_Neg1_1x = B101110, 143 | ADC_Input_Pos3_Neg1_20x = B101111, 144 | ADC_Input_Pos3_Neg2_1x = B110000, 145 | ADC_Input_Pos3_Neg2_20x = B110001, 146 | ADC_Input_Pos3_Neg3_1x = B100100, // For offset calibration, only. 147 | ADC_Input_Pos3_Neg3_20x = B100101, // For offset calibration, only. 148 | ADC_Input_Pos3_Neg4_1x = B010010, 149 | ADC_Input_Pos3_Neg4_20x = B010011, 150 | ADC_Input_Pos3_Neg5_1x = B010100, 151 | ADC_Input_Pos3_Neg5_20x = B010101, 152 | ADC_Input_Pos3_Neg6_1x = B010110, 153 | ADC_Input_Pos3_Neg6_20x = B010111, 154 | ADC_Input_Pos3_Neg7_1x = B011000, 155 | ADC_Input_Pos3_Neg7_20x = B011001, 156 | ADC_Input_Pos4_Neg3_1x = B110010, 157 | ADC_Input_Pos4_Neg3_20x = B110011, 158 | ADC_Input_Pos4_Neg5_1x = B011010, 159 | ADC_Input_Pos4_Neg5_20x = B011011, 160 | ADC_Input_Pos5_Neg3_1x = B110100, 161 | ADC_Input_Pos5_Neg3_20x = B110101, 162 | ADC_Input_Pos5_Neg4_1x = B111010, 163 | ADC_Input_Pos5_Neg4_20x = B111011, 164 | ADC_Input_Pos5_Neg6_1x = B011100, 165 | ADC_Input_Pos5_Neg6_20x = B011101, 166 | ADC_Input_Pos6_Neg3_1x = B110110, 167 | ADC_Input_Pos6_Neg3_20x = B110111, 168 | ADC_Input_Pos6_Neg5_1x = B111100, 169 | ADC_Input_Pos6_Neg5_20x = B111101, 170 | ADC_Input_Pos6_Neg7_1x = B011110, 171 | ADC_Input_Pos6_Neg7_20x = B011111, 172 | ADC_Input_Pos7_Neg3_1x = B111000, 173 | ADC_Input_Pos7_Neg3_20x = B111001, 174 | ADC_Input_Pos7_Neg6_1x = B111110, 175 | ADC_Input_Pos7_Neg6_20x = B111111, 176 | ADC_Input_Pos7_Neg7_1x = B100110, // For offset calibration, only. 177 | ADC_Input_Pos7_Neg7_20x = B100111 // For offset calibration, only. 178 | } 179 | adc_ic_t; 180 | 181 | __attribute__((always_inline)) static inline void ADC_SetInputChannel( adc_ic_t ic ) 182 | { 183 | ADMUX = (ADMUX & ~MASK6(MUX5,MUX4,MUX3,MUX2,MUX1,MUX0)) | (ic << MUX0); 184 | } 185 | 186 | __attribute__((always_inline)) static inline void ADC_StartConversion( void ) 187 | { 188 | ADCSRA |= MASK1( ADSC ); 189 | } 190 | 191 | __attribute__((always_inline)) static inline uint8_t ADC_ConversionInProgress( void ) 192 | { 193 | return( (ADCSRA & (1<> 0) << REFS0) 225 | | (((vr & B100) >> 2) << REFS2); 226 | } 227 | 228 | typedef enum 229 | { 230 | ADC_Input_ADC0 = B0000, 231 | ADC_Input_ADC1 = B0001, 232 | ADC_Input_ADC2 = B0010, 233 | ADC_Input_ADC3 = B0011, 234 | 235 | ADC_Input_Pos2_Neg2_1x = B0100, // For offset calibration, only. 236 | ADC_Input_Pos2_Neg2_20x = B0101, // For offset calibration, only. 237 | ADC_Input_Pos2_Neg3_1x = B0110, 238 | ADC_Input_Pos2_Neg3_20x = B0111, 239 | ADC_Input_Pos0_Neg0_1x = B1000, 240 | ADC_Input_Pos0_Neg0_20x = B1001, 241 | ADC_Input_Pos0_Neg1_1x = B1010, 242 | ADC_Input_Pos0_Neg1_20x = B1011, 243 | 244 | ADC_Input_VBG = B1100, 245 | ADC_Input_GND = B1101, 246 | ADC_Input_NA = B1110, 247 | ADC_Input_ADC4 = B1111 // For temperature sensor. 248 | } 249 | adc_ic_t; 250 | 251 | __attribute__((always_inline)) static inline void ADC_SetInputChannel( adc_ic_t ic ) 252 | { 253 | ADMUX = (ADMUX & ~MASK4(MUX3,MUX2,MUX1,MUX0)) | (ic << MUX0); 254 | } 255 | 256 | __attribute__((always_inline)) static inline void ADC_StartConversion( void ) 257 | { 258 | ADCSRA |= MASK1( ADSC ); 259 | } 260 | 261 | __attribute__((always_inline)) static inline uint8_t ADC_ConversionInProgress( void ) 262 | { 263 | return( (ADCSRA & (1<. 21 | 22 | ==============================================================================*/ 23 | 24 | #ifndef core_build_options_h 25 | #define core_build_options_h 26 | 27 | 28 | /*============================================================================= 29 | Low power / smaller code options 30 | =============================================================================*/ 31 | 32 | #define INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER 1 33 | #define INITIALIZE_SECONDARY_TIMERS 1 34 | 35 | 36 | /*============================================================================= 37 | Build options for the ATtinyX313 processor 38 | =============================================================================*/ 39 | 40 | #if defined( __AVR_ATtiny2313__ ) || defined( __AVR_ATtiny4313__ ) 41 | #define __AVR_ATtinyX313__ 42 | #endif 43 | 44 | #if defined( __AVR_ATtinyX313__ ) 45 | 46 | /* 47 | The old standby ... millis on Timer 0. 48 | */ 49 | #define TIMER_TO_USE_FOR_MILLIS 0 50 | 51 | /* 52 | Tone goes on whichever timer was not used for millis. 53 | */ 54 | #if TIMER_TO_USE_FOR_MILLIS == 1 55 | #define TIMER_TO_USE_FOR_TONE 0 56 | #else 57 | #define TIMER_TO_USE_FOR_TONE 1 58 | #endif 59 | 60 | #define HAVE_ADC 0 61 | 62 | #define DEFAULT_TO_TINY_DEBUG_SERIAL 0 63 | 64 | #endif 65 | 66 | 67 | /*============================================================================= 68 | Build options for the ATtiny84 processor 69 | =============================================================================*/ 70 | 71 | #if defined( __AVR_ATtiny24__ ) || defined( __AVR_ATtiny44__ ) || defined( __AVR_ATtiny84__ ) 72 | #define __AVR_ATtinyX4__ 73 | #endif 74 | 75 | #if defined( __AVR_ATtinyX4__ ) 76 | 77 | /* 78 | The old standby ... millis on Timer 0. 79 | */ 80 | #define TIMER_TO_USE_FOR_MILLIS 0 81 | 82 | /* 83 | Tone goes on whichever timer was not used for millis. 84 | */ 85 | #if TIMER_TO_USE_FOR_MILLIS == 1 86 | #define TIMER_TO_USE_FOR_TONE 0 87 | #else 88 | #define TIMER_TO_USE_FOR_TONE 1 89 | #endif 90 | 91 | #define HAVE_ADC 1 92 | 93 | #define DEFAULT_TO_TINY_DEBUG_SERIAL 1 94 | 95 | #endif 96 | 97 | 98 | /*============================================================================= 99 | Build options for the ATtiny85 processor 100 | =============================================================================*/ 101 | 102 | #if defined( __AVR_ATtiny25__ ) || defined( __AVR_ATtiny45__ ) || defined( __AVR_ATtiny85__ ) 103 | #define __AVR_ATtinyX5__ 104 | #endif 105 | 106 | #if defined( __AVR_ATtinyX5__ ) 107 | 108 | /* 109 | For various reasons, Timer 1 is a better choice for the millis timer on the 110 | '85 processor. 111 | */ 112 | #define TIMER_TO_USE_FOR_MILLIS 1 113 | 114 | /* 115 | If the following is true (non-zero) there will be two phase-correct PWM 116 | pins and one fast PWM pin. If false there will be one phase-correct PWM 117 | pin and two fast PWM pins. 118 | */ 119 | #define FAVOR_PHASE_CORRECT_PWM 1 120 | 121 | /* 122 | Tone goes on whichever timer was not used for millis. 123 | */ 124 | #if TIMER_TO_USE_FOR_MILLIS == 1 125 | #define TIMER_TO_USE_FOR_TONE 0 126 | #else 127 | #define TIMER_TO_USE_FOR_TONE 1 128 | #endif 129 | 130 | #define HAVE_ADC 1 131 | 132 | #define DEFAULT_TO_TINY_DEBUG_SERIAL 1 133 | 134 | #endif 135 | 136 | 137 | /*============================================================================= 138 | There doesn't seem to be many people using a bootloader so we'll assume 139 | there isn't one. If the following is true (non-zero), the timers are 140 | reinitialized to their power-up state in init just in case the bootloader 141 | left them in a bad way. 142 | =============================================================================*/ 143 | 144 | #define HAVE_BOOTLOADER 0 145 | 146 | 147 | /*============================================================================= 148 | Allow the ADC to be optional for low-power applications 149 | =============================================================================*/ 150 | 151 | #if ! defined( HAVE_ADC ) 152 | #define HAVE_ADC 0 153 | #endif 154 | 155 | #if ! HAVE_ADC 156 | #undef INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER 157 | #define INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER 0 158 | #else 159 | #if ! defined( INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER ) 160 | #define INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER 1 161 | #endif 162 | #endif 163 | 164 | 165 | /*============================================================================= 166 | Allow the "secondary timers" to be optional for low-power applications 167 | =============================================================================*/ 168 | 169 | #if ! defined( INITIALIZE_SECONDARY_TIMERS ) 170 | #define INITIALIZE_SECONDARY_TIMERS 1 171 | #endif 172 | 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/core_macros.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | core_macros.h - Simple but handy macros. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #ifndef core_macros_h 25 | #define core_macros_h 26 | 27 | 28 | /*============================================================================= 29 | Bitmask macros 30 | =============================================================================*/ 31 | 32 | #define MASK1(b1) ( (1<. 21 | 22 | ==============================================================================*/ 23 | 24 | #ifndef core_pins_h 25 | #define core_pins_h 26 | 27 | #include "core_build_options.h" 28 | 29 | 30 | /*============================================================================= 31 | Pin definitions for the ATtinyX313 32 | =============================================================================*/ 33 | 34 | #if defined( __AVR_ATtinyX313__ ) 35 | 36 | #define PIN_D0 ( 0) 37 | #define PIN_D1 ( 1) 38 | #define PIN_A1 ( 2) 39 | #define PIN_A0 ( 3) 40 | #define PIN_D2 ( 4) 41 | #define PIN_D3 ( 5) 42 | #define PIN_D4 ( 6) 43 | #define PIN_D5 ( 7) 44 | #define PIN_D6 ( 8) 45 | #define PIN_B0 ( 9) 46 | #define PIN_B1 (10) 47 | #define PIN_B2 (11) 48 | #define PIN_B3 (12) 49 | #define PIN_B4 (13) 50 | #define PIN_B5 (14) 51 | #define PIN_B6 (15) 52 | #define PIN_B7 (16) 53 | #define PIN_A2 (17) /* RESET */ 54 | 55 | #define CORE_DIGITAL_FIRST (0) 56 | #define CORE_DIGITAL_LAST (17) 57 | #define CORE_DIGITAL_COUNT (CORE_DIGITAL_LAST-CORE_DIGITAL_FIRST+1) 58 | #define CORE_RESET_INCLUDED (1) 59 | 60 | #define CORE_ANALOG_COUNT (0) 61 | 62 | #define CORE_INT0_PIN PIN_D2 63 | #define CORE_INT1_PIN PIN_D3 64 | 65 | #define CORE_OC0A_PIN PIN_B2 66 | #define CORE_OC0B_PIN PIN_D5 67 | #define CORE_OC1A_PIN PIN_B3 68 | #define CORE_OC1B_PIN PIN_B4 69 | 70 | #define CORE_PWM0_PIN CORE_OC0A_PIN 71 | #define CORE_PWM0_TIMER 0 72 | #define CORE_PWM0_CHANNEL A 73 | 74 | #define CORE_PWM1_PIN CORE_OC0B_PIN 75 | #define CORE_PWM1_TIMER 0 76 | #define CORE_PWM1_CHANNEL B 77 | 78 | #define CORE_PWM2_PIN CORE_OC1A_PIN 79 | #define CORE_PWM2_TIMER 1 80 | #define CORE_PWM2_CHANNEL A 81 | 82 | #define CORE_PWM3_PIN CORE_OC1B_PIN 83 | #define CORE_PWM3_TIMER 1 84 | #define CORE_PWM3_CHANNEL B 85 | 86 | #define CORE_PWM_COUNT (4) 87 | 88 | #endif 89 | 90 | 91 | /*============================================================================= 92 | Pin definitions for the ATtiny84 93 | =============================================================================*/ 94 | 95 | #if defined( __AVR_ATtinyX4__ ) 96 | 97 | #define PIN_A0 (10) 98 | #define PIN_A1 ( 9) 99 | #define PIN_A2 ( 8) 100 | #define PIN_A3 ( 7) 101 | #define PIN_A4 ( 6) 102 | #define PIN_A5 ( 5) 103 | #define PIN_A6 ( 4) 104 | #define PIN_A7 ( 3) 105 | #define PIN_B0 ( 0) 106 | #define PIN_B1 ( 1) 107 | #define PIN_B2 ( 2) 108 | #define PIN_B3 (11) /* RESET */ 109 | 110 | #define CORE_DIGITAL_FIRST (0) 111 | #define CORE_DIGITAL_LAST (11) 112 | #define CORE_DIGITAL_COUNT (CORE_DIGITAL_LAST-CORE_DIGITAL_FIRST+1) 113 | #define CORE_RESET_INCLUDED (1) 114 | 115 | #define CORE_ANALOG_FIRST (CORE_DIGITAL_LAST+1) 116 | #define CORE_ANALOG_COUNT (8) 117 | #define CORE_ANALOG_LAST (CORE_ANALOG_FIRST+CORE_ANALOG_COUNT-1) 118 | 119 | #define CORE_INT0_PIN PIN_B2 120 | 121 | #define CORE_OC0A_PIN PIN_B2 122 | #define CORE_OC0B_PIN PIN_A7 123 | #define CORE_OC1A_PIN PIN_A6 124 | #define CORE_OC1B_PIN PIN_A5 125 | 126 | #define CORE_PWM0_PIN CORE_OC0A_PIN 127 | #define CORE_PWM0_TIMER 0 128 | #define CORE_PWM0_CHANNEL A 129 | 130 | #define CORE_PWM1_PIN CORE_OC0B_PIN 131 | #define CORE_PWM1_TIMER 0 132 | #define CORE_PWM1_CHANNEL B 133 | 134 | #define CORE_PWM2_PIN CORE_OC1A_PIN 135 | #define CORE_PWM2_TIMER 1 136 | #define CORE_PWM2_CHANNEL A 137 | 138 | #define CORE_PWM3_PIN CORE_OC1B_PIN 139 | #define CORE_PWM3_TIMER 1 140 | #define CORE_PWM3_CHANNEL B 141 | 142 | #define CORE_PWM_COUNT (4) 143 | 144 | #endif 145 | 146 | 147 | /*============================================================================= 148 | Pin definitions for the ATtiny85 149 | =============================================================================*/ 150 | 151 | #if defined( __AVR_ATtinyX5__ ) 152 | 153 | #define PIN_B0 ( 0) 154 | #define PIN_B1 ( 1) 155 | #define PIN_B2 ( 2) 156 | #define PIN_B3 ( 3) 157 | #define PIN_B4 ( 4) 158 | #define PIN_B5 ( 5) /* RESET */ 159 | 160 | #define CORE_DIGITAL_FIRST (0) 161 | #define CORE_DIGITAL_LAST (5) 162 | #define CORE_DIGITAL_COUNT (CORE_DIGITAL_LAST-CORE_DIGITAL_FIRST+1) 163 | #define CORE_RESET_INCLUDED (1) 164 | 165 | #define CORE_ANALOG_FIRST (CORE_DIGITAL_LAST+1) 166 | #define CORE_ANALOG_COUNT (4) 167 | #define CORE_ANALOG_LAST (CORE_ANALOG_FIRST+CORE_ANALOG_COUNT-1) 168 | 169 | #define CORE_INT0_PIN PIN_B2 170 | 171 | #define CORE_OC0A_PIN PIN_B0 172 | #define CORE_OC0B_PIN PIN_B1 173 | #define CORE_OC1A_PIN PIN_B1 174 | #define CORE_OC1B_PIN PIN_B4 175 | 176 | /* Note: By default, CORE_OC1A_PIN is not used for PWM. It overlaps with 177 | CORE_OC0B_PIN. CORE_OC0B_PIN was used because it supports phase-correct PWM. 178 | There is a build option in "core_build_options.h" to determine which channel 179 | to use */ 180 | 181 | #define CORE_PWM0_PIN CORE_OC0A_PIN 182 | #define CORE_PWM0_TIMER 0 183 | #define CORE_PWM0_CHANNEL A 184 | 185 | #if FAVOR_PHASE_CORRECT_PWM 186 | #define CORE_PWM1_PIN CORE_OC0B_PIN 187 | #define CORE_PWM1_TIMER 0 188 | #define CORE_PWM1_CHANNEL B 189 | #else 190 | #define CORE_PWM1_PIN CORE_OC1A_PIN 191 | #define CORE_PWM1_TIMER 1 192 | #define CORE_PWM1_CHANNEL A 193 | #endif 194 | 195 | #define CORE_PWM2_PIN CORE_OC1B_PIN 196 | #define CORE_PWM2_TIMER 1 197 | #define CORE_PWM2_CHANNEL B 198 | 199 | #define CORE_PWM_COUNT (3) 200 | 201 | #endif 202 | 203 | 204 | #endif 205 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | init(); 6 | 7 | setup(); 8 | 9 | for (;;) 10 | loop(); 11 | 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/pins_arduino.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambo/arduino-tiny/e1c107a5a18fef491c824be8e6c88ef8f59be594/hardware/tiny/cores/tiny/pins_arduino.c -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ 23 | 24 | Modified 28-08-2009 for attiny84 R.Wiersma 25 | Modified 14-10-2009 for attiny45 Saposoft 26 | */ 27 | 28 | #ifndef Pins_Arduino_h 29 | #define Pins_Arduino_h 30 | 31 | #include 32 | 33 | #include "core_build_options.h" 34 | 35 | #if defined( __AVR_ATtinyX313__ ) 36 | #define PORT_A_ID 1 37 | #define PORT_B_ID 2 38 | #define PORT_D_ID 4 39 | #endif 40 | 41 | #if defined( __AVR_ATtinyX4__ ) 42 | #define PORT_A_ID 1 43 | #define PORT_B_ID 2 44 | #endif 45 | 46 | #if defined( __AVR_ATtinyX5__ ) 47 | #define PORT_B_ID 1 48 | #endif 49 | 50 | #define NOT_A_PIN 0 51 | #define NOT_A_PORT 0 52 | 53 | #define NOT_ON_TIMER 0 54 | #define TIMER0A 1 55 | #define TIMER0B 2 56 | #define TIMER1A 3 57 | #define TIMER1B 4 58 | 59 | //changed it to uint16_t to uint8_t 60 | extern const uint8_t PROGMEM port_to_mode_PGM[]; 61 | extern const uint8_t PROGMEM port_to_input_PGM[]; 62 | extern const uint8_t PROGMEM port_to_output_PGM[]; 63 | extern const uint8_t PROGMEM port_to_pcmask_PGM[]; 64 | 65 | extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; 66 | // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; 67 | extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; 68 | extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; 69 | 70 | // Get the bit location within the hardware port of the given virtual pin. 71 | // This comes from the pins_*.c file for the active board configuration. 72 | // 73 | // These perform slightly better as macros compared to inline functions 74 | // 75 | #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) 76 | #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) 77 | #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) 78 | #define analogInPinToBit(P) (P) 79 | // in the following lines modified pgm_read_word in pgm_read_byte, word doesn't work on attiny45 80 | #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_output_PGM + (P))) ) 81 | #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_input_PGM + (P))) ) 82 | #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_mode_PGM + (P))) ) 83 | #define portPcMaskRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_pcmask_PGM + (P))) ) 84 | 85 | #if defined(__AVR_ATtinyX5__) 86 | #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 5) ? (&GIMSK) : ((uint8_t *)NULL)) 87 | #define digitalPinToPCICRbit(p) (PCIE) 88 | #define digitalPinToPCMSK(p) (((p) >= 0 && (p) <= 5) ? (&PCMSK) : ((uint8_t *)NULL)) 89 | #define digitalPinToPCMSKbit(p) (p) 90 | #endif 91 | 92 | #if defined(__AVR_ATtinyX4__) 93 | #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 10) ? (&GIMSK) : ((uint8_t *)NULL)) 94 | #define digitalPinToPCICRbit(p) (((p) <= 2) ? PCIE1 : PCIE0) 95 | #define digitalPinToPCMSK(p) (((p) <= 2) ? (&PCMSK1) : (((p) <= 10) ? (&PCMSK0) : ((uint8_t *)NULL))) 96 | #define digitalPinToPCMSKbit(p) (((p) <= 2) ? (p) : (10 - (p))) 97 | #endif 98 | 99 | #if defined(__AVR_ATtiny4313__) 100 | #define digitalPinToPCX(p,s1,s2,s3,s4,s5) \ 101 | (((p) >= 0) \ 102 | ? (((p) <= 1) ? (s1) /* 0 - 1 ==> D0 - D1 */ \ 103 | : (((p) <= 3) ? (s2) /* 2 - 3 ==> A1 - A0 */ \ 104 | : (((p) <= 8) ? (s3) /* 4 - 8 ==> D2 - D6 */ \ 105 | : (((p) <= 16) ? (s4) /* 9 - 16 ==> B0 - B7 */ \ 106 | : (s5))))) \ 107 | : (s5)) 108 | // s1 D s2 A s3 D s4 B 109 | #define digitalPinToPCICR(p) digitalPinToPCX( p, &GIMSK, &GIMSK, &GIMSK, &GIMSK, NULL ) 110 | #define digitalPinToPCICRbit(p) digitalPinToPCX( p, PCIE2, PCIE1, PCIE2, PCIE0, 0 ) 111 | #define digitalPinToPCMSK(p) digitalPinToPCX( p, &PCMSK2, &PCMSK1, &PCMSK2, &PCMSK0, NULL ) 112 | #define digitalPinToPCMSKbit(p) digitalPinToPCX( p, p, 3-p, p-2, p-9, 0 ) 113 | #endif 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 970 2010-05-25 20:16:15Z dmellis $ 23 | 24 | Modified 28-08-2009 for attiny84 R.Wiersma 25 | Modified 14-10-2009 for attiny45 Saposoft 26 | Modified 20-11-2010 - B.Cook - Rewritten to use the various Veneers. 27 | */ 28 | 29 | #include "core_build_options.h" 30 | #include "core_adc.h" 31 | #include "core_timers.h" 32 | #include "wiring_private.h" 33 | #include "ToneTimer.h" 34 | 35 | #define millistimer_(t) TIMER_PASTE_A( timer, TIMER_TO_USE_FOR_MILLIS, t ) 36 | #define MillisTimer_(f) TIMER_PASTE_A( Timer, TIMER_TO_USE_FOR_MILLIS, f ) 37 | #define MILLISTIMER_(c) TIMER_PASTE_A( TIMER, TIMER_TO_USE_FOR_MILLIS, c ) 38 | 39 | #define MillisTimer_SetToPowerup MillisTimer_(SetToPowerup) 40 | #define MillisTimer_SetWaveformGenerationMode MillisTimer_(SetWaveformGenerationMode) 41 | #define MillisTimer_GetCount MillisTimer_(GetCount) 42 | #define MillisTimer_IsOverflowSet MillisTimer_(IsOverflowSet) 43 | #define MillisTimer_ClockSelect MillisTimer_(ClockSelect) 44 | #define MillisTimer_EnableOverflowInterrupt MillisTimer_(EnableOverflowInterrupt) 45 | #define MILLISTIMER_OVF_vect MILLISTIMER_(OVF_vect) 46 | 47 | 48 | #if F_CPU >= 3000000L 49 | #define MillisTimer_Prescale_Index MillisTimer_(Prescale_Value_64) 50 | #define MillisTimer_Prescale_Value (64) 51 | #define ToneTimer_Prescale_Index ToneTimer_(Prescale_Value_64) 52 | #define ToneTimer_Prescale_Value (64) 53 | #else 54 | #define MillisTimer_Prescale_Index MillisTimer_(Prescale_Value_8) 55 | #define MillisTimer_Prescale_Value (8) 56 | #define ToneTimer_Prescale_Index ToneTimer_(Prescale_Value_8) 57 | #define ToneTimer_Prescale_Value (8) 58 | #endif 59 | 60 | // the prescaler is set so that the millis timer ticks every MillisTimer_Prescale_Value (64) clock cycles, and the 61 | // the overflow handler is called every 256 ticks. 62 | #define MICROSECONDS_PER_MILLIS_OVERFLOW (clockCyclesToMicroseconds(MillisTimer_Prescale_Value * 256)) 63 | 64 | // the whole number of milliseconds per millis timer overflow 65 | #define MILLIS_INC (MICROSECONDS_PER_MILLIS_OVERFLOW / 1000) 66 | 67 | // the fractional number of milliseconds per millis timer overflow. we shift right 68 | // by three to fit these numbers into a byte. (for the clock speeds we care 69 | // about - 8 and 16 MHz - this doesn't lose precision.) 70 | #define FRACT_INC ((MICROSECONDS_PER_MILLIS_OVERFLOW % 1000) >> 3) 71 | #define FRACT_MAX (1000 >> 3) 72 | 73 | volatile unsigned long millis_timer_overflow_count = 0; 74 | volatile unsigned long millis_timer_millis = 0; 75 | static unsigned char millis_timer_fract = 0; 76 | 77 | ISR(MILLISTIMER_OVF_vect) 78 | { 79 | // copy these to local variables so they can be stored in registers 80 | // (volatile variables must be read from memory on every access) 81 | unsigned long m = millis_timer_millis; 82 | unsigned char f = millis_timer_fract; 83 | 84 | /* rmv: The code below generates considerably less code (emtpy Sketch is 326 versus 304)... 85 | 86 | m += MILLIS_INC; 87 | f += FRACT_INC; 88 | if (f >= FRACT_MAX) { 89 | f -= FRACT_MAX; 90 | m += 1; 91 | } 92 | ...rmv */ 93 | 94 | f += FRACT_INC; 95 | 96 | if (f >= FRACT_MAX) 97 | { 98 | f -= FRACT_MAX; 99 | m = m + MILLIS_INC + 1; 100 | } 101 | else 102 | { 103 | m += MILLIS_INC; 104 | } 105 | 106 | millis_timer_fract = f; 107 | millis_timer_millis = m; 108 | millis_timer_overflow_count++; 109 | } 110 | 111 | unsigned long millis() 112 | { 113 | unsigned long m; 114 | uint8_t oldSREG = SREG; 115 | 116 | // disable interrupts while we read millis_timer_millis or we might get an 117 | // inconsistent value (e.g. in the middle of a write to millis_timer_millis) 118 | cli(); 119 | m = millis_timer_millis; 120 | SREG = oldSREG; 121 | 122 | return m; 123 | } 124 | 125 | unsigned long micros() 126 | { 127 | unsigned long m; 128 | uint8_t oldSREG = SREG, t; 129 | 130 | cli(); 131 | m = millis_timer_overflow_count; 132 | t = MillisTimer_GetCount(); 133 | 134 | if (MillisTimer_IsOverflowSet() && (t < 255)) 135 | m++; 136 | 137 | SREG = oldSREG; 138 | 139 | return ((m << 8) + t) * (MillisTimer_Prescale_Value / clockCyclesPerMicrosecond()); 140 | } 141 | 142 | void delay(unsigned long ms) 143 | { 144 | uint16_t start = (uint16_t)micros(); 145 | 146 | while (ms > 0) { 147 | if (((uint16_t)micros() - start) >= 1000) { 148 | ms--; 149 | start += 1000; 150 | } 151 | } 152 | } 153 | 154 | /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ 155 | void delayMicroseconds(unsigned int us) 156 | { 157 | // calling avrlib's delay_us() function with low values (e.g. 1 or 158 | // 2 microseconds) gives delays longer than desired. 159 | //delay_us(us); 160 | 161 | #if F_CPU >= 16000000L 162 | // for the 16 MHz clock on most Arduino boards 163 | 164 | // for a one-microsecond delay, simply return. the overhead 165 | // of the function call yields a delay of approximately 1 1/8 us. 166 | if (--us == 0) 167 | return; 168 | 169 | // the following loop takes a quarter of a microsecond (4 cycles) 170 | // per iteration, so execute it four times for each microsecond of 171 | // delay requested. 172 | us <<= 2; 173 | 174 | // account for the time taken in the preceeding commands. 175 | us -= 2; 176 | #else 177 | // for the 8 MHz internal clock on the ATmega168 178 | 179 | // for a one- or two-microsecond delay, simply return. the overhead of 180 | // the function calls takes more than two microseconds. can't just 181 | // subtract two, since us is unsigned; we'd overflow. 182 | if (--us == 0) 183 | return; 184 | if (--us == 0) 185 | return; 186 | 187 | // the following loop takes half of a microsecond (4 cycles) 188 | // per iteration, so execute it twice for each microsecond of 189 | // delay requested. 190 | us <<= 1; 191 | 192 | // partially compensate for the time taken by the preceeding commands. 193 | // we can't subtract any more than this or we'd overflow w/ small delays. 194 | us--; 195 | #endif 196 | 197 | // busy wait 198 | __asm__ __volatile__ ( 199 | "1: sbiw %0,1" "\n\t" // 2 cycles 200 | "brne 1b" : "=w" (us) : "0" (us) // 2 cycles 201 | ); 202 | } 203 | 204 | static void initToneTimerInternal(void) 205 | { 206 | // Stop the clock while we make changes 207 | ToneTimer_ClockSelect( ToneTimer_(Stopped) ); 208 | 209 | // Set the timer to phase-correct PWM 210 | #if defined( TONETIMER_SUPPORTS_PHASE_CORRECT_PWM ) && TONETIMER_SUPPORTS_PHASE_CORRECT_PWM 211 | ToneTimer_SetWaveformGenerationMode( ToneTimer_(Phase_Correct_PWM_FF) ); 212 | #else 213 | ToneTimer_SetWaveformGenerationMode( ToneTimer_(Fast_PWM_FF) ); 214 | #endif 215 | 216 | // Timer is processor clock divided by ToneTimer_Prescale_Index (64) 217 | ToneTimer_ClockSelect( ToneTimer_Prescale_Index ); 218 | } 219 | 220 | void initToneTimer(void) 221 | { 222 | // Ensure the timer is in the same state as power-up 223 | ToneTimer_SetToPowerup(); 224 | 225 | #if defined( INITIALIZE_SECONDARY_TIMERS ) && INITIALIZE_SECONDARY_TIMERS 226 | // Prepare the timer for PWM 227 | initToneTimerInternal(); 228 | #endif 229 | } 230 | 231 | void init(void) 232 | { 233 | // this needs to be called before setup() or some functions won't work there 234 | sei(); 235 | 236 | // In case the bootloader left our millis timer in a bad way 237 | #if defined( HAVE_BOOTLOADER ) && HAVE_BOOTLOADER 238 | MillisTimer_SetToPowerup(); 239 | #endif 240 | 241 | // Use the Millis Timer for fast PWM 242 | MillisTimer_SetWaveformGenerationMode( MillisTimer_(Fast_PWM_FF) ); 243 | 244 | // Millis timer is always processor clock divided by MillisTimer_Prescale_Value (64) 245 | MillisTimer_ClockSelect( MillisTimer_Prescale_Index ); 246 | 247 | // Enable the overlow interrupt (this is the basic system tic-toc for millis) 248 | MillisTimer_EnableOverflowInterrupt(); 249 | 250 | // Initialize the timer used for Tone 251 | #if defined( INITIALIZE_SECONDARY_TIMERS ) && INITIALIZE_SECONDARY_TIMERS 252 | initToneTimerInternal(); 253 | #endif 254 | 255 | // Initialize the ADC 256 | #if defined( INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER ) && INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER 257 | ADC_PrescalerSelect( ADC_ARDUINO_PRESCALER ); 258 | ADC_Enable(); 259 | #endif 260 | } 261 | 262 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/wiring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.h - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 1073 2010-08-17 21:50:41Z dmellis $ 23 | 24 | Modified 28-08-2009 for attiny84 R.Wiersma 25 | Modified 14-108-2009 for attiny45 Saposoft 26 | */ 27 | 28 | #ifndef Wiring_h 29 | #define Wiring_h 30 | 31 | #include 32 | #include 33 | 34 | #include "binary.h" 35 | #include "core_build_options.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C"{ 39 | #endif 40 | 41 | #define HIGH 0x1 42 | #define LOW 0x0 43 | 44 | #define INPUT 0x0 45 | #define OUTPUT 0x1 46 | 47 | #define true 0x1 48 | #define false 0x0 49 | 50 | #define PI 3.1415926535897932384626433832795 51 | #define HALF_PI 1.5707963267948966192313216916398 52 | #define TWO_PI 6.283185307179586476925286766559 53 | #define DEG_TO_RAD 0.017453292519943295769236907684886 54 | #define RAD_TO_DEG 57.295779513082320876798154814105 55 | 56 | #define SERIAL 0x0 57 | #define DISPLAY 0x1 58 | 59 | #define LSBFIRST 0 60 | #define MSBFIRST 1 61 | 62 | #define CHANGE 1 63 | #define FALLING 2 64 | #define RISING 3 65 | 66 | /* rmv or fix 67 | #if defined(__AVR_ATmega1280__) 68 | #define INTERNAL1V1 2 69 | #define INTERNAL2V56 3 70 | #else 71 | #define INTERNAL 3 72 | #endif 73 | #define DEFAULT 1 74 | #define EXTERNAL 0 75 | */ 76 | 77 | /* rmv 78 | analogReference constants for ATmega168. These are NOT correct for the ATtiny84 nor for the ATtiny85. The correct values are below. 79 | 80 | // Internal 1.1V Voltage Reference with external capacitor at AREF pin 81 | #define INTERNAL 3 82 | 83 | // AVCC with external capacitor at AREF pin 84 | #define DEFAULT 1 85 | 86 | // AREF, Internal Vref turned off 87 | #define EXTERNAL 0 88 | */ 89 | 90 | 91 | #if defined( __AVR_ATtinyX313__ ) 92 | 93 | #define DEFAULT (0) 94 | 95 | #elif defined( __AVR_ATtinyX4__ ) 96 | 97 | // VCC used as analog reference, disconnected from PA0 (AREF) 98 | #define DEFAULT (0) 99 | 100 | // External voltage reference at PA0 (AREF) pin, internal reference turned off 101 | #define EXTERNAL (1) 102 | 103 | // Internal 1.1V voltage reference 104 | #define INTERNAL (2) 105 | 106 | #elif defined( __AVR_ATtinyX5__ ) 107 | 108 | // X 0 0 VCC used as Voltage Reference, disconnected from PB0 (AREF). 109 | #define DEFAULT (0) 110 | 111 | // X 0 1 External Voltage Reference at PB0 (AREF) pin, Internal Voltage Reference turned off. 112 | #define EXTERNAL (1) 113 | 114 | // 0 1 0 Internal 1.1V Voltage Reference. 115 | #define INTERNAL (2) 116 | #define INTERNAL1V1 INTERNAL 117 | 118 | // 1 1 1 Internal 2.56V Voltage Reference with external bypass capacitor at PB0 (AREF) pin(1). 119 | #define INTERNAL2V56 (7) 120 | 121 | // An alternative for INTERNAL2V56 is (6) ... 122 | // 1 1 0 Internal 2.56V Voltage Reference without external bypass capacitor, disconnected from PB0 (AREF)(1). 123 | 124 | #endif 125 | 126 | 127 | // undefine stdlib's abs if encountered 128 | #ifdef abs 129 | #undef abs 130 | #endif 131 | 132 | #define min(a,b) ((a)<(b)?(a):(b)) 133 | #define max(a,b) ((a)>(b)?(a):(b)) 134 | #define abs(x) ((x)>0?(x):-(x)) 135 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 136 | //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 137 | #define radians(deg) ((deg)*DEG_TO_RAD) 138 | #define degrees(rad) ((rad)*RAD_TO_DEG) 139 | #define sq(x) ((x)*(x)) 140 | 141 | #define interrupts() sei() 142 | #define noInterrupts() cli() 143 | 144 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 145 | #define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) ) 146 | #define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L ) 147 | 148 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 149 | #define highByte(w) ((uint8_t) ((w) >> 8)) 150 | 151 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 152 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 153 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 154 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 155 | 156 | typedef unsigned int word; 157 | 158 | #define bit(b) (1UL << (b)) 159 | 160 | typedef uint8_t boolean; 161 | typedef uint8_t byte; 162 | 163 | void initToneTimer(void); 164 | void init(void); 165 | 166 | void pinMode(uint8_t, uint8_t); 167 | void digitalWrite(uint8_t, uint8_t); 168 | int digitalRead(uint8_t); 169 | int analogRead(uint8_t); 170 | void analogReference(uint8_t mode); 171 | void analogWrite(uint8_t, int); 172 | 173 | unsigned long millis(void); 174 | unsigned long micros(void); 175 | void delay(unsigned long); 176 | void delayMicroseconds(unsigned int us); 177 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 178 | 179 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); 180 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); 181 | 182 | void attachInterrupt(uint8_t, void (*)(void), int mode); 183 | void detachInterrupt(uint8_t); 184 | 185 | void setup(void); 186 | void loop(void); 187 | 188 | #ifdef __cplusplus 189 | } // extern "C" 190 | #endif 191 | 192 | #endif 193 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_analog.c - analog input and output 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | 24 | Modified 28-08-2009 for attiny84 R.Wiersma 25 | Modified 14-10-2009 for attiny45 Saposoft 26 | Corrected 17-05-2010 for ATtiny84 B.Cook 27 | */ 28 | 29 | #include "wiring_private.h" 30 | #include "pins_arduino.h" 31 | #include "core_adc.h" 32 | #include "core_pins.h" 33 | #include "core_timers.h" 34 | #include "PwmTimer.h" 35 | 36 | uint8_t analog_reference = DEFAULT; 37 | 38 | void analogReference(uint8_t mode) 39 | { 40 | // can't actually set the register here because the default setting 41 | // will connect AVCC and the AREF pin, which would cause a short if 42 | // there's something connected to AREF. 43 | // fix? Validate the mode? 44 | analog_reference = mode; 45 | } 46 | 47 | int analogRead(uint8_t pin) 48 | { 49 | #if defined( CORE_ANALOG_FIRST ) 50 | if ( pin >= CORE_ANALOG_FIRST ) pin -= CORE_ANALOG_FIRST; // allow for channel or pin numbers 51 | #endif 52 | 53 | // fix? Validate pin? 54 | 55 | ADC_SetVoltageReference( analog_reference ); 56 | ADC_SetInputChannel( pin ); 57 | 58 | ADC_StartConversion(); 59 | 60 | while( ADC_ConversionInProgress() ); 61 | 62 | return( ADC_GetDataRegister() ); 63 | } 64 | 65 | // Right now, PWM output only works on the pins with 66 | // hardware support. These are defined in the appropriate 67 | // pins_*.c file. For the rest of the pins, we default 68 | // to digital output. 69 | void analogWrite(uint8_t pin, int val) 70 | { 71 | // We need to make sure the PWM output is enabled for those pins 72 | // that support it, as we turn it off when digitally reading or 73 | // writing with them. Also, make sure the pin is in output mode 74 | // for consistenty with Wiring, which doesn't require a pinMode 75 | // call for the analog output pins. 76 | pinMode(pin, OUTPUT); 77 | 78 | if (val <= 0) 79 | { 80 | digitalWrite(pin, LOW); 81 | } 82 | else if (val >= 255) 83 | { 84 | digitalWrite(pin, HIGH); 85 | } 86 | else 87 | { 88 | #if CORE_PWM_COUNT >= 1 89 | if ( pin == CORE_PWM0_PIN ) 90 | { 91 | Pwm0_SetCompareOutputMode( Pwm0_Clear ); 92 | Pwm0_SetOutputCompareMatch( val ); 93 | } 94 | else 95 | #endif 96 | 97 | #if CORE_PWM_COUNT >= 2 98 | if ( pin == CORE_PWM1_PIN ) 99 | { 100 | Pwm1_SetCompareOutputMode( Pwm1_Clear ); 101 | Pwm1_SetOutputCompareMatch( val ); 102 | } 103 | else 104 | #endif 105 | 106 | #if CORE_PWM_COUNT >= 3 107 | if ( pin == CORE_PWM2_PIN ) 108 | { 109 | Pwm2_SetCompareOutputMode( Pwm2_Clear ); 110 | Pwm2_SetOutputCompareMatch( val ); 111 | } 112 | else 113 | #endif 114 | 115 | #if CORE_PWM_COUNT >= 4 116 | if ( pin == CORE_PWM3_PIN ) 117 | { 118 | Pwm3_SetCompareOutputMode( Pwm3_Clear ); 119 | Pwm3_SetOutputCompareMatch( val ); 120 | } 121 | else 122 | #endif 123 | 124 | #if CORE_PWM_COUNT >= 5 125 | #error Only 4 PWM pins are supported. Add more conditions. 126 | #endif 127 | 128 | { 129 | if (val < 128) 130 | { 131 | digitalWrite(pin, LOW); 132 | } 133 | else 134 | { 135 | digitalWrite(pin, HIGH); 136 | } 137 | } 138 | 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | 24 | Modified 28-08-2009 for attiny84 R.Wiersma 25 | Modified 14-10-2009 for attiny45 Saposoft 26 | */ 27 | 28 | #include "wiring_private.h" 29 | #include "pins_arduino.h" 30 | #include "core_pins.h" 31 | #include "core_timers.h" 32 | #include "PwmTimer.h" 33 | 34 | void pinMode(uint8_t pin, uint8_t mode) 35 | { 36 | uint8_t bit = digitalPinToBitMask(pin); 37 | uint8_t port = digitalPinToPort(pin); 38 | volatile uint8_t *reg; 39 | 40 | if (port == NOT_A_PIN) return; 41 | 42 | // JWS: can I let the optimizer do this? 43 | reg = portModeRegister(port); 44 | 45 | if (mode == INPUT) { 46 | uint8_t oldSREG = SREG; 47 | cli(); 48 | *reg &= ~bit; 49 | SREG = oldSREG; 50 | } else { 51 | uint8_t oldSREG = SREG; 52 | cli(); 53 | *reg |= bit; 54 | SREG = oldSREG; 55 | } 56 | } 57 | 58 | // Forcing this inline keeps the callers from having to push their own stuff 59 | // on the stack. It is a good performance win and only takes 1 more byte per 60 | // user than calling. (It will take more bytes on the 168.) 61 | // 62 | // But shouldn't this be moved into pinMode? Seems silly to check and do on 63 | // each digitalread or write. 64 | // 65 | __attribute__((always_inline)) static inline void turnOffPWM( uint8_t pin ) 66 | { 67 | #if CORE_PWM_COUNT >= 1 68 | if ( pin == CORE_PWM0_PIN ) 69 | { 70 | Pwm0_SetCompareOutputMode( Pwm0_Disconnected ); 71 | } 72 | else 73 | #endif 74 | 75 | #if CORE_PWM_COUNT >= 2 76 | if ( pin == CORE_PWM1_PIN ) 77 | { 78 | Pwm1_SetCompareOutputMode( Pwm1_Disconnected ); 79 | } 80 | else 81 | #endif 82 | 83 | #if CORE_PWM_COUNT >= 3 84 | if ( pin == CORE_PWM2_PIN ) 85 | { 86 | Pwm2_SetCompareOutputMode( Pwm2_Disconnected ); 87 | } 88 | else 89 | #endif 90 | 91 | #if CORE_PWM_COUNT >= 4 92 | if ( pin == CORE_PWM3_PIN ) 93 | { 94 | Pwm3_SetCompareOutputMode( Pwm3_Disconnected ); 95 | } 96 | else 97 | #endif 98 | 99 | #if CORE_PWM_COUNT >= 5 100 | #error Only 4 PWM pins are supported. Add more conditions. 101 | #endif 102 | 103 | { 104 | } 105 | 106 | } 107 | 108 | void digitalWrite(uint8_t pin, uint8_t val) 109 | { 110 | uint8_t bit = digitalPinToBitMask(pin); 111 | uint8_t port = digitalPinToPort(pin); 112 | volatile uint8_t *out; 113 | 114 | if (port == NOT_A_PIN) return; 115 | 116 | // If the pin that support PWM output, we need to turn it off 117 | // before doing a digital write. 118 | turnOffPWM( pin ); 119 | 120 | out = portOutputRegister(port); 121 | 122 | if (val == LOW) { 123 | uint8_t oldSREG = SREG; 124 | cli(); 125 | *out &= ~bit; 126 | SREG = oldSREG; 127 | } else { 128 | uint8_t oldSREG = SREG; 129 | cli(); 130 | *out |= bit; 131 | SREG = oldSREG; 132 | } 133 | } 134 | 135 | int digitalRead(uint8_t pin) 136 | { 137 | uint8_t bit = digitalPinToBitMask(pin); 138 | uint8_t port = digitalPinToPort(pin); 139 | 140 | if (port == NOT_A_PIN) return LOW; 141 | 142 | // If the pin that support PWM output, we need to turn it off 143 | // before getting a digital reading. 144 | turnOffPWM( pin ); 145 | 146 | if (*portInputRegister(port) & bit) return HIGH; 147 | return LOW; 148 | } 149 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/wiring_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_private.h - Internal header file. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $ 23 | 24 | Modified 28-08-2009 for attiny84 R.Wiersma 25 | */ 26 | 27 | #ifndef WiringPrivate_h 28 | #define WiringPrivate_h 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "wiring.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C"{ 40 | #endif 41 | 42 | #ifndef cbi 43 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 44 | #endif 45 | #ifndef sbi 46 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 47 | #endif 48 | 49 | #if defined( EXT_INT0_vect ) 50 | #define EXTERNAL_INTERRUPT_0_vect EXT_INT0_vect 51 | #elif defined( INT0_vect ) 52 | #define EXTERNAL_INTERRUPT_0_vect INT0_vect 53 | #endif 54 | 55 | #if defined( EXT_INT1_vect ) 56 | #define EXTERNAL_INTERRUPT_1_vect EXT_INT1_vect 57 | #elif defined( INT1_vect ) 58 | #define EXTERNAL_INTERRUPT_1_vect INT1_vect 59 | #endif 60 | 61 | #if defined( EXT_INT2_vect ) 62 | #define EXTERNAL_INTERRUPT_2_vect EXT_INT2_vect 63 | #elif defined( INT2_vect ) 64 | #define EXTERNAL_INTERRUPT_2_vect INT2_vect 65 | #endif 66 | 67 | #if defined( EXT_INT3_vect ) 68 | #define EXTERNAL_INTERRUPT_3_vect EXT_INT3_vect 69 | #elif defined( INT3_vect ) 70 | #define EXTERNAL_INTERRUPT_3_vect INT3_vect 71 | #endif 72 | 73 | #if defined( EXT_INT4_vect ) 74 | #define EXTERNAL_INTERRUPT_4_vect EXT_INT4_vect 75 | #elif defined( INT4_vect ) 76 | #define EXTERNAL_INTERRUPT_4_vect INT4_vect 77 | #endif 78 | 79 | #if defined( EXT_INT5_vect ) 80 | #define EXTERNAL_INTERRUPT_5_vect EXT_INT5_vect 81 | #elif defined( INT5_vect ) 82 | #define EXTERNAL_INTERRUPT_5_vect INT5_vect 83 | #endif 84 | 85 | #if defined( EXT_INT6_vect ) 86 | #define EXTERNAL_INTERRUPT_6_vect EXT_INT6_vect 87 | #elif defined( INT6_vect ) 88 | #define EXTERNAL_INTERRUPT_6_vect INT6_vect 89 | #endif 90 | 91 | #if defined( EXT_INT7_vect ) 92 | #define EXTERNAL_INTERRUPT_7_vect EXT_INT7_vect 93 | #elif defined( INT7_vect ) 94 | #define EXTERNAL_INTERRUPT_7_vect INT7_vect 95 | #endif 96 | 97 | #if defined( EXT_INT8_vect ) 98 | #define EXTERNAL_INTERRUPT_8_vect EXT_INT8_vect 99 | #elif defined( INT8_vect ) 100 | #define EXTERNAL_INTERRUPT_8_vect INT8_vect 101 | #endif 102 | 103 | #if defined( EXT_INT9_vect ) 104 | #define EXTERNAL_INTERRUPT_9_vect EXT_INT9_vect 105 | #elif defined( INT9_vect ) 106 | #define EXTERNAL_INTERRUPT_9_vect INT9_vect 107 | #endif 108 | 109 | #if defined( EXTERNAL_INTERRUPT_9_vect ) 110 | #define NUMBER_EXTERNAL_INTERRUPTS (10) 111 | #elif defined( EXTERNAL_INTERRUPT_8_vect ) 112 | #define NUMBER_EXTERNAL_INTERRUPTS (9) 113 | #elif defined( EXTERNAL_INTERRUPT_7_vect ) 114 | #define NUMBER_EXTERNAL_INTERRUPTS (8) 115 | #elif defined( EXTERNAL_INTERRUPT_6_vect ) 116 | #define NUMBER_EXTERNAL_INTERRUPTS (7) 117 | #elif defined( EXTERNAL_INTERRUPT_5_vect ) 118 | #define NUMBER_EXTERNAL_INTERRUPTS (6) 119 | #elif defined( EXTERNAL_INTERRUPT_4_vect ) 120 | #define NUMBER_EXTERNAL_INTERRUPTS (5) 121 | #elif defined( EXTERNAL_INTERRUPT_3_vect ) 122 | #define NUMBER_EXTERNAL_INTERRUPTS (4) 123 | #elif defined( EXTERNAL_INTERRUPT_2_vect ) 124 | #define NUMBER_EXTERNAL_INTERRUPTS (3) 125 | #elif defined( EXTERNAL_INTERRUPT_1_vect ) 126 | #define NUMBER_EXTERNAL_INTERRUPTS (2) 127 | #elif defined( EXTERNAL_INTERRUPT_0_vect ) 128 | #define NUMBER_EXTERNAL_INTERRUPTS (1) 129 | #else 130 | #define NUMBER_EXTERNAL_INTERRUPTS (0) 131 | #endif 132 | 133 | #if NUMBER_EXTERNAL_INTERRUPTS >= 1 134 | #define EXTERNAL_INTERRUPT_0 (0) 135 | #endif 136 | 137 | #if NUMBER_EXTERNAL_INTERRUPTS >= 2 138 | #define EXTERNAL_INTERRUPT_1 (1) 139 | #endif 140 | 141 | #if NUMBER_EXTERNAL_INTERRUPTS >= 3 142 | #define EXTERNAL_INTERRUPT_2 (2) 143 | #endif 144 | 145 | #if NUMBER_EXTERNAL_INTERRUPTS >= 4 146 | #define EXTERNAL_INTERRUPT_3 (3) 147 | #endif 148 | 149 | #if NUMBER_EXTERNAL_INTERRUPTS >= 5 150 | #define EXTERNAL_INTERRUPT_4 (4) 151 | #endif 152 | 153 | #if NUMBER_EXTERNAL_INTERRUPTS >= 6 154 | #define EXTERNAL_INTERRUPT_5 (5) 155 | #endif 156 | 157 | #if NUMBER_EXTERNAL_INTERRUPTS >= 7 158 | #define EXTERNAL_INTERRUPT_6 (6) 159 | #endif 160 | 161 | #if NUMBER_EXTERNAL_INTERRUPTS >= 8 162 | #define EXTERNAL_INTERRUPT_7 (7) 163 | #endif 164 | 165 | #if NUMBER_EXTERNAL_INTERRUPTS >= 9 166 | #define EXTERNAL_INTERRUPT_8 (8) 167 | #endif 168 | 169 | #if NUMBER_EXTERNAL_INTERRUPTS >= 10 170 | #define EXTERNAL_INTERRUPT_9 (9) 171 | #endif 172 | 173 | typedef void (*voidFuncPtr)(void); 174 | 175 | #ifdef __cplusplus 176 | } // extern "C" 177 | #endif 178 | 179 | #endif 180 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/wiring_pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_pulse.c - pulseIn() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 29 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 30 | * to 3 minutes in length, but must be called at least a few dozen microseconds 31 | * before the start of the pulse. */ 32 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) 33 | { 34 | // cache the port and bit of the pin in order to speed up the 35 | // pulse width measuring loop and achieve finer resolution. calling 36 | // digitalRead() instead yields much coarser resolution. 37 | uint8_t bit = digitalPinToBitMask(pin); 38 | uint8_t port = digitalPinToPort(pin); 39 | uint8_t stateMask = (state ? bit : 0); 40 | unsigned long width = 0; // keep initialization out of time critical area 41 | 42 | // convert the timeout from microseconds to a number of times through 43 | // the initial loop; it takes 16 clock cycles per iteration. 44 | unsigned long numloops = 0; 45 | unsigned long maxloops = microsecondsToClockCycles(timeout) / 16; 46 | 47 | // wait for any previous pulse to end 48 | while ((*portInputRegister(port) & bit) == stateMask) 49 | if (numloops++ == maxloops) 50 | return 0; 51 | 52 | // wait for the pulse to start 53 | while ((*portInputRegister(port) & bit) != stateMask) 54 | if (numloops++ == maxloops) 55 | return 0; 56 | 57 | // wait for the pulse to stop 58 | while ((*portInputRegister(port) & bit) == stateMask) { 59 | if (numloops++ == maxloops) 60 | return 0; 61 | width++; 62 | } 63 | 64 | // convert the reading to microseconds. The loop has been determined 65 | // to be 20 clock cycles long and have about 16 clocks between the edge 66 | // and the start of the loop. There will be some error introduced by 67 | // the interrupt handlers. 68 | return clockCyclesToMicroseconds(width * 21 + 16); 69 | } 70 | -------------------------------------------------------------------------------- /hardware/tiny/cores/tiny/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 28 | uint8_t value = 0; 29 | uint8_t i; 30 | 31 | for (i = 0; i < 8; ++i) { 32 | digitalWrite(clockPin, HIGH); 33 | if (bitOrder == LSBFIRST) 34 | value |= digitalRead(dataPin) << i; 35 | else 36 | value |= digitalRead(dataPin) << (7 - i); 37 | digitalWrite(clockPin, LOW); 38 | } 39 | return value; 40 | } 41 | 42 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) 43 | { 44 | uint8_t i; 45 | 46 | for (i = 0; i < 8; i++) { 47 | if (bitOrder == LSBFIRST) 48 | digitalWrite(dataPin, !!(val & (1 << i))); 49 | else 50 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 51 | 52 | digitalWrite(clockPin, HIGH); 53 | digitalWrite(clockPin, LOW); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /libraries/PinChangeInterrupt/PinChangeInterrupt.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | PinChangeInterrupt.h - Enhanced pin change interrupts for tiny processors. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #ifndef PinChangeInterrupt_h 25 | #define PinChangeInterrupt_h 26 | 27 | #include 28 | 29 | #include 30 | // rmv #include "wiring_private.h" 31 | 32 | 33 | #if defined( __AVR_ATtiny2313__ ) 34 | #define NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS (1) 35 | #define NUMBER_PIN_CHANGE_INTERRUPT_PORTS 1 36 | #endif 37 | 38 | #if defined( __AVR_ATtinyX4__ ) 39 | #define NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS (3) 40 | #define NUMBER_PIN_CHANGE_INTERRUPT_PORTS 2 41 | #endif 42 | 43 | #if defined( __AVR_ATtinyX5__ ) 44 | #define NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS (3) 45 | #define NUMBER_PIN_CHANGE_INTERRUPT_PORTS 1 46 | #endif 47 | 48 | void attachPcInterrupt( uint8_t pin, void (*callback)(void), uint8_t mode ); 49 | void detachPcInterrupt( uint8_t pin ); 50 | void detachPcInterrupt( uint8_t pin, void (*callback)(void), uint8_t mode ); 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libraries/PinChangeInterrupt/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For PinChangeInterrupt 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | attachPcInterrupt KEYWORD2 14 | detachPcInterrupt KEYWORD2 15 | 16 | ####################################### 17 | # Constants (LITERAL1) 18 | ####################################### 19 | 20 | -------------------------------------------------------------------------------- /libraries/PinChangeInterrupt/readme.txt: -------------------------------------------------------------------------------- 1 | =========================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of Arduino-Tiny. 6 | 7 | Arduino-Tiny is free software: you can redistribute it and/or modify it 8 | under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | Arduino-Tiny is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with Arduino-Tiny. If not, see . 19 | 20 | =========================================================================== 21 | 22 | Tiny Pin Change Interrupts 23 | 24 | Tiny Pin Change Interrupts is a library for hooking the pin-change 25 | interrupts on AVR processors. 26 | 27 | =========================================================================== 28 | 29 | 30 | Availability 31 | =========================================================================== 32 | 33 | A ZIP package is available here... 34 | http://code.google.com/p/arduino-tiny/ 35 | 36 | The source code is here... 37 | http://code.google.com/p/arduino-tiny/source/browse/#svn/trunk/libraries/PinChangeInterrupt 38 | 39 | 40 | License 41 | =========================================================================== 42 | 43 | This library is released under the GNU Lesser General Public License. 44 | -------------------------------------------------------------------------------- /libraries/PinChangeInterruptSimple/PinChangeInterruptSimple.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | PinChangeInterruptSimple.cpp - Simple pin change interrupts for tiny 4 | processors. 5 | 6 | Copyright 2010 Rowdy Dog Software. 7 | 8 | This file is part of Arduino-Tiny. 9 | 10 | Arduino-Tiny is free software: you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or (at your 13 | option) any later version. 14 | 15 | Arduino-Tiny is distributed in the hope that it will be useful, but 16 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public License 21 | along with Arduino-Tiny. If not, see . 22 | 23 | ==============================================================================*/ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | 35 | typedef struct 36 | { 37 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 38 | uint8_t port; 39 | #endif 40 | uint8_t changeMask; 41 | void (*callback)(void); 42 | // voidFuncPtr callback; 43 | } 44 | pcint_entry_t; 45 | 46 | typedef volatile pcint_entry_t* pcint_entry_p; 47 | 48 | 49 | volatile static pcint_entry_t pcint[NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS]; 50 | 51 | 52 | static volatile uint8_t previousPinValue0; 53 | 54 | #if defined( PCMSK1 ) 55 | static volatile uint8_t previousPinValue1; 56 | #endif 57 | 58 | 59 | void attachPcInterrupt( uint8_t pin, void (*callback)(void), uint8_t mode ) 60 | { 61 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 62 | uint8_t port; 63 | #endif 64 | uint8_t bitMask; 65 | uint8_t changeMask; 66 | pcint_entry_p hole; 67 | pcint_entry_p entry; 68 | 69 | //changeMask = 0; 70 | 71 | bitMask = digitalPinToBitMask( pin ); 72 | 73 | changeMask = bitMask; 74 | 75 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 76 | port = digitalPinToPort( pin ); 77 | #endif 78 | 79 | tryAgain: 80 | 81 | hole = 0; 82 | 83 | entry = pcint; 84 | for ( uint8_t i=0; i < NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS; ++i ) 85 | { 86 | uint8_t SaveSREG = SREG; 87 | cli(); 88 | 89 | if ( (hole == 0) && (entry->callback == 0) ) 90 | { 91 | hole = entry; 92 | } 93 | else 94 | { 95 | if ( 96 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 97 | (port == entry->port) && 98 | #endif 99 | (changeMask == entry->changeMask) 100 | && (callback == entry->callback) ) 101 | { 102 | SREG = SaveSREG; 103 | return; 104 | } 105 | } 106 | 107 | SREG = SaveSREG; 108 | 109 | ++entry; 110 | } 111 | 112 | if ( hole == 0 ) 113 | return; 114 | 115 | uint8_t SaveSREG = SREG; 116 | cli(); 117 | 118 | if ( hole->callback == 0 ) 119 | { 120 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 121 | hole->port = port; 122 | #endif 123 | hole->changeMask = changeMask; 124 | hole->callback = callback; 125 | 126 | #if defined( __AVR_ATtinyX4__ ) 127 | 128 | if ( port == PORT_A_ID ) 129 | { 130 | GIMSK |= MASK1( PCIE0 ); 131 | 132 | if ( (PCMSK0 & bitMask) == 0 ) 133 | { 134 | previousPinValue0 |= (PINA & bitMask); 135 | PCMSK0 |= bitMask; 136 | } 137 | } 138 | else // if ( port = PORT_ID_B ) 139 | { 140 | GIMSK |= MASK1( PCIE1 ); 141 | 142 | if ( (PCMSK1 & bitMask) == 0 ) 143 | { 144 | previousPinValue1 |= (PINB & bitMask); 145 | PCMSK1 |= bitMask; 146 | } 147 | } 148 | 149 | #endif 150 | 151 | 152 | #if defined( __AVR_ATtinyX5__ ) || defined( __AVR_ATtiny2313__ ) 153 | 154 | GIMSK |= MASK1( PCIE ); 155 | 156 | if ( (PCMSK & bitMask) == 0 ) 157 | { 158 | previousPinValue0 |= (PINB & bitMask); 159 | PCMSK |= bitMask; 160 | } 161 | 162 | #endif 163 | } 164 | else 165 | { 166 | SREG = SaveSREG; 167 | goto tryAgain; 168 | } 169 | 170 | SREG = SaveSREG; 171 | } 172 | 173 | 174 | static void ClearEntry( pcint_entry_p entry ) 175 | { 176 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 177 | entry->port = 0; 178 | #endif 179 | entry->changeMask = 0; 180 | entry->callback = 0; 181 | } 182 | 183 | static void InterruptOff( 184 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 185 | uint8_t port, 186 | #endif 187 | uint8_t bitMask ) 188 | { 189 | #if defined( __AVR_ATtinyX4__ ) 190 | 191 | if ( port == PORT_A_ID ) 192 | { 193 | previousPinValue0 &= bitMask; 194 | PCMSK0 &= bitMask; 195 | 196 | if ( PCMSK0 == 0 ) 197 | { 198 | GIMSK &= ~ MASK1( PCIE0 ); 199 | } 200 | } 201 | else // if ( port = PORT_ID_B ) 202 | { 203 | previousPinValue1 &= bitMask; 204 | PCMSK1 &= bitMask; 205 | 206 | if ( PCMSK1 == 0 ) 207 | { 208 | GIMSK &= ~ MASK1( PCIE1 ); 209 | } 210 | } 211 | 212 | #endif 213 | 214 | 215 | #if defined( __AVR_ATtinyX5__ ) || defined( __AVR_ATtiny2313__ ) 216 | 217 | previousPinValue0 &= bitMask; 218 | PCMSK &= bitMask; 219 | 220 | if ( PCMSK == 0 ) 221 | { 222 | GIMSK &= ~ MASK1( PCIE ); 223 | } 224 | 225 | #endif 226 | } 227 | 228 | void detachPcInterrupt( uint8_t pin ) 229 | { 230 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 231 | uint8_t port; 232 | #endif 233 | uint8_t bitMask; 234 | pcint_entry_p entry; 235 | 236 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 237 | port = digitalPinToPort( pin ); 238 | #endif 239 | bitMask = digitalPinToBitMask( pin ); 240 | 241 | InterruptOff( 242 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 243 | port, 244 | #endif 245 | ~ bitMask ); 246 | 247 | entry = pcint; 248 | for ( uint8_t i=0; i < NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS; ++i ) 249 | { 250 | uint8_t SaveSREG = SREG; 251 | cli(); 252 | 253 | if ( 254 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 255 | (entry->port == port) && 256 | #endif 257 | ( (entry->changeMask == bitMask) ) ) 258 | { 259 | ClearEntry( entry ); 260 | } 261 | 262 | SREG = SaveSREG; 263 | 264 | ++entry; 265 | } 266 | } 267 | 268 | 269 | void detachPcInterrupt( uint8_t pin, void (*callback)(void), uint8_t mode ) 270 | { 271 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 272 | uint8_t port; 273 | #endif 274 | uint8_t bitMask; 275 | uint8_t changeMask; 276 | uint8_t otherMask; 277 | pcint_entry_p entry; 278 | 279 | changeMask = 0; 280 | 281 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 282 | port = digitalPinToPort( pin ); 283 | #endif 284 | bitMask = digitalPinToBitMask( pin ); 285 | 286 | changeMask = bitMask; 287 | 288 | otherMask = 0; 289 | 290 | entry = pcint; 291 | for ( uint8_t i=0; i < NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS; ++i ) 292 | { 293 | uint8_t SaveSREG = SREG; 294 | cli(); 295 | 296 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 297 | if ( (entry->port == port) ) 298 | #endif 299 | { 300 | if ( (callback == entry->callback) 301 | && (changeMask == entry->changeMask) ) 302 | { 303 | ClearEntry( entry ); 304 | } 305 | else 306 | { 307 | otherMask |= entry->changeMask; 308 | } 309 | } 310 | 311 | SREG = SaveSREG; 312 | 313 | ++entry; 314 | } 315 | 316 | if ( (otherMask & bitMask) == 0 ) 317 | { 318 | InterruptOff( 319 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 320 | port, 321 | #endif 322 | ~ bitMask ); 323 | } 324 | } 325 | 326 | 327 | static void PCINTX_common( 328 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 329 | uint8_t port, 330 | #endif 331 | uint8_t currentPinValue, volatile uint8_t& previousPinValue ) 332 | { 333 | pcint_entry_p entry; 334 | uint8_t changeMask; 335 | 336 | changeMask = previousPinValue ^ currentPinValue; 337 | previousPinValue = currentPinValue; 338 | 339 | 340 | entry = pcint; 341 | for ( uint8_t i=0; i < NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS; ++i ) 342 | { 343 | if ( 344 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 345 | (entry->port == port) && 346 | #endif 347 | (entry->callback != 0) 348 | && ( (entry->changeMask & changeMask) ) ) 349 | { 350 | (entry->callback)(); 351 | } 352 | ++entry; 353 | } 354 | } 355 | 356 | #if defined( PCINT1_vect ) 357 | ISR( PCINT1_vect ) 358 | { 359 | #if defined( __AVR_ATtinyX4__ ) 360 | PCINTX_common( 361 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 362 | PORT_B_ID, 363 | #endif 364 | PINB & PCMSK1, previousPinValue1 ); 365 | #endif 366 | } 367 | #endif 368 | 369 | ISR( PCINT0_vect ) 370 | { 371 | #if defined( __AVR_ATtinyX4__ ) 372 | PCINTX_common( 373 | #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 374 | PORT_A_ID, 375 | #endif 376 | PINA & PCMSK0, previousPinValue0 ); 377 | #endif 378 | 379 | #if defined( __AVR_ATtinyX5__ ) || defined( __AVR_ATtiny2313__ ) 380 | PCINTX_common( PINB & PCMSK, previousPinValue0 ); 381 | #endif 382 | } 383 | 384 | 385 | 386 | /* 387 | GIMSK |= MASK2( PCIE1, PCIE0 ); 388 | 389 | volatile uint8_t* pcMaskRegister; 390 | pcMaskRegister = portPcMaskRegister( port ); 391 | 392 | if ( (*pcMaskRegister & bitMask) == 0 ) 393 | { 394 | volatile uint8_t* inputRegister; 395 | inputRegister = portInputRegister( port ); 396 | 397 | portInputRegister( port ); 398 | previousPin[port-1] |= (*inputRegister & bitMask); 399 | *pcMaskRegister |= bitMask; 400 | } 401 | */ 402 | 403 | /* 404 | '2313... 405 | 406 | PCMSK PCINT[7:0] PINB (bits line up) 407 | 408 | GIMSK 409 | PCIE PCINT[7:0] 410 | 411 | PCINT 412 | 413 | 414 | '84... 415 | 416 | PCMSK1 PCINT[11:8] PINB (bits line up) 417 | 418 | PCMSK0 PCINT[7:0] PINA (bits line up) 419 | 420 | GIMSK 421 | PCIE1 PCINT[11:8] 422 | PCIE0 PCINT[7:0] 423 | 424 | PCINT1 425 | PCINT0 426 | 427 | 428 | '85... 429 | 430 | PCMSK PCINT[5:0] PINB (bits line up) 431 | 432 | GIMSK 433 | PCIE PCINT[5:0] 434 | 435 | PCINT0 436 | 437 | 438 | '328... 439 | 440 | PCMSK2 PCINT[23:16] PIND (bits line up) 441 | 442 | PCMSK1 PCINT[14:8] PINC (bits line up) 443 | 444 | PCMSK0 PCINT[7:0] PINB (bits line up) 445 | 446 | PCICR 447 | PCIE2 PCINT[23:16] 448 | PCIE1 PCINT[14:8] 449 | PCIE0 PCINT[7:0] 450 | 451 | PCINT2 452 | PCINT1 453 | PCINT0 454 | */ 455 | -------------------------------------------------------------------------------- /libraries/PinChangeInterruptSimple/PinChangeInterruptSimple.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | PinChangeInterruptSimple.h - Simple pin change interrupts for tiny processors. 4 | 5 | Copyright 2010 Rowdy Dog Software. 6 | 7 | This file is part of Arduino-Tiny. 8 | 9 | Arduino-Tiny is free software: you can redistribute it and/or modify it 10 | under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or (at your 12 | option) any later version. 13 | 14 | Arduino-Tiny is distributed in the hope that it will be useful, but 15 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 | License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with Arduino-Tiny. If not, see . 21 | 22 | ==============================================================================*/ 23 | 24 | #ifndef PinChangeInterruptSimple_h 25 | #define PinChangeInterruptSimple_h 26 | 27 | #include 28 | 29 | #include 30 | // rmv #include "wiring_private.h" 31 | 32 | 33 | #if defined( __AVR_ATtiny2313__ ) 34 | #define NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS (1) 35 | #define NUMBER_PIN_CHANGE_INTERRUPT_PORTS 1 36 | #endif 37 | 38 | #if defined( __AVR_ATtinyX4__ ) 39 | #define NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS (3) 40 | #define NUMBER_PIN_CHANGE_INTERRUPT_PORTS 2 41 | #endif 42 | 43 | #if defined( __AVR_ATtinyX5__ ) 44 | #define NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS (3) 45 | #define NUMBER_PIN_CHANGE_INTERRUPT_PORTS 1 46 | #endif 47 | 48 | void attachPcInterrupt( uint8_t pin, void (*callback)(void), uint8_t mode ); 49 | void detachPcInterrupt( uint8_t pin ); 50 | void detachPcInterrupt( uint8_t pin, void (*callback)(void), uint8_t mode ); 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libraries/PinChangeInterruptSimple/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For PinChangeInterrupt 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | attachPcInterrupt KEYWORD2 14 | detachPcInterrupt KEYWORD2 15 | 16 | ####################################### 17 | # Constants (LITERAL1) 18 | ####################################### 19 | 20 | -------------------------------------------------------------------------------- /libraries/PinChangeInterruptSimple/readme.txt: -------------------------------------------------------------------------------- 1 | =========================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of Arduino-Tiny. 6 | 7 | Arduino-Tiny is free software: you can redistribute it and/or modify it 8 | under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | Arduino-Tiny is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with Arduino-Tiny. If not, see . 19 | 20 | =========================================================================== 21 | 22 | Tiny Pin Change Interrupts 23 | 24 | Tiny Pin Change Interrupts is a library for hooking the pin-change 25 | interrupts on AVR processors. 26 | 27 | =========================================================================== 28 | 29 | 30 | Availability 31 | =========================================================================== 32 | 33 | A ZIP package is available here... 34 | http://code.google.com/p/arduino-tiny/ 35 | 36 | The source code is here... 37 | http://code.google.com/p/arduino-tiny/source/browse/#svn/trunk/libraries/PinChangeInterrupt 38 | 39 | 40 | License 41 | =========================================================================== 42 | 43 | This library is released under the GNU Lesser General Public License. 44 | -------------------------------------------------------------------------------- /libraries/TinyTuner/TinyTuner.cpp: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of TinyTuner. 6 | 7 | TinyTuner is free software: you can redistribute it and/or modify it under 8 | the terms of the GNU Lesser General Public License as published by the Free 9 | Software Foundation, either version 3 of the License, or (at your option) 10 | any later version. 11 | 12 | TinyTuner is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with TinyTuner. If not, see . 19 | 20 | Inspired by the work of oPossum (Kevin Timmerman)... 21 | http://forums.adafruit.com/viewtopic.php?t=5078 22 | 23 | ==============================================================================*/ 24 | 25 | #include "TinyTuner.h" 26 | 27 | -------------------------------------------------------------------------------- /libraries/TinyTuner/examples/Interactive_to_Serial/Interactive_to_Serial.pde: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of TinyTuner. 6 | 7 | TinyTuner is free software: you can redistribute it and/or modify it under 8 | the terms of the GNU Lesser General Public License as published by the Free 9 | Software Foundation, either version 3 of the License, or (at your option) 10 | any later version. 11 | 12 | TinyTuner is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with TinyTuner. If not, see . 19 | 20 | Inspired by the work of oPossum (Kevin Timmerman)... 21 | http://forums.adafruit.com/viewtopic.php?t=5078 22 | 23 | ==============================================================================*/ 24 | 25 | /*============================================================================== 26 | 27 | The purpose of this example is to determine the optimal calibration register 28 | value based on input from a serial port and print the value to the serial 29 | port. 30 | 31 | ================================================================================ 32 | 33 | ATtiny84 Instructions... 34 | 35 | - Select the correct board / serial port 36 | 37 | - Upload this Sketch to the processor 38 | 39 | - Connect PB0 / Pin 0 to receive on the serial converter 40 | 41 | - Connect PB1 / Pin 1 to transmit on the serial converter 42 | 43 | - Start your favorite terminal program, open the correct serial port, change 44 | the baud rate to 9600 45 | 46 | - Reset the processor. A welcome message should be displayed. 47 | 48 | - Continue sending single 'x' characters (no carriage-return; no line-feed) 49 | until the calibration finishes 50 | 51 | ================================================================================ 52 | 53 | ATtiny85 / ATtiny45 Instructions... 54 | 55 | - Select the correct board / serial port 56 | 57 | - Upload this Sketch to the processor 58 | 59 | - Connect PB3 / Pin 3 to receive on the serial converter 60 | 61 | - Connect PB4 / Pin 4 to transmit on the serial converter 62 | 63 | - Start your favorite terminal program, open the correct serial port, change 64 | the baud rate to 9600 65 | 66 | - Reset the processor. A welcome message should be displayed. 67 | 68 | - Continue sending single 'x' characters (no carriage-return; no line-feed) 69 | until the calibration finishes 70 | 71 | ==============================================================================*/ 72 | 73 | #include 74 | #include 75 | 76 | const char Hello[] PROGMEM = 77 | "\r\n\r\n\r\n\r\n" 78 | "--------------------------------------------------------------------------------\r\n" 79 | "Poor Man's Tiny Tuner\r\n" 80 | "Slowly send lowercase 'x' to tune the oscillator...\r\n\r\n"; 81 | 82 | const char StartingValue1[] PROGMEM = 83 | " // Starting OSCCAL value is 0x"; 84 | 85 | const char StartingValue2[] PROGMEM = 86 | "\r\n\r\n"; 87 | 88 | const char Header[] PROGMEM = 89 | "Step OSCCAL\r\n"; 90 | 91 | const char Bye1[] PROGMEM = 92 | "\r\n" 93 | "Copy-and-paste the following line of code at the top of setup...\r\n\r\n" 94 | " OSCCAL = 0x"; 95 | 96 | const char Bye2[] PROGMEM = 97 | ";\r\n\r\n" 98 | "--------------------------------------------------------------------------------\r\n"; 99 | 100 | const char Pad5[] PROGMEM = " "; 101 | 102 | void setup( void ) 103 | { 104 | Serial.begin( 9600 ); 105 | Serial_printP( Hello ); 106 | Serial_printP( StartingValue1 ); 107 | Serial.print( OSCCAL, HEX ); 108 | Serial_printP( StartingValue2 ); 109 | } 110 | 111 | void loop( void ) 112 | { 113 | TinyTuner tt; 114 | bool KeepGoing; 115 | unsigned Step; 116 | 117 | Serial_printP( Header ); 118 | 119 | KeepGoing = true; 120 | Step = 0; 121 | 122 | while ( KeepGoing ) 123 | { 124 | ++Step; 125 | Serial.write( ' ' ); 126 | 127 | if ( Step < 10 ) 128 | { 129 | Serial.write( ' ' ); 130 | } 131 | Serial.print( Step ); 132 | Serial_printP( Pad5 ); 133 | 134 | KeepGoing = tt.update(); 135 | 136 | Serial.print( OSCCAL, HEX ); 137 | Serial.println(); 138 | } 139 | Serial_printP( Bye1 ); 140 | Serial.print( OSCCAL, HEX ); 141 | Serial_printP( Bye2 ); 142 | } 143 | 144 | void Serial_printP( const char* p ) 145 | { 146 | char ch; 147 | 148 | ch = pgm_read_byte( p ); 149 | 150 | while ( ch != 0 ) 151 | { 152 | Serial.write( ch ); 153 | ++p; 154 | ch = pgm_read_byte( p ); 155 | } 156 | } 157 | 158 | -------------------------------------------------------------------------------- /libraries/TinyTuner/examples/Interactive_to_Serial_with_Details/Interactive_to_Serial_with_Details.pde: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of TinyTuner. 6 | 7 | TinyTuner is free software: you can redistribute it and/or modify it under 8 | the terms of the GNU Lesser General Public License as published by the Free 9 | Software Foundation, either version 3 of the License, or (at your option) 10 | any later version. 11 | 12 | TinyTuner is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with TinyTuner. If not, see . 19 | 20 | Inspired by the work of oPossum (Kevin Timmerman)... 21 | http://forums.adafruit.com/viewtopic.php?t=5078 22 | 23 | ==============================================================================*/ 24 | 25 | /*============================================================================== 26 | 27 | The purpose of this example is to determine the optimal calibration register 28 | value based on input from a serial port and print the value to the serial 29 | port. 30 | 31 | ================================================================================ 32 | 33 | ATtiny84 Instructions... 34 | 35 | - Select the correct board / serial port 36 | 37 | - Upload this Sketch to the processor 38 | 39 | - Connect PB0 / Pin 0 to receive on the serial converter 40 | 41 | - Connect PB1 / Pin 1 to transmit on the serial converter 42 | 43 | - Start your favorite terminal program, open the correct serial port, change 44 | the baud rate to 9600 45 | 46 | - Reset the processor. A welcome message should be displayed. 47 | 48 | - Continue sending single 'x' characters (no carriage-return; no line-feed) 49 | until the calibration finishes 50 | 51 | ================================================================================ 52 | 53 | ATtiny85 Instructions... 54 | 55 | - Note: This Sketch is too large to fit on the ATtiny45 processor. Use the 56 | Interactive_to_Serial example instead. 57 | 58 | - Select the correct board / serial port 59 | 60 | - Upload this Sketch to the processor 61 | 62 | - Connect PB3 / Pin 3 to receive on the serial converter 63 | 64 | - Connect PB4 / Pin 4 to transmit on the serial converter 65 | 66 | - Start your favorite terminal program, open the correct serial port, change 67 | the baud rate to 9600 68 | 69 | - Reset the processor. A welcome message should be displayed. 70 | 71 | - Continue sending single 'x' characters (no carriage-return; no line-feed) 72 | until the calibration finishes 73 | 74 | ==============================================================================*/ 75 | 76 | #include 77 | #include 78 | 79 | const char Hello[] PROGMEM = 80 | "\r\n\r\n\r\n\r\n" 81 | "--------------------------------------------------------------------------------\r\n" 82 | "Poor Man's Tiny Tuner\r\n" 83 | "Slowly send lowercase 'x' to tune the oscillator...\r\n\r\n"; 84 | 85 | const char Header[] PROGMEM = 86 | " Left This Right\r\n" 87 | " ------------------------------- ------------------------------- -------------------------------\r\n" 88 | "Step OSCCAL State Position Cal 9bt Err # C9bt CClk Cal 9bt Err # C9bt CClk Cal 9bt Err # C9bt CClk\r\n" 89 | "---- ------ --------- -------- --- ---- --- - ----- ----- --- ---- --- - ----- ----- --- ---- --- - ----- -----\r\n"; 90 | 91 | const char StateFirstPass[] PROGMEM = "FirstPass "; 92 | const char StateBigSteps[] PROGMEM = "BigSteps "; 93 | const char StateConfirm[] PROGMEM = "Confirm "; 94 | const char StateFinished[] PROGMEM = "Finished "; 95 | 96 | const char PositionLeft[] PROGMEM = "Left "; 97 | const char PositionThis[] PROGMEM = "This "; 98 | const char PositionRight[] PROGMEM = "Right"; 99 | const char PositionMax[] PROGMEM = "Max "; 100 | 101 | /* 102 | Left This Right 103 | ------------------------------- ------------------------------- ------------------------------- 104 | Step OSCCAL State Position Cal 9bt Err # C9bt CClk Cal 9bt Err # C9bt CClk Cal 9bt Err # C9bt CClk 105 | ---- ------ --------- -------- --- ---- --- - ----- ----- --- ---- --- - ----- ----- --- ---- --- - ----- ----- 106 | 1 9B BigSteps This -1 0 0 0 0 0 27 0 0 0 0 0 33 1550 250 0 0 0 107 | 2 9A BigSteps This -1 0 0 0 0 0 26 0 0 0 0 0 27 1508 40 0 0 0 108 | 3 9A Confirm This 25 1498 10 0 0 0 26 1498 10 1 1498 0 27 1508 40 1 1508 0 109 | 4 9A Confirm This 25 1498 10 0 0 0 26 1497 10 2 2995 0 27 1508 40 1 1508 0 110 | 5 9A Confirm This 25 1498 10 0 0 0 26 1500 10 0 0 0 27 1508 40 1 1508 0 111 | 6 9A Confirm This 25 1498 10 0 0 0 26 1500 10 1 1500 0 27 1508 40 1 1508 0 112 | 7 9A Confirm This 25 1498 10 0 0 0 26 1500 10 2 3000 0 27 1508 40 1 1508 0 113 | 8 99 Confirm Left 25 1498 10 0 0 0 26 1499 10 3 4499 0 27 1508 40 1 1508 0 114 | 9 99 Confirm Left 25 1493 10 1 1493 0 26 1499 10 3 4499 0 27 1508 40 1 1508 0 115 | 10 99 Confirm Left 25 1492 10 2 2985 0 26 1499 10 3 4499 0 27 1508 40 1 1508 0 116 | 11 9B Confirm Right 25 1493 10 3 4478 0 26 1499 10 3 4499 0 27 1508 40 1 1508 0 117 | 12 9B Confirm Right 25 1493 10 3 4478 0 26 1499 10 3 4499 0 27 1508 40 2 3016 0 118 | 13 9A Finished This 25 1493 37 3 4478 7463 26 1499 2 3 4499 7498 27 1509 42 3 4525 7542 119 | */ 120 | 121 | const char Bye1[] PROGMEM = 122 | "\r\n" 123 | "Copy-and-paste the following line of code at the top of setup...\r\n\r\n" 124 | " OSCCAL = 0x"; 125 | 126 | const char Bye2[] PROGMEM = 127 | ";\r\n\r\n" 128 | "--------------------------------------------------\r\n"; 129 | 130 | const char Pad2[] PROGMEM = " "; 131 | const char Pad3[] PROGMEM = " "; 132 | const char Pad4[] PROGMEM = " "; 133 | const char Pad5[] PROGMEM = " "; 134 | const char Pad7[] PROGMEM = " "; 135 | 136 | void setup( void ) 137 | { 138 | Serial.begin( 9600 ); 139 | Serial_printP( Hello ); 140 | } 141 | 142 | void loop( void ) 143 | { 144 | TinyTuner tt; 145 | bool KeepGoing; 146 | unsigned Step; 147 | TinyTuner::position_t position; 148 | TinyTuner::debug_t debug; 149 | 150 | /* 151 | Find a resolution to this... 152 | 153 | c:/arduino/arduino-0019/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default': 154 | (.vectors+0x8): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_4' defined in .text.__vector_4 section in core.a(wiring.c.o) 155 | 156 | ...and then it will be possible to... 157 | 158 | tt.fullInit(); 159 | */ 160 | 161 | Serial_printP( Header ); 162 | 163 | KeepGoing = true; 164 | Step = 0; 165 | 166 | while ( KeepGoing ) 167 | { 168 | ++Step; 169 | Serial.write( ' ' ); 170 | 171 | if ( Step < 10 ) 172 | { 173 | Serial.write( ' ' ); 174 | } 175 | Serial.print( Step ); 176 | Serial_printP( Pad5 ); 177 | 178 | KeepGoing = tt.update(); 179 | 180 | tt.getDebug( debug ); 181 | Serial.print( debug.calibration, HEX ); 182 | Serial_printP( Pad4 ); 183 | switch ( debug.state ) 184 | { 185 | case TinyTuner::sFirstPass: 186 | Serial_printP( StateFirstPass ); 187 | break; 188 | case TinyTuner::sBigSteps: 189 | Serial_printP( StateBigSteps ); 190 | break; 191 | case TinyTuner::sConfirm: 192 | Serial_printP( StateConfirm ); 193 | break; 194 | case TinyTuner::sFinished: 195 | Serial_printP( StateFinished ); 196 | break; 197 | } 198 | switch ( debug.position ) 199 | { 200 | case TinyTuner::pLeft: 201 | Serial_printP( PositionLeft ); 202 | break; 203 | case TinyTuner::pThis: 204 | Serial_printP( PositionThis ); 205 | break; 206 | case TinyTuner::pRight: 207 | Serial_printP( PositionRight ); 208 | break; 209 | case TinyTuner::pMax: 210 | Serial_printP( PositionMax ); 211 | break; 212 | } 213 | Serial_printP( Pad3 ); 214 | for ( position=TinyTuner::pLeft; position < TinyTuner::pMax; position=(TinyTuner::position_t)(position+1) ) 215 | { 216 | Serial_printP( Pad4 ); 217 | Serial_printPaddedIntger( debug.info[position].OsccalValue, 3 ); 218 | Serial_printP( Pad2 ); 219 | Serial_printPaddedIntger( debug.info[position].NineBitTime, 4 ); 220 | Serial_printP( Pad2 ); 221 | Serial_printPaddedIntger( debug.info[position].Error, 3 ); 222 | Serial_printP( Pad2 ); 223 | Serial_printPaddedIntger( debug.info[position].ConfirmCount, 1 ); 224 | Serial_printP( Pad2 ); 225 | Serial_printPaddedIntger( debug.info[position].ConfirmNineBitTime, 5 ); 226 | Serial_printP( Pad2 ); 227 | Serial_printPaddedIntger( debug.info[position].ConfirmClocks, 5 ); 228 | } 229 | Serial.println(); 230 | } 231 | Serial_printP( Bye1 ); 232 | Serial.print( OSCCAL, HEX ); 233 | Serial_printP( Bye2 ); 234 | } 235 | 236 | void Serial_printP( const char* p ) 237 | { 238 | char ch; 239 | 240 | ch = pgm_read_byte( p ); 241 | 242 | while ( ch != 0 ) 243 | { 244 | Serial.write( ch ); 245 | ++p; 246 | ch = pgm_read_byte( p ); 247 | } 248 | } 249 | 250 | void Serial_printPaddedIntger( long v, int width ) 251 | { 252 | bool Negative; 253 | long Power10; 254 | int i; 255 | 256 | --width; 257 | 258 | if ( v < 0 ) 259 | { 260 | v = -v; 261 | Negative = true; 262 | --width; 263 | } 264 | else 265 | { 266 | Negative = false; 267 | } 268 | 269 | Power10 = 10L; 270 | for ( i=1; i <= 9; ++i ) 271 | { 272 | if ( v >= Power10 ) 273 | { 274 | --width; 275 | } 276 | else 277 | { 278 | break; 279 | } 280 | Power10 = Power10 * 10; 281 | } 282 | 283 | while ( width > 0 ) 284 | { 285 | Serial.write( ' ' ); 286 | --width; 287 | } 288 | 289 | if ( Negative ) 290 | { 291 | Serial.write( '-' ); 292 | } 293 | 294 | Serial.print( v, DEC ); 295 | } 296 | -------------------------------------------------------------------------------- /libraries/TinyTuner/examples/Interactive_with_NewSoftSerial/Interactive_with_NewSoftSerial.pde: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of TinyTuner. 6 | 7 | TinyTuner is free software: you can redistribute it and/or modify it under 8 | the terms of the GNU Lesser General Public License as published by the Free 9 | Software Foundation, either version 3 of the License, or (at your option) 10 | any later version. 11 | 12 | TinyTuner is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with TinyTuner. If not, see . 19 | 20 | Inspired by the work of oPossum (Kevin Timmerman)... 21 | http://forums.adafruit.com/viewtopic.php?t=5078 22 | 23 | ==============================================================================*/ 24 | #include 25 | #include 26 | 27 | NewSoftSerial nss( 2, 1 ); 28 | 29 | void setup( void ) 30 | { 31 | nss.begin( 9600 ); 32 | 33 | nss.println( "\r\n\r\n\r\n" ); 34 | //nss.println( "--------------------------------------------------" ); 35 | nss.println( "Poor Man's Tiny Tuner\n" ); 36 | nss.println( "Slowly send lowercase 'x' to tune the oscillator..." ); 37 | } 38 | 39 | 40 | void loop( void ) 41 | { 42 | Tiny84Tuner tt; 43 | bool KeepGoing = true; 44 | 45 | while ( KeepGoing ) 46 | { 47 | nss.print( OSCCAL, HEX ); 48 | nss.print( ": " ); 49 | 50 | KeepGoing = tt.update(); 51 | 52 | switch ( tt.getState() ) 53 | { 54 | case Tiny84Tuner::sFirstPass: 55 | nss.print( "FirstPass " ); 56 | break; 57 | case Tiny84Tuner::sBigSteps: 58 | nss.print( "BigSteps " ); 59 | break; 60 | case Tiny84Tuner::sConfirm: 61 | nss.print( "Confirm " ); 62 | break; 63 | case Tiny84Tuner::sFinished: 64 | nss.print( "Finished " ); 65 | break; 66 | } 67 | nss.println(); 68 | } 69 | nss.println(); 70 | //nss.println( "Copy-and-paste the following line of code at the top of setup...\r\n" ); 71 | nss.print( " OSCCAL = 0x" ); 72 | nss.print( OSCCAL, HEX ); 73 | nss.println( ";\r\n" ); 74 | //nss.println( "\r\n--------------------------------------------------" ); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /libraries/TinyTuner/examples/Read_from_EEPROM/Read_from_EEPROM.pde: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of TinyTuner. 6 | 7 | TinyTuner is free software: you can redistribute it and/or modify it under 8 | the terms of the GNU Lesser General Public License as published by the Free 9 | Software Foundation, either version 3 of the License, or (at your option) 10 | any later version. 11 | 12 | TinyTuner is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with TinyTuner. If not, see . 19 | 20 | Inspired by the work of oPossum (Kevin Timmerman)... 21 | http://forums.adafruit.com/viewtopic.php?t=5078 22 | 23 | ==============================================================================*/ 24 | 25 | /*============================================================================== 26 | 27 | The purpose of this example is to print the optimal calibration register 28 | value from a previous run of the Save_to_EEPROM example. 29 | 30 | ================================================================================ 31 | 32 | ATtiny84 Instructions... 33 | 34 | - Select the correct board / serial port 35 | 36 | - Upload this Sketch to the processor 37 | 38 | - Connect PB0 / Pin 0 to receive on the serial converter 39 | 40 | - Start your favorite terminal program, open the correct serial port, change 41 | the baud rate to 9600 42 | 43 | - Reset the processor 44 | 45 | - The value from EEPROM address zero should be displayed 46 | 47 | ================================================================================ 48 | 49 | ATtiny85 / ATtiny45 Instructions... 50 | 51 | - Select the correct board / serial port 52 | 53 | - Upload this Sketch to the processor 54 | 55 | - Connect PB3 / Pin 3 to receive on the serial converter 56 | 57 | - Start your favorite terminal program, open the correct serial port, change 58 | the baud rate to 9600 59 | 60 | - Reset the processor 61 | 62 | - The value from EEPROM address zero should be displayed 63 | 64 | ==============================================================================*/ 65 | 66 | #include 67 | 68 | void setup( void ) 69 | { 70 | Serial.begin( 9600 ); 71 | 72 | Serial.println( "\r\n\r\n\r\n" ); 73 | Serial.println( "Poor Man's Tiny Tuner\n" ); 74 | Serial.println( "Place this line of code at the top of setup...\r\n" ); 75 | Serial.print( " OSCCAL = 0x" ); 76 | Serial.print( EEPROM.read( 0 ), HEX ); 77 | Serial.println( ";\r\n" ); 78 | } 79 | 80 | void loop( void ) 81 | { 82 | } 83 | -------------------------------------------------------------------------------- /libraries/TinyTuner/examples/Save_to_EEPROM/Save_to_EEPROM.pde: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of TinyTuner. 6 | 7 | TinyTuner is free software: you can redistribute it and/or modify it under 8 | the terms of the GNU Lesser General Public License as published by the Free 9 | Software Foundation, either version 3 of the License, or (at your option) 10 | any later version. 11 | 12 | TinyTuner is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with TinyTuner. If not, see . 19 | 20 | Inspired by the work of oPossum (Kevin Timmerman)... 21 | http://forums.adafruit.com/viewtopic.php?t=5078 22 | 23 | ==============================================================================*/ 24 | 25 | /*============================================================================== 26 | 27 | The purpose of this example is to determine the optimal calibration register 28 | value based on input from a serial port and store the value at EEPROM 29 | address zero. 30 | 31 | ================================================================================ 32 | 33 | ATtiny84 Instructions... 34 | 35 | - Select the correct board / serial port 36 | 37 | - Upload this Sketch to the processor 38 | 39 | - Connect PB1 / Pin 1 to transmit on the serial converter 40 | 41 | - Connect an LED + resistor --> ground on PA6 / Pin 4 42 | 43 | - Start your favorite terminal program, open the correct serial port, change 44 | the baud rate to 9600 45 | 46 | - Reset the processor 47 | 48 | - Continue sending single 'x' characters (no carriage-return; no line-feed) 49 | until the LED glows solid. As each 'x' is sent, the LED should blink. 50 | 51 | - The calibration register value is stored at EEPROM address zero 52 | 53 | ================================================================================ 54 | 55 | ATtiny85 / ATtiny45 Instructions... 56 | 57 | - Select the correct board / serial port 58 | 59 | - Upload this Sketch to the processor 60 | 61 | - Connect PB4 / Pin 4 to transmit on the serial converter 62 | 63 | - Connect an LED + resistor --> ground on PB0 / Pin 0 64 | 65 | - Start your favorite terminal program, open the correct serial port, change 66 | the baud rate to 9600 67 | 68 | - Reset the processor 69 | 70 | - Continue sending single 'x' characters (no carriage-return; no line-feed) 71 | until the LED glows solid. As each 'x' is sent, the LED should blink. 72 | 73 | - The calibration register value is stored at EEPROM address zero 74 | 75 | ==============================================================================*/ 76 | 77 | #include 78 | #include 79 | #include "s2eLed.h" 80 | 81 | void setup( void ) 82 | { 83 | pinMode( PinLED, OUTPUT ); 84 | } 85 | 86 | void loop( void ) 87 | { 88 | TinyTuner tt; 89 | bool KeepGoing = true; 90 | 91 | while ( KeepGoing ) 92 | { 93 | KeepGoing = tt.update(); 94 | 95 | for ( uint8_t i=0; i < 2; ++i ) 96 | { 97 | digitalWrite( PinLED, ! digitalRead( PinLED ) ); 98 | delay( 100 ); 99 | } 100 | } 101 | uint8_t Temp = OSCCAL; 102 | EEPROM.write( 0, Temp ); 103 | 104 | if ( EEPROM.read(0) == Temp ) 105 | { 106 | digitalWrite( PinLED, HIGH ); 107 | } 108 | else 109 | { 110 | digitalWrite( PinLED, LOW ); 111 | } 112 | while ( 1 ); 113 | } -------------------------------------------------------------------------------- /libraries/TinyTuner/examples/Save_to_EEPROM/s2eLed.h: -------------------------------------------------------------------------------- 1 | #ifndef s2eLed_h 2 | #define s2eLed_h 3 | 4 | #include 5 | 6 | 7 | #if defined( __AVR_ATtiny2313__ ) 8 | 9 | const uint8_t PinLED = 4; 10 | 11 | #elif defined( __AVR_ATtinyX4__ ) 12 | 13 | const uint8_t PinLED = 4; 14 | 15 | #elif defined( __AVR_ATtinyX5__ ) 16 | 17 | const uint8_t PinLED = 0; 18 | 19 | #endif 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /libraries/TinyTuner/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For TinyTuner 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | TinyTuner KEYWORD1 10 | Tiny84Tuner KEYWORD1 11 | Tiny85Tuner KEYWORD1 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | 17 | update KEYWORD2 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | 23 | -------------------------------------------------------------------------------- /libraries/TinyTuner/readme.txt: -------------------------------------------------------------------------------- 1 | =========================================================================== 2 | 3 | Copyright 2010 Rowdy Dog Software. 4 | 5 | This file is part of TinyTuner. 6 | 7 | TinyTuner is free software: you can redistribute it and/or modify it 8 | under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or (at 10 | your option) any later version. 11 | 12 | TinyTuner is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with TinyTuner. If not, see . 19 | 20 | =========================================================================== 21 | 22 | (Poor Man's) Tiny Tuner 23 | 24 | TinyTuner is a library for tuning the internal oscillator on AVR processors. 25 | 26 | Thank you to Atmel for the motivation and oPossum (Kevin Timmerman) for the inspiration... 27 | http://forums.adafruit.com/viewtopic.php?t=5078 28 | 29 | 30 | Introduction 31 | =========================================================================== 32 | 33 | Some stand-alone projects don't need a highly accurate processor clock and can benefit from a reduced component count. Using the internal oscillator is a perfect fit. The only problem with the internal oscillator is that, from the factory, it can be up to 10% off. For most applications, a 10% error in the clock is a problem. For example, the highest serial baud rate that can be reached when the clock is 4.5% off is 19200. An application that needs a baud rate of 57600 isn't going to work. 34 | 35 | 36 | Techniques 37 | =========================================================================== 38 | 39 | There are a few different methods for tuning the internal oscillator. These are the two I've tried... 40 | http://atmel.com/dyn/resources/prod_documents/doc2555.pdf 41 | http://forums.adafruit.com/viewtopic.php?t=5078 42 | 43 | I had no luck with the AVR053 method. At one point, my ATtiny2313 processor stopped working (meaning the processor would not execute instructions when powered; yikes!). I have no idea what I did wrong or how I got the processor back to life. For someone (like me) who dislikes assembly and has never compiled an assembly source file, this method is, in the best case, very annoying. 44 | 45 | I have not actually tried the oPossum for one reason: assembly. Inspired by the idea to use a serial connection to tune the processor, I decided to create something that was more Arduino friendly. 46 | 47 | 48 | Overview 49 | =========================================================================== 50 | 51 | The idea is simple: Use the AVR processor to measure the time of some serial data. If the serial data is accurately clocked (and generally it is) it is possible to adjust the internal oscillator until the measured time matches the expected time. The core of the technique is TimeNineBits. This function waits until a start bit arrives then counts until a stop bit arrives. If the count is too high, the processor is running too fast. If the count is too low, the processor is running too slow. 52 | 53 | 54 | Using 55 | =========================================================================== 56 | 57 | The Tiny84Tuner class is included for tuning an ATtiny84 processor using pin 0 (PB0). Connect anything to pin 0 that accurately outputs a lowercase 'x' at 9600 baud. Ensure the ATtiny84 processor is using the internal oscillator. Add something like this to a Sketch... 58 | 59 | #include 60 | 61 | void Tune( void ) 62 | { 63 | Tiny84Tuner tt; 64 | bool KeepGoing = true; 65 | 66 | while ( KeepGoing ) 67 | { 68 | KeepGoing = tt.update(); 69 | 70 | // Optionally provide feedback here 71 | } 72 | // At this point, OSCCAL is set to the optimal value 73 | } 74 | 75 | When Tune returns, OSCCAL is set to the optimal value. This value can be saved to EEPROM, output to a terminal using NewSoftSerial, or used as-is. 76 | 77 | 78 | For other processors, it is necessary to create a class instance using the TinyTuner template. The syntax looks like this... 79 | 80 | TinyTuner<0x16,0x00> tt; 81 | 82 | "0x16" is the PIN register and "0x00" is the bit within the register. This pair of values defines the pin where the serial data arrives and can be determined from the processor's datasheet. (I apologize for not supporting Arduino pin numbers nor the GCC #defines.) "tt" is used like in the example above. 83 | 84 | 85 | The ZIP package includes three example Sketches. All three use Tiny84Tuner. Interactive_with_NewSoftSerial is intended to be used interactively. As a human sends each 'x', a status message is sent back. The final result is the OSCCAL register value. 86 | 87 | Save_to_EEPROM blinks an LED as each 'x' is processed. When the optimal value is reached, the value is written to address zero in EEPROM, the LED is lit solid, and the Sketch stops running. Read_from_EEPROM simply reads the value from EEPROM address zero and outputs it to a terminal using NewSoftSerial. 88 | 89 | 90 | Warnings 91 | =========================================================================== 92 | 93 | If no 'x' characters are sent, TimeNineBits never returns. TimeNineBits will very likely fail or not return if something other than 'x' is sent. 94 | 95 | Interrupts are left enabled until just a bit too late. This allows TimeNineBits to potentially be used side-by-side with other interrupt driven code (like Servo). There is a slight possibility that an interrupt will occur just past the start bit which will throw off the timing. As far as I can tell, Tiny Tuner recovers when this happens. 96 | 97 | Typically, the optimal value can be determined within a few iterations. For various reasons, the target value and the two values on each side are sampled three times to ensure the target value really is optimal. The total number of iterations is usually 10 (but can be more). 98 | 99 | TimeNineBits runs at 8 MHz regardless of the fuse settings. The processor speed is restored after TimeNineBits completes. This is required to make an accurate measurement; 1 MHz just doesn't cut it. 100 | 101 | Small variations in temperature have a very small but measurable effect on the internal oscillator. 102 | 103 | Small variations in supply voltage have a small but measurable effect on the internal oscillator. 104 | 105 | While I have carefully researched and thoroughly tested this library is WITHOUT ANY WARRANTY. 106 | 107 | 108 | Availability 109 | =========================================================================== 110 | 111 | A ZIP package is available here... 112 | http://arduino-tiny.googlecode.com/files/TinyTuner-0001.zip 113 | 114 | The source code is here... 115 | http://code.google.com/p/arduino-tiny/source/browse/#svn/trunk/libraries/TinyTuner 116 | 117 | 118 | License 119 | =========================================================================== 120 | 121 | This library is released under the GNU Lesser General Public License. 122 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambo/arduino-tiny/e1c107a5a18fef491c824be8e6c88ef8f59be594/readme.txt --------------------------------------------------------------------------------