diff --git a/.gitignore b/.gitignore index 1db215cf..9f7304ea 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,7 @@ table.py reference/hardware/v0.2/~$schematic v0.2_bom.xlsx reference/hardware/v0.4/gerbers/Archive.zip +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..2c4ff5c9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/lib/readme.txt b/lib/readme.txt new file mode 100644 index 00000000..dbadc3d6 --- /dev/null +++ b/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/page/librarymanager/ldf.html diff --git a/maths.h b/maths.h deleted file mode 100644 index bf94c51a..00000000 --- a/maths.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MATH_H -#define MATH_H - -int fastMap1023toX(unsigned long x, int out_max); - -#endif diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 00000000..222e59e3 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,46 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:megaatmega2560] +platform=atmelavr +board=megaatmega2560 +framework=arduino +build_unflags = -Os +build_flags = -O3 -ffast-math +lib_deps = EEPROM + +[env:teensy35] +platform=teensy +board=teensy35 +framework=arduino +lib_deps = EEPROM, FlexCAN + +[env:LaunchPad_tm4c1294ncpdt] +platform = titiva +framework = energia +board = lptm4c1294ncpdt +lib_deps = EEPROM + +[env:genericSTM32F103RB] +platform = ststm32 +framework = arduino +; framework-arduinoststm32 +board = genericSTM32F103RB +lib_deps = EEPROM +build_flags = -fpermissive + + +[platformio] +src_dir=speeduino +env_default = megaatmega2560 +;The following lines are for testing / experimentation only. Comment the line above to try them out +;env_default = teensy35 +;env_default = LaunchPad_tm4c1294ncpdt +;env_default = genericSTM32F103RB diff --git a/reference/Speeduino base tune.msq b/reference/Speeduino base tune.msq index 30375fd6..803ff4bd 100644 --- a/reference/Speeduino base tune.msq +++ b/reference/Speeduino base tune.msq @@ -1,7 +1,7 @@ - - + + "0" @@ -43,21 +43,21 @@ 7000.0 - 15.0 - 25.0 + 16.0 + 26.0 30.0 - 35.0 + 36.0 40.0 - 45.0 + 46.0 50.0 - 55.0 + 56.0 60.0 - 65.0 + 66.0 70.0 - 75.0 - 85.0 + 76.0 + 86.0 90.0 - 95.0 + 96.0 100.0 @@ -81,7 +81,7 @@ 20.0 "Speeduino v0.4" "Board Default" -"One" +"Normal" 3.2 0.0 70.0 @@ -103,7 +103,7 @@ "No" "No" "Yes" -"No" +"Enabled" 1.0 355.0 355.0 @@ -156,7 +156,7 @@ 17.0 20.0 20.0 20.0 21.0 23.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 29.0 30.0 31.0 17.0 20.0 20.0 20.0 21.0 22.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 28.0 29.0 30.0 18.0 18.0 18.0 18.0 21.0 21.0 21.0 21.0 21.0 21.0 21.0 20.0 19.0 20.0 20.0 20.0 - 18.0 18.0 18.0 18.0 20.0 20.0 20.0 20.0 19.0 16.0 19.0 18.0 18.0 18.0 18.0 18.0 + 18.0 18.0 18.0 18.0 20.0 20.0 20.0 20.0 19.0 19.0 19.0 18.0 18.0 18.0 18.0 18.0 18.0 18.0 18.0 18.0 18.0 18.0 18.0 18.0 17.0 17.0 17.0 16.0 16.0 16.0 16.0 16.0 18.0 18.0 18.0 18.0 17.0 17.0 17.0 17.0 16.0 16.0 16.0 15.0 15.0 15.0 15.0 15.0 18.0 18.0 18.0 18.0 16.0 16.0 16.0 16.0 15.0 15.0 15.0 14.0 14.0 14.0 14.0 14.0 @@ -183,22 +183,22 @@ 7700.0 + 10.0 + 16.0 20.0 + 26.0 30.0 + 36.0 40.0 + 46.0 50.0 - 60.0 - 70.0 + 56.0 + 66.0 + 74.0 80.0 - 90.0 - 100.0 - 115.0 - 130.0 - 145.0 - 160.0 - 175.0 - 190.0 - 205.0 + 88.0 + 96.0 + 104.0 @@ -288,7 +288,7 @@ 200.0 1.0 "Off" -"1" +"3" "LOW" @@ -329,21 +329,21 @@ 7000.0 - 15.0 - 25.0 + 16.0 + 26.0 30.0 - 35.0 + 36.0 40.0 - 45.0 + 46.0 50.0 - 55.0 + 56.0 60.0 - 65.0 + 66.0 70.0 - 75.0 - 85.0 + 76.0 + 86.0 90.0 - 95.0 + 96.0 100.0 @@ -365,8 +365,12 @@ 15.0 1200.0 70.0 -90.0 -20.0 +"26" +"ONE" +"ONE" +"20" +"ONE" +"ONE" 6.6 9.4 @@ -408,13 +412,13 @@ 30.0 300.0 120.0 -"1" +"Board Default" "No" "LOW" 3500.0 15.0 4000.0 -255.0 +50.0 10.0 0.0 5.0 @@ -422,16 +426,16 @@ 100.0 0.0 0.0 -"Float" +"Pullup" "No" -"ONE" +"No" "ONE" "ONE" "ONE" "ONE" -4500.0 -3000.0 -6000.0 +400.0 +5.0 +2000.0 @@ -600,9 +604,9 @@ 7000.0 - 35.0 + 36.0 50.0 - 65.0 + 66.0 80.0 100.0 120.0 @@ -624,9 +628,9 @@ 7000.0 - 35.0 + 36.0 50.0 - 65.0 + 66.0 80.0 100.0 120.0 @@ -648,9 +652,9 @@ 7000.0 - 35.0 + 36.0 50.0 - 65.0 + 66.0 80.0 100.0 120.0 @@ -672,9 +676,9 @@ 7000.0 - 35.0 + 36.0 50.0 - 65.0 + 66.0 80.0 100.0 120.0 diff --git a/reference/speeduino.ini b/reference/speeduino.ini index f7a26507..39bdde37 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -1,4 +1,4 @@ -;------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- #unset CAN_COMMANDS [MegaTune] @@ -6,7 +6,7 @@ queryCommand = "Q" ;signature = 20 - signature = "speeduino 201701-dev" + signature = "speeduino 201702-dev" versionInfo = "S" ; Put this in the title bar. @@ -22,9 +22,9 @@ ; folder. If is is an undefined referenceName, it will be added. ; keyword = referenceName, DisplayName - settingGroup = boostUnits, "Boost table units" - settingOption = DEFAULT, "kPa" - settingOption = BOOSTPSI, "PSI" + ;settingGroup = boostUnits, "Boost table units" + ;settingOption = DEFAULT, "kPa" + ;settingOption = BOOSTPSI, "PSI" [PcVariables] ; valid types: boolean, double, int, list @@ -168,7 +168,7 @@ page = 2 unused2-26e= bits, U08, 26, [4:4], "No", "Yes" unused2-26f= bits, U08, 26, [5:5], "No", "Yes" unused2-26g= bits, U08, 26, [6:6], "No", "Yes" - unused2-26h= bits, U08, 26, [7:7], "No", "Yes" + indInjAng = bits, U08, 26, [7:7], "Disabled", "Enabled" injOpen = scalar, U08, 27, "ms", 0.1, 0.0, 0.1, 25.5, 1 inj1Ang = scalar, U16, 28, "deg", 1.0, 0.0, 0.0, 360, 0 inj2Ang = scalar, U16, 30, "deg", 1.0, 0.0, 0.0, 360, 0 @@ -249,7 +249,7 @@ page = 4 oddfire = bits, U08, 5,[3:3], "No", "Yes" TrigPattern= bits, U08, 5,[4:7], "Missing Tooth", "Basic Distributor", "Dual Wheel", "GM 7X", "4G63 / Miata", "GM 24X", "Jeep 2000", "Audi 135", "Honda D17", "Miata 99-05", "Mazda AU", "Non-360 Dual", "INVALID", "INVALID", "INVALID", "INVALID" TrigEdgeSec= bits, U08, 6,[0:0], "Leading", "Trailing" - fuelPumpPin= bits , U08, 6,[1:6], "Board Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" + fuelPumpPin= bits , U08, 6,[1:6], "Board Default", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" unused4-6h = bits, U08, 6,[7:7], "No", "Yes" unused4-7 = scalar, U08, 7, "ADC", 1, 0, 0, 255, 0 IdleAdvRPM = scalar, U08, 8, "RPM", 100, 0, 0, 1200, 0 @@ -311,7 +311,7 @@ page = 4 dfcoTPSThresh= scalar, U08, 62, "%", 1.0, 0.0, 0, 100.0, 0 ;ranking ignition bypass ignBypassEnable = bits, U08, 63, [0:0], "Off", "On" - ignBypassPin = bits , U08, 63, [1:6], "INVALID", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" + ignBypassPin = bits , U08, 63, [1:6], "INVALID", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" ignBypassHiLo = bits, U08, 63, [7:7], "LOW", "HIGH" @@ -357,10 +357,10 @@ page = 6 ego_sdelay = scalar, U08, 10, "sec", 1, 0, 0, 120, 0 egoRPM = scalar, U08, 11, "rpm", 100, 0.0, 100, 25500, 0 egoTPSMax = scalar, U08, 12, "%", 1, 0, 0, 120, 0 - vvtPin = bits , U08, 13, [0:5], "Board Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" + vvtPin = bits , U08, 13, [0:5], "Board Default", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" unused6-13e = bits, U08, 13, [6:6], "ONE", "INVALID" unused6-13f = bits, U08, 13, [7:7], "ONE", "INVALID" - boostPin = bits, U08, 14, [0:5], "Board Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" + boostPin = bits, U08, 14, [0:5], "Board Default", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" unused6-14e = bits, U08, 14, [6:6], "ONE", "INVALID" unused6-14f = bits, U08, 14, [7:7], "ONE", "INVALID" brvBins = array, U08, 15, [6], "V", 0.1, 0, 6, 24, 1 ; Bins for the battery reference voltage @@ -378,7 +378,7 @@ page = 6 idleFreq = scalar, U08, 47, "Hz", 2.0, 0.0, 10, 511, 0 ; Launch Control - launchPin = bits , U08, 48, [0:5], "Board Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" + launchPin = bits , U08, 48, [0:5], "Board Default", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" launchEnable= bits, U08, 48, [6:6], "No", "Yes" launchHiLo = bits, U08, 48, [7:7], "LOW", "HIGH" @@ -445,13 +445,13 @@ page = 7 ; Begin fan control vairables fanInv = bits, U08, 56, [0:0], "No", "Yes" fanEnable = bits, U08, 56, [1:1], "Off", "On/Off" - fanPin = bits , U08, 56, [2:7], "Board Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" + fanPin = bits , U08, 56, [2:7], "Board Default", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" #if CELSIUS fanSP = scalar, U08, 57, "C", 1.0, -40, -40, 215.0, 0 - fanHyster = scalar, U08, 58, "C", 1.0, -40, -40, 215.0, 0 + fanHyster = scalar, U08, 58, "C", 1.0, 0.0, 0.0, 40, 0 #else fanSP = scalar, U08, 57, "F", 1.8, -22.23, -40, 215.0, 0 - fanHyster = scalar, U08, 58, "F", 1.8, -22.23, -40, 215.0, 0 + fanHyster = scalar, U08, 58, "F", 1.0, 0.0, 0.0, 40, 0 #endif fanFreq = scalar, U08 , 59, "Hz", 2.0, 0.0, 10, 511, 0 #if CELSIUS @@ -465,12 +465,11 @@ page = 7 ;-------------------------------------------------- page = 8 ;notes for boostTable in PSI~~~There are 6.895 psis to a kPa then x 2 like the kPa ver~~~div atmos. pressure in kPa by 2 and make neg so to subtract instead of add - #if BOOSTPSI - boostTable = array, U08, 0,[8x8], "PSI", 0.29007547546041846, -50.6625, 0, 74, 0 -; boostTable = array, U08, 0,[8x8], "PSI", 0.14503773773020923, -2.10304719708803, 0, 74, 0 #0.043511 0.02900754754 0.05801509508 - #else +; #if BOOSTPSI +; boostTable = array, U08, 0,[8x8], "PSI", 0.29007547546041846, -50.6625, 0, 74, 0 +; #else boostTable = array, U08, 0,[8x8], "kPa", 2.0, 0.0, 0, 511, 0 - #endif +; #endif rpmBinsBoost = array, U08, 64,[ 8], "RPM", 100.0, 0.0, 100, 25500, 0 tpsBinsBoost = array, U08, 72,[ 8], "TPS", 1.0, 0.0, 0.0, 255.0, 0 vvtTable = array, U08, 80,[8x8], "%", 1.0, 0.0, 0, 100, 0 @@ -651,6 +650,7 @@ page = 10 [ConstantsExtensions] requiresPowerCycle = nCylinders requiresPowerCycle = pinLayout + requiresPowerCycle = fanPin requiresPowerCycle = reqFuel requiresPowerCycle = numteeth requiresPowerCycle = onetwo @@ -675,6 +675,7 @@ page = 10 defaultValue = pinLayout, 1 defaultValue = TrigPattern, 0 defaultValue = sparkMode, 0 + defaultValue = indInjAng, 0 defaultValue = inj1Ang, 355 defaultValue = inj2Ang, 355 defaultValue = inj3Ang, 355 @@ -1023,10 +1024,12 @@ menuDialog = main dialog = injChars, "Injector Characteristics" field = "Injector Open Time", injOpen field = "Injector close angle" - field = "Channel 1", inj1Ang - field = "Channel 2", inj2Ang, { nCylinders > 1 } - field = "Channel 3", inj3Ang, { nCylinders > 4 || nCylinders == 3 || ((nCylinders == 4) && (injLayout == 3)) } - field = "Channel 4", inj4Ang, { nCylinders > 6 || ((nCylinders == 4) && (injLayout == 3)) } + field = "", inj1Ang, { indInjAng == 0 } + field = "Individual channel setting", indInjAng + field = "Channel 1", inj1Ang, { indInjAng } + field = "Channel 2", inj2Ang, { nCylinders > 1 && indInjAng } + field = "Channel 3", inj3Ang, { indInjAng && (nCylinders > 4 || nCylinders == 3 || ((nCylinders == 4) && (injLayout == 3))) } + field = "Channel 4", inj4Ang, { indInjAng && (nCylinders > 6 || ((nCylinders == 4) && (injLayout == 3))) } field = "Injector Duty Limit", dutyLim panel = injector_voltage_curve diff --git a/auxiliaries.h b/speeduino/auxiliaries.h similarity index 100% rename from auxiliaries.h rename to speeduino/auxiliaries.h diff --git a/auxiliaries.ino b/speeduino/auxiliaries.ino similarity index 100% rename from auxiliaries.ino rename to speeduino/auxiliaries.ino diff --git a/cancomms.h b/speeduino/cancomms.h similarity index 100% rename from cancomms.h rename to speeduino/cancomms.h diff --git a/cancomms.ino b/speeduino/cancomms.ino similarity index 86% rename from cancomms.ino rename to speeduino/cancomms.ino index 4c4c01f3..594c0727 100644 --- a/cancomms.ino +++ b/speeduino/cancomms.ino @@ -15,6 +15,8 @@ sendcancommand is called when a comman d is to be sent via serial3 to the Can in //#include "globals.h" //#include "storage.h" +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) + void canCommand() { switch (Serial3.read()) @@ -47,16 +49,16 @@ void canCommand() while (Serial3.available() == 0) { } Llength= Serial3.read(); // next the number of bytes expected value for (uint8_t Lcount = 0; Lcount > 2; } //Lite filter level is 25% of previous gap else if(configPage2.triggerFilter == 2) { triggerFilterTime = curGap >> 1; } //Medium filter level is 50% of previous gap else if (configPage2.triggerFilter == 3) { triggerFilterTime = (curGap * 3) >> 2; } //Aggressive filter level is 75% of previous gap - else { triggerFilterTime = 0; } //trigger filter is turned off. + else { triggerFilterTime = 0; } //trigger filter is turned off. } /* @@ -76,11 +76,11 @@ static inline int crankingGetRPM(byte totalTeeth) { noInterrupts(); revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime) * totalTeeth; - interrupts(); + interrupts(); return (US_IN_MINUTE / revolutionTime); } -/* +/* Name: Missing tooth wheel Desc: A multi-tooth wheel with one of more 'missing' teeth. The first tooth after the missing one is considered number 1 and isthe basis for the trigger angle Note: This does not currently support dual wheel (ie missing tooth + single tooth on cam) @@ -93,7 +93,7 @@ void triggerSetup_missingTooth() triggerFilterTime = (int)(1000000 / (MAX_RPM / 60 * configPage2.triggerTeeth)); //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise secondDerivEnabled = false; decoderIsSequential = false; - checkSyncToothCount = (configPage2.triggerTeeth) >> 1; //50% of the total teeth. + checkSyncToothCount = (configPage2.triggerTeeth) >> 1; //50% of the total teeth. MAX_STALL_TIME = (3333UL * triggerToothAngle * (configPage2.triggerMissingTeeth + 1)); //Minimum 50rpm. (3333uS is the time per degree at 50rpm) } @@ -106,7 +106,7 @@ void triggerPri_missingTooth() curGap = curTime - toothLastToothTime; if ( curGap < triggerFilterTime ) { return; } //Debounce check. Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS) toothCurrentCount++; //Increment the tooth counter - + addToothLogEntry(curGap); //if(toothCurrentCount > checkSyncToothCount || !currentStatus.hasSync) @@ -115,16 +115,16 @@ void triggerPri_missingTooth() //If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after the gap if(configPage2.triggerMissingTeeth == 1) { targetGap = (3 * (toothLastToothTime - toothLastMinusOneToothTime)) >> 1; } //Multiply by 1.5 (Checks for a gap 1.5x greater than the last one) (Uses bitshift to multiply by 3 then divide by 2. Much faster than multiplying by 1.5) else { targetGap = ((toothLastToothTime - toothLastMinusOneToothTime)) * 2; } //Multiply by 2 (Checks for a gap 2x greater than the last one) - + if ( curGap > targetGap || toothCurrentCount > triggerActualTeeth) - { - if(toothCurrentCount < (triggerActualTeeth) && currentStatus.hasSync) { currentStatus.hasSync = false; return; } //This occurs when we're at tooth #1, but haven't seen all the other teeth. This indicates a signal issue so we flag lost sync so this will attempt to resync on the next revolution. - toothCurrentCount = 1; + { + if(toothCurrentCount < (triggerActualTeeth) && currentStatus.hasSync) { currentStatus.hasSync = false; return; } //This occurs when we're at tooth #1, but haven't seen all the other teeth. This indicates a signal issue so we flag lost sync so this will attempt to resync on the next revolution. + toothCurrentCount = 1; revolutionOne = !revolutionOne; //Flip sequential revolution tracker toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; currentStatus.hasSync = true; - currentStatus.startRevolutions++; //Counter + currentStatus.startRevolutions++; //Counter triggerFilterTime = 0; //This is used to prevent a condition where serious intermitent signals (Eg someone furiously plugging the sensor wire in and out) can leave the filter in an unrecoverable state } else @@ -133,13 +133,13 @@ void triggerPri_missingTooth() setFilter(curGap); } } - + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } void triggerSec_missingTooth() -{ +{ //TODO: This should really have filtering enabled on the secondary input. revolutionOne = 1; } @@ -156,32 +156,33 @@ int getCrankAngle_missingTooth(int timePerDegree) unsigned long tempToothLastToothTime; int tempToothCurrentCount; bool tempRevolutionOne; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; tempRevolutionOne = revolutionOne; interrupts(); - + int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. //Estimate the number of degrees travelled since the last tooth} - long elapsedTime = micros() - tempToothLastToothTime; + long elapsedTime = (micros() - tempToothLastToothTime); + //crankAngle += DIV_ROUND_CLOSEST(elapsedTime, timePerDegree); if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } //Sequential check (simply sets whether we're on the first or 2nd revoltuion of the cycle) if (tempRevolutionOne) { crankAngle += 360; } - if (crankAngle >= 720) { crankAngle -= 720; } + if (crankAngle >= 720) { crankAngle -= 720; } else if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += CRANK_ANGLE_MAX; } - + return crankAngle; } -/* +/* Name: Dual wheel -Desc: 2 wheels located either both on the crank or with the primary on the crank and the secondary on the cam. +Desc: 2 wheels located either both on the crank or with the primary on the crank and the secondary on the cam. Note: There can be no missing teeth on the primary wheel */ void triggerSetup_DualWheel() @@ -197,7 +198,7 @@ void triggerSetup_DualWheel() void triggerPri_DualWheel() -{ +{ curTime = micros(); curGap = curTime - toothLastToothTime; if ( curGap < triggerFilterTime ) { return; } //Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. @@ -206,11 +207,11 @@ void triggerPri_DualWheel() toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; - + if ( !currentStatus.hasSync ) { return; } - + if ( toothCurrentCount == 1 || toothCurrentCount > configPage2.triggerTeeth ) - { + { toothCurrentCount = 1; revolutionOne = !revolutionOne; //Flip sequential revolution tracker toothOneMinusOneTime = toothOneTime; @@ -219,30 +220,30 @@ void triggerPri_DualWheel() } setFilter(curGap); //Recalc the new filter value - + } void triggerSec_DualWheel() -{ +{ curTime2 = micros(); curGap2 = curTime2 - toothLastSecToothTime; - if ( curGap2 < triggerSecFilterTime ) { return; } + if ( curGap2 < triggerSecFilterTime ) { return; } toothLastSecToothTime = curTime2; triggerSecFilterTime = curGap2 >> 2; //Set filter at 25% of the current speed toothCurrentCount = configPage2.triggerTeeth; - + if(!currentStatus.hasSync) { toothLastToothTime = micros(); toothLastMinusOneToothTime = (toothOneTime - 6000000) / configPage2.triggerTeeth; //Fixes RPM at 10rpm until a full revolution has taken place - + currentStatus.hasSync = true; } revolutionOne = 1; //Sequential revolution reset -} +} int getRPM_DualWheel() { @@ -257,16 +258,16 @@ int getCrankAngle_DualWheel(int timePerDegree) unsigned long tempToothLastToothTime; int tempToothCurrentCount; bool tempRevolutionOne; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; tempRevolutionOne = revolutionOne; interrupts(); - + //Handle case where the secondary tooth was the last one seen if(tempToothCurrentCount == 0) { tempToothCurrentCount = configPage2.triggerTeeth; } - + int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. //Estimate the number of degrees travelled since the last tooth} long elapsedTime = micros() - tempToothLastToothTime; @@ -275,11 +276,11 @@ int getCrankAngle_DualWheel(int timePerDegree) //Sequential check (simply sets whether we're on the first or 2nd revoltuion of the cycle) if (tempRevolutionOne) { crankAngle += 360; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += CRANK_ANGLE_MAX; } - + return crankAngle; } @@ -299,7 +300,7 @@ void triggerSetup_BasicDistributor() triggerFilterTime = triggerFilterTime / 2; //Safety margin secondDerivEnabled = false; decoderIsSequential = false; - MAX_STALL_TIME = (1851UL * triggerToothAngle); //Minimum 90rpm. (1851uS is the time per degree at 90rpm). This decoder uses 90rpm rather than 50rpm due to the potentially very high stall time on a 4 cylinder if we wait that long. + MAX_STALL_TIME = (1851UL * triggerToothAngle); //Minimum 90rpm. (1851uS is the time per degree at 90rpm). This decoder uses 90rpm rather than 50rpm due to the potentially very high stall time on a 4 cylinder if we wait that long. } void triggerPri_BasicDistributor() @@ -307,20 +308,20 @@ void triggerPri_BasicDistributor() curTime = micros(); curGap = curTime - toothLastToothTime; if ( curGap < triggerFilterTime ) { return; } //Noise rejection check. Pulses should never be less than triggerFilterTime - + if(toothCurrentCount == triggerActualTeeth ) //Check if we're back to the beginning of a revolution - { + { toothCurrentCount = 1; //Reset the counter toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; currentStatus.hasSync = true; - currentStatus.startRevolutions++; //Counter + currentStatus.startRevolutions++; //Counter } - else - { - toothCurrentCount++; //Increment the tooth counter + else + { + toothCurrentCount++; //Increment the tooth counter } - + setFilter(curGap); //Recalc the new filter value addToothLogEntry(curGap); @@ -331,7 +332,7 @@ void triggerPri_BasicDistributor() endCoil3Charge(); endCoil4Charge(); } - + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -339,9 +340,9 @@ void triggerSec_BasicDistributor() { return; } //Not required int getRPM_BasicDistributor() { uint16_t tempRPM; - if(currentStatus.RPM < configPage2.crankRPM) + if(currentStatus.RPM < configPage2.crankRPM) { tempRPM = crankingGetRPM(triggerActualTeeth); } - else + else { tempRPM = stdGetRPM(); } return tempRPM << 1; //Multiply RPM by 2 due to tracking over 720 degrees now rather than 360 @@ -351,26 +352,26 @@ int getCrankAngle_BasicDistributor(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - + //int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. //crankAngle += ldiv( (micros() - tempToothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth - - + + int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. //Estimate the number of degrees travelled since the last tooth} long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += CRANK_ANGLE_MAX; } - + return crankAngle; } @@ -393,28 +394,28 @@ void triggerPri_GM7X() curTime = micros(); curGap = curTime - toothLastToothTime; toothCurrentCount++; //Increment the tooth counter - + addToothLogEntry(curGap); - + // if( toothCurrentCount > 7 ) { - toothCurrentCount = 1; - toothOneMinusOneTime = toothOneTime; + toothCurrentCount = 1; + toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; } else { targetGap = (lastGap) >> 1; //The target gap is set at half the last tooth gap if ( curGap < targetGap) //If the gap between this tooth and the last one is less than half of the previous gap, then we are very likely at the magical 3rd tooth - { - toothCurrentCount = 3; + { + toothCurrentCount = 3; currentStatus.hasSync = true; - currentStatus.startRevolutions++; //Counter + currentStatus.startRevolutions++; //Counter return; //We return here so that the tooth times below don't get set (The magical 3rd tooth should not be considered for any calculations that use those times) - } + } } - + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -428,12 +429,12 @@ int getCrankAngle_GM7X(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - + //Check if the last tooth seen was the reference tooth (Number 3). All others can be calculated, but tooth 3 has a unique angle int crankAngle; if( tempToothCurrentCount < 3 ) @@ -448,16 +449,16 @@ int getCrankAngle_GM7X(int timePerDegree) { crankAngle = (tempToothCurrentCount - 2) * triggerToothAngle + 42; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. } - + //Estimate the number of degrees travelled since the last tooth} long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } @@ -477,9 +478,9 @@ void triggerSetup_4G63() decoderIsSequential = true; MAX_STALL_TIME = 366667UL; //Minimum 50rpm based on the 110 degree tooth spacing toothLastToothTime = micros(); //Set a startup value here to avoid filter errors when starting - + //Note that these angles are for every rising and falling edge - + toothAngles[0] = 355; //Falling edge of tooth #1 toothAngles[1] = 105; //Rising edge of tooth #2 toothAngles[2] = 175; //Falling edge of tooth #2 @@ -500,8 +501,8 @@ void triggerSetup_4G63() toothAngles[10] = 535; //Rising edge of wide cam tooth toothAngles[11] = 645; //Rising edge of tooth #1 */ - - triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth. + + triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth. triggerSecFilterTime = (int)(1000000 / (MAX_RPM / 60 * 2)) / 2; //Same as above, but fixed at 2 teeth on the secondary input and divided by 2 (for cam speed) } @@ -512,14 +513,14 @@ void triggerPri_4G63() if ( curGap < triggerFilterTime ) { return; } //Filter check. Pulses should never be less than triggerFilterTime addToothLogEntry(curGap); - triggerFilterTime = curGap >> 2; //This only applies during non-sync conditions. If there is sync then triggerFilterTime gets changed again below with a better value. - + triggerFilterTime = curGap >> 2; //This only applies during non-sync conditions. If there is sync then triggerFilterTime gets changed again below with a better value. + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; - + toothCurrentCount++; if(toothCurrentCount == 1 || toothCurrentCount == 5) //Trigger is on CHANGE, hence 4 pulses = 1 crank rev - { + { toothCurrentCount = 1; //Reset the counter toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; @@ -534,40 +535,40 @@ void triggerPri_4G63() if( toothCurrentCount == 1 ) { endCoil1Charge(); } else if( toothCurrentCount == 3 ) { endCoil2Charge(); } } - + //Whilst this is an uneven tooth pattern, if the specific angle between the last 2 teeth is specified, 1st deriv prediction can be used - if(configPage2.triggerFilter == 1 || currentStatus.RPM < 1800) - { + if(configPage2.triggerFilter == 1 || currentStatus.RPM < 1800) + { //Lite filter if(toothCurrentCount == 1 || toothCurrentCount == 3) { triggerToothAngle = 70; triggerFilterTime = curGap; } //Trigger filter is set to whatever time it took to do 70 degrees (Next trigger is 110 degrees away) else { triggerToothAngle = 110; triggerFilterTime = (curGap * 3) >> 3; } //Trigger filter is set to (110*3)/8=41.25=41 degrees (Next trigger is 70 degrees away). } - else if(configPage2.triggerFilter == 2) + else if(configPage2.triggerFilter == 2) { //Medium filter level if(toothCurrentCount == 1 || toothCurrentCount == 3) { triggerToothAngle = 70; triggerFilterTime = (curGap * 5) >> 2 ; } //87.5 degrees with a target of 110 else { triggerToothAngle = 110; triggerFilterTime = (curGap >> 1); } //55 degrees with a target of 70 - } - else if (configPage2.triggerFilter == 3) + } + else if (configPage2.triggerFilter == 3) { //Aggressive filter level if(toothCurrentCount == 1 || toothCurrentCount == 3) { triggerToothAngle = 70; triggerFilterTime = (curGap * 11) >> 3 ; } //96.26 degrees with a target of 110 else { triggerToothAngle = 110; triggerFilterTime = (curGap * 9) >> 5; } //61.87 degrees with a target of 70 } - else { triggerFilterTime = 0; } //trigger filter is turned off. + else { triggerFilterTime = 0; } //trigger filter is turned off. } void triggerSec_4G63() -{ +{ curTime2 = micros(); curGap2 = curTime2 - toothLastSecToothTime; - if ( curGap2 < triggerSecFilterTime ) { return; } + if ( curGap2 < triggerSecFilterTime ) { return; } toothLastSecToothTime = curTime2; - + if(BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) || !currentStatus.hasSync) { - triggerFilterTime = 1500; //If this is removed, can have trouble getting sync again after the engine is turned off (but ECU not reset). - + triggerFilterTime = 1500; //If this is removed, can have trouble getting sync again after the engine is turned off (but ECU not reset). + //Check the status of the crank trigger bool crank = digitalRead(pinTrigger); if(crank == HIGH) @@ -578,29 +579,29 @@ void triggerSec_4G63() toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; */ - } + } } //else { triggerFilterTime = 1500; } //reset filter time (ugly) - return; + return; } int getRPM_4G63() { - //During cranking, RPM is calculated 4 times per revolution, once for each rising/falling of the crank signal. + //During cranking, RPM is calculated 4 times per revolution, once for each rising/falling of the crank signal. //Because these signals aren't even (Alternating 110 and 70 degrees), this needs a special function if(!currentStatus.hasSync) { return 0; } - if(currentStatus.RPM < configPage2.crankRPM) - { + if(currentStatus.RPM < configPage2.crankRPM) + { if(currentStatus.startRevolutions < 2) { return 0; } //Need at least 2 full revolutions to prevent crazy initial rpm value int tempToothAngle; noInterrupts(); tempToothAngle = triggerToothAngle; /* High-res mode - if(toothCurrentCount == 1) { tempToothAngle = 70; } + if(toothCurrentCount == 1) { tempToothAngle = 70; } else { tempToothAngle = toothAngles[toothCurrentCount-1] - toothAngles[toothCurrentCount-2]; } */ - revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime); //Note that trigger tooth angle changes between 70 and 110 depending on the last tooth that was seen + revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime); //Note that trigger tooth angle changes between 70 and 110 depending on the last tooth that was seen interrupts(); revolutionTime = revolutionTime * 36; int tempRPM = ((unsigned long)tempToothAngle * 6000000UL) / revolutionTime; @@ -615,23 +616,23 @@ int getCrankAngle_4G63(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - - int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. + + int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. //Estimate the number of degrees travelled since the last tooth} - + unsigned long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } @@ -681,28 +682,28 @@ void triggerPri_24X() if(toothCurrentCount == 25) { currentStatus.hasSync = false; return; } //Indicates sync has not been achieved (Still waiting for 1 revolution of the crank to take place) curTime = micros(); curGap = curTime - toothLastToothTime; - + if(toothCurrentCount == 0) - { + { toothCurrentCount = 1; //Reset the counter toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; currentStatus.hasSync = true; - currentStatus.startRevolutions++; //Counter + currentStatus.startRevolutions++; //Counter } else { toothCurrentCount++; //Increment the tooth counter } - + addToothLogEntry(curGap); - + toothLastToothTime = curTime; } void triggerSec_24X() -{ +{ toothCurrentCount = 0; //All we need to do is reset the tooth count back to zero, indicating that we're at the beginning of a new revolution - return; + return; } int getRPM_24X() @@ -714,25 +715,25 @@ int getCrankAngle_24X(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - + int crankAngle; - if (toothCurrentCount == 0) { crankAngle = 0 + configPage2.triggerAngle; } //This is the special case to handle when the 'last tooth' seen was the cam tooth. 0 is the angle at which the crank tooth goes high (Within 360 degrees). - else { crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle;} //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. - + if (toothCurrentCount == 0) { crankAngle = 0 + configPage2.triggerAngle; } //This is the special case to handle when the 'last tooth' seen was the cam tooth. 0 is the angle at which the crank tooth goes high (Within 360 degrees). + else { crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle;} //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. + //Estimate the number of degrees travelled since the last tooth} long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } @@ -759,7 +760,7 @@ void triggerSetup_Jeep2000() toothAngles[10] = 454; toothAngles[11] = 474; - MAX_STALL_TIME = (3333UL * 60); //Minimum 50rpm. (3333uS is the time per degree at 50rpm). Largest gap between teeth is 60 degrees. + MAX_STALL_TIME = (3333UL * 60); //Minimum 50rpm. (3333uS is the time per degree at 50rpm). Largest gap between teeth is 60 degrees. toothCurrentCount = 13; //We set the initial tooth value to be something that should never be reached. This indicates no sync secondDerivEnabled = false; decoderIsSequential = false; @@ -771,14 +772,14 @@ void triggerPri_Jeep2000() curTime = micros(); curGap = curTime - toothLastToothTime; if ( curGap < triggerFilterTime ) { return; } //Noise rejection check. Pulses should never be less than triggerFilterTime - + if(toothCurrentCount == 0) - { + { toothCurrentCount = 1; //Reset the counter toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; currentStatus.hasSync = true; - currentStatus.startRevolutions++; //Counter + currentStatus.startRevolutions++; //Counter } else { @@ -786,16 +787,16 @@ void triggerPri_Jeep2000() } setFilter(curGap); //Recalc the new filter value - + addToothLogEntry(curGap); - + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } void triggerSec_Jeep2000() -{ +{ toothCurrentCount = 0; //All we need to do is reset the tooth count back to zero, indicating that we're at the beginning of a new revolution - return; + return; } int getRPM_Jeep2000() @@ -807,30 +808,30 @@ int getCrankAngle_Jeep2000(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - + int crankAngle; - if (toothCurrentCount == 0) { crankAngle = 146 + configPage2.triggerAngle; } //This is the special case to handle when the 'last tooth' seen was the cam tooth. 146 is the angle at which the crank tooth goes high. - else { crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle;} //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. + if (toothCurrentCount == 0) { crankAngle = 146 + configPage2.triggerAngle; } //This is the special case to handle when the 'last tooth' seen was the cam tooth. 146 is the angle at which the crank tooth goes high. + else { crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle;} //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. //Estimate the number of degrees travelled since the last tooth} long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } -/* +/* Name: Audi 135 -Desc: 135 teeth on the crank and 1 tooth on the cam. +Desc: 135 teeth on the crank and 1 tooth on the cam. Note: This is very similar to the dual wheel decoder, however due to the 135 teeth not dividing evenly into 360, only every 3rd crank tooth is used in calculating the crank angle. This effectively makes it a 45 tooth dual wheel setup */ void triggerSetup_Audi135() @@ -846,7 +847,7 @@ void triggerSetup_Audi135() } void triggerPri_Audi135() -{ +{ curTime = micros(); curGap = curTime - toothSystemLastToothTime; if ( curGap < triggerFilterTime ) { return; } @@ -855,38 +856,38 @@ void triggerPri_Audi135() addToothLogEntry(curGap); if ( !currentStatus.hasSync ) { return; } if ( toothSystemCount < 3 ) { return; } //We only proceed for every third tooth - + toothSystemCount = 0; toothCurrentCount++; //Increment the tooth counter - + if ( toothCurrentCount == 1 || toothCurrentCount > 45 ) - { + { toothCurrentCount = 1; toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; currentStatus.startRevolutions++; //Counter - } + } setFilter(curGap); //Recalc the new filter value - + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } void triggerSec_Audi135() -{ +{ curTime2 = micros(); curGap2 = curTime2 - toothLastSecToothTime; - if ( curGap2 < triggerSecFilterTime ) { return; } + if ( curGap2 < triggerSecFilterTime ) { return; } toothLastSecToothTime = curTime2; - + if( !currentStatus.hasSync ) { toothCurrentCount = 0; currentStatus.hasSync = true; toothSystemCount = 3; //Need to set this to 3 so that the next primary tooth is counted } -} +} int getRPM_Audi135() { @@ -894,36 +895,36 @@ int getRPM_Audi135() } int getCrankAngle_Audi135(int timePerDegree) -{ +{ //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - + //Handle case where the secondary tooth was the last one seen if(tempToothCurrentCount == 0) { tempToothCurrentCount = 45; } - + int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. //Estimate the number of degrees travelled since the last tooth} long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } /* ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Name: Honda D17 -Desc: -Note: +Desc: +Note: */ void triggerSetup_HondaD17() { @@ -939,33 +940,33 @@ void triggerPri_HondaD17() curTime = micros(); curGap = curTime - toothLastToothTime; toothCurrentCount++; //Increment the tooth counter - + addToothLogEntry(curGap); - + // if( toothCurrentCount == 13 && currentStatus.hasSync) { - toothCurrentCount = 0; + toothCurrentCount = 0; return; } else if( toothCurrentCount == 1 && currentStatus.hasSync) { - toothOneMinusOneTime = toothOneTime; + toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; - currentStatus.startRevolutions++; //Counter + currentStatus.startRevolutions++; //Counter } else { //13th tooth targetGap = (lastGap) >> 1; //The target gap is set at half the last tooth gap if ( curGap < targetGap) //If the gap between this tooth and the last one is less than half of the previous gap, then we are very likely at the magical 13th tooth - { - toothCurrentCount = 0; + { + toothCurrentCount = 0; currentStatus.hasSync = true; return; //We return here so that the tooth times below don't get set (The magical 13th tooth should not be considered for any calculations that use those times) - } + } } - + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -979,32 +980,32 @@ int getCrankAngle_HondaD17(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - + //Check if the last tooth seen was the reference tooth 13 (Number 0 here). All others can be calculated, but tooth 3 has a unique angle int crankAngle; if( tempToothCurrentCount == 0 ) { - crankAngle = 11 * triggerToothAngle + configPage2.triggerAngle; //if temptoothCurrentCount is 0, the last tooth seen was the 13th one. Based on this, ignore the 13th tooth and use the 12th one as the last reference. + crankAngle = 11 * triggerToothAngle + configPage2.triggerAngle; //if temptoothCurrentCount is 0, the last tooth seen was the 13th one. Based on this, ignore the 13th tooth and use the 12th one as the last reference. } else { crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. } - + //Estimate the number of degrees travelled since the last tooth} long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } @@ -1021,16 +1022,16 @@ void triggerSetup_Miata9905() toothCurrentCount = 99; //Fake tooth count represents no sync secondDerivEnabled = false; decoderIsSequential = true; - + //Note that these angles are for every rising and falling edge - + toothAngles[0] = 350; //Falling edge of tooth #1 toothAngles[1] = 100; //Rising edge of tooth #2 toothAngles[2] = 170; //Falling edge of tooth #2 toothAngles[3] = 280; //Rising edge of tooth #1 MAX_STALL_TIME = (3333UL * triggerToothAngle); //Minimum 50rpm. (3333uS is the time per degree at 50rpm) - triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth. + triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth. triggerSecFilterTime = (int)(1000000 / (MAX_RPM / 60 * 2)) / 2; //Same as above, but fixed at 2 teeth on the secondary input and divided by 2 (for cam speed) } @@ -1039,10 +1040,10 @@ void triggerPri_Miata9905() curTime = micros(); curGap = curTime - toothLastToothTime; if ( curGap < triggerFilterTime ) { return; } //Debounce check. Pulses should never be less than triggerFilterTime - + toothCurrentCount++; if(toothCurrentCount == 1 || toothCurrentCount == 5) //Trigger is on CHANGE, hence 4 pulses = 1 crank rev - { + { toothCurrentCount = 1; //Reset the counter toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; @@ -1051,52 +1052,52 @@ void triggerPri_Miata9905() //if ((startRevolutions & 15) == 1) { currentStatus.hasSync = false; } //Every 64 revolutions, force a resync with the cam } else if (!currentStatus.hasSync) { return; } - + addToothLogEntry(curGap); - + //Whilst this is an uneven tooth pattern, if the specific angle between the last 2 teeth is specified, 1st deriv prediction can be used if(toothCurrentCount == 1 || toothCurrentCount == 3) { triggerToothAngle = 70; triggerFilterTime = curGap; } //Trigger filter is set to whatever time it took to do 70 degrees (Next trigger is 110 degrees away) else { triggerToothAngle = 110; triggerFilterTime = (curGap * 3) >> 3; } //Trigger filter is set to (110*3)/8=41.25=41 degrees (Next trigger is 70 degrees away). - + curGap = curGap >> 1; - + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } void triggerSec_Miata9905() -{ +{ curTime2 = micros(); curGap2 = curTime2 - toothLastSecToothTime; - if ( curGap2 < triggerSecFilterTime ) { return; } + if ( curGap2 < triggerSecFilterTime ) { return; } toothLastSecToothTime = curTime2; lastGap = curGap2; - + if(BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) || !currentStatus.hasSync) { triggerFilterTime = 1500; //Check the status of the crank trigger targetGap = (lastGap) >> 1; //The target gap is set at half the last tooth gap if ( curGap < targetGap) //If the gap between this tooth and the last one is less than half of the previous gap, then we are very likely at the extra (3rd) tooth on the cam). This tooth is located at 421 crank degrees (aka 61 degrees) and therefore the last crank tooth seen was number 1 (At 350 degrees) - { - toothCurrentCount = 1; + { + toothCurrentCount = 1; currentStatus.hasSync = true; - } + } } //else { triggerFilterTime = 1500; } //reset filter time (ugly) - return; + return; } int getRPM_Miata9905() { - //During cranking, RPM is calculated 4 times per revolution, once for each tooth on the crank signal. + //During cranking, RPM is calculated 4 times per revolution, once for each tooth on the crank signal. //Because these signals aren't even (Alternating 110 and 70 degrees), this needs a special function - if(currentStatus.RPM < configPage2.crankRPM) - { + if(currentStatus.RPM < configPage2.crankRPM) + { int tempToothAngle; noInterrupts(); tempToothAngle = triggerToothAngle; - revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime); //Note that trigger tooth angle changes between 70 and 110 depending on the last tooth that was seen + revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime); //Note that trigger tooth angle changes between 70 and 110 depending on the last tooth that was seen interrupts(); revolutionTime = revolutionTime * 36; return (tempToothAngle * 60000000L) / revolutionTime; @@ -1110,30 +1111,30 @@ int getCrankAngle_Miata9905(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - - int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. + + int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. //Estimate the number of degrees travelled since the last tooth} - + long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } /* ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Name: Mazda AU version -Desc: -Note: +Desc: +Note: Tooth #2 is defined as the next crank tooth after the single cam tooth Tooth number one is at 348* ATDC */ @@ -1144,14 +1145,14 @@ void triggerSetup_MazdaAU() secondaryToothCount = 0; //Needed for the cam tooth tracking secondDerivEnabled = false; decoderIsSequential = true; - + toothAngles[0] = 348; //tooth #1 toothAngles[1] = 96; //tooth #2 toothAngles[2] = 168; //tooth #3 toothAngles[3] = 276; //tooth #4 MAX_STALL_TIME = (3333UL * triggerToothAngle); //Minimum 50rpm. (3333uS is the time per degree at 50rpm) - triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth. + triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth. triggerSecFilterTime = (int)(1000000 / (MAX_RPM / 60 * 2)) / 2; //Same as above, but fixed at 2 teeth on the secondary input and divided by 2 (for cam speed) } @@ -1162,10 +1163,10 @@ void triggerPri_MazdaAU() if ( curGap < triggerFilterTime ) { return; } //Filter check. Pulses should never be less than triggerFilterTime addToothLogEntry(curGap); - + toothCurrentCount++; if(toothCurrentCount == 1 || toothCurrentCount == 5) //Trigger is on CHANGE, hence 4 pulses = 1 crank rev - { + { toothCurrentCount = 1; //Reset the counter toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; @@ -1181,35 +1182,35 @@ void triggerPri_MazdaAU() if( toothCurrentCount == 1 ) { endCoil1Charge(); } else if( toothCurrentCount == 3 ) { endCoil2Charge(); } } - + //Whilst this is an uneven tooth pattern, if the specific angle between the last 2 teeth is specified, 1st deriv prediction can be used if(toothCurrentCount == 1 || toothCurrentCount == 3) { triggerToothAngle = 72; triggerFilterTime = curGap; } //Trigger filter is set to whatever time it took to do 72 degrees (Next trigger is 108 degrees away) else { triggerToothAngle = 108; triggerFilterTime = (curGap * 3) >> 3; } //Trigger filter is set to (108*3)/8=40 degrees (Next trigger is 70 degrees away). - + toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } void triggerSec_MazdaAU() -{ +{ curTime2 = micros(); lastGap = curGap2; curGap2 = curTime2 - toothLastSecToothTime; - //if ( curGap2 < triggerSecFilterTime ) { return; } + //if ( curGap2 < triggerSecFilterTime ) { return; } toothLastSecToothTime = curTime2; - + //if(BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) || !currentStatus.hasSync) //Not sure if the cranking check is needed here if(!currentStatus.hasSync) { //we find sync by looking for the 2 teeth that are close together. The next crank tooth after that is the one we're looking for. //For the sake of this decoder, the lone cam tooth will be designated #1 if(secondaryToothCount == 2) - { - toothCurrentCount = 1; + { + toothCurrentCount = 1; currentStatus.hasSync = true; } else { - triggerFilterTime = 1500; //In case the engine has been running and then lost sync. + triggerFilterTime = 1500; //In case the engine has been running and then lost sync. targetGap = (lastGap) >> 1; //The target gap is set at half the last tooth gap if ( curGap2 < targetGap) //If the gap between this tooth and the last one is less than half of the previous gap, then we are very likely at the extra (3rd) tooth on the cam). This tooth is located at 421 crank degrees (aka 61 degrees) and therefore the last crank tooth seen was number 1 (At 350 degrees) { @@ -1219,22 +1220,22 @@ void triggerSec_MazdaAU() secondaryToothCount++; } - return; + return; } int getRPM_MazdaAU() { if (!currentStatus.hasSync) { return 0; } - - //During cranking, RPM is calculated 4 times per revolution, once for each tooth on the crank signal. + + //During cranking, RPM is calculated 4 times per revolution, once for each tooth on the crank signal. //Because these signals aren't even (Alternating 108 and 72 degrees), this needs a special function - if(currentStatus.RPM < configPage2.crankRPM) - { + if(currentStatus.RPM < configPage2.crankRPM) + { int tempToothAngle; noInterrupts(); tempToothAngle = triggerToothAngle; - revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime); //Note that trigger tooth angle changes between 72 and 108 depending on the last tooth that was seen + revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime); //Note that trigger tooth angle changes between 72 and 108 depending on the last tooth that was seen interrupts(); revolutionTime = revolutionTime * 36; return (tempToothAngle * 60000000L) / revolutionTime; @@ -1248,29 +1249,29 @@ int getCrankAngle_MazdaAU(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - - int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. + + int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. //Estimate the number of degrees travelled since the last tooth} - + long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } -/* +/* Name: Non-360 Dual wheel -Desc: 2 wheels located either both on the crank or with the primary on the crank and the secondary on the cam. +Desc: 2 wheels located either both on the crank or with the primary on the crank and the secondary on the cam. Note: There can be no missing teeth on the primary wheel */ void triggerSetup_non360() @@ -1286,14 +1287,14 @@ void triggerSetup_non360() void triggerPri_non360() -{ +{ //This is not used, the trigger is identical to the dual wheel one, so that is used instead. } void triggerSec_non360() -{ +{ //This is not used, the trigger is identical to the dual wheel one, so that is used instead. -} +} int getRPM_non360() { @@ -1307,30 +1308,27 @@ int getCrankAngle_non360(int timePerDegree) //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; - //Grab some variables that are used in the trigger code and assign them to temp variables. + //Grab some variables that are used in the trigger code and assign them to temp variables. noInterrupts(); tempToothCurrentCount = toothCurrentCount; tempToothLastToothTime = toothLastToothTime; interrupts(); - + //Handle case where the secondary tooth was the last one seen if(tempToothCurrentCount == 0) { tempToothCurrentCount = configPage2.triggerTeeth; } //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle; - crankAngle = (crankAngle / configPage2.TrigAngMul) + configPage2.triggerAngle; //Have to divide by the multiplier to get back to actual crank angle. - + crankAngle = (crankAngle / configPage2.TrigAngMul) + configPage2.triggerAngle; //Have to divide by the multiplier to get back to actual crank angle. + //Estimate the number of degrees travelled since the last tooth} long elapsedTime = micros() - tempToothLastToothTime; if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; } - - if (crankAngle >= 720) { crankAngle -= 720; } + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; } if (crankAngle < 0) { crankAngle += 360; } - + return crankAngle; } - - - diff --git a/display.h b/speeduino/display.h similarity index 100% rename from display.h rename to speeduino/display.h diff --git a/display.ino b/speeduino/display.ino similarity index 99% rename from display.ino rename to speeduino/display.ino index 25c0b2b6..acf11a7e 100644 --- a/display.ino +++ b/speeduino/display.ino @@ -4,6 +4,8 @@ Copyright (C) Josh Stewart A full copy of the license may be found in the projects root directory */ +#ifdef USE_DISPLAY + #include #include #include "src/Adafruit_SSD1306/Adafruit_GFX.h" @@ -15,7 +17,7 @@ void initialiseDisplay() { //Protection against older pin mappings where the crank/cam signals were on the SDA and SCL pins. This will cause the Arduino to lock hard if you try to initialise i2c devices when a crank signal is coming in if(pinTrigger == 20 || pinTrigger == 21 || pinTrigger2 == 20 || pinTrigger2 == 21) { return; } - + switch(configPage1.displayType) { case 1: @@ -29,9 +31,9 @@ void initialiseDisplay() break; case 4: display.SSD1306_SETCOMPINS_V = 0x12; - break; + break; } - + display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) display.clearDisplay(); display.setTextSize(1); @@ -89,7 +91,7 @@ void updateDisplay() display.print(currentStatus.coolant); break; } - + display.setCursor(0,11); switch(configPage1.display3) { @@ -134,7 +136,7 @@ void updateDisplay() display.print(currentStatus.coolant); break; } - + display.setCursor(64,0); switch(configPage1.display2) { @@ -159,7 +161,7 @@ void updateDisplay() display.print(currentStatus.freeRAM); break; } - + display.setCursor(64,11); switch(configPage1.display4) { @@ -184,10 +186,11 @@ void updateDisplay() display.print(currentStatus.freeRAM); break; } - + int barWidth = ldiv(((unsigned long)currentStatus.RPM * 128), 9000).quot; //int barWidth = map(currentStatus.RPM, 0, 9000, 0, 128); display.fillRect(0, 20, barWidth, 10, 1); - + display.display(); } +#endif diff --git a/errors.h b/speeduino/errors.h similarity index 100% rename from errors.h rename to speeduino/errors.h diff --git a/errors.ino b/speeduino/errors.ino similarity index 100% rename from errors.ino rename to speeduino/errors.ino diff --git a/globals.h b/speeduino/globals.h similarity index 96% rename from globals.h rename to speeduino/globals.h index 5d79ee36..477ee0d5 100644 --- a/globals.h +++ b/speeduino/globals.h @@ -31,7 +31,7 @@ #define BIT_SQUIRT_INJ3 2 //inj3 Squirt #define BIT_SQUIRT_INJ4 3 //inj4 Squirt #define BIT_SQUIRT_DFCO 4 //Decelleration fuel cutoff -#define BIT_SQUIRT_BOOSTCUT 5 //Fuel component of MAP based boost cut out +#define BIT_SQUIRT_BOOSTCUT 5 //Fuel component of MAP based boost cut out #define BIT_SQUIRT_TOOTHLOG1READY 6 //Used to flag if tooth log 1 is ready #define BIT_SQUIRT_TOOTHLOG2READY 7 //Used to flag if tooth log 2 is ready (Log is not currently used) @@ -43,7 +43,7 @@ #define BIT_SPARK_BOOSTCUT 4 //Spark component of MAP based boost cut out #define BIT_SPARK_ERROR 5 // Error is detected #define BIT_SPARK_IDLE 6 // idle on -#define BIT_SPARK_SYNC 7 // Whether engine has sync or not +#define BIT_SPARK_SYNC 7 // Whether engine has sync or not #define BIT_SPARK2_FLATSH 0 //Flat shift hard cut #define BIT_SPARK2_FLATSS 1 //Flat shift soft cut @@ -91,7 +91,7 @@ const byte signature = 20; const char displaySignature[] = "speeduino 201609-dev"; const char TSfirmwareVersion[] = "Speeduino 2016.09"; -const byte data_structure_version = 2; //This identifies the data structure when reading / writing. +const byte data_structure_version = 2; //This identifies the data structure when reading / writing. const byte page_size = 64; const int npage_size[11] ={0,288,64,288,64,288,64,64,160,192,128}; //const byte page10_size = 128; @@ -147,7 +147,7 @@ struct statuses { long longRPM; int mapADC; long MAP; //Has to be a long for PID calcs (Boost control) - int baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running + byte baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running byte TPS; //The current TPS reading (0% - 100%) byte TPSlast; //The previous TPS reading unsigned long TPS_time; //The time the TPS sample was taken @@ -181,7 +181,7 @@ struct statuses { byte afrTarget; byte idleDuty; bool fanOn; //Whether or not the fan is turned on - volatile byte ethanolPct; //Ethanol reading (if enabled). 0 = No ethanol, 100 = pure ethanol. Eg E85 = 85. + volatile byte ethanolPct; //Ethanol reading (if enabled). 0 = No ethanol, 100 = pure ethanol. Eg E85 = 85. unsigned long TAEEndTime; //The target end time used whenever TAE is turned on volatile byte squirt; volatile byte spark; @@ -192,28 +192,28 @@ struct statuses { unsigned int PW3; //In uS unsigned int PW4; //In uS volatile byte runSecs; //Counter of seconds since cranking commenced (overflows at 255 obviously) - volatile byte secl; //Continous + volatile byte secl; //Continous volatile unsigned int loopsPerSecond; boolean launchingSoft; //True when in launch control soft limit mode boolean launchingHard; //True when in launch control hard limit mode int freeRAM; unsigned int clutchEngagedRPM; bool flatShiftingHard; - volatile byte startRevolutions = 0; //A counter for how many revolutions have been completed since sync was achieved. - + volatile byte startRevolutions; //A counter for how many revolutions have been completed since sync was achieved. + //Helpful bitwise operations: //Useful reference: http://playground.arduino.cc/Code/BitMath // y = (x >> n) & 1; // n=0..15. stores nth bit of x in y. y becomes 0 or 1. // x &= ~(1 << n); // forces nth bit of x to be 0. all other bits left alone. // x |= (1 << n); // forces nth bit of x to be 1. all other bits left alone. - + }; struct statuses currentStatus; //The global status object //Page 1 of the config - See the ini file for further reference //This mostly covers off variables that are required for fuel struct config1 { - + byte unused1; //Cold cranking pulsewidth modifier. This is added to the fuel pulsewidth when cranking under a certain temp threshold (ms) byte unused2; //Warm cranking pulsewidth modifier. This is added to the fuel pulsewidth when cranking (ms) byte asePct; //Afterstart enrichment (%) @@ -227,30 +227,31 @@ struct config1 { byte taeColdA; byte tpsThresh; byte taeTime; - + //Display config bits byte displayType : 3; byte display1 : 3; byte display2 : 2; - + byte display3 : 3; byte display4 : 2; byte display5 : 3; - + byte displayB1 : 4; byte displayB2 : 4; - + byte reqFuel; byte divider; byte injTiming : 1; byte multiplyMAP : 1; byte includeAFR : 1; - byte unused26 : 5; + byte unused26 : 4; + byte indInjAng : 1; byte injOpen; //Injector opening time (ms * 10) unsigned int inj1Ang; - unsigned int inj2Ang; - unsigned int inj3Ang; - unsigned int inj4Ang; + unsigned int inj2Ang; + unsigned int inj3Ang; + unsigned int inj4Ang; //config1 in ini byte mapSample : 2; @@ -258,21 +259,21 @@ struct config1 { byte injType : 1; byte nCylinders : 4; //Number of cylinders - //config2 in ini + //config2 in ini byte cltType1 : 2; byte matType1 : 2; byte nInjectors : 4; //Number of injectors - + //config3 in ini - byte engineType : 1; + byte engineType : 1; byte flexEnabled : 1; byte algorithm : 1; //"Speed Density", "Alpha-N" byte baroCorr : 1; byte injLayout : 2; byte canEnable : 1; //is can interface enabled byte unused2_38h : 1; - + byte primePulse; byte dutyLim; byte flexFreqLow; //Lowest valid frequency reading from the flex sensor @@ -294,18 +295,18 @@ struct config1 { byte unused61; byte unused62; byte unused63; - + }; //Page 2 of the config - See the ini file for further reference //This mostly covers off variables that are required for ignition struct config2 { - + int triggerAngle; byte FixAng; byte CrankAng; - byte TrigAngMul; //Multiplier for non evenly divisible tooth counts. - + byte TrigAngMul; //Multiplier for non evenly divisible tooth counts. + byte TrigEdge : 1; byte TrigSpeed : 1; byte IgInv : 1; @@ -315,22 +316,22 @@ struct config2 { byte TrigEdgeSec : 1; byte fuelPumpPin : 6; byte unused4_6b : 1; - + byte unused4_7; byte IdleAdvRPM; byte IdleAdvCLT; //The temperature below which the idle is advanced byte IdleDelayTime; byte StgCycles; //The number of initial cycles before the ignition should fire when first cranking - + byte dwellCont : 1; //Fixed duty dwell control byte useDwellLim : 1; //Whether the dwell limiter is off or on byte sparkMode : 2; //Spark output mode (Eg Wasted spark, single channel or Wasted COP) byte dfcoEnabled : 1; //Whether or not DFCO is turned on byte triggerFilter : 2; //The mode of trigger filter being used (0=Off, 1=Light (Not currently used), 2=Normal, 3=Aggressive) - byte ignCranklock : 1; //Whether or not the ignition timing during cranking is locked to a CAS pulse. Only currently valid for Basic distributor and 4G63. - + byte ignCranklock : 1; //Whether or not the ignition timing during cranking is locked to a CAS pulse. Only currently valid for Basic distributor and 4G63. + byte dwellCrank; //Dwell time whilst cranking - byte dwellRun; //Dwell time whilst running + byte dwellRun; //Dwell time whilst running byte triggerTeeth; //The full count of teeth on the trigger wheel if there were no gaps byte triggerMissingTeeth; //The size of the tooth gap (ie number of missing teeth) byte crankRPM; //RPM below which the engine is considered to be cranking @@ -352,21 +353,21 @@ struct config2 { byte ignBypassEnabled : 1; //Whether or not the ignition bypass is enabled byte ignBypassPin : 6; //Pin the ignition bypass is activated on - byte ignBypassHiLo : 1; //Whether this should be active high or low. + byte ignBypassHiLo : 1; //Whether this should be active high or low. + - }; //Page 3 of the config - See the ini file for further reference //This mostly covers off variables that are required for AFR targets and closed loop struct config3 { - + byte egoAlgorithm : 2; byte egoType : 2; byte boostEnabled : 1; byte vvtEnabled : 1; byte boostCutType : 2; - + byte egoKP; byte egoKI; byte egoKD; @@ -379,9 +380,9 @@ struct config3 { byte ego_sdelay; //Time in seconds after engine starts that closed loop becomes available byte egoRPM; //RPM must be above this for closed loop to function byte egoTPSMax; //TPS must be below this for closed loop to function - byte boostPin : 6; - byte unused6_13 : 2; byte vvtPin : 6; + byte unused6_13 : 2; + byte boostPin : 6; byte unused6_14 : 2; byte voltageCorrectionBins[6]; //X axis bins for voltage correction tables byte injVoltageCorrectionValues[6]; //Correction table for injector PW vs battery voltage @@ -390,11 +391,11 @@ struct config3 { byte boostFreq; //Frequency of the boost PWM valve byte vvtFreq; //Frequency of the vvt PWM valve byte idleFreq; - + byte launchPin : 6; byte launchEnabled : 1; byte launchHiLo : 1; - + byte lnchSoftLim; int8_t lnchRetard; //Allow for negative advance value (ATDC) byte lnchHardLim; @@ -404,12 +405,12 @@ struct config3 { byte idleKP; byte idleKI; byte idleKD; - + byte boostLimit; //Is divided by 2, allowing kPa values up to 511 byte boostKP; byte boostKI; byte boostKD; - + byte lnchPullRes : 2; byte fuelTrimEnabled : 1; byte flatSEnable : 1; @@ -418,7 +419,7 @@ struct config3 { byte flatSRetard; byte flatSArm; - + }; @@ -432,22 +433,22 @@ struct config4 { byte iacCrankSteps[4]; //Steps to use when cranking (Stepper motor) byte iacCrankDuty[4]; //Duty cycle to use on PWM valves when cranking byte iacCrankBins[4]; //Temperature Bins for the above 2 curves - + byte iacAlgorithm : 3; //Valid values are: "None", "On/Off", "PWM", "PWM Closed Loop", "Stepper", "Stepper Closed Loop" byte iacStepTime : 3; //How long to pulse the stepper for to ensure the step completes (ms) byte iacChannels : 1; //How many outputs to use in PWM mode (0 = 1 channel, 1 = 2 channels) byte iacPWMdir : 1; //Directino of the PWM valve. 0 = Normal = Higher RPM with more duty. 1 = Reverse = Lower RPM with more duty - + byte iacFastTemp; //Fast idle temp when using a simple on/off valve - + byte iacStepHome; //When using a stepper motor, the number of steps to be taken on startup to home the motor byte iacStepHyster; //Hysteresis temperature (*10). Eg 2.2C = 22 - + byte fanInv : 1; // Fan output inversion bit byte fanEnable : 1; // Fan enable bit. 0=Off, 1=On/Off byte fanPin : 5; byte fanSP; // Cooling fan start temperature - byte fanHyster; // Fan hysteresis + byte fanHyster; // Fan hysteresis byte fanFreq; // Fan PWM frequency byte fanPWMBins[4]; //Temperature Bins for the PWM fan control }; diff --git a/idle.h b/speeduino/idle.h similarity index 100% rename from idle.h rename to speeduino/idle.h diff --git a/idle.ino b/speeduino/idle.ino similarity index 100% rename from idle.ino rename to speeduino/idle.ino diff --git a/speeduino/maths.h b/speeduino/maths.h new file mode 100644 index 00000000..7daa0e7b --- /dev/null +++ b/speeduino/maths.h @@ -0,0 +1,7 @@ +#ifndef MATH_H +#define MATH_H + +int fastMap1023toX(unsigned long, int); +unsigned long percentage(byte, unsigned long); + +#endif diff --git a/maths.ino b/speeduino/maths.ino similarity index 96% rename from maths.ino rename to speeduino/maths.ino index fe5c7265..4c142533 100644 --- a/maths.ino +++ b/speeduino/maths.ino @@ -1,5 +1,7 @@ #include "maths.h" +#define DIV_ROUND_CLOSEST(n, d) ((((n) < 0) ^ ((d) < 0)) ? (((n) - (d)/2)/(d)) : (((n) + (d)/2)/(d))) + //Replace the standard arduino map() function to use the div function instead int fastMap(unsigned long x, int in_min, int in_max, int out_min, int out_max) { diff --git a/scheduledIO.h b/speeduino/scheduledIO.h similarity index 100% rename from scheduledIO.h rename to speeduino/scheduledIO.h diff --git a/scheduledIO.ino b/speeduino/scheduledIO.ino similarity index 100% rename from scheduledIO.ino rename to speeduino/scheduledIO.ino diff --git a/scheduler.h b/speeduino/scheduler.h similarity index 94% rename from scheduler.h rename to speeduino/scheduler.h index d7c1385a..0df6c80f 100644 --- a/scheduler.h +++ b/speeduino/scheduler.h @@ -1,5 +1,5 @@ /* -This scheduler is designed to maintain 2 schedules for use by the fuel and ignition systems. +This scheduler is designed to maintain 2 schedules for use by the fuel and ignition systems. It functions by waiting for the overflow vectors from each of the timers in use to overflow, which triggers an interrupt //Technical @@ -25,20 +25,17 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd #ifndef SCHEDULER_H #define SCHEDULER_H -#ifdef __SAM3X8E__ - //Do stuff for ARM based CPUs -#else - #include - #include -#endif #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) + #include + #include + //Refer to http://svn.savannah.nongnu.org/viewvc/trunk/avr-libc/include/avr/iomxx0_1.h?root=avr-libc&view=markup #define FUEL1_COUNTER TCNT3 #define FUEL2_COUNTER TCNT3 #define FUEL3_COUNTER TCNT3 #define FUEL4_COUNTER TCNT4 - + #define IGN1_COUNTER TCNT5 #define IGN2_COUNTER TCNT5 #define IGN3_COUNTER TCNT5 @@ -49,7 +46,7 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd #define FUEL2_COMPARE OCR3B #define FUEL3_COMPARE OCR3C #define FUEL4_COMPARE OCR4B - + #define IGN1_COMPARE OCR5A #define IGN2_COMPARE OCR5B #define IGN3_COMPARE OCR5C @@ -72,7 +69,7 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd #define IGN4_TIMER_ENABLE() TIMSK4 |= (1 << OCIE4A) //Turn on the A compare unit (ie turn on the interrupt) #define IGN5_TIMER_ENABLE() TIMSK1 |= (1 << OCIE1C) //Turn on the A compare unit (ie turn on the interrupt) - #define IGN1_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5A) //Turn off this output compare unit + #define IGN1_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5A) //Turn off this output compare unit #define IGN2_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5B) //Turn off this output compare unit #define IGN3_TIMER_DISABLE() TIMSK5 &= ~(1 << OCIE5C) //Turn off this output compare unit #define IGN4_TIMER_DISABLE() TIMSK4 &= ~(1 << OCIE4A) //Turn off this output compare unit @@ -81,7 +78,7 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd #define MAX_TIMER_PERIOD 262140 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 4, as each timer tick is 4uS) #define uS_TO_TIMER_COMPARE(uS1) (uS1 >> 2) //Converts a given number of uS into the required number of timer ticks until that time has passed -#elif defined(CORE_TEENSY) +#elif defined(CORE_TEENSY) //http://shawnhymel.com/661/learning-the-teensy-lc-interrupt-service-routines/ #define FUEL1_COUNTER FTM0_CNT #define FUEL2_COUNTER FTM0_CNT @@ -128,7 +125,12 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd #define IGN5_TIMER_DISABLE() FTM1_C0SC &= ~FTM_CSC_CHIE #define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535 - #define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed. + #define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed. + +#elif defined(STM32_MCU_SERIES) + //Placeholders ONLY! + #define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535 + #define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed. #endif void initialiseSchedulers(); @@ -211,18 +213,18 @@ static inline unsigned int setQueue(volatile Schedule *queue[], Schedule *schedu queue[2] = schedule1; queue[3] = schedule1; tmpQueue[2] = schedule1->startCompare - CNT; - tmpQueue[3] = schedule1->endCompare - CNT; + tmpQueue[3] = schedule1->endCompare - CNT; } else { queue[2] = schedule2; - queue[3] = schedule2; + queue[3] = schedule2; tmpQueue[2] = schedule2->startCompare - CNT; - tmpQueue[3] = schedule2->endCompare - CNT; + tmpQueue[3] = schedule2->endCompare - CNT; } - //Sort the queues. Both queues are kept in sync. + //Sort the queues. Both queues are kept in sync. //This implementes a sorting networking based on the Bose-Nelson sorting network //See: http://pages.ripco.net/~jgamble/nw.html #define SWAP(x,y) if(tmpQueue[y] < tmpQueue[x]) { unsigned int tmp = tmpQueue[x]; tmpQueue[x] = tmpQueue[y]; tmpQueue[y] = tmp; volatile Schedule *tmpS = queue[x]; queue[x] = queue[y]; queue[y] = tmpS; } @@ -233,11 +235,11 @@ static inline unsigned int setQueue(volatile Schedule *queue[], Schedule *schedu SWAP(1, 2); //Return the next compare time in the queue - return tmpQueue[0] + CNT; //Return the + return tmpQueue[0] + CNT; //Return the } /* - * Moves all the Schedules in a queue forward one position. + * Moves all the Schedules in a queue forward one position. * The current item (0) is discarded * The final queue slot is set to nullSchedule to indicate that no action should be taken */ diff --git a/scheduler.ino b/speeduino/scheduler.ino similarity index 98% rename from scheduler.ino rename to speeduino/scheduler.ino index a958bf1b..448be324 100644 --- a/scheduler.ino +++ b/speeduino/scheduler.ino @@ -34,8 +34,8 @@ void initialiseSchedulers() TCNT4 = 0; //Reset Timer Count TIFR4 = 0x00; //Timer4 INT Flag Reg: Clear Timer Overflow Flag TCCR4A = 0x00; //Timer4 Control Reg A: Wave Gen Mode normal - TCCR4B = (1 << CS12); //Timer4 Control Reg B: aka Divisor = 256 = 122.5HzTimer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg - + TCCR4B = (1 << CS12); //Timer4 Control Reg B: aka Divisor = 256 = 122.5HzTimer Prescaler set to 256. Refer to http://www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg + #elif defined (CORE_TEENSY) && defined (__MK20DX256__) //FlexTimer 0 is used for 4 ignition and 4 injection schedules. There are 8 channels on this module, so no other timers are needed @@ -57,23 +57,23 @@ void initialiseSchedulers() FTM1_CNTIN = 0x0000; //Shouldn't be needed, but just in case FTM1_CNT = 0x0000; // Reset the count to zero FTM1_MOD = 0xFFFF; // max modulus = 65535 - + /* * Enable the clock for FTM0/1 * 00 No clock selected. Disables the FTM counter. * 01 System clock * 10 Fixed frequency clock * 11 External clock - */ + */ FTM0_SC |= FTM_SC_CLKS(0b1); FTM1_SC |= FTM_SC_CLKS(0b1); - /* - * Set Prescaler + /* + * Set Prescaler * This is the slowest that the timer can be clocked (Without used the slow timer, which is too slow). It results in ticks of 2.13333uS on the teensy 3.5: * 60000000 Hz = F_BUS * 128 * 1000000uS / F_BUS = 2.133uS - * + * * 000 = Divide by 1 * 001 Divide by 2 * 010 Divide by 4 @@ -86,38 +86,38 @@ void initialiseSchedulers() FTM0_SC |= FTM_SC_PS(0b111); FTM1_SC |= FTM_SC_PS(0b111); - //Setup the channels (See Pg 1014 of K64 DS). + //Setup the channels (See Pg 1014 of K64 DS). //FTM0_C0SC &= ~FTM_CSC_ELSB; //Probably not needed as power on state should be 0 //FTM0_C0SC &= ~FTM_CSC_ELSA; //Probably not needed as power on state should be 0 //FTM0_C0SC &= ~FTM_CSC_DMA; //Probably not needed as power on state should be 0 FTM0_C0SC &= ~FTM_CSC_MSB; //According to Pg 965 of the K64 datasheet, this should not be needed as MSB is reset to 0 upon reset, but the channel interrupt fails to fire without it FTM0_C0SC |= FTM_CSC_MSA; //Enable Compare mode FTM0_C0SC |= FTM_CSC_CHIE; //Enable channel compare interrupt - + FTM0_C1SC &= ~FTM_CSC_MSB; //According to Pg 965 of the datasheet, this should not be needed as MSB is reset to 0 upon reset, but the channel interrupt fails to fire without it FTM0_C1SC |= FTM_CSC_MSA; //Enable Compare mode FTM0_C1SC |= FTM_CSC_CHIE; //Enable channel compare interrupt - + FTM0_C2SC &= ~FTM_CSC_MSB; //According to Pg 965 of the datasheet, this should not be needed as MSB is reset to 0 upon reset, but the channel interrupt fails to fire without it FTM0_C2SC |= FTM_CSC_MSA; //Enable Compare mode FTM0_C2SC |= FTM_CSC_CHIE; //Enable channel compare interrupt - + FTM0_C3SC &= ~FTM_CSC_MSB; //According to Pg 965 of the datasheet, this should not be needed as MSB is reset to 0 upon reset, but the channel interrupt fails to fire without it FTM0_C3SC |= FTM_CSC_MSA; //Enable Compare mode FTM0_C3SC |= FTM_CSC_CHIE; //Enable channel compare interrupt - + FTM0_C4SC &= ~FTM_CSC_MSB; //According to Pg 965 of the datasheet, this should not be needed as MSB is reset to 0 upon reset, but the channel interrupt fails to fire without it FTM0_C4SC |= FTM_CSC_MSA; //Enable Compare mode FTM0_C4SC |= FTM_CSC_CHIE; //Enable channel compare interrupt - + FTM0_C5SC &= ~FTM_CSC_MSB; //According to Pg 965 of the datasheet, this should not be needed as MSB is reset to 0 upon reset, but the channel interrupt fails to fire without it FTM0_C5SC |= FTM_CSC_MSA; //Enable Compare mode FTM0_C5SC |= FTM_CSC_CHIE; //Enable channel compare interrupt - + FTM0_C6SC &= ~FTM_CSC_MSB; //According to Pg 965 of the datasheet, this should not be needed as MSB is reset to 0 upon reset, but the channel interrupt fails to fire without it FTM0_C6SC |= FTM_CSC_MSA; //Enable Compare mode FTM0_C6SC |= FTM_CSC_CHIE; //Enable channel compare interrupt - + FTM0_C7SC &= ~FTM_CSC_MSB; //According to Pg 965 of the datasheet, this should not be needed as MSB is reset to 0 upon reset, but the channel interrupt fails to fire without it FTM0_C7SC |= FTM_CSC_MSA; //Enable Compare mode FTM0_C7SC |= FTM_CSC_CHIE; //Enable channel compare interrupt @@ -130,10 +130,10 @@ void initialiseSchedulers() // enable IRQ Interrupt NVIC_ENABLE_IRQ(IRQ_FTM0); NVIC_ENABLE_IRQ(IRQ_FTM1); - + #endif - fuelSchedule1.Status = OFF; + fuelSchedule1.Status = OFF; fuelSchedule2.Status = OFF; fuelSchedule3.Status = OFF; fuelSchedule4.Status = OFF; @@ -150,15 +150,15 @@ void initialiseSchedulers() ignitionSchedule3.Status = OFF; ignitionSchedule4.Status = OFF; ignitionSchedule5.Status = OFF; - + ignitionSchedule1.schedulesSet = 0; ignitionSchedule2.schedulesSet = 0; ignitionSchedule3.schedulesSet = 0; ignitionSchedule4.schedulesSet = 0; ignitionSchedule5.schedulesSet = 0; - + } - + /* These 8 function turn a schedule on, provides the time to start and the duration and gives it callback functions. All 8 functions operate the same, just on different schedules @@ -171,7 +171,7 @@ endCallback: This function is called once the duration time has been reached void setFuelSchedule1(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) { if(fuelSchedule1.Status == RUNNING) { return; } //Check that we're not already part way through a schedule - + fuelSchedule1.StartCallback = startCallback; //Name the start callback function fuelSchedule1.EndCallback = endCallback; //Name the end callback function fuelSchedule1.duration = duration; @@ -179,7 +179,7 @@ void setFuelSchedule1(void (*startCallback)(), unsigned long timeout, unsigned l /* * The following must be enclosed in the noInterupts block to avoid contention caused if the relevant interrupts fires before the state is fully set * We need to calculate the value to reset the timer to (preload) in order to achieve the desired overflow time - * As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) + * As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) * unsigned int absoluteTimeout = TCNT3 + (timeout / 16); //Each tick occurs every 16uS with the 256 prescaler, so divide the timeout by 16 to get ther required number of ticks. Add this to the current tick count to get the target time. This will automatically overflow as required */ noInterrupts(); @@ -196,7 +196,7 @@ void setFuelSchedule1(void (*startCallback)(), unsigned long timeout, unsigned l void setFuelSchedule2(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) { if(fuelSchedule2.Status == RUNNING) { return; } //Check that we're not already part way through a schedule - + fuelSchedule2.StartCallback = startCallback; //Name the start callback function fuelSchedule2.EndCallback = endCallback; //Name the end callback function fuelSchedule2.duration = duration; @@ -204,7 +204,7 @@ void setFuelSchedule2(void (*startCallback)(), unsigned long timeout, unsigned l /* * The following must be enclosed in the noIntterupts block to avoid contention caused if the relevant interrupts fires before the state is fully set * We need to calculate the value to reset the timer to (preload) in order to achieve the desired overflow time - * As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) + * As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) * unsigned int absoluteTimeout = TCNT3 + (timeout / 16); //Each tick occurs every 16uS with the 256 prescaler, so divide the timeout by 16 to get ther required number of ticks. Add this to the current tick count to get the target time. This will automatically overflow as required */ noInterrupts(); @@ -223,11 +223,11 @@ void setFuelSchedule3(void (*startCallback)(), unsigned long timeout, unsigned l fuelSchedule3.StartCallback = startCallback; //Name the start callback function fuelSchedule3.EndCallback = endCallback; //Name the end callback function fuelSchedule3.duration = duration; - + /* * The following must be enclosed in the noIntterupts block to avoid contention caused if the relevant interrupts fires before the state is fully set * We need to calculate the value to reset the timer to (preload) in order to achieve the desired overflow time - * As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) + * As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) * unsigned int absoluteTimeout = TCNT3 + (timeout / 16); //Each tick occurs every 16uS with the 256 prescaler, so divide the timeout by 16 to get ther required number of ticks. Add this to the current tick count to get the target time. This will automatically overflow as required */ noInterrupts(); @@ -242,15 +242,15 @@ void setFuelSchedule3(void (*startCallback)(), unsigned long timeout, unsigned l void setFuelSchedule4(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) //Uses timer 4 compare B { if(fuelSchedule4.Status == RUNNING) { return; } //Check that we're not already part way through a schedule - + fuelSchedule4.StartCallback = startCallback; //Name the start callback function fuelSchedule4.EndCallback = endCallback; //Name the end callback function fuelSchedule4.duration = duration; - + /* * The following must be enclosed in the noIntterupts block to avoid contention caused if the relevant interrupts fires before the state is fully set * We need to calculate the value to reset the timer to (preload) in order to achieve the desired overflow time - * As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) + * As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) * unsigned int absoluteTimeout = TCNT3 + (timeout / 16); //Each tick occurs every 16uS with the 256 prescaler, so divide the timeout by 16 to get ther required number of ticks. Add this to the current tick count to get the target time. This will automatically overflow as required */ noInterrupts(); @@ -265,9 +265,9 @@ void setFuelSchedule4(void (*startCallback)(), unsigned long timeout, unsigned l void setFuelSchedule5(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) { if(fuelSchedule5.Status == RUNNING) { return; } //Check that we're not already part way through a schedule - + //We need to calculate the value to reset the timer to (preload) in order to achieve the desired overflow time - //As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) + //As the timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) //unsigned int absoluteTimeout = TCNT3 + (timeout / 16); //Each tick occurs every 16uS with the 256 prescaler, so divide the timeout by 16 to get ther required number of ticks. Add this to the current tick count to get the target time. This will automatically overflow as required fuelSchedule5.StartCallback = startCallback; //Name the start callback function fuelSchedule5.EndCallback = endCallback; //Name the end callback function @@ -295,8 +295,8 @@ void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsign ignitionSchedule1.StartCallback = startCallback; //Name the start callback function ignitionSchedule1.EndCallback = endCallback; //Name the start callback function ignitionSchedule1.duration = duration; - - //As the timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency)) + + //As the timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency)) if (timeout > MAX_TIMER_PERIOD) { timeout = MAX_TIMER_PERIOD - 1; } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking. noInterrupts(); @@ -311,14 +311,14 @@ void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsign void setIgnitionSchedule2(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) { if(ignitionSchedule2.Status == RUNNING) { return; } //Check that we're not already part way through a schedule - + ignitionSchedule2.StartCallback = startCallback; //Name the start callback function ignitionSchedule2.EndCallback = endCallback; //Name the start callback function ignitionSchedule2.duration = duration; - - //As the timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency)) + + //As the timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency)) if (timeout > MAX_TIMER_PERIOD) { timeout = MAX_TIMER_PERIOD - 1; } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking. - + noInterrupts(); ignitionSchedule2.startCompare = IGN2_COUNTER + uS_TO_TIMER_COMPARE(timeout); //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4) ignitionSchedule2.endCompare = ignitionSchedule2.startCompare + uS_TO_TIMER_COMPARE(duration); @@ -335,10 +335,10 @@ void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsign ignitionSchedule3.StartCallback = startCallback; //Name the start callback function ignitionSchedule3.EndCallback = endCallback; //Name the start callback function ignitionSchedule3.duration = duration; - - //The timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency)) + + //The timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency)) if (timeout > MAX_TIMER_PERIOD) { timeout = MAX_TIMER_PERIOD - 1; } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking. - + noInterrupts(); ignitionSchedule3.startCompare = IGN3_COUNTER + uS_TO_TIMER_COMPARE(timeout); //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4) ignitionSchedule3.endCompare = ignitionSchedule3.startCompare + uS_TO_TIMER_COMPARE(duration); @@ -346,7 +346,7 @@ void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsign ignitionSchedule3.Status = PENDING; //Turn this schedule on ignitionSchedule3.schedulesSet++; interrupts(); - IGN3_TIMER_ENABLE(); + IGN3_TIMER_ENABLE(); } void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) { @@ -355,7 +355,7 @@ void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsign ignitionSchedule4.StartCallback = startCallback; //Name the start callback function ignitionSchedule4.EndCallback = endCallback; //Name the start callback function ignitionSchedule4.duration = duration; - + //We need to calculate the value to reset the timer to (preload) in order to achieve the desired overflow time //The timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) //Note this is different to the other ignition timers @@ -368,7 +368,7 @@ void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsign ignitionSchedule4.Status = PENDING; //Turn this schedule on ignitionSchedule4.schedulesSet++; interrupts(); - IGN4_TIMER_ENABLE(); + IGN4_TIMER_ENABLE(); } void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)()) { @@ -377,7 +377,7 @@ void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsign ignitionSchedule5.StartCallback = startCallback; //Name the start callback function ignitionSchedule5.EndCallback = endCallback; //Name the start callback function ignitionSchedule5.duration = duration; - + //We need to calculate the value to reset the timer to (preload) in order to achieve the desired overflow time //The timer is ticking every 16uS (Time per Tick = (Prescale)*(1/Frequency)) //Note this is different to the other ignition timers @@ -390,9 +390,9 @@ void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsign ignitionSchedule5.Status = PENDING; //Turn this schedule on ignitionSchedule5.schedulesSet++; interrupts(); - IGN5_TIMER_ENABLE(); + IGN5_TIMER_ENABLE(); } - + /*******************************************************************************************************************************************************************************************************/ //This function (All 8 ISR functions that are below) gets called when either the start time or the duration time are reached //This calls the relevant callback function (startCallback or endCallback) depending on the status of the schedule. @@ -461,7 +461,7 @@ static inline void fuelSchedule3Interrupt() //Most ARM chips can simply call a f FUEL3_TIMER_DISABLE(); } } - + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this ISR(TIMER4_COMPB_vect, ISR_NOBLOCK) //fuelSchedule4 #elif defined (CORE_TEENSY) @@ -479,10 +479,10 @@ static inline void fuelSchedule4Interrupt() //Most ARM chips can simply call a f fuelSchedule4.EndCallback(); fuelSchedule4.Status = OFF; //Turn off the schedule fuelSchedule4.schedulesSet = 0; - FUEL4_TIMER_DISABLE(); + FUEL4_TIMER_DISABLE(); } } - + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this ISR(TIMER5_COMPA_vect) //ignitionSchedule1 #elif defined (CORE_TEENSY) @@ -506,7 +506,7 @@ static inline void ignitionSchedule1Interrupt() //Most ARM chips can simply call IGN1_TIMER_DISABLE(); } } - + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this ISR(TIMER5_COMPB_vect) //ignitionSchedule2 #elif defined (CORE_TEENSY) @@ -530,7 +530,7 @@ static inline void ignitionSchedule2Interrupt() //Most ARM chips can simply call IGN2_TIMER_DISABLE(); } } - + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this ISR(TIMER5_COMPC_vect) //ignitionSchedule3 #elif defined (CORE_TEENSY) @@ -554,7 +554,7 @@ static inline void ignitionSchedule3Interrupt() //Most ARM chips can simply call IGN3_TIMER_DISABLE(); } } - + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this ISR(TIMER4_COMPA_vect) //ignitionSchedule4 #elif defined (CORE_TEENSY) @@ -603,16 +603,16 @@ static inline void ignitionSchedule5Interrupt() //Most ARM chips can simply call } } - + #if defined(CORE_TEENSY) -void ftm0_isr(void) +void ftm0_isr(void) { - - if(FTM0_C0SC & FTM_CSC_CHF) { FTM0_C0SC &= ~FTM_CSC_CHF; fuelSchedule1Interrupt(); } - else if(FTM0_C1SC & FTM_CSC_CHF) { FTM0_C1SC &= ~FTM_CSC_CHF; fuelSchedule2Interrupt(); } - else if(FTM0_C2SC & FTM_CSC_CHF) { FTM0_C2SC &= ~FTM_CSC_CHF; fuelSchedule3Interrupt(); } - else if(FTM0_C3SC & FTM_CSC_CHF) { FTM0_C3SC &= ~FTM_CSC_CHF; fuelSchedule4Interrupt(); } + + if(FTM0_C0SC & FTM_CSC_CHF) { FTM0_C0SC &= ~FTM_CSC_CHF; fuelSchedule1Interrupt(); } + else if(FTM0_C1SC & FTM_CSC_CHF) { FTM0_C1SC &= ~FTM_CSC_CHF; fuelSchedule2Interrupt(); } + else if(FTM0_C2SC & FTM_CSC_CHF) { FTM0_C2SC &= ~FTM_CSC_CHF; fuelSchedule3Interrupt(); } + else if(FTM0_C3SC & FTM_CSC_CHF) { FTM0_C3SC &= ~FTM_CSC_CHF; fuelSchedule4Interrupt(); } else if(FTM0_C4SC & FTM_CSC_CHF) { FTM0_C4SC &= ~FTM_CSC_CHF; ignitionSchedule1Interrupt(); } else if(FTM0_C5SC & FTM_CSC_CHF) { FTM0_C5SC &= ~FTM_CSC_CHF; ignitionSchedule2Interrupt(); } else if(FTM0_C6SC & FTM_CSC_CHF) { FTM0_C6SC &= ~FTM_CSC_CHF; ignitionSchedule3Interrupt(); } diff --git a/sensors.h b/speeduino/sensors.h similarity index 93% rename from sensors.h rename to speeduino/sensors.h index 5b2805d5..d5ae9547 100644 --- a/sensors.h +++ b/speeduino/sensors.h @@ -1,7 +1,7 @@ #ifndef SENSORS_H #define SENSORS_H -// The following are alpha values for the ADC filters. +// The following are alpha values for the ADC filters. // Their values are from 0 to 255 with 0 being no filtering and 255 being maximum #define ADCFILTER_TPS 128 #define ADCFILTER_CLT 180 @@ -21,12 +21,12 @@ volatile int AnChannel[15]; unsigned long MAPrunningValue; //Used for tracking either the total of all MAP readings in this cycle (Event average) or the lowest value detected in this cycle (event minimum) unsigned int MAPcount; //Number of samples taken in the current MAP cycle -byte MAPcurRev = 0; //Tracks which revolution we're sampling on +byte MAPcurRev; //Tracks which revolution we're sampling on /* * Simple low pass IIR filter macro for the analog inputs * This is effectively implementing the smooth filter from http://playground.arduino.cc/Main/Smooth - * But removes the use of floats and uses 8 bits of fixed precision. + * But removes the use of floats and uses 8 bits of fixed precision. */ #define ADC_FILTER(input, alpha, prior) (((long)input * (256 - alpha) + ((long)prior * alpha))) >> 8 @@ -45,7 +45,7 @@ ISR(ADC_vect) //ADCSRA = 0x6E; // ADC disabled by clearing bit 7(ADEN) //BIT_CLEAR(ADCSRA, ADIE); - + nChannel = ADMUX & 0x07; #if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) if (nChannel==7) { ADMUX = 0x40; } @@ -57,7 +57,7 @@ ISR(ADC_vect) ADCSRB = 0x00; //clear MUX5 bit } else if (nChannel == 7) //channel 7 - { + { ADMUX = 0x40; ADCSRB = 0x08; //Set MUX5 bit } diff --git a/sensors.ino b/speeduino/sensors.ino similarity index 91% rename from sensors.ino rename to speeduino/sensors.ino index 018075b9..2587fb6f 100644 --- a/sensors.ino +++ b/speeduino/sensors.ino @@ -14,7 +14,7 @@ void initialiseADC() //the code on ISR run each conversion every 25 ADC clock, conversion run about 100KHz effectively //making a 6250 conversions/s on 16 channels and 12500 on 8 channels devices. noInterrupts(); //Interrupts should be turned off when playing with any of these registers - + ADCSRB = 0x00; //ADC Auto Trigger Source is in Free Running mode ADMUX = 0x40; //Select AREF as reference, ADC Left Adjust Result, Starting at channel 0 @@ -28,12 +28,12 @@ void initialiseADC() BIT_SET(ADCSRA,ADPS2); BIT_SET(ADCSRA,ADPS1); BIT_SET(ADCSRA,ADPS0); - + BIT_SET(ADCSRA,ADEN); //Enable ADC - + interrupts(); BIT_SET(ADCSRA,ADSC); //Start conversion - + #else //This sets the ADC (Analog to Digitial Converter) to run at 1Mhz, greatly reducing analog read times (MAP/TPS) when using the standard analogRead() function //1Mhz is the fastest speed permitted by the CPU without affecting accuracy @@ -42,22 +42,24 @@ void initialiseADC() BIT_CLEAR(ADCSRA,ADPS1); BIT_CLEAR(ADCSRA,ADPS0); #endif + MAPcurRev = 0; + MAPcount = 0; #endif } void instanteneousMAPReading() { //Instantaneous MAP readings - #if defined(ANALOG_ISR) + #if defined(ANALOG_ISR) tempReading = AnChannel[pinMAP-A0]; #else tempReading = analogRead(pinMAP); tempReading = analogRead(pinMAP); - #endif + #endif //Error checking if(tempReading >= VALID_MAP_MAX || tempReading <= VALID_MAP_MIN) { mapErrorCount += 1; } else { currentStatus.mapADC = tempReading; mapErrorCount = 0; } - + currentStatus.MAP = fastMap1023toX(currentStatus.mapADC, configPage1.mapMax); //Get the current MAP value } @@ -70,21 +72,21 @@ void readMAP() //Instantaneous MAP readings instanteneousMAPReading(); break; - + case 1: //Average of a cycle - - if (currentStatus.RPM < 1) { instanteneousMAPReading(); return; } //If the engine isn't running, fall back to instantaneous reads - - if( (MAPcurRev == currentStatus.startRevolutions) || (MAPcurRev == currentStatus.startRevolutions+1) ) //2 revolutions are looked at for 4 stroke. 2 stroke not currently catered for. + + if (currentStatus.RPM < 1 || !currentStatus.hasSync) { instanteneousMAPReading(); return; } //If the engine isn't running, fall back to instantaneous reads + + if( (MAPcurRev == currentStatus.startRevolutions) || (MAPcurRev == currentStatus.startRevolutions+1) ) //2 revolutions are looked at for 4 stroke. 2 stroke not currently catered for. { - #if defined(ANALOG_ISR) + #if defined(ANALOG_ISR) tempReading = AnChannel[pinMAP-A0]; #else tempReading = analogRead(pinMAP); tempReading = analogRead(pinMAP); #endif - + //Error check if(tempReading < VALID_MAP_MAX && tempReading > VALID_MAP_MIN) { @@ -96,6 +98,10 @@ void readMAP() else { //Reaching here means that the last cylce has completed and the MAP value should be calculated + + //Sanity check + if (MAPrunningValue == 0 || MAPcount == 0) { instanteneousMAPReading(); return; } + currentStatus.mapADC = ldiv(MAPrunningValue, MAPcount).quot; currentStatus.MAP = fastMap1023toX(currentStatus.mapADC, configPage1.mapMax); //Get the current MAP value MAPcurRev = currentStatus.startRevolutions; //Reset the current rev count @@ -103,14 +109,14 @@ void readMAP() MAPcount = 0; } break; - + case 2: //Minimum reading in a cycle if (currentStatus.RPM < 1) { instanteneousMAPReading(); return; } //If the engine isn't running, fall back to instantaneous reads - - if( (MAPcurRev == currentStatus.startRevolutions) || (MAPcurRev == currentStatus.startRevolutions+1) ) //2 revolutions are looked at for 4 stroke. 2 stroke not currently catered for. + + if( (MAPcurRev == currentStatus.startRevolutions) || (MAPcurRev == currentStatus.startRevolutions+1) ) //2 revolutions are looked at for 4 stroke. 2 stroke not currently catered for. { - #if defined(ANALOG_ISR) + #if defined(ANALOG_ISR) tempReading = AnChannel[pinMAP-A0]; #else tempReading = analogRead(pinMAP); @@ -139,24 +145,24 @@ void readTPS() { currentStatus.TPSlast = currentStatus.TPS; currentStatus.TPSlast_time = currentStatus.TPS_time; - #if defined(ANALOG_ISR) + #if defined(ANALOG_ISR) byte tempTPS = fastMap1023toX(AnChannel[pinTPS-A0], 255); //Get the current raw TPS ADC value and map it into a byte #else analogRead(pinTPS); byte tempTPS = fastMap1023toX(analogRead(pinTPS), 255); //Get the current raw TPS ADC value and map it into a byte #endif currentStatus.tpsADC = ADC_FILTER(tempTPS, ADCFILTER_TPS, currentStatus.tpsADC); - //Check that the ADC values fall within the min and max ranges (Should always be the case, but noise can cause these to fluctuate outside the defined range). + //Check that the ADC values fall within the min and max ranges (Should always be the case, but noise can cause these to fluctuate outside the defined range). byte tempADC = currentStatus.tpsADC; //The tempADC value is used in order to allow TunerStudio to recover and redo the TPS calibration if this somehow gets corrupted if (currentStatus.tpsADC < configPage1.tpsMin) { tempADC = configPage1.tpsMin; } else if(currentStatus.tpsADC > configPage1.tpsMax) { tempADC = configPage1.tpsMax; } currentStatus.TPS = map(tempADC, configPage1.tpsMin, configPage1.tpsMax, 0, 100); //Take the raw TPS ADC value and convert it into a TPS% based on the calibrated values - currentStatus.TPS_time = currentLoopTime; + currentStatus.TPS_time = currentLoopTime; } void readCLT() { - #if defined(ANALOG_ISR) + #if defined(ANALOG_ISR) tempReading = fastMap1023toX(AnChannel[pinCLT-A0], 511); //Get the current raw CLT value #else tempReading = analogRead(pinCLT); @@ -168,7 +174,7 @@ void readCLT() void readIAT() { - #if defined(ANALOG_ISR) + #if defined(ANALOG_ISR) tempReading = fastMap1023toX(AnChannel[pinIAT-A0], 511); //Get the current raw IAT value #else tempReading = analogRead(pinIAT); @@ -180,16 +186,16 @@ void readIAT() void readO2() { - #if defined(ANALOG_ISR) - tempReading = fastMap1023toX(AnChannel[pinO2-A0], 511); //Get the current O2 value. + #if defined(ANALOG_ISR) + tempReading = fastMap1023toX(AnChannel[pinO2-A0], 511); //Get the current O2 value. #else tempReading = analogRead(pinO2); - tempReading = fastMap1023toX(analogRead(pinO2), 511); //Get the current O2 value. + tempReading = fastMap1023toX(analogRead(pinO2), 511); //Get the current O2 value. #endif currentStatus.O2ADC = ADC_FILTER(tempReading, ADCFILTER_O2, currentStatus.O2ADC); currentStatus.O2 = o2CalibrationTable[currentStatus.O2ADC]; } - + /* Second O2 currently disabled as its not being used currentStatus.O2_2ADC = map(analogRead(pinO2_2), 0, 1023, 0, 511); //Get the current O2 value. currentStatus.O2_2ADC = ADC_FILTER(tempReading, ADCFILTER_O2, currentStatus.O2_2ADC); @@ -198,7 +204,7 @@ void readO2() void readBat() { - #if defined(ANALOG_ISR) + #if defined(ANALOG_ISR) tempReading = fastMap1023toX(AnChannel[pinBat-A0], 245); //Get the current raw Battery value. Permissible values are from 0v to 24.5v (245) #else tempReading = analogRead(pinBat); @@ -215,4 +221,3 @@ void flexPulse() { ++flexCounter; } - diff --git a/speeduino.ino b/speeduino/speeduino.ino similarity index 93% rename from speeduino.ino rename to speeduino/speeduino.ino index d776f4c6..83c0a567 100644 --- a/speeduino.ino +++ b/speeduino/speeduino.ino @@ -28,10 +28,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "scheduler.h" #include "comms.h" #include "cancomms.h" -#include "math.h" +#include "maths.h" #include "corrections.h" #include "timers.h" -//#include "display.h" +//#include "display.h" #include "decoders.h" #include "idle.h" #include "auxiliaries.h" @@ -79,7 +79,7 @@ unsigned long currentLoopTime; //The time the current loop started (uS) unsigned long previousLoopTime; //The time the previous loop started (uS) int CRANK_ANGLE_MAX = 720; -int CRANK_ANGLE_MAX_IGN = 360, CRANK_ANGLE_MAX_INJ = 360; // The number of crank degrees that the system track over. 360 for wasted / timed batch and 720 for sequential +int CRANK_ANGLE_MAX_IGN = 360, CRANK_ANGLE_MAX_INJ = 360; // The number of crank degrees that the system track over. 360 for wasted / timed batch and 720 for sequential //bool useSequentialFuel; // Whether sequential fueling is to be used (1 squirt per cycle) //bool useSequentialIgnition; // Whether sequential ignition is used (1 spark per cycle) @@ -130,13 +130,9 @@ int timePerDegree; byte degreesPerLoop; //The number of crank degrees that pass for each mainloop of the program volatile bool fpPrimed = false; //Tracks whether or not the fuel pump priming has been completed yet -void setup() +void setup() { - Serial.begin(115200); -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3 - if (configPage1.canEnable) { Serial3.begin(115200); } -#endif - + //Setup the dummy fuel and ignition tables //dummyFuelTable(&fuelTable); //dummyIgnitionTable(&ignitionTable); @@ -149,9 +145,14 @@ void setup() table3D_setSize(&trim2Table, 6); table3D_setSize(&trim3Table, 6); table3D_setSize(&trim4Table, 6); - + loadConfig(); - + + Serial.begin(115200); +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3 + if (configPage1.canEnable) { Serial3.begin(115200); } +#endif + //Repoint the 2D table structs to the config pages that were just loaded taeTable.valueSize = SIZE_BYTE; //Set this table to use byte values taeTable.xSize = 4; @@ -161,7 +162,7 @@ void setup() WUETable.xSize = 10; WUETable.values = configPage1.wueValues; WUETable.axisX = configPage2.wueBins; - + dwellVCorrectionTable.valueSize = SIZE_BYTE; dwellVCorrectionTable.xSize = 6; dwellVCorrectionTable.values = configPage2.dwellCorrectionValues; @@ -178,13 +179,13 @@ void setup() IATRetardTable.xSize = 6; IATRetardTable.values = configPage2.iatRetValues; IATRetardTable.axisX = configPage2.iatRetBins; - + //Setup the calibration tables loadCalibration(); //Set the pin mappings setPinMapping(configPage1.pinMapping); - //Need to check early on whether the coil charging is inverted. If this is not set straight away it can cause an unwanted spark at bootup + //Need to check early on whether the coil charging is inverted. If this is not set straight away it can cause an unwanted spark at bootup if(configPage2.IgInv == 1) { coilHIGH = LOW, coilLOW = HIGH; } else { coilHIGH = HIGH, coilLOW = LOW; } endCoil1Charge(); @@ -192,14 +193,14 @@ void setup() endCoil3Charge(); endCoil4Charge(); endCoil5Charge(); - + //Similar for injectors, make sure they're turned off closeInjector1(); closeInjector2(); closeInjector3(); closeInjector4(); closeInjector5(); - + //Set the tacho output default state digitalWrite(pinTachOut, HIGH); @@ -207,7 +208,7 @@ void setup() readMAP(); /* * The highest sea-level pressure on Earth occurs in Siberia, where the Siberian High often attains a sea-level pressure above 105 kPa; - * with record highs close to 108.5 kPa. + * with record highs close to 108.5 kPa. * The lowest measurable sea-level pressure is found at the centers of tropical cyclones and tornadoes, with a record low of 87 kPa; */ if ((currentStatus.MAP >= BARO_MIN) && (currentStatus.MAP <= BARO_MAX)) //Check if engine isn't running @@ -215,13 +216,13 @@ void setup() currentStatus.baro = currentStatus.MAP; EEPROM.update(EEPROM_LAST_BARO, currentStatus.baro); } - else + else { //Attempt to use the last known good baro reading from EEPROM if ((EEPROM.read(EEPROM_LAST_BARO) >= BARO_MIN) && (EEPROM.read(EEPROM_LAST_BARO) <= BARO_MAX)) //Make sure it's not invalid (Possible on first run etc) { currentStatus.baro = EEPROM.read(EEPROM_LAST_BARO); } //last baro correction - else { currentStatus.baro = 100; } //Final fall back position. - } + else { currentStatus.baro = 100; } //Final fall back position. + } //Perform all initialisations initialiseSchedulers(); @@ -235,29 +236,30 @@ void setup() //Check whether the flex sensor is enabled and if so, attach an interupt for it if(configPage1.flexEnabled) - { + { attachInterrupt(digitalPinToInterrupt(pinFlex), flexPulse, RISING); currentStatus.ethanolPct = 0; } - + //Once the configs have been loaded, a number of one time calculations can be completed req_fuel_uS = configPage1.reqFuel * 100; //Convert to uS and an int. This is the only variable to be used in calculations - inj_opentime_uS = configPage1.injOpen * 100; //Injector open time. Comes through as ms*10 (Eg 15.5ms = 155). - + inj_opentime_uS = configPage1.injOpen * 100; //Injector open time. Comes through as ms*10 (Eg 15.5ms = 155). + //Begin the main crank trigger interrupt pin setup //The interrupt numbering is a bit odd - See here for reference: http://arduino.cc/en/Reference/AttachInterrupt - //These assignments are based on the Arduino Mega AND VARY BETWEEN BOARDS. Please confirm the board you are using and update acordingly. + //These assignments are based on the Arduino Mega AND VARY BETWEEN BOARDS. Please confirm the board you are using and update acordingly. byte triggerInterrupt = 0; // By default, use the first interrupt byte triggerInterrupt2 = 1; currentStatus.RPM = 0; currentStatus.hasSync = false; - currentStatus.runSecs = 0; + currentStatus.runSecs = 0; currentStatus.secl = 0; + currentStatus.startRevolutions = 0; currentStatus.flatShiftingHard = false; currentStatus.launchingHard = false; triggerFilterTime = 0; //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise. This is simply a default value, the actual values are set in the setup() functinos of each decoder - - switch (pinTrigger) { + + switch (pinTrigger) { //Arduino Mega 2560 mapping case 2: triggerInterrupt = 0; break; @@ -271,9 +273,9 @@ void setup() triggerInterrupt = 3; break; case 21: triggerInterrupt = 2; break; - + } - switch (pinTrigger2) { + switch (pinTrigger2) { //Arduino Mega 2560 mapping case 2: triggerInterrupt2 = 0; break; @@ -287,14 +289,14 @@ void setup() triggerInterrupt2 = 3; break; case 21: triggerInterrupt2 = 2; break; - + } pinMode(pinTrigger, INPUT); pinMode(pinTrigger2, INPUT); pinMode(pinTrigger3, INPUT); //digitalWrite(pinTrigger, HIGH); - + //Set the trigger function based on the decoder in the config switch (configPage2.TrigPattern) { @@ -305,52 +307,52 @@ void setup() triggerSecondary = triggerSec_missingTooth; getRPM = getRPM_missingTooth; getCrankAngle = getCrankAngle_missingTooth; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) else { attachInterrupt(triggerInterrupt, trigger, FALLING); } if(configPage2.TrigEdgeSec == 0) { attachInterrupt(triggerInterrupt2, triggerSec_missingTooth, RISING); } else { attachInterrupt(triggerInterrupt2, triggerSec_missingTooth, FALLING); } break; - + case 1: // Basic distributor triggerSetup_BasicDistributor(); trigger = triggerPri_BasicDistributor; getRPM = getRPM_BasicDistributor; getCrankAngle = getCrankAngle_BasicDistributor; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) else { attachInterrupt(triggerInterrupt, trigger, FALLING); } break; - + case 2: triggerSetup_DualWheel(); trigger = triggerPri_DualWheel; getRPM = getRPM_DualWheel; getCrankAngle = getCrankAngle_DualWheel; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) else { attachInterrupt(triggerInterrupt, trigger, FALLING); } if(configPage2.TrigEdgeSec == 0) { attachInterrupt(triggerInterrupt2, triggerSec_DualWheel, RISING); } else { attachInterrupt(triggerInterrupt2, triggerSec_DualWheel, FALLING); } break; - + case 3: triggerSetup_GM7X(); trigger = triggerPri_GM7X; getRPM = getRPM_GM7X; getCrankAngle = getCrankAngle_GM7X; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) else { attachInterrupt(triggerInterrupt, trigger, FALLING); } break; - + case 4: triggerSetup_4G63(); trigger = triggerPri_4G63; getRPM = getRPM_4G63; getCrankAngle = getCrankAngle_4G63; - + //These may both need to change, not sure if(configPage2.TrigEdge == 0) { @@ -359,39 +361,39 @@ void setup() } else { - attachInterrupt(triggerInterrupt, trigger, CHANGE); // Primary trigger connects to + attachInterrupt(triggerInterrupt, trigger, CHANGE); // Primary trigger connects to attachInterrupt(triggerInterrupt2, triggerSec_4G63, FALLING); } break; - + case 5: triggerSetup_24X(); trigger = triggerPri_24X; getRPM = getRPM_24X; getCrankAngle = getCrankAngle_24X; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) - else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to + else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to attachInterrupt(triggerInterrupt2, triggerSec_24X, CHANGE); break; - + case 6: triggerSetup_Jeep2000(); trigger = triggerPri_Jeep2000; getRPM = getRPM_Jeep2000; getCrankAngle = getCrankAngle_Jeep2000; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) - else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to + else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to attachInterrupt(triggerInterrupt2, triggerSec_Jeep2000, CHANGE); break; - + case 7: triggerSetup_Audi135(); trigger = triggerPri_Audi135; getRPM = getRPM_Audi135; getCrankAngle = getCrankAngle_Audi135; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) else { attachInterrupt(triggerInterrupt, trigger, FALLING); } attachInterrupt(triggerInterrupt2, triggerSec_Audi135, RISING); @@ -402,9 +404,9 @@ void setup() trigger = triggerPri_HondaD17; getRPM = getRPM_HondaD17; getCrankAngle = getCrankAngle_HondaD17; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) - else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to + else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to attachInterrupt(triggerInterrupt2, triggerSec_HondaD17, CHANGE); break; @@ -413,7 +415,7 @@ void setup() trigger = triggerPri_Miata9905; getRPM = getRPM_Miata9905; getCrankAngle = getCrankAngle_Miata9905; - + //These may both need to change, not sure if(configPage2.TrigEdge == 0) { @@ -422,7 +424,7 @@ void setup() } else { - attachInterrupt(triggerInterrupt, trigger, FALLING); // Primary trigger connects to + attachInterrupt(triggerInterrupt, trigger, FALLING); // Primary trigger connects to attachInterrupt(triggerInterrupt2, triggerSec_Miata9905, RISING); } break; @@ -432,9 +434,9 @@ void setup() trigger = triggerPri_MazdaAU; getRPM = getRPM_MazdaAU; getCrankAngle = getCrankAngle_MazdaAU; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) - else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to + else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to attachInterrupt(triggerInterrupt2, triggerSec_MazdaAU, FALLING); break; @@ -443,33 +445,33 @@ void setup() trigger = triggerPri_DualWheel; //Is identical to the dual wheel decoder, so that is used. Same goes for the secondary below getRPM = getRPM_non360; getCrankAngle = getCrankAngle_non360; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) - else { attachInterrupt(triggerInterrupt, trigger, FALLING); } - attachInterrupt(triggerInterrupt2, triggerSec_DualWheel, FALLING); //Note the use of the Dual Wheel trigger function here. No point in having the same code in twice. + else { attachInterrupt(triggerInterrupt, trigger, FALLING); } + attachInterrupt(triggerInterrupt2, triggerSec_DualWheel, FALLING); //Note the use of the Dual Wheel trigger function here. No point in having the same code in twice. break; - + default: trigger = triggerPri_missingTooth; getRPM = getRPM_missingTooth; getCrankAngle = getCrankAngle_missingTooth; - + if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) else { attachInterrupt(triggerInterrupt, trigger, FALLING); } break; } //End crank triger interrupt attachment - + req_fuel_uS = req_fuel_uS / engineSquirtsPerCycle; //The req_fuel calculation above gives the total required fuel (At VE 100%) in the full cycle. If we're doing more than 1 squirt per cycle then we need to split the amount accordingly. (Note that in a non-sequential 4-stroke setup you cannot have less than 2 squirts as you cannot determine the stroke to make the single squirt on) - + //Initial values for loop times previousLoopTime = 0; currentLoopTime = micros(); - + mainLoopCount = 0; ignitionCount = 0; - + //Calculate the number of degrees between cylinders switch (configPage1.nCylinders) { case 1: @@ -481,11 +483,11 @@ void setup() case 2: channel1IgnDegrees = 0; - if (configPage1.engineType == EVEN_FIRE ) + if (configPage1.engineType == EVEN_FIRE ) { channel2IgnDegrees = 180; } - else { channel2IgnDegrees = configPage1.oddfire2; } + else { channel2IgnDegrees = configPage1.oddfire2; } //For alternating injection, the squirt occurs at different times for each channel if(configPage1.injLayout == INJ_SEMISEQUENTIAL) @@ -501,7 +503,7 @@ void setup() case 3: channel1IgnDegrees = 0; - if (configPage1.engineType == EVEN_FIRE ) + if (configPage1.engineType == EVEN_FIRE ) { channel2IgnDegrees = 120; channel3IgnDegrees = 240; @@ -511,7 +513,7 @@ void setup() channel2IgnDegrees = configPage1.oddfire2; channel3IgnDegrees = configPage1.oddfire3; } - + //For alternatiing injection, the squirt occurs at different times for each channel if(configPage1.injLayout == INJ_SEMISEQUENTIAL || configPage1.injLayout == INJ_PAIRED) { @@ -536,7 +538,7 @@ void setup() case 4: channel1IgnDegrees = 0; - if (configPage1.engineType == EVEN_FIRE ) + if (configPage1.engineType == EVEN_FIRE ) { channel2IgnDegrees = 180; @@ -544,7 +546,7 @@ void setup() { channel3IgnDegrees = 360; channel4IgnDegrees = 540; - + CRANK_ANGLE_MAX_IGN = 720; } } @@ -570,7 +572,7 @@ void setup() channel3InjEnabled = true; channel4InjEnabled = true; - + CRANK_ANGLE_MAX_INJ = 720; req_fuel_uS = req_fuel_uS * 2; } @@ -592,7 +594,7 @@ void setup() channel3IgnDegrees = 288; channel4IgnDegrees = 432; channel5IgnDegrees = 576; - + CRANK_ANGLE_MAX_IGN = 720; } @@ -612,7 +614,7 @@ void setup() channel3InjDegrees = 288; channel4InjDegrees = 432; channel5InjDegrees = 576; - + CRANK_ANGLE_MAX_INJ = 720; } if (!configPage1.injTiming) { channel1InjDegrees = channel2InjDegrees = channel3InjDegrees = channel4InjDegrees = channel5InjDegrees = 0; } //For simultaneous, all squirts happen at the same time @@ -627,7 +629,7 @@ void setup() channel1IgnDegrees = 0; channel2IgnDegrees = 120; channel3IgnDegrees = 240; - + //For alternatiing injection, the squirt occurs at different times for each channel /* if(configPage1.injLayout == INJ_SEMISEQUENTIAL || configPage1.injLayout == INJ_SEQUENTIAL || configPage1.injLayout == INJ_PAIRED) //No full sequential for more than 4 cylinders @@ -638,7 +640,7 @@ void setup() } */ if (!configPage1.injTiming) { channel1InjDegrees = channel2InjDegrees = channel3InjDegrees = 0; } //For simultaneous, all squirts happen at the same time - + configPage1.injLayout = 0; //This is a failsafe. We can never run semi-sequential with more than 4 cylinders channel1InjEnabled = true; @@ -650,7 +652,7 @@ void setup() channel2IgnDegrees = 90; channel3IgnDegrees = 180; channel4IgnDegrees = 270; - + //For alternatiing injection, the squirt occurs at different times for each channel /* if(configPage1.injLayout == INJ_SEMISEQUENTIAL || configPage1.injTiming == INJ_SEQUENTIAL) //No full sequential for more than 4 cylinders @@ -662,7 +664,7 @@ void setup() } */ if (!configPage1.injTiming) { channel1InjDegrees = channel2InjDegrees = channel3InjDegrees = channel4InjDegrees = 0; } //For simultaneous, all squirts happen at the same time - + configPage1.injLayout = 0; //This is a failsafe. We can never run semi-sequential with more than 4 cylinders channel1InjEnabled = true; @@ -675,7 +677,7 @@ void setup() channel2InjDegrees = 180; break; } - + switch(configPage2.sparkMode) { case IGN_MODE_WASTED: @@ -691,7 +693,7 @@ void setup() ign5StartFunction = beginCoil5Charge; ign5EndFunction = endCoil5Charge; break; - + case IGN_MODE_SINGLE: //Single channel mode. All ignition pulses are on channel 1 ign1StartFunction = beginCoil1Charge; @@ -705,7 +707,7 @@ void setup() ign5StartFunction = beginCoil1Charge; ign5EndFunction = endCoil1Charge; break; - + case IGN_MODE_WASTEDCOP: //Wasted COP mode. Ignition channels 1&3 and 2&4 are paired together //This is not a valid mode for >4 cylinders @@ -715,7 +717,7 @@ void setup() ign1EndFunction = endCoil1and3Charge; ign2StartFunction = beginCoil2and4Charge; ign2EndFunction = endCoil2and4Charge; - + ign3StartFunction = nullCallback; ign3EndFunction = nullCallback; ign4StartFunction = nullCallback; @@ -748,8 +750,8 @@ void setup() ign4EndFunction = endCoil4Charge; ign5StartFunction = beginCoil5Charge; ign5EndFunction = endCoil5Charge; - break; - + break; + default: //Wasted spark (Shouldn't ever happen anyway) ign1StartFunction = beginCoil1Charge; @@ -764,7 +766,7 @@ void setup() ign5EndFunction = endCoil5Charge; break; } - + //Begin priming the fuel pump. This is turned off in the low resolution, 1s interrupt in timers.ino digitalWrite(pinFuelPump, HIGH); fuelPumpOn = true; @@ -773,15 +775,15 @@ void setup() setFuelSchedule2(openInjector2and3, 100, (unsigned long)(configPage1.primePulse * 100), closeInjector2and3); } -void loop() +void loop() { - mainLoopCount++; + mainLoopCount++; //Check for any requets from serial. Serial operations are checked under 2 scenarios: // 1) Every 64 loops (64 Is more than fast enough for TunerStudio). This function is equivalent to ((loopCount % 64) == 1) but is considerably faster due to not using the mod or division operations // 2) If the amount of data in the serial buffer is greater than a set threhold (See globals.h). This is to avoid serial buffer overflow when large amounts of data is being sent - if ( ((mainLoopCount & 31) == 1) or (Serial.available() > SERIAL_BUFFER_THRESHOLD) ) + if ( ((mainLoopCount & 31) == 1) or (Serial.available() > SERIAL_BUFFER_THRESHOLD) ) { - if (Serial.available() > 0) + if (Serial.available() > 0) { command(); } @@ -790,9 +792,9 @@ void loop() //if Can interface is enabled then check for serial3 requests. if (configPage1.canEnable) { - if ( ((mainLoopCount & 31) == 1) or (Serial3.available() > SERIAL_BUFFER_THRESHOLD) ) + if ( ((mainLoopCount & 31) == 1) or (Serial3.available() > SERIAL_BUFFER_THRESHOLD) ) { - if (Serial3.available() > 0) + if (Serial3.available() > 0) { canCommand(); } @@ -801,19 +803,19 @@ void loop() #endif // if (configPage1.displayType && (mainLoopCount & 255) == 1) { updateDisplay();} //Displays currently disabled - + previousLoopTime = currentLoopTime; currentLoopTime = micros(); unsigned long timeToLastTooth = (currentLoopTime - toothLastToothTime); if ( (timeToLastTooth < MAX_STALL_TIME) || (toothLastToothTime > currentLoopTime) ) //Check how long ago the last tooth was seen compared to now. If it was more than half a second ago then the engine is probably stopped. toothLastToothTime can be greater than currentLoopTime if a pulse occurs between getting the lastest time and doing the comparison { currentStatus.RPM = currentStatus.longRPM = getRPM(); //Long RPM is included here - if(fuelPumpOn == false) { digitalWrite(pinFuelPump, HIGH); fuelPumpOn = true; } //Check if the fuel pump is on and turn it on if it isn't. + if(fuelPumpOn == false) { digitalWrite(pinFuelPump, HIGH); fuelPumpOn = true; } //Check if the fuel pump is on and turn it on if it isn't. } else { //We reach here if the time between teeth is too great. This VERY likely means the engine has stopped - currentStatus.RPM = 0; + currentStatus.RPM = 0; currentStatus.PW1 = 0; currentStatus.VE = 0; toothLastToothTime = 0; @@ -822,6 +824,7 @@ void loop() secCounter = 0; //Reset our seconds counter. currentStatus.startRevolutions = 0; MAPcurRev = 0; + MAPcount = 0; currentStatus.rpmDOT = 0; ignitionOn = false; fuelOn = false; @@ -829,34 +832,34 @@ void loop() fuelPumpOn = false; disableIdle(); //Turn off the idle PWM } - + //Uncomment the following for testing /* currentStatus.hasSync = true; currentStatus.RPM = 500; */ - + //***Perform sensor reads*** //----------------------------------------------------------------------------------------------------- readMAP(); - + //TPS setting to be performed every 32 loops (any faster and it can upset the TPSdot sampling time) if ((mainLoopCount & 31) == 1) { readTPS(); - + //Check for launching/flat shift (clutch) can be done around here too previousClutchTrigger = clutchTrigger; if(configPage3.launchHiLo) { clutchTrigger = digitalRead(pinLaunch); } - else { clutchTrigger = !digitalRead(pinLaunch); } + else { clutchTrigger = !digitalRead(pinLaunch); } if(previousClutchTrigger != clutchTrigger) { currentStatus.clutchEngagedRPM = currentStatus.RPM; } - - if (configPage3.launchEnabled && clutchTrigger && (currentStatus.clutchEngagedRPM < ((unsigned int)(configPage3.flatSArm) * 100)) && (currentStatus.RPM > ((unsigned int)(configPage3.lnchHardLim) * 100)) ) { currentStatus.launchingHard = true; BIT_SET(currentStatus.spark, BIT_SPARK_HLAUNCH); } //HardCut rev limit for 2-step launch control. + + if (configPage3.launchEnabled && clutchTrigger && (currentStatus.clutchEngagedRPM < ((unsigned int)(configPage3.flatSArm) * 100)) && (currentStatus.RPM > ((unsigned int)(configPage3.lnchHardLim) * 100)) ) { currentStatus.launchingHard = true; BIT_SET(currentStatus.spark, BIT_SPARK_HLAUNCH); } //HardCut rev limit for 2-step launch control. else { currentStatus.launchingHard = false; BIT_CLEAR(currentStatus.spark, BIT_SPARK_HLAUNCH); } if(configPage3.flatSEnable && clutchTrigger && (currentStatus.RPM > ((unsigned int)(configPage3.flatSArm) * 100)) && (currentStatus.RPM > currentStatus.clutchEngagedRPM) ) { currentStatus.flatShiftingHard = true; } - else { currentStatus.flatShiftingHard = false; } + else { currentStatus.flatShiftingHard = false; } //Boost cutoff is very similar to launchControl, but with a check against MAP rather than a switch if(configPage3.boostCutType && currentStatus.MAP > (configPage3.boostLimit * 2) ) //The boost limit is divided by 2 to allow a limit up to 511kPa @@ -882,7 +885,7 @@ void loop() BIT_CLEAR(currentStatus.spark, BIT_SPARK_BOOSTCUT); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_BOOSTCUT); } - + //And check whether the tooth log buffer is ready if(toothHistoryIndex > TOOTH_LOG_SIZE) { BIT_SET(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } } @@ -894,13 +897,13 @@ void loop() readCLT(); readIAT(); readO2(); - readBat(); - + readBat(); + vvtControl(); boostControl(); //Most boost tends to run at about 30Hz, so placing it here ensures a new target time is fetched frequently enough - idleControl(); //Perform any idle related actions. Even at higher frequencies, running 4x per second is sufficient. + idleControl(); //Perform any idle related actions. Even at higher frequencies, running 4x per second is sufficient. } - if(configPage4.iacAlgorithm == 4) { idleControl(); } //Run idlecontrol every loop for stepper idle. + if(configPage4.iacAlgorithm == 4) { idleControl(); } //Run idlecontrol every loop for stepper idle. //Always check for sync //Main loop runs within this clause @@ -908,7 +911,7 @@ void loop() { if(currentStatus.startRevolutions >= configPage2.StgCycles) { ignitionOn = true; fuelOn = true;} //Enable the fuel and ignition, assuming staging revolutions are complete //If it is, check is we're running or cranking - if(currentStatus.RPM > ((unsigned int)configPage2.crankRPM * 100)) //Crank RPM stored in byte as RPM / 100 + if(currentStatus.RPM > ((unsigned int)configPage2.crankRPM * 100)) //Crank RPM stored in byte as RPM / 100 { BIT_SET(currentStatus.engine, BIT_ENGINE_RUN); //Sets the engine running bit //Only need to do anything if we're transitioning from cranking to running @@ -917,31 +920,31 @@ void loop() BIT_CLEAR(currentStatus.engine, BIT_ENGINE_CRANK); //clears the engine cranking bit if(configPage2.ignBypassEnabled) { digitalWrite(pinIgnBypass, HIGH); } } - } - else + } + else { //Sets the engine cranking bit, clears the engine running bit - BIT_SET(currentStatus.engine, BIT_ENGINE_CRANK); - BIT_CLEAR(currentStatus.engine, BIT_ENGINE_RUN); + BIT_SET(currentStatus.engine, BIT_ENGINE_CRANK); + BIT_CLEAR(currentStatus.engine, BIT_ENGINE_RUN); currentStatus.runSecs = 0; //We're cranking (hopefully), so reset the engine run time to prompt ASE. if(configPage2.ignBypassEnabled) { digitalWrite(pinIgnBypass, LOW); } - } - + } + //END SETTING STATUSES //----------------------------------------------------------------------------------------------------- - + //Begin the fuel calculation //Calculate an injector pulsewidth from the VE currentStatus.corrections = correctionsFuel(); //currentStatus.corrections = 100; if (configPage1.algorithm == 0) //Check which fuelling algorithm is being used - { + { //Speed Density currentStatus.VE = get3DTableValue(&fuelTable, currentStatus.MAP, currentStatus.RPM); //Perform lookup into fuel map for RPM vs MAP value currentStatus.PW1 = PW_SD(req_fuel_uS, currentStatus.VE, currentStatus.MAP, currentStatus.corrections, inj_opentime_uS); currentStatus.advance = get3DTableValue(&ignitionTable, currentStatus.MAP, currentStatus.RPM); //As above, but for ignition advance } else - { + { //Alpha-N currentStatus.VE = get3DTableValue(&fuelTable, currentStatus.TPS, currentStatus.RPM); //Perform lookup into fuel map for RPM vs TPS value currentStatus.PW1 = PW_AN(req_fuel_uS, currentStatus.VE, currentStatus.TPS, currentStatus.corrections, inj_opentime_uS); //Calculate pulsewidth using the Alpha-N algorithm (in uS) @@ -956,7 +959,7 @@ void loop() //Adjust the advance based on IAT. If the adjustment amount is greater than the current advance, just set advance to 0 byte advanceIATadjust = table2D_getValue(&IATRetardTable, currentStatus.IAT); if (advanceIATadjust <= currentStatus.advance) { currentStatus.advance -= advanceIATadjust; } - else { currentStatus.advance = 0; } + else { currentStatus.advance = 0; } */ int injector1StartAngle = 0; @@ -972,13 +975,14 @@ void loop() //These are used for comparisons on channels above 1 where the starting angle (for injectors or ignition) can be less than a single loop time //(Don't ask why this is needed, it will break your head) int tempCrankAngle; - int tempStartAngle; - + int tempStartAngle; + //******************************************************** //How fast are we going? Need to know how long (uS) it will take to get from one tooth to the next. We then use that to estimate how far we are between the last tooth and the next one //We use a 1st Deriv accleration prediction, but only when there is an even spacing between primary sensor teeth //Any decoder that has uneven spacing has its triggerToothAngle set to 0 if(secondDerivEnabled && toothHistoryIndex >= 3 && currentStatus.RPM < 2000) //toothHistoryIndex must be greater than or equal to 3 as we need the last 3 entries. Currently this mode only runs below 3000 rpm + //if(true) { //Only recalculate deltaV if the tooth has changed since last time (DeltaV stays the same until the next tooth) //if (deltaToothCount != toothCurrentCount) @@ -1000,22 +1004,25 @@ void loop() else { angle1 = angle2 = triggerToothAngle; } } else { angle1 = angle2 = triggerToothAngle; } - + long toothDeltaV = (1000000L * angle2 / toothHistory[toothHistoryIndex]) - (1000000L * angle1 / toothHistory[toothHistoryIndex-1]); long toothDeltaT = toothHistory[toothHistoryIndex]; //long timeToLastTooth = micros() - toothLastToothTime; //Cannot be unsigned - + rpmDelta = (toothDeltaV << 10) / (6 * toothDeltaT); - } - - + } + + timePerDegree = ldiv( 166666L, (currentStatus.RPM + rpmDelta)).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) } else { - timePerDegree = ldiv( 166666L, currentStatus.RPM ).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) + long rpm_adjust = ((long)(micros() - toothOneTime) * (long)currentStatus.rpmDOT) / 1000000; //Take into account any likely accleration that has occurred since the last full revolution completed + + //timePerDegree = DIV_ROUND_CLOSEST(166666L, (currentStatus.RPM + rpm_adjust)); + timePerDegree = ldiv( 166666L, currentStatus.RPM + rpm_adjust).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) } - + //Check that the duty cycle of the chosen pulsewidth isn't too high. This is disabled at cranking if( !BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) ) { @@ -1023,16 +1030,17 @@ void loop() if (CRANK_ANGLE_MAX_INJ == 720) { pwLimit = pwLimit * 2; } //For sequential, the maximum pulse time is double (2 revolutions). Wouldn't work for 2 stroke... if (currentStatus.PW1 > pwLimit) { currentStatus.PW1 = pwLimit; } } - - + + //*********************************************************************************************** //BEGIN INJECTION TIMING //Determine next firing angles currentStatus.PW2 = currentStatus.PW3 = currentStatus.PW4 = currentStatus.PW1; // Initial state is for all pulsewidths to be the same (This gets changed below) + if(!configPage1.indInjAng) {configPage1.inj4Ang = configPage1.inj3Ang = configPage1.inj2Ang = configPage1.inj1Ang;} //Forcing all injector close angles to be the same. int PWdivTimerPerDegree = div(currentStatus.PW1, timePerDegree).quot; //How many crank degrees the calculated PW will take at the current speed injector1StartAngle = configPage1.inj1Ang - ( PWdivTimerPerDegree ); //This is a little primitive, but is based on the idea that all fuel needs to be delivered before the inlet valve opens. See http://www.extraefi.co.uk/sequential_fuel.html for more detail - if(injector1StartAngle < 0) {injector1StartAngle += CRANK_ANGLE_MAX_INJ;} - + if(injector1StartAngle < 0) {injector1StartAngle += CRANK_ANGLE_MAX_INJ;} + //Repeat the above for each cylinder switch (configPage1.nCylinders) { @@ -1044,7 +1052,7 @@ void loop() //3 cylinders case 3: injector2StartAngle = (configPage1.inj2Ang + channel2InjDegrees - ( PWdivTimerPerDegree )); - if(injector2StartAngle > CRANK_ANGLE_MAX_INJ) {injector2StartAngle -= CRANK_ANGLE_MAX_INJ;} + if(injector2StartAngle > CRANK_ANGLE_MAX_INJ) {injector2StartAngle -= CRANK_ANGLE_MAX_INJ;} injector3StartAngle = (configPage1.inj3Ang + channel3InjDegrees - ( PWdivTimerPerDegree )); if(injector3StartAngle > CRANK_ANGLE_MAX_INJ) {injector3StartAngle -= CRANK_ANGLE_MAX_INJ;} break; @@ -1066,7 +1074,7 @@ void loop() unsigned long pw2percent = 100 + (byte)get3DTableValue(&trim2Table, currentStatus.MAP, currentStatus.RPM) - OFFSET_FUELTRIM; unsigned long pw3percent = 100 + (byte)get3DTableValue(&trim3Table, currentStatus.MAP, currentStatus.RPM) - OFFSET_FUELTRIM; unsigned long pw4percent = 100 + (byte)get3DTableValue(&trim4Table, currentStatus.MAP, currentStatus.RPM) - OFFSET_FUELTRIM; - + if (pw1percent != 100) { currentStatus.PW1 = (pw1percent * currentStatus.PW1) / 100; } if (pw2percent != 100) { currentStatus.PW2 = (pw2percent * currentStatus.PW2) / 100; } if (pw3percent != 100) { currentStatus.PW3 = (pw3percent * currentStatus.PW3) / 100; } @@ -1086,16 +1094,16 @@ void loop() if(injector5StartAngle > CRANK_ANGLE_MAX_INJ) {injector5StartAngle -= CRANK_ANGLE_MAX_INJ;} break; //6 cylinders - case 6: + case 6: injector2StartAngle = (configPage1.inj2Ang + channel2InjDegrees - ( PWdivTimerPerDegree )); - if(injector2StartAngle > CRANK_ANGLE_MAX_INJ) {injector2StartAngle -= CRANK_ANGLE_MAX_INJ;} + if(injector2StartAngle > CRANK_ANGLE_MAX_INJ) {injector2StartAngle -= CRANK_ANGLE_MAX_INJ;} injector3StartAngle = (configPage1.inj3Ang + channel3InjDegrees - ( PWdivTimerPerDegree )); if(injector3StartAngle > CRANK_ANGLE_MAX_INJ) {injector3StartAngle -= CRANK_ANGLE_MAX_INJ;} break; //8 cylinders - case 8: + case 8: injector2StartAngle = (configPage1.inj2Ang + channel2InjDegrees - ( PWdivTimerPerDegree )); - if(injector2StartAngle > CRANK_ANGLE_MAX_INJ) {injector2StartAngle -= CRANK_ANGLE_MAX_INJ;} + if(injector2StartAngle > CRANK_ANGLE_MAX_INJ) {injector2StartAngle -= CRANK_ANGLE_MAX_INJ;} injector3StartAngle = (configPage1.inj3Ang + channel3InjDegrees - ( PWdivTimerPerDegree )); if(injector3StartAngle > CRANK_ANGLE_MAX_INJ) {injector3StartAngle -= CRANK_ANGLE_MAX_INJ;} injector4StartAngle = (configPage1.inj4Ang + channel4InjDegrees - ( PWdivTimerPerDegree )); @@ -1105,13 +1113,13 @@ void loop() default: break; } - + //*********************************************************************************************** //| BEGIN IGNITION CALCULATIONS BIT_CLEAR(currentStatus.spark, BIT_SPARK_HRDLIM); if (currentStatus.RPM > ((unsigned int)(configPage2.HardRevLim) * 100) ) { BIT_SET(currentStatus.spark, BIT_SPARK_HRDLIM); } //Hardcut RPM limit - - + + //Set dwell //Dwell is stored as ms * 10. ie Dwell of 4.3ms would be 43 in configPage2. This number therefore needs to be multiplied by 100 to get dwell in uS if ( BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) ) { currentStatus.dwell = (configPage2.dwellCrank * 100); } @@ -1120,12 +1128,12 @@ void loop() currentStatus.dwellCorrection = table2D_getValue(&dwellVCorrectionTable, currentStatus.battery10); if (currentStatus.dwellCorrection != 100) { currentStatus.dwell = divs100(currentStatus.dwell) * currentStatus.dwellCorrection; } int dwellAngle = (div(currentStatus.dwell, timePerDegree).quot ); //Convert the dwell time to dwell angle based on the current engine speed - + //Calculate start angle for each channel //1 cylinder (Everyone gets this) ignition1StartAngle = CRANK_ANGLE_MAX_IGN - currentStatus.advance - dwellAngle; // 360 - desired advance angle - number of degrees the dwell will take - if(ignition1StartAngle < 0) {ignition1StartAngle += CRANK_ANGLE_MAX_IGN;} - + if(ignition1StartAngle < 0) {ignition1StartAngle += CRANK_ANGLE_MAX_IGN;} + //This test for more cylinders and do the same thing switch (configPage1.nCylinders) { @@ -1137,7 +1145,7 @@ void loop() //3 cylinders case 3: ignition2StartAngle = channel2IgnDegrees + CRANK_ANGLE_MAX_IGN - currentStatus.advance - dwellAngle; - if(ignition2StartAngle > CRANK_ANGLE_MAX_IGN) {ignition2StartAngle -= CRANK_ANGLE_MAX_IGN;} + if(ignition2StartAngle > CRANK_ANGLE_MAX_IGN) {ignition2StartAngle -= CRANK_ANGLE_MAX_IGN;} ignition3StartAngle = channel3IgnDegrees + 360 - currentStatus.advance - dwellAngle; if(ignition3StartAngle > CRANK_ANGLE_MAX_IGN) {ignition3StartAngle -= CRANK_ANGLE_MAX_IGN;} break; @@ -1163,54 +1171,54 @@ void loop() ignition3StartAngle = channel3IgnDegrees + CRANK_ANGLE_MAX_IGN - currentStatus.advance - dwellAngle; if(ignition3StartAngle > CRANK_ANGLE_MAX_IGN) {ignition3StartAngle -= CRANK_ANGLE_MAX_IGN;} - + ignition4StartAngle = channel4IgnDegrees + CRANK_ANGLE_MAX - currentStatus.advance - dwellAngle; if(ignition4StartAngle > CRANK_ANGLE_MAX_IGN) {ignition4StartAngle -= CRANK_ANGLE_MAX_IGN;} - + ignition5StartAngle = channel5IgnDegrees + CRANK_ANGLE_MAX - currentStatus.advance - dwellAngle; if(ignition5StartAngle > CRANK_ANGLE_MAX_IGN) {ignition5StartAngle -= CRANK_ANGLE_MAX_IGN;} - + break; //6 cylinders case 6: ignition2StartAngle = channel2IgnDegrees + CRANK_ANGLE_MAX_IGN - currentStatus.advance - dwellAngle; - if(ignition2StartAngle > CRANK_ANGLE_MAX_IGN) {ignition2StartAngle -= CRANK_ANGLE_MAX_IGN;} + if(ignition2StartAngle > CRANK_ANGLE_MAX_IGN) {ignition2StartAngle -= CRANK_ANGLE_MAX_IGN;} ignition3StartAngle = channel3IgnDegrees + CRANK_ANGLE_MAX_IGN - currentStatus.advance - dwellAngle; if(ignition3StartAngle > CRANK_ANGLE_MAX_IGN) {ignition3StartAngle -= CRANK_ANGLE_MAX_IGN;} break; //8 cylinders case 8: ignition2StartAngle = channel2IgnDegrees + CRANK_ANGLE_MAX_IGN - currentStatus.advance - dwellAngle; - if(ignition2StartAngle > CRANK_ANGLE_MAX_IGN) {ignition2StartAngle -= CRANK_ANGLE_MAX_IGN;} + if(ignition2StartAngle > CRANK_ANGLE_MAX_IGN) {ignition2StartAngle -= CRANK_ANGLE_MAX_IGN;} ignition3StartAngle = channel3IgnDegrees + CRANK_ANGLE_MAX - currentStatus.advance - dwellAngle; if(ignition3StartAngle > CRANK_ANGLE_MAX_IGN) {ignition3StartAngle -= CRANK_ANGLE_MAX_IGN;} ignition4StartAngle = channel4IgnDegrees + CRANK_ANGLE_MAX - currentStatus.advance - dwellAngle; if(ignition4StartAngle > CRANK_ANGLE_MAX_IGN) {ignition4StartAngle -= CRANK_ANGLE_MAX_IGN;} break; - + //Will hit the default case on 1 cylinder or >8 cylinders. Do nothing in these cases default: break; } - + //*********************************************************************************************** //| BEGIN FUEL SCHEDULES //Finally calculate the time (uS) until we reach the firing angles and set the schedules //We only need to set the shcedule if we're BEFORE the open angle //This may potentially be called a number of times as we get closer and closer to the opening time - + //Determine the current crank angle int crankAngle = getCrankAngle(timePerDegree); if (crankAngle > CRANK_ANGLE_MAX_INJ ) { crankAngle -= 360; } - + if (fuelOn && currentStatus.PW1 > 0 && !BIT_CHECK(currentStatus.squirt, BIT_SQUIRT_BOOSTCUT)) { if (injector1StartAngle <= crankAngle && fuelSchedule1.schedulesSet == 0) { injector1StartAngle += CRANK_ANGLE_MAX_INJ; } if (injector1StartAngle > crankAngle) - { + { if (configPage1.injLayout == INJ_SEMISEQUENTIAL) { - setFuelSchedule1(openInjector1and4, + setFuelSchedule1(openInjector1and4, ((unsigned long)(injector1StartAngle - crankAngle) * (unsigned long)timePerDegree), (unsigned long)currentStatus.PW1, closeInjector1and4 @@ -1218,14 +1226,14 @@ void loop() } else { - setFuelSchedule1(openInjector1, + setFuelSchedule1(openInjector1, ((unsigned long)(injector1StartAngle - crankAngle) * (unsigned long)timePerDegree), (unsigned long)currentStatus.PW1, closeInjector1 ); } } - + /*----------------------------------------------------------------------------------------- | A Note on tempCrankAngle and tempStartAngle: | The use of tempCrankAngle/tempStartAngle is described below. It is then used in the same way for channels 2, 3 and 4 on both injectors and ignition @@ -1233,7 +1241,7 @@ void loop() | Eg: If cylinder 2 TDC is 180 degrees after cylinder 1 (Eg a standard 4 cylidner engine), then tempCrankAngle is 180* less than the current crank angle and | tempStartAngle is the desired open time less 180*. Thus the cylinder is being treated relative to its own TDC, regardless of its offset | - | This is done to avoid problems with very short of very long times until tempStartAngle. + | This is done to avoid problems with very short of very long times until tempStartAngle. | This will very likely need to be rewritten when sequential is enabled |------------------------------------------------------------------------------------------ */ @@ -1245,10 +1253,10 @@ void loop() if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_INJ; } if (tempStartAngle <= tempCrankAngle && fuelSchedule2.schedulesSet == 0) { tempStartAngle += CRANK_ANGLE_MAX_INJ; } if ( tempStartAngle > tempCrankAngle ) - { + { if (configPage1.injLayout == 1) { - setFuelSchedule2(openInjector2and3, + setFuelSchedule2(openInjector2and3, ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree), (unsigned long)currentStatus.PW2, closeInjector2and3 @@ -1256,7 +1264,7 @@ void loop() } else { - setFuelSchedule2(openInjector2, + setFuelSchedule2(openInjector2, ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree), (unsigned long)currentStatus.PW2, closeInjector2 @@ -1273,8 +1281,8 @@ void loop() if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_INJ; } if (tempStartAngle <= tempCrankAngle && fuelSchedule3.schedulesSet == 0) { tempStartAngle += CRANK_ANGLE_MAX_INJ; } if ( tempStartAngle > tempCrankAngle ) - { - setFuelSchedule3(openInjector3, + { + setFuelSchedule3(openInjector3, ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree), (unsigned long)currentStatus.PW3, closeInjector3 @@ -1290,8 +1298,8 @@ void loop() if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_INJ; } if (tempStartAngle <= tempCrankAngle && fuelSchedule4.schedulesSet == 0) { tempStartAngle += CRANK_ANGLE_MAX_INJ; } if ( tempStartAngle > tempCrankAngle ) - { - setFuelSchedule4(openInjector4, + { + setFuelSchedule4(openInjector4, ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree), (unsigned long)currentStatus.PW4, closeInjector4 @@ -1307,9 +1315,9 @@ void loop() if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_INJ; } if (tempStartAngle <= tempCrankAngle && fuelSchedule5.schedulesSet == 0) { tempStartAngle += CRANK_ANGLE_MAX_INJ; } if ( tempStartAngle > tempCrankAngle ) - { + { //Note the hacky use of fuel schedule 3 below - setFuelSchedule3(openInjector3and5, + setFuelSchedule3(openInjector3and5, ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree), (unsigned long)currentStatus.PW1, closeInjector3and5 @@ -1320,10 +1328,8 @@ void loop() //*********************************************************************************************** //| BEGIN IGNITION SCHEDULES //Likewise for the ignition - crankAngle = getCrankAngle(timePerDegree); //Refresh with the latest crank angle - if (crankAngle > CRANK_ANGLE_MAX_IGN ) { crankAngle -= 360; } - //fixedCrankingOverride is used to extend the dwell during cranking so that the decoder can trigger the spark upon seeing a certain tooth. Currently only available on the basic distributor and 4g63 decoders. + //fixedCrankingOverride is used to extend the dwell during cranking so that the decoder can trigger the spark upon seeing a certain tooth. Currently only available on the basic distributor and 4g63 decoders. if ( configPage2.ignCranklock && BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) { fixedCrankingOverride = currentStatus.dwell * 2; } else { fixedCrankingOverride = 0; } @@ -1331,13 +1337,25 @@ void loop() //Check for hard cut rev limit (If we're above the hardcut limit, we simply don't set a spark schedule) if(ignitionOn && !currentStatus.launchingHard && !BIT_CHECK(currentStatus.spark, BIT_SPARK_BOOSTCUT) && !BIT_CHECK(currentStatus.spark, BIT_SPARK_HRDLIM) && !currentStatus.flatShiftingHard) { - + + //Refresh the current crank angle info + //ignition1StartAngle = 335; + crankAngle = getCrankAngle(timePerDegree); //Refresh with the latest crank angle + if (crankAngle > CRANK_ANGLE_MAX_IGN ) { crankAngle -= 360; } + //if (ignition1StartAngle <= crankAngle && ignition1.schedulesSet == 0) { ignition1StartAngle += CRANK_ANGLE_MAX_IGN; } if (ignition1StartAngle > crankAngle) { - setIgnitionSchedule1(ign1StartFunction, - ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree), - currentStatus.dwell + fixedCrankingOverride, + /* + long some_time = ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree); + long newRPM = (long)(some_time * currentStatus.rpmDOT) / 1000000L; + newRPM = currentStatus.RPM + (newRPM/2); + unsigned long timePerDegree_1 = ldiv( 166666L, newRPM).quot; + unsigned long timeout = (unsigned long)(ignition1StartAngle - crankAngle) * 282UL; + */ + setIgnitionSchedule1(ign1StartFunction, + ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree), //(timeout/10), + currentStatus.dwell + fixedCrankingOverride, //((unsigned long)((unsigned long)currentStatus.dwell* currentStatus.RPM) / newRPM) + fixedCrankingOverride, ign1EndFunction ); } @@ -1348,55 +1366,55 @@ void loop() if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_IGN; } //if ( (tempStartAngle > tempCrankAngle) && ign2LastRev != startRevolutions) //if ( ign2LastRev != startRevolutions ) - { + { unsigned long ignition2StartTime = 0; if(tempStartAngle > tempCrankAngle) { ignition2StartTime = ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree); } //else if (tempStartAngle < tempCrankAngle) { ignition2StartTime = ((long)(360 - tempCrankAngle + tempStartAngle) * (long)timePerDegree); } else { ignition2StartTime = 0; } - + if(ignition2StartTime > 0) { - setIgnitionSchedule2(ign2StartFunction, + setIgnitionSchedule2(ign2StartFunction, ignition2StartTime, currentStatus.dwell + fixedCrankingOverride, ign2EndFunction ); } } - + tempCrankAngle = crankAngle - channel3IgnDegrees; if( tempCrankAngle < 0) { tempCrankAngle += CRANK_ANGLE_MAX_IGN; } tempStartAngle = ignition3StartAngle - channel3IgnDegrees; if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_IGN; } //if (tempStartAngle > tempCrankAngle) - { + { long ignition3StartTime = 0; if(tempStartAngle > tempCrankAngle) { ignition3StartTime = ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree); } //else if (tempStartAngle < tempCrankAngle) { ignition4StartTime = ((long)(360 - tempCrankAngle + tempStartAngle) * (long)timePerDegree); } else { ignition3StartTime = 0; } - + if(ignition3StartTime > 0) { - setIgnitionSchedule3(ign3StartFunction, + setIgnitionSchedule3(ign3StartFunction, ignition3StartTime, currentStatus.dwell + fixedCrankingOverride, ign3EndFunction ); } } - + tempCrankAngle = crankAngle - channel4IgnDegrees; if( tempCrankAngle < 0) { tempCrankAngle += CRANK_ANGLE_MAX_IGN; } tempStartAngle = ignition4StartAngle - channel4IgnDegrees; if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_IGN; } //if (tempStartAngle > tempCrankAngle) - { - + { + long ignition4StartTime = 0; if(tempStartAngle > tempCrankAngle) { ignition4StartTime = ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree); } //else if (tempStartAngle < tempCrankAngle) { ignition4StartTime = ((long)(360 - tempCrankAngle + tempStartAngle) * (long)timePerDegree); } else { ignition4StartTime = 0; } - + if(ignition4StartTime > 0) { - setIgnitionSchedule4(ign4StartFunction, + setIgnitionSchedule4(ign4StartFunction, ignition4StartTime, currentStatus.dwell + fixedCrankingOverride, ign4EndFunction @@ -1409,23 +1427,21 @@ void loop() tempStartAngle = ignition5StartAngle - channel5IgnDegrees; if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX_IGN; } //if (tempStartAngle > tempCrankAngle) - { - + { + long ignition5StartTime = 0; if(tempStartAngle > tempCrankAngle) { ignition5StartTime = ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree); } //else if (tempStartAngle < tempCrankAngle) { ignition4StartTime = ((long)(360 - tempCrankAngle + tempStartAngle) * (long)timePerDegree); } else { ignition5StartTime = 0; } - + if(ignition5StartTime > 0) { - setIgnitionSchedule5(ign5StartFunction, + setIgnitionSchedule5(ign5StartFunction, ignition5StartTime, currentStatus.dwell + fixedCrankingOverride, ign5EndFunction ); } } - - } - - } -} + } //Ignition schedules on + } //Has sync and RPM +} //loop() diff --git a/src/DigitalWriteFast/digitalWriteFast.h b/speeduino/src/DigitalWriteFast/digitalWriteFast.h similarity index 100% rename from src/DigitalWriteFast/digitalWriteFast.h rename to speeduino/src/DigitalWriteFast/digitalWriteFast.h diff --git a/src/PID_v1/Examples/PID_AdaptiveTunings/PID_AdaptiveTunings.ino b/speeduino/src/PID_v1/Examples/PID_AdaptiveTunings/PID_AdaptiveTunings.ino similarity index 100% rename from src/PID_v1/Examples/PID_AdaptiveTunings/PID_AdaptiveTunings.ino rename to speeduino/src/PID_v1/Examples/PID_AdaptiveTunings/PID_AdaptiveTunings.ino diff --git a/src/PID_v1/Examples/PID_Basic/PID_Basic.ino b/speeduino/src/PID_v1/Examples/PID_Basic/PID_Basic.ino similarity index 100% rename from src/PID_v1/Examples/PID_Basic/PID_Basic.ino rename to speeduino/src/PID_v1/Examples/PID_Basic/PID_Basic.ino diff --git a/src/PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino b/speeduino/src/PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino similarity index 100% rename from src/PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino rename to speeduino/src/PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino diff --git a/src/PID_v1/PID_v1.cpp b/speeduino/src/PID_v1/PID_v1.cpp similarity index 100% rename from src/PID_v1/PID_v1.cpp rename to speeduino/src/PID_v1/PID_v1.cpp diff --git a/src/PID_v1/PID_v1.h b/speeduino/src/PID_v1/PID_v1.h similarity index 100% rename from src/PID_v1/PID_v1.h rename to speeduino/src/PID_v1/PID_v1.h diff --git a/src/PID_v1/keywords.txt b/speeduino/src/PID_v1/keywords.txt similarity index 100% rename from src/PID_v1/keywords.txt rename to speeduino/src/PID_v1/keywords.txt diff --git a/storage.h b/speeduino/storage.h similarity index 100% rename from storage.h rename to speeduino/storage.h diff --git a/storage.ino b/speeduino/storage.ino similarity index 87% rename from storage.ino rename to speeduino/storage.ino index 28f7a52e..ac95ecf8 100644 --- a/storage.ino +++ b/speeduino/storage.ino @@ -19,128 +19,128 @@ void writeConfig() We only ever write to the EEPROM where the new value is different from the currently stored byte This is due to the limited write life of the EEPROM (Approximately 100,000 writes) */ - + int offset; //Create a pointer to the config page byte* pnt_configPage; - + if(EEPROM.read(0) != data_structure_version) { EEPROM.write(0,data_structure_version); } //Write the data structure version - - + + /*--------------------------------------------------- | Fuel table (See storage.h for data layout) - Page 1 - | 16x16 table itself + the 16 values along each of the axis + | 16x16 table itself + the 16 values along each of the axis -----------------------------------------------------*/ if(EEPROM.read(EEPROM_CONFIG1_XSIZE) != fuelTable.xSize) { EEPROM.write(EEPROM_CONFIG1_XSIZE, fuelTable.xSize); } //Write the VE Tables RPM dimension size if(EEPROM.read(EEPROM_CONFIG1_YSIZE) != fuelTable.ySize) { EEPROM.write(EEPROM_CONFIG1_YSIZE, fuelTable.ySize); } //Write the VE Tables MAP/TPS dimension size - for(int x=EEPROM_CONFIG1_MAP; x -#else - #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) -#endif - -Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h): - WIDTH(w), HEIGHT(h) -{ - _width = WIDTH; - _height = HEIGHT; - rotation = 0; - cursor_y = cursor_x = 0; - textsize = 1; - textcolor = textbgcolor = 0xFFFF; - wrap = true; -} - -// Draw a circle outline -void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, - uint16_t color) { - int16_t f = 1 - r; - int16_t ddF_x = 1; - int16_t ddF_y = -2 * r; - int16_t x = 0; - int16_t y = r; - - drawPixel(x0 , y0+r, color); - drawPixel(x0 , y0-r, color); - drawPixel(x0+r, y0 , color); - drawPixel(x0-r, y0 , color); - - while (x= 0) { - y--; - ddF_y += 2; - f += ddF_y; - } - x++; - ddF_x += 2; - f += ddF_x; - - drawPixel(x0 + x, y0 + y, color); - drawPixel(x0 - x, y0 + y, color); - drawPixel(x0 + x, y0 - y, color); - drawPixel(x0 - x, y0 - y, color); - drawPixel(x0 + y, y0 + x, color); - drawPixel(x0 - y, y0 + x, color); - drawPixel(x0 + y, y0 - x, color); - drawPixel(x0 - y, y0 - x, color); - } -} - -void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, - int16_t r, uint8_t cornername, uint16_t color) { - int16_t f = 1 - r; - int16_t ddF_x = 1; - int16_t ddF_y = -2 * r; - int16_t x = 0; - int16_t y = r; - - while (x= 0) { - y--; - ddF_y += 2; - f += ddF_y; - } - x++; - ddF_x += 2; - f += ddF_x; - if (cornername & 0x4) { - drawPixel(x0 + x, y0 + y, color); - drawPixel(x0 + y, y0 + x, color); - } - if (cornername & 0x2) { - drawPixel(x0 + x, y0 - y, color); - drawPixel(x0 + y, y0 - x, color); - } - if (cornername & 0x8) { - drawPixel(x0 - y, y0 + x, color); - drawPixel(x0 - x, y0 + y, color); - } - if (cornername & 0x1) { - drawPixel(x0 - y, y0 - x, color); - drawPixel(x0 - x, y0 - y, color); - } - } -} - -void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, - uint16_t color) { - drawFastVLine(x0, y0-r, 2*r+1, color); - fillCircleHelper(x0, y0, r, 3, 0, color); -} - -// Used to do circles and roundrects -void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, - uint8_t cornername, int16_t delta, uint16_t color) { - - int16_t f = 1 - r; - int16_t ddF_x = 1; - int16_t ddF_y = -2 * r; - int16_t x = 0; - int16_t y = r; - - while (x= 0) { - y--; - ddF_y += 2; - f += ddF_y; - } - x++; - ddF_x += 2; - f += ddF_x; - - if (cornername & 0x1) { - drawFastVLine(x0+x, y0-y, 2*y+1+delta, color); - drawFastVLine(x0+y, y0-x, 2*x+1+delta, color); - } - if (cornername & 0x2) { - drawFastVLine(x0-x, y0-y, 2*y+1+delta, color); - drawFastVLine(x0-y, y0-x, 2*x+1+delta, color); - } - } -} - -// Bresenham's algorithm - thx wikpedia -void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, - int16_t x1, int16_t y1, - uint16_t color) { - int16_t steep = abs(y1 - y0) > abs(x1 - x0); - if (steep) { - swap(x0, y0); - swap(x1, y1); - } - - if (x0 > x1) { - swap(x0, x1); - swap(y0, y1); - } - - int16_t dx, dy; - dx = x1 - x0; - dy = abs(y1 - y0); - - int16_t err = dx / 2; - int16_t ystep; - - if (y0 < y1) { - ystep = 1; - } else { - ystep = -1; - } - - for (; x0<=x1; x0++) { - if (steep) { - drawPixel(y0, x0, color); - } else { - drawPixel(x0, y0, color); - } - err -= dy; - if (err < 0) { - y0 += ystep; - err += dx; - } - } -} - -// Draw a rectangle -void Adafruit_GFX::drawRect(int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t color) { - drawFastHLine(x, y, w, color); - drawFastHLine(x, y+h-1, w, color); - drawFastVLine(x, y, h, color); - drawFastVLine(x+w-1, y, h, color); -} - -void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, - int16_t h, uint16_t color) { - // Update in subclasses if desired! - drawLine(x, y, x, y+h-1, color); -} - -void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, - int16_t w, uint16_t color) { - // Update in subclasses if desired! - drawLine(x, y, x+w-1, y, color); -} - -void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, - uint16_t color) { - // Update in subclasses if desired! - for (int16_t i=x; i= y1 >= y0) - if (y0 > y1) { - swap(y0, y1); swap(x0, x1); - } - if (y1 > y2) { - swap(y2, y1); swap(x2, x1); - } - if (y0 > y1) { - swap(y0, y1); swap(x0, x1); - } - - if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing - a = b = x0; - if(x1 < a) a = x1; - else if(x1 > b) b = x1; - if(x2 < a) a = x2; - else if(x2 > b) b = x2; - drawFastHLine(a, y0, b-a+1, color); - return; - } - - int16_t - dx01 = x1 - x0, - dy01 = y1 - y0, - dx02 = x2 - x0, - dy02 = y2 - y0, - dx12 = x2 - x1, - dy12 = y2 - y1; - int32_t - sa = 0, - sb = 0; - - // For upper part of triangle, find scanline crossings for segments - // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 - // is included here (and second loop will be skipped, avoiding a /0 - // error there), otherwise scanline y1 is skipped here and handled - // in the second loop...which also avoids a /0 error here if y0=y1 - // (flat-topped triangle). - if(y1 == y2) last = y1; // Include y1 scanline - else last = y1-1; // Skip it - - for(y=y0; y<=last; y++) { - a = x0 + sa / dy01; - b = x0 + sb / dy02; - sa += dx01; - sb += dx02; - /* longhand: - a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); - b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); - */ - if(a > b) swap(a,b); - drawFastHLine(a, y, b-a+1, color); - } - - // For lower part of triangle, find scanline crossings for segments - // 0-2 and 1-2. This loop is skipped if y1=y2. - sa = dx12 * (y - y1); - sb = dx02 * (y - y0); - for(; y<=y2; y++) { - a = x1 + sa / dy12; - b = x0 + sb / dy02; - sa += dx12; - sb += dx02; - /* longhand: - a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); - b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); - */ - if(a > b) swap(a,b); - drawFastHLine(a, y, b-a+1, color); - } -} - -void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, - const uint8_t *bitmap, int16_t w, int16_t h, - uint16_t color) { - - int16_t i, j, byteWidth = (w + 7) / 8; - - for(j=0; j> (i & 7))) { - drawPixel(x+i, y+j, color); - } - } - } -} - -// Draw a 1-bit color bitmap at the specified x, y position from the -// provided bitmap buffer (must be PROGMEM memory) using color as the -// foreground color and bg as the background color. -void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, - const uint8_t *bitmap, int16_t w, int16_t h, - uint16_t color, uint16_t bg) { - - int16_t i, j, byteWidth = (w + 7) / 8; - - for(j=0; j> (i & 7))) { - drawPixel(x+i, y+j, color); - } - else { - drawPixel(x+i, y+j, bg); - } - } - } -} - -//Draw XBitMap Files (*.xbm), exported from GIMP, -//Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor. -//C Array can be directly used with this function -void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y, - const uint8_t *bitmap, int16_t w, int16_t h, - uint16_t color) { - - int16_t i, j, byteWidth = (w + 7) / 8; - - for(j=0; j= 100 -size_t Adafruit_GFX::write(uint8_t c) { -#else -void Adafruit_GFX::write(uint8_t c) { -#endif - if (c == '\n') { - cursor_y += textsize*8; - cursor_x = 0; - } else if (c == '\r') { - // skip em - } else { - drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize); - cursor_x += textsize*6; - if (wrap && (cursor_x > (_width - textsize*6))) { - cursor_y += textsize*8; - cursor_x = 0; - } - } -#if ARDUINO >= 100 - return 1; -#endif -} - -// Draw a character -void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, - uint16_t color, uint16_t bg, uint8_t size) { - - if((x >= _width) || // Clip right - (y >= _height) || // Clip bottom - ((x + 6 * size - 1) < 0) || // Clip left - ((y + 8 * size - 1) < 0)) // Clip top - return; - - for (int8_t i=0; i<6; i++ ) { - uint8_t line; - if (i == 5) - line = 0x0; - else - line = pgm_read_byte(font+(c*5)+i); - for (int8_t j = 0; j<8; j++) { - if (line & 0x1) { - if (size == 1) // default size - drawPixel(x+i, y+j, color); - else { // big size - fillRect(x+(i*size), y+(j*size), size, size, color); - } - } else if (bg != color) { - if (size == 1) // default size - drawPixel(x+i, y+j, bg); - else { // big size - fillRect(x+i*size, y+j*size, size, size, bg); - } - } - line >>= 1; - } - } -} - -void Adafruit_GFX::setCursor(int16_t x, int16_t y) { - cursor_x = x; - cursor_y = y; -} - -void Adafruit_GFX::setTextSize(uint8_t s) { - textsize = (s > 0) ? s : 1; -} - -void Adafruit_GFX::setTextColor(uint16_t c) { - // For 'transparent' background, we'll set the bg - // to the same as fg instead of using a flag - textcolor = textbgcolor = c; -} - -void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) { - textcolor = c; - textbgcolor = b; -} - -void Adafruit_GFX::setTextWrap(boolean w) { - wrap = w; -} - -uint8_t Adafruit_GFX::getRotation(void) const { - return rotation; -} - -void Adafruit_GFX::setRotation(uint8_t x) { - rotation = (x & 3); - switch(rotation) { - case 0: - case 2: - _width = WIDTH; - _height = HEIGHT; - break; - case 1: - case 3: - _width = HEIGHT; - _height = WIDTH; - break; - } -} - -// Return the size of the display (per current rotation) -int16_t Adafruit_GFX::width(void) const { - return _width; -} - -int16_t Adafruit_GFX::height(void) const { - return _height; -} - -void Adafruit_GFX::invertDisplay(boolean i) { - // Do nothing, must be subclassed if supported -} - diff --git a/src/Adafruit_SSD1306/Adafruit_GFX.h b/src/Adafruit_SSD1306/Adafruit_GFX.h deleted file mode 100755 index 36396d8c..00000000 --- a/src/Adafruit_SSD1306/Adafruit_GFX.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef _ADAFRUIT_GFX_H -#define _ADAFRUIT_GFX_H - -#if ARDUINO >= 100 - #include "Arduino.h" - #include "Print.h" -#else - #include "WProgram.h" -#endif - -#define swap(a, b) { int16_t t = a; a = b; b = t; } - -class Adafruit_GFX : public Print { - - public: - - Adafruit_GFX(int16_t w, int16_t h); // Constructor - - // This MUST be defined by the subclass: - virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; - - // These MAY be overridden by the subclass to provide device-specific - // optimized code. Otherwise 'generic' versions are used. - virtual void - drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color), - drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), - drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), - drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), - fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), - fillScreen(uint16_t color), - invertDisplay(boolean i); - - // These exist only with Adafruit_GFX (no subclass overrides) - void - drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), - drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, - uint16_t color), - fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), - fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, - int16_t delta, uint16_t color), - drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, - int16_t x2, int16_t y2, uint16_t color), - fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, - int16_t x2, int16_t y2, uint16_t color), - drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, - int16_t radius, uint16_t color), - fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, - int16_t radius, uint16_t color), - drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, - int16_t w, int16_t h, uint16_t color), - drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, - int16_t w, int16_t h, uint16_t color, uint16_t bg), - drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, - int16_t w, int16_t h, uint16_t color), - drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, - uint16_t bg, uint8_t size), - setCursor(int16_t x, int16_t y), - setTextColor(uint16_t c), - setTextColor(uint16_t c, uint16_t bg), - setTextSize(uint8_t s), - setTextWrap(boolean w), - setRotation(uint8_t r); - -#if ARDUINO >= 100 - virtual size_t write(uint8_t); -#else - virtual void write(uint8_t); -#endif - - int16_t height(void) const; - int16_t width(void) const; - - uint8_t getRotation(void) const; - - protected: - const int16_t - WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes - int16_t - _width, _height, // Display w/h as modified by current rotation - cursor_x, cursor_y; - uint16_t - textcolor, textbgcolor; - uint8_t - textsize, - rotation; - boolean - wrap; // If set, 'wrap' text at right edge of display -}; - -#endif // _ADAFRUIT_GFX_H diff --git a/src/Adafruit_SSD1306/Adafruit_SSD1306.cpp b/src/Adafruit_SSD1306/Adafruit_SSD1306.cpp deleted file mode 100755 index 987dde51..00000000 --- a/src/Adafruit_SSD1306/Adafruit_SSD1306.cpp +++ /dev/null @@ -1,773 +0,0 @@ -/********************************************************************* -This is a library for our Monochrome OLEDs based on SSD1306 drivers - - Pick one up today in the adafruit shop! - ------> http://www.adafruit.com/category/63_98 - -These displays use SPI to communicate, 4 or 5 pins are required to -interface - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen below must be included in any redistribution -*********************************************************************/ - -#include -#ifndef __SAM3X8E__ - #include -#endif -#include - -#include - -#include "Adafruit_GFX.h" -#include "Adafruit_SSD1306.h" - -// the memory buffer for the LCD - -static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = { -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, -0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, -0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF, -#if (SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH > 96*16) -0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, -0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, -0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8, -0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, -0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01, -0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF, -0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00, -0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF, -0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF, -0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F, -0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, -0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03, -0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, -0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00, -0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, -0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03, -0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -#if (SSD1306_LCDHEIGHT == 64) -0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F, -0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F, -0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0, -0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, -0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E, -0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC, -0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06, -0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8, -0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, -0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C, -0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, -0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, -0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07, -0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif -#endif -}; - - - -// the most basic function, set a single pixel -void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) { - if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) - return; - - // check rotation, move pixel around if necessary - switch (getRotation()) { - case 1: - swap(x, y); - x = WIDTH - x - 1; - break; - case 2: - x = WIDTH - x - 1; - y = HEIGHT - y - 1; - break; - case 3: - swap(x, y); - y = HEIGHT - y - 1; - break; - } - - // x is which column - switch (color) - { - case WHITE: buffer[x+ (y/8)*SSD1306_LCDWIDTH] |= (1 << (y&7)); break; - case BLACK: buffer[x+ (y/8)*SSD1306_LCDWIDTH] &= ~(1 << (y&7)); break; - case INVERSE: buffer[x+ (y/8)*SSD1306_LCDWIDTH] ^= (1 << (y&7)); break; - } - -} - -Adafruit_SSD1306::Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { - cs = CS; - rst = RST; - dc = DC; - sclk = SCLK; - sid = SID; - hwSPI = false; -} - -// constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset -Adafruit_SSD1306::Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { - dc = DC; - rst = RST; - cs = CS; - hwSPI = true; -} - -// initializer for I2C - we only indicate the reset pin! -Adafruit_SSD1306::Adafruit_SSD1306(int8_t reset) : -Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { - sclk = dc = cs = sid = -1; - rst = reset; -} - - -void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { - _vccstate = vccstate; - _i2caddr = i2caddr; - - // set pin directions - if (sid != -1){ - pinMode(dc, OUTPUT); - pinMode(cs, OUTPUT); - csport = portOutputRegister(digitalPinToPort(cs)); - cspinmask = digitalPinToBitMask(cs); - dcport = portOutputRegister(digitalPinToPort(dc)); - dcpinmask = digitalPinToBitMask(dc); - if (!hwSPI){ - // set pins for software-SPI - pinMode(sid, OUTPUT); - pinMode(sclk, OUTPUT); - clkport = portOutputRegister(digitalPinToPort(sclk)); - clkpinmask = digitalPinToBitMask(sclk); - mosiport = portOutputRegister(digitalPinToPort(sid)); - mosipinmask = digitalPinToBitMask(sid); - } - if (hwSPI){ - SPI.begin (); -#ifdef __SAM3X8E__ - SPI.setClockDivider (9); // 9.3 MHz -#else - SPI.setClockDivider (SPI_CLOCK_DIV2); // 8 MHz -#endif - } - } - else - { - // I2C Init - Wire.begin(); -#ifdef __SAM3X8E__ - // Force 400 KHz I2C, rawr! (Uses pins 20, 21 for SDA, SCL) - TWI1->TWI_CWGR = 0; - TWI1->TWI_CWGR = ((VARIANT_MCK / (2 * 400000)) - 4) * 0x101; -#else - TWBR = 10; //Force 400 Khz on AVR -#endif - } - - if (reset) { - // Setup reset pin direction (used by both SPI and I2C) - pinMode(rst, OUTPUT); - digitalWrite(rst, HIGH); - // VDD (3.3V) goes high at start, lets just chill for a ms - delay(1); - // bring reset low - digitalWrite(rst, LOW); - // wait 10ms - delay(10); - // bring out of reset - digitalWrite(rst, HIGH); - // turn on VCC (9V?) - } - - #if defined SSD1306_128_32 - // Init sequence for 128x32 OLED module - ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE - ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5 - ssd1306_command(0x80); // the suggested ratio 0x80 - ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8 - ssd1306_command(0x1F); - ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3 - ssd1306_command(0x0); // no offset - ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 - ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D - if (vccstate == SSD1306_EXTERNALVCC) - { ssd1306_command(0x10); } - else - { ssd1306_command(0x14); } - ssd1306_command(SSD1306_MEMORYMODE); // 0x20 - ssd1306_command(0x00); // 0x0 act like ks0108 - ssd1306_command(SSD1306_SEGREMAP | 0x1); - ssd1306_command(SSD1306_COMSCANDEC); - ssd1306_command(SSD1306_SETCOMPINS); // 0xDA - ssd1306_command(SSD1306_SETCOMPINS_V); //Speeduino modified. Value 0x02 is used for original adafruit displays. 0x012 is used for some others //ssd1306_command(0x012);//ssd1306_command(0x02); - ssd1306_command(SSD1306_SETCONTRAST); // 0x81 - ssd1306_command(0x8F); - ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9 - if (vccstate == SSD1306_EXTERNALVCC) - { ssd1306_command(0x22); } - else - { ssd1306_command(0xF1); } - ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB - ssd1306_command(0x40); - ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4 - ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6 - #endif - - #if defined SSD1306_128_64 - // Init sequence for 128x64 OLED module - ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE - ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5 - ssd1306_command(0x80); // the suggested ratio 0x80 - ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8 - ssd1306_command(0x3F); - ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3 - ssd1306_command(0x0); // no offset - ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 - ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D - if (vccstate == SSD1306_EXTERNALVCC) - { ssd1306_command(0x10); } - else - { ssd1306_command(0x14); } - ssd1306_command(SSD1306_MEMORYMODE); // 0x20 - ssd1306_command(0x00); // 0x0 act like ks0108 - ssd1306_command(SSD1306_SEGREMAP | 0x1); - ssd1306_command(SSD1306_COMSCANDEC); - ssd1306_command(SSD1306_SETCOMPINS); // 0xDA - ssd1306_command(SSD1306_SETCOMPINS_V); - ssd1306_command(SSD1306_SETCONTRAST); // 0x81 - if (vccstate == SSD1306_EXTERNALVCC) - { ssd1306_command(0x9F); } - else - { ssd1306_command(0xCF); } - ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9 - if (vccstate == SSD1306_EXTERNALVCC) - { ssd1306_command(0x22); } - else - { ssd1306_command(0xF1); } - ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB - ssd1306_command(0x40); - ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4 - ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6 - #endif - - #if defined SSD1306_96_16 - // Init sequence for 96x16 OLED module - ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE - ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5 - ssd1306_command(0x80); // the suggested ratio 0x80 - ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8 - ssd1306_command(0x0F); - ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3 - ssd1306_command(0x00); // no offset - ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 - ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D - if (vccstate == SSD1306_EXTERNALVCC) - { ssd1306_command(0x10); } - else - { ssd1306_command(0x14); } - ssd1306_command(SSD1306_MEMORYMODE); // 0x20 - ssd1306_command(0x00); // 0x0 act like ks0108 - ssd1306_command(SSD1306_SEGREMAP | 0x1); - ssd1306_command(SSD1306_COMSCANDEC); - ssd1306_command(SSD1306_SETCOMPINS); // 0xDA - ssd1306_command(0x2); //ada x12 - ssd1306_command(SSD1306_SETCONTRAST); // 0x81 - if (vccstate == SSD1306_EXTERNALVCC) - { ssd1306_command(0x10); } - else - { ssd1306_command(0xAF); } - ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9 - if (vccstate == SSD1306_EXTERNALVCC) - { ssd1306_command(0x22); } - else - { ssd1306_command(0xF1); } - ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB - ssd1306_command(0x40); - ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4 - ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6 - #endif - - ssd1306_command(SSD1306_DISPLAYON);//--turn on oled panel -} - - -void Adafruit_SSD1306::invertDisplay(uint8_t i) { - if (i) { - ssd1306_command(SSD1306_INVERTDISPLAY); - } else { - ssd1306_command(SSD1306_NORMALDISPLAY); - } -} - -void Adafruit_SSD1306::ssd1306_command(uint8_t c) { - if (sid != -1) - { - // SPI - //digitalWrite(cs, HIGH); - *csport |= cspinmask; - //digitalWrite(dc, LOW); - *dcport &= ~dcpinmask; - //digitalWrite(cs, LOW); - *csport &= ~cspinmask; - fastSPIwrite(c); - //digitalWrite(cs, HIGH); - *csport |= cspinmask; - } - else - { - // I2C - uint8_t control = 0x00; // Co = 0, D/C = 0 - Wire.beginTransmission(_i2caddr); - WIRE_WRITE(control); - WIRE_WRITE(c); - Wire.endTransmission(); - } -} - -// startscrollright -// Activate a right handed scroll for rows start through stop -// Hint, the display is 16 rows tall. To scroll the whole display, run: -// display.scrollright(0x00, 0x0F) -void Adafruit_SSD1306::startscrollright(uint8_t start, uint8_t stop){ - ssd1306_command(SSD1306_RIGHT_HORIZONTAL_SCROLL); - ssd1306_command(0X00); - ssd1306_command(start); - ssd1306_command(0X00); - ssd1306_command(stop); - ssd1306_command(0X00); - ssd1306_command(0XFF); - ssd1306_command(SSD1306_ACTIVATE_SCROLL); -} - -// startscrollleft -// Activate a right handed scroll for rows start through stop -// Hint, the display is 16 rows tall. To scroll the whole display, run: -// display.scrollright(0x00, 0x0F) -void Adafruit_SSD1306::startscrollleft(uint8_t start, uint8_t stop){ - ssd1306_command(SSD1306_LEFT_HORIZONTAL_SCROLL); - ssd1306_command(0X00); - ssd1306_command(start); - ssd1306_command(0X00); - ssd1306_command(stop); - ssd1306_command(0X00); - ssd1306_command(0XFF); - ssd1306_command(SSD1306_ACTIVATE_SCROLL); -} - -// startscrolldiagright -// Activate a diagonal scroll for rows start through stop -// Hint, the display is 16 rows tall. To scroll the whole display, run: -// display.scrollright(0x00, 0x0F) -void Adafruit_SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){ - ssd1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA); - ssd1306_command(0X00); - ssd1306_command(SSD1306_LCDHEIGHT); - ssd1306_command(SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL); - ssd1306_command(0X00); - ssd1306_command(start); - ssd1306_command(0X00); - ssd1306_command(stop); - ssd1306_command(0X01); - ssd1306_command(SSD1306_ACTIVATE_SCROLL); -} - -// startscrolldiagleft -// Activate a diagonal scroll for rows start through stop -// Hint, the display is 16 rows tall. To scroll the whole display, run: -// display.scrollright(0x00, 0x0F) -void Adafruit_SSD1306::startscrolldiagleft(uint8_t start, uint8_t stop){ - ssd1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA); - ssd1306_command(0X00); - ssd1306_command(SSD1306_LCDHEIGHT); - ssd1306_command(SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL); - ssd1306_command(0X00); - ssd1306_command(start); - ssd1306_command(0X00); - ssd1306_command(stop); - ssd1306_command(0X01); - ssd1306_command(SSD1306_ACTIVATE_SCROLL); -} - -void Adafruit_SSD1306::stopscroll(void){ - ssd1306_command(SSD1306_DEACTIVATE_SCROLL); -} - -// Dim the display -// dim = true: display is dimmed -// dim = false: display is normal -void Adafruit_SSD1306::dim(boolean dim) { - uint8_t contrast; - - if (dim) { - contrast = 0; // Dimmed display - } else { - if (_vccstate == SSD1306_EXTERNALVCC) { - contrast = 0x9F; - } else { - contrast = 0xCF; - } - } - // the range of contrast to too small to be really useful - // it is useful to dim the display - ssd1306_command(SSD1306_SETCONTRAST); - ssd1306_command(contrast); -} - -void Adafruit_SSD1306::ssd1306_data(uint8_t c) { - if (sid != -1) - { - // SPI - //digitalWrite(cs, HIGH); - *csport |= cspinmask; - //digitalWrite(dc, HIGH); - *dcport |= dcpinmask; - //digitalWrite(cs, LOW); - *csport &= ~cspinmask; - fastSPIwrite(c); - //digitalWrite(cs, HIGH); - *csport |= cspinmask; - } - else - { - // I2C - uint8_t control = 0x40; // Co = 0, D/C = 1 - Wire.beginTransmission(_i2caddr); - WIRE_WRITE(control); - WIRE_WRITE(c); - Wire.endTransmission(); - } -} - -void Adafruit_SSD1306::display(void) { - ssd1306_command(SSD1306_COLUMNADDR); - ssd1306_command(0); // Column start address (0 = reset) - ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset) - - ssd1306_command(SSD1306_PAGEADDR); - ssd1306_command(0); // Page start address (0 = reset) - #if SSD1306_LCDHEIGHT == 64 - ssd1306_command(7); // Page end address - #endif - #if SSD1306_LCDHEIGHT == 32 - ssd1306_command(3); // Page end address - #endif - #if SSD1306_LCDHEIGHT == 16 - ssd1306_command(1); // Page end address - #endif - - if (sid != -1) - { - // SPI - *csport |= cspinmask; - *dcport |= dcpinmask; - *csport &= ~cspinmask; - - for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { - fastSPIwrite(buffer[i]); - //ssd1306_data(buffer[i]); - } - *csport |= cspinmask; - } - else - { - // save I2C bitrate -#ifndef __SAM3X8E__ - uint8_t twbrbackup = TWBR; - TWBR = 12; // upgrade to 400KHz! -#endif - - //Serial.println(TWBR, DEC); - //Serial.println(TWSR & 0x3, DEC); - - // I2C - for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { - // send a bunch of data in one xmission - Wire.beginTransmission(_i2caddr); - WIRE_WRITE(0x40); - for (uint8_t x=0; x<16; x++) { - WIRE_WRITE(buffer[i]); - i++; - } - i--; - Wire.endTransmission(); - } -#ifndef __SAM3X8E__ - TWBR = twbrbackup; -#endif - } -} - -// clear everything -void Adafruit_SSD1306::clearDisplay(void) { - memset(buffer, 0, (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8)); -} - - -inline void Adafruit_SSD1306::fastSPIwrite(uint8_t d) { - - if(hwSPI) { - (void)SPI.transfer(d); - } else { - for(uint8_t bit = 0x80; bit; bit >>= 1) { - *clkport &= ~clkpinmask; - if(d & bit) *mosiport |= mosipinmask; - else *mosiport &= ~mosipinmask; - *clkport |= clkpinmask; - } - } - //*csport |= cspinmask; -} - -void Adafruit_SSD1306::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { - boolean bSwap = false; - switch(rotation) { - case 0: - // 0 degree rotation, do nothing - break; - case 1: - // 90 degree rotation, swap x & y for rotation, then invert x - bSwap = true; - swap(x, y); - x = WIDTH - x - 1; - break; - case 2: - // 180 degree rotation, invert x and y - then shift y around for height. - x = WIDTH - x - 1; - y = HEIGHT - y - 1; - x -= (w-1); - break; - case 3: - // 270 degree rotation, swap x & y for rotation, then invert y and adjust y for w (not to become h) - bSwap = true; - swap(x, y); - y = HEIGHT - y - 1; - y -= (w-1); - break; - } - - if(bSwap) { - drawFastVLineInternal(x, y, w, color); - } else { - drawFastHLineInternal(x, y, w, color); - } -} - -void Adafruit_SSD1306::drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) { - // Do bounds/limit checks - if(y < 0 || y >= HEIGHT) { return; } - - // make sure we don't try to draw below 0 - if(x < 0) { - w += x; - x = 0; - } - - // make sure we don't go off the edge of the display - if( (x + w) > WIDTH) { - w = (WIDTH - x); - } - - // if our width is now negative, punt - if(w <= 0) { return; } - - // set up the pointer for movement through the buffer - register uint8_t *pBuf = buffer; - // adjust the buffer pointer for the current row - pBuf += ((y/8) * SSD1306_LCDWIDTH); - // and offset x columns in - pBuf += x; - - register uint8_t mask = 1 << (y&7); - - switch (color) - { - case WHITE: while(w--) { *pBuf++ |= mask; }; break; - case BLACK: mask = ~mask; while(w--) { *pBuf++ &= mask; }; break; - case INVERSE: while(w--) { *pBuf++ ^= mask; }; break; - } -} - -void Adafruit_SSD1306::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { - bool bSwap = false; - switch(rotation) { - case 0: - break; - case 1: - // 90 degree rotation, swap x & y for rotation, then invert x and adjust x for h (now to become w) - bSwap = true; - swap(x, y); - x = WIDTH - x - 1; - x -= (h-1); - break; - case 2: - // 180 degree rotation, invert x and y - then shift y around for height. - x = WIDTH - x - 1; - y = HEIGHT - y - 1; - y -= (h-1); - break; - case 3: - // 270 degree rotation, swap x & y for rotation, then invert y - bSwap = true; - swap(x, y); - y = HEIGHT - y - 1; - break; - } - - if(bSwap) { - drawFastHLineInternal(x, y, h, color); - } else { - drawFastVLineInternal(x, y, h, color); - } -} - - -void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h, uint16_t color) { - - // do nothing if we're off the left or right side of the screen - if(x < 0 || x >= WIDTH) { return; } - - // make sure we don't try to draw below 0 - if(__y < 0) { - // __y is negative, this will subtract enough from __h to account for __y being 0 - __h += __y; - __y = 0; - - } - - // make sure we don't go past the height of the display - if( (__y + __h) > HEIGHT) { - __h = (HEIGHT - __y); - } - - // if our height is now negative, punt - if(__h <= 0) { - return; - } - - // this display doesn't need ints for coordinates, use local byte registers for faster juggling - register uint8_t y = __y; - register uint8_t h = __h; - - - // set up the pointer for fast movement through the buffer - register uint8_t *pBuf = buffer; - // adjust the buffer pointer for the current row - pBuf += ((y/8) * SSD1306_LCDWIDTH); - // and offset x columns in - pBuf += x; - - // do the first partial byte, if necessary - this requires some masking - register uint8_t mod = (y&7); - if(mod) { - // mask off the high n bits we want to set - mod = 8-mod; - - // note - lookup table results in a nearly 10% performance improvement in fill* functions - // register uint8_t mask = ~(0xFF >> (mod)); - static uint8_t premask[8] = {0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE }; - register uint8_t mask = premask[mod]; - - // adjust the mask if we're not going to reach the end of this byte - if( h < mod) { - mask &= (0XFF >> (mod-h)); - } - - switch (color) - { - case WHITE: *pBuf |= mask; break; - case BLACK: *pBuf &= ~mask; break; - case INVERSE: *pBuf ^= mask; break; - } - - // fast exit if we're done here! - if(h= 8) { - if (color == INVERSE) { // separate copy of the code so we don't impact performance of the black/white write version with an extra comparison per loop - do { - *pBuf=~(*pBuf); - - // adjust the buffer forward 8 rows worth of data - pBuf += SSD1306_LCDWIDTH; - - // adjust h & y (there's got to be a faster way for me to do this, but this should still help a fair bit for now) - h -= 8; - } while(h >= 8); - } - else { - // store a local value to work with - register uint8_t val = (color == WHITE) ? 255 : 0; - - do { - // write our value in - *pBuf = val; - - // adjust the buffer forward 8 rows worth of data - pBuf += SSD1306_LCDWIDTH; - - // adjust h & y (there's got to be a faster way for me to do this, but this should still help a fair bit for now) - h -= 8; - } while(h >= 8); - } - } - - // now do the final partial byte, if necessary - if(h) { - mod = h & 7; - // this time we want to mask the low bits of the byte, vs the high bits we did above - // register uint8_t mask = (1 << mod) - 1; - // note - lookup table results in a nearly 10% performance improvement in fill* functions - static uint8_t postmask[8] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F }; - register uint8_t mask = postmask[mod]; - switch (color) - { - case WHITE: *pBuf |= mask; break; - case BLACK: *pBuf &= ~mask; break; - case INVERSE: *pBuf ^= mask; break; - } - } -} diff --git a/src/Adafruit_SSD1306/Adafruit_SSD1306.h b/src/Adafruit_SSD1306/Adafruit_SSD1306.h deleted file mode 100755 index 15d83d64..00000000 --- a/src/Adafruit_SSD1306/Adafruit_SSD1306.h +++ /dev/null @@ -1,172 +0,0 @@ -/********************************************************************* -This is a library for our Monochrome OLEDs based on SSD1306 drivers - - Pick one up today in the adafruit shop! - ------> http://www.adafruit.com/category/63_98 - -These displays use SPI to communicate, 4 or 5 pins are required to -interface - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen must be included in any redistribution -*********************************************************************/ - -#if ARDUINO >= 100 - #include "Arduino.h" - #define WIRE_WRITE Wire.write -#else - #include "WProgram.h" - #define WIRE_WRITE Wire.send -#endif - -#ifdef __SAM3X8E__ - typedef volatile RwReg PortReg; - typedef uint32_t PortMask; -#else - typedef volatile uint8_t PortReg; - typedef uint8_t PortMask; -#endif - -#include -#include "Adafruit_GFX.h" - -#define BLACK 0 -#define WHITE 1 -#define INVERSE 2 - -#define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D -// Address for 128x32 is 0x3C -// Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded) - -/*========================================================================= - SSD1306 Displays - ----------------------------------------------------------------------- - The driver is used in multiple displays (128x64, 128x32, etc.). - Select the appropriate display below to create an appropriately - sized framebuffer, etc. - - SSD1306_128_64 128x64 pixel display - - SSD1306_128_32 128x32 pixel display - - SSD1306_96_16 - - -----------------------------------------------------------------------*/ - // #define SSD1306_128_64 - #define SSD1306_128_32 - // #define SSD1306_96_16 -/*=========================================================================*/ - -#if defined SSD1306_128_64 && defined SSD1306_128_32 - #error "Only one SSD1306 display can be specified at once in SSD1306.h" -#endif -#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16 - #error "At least one SSD1306 display must be specified in SSD1306.h" -#endif - -#if defined SSD1306_128_64 - #define SSD1306_LCDWIDTH 128 - #define SSD1306_LCDHEIGHT 64 -#endif -#if defined SSD1306_128_32 - #define SSD1306_LCDWIDTH 128 - #define SSD1306_LCDHEIGHT 32 -#endif -#if defined SSD1306_96_16 - #define SSD1306_LCDWIDTH 96 - #define SSD1306_LCDHEIGHT 16 -#endif - -#define SSD1306_SETCONTRAST 0x81 -#define SSD1306_DISPLAYALLON_RESUME 0xA4 -#define SSD1306_DISPLAYALLON 0xA5 -#define SSD1306_NORMALDISPLAY 0xA6 -#define SSD1306_INVERTDISPLAY 0xA7 -#define SSD1306_DISPLAYOFF 0xAE -#define SSD1306_DISPLAYON 0xAF - -#define SSD1306_SETDISPLAYOFFSET 0xD3 -#define SSD1306_SETCOMPINS 0xDA - -#define SSD1306_SETVCOMDETECT 0xDB - -#define SSD1306_SETDISPLAYCLOCKDIV 0xD5 -#define SSD1306_SETPRECHARGE 0xD9 - -#define SSD1306_SETMULTIPLEX 0xA8 - -#define SSD1306_SETLOWCOLUMN 0x00 -#define SSD1306_SETHIGHCOLUMN 0x10 - -#define SSD1306_SETSTARTLINE 0x40 - -#define SSD1306_MEMORYMODE 0x20 -#define SSD1306_COLUMNADDR 0x21 -#define SSD1306_PAGEADDR 0x22 - -#define SSD1306_COMSCANINC 0xC0 -#define SSD1306_COMSCANDEC 0xC8 - -#define SSD1306_SEGREMAP 0xA0 - -#define SSD1306_CHARGEPUMP 0x8D - -#define SSD1306_EXTERNALVCC 0x1 -#define SSD1306_SWITCHCAPVCC 0x2 - -// Scrolling #defines -#define SSD1306_ACTIVATE_SCROLL 0x2F -#define SSD1306_DEACTIVATE_SCROLL 0x2E -#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 -#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 -#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 -#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 -#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A - -class Adafruit_SSD1306 : public Adafruit_GFX { - public: - Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS); - Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS); - Adafruit_SSD1306(int8_t RST); - - void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool reset=true); - void ssd1306_command(uint8_t c); - void ssd1306_data(uint8_t c); - - void clearDisplay(void); - void invertDisplay(uint8_t i); - void display(); - - void startscrollright(uint8_t start, uint8_t stop); - void startscrollleft(uint8_t start, uint8_t stop); - - void startscrolldiagright(uint8_t start, uint8_t stop); - void startscrolldiagleft(uint8_t start, uint8_t stop); - void stopscroll(void); - - void dim(boolean dim); - - void drawPixel(int16_t x, int16_t y, uint16_t color); - - virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); - virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); - - byte SSD1306_SETCOMPINS_V; - - private: - int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs; - void fastSPIwrite(uint8_t c); - - boolean hwSPI; - PortReg *mosiport, *clkport, *csport, *dcport; - PortMask mosipinmask, clkpinmask, cspinmask, dcpinmask; - - inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline)); - inline void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) __attribute__((always_inline)); - -}; diff --git a/src/Adafruit_SSD1306/README.txt b/src/Adafruit_SSD1306/README.txt deleted file mode 100755 index 420cc153..00000000 --- a/src/Adafruit_SSD1306/README.txt +++ /dev/null @@ -1,24 +0,0 @@ -This is a library for our Monochrome OLEDs based on SSD1306 drivers - - Pick one up today in the adafruit shop! - ------> http://www.adafruit.com/category/63_98 - -These displays use SPI to communicate, 4 or 5 pins are required to -interface - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -Scrolling code contributed by Michael Gregg -BSD license, check license.txt for more information -All text above must be included in any redistribution - -To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1306. Check that the Adafruit_SSD1306 folder contains Adafruit_SSD1306.cpp and Adafruit_SSD1306.h - -Place the Adafruit_SSD1306 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. - -You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from -https://github.com/adafruit/Adafruit-GFX-Library -and download/install that library as well \ No newline at end of file diff --git a/src/Adafruit_SSD1306/examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino b/src/Adafruit_SSD1306/examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino deleted file mode 100755 index e82ebc10..00000000 --- a/src/Adafruit_SSD1306/examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino +++ /dev/null @@ -1,357 +0,0 @@ -/********************************************************************* -This is an example for our Monochrome OLEDs based on SSD1306 drivers - - Pick one up today in the adafruit shop! - ------> http://www.adafruit.com/category/63_98 - -This example is for a 128x32 size display using I2C to communicate -3 pins are required to interface (2 I2C and one reset) - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen must be included in any redistribution -*********************************************************************/ - -#include -#include -#include -#include - -#define OLED_RESET 4 -Adafruit_SSD1306 display(OLED_RESET); - -#define NUMFLAKES 10 -#define XPOS 0 -#define YPOS 1 -#define DELTAY 2 - - -#define LOGO16_GLCD_HEIGHT 16 -#define LOGO16_GLCD_WIDTH 16 -static const unsigned char PROGMEM logo16_glcd_bmp[] = -{ B00000000, B11000000, - B00000001, B11000000, - B00000001, B11000000, - B00000011, B11100000, - B11110011, B11100000, - B11111110, B11111000, - B01111110, B11111111, - B00110011, B10011111, - B00011111, B11111100, - B00001101, B01110000, - B00011011, B10100000, - B00111111, B11100000, - B00111111, B11110000, - B01111100, B11110000, - B01110000, B01110000, - B00000000, B00110000 }; - -#if (SSD1306_LCDHEIGHT != 32) -#error("Height incorrect, please fix Adafruit_SSD1306.h!"); -#endif - -void setup() { - Serial.begin(9600); - - // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) - // init done - - // Show image buffer on the display hardware. - // Since the buffer is intialized with an Adafruit splashscreen - // internally, this will display the splashscreen. - display.display(); - delay(2000); - - // Clear the buffer. - display.clearDisplay(); - - // draw a single pixel - display.drawPixel(10, 10, WHITE); - // Show the display buffer on the hardware. - // NOTE: You _must_ call display after making any drawing commands - // to make them visible on the display hardware! - display.display(); - delay(2000); - display.clearDisplay(); - - // draw many lines - testdrawline(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw rectangles - testdrawrect(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw multiple rectangles - testfillrect(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw mulitple circles - testdrawcircle(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw a white circle, 10 pixel radius - display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); - display.display(); - delay(2000); - display.clearDisplay(); - - testdrawroundrect(); - delay(2000); - display.clearDisplay(); - - testfillroundrect(); - delay(2000); - display.clearDisplay(); - - testdrawtriangle(); - delay(2000); - display.clearDisplay(); - - testfilltriangle(); - delay(2000); - display.clearDisplay(); - - // draw the first ~12 characters in the font - testdrawchar(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw scrolling text - testscrolltext(); - delay(2000); - display.clearDisplay(); - - // text display tests - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - display.println("Hello, world!"); - display.setTextColor(BLACK, WHITE); // 'inverted' text - display.println(3.141592); - display.setTextSize(2); - display.setTextColor(WHITE); - display.print("0x"); display.println(0xDEADBEEF, HEX); - display.display(); - delay(2000); - - // miniature bitmap display - display.clearDisplay(); - display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); - display.display(); - - // invert the display - display.invertDisplay(true); - delay(1000); - display.invertDisplay(false); - delay(1000); - - // draw a bitmap icon and 'animate' movement - testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); -} - - -void loop() { - -} - - -void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { - uint8_t icons[NUMFLAKES][3]; - - // initialize - for (uint8_t f=0; f< NUMFLAKES; f++) { - icons[f][XPOS] = random(display.width()); - icons[f][YPOS] = 0; - icons[f][DELTAY] = random(5) + 1; - - Serial.print("x: "); - Serial.print(icons[f][XPOS], DEC); - Serial.print(" y: "); - Serial.print(icons[f][YPOS], DEC); - Serial.print(" dy: "); - Serial.println(icons[f][DELTAY], DEC); - } - - while (1) { - // draw each icon - for (uint8_t f=0; f< NUMFLAKES; f++) { - display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); - } - display.display(); - delay(200); - - // then erase it + move it - for (uint8_t f=0; f< NUMFLAKES; f++) { - display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK); - // move it - icons[f][YPOS] += icons[f][DELTAY]; - // if its gone, reinit - if (icons[f][YPOS] > display.height()) { - icons[f][XPOS] = random(display.width()); - icons[f][YPOS] = 0; - icons[f][DELTAY] = random(5) + 1; - } - } - } -} - - -void testdrawchar(void) { - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - - for (uint8_t i=0; i < 168; i++) { - if (i == '\n') continue; - display.write(i); - if ((i > 0) && (i % 21 == 0)) - display.println(); - } - display.display(); -} - -void testdrawcircle(void) { - for (int16_t i=0; i0; i-=5) { - display.fillTriangle(display.width()/2, display.height()/2-i, - display.width()/2-i, display.height()/2+i, - display.width()/2+i, display.height()/2+i, WHITE); - if (color == WHITE) color = BLACK; - else color = WHITE; - display.display(); - } -} - -void testdrawroundrect(void) { - for (int16_t i=0; i=0; i-=4) { - display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); - display.display(); - } - delay(250); - - display.clearDisplay(); - for (int16_t i=display.width()-1; i>=0; i-=4) { - display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); - display.display(); - } - for (int16_t i=display.height()-1; i>=0; i-=4) { - display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); - display.display(); - } - delay(250); - - display.clearDisplay(); - for (int16_t i=0; i http://www.adafruit.com/category/63_98 - -This example is for a 128x32 size display using SPI to communicate -4 or 5 pins are required to interface - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen must be included in any redistribution -*********************************************************************/ - -#include -#include -#include -#include - -// If using software SPI (the default case): -#define OLED_MOSI 9 -#define OLED_CLK 10 -#define OLED_DC 11 -#define OLED_CS 12 -#define OLED_RESET 13 -Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); - -/* Uncomment this block to use hardware SPI -#define OLED_DC 6 -#define OLED_CS 7 -#define OLED_RESET 8 -Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS); -*/ - -#define NUMFLAKES 10 -#define XPOS 0 -#define YPOS 1 -#define DELTAY 2 - -#define LOGO16_GLCD_HEIGHT 16 -#define LOGO16_GLCD_WIDTH 16 -static const unsigned char PROGMEM logo16_glcd_bmp[] = -{ B00000000, B11000000, - B00000001, B11000000, - B00000001, B11000000, - B00000011, B11100000, - B11110011, B11100000, - B11111110, B11111000, - B01111110, B11111111, - B00110011, B10011111, - B00011111, B11111100, - B00001101, B01110000, - B00011011, B10100000, - B00111111, B11100000, - B00111111, B11110000, - B01111100, B11110000, - B01110000, B01110000, - B00000000, B00110000 }; - -#if (SSD1306_LCDHEIGHT != 32) -#error("Height incorrect, please fix Adafruit_SSD1306.h!"); -#endif - -void setup() { - Serial.begin(9600); - - // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) - display.begin(SSD1306_SWITCHCAPVCC); - // init done - - // Show image buffer on the display hardware. - // Since the buffer is intialized with an Adafruit splashscreen - // internally, this will display the splashscreen. - display.display(); - delay(2000); - - // Clear the buffer. - display.clearDisplay(); - - // draw a single pixel - display.drawPixel(10, 10, WHITE); - // Show the display buffer on the hardware. - // NOTE: You _must_ call display after making any drawing commands - // to make them visible on the display hardware! - display.display(); - delay(2000); - display.clearDisplay(); - - // draw many lines - testdrawline(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw rectangles - testdrawrect(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw multiple rectangles - testfillrect(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw mulitple circles - testdrawcircle(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw a white circle, 10 pixel radius - display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); - display.display(); - delay(2000); - display.clearDisplay(); - - testdrawroundrect(); - delay(2000); - display.clearDisplay(); - - testfillroundrect(); - delay(2000); - display.clearDisplay(); - - testdrawtriangle(); - delay(2000); - display.clearDisplay(); - - testfilltriangle(); - delay(2000); - display.clearDisplay(); - - // draw the first ~12 characters in the font - testdrawchar(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw scrolling text - testscrolltext(); - delay(2000); - display.clearDisplay(); - - // text display tests - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - display.println("Hello, world!"); - display.setTextColor(BLACK, WHITE); // 'inverted' text - display.println(3.141592); - display.setTextSize(2); - display.setTextColor(WHITE); - display.print("0x"); display.println(0xDEADBEEF, HEX); - display.display(); - delay(2000); - - // miniature bitmap display - display.clearDisplay(); - display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); - display.display(); - - // invert the display - display.invertDisplay(true); - delay(1000); - display.invertDisplay(false); - delay(1000); - - // draw a bitmap icon and 'animate' movement - testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); -} - - -void loop() { - -} - - -void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { - uint8_t icons[NUMFLAKES][3]; - - // initialize - for (uint8_t f=0; f< NUMFLAKES; f++) { - icons[f][XPOS] = random(display.width()); - icons[f][YPOS] = 0; - icons[f][DELTAY] = random(5) + 1; - - Serial.print("x: "); - Serial.print(icons[f][XPOS], DEC); - Serial.print(" y: "); - Serial.print(icons[f][YPOS], DEC); - Serial.print(" dy: "); - Serial.println(icons[f][DELTAY], DEC); - } - - while (1) { - // draw each icon - for (uint8_t f=0; f< NUMFLAKES; f++) { - display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); - } - display.display(); - delay(200); - - // then erase it + move it - for (uint8_t f=0; f< NUMFLAKES; f++) { - display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK); - // move it - icons[f][YPOS] += icons[f][DELTAY]; - // if its gone, reinit - if (icons[f][YPOS] > display.height()) { - icons[f][XPOS] = random(display.width()); - icons[f][YPOS] = 0; - icons[f][DELTAY] = random(5) + 1; - } - } - } -} - - -void testdrawchar(void) { - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - - for (uint8_t i=0; i < 168; i++) { - if (i == '\n') continue; - display.write(i); - if ((i > 0) && (i % 21 == 0)) - display.println(); - } - display.display(); -} - -void testdrawcircle(void) { - for (int16_t i=0; i0; i-=5) { - display.fillTriangle(display.width()/2, display.height()/2-i, - display.width()/2-i, display.height()/2+i, - display.width()/2+i, display.height()/2+i, WHITE); - if (color == WHITE) color = BLACK; - else color = WHITE; - display.display(); - } -} - -void testdrawroundrect(void) { - for (int16_t i=0; i=0; i-=4) { - display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); - display.display(); - } - delay(250); - - display.clearDisplay(); - for (int16_t i=display.width()-1; i>=0; i-=4) { - display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); - display.display(); - } - for (int16_t i=display.height()-1; i>=0; i-=4) { - display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); - display.display(); - } - delay(250); - - display.clearDisplay(); - for (int16_t i=0; i http://www.adafruit.com/category/63_98 - -This example is for a 128x64 size display using I2C to communicate -3 pins are required to interface (2 I2C and one reset) - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen must be included in any redistribution -*********************************************************************/ - -#include -#include -#include -#include - -#define OLED_RESET 4 -Adafruit_SSD1306 display(OLED_RESET); - -#define NUMFLAKES 10 -#define XPOS 0 -#define YPOS 1 -#define DELTAY 2 - - -#define LOGO16_GLCD_HEIGHT 16 -#define LOGO16_GLCD_WIDTH 16 -static const unsigned char PROGMEM logo16_glcd_bmp[] = -{ B00000000, B11000000, - B00000001, B11000000, - B00000001, B11000000, - B00000011, B11100000, - B11110011, B11100000, - B11111110, B11111000, - B01111110, B11111111, - B00110011, B10011111, - B00011111, B11111100, - B00001101, B01110000, - B00011011, B10100000, - B00111111, B11100000, - B00111111, B11110000, - B01111100, B11110000, - B01110000, B01110000, - B00000000, B00110000 }; - -#if (SSD1306_LCDHEIGHT != 64) -#error("Height incorrect, please fix Adafruit_SSD1306.h!"); -#endif - -void setup() { - Serial.begin(9600); - - // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) - display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64) - // init done - - // Show image buffer on the display hardware. - // Since the buffer is intialized with an Adafruit splashscreen - // internally, this will display the splashscreen. - display.display(); - delay(2000); - - // Clear the buffer. - display.clearDisplay(); - - // draw a single pixel - display.drawPixel(10, 10, WHITE); - // Show the display buffer on the hardware. - // NOTE: You _must_ call display after making any drawing commands - // to make them visible on the display hardware! - display.display(); - delay(2000); - display.clearDisplay(); - - // draw many lines - testdrawline(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw rectangles - testdrawrect(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw multiple rectangles - testfillrect(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw mulitple circles - testdrawcircle(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw a white circle, 10 pixel radius - display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); - display.display(); - delay(2000); - display.clearDisplay(); - - testdrawroundrect(); - delay(2000); - display.clearDisplay(); - - testfillroundrect(); - delay(2000); - display.clearDisplay(); - - testdrawtriangle(); - delay(2000); - display.clearDisplay(); - - testfilltriangle(); - delay(2000); - display.clearDisplay(); - - // draw the first ~12 characters in the font - testdrawchar(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw scrolling text - testscrolltext(); - delay(2000); - display.clearDisplay(); - - // text display tests - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - display.println("Hello, world!"); - display.setTextColor(BLACK, WHITE); // 'inverted' text - display.println(3.141592); - display.setTextSize(2); - display.setTextColor(WHITE); - display.print("0x"); display.println(0xDEADBEEF, HEX); - display.display(); - delay(2000); - - // miniature bitmap display - display.clearDisplay(); - display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); - display.display(); - - // invert the display - display.invertDisplay(true); - delay(1000); - display.invertDisplay(false); - delay(1000); - - // draw a bitmap icon and 'animate' movement - testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); -} - - -void loop() { - -} - - -void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { - uint8_t icons[NUMFLAKES][3]; - - // initialize - for (uint8_t f=0; f< NUMFLAKES; f++) { - icons[f][XPOS] = random(display.width()); - icons[f][YPOS] = 0; - icons[f][DELTAY] = random(5) + 1; - - Serial.print("x: "); - Serial.print(icons[f][XPOS], DEC); - Serial.print(" y: "); - Serial.print(icons[f][YPOS], DEC); - Serial.print(" dy: "); - Serial.println(icons[f][DELTAY], DEC); - } - - while (1) { - // draw each icon - for (uint8_t f=0; f< NUMFLAKES; f++) { - display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); - } - display.display(); - delay(200); - - // then erase it + move it - for (uint8_t f=0; f< NUMFLAKES; f++) { - display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK); - // move it - icons[f][YPOS] += icons[f][DELTAY]; - // if its gone, reinit - if (icons[f][YPOS] > display.height()) { - icons[f][XPOS] = random(display.width()); - icons[f][YPOS] = 0; - icons[f][DELTAY] = random(5) + 1; - } - } - } -} - - -void testdrawchar(void) { - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - - for (uint8_t i=0; i < 168; i++) { - if (i == '\n') continue; - display.write(i); - if ((i > 0) && (i % 21 == 0)) - display.println(); - } - display.display(); -} - -void testdrawcircle(void) { - for (int16_t i=0; i0; i-=5) { - display.fillTriangle(display.width()/2, display.height()/2-i, - display.width()/2-i, display.height()/2+i, - display.width()/2+i, display.height()/2+i, WHITE); - if (color == WHITE) color = BLACK; - else color = WHITE; - display.display(); - } -} - -void testdrawroundrect(void) { - for (int16_t i=0; i=0; i-=4) { - display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); - display.display(); - } - delay(250); - - display.clearDisplay(); - for (int16_t i=display.width()-1; i>=0; i-=4) { - display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); - display.display(); - } - for (int16_t i=display.height()-1; i>=0; i-=4) { - display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); - display.display(); - } - delay(250); - - display.clearDisplay(); - for (int16_t i=0; i http://www.adafruit.com/category/63_98 - -This example is for a 128x64 size display using SPI to communicate -4 or 5 pins are required to interface - -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Written by Limor Fried/Ladyada for Adafruit Industries. -BSD license, check license.txt for more information -All text above, and the splash screen must be included in any redistribution -*********************************************************************/ - -#include -#include -#include -#include - -// If using software SPI (the default case): -#define OLED_MOSI 9 -#define OLED_CLK 10 -#define OLED_DC 11 -#define OLED_CS 12 -#define OLED_RESET 13 -Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); - -/* Uncomment this block to use hardware SPI -#define OLED_DC 6 -#define OLED_CS 7 -#define OLED_RESET 8 -Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS); -*/ - -#define NUMFLAKES 10 -#define XPOS 0 -#define YPOS 1 -#define DELTAY 2 - -#define LOGO16_GLCD_HEIGHT 16 -#define LOGO16_GLCD_WIDTH 16 -static const unsigned char PROGMEM logo16_glcd_bmp[] = -{ B00000000, B11000000, - B00000001, B11000000, - B00000001, B11000000, - B00000011, B11100000, - B11110011, B11100000, - B11111110, B11111000, - B01111110, B11111111, - B00110011, B10011111, - B00011111, B11111100, - B00001101, B01110000, - B00011011, B10100000, - B00111111, B11100000, - B00111111, B11110000, - B01111100, B11110000, - B01110000, B01110000, - B00000000, B00110000 }; - -#if (SSD1306_LCDHEIGHT != 64) -#error("Height incorrect, please fix Adafruit_SSD1306.h!"); -#endif - -void setup() { - Serial.begin(9600); - - // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) - display.begin(SSD1306_SWITCHCAPVCC); - // init done - - // Show image buffer on the display hardware. - // Since the buffer is intialized with an Adafruit splashscreen - // internally, this will display the splashscreen. - display.display(); - delay(2000); - - // Clear the buffer. - display.clearDisplay(); - - // draw a single pixel - display.drawPixel(10, 10, WHITE); - // Show the display buffer on the hardware. - // NOTE: You _must_ call display after making any drawing commands - // to make them visible on the display hardware! - display.display(); - delay(2000); - display.clearDisplay(); - - // draw many lines - testdrawline(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw rectangles - testdrawrect(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw multiple rectangles - testfillrect(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw mulitple circles - testdrawcircle(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw a white circle, 10 pixel radius - display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); - display.display(); - delay(2000); - display.clearDisplay(); - - testdrawroundrect(); - delay(2000); - display.clearDisplay(); - - testfillroundrect(); - delay(2000); - display.clearDisplay(); - - testdrawtriangle(); - delay(2000); - display.clearDisplay(); - - testfilltriangle(); - delay(2000); - display.clearDisplay(); - - // draw the first ~12 characters in the font - testdrawchar(); - display.display(); - delay(2000); - display.clearDisplay(); - - // draw scrolling text - testscrolltext(); - delay(2000); - display.clearDisplay(); - - // text display tests - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - display.println("Hello, world!"); - display.setTextColor(BLACK, WHITE); // 'inverted' text - display.println(3.141592); - display.setTextSize(2); - display.setTextColor(WHITE); - display.print("0x"); display.println(0xDEADBEEF, HEX); - display.display(); - delay(2000); - - // miniature bitmap display - display.clearDisplay(); - display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); - display.display(); - - // invert the display - display.invertDisplay(true); - delay(1000); - display.invertDisplay(false); - delay(1000); - - // draw a bitmap icon and 'animate' movement - testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); -} - - -void loop() { - -} - - -void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { - uint8_t icons[NUMFLAKES][3]; - - // initialize - for (uint8_t f=0; f< NUMFLAKES; f++) { - icons[f][XPOS] = random(display.width()); - icons[f][YPOS] = 0; - icons[f][DELTAY] = random(5) + 1; - - Serial.print("x: "); - Serial.print(icons[f][XPOS], DEC); - Serial.print(" y: "); - Serial.print(icons[f][YPOS], DEC); - Serial.print(" dy: "); - Serial.println(icons[f][DELTAY], DEC); - } - - while (1) { - // draw each icon - for (uint8_t f=0; f< NUMFLAKES; f++) { - display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); - } - display.display(); - delay(200); - - // then erase it + move it - for (uint8_t f=0; f< NUMFLAKES; f++) { - display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK); - // move it - icons[f][YPOS] += icons[f][DELTAY]; - // if its gone, reinit - if (icons[f][YPOS] > display.height()) { - icons[f][XPOS] = random(display.width()); - icons[f][YPOS] = 0; - icons[f][DELTAY] = random(5) + 1; - } - } - } -} - - -void testdrawchar(void) { - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - - for (uint8_t i=0; i < 168; i++) { - if (i == '\n') continue; - display.write(i); - if ((i > 0) && (i % 21 == 0)) - display.println(); - } - display.display(); -} - -void testdrawcircle(void) { - for (int16_t i=0; i0; i-=5) { - display.fillTriangle(display.width()/2, display.height()/2-i, - display.width()/2-i, display.height()/2+i, - display.width()/2+i, display.height()/2+i, WHITE); - if (color == WHITE) color = BLACK; - else color = WHITE; - display.display(); - } -} - -void testdrawroundrect(void) { - for (int16_t i=0; i=0; i-=4) { - display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); - display.display(); - } - delay(250); - - display.clearDisplay(); - for (int16_t i=display.width()-1; i>=0; i-=4) { - display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); - display.display(); - } - for (int16_t i=display.height()-1; i>=0; i-=4) { - display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); - display.display(); - } - delay(250); - - display.clearDisplay(); - for (int16_t i=0; i - #include -#else - #define PROGMEM -#endif - -// Standard ASCII 5x7 font - -static const unsigned char font[] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, - 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, - 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, - 0x18, 0x3C, 0x7E, 0x3C, 0x18, - 0x1C, 0x57, 0x7D, 0x57, 0x1C, - 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, - 0x00, 0x18, 0x3C, 0x18, 0x00, - 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, - 0x00, 0x18, 0x24, 0x18, 0x00, - 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, - 0x30, 0x48, 0x3A, 0x06, 0x0E, - 0x26, 0x29, 0x79, 0x29, 0x26, - 0x40, 0x7F, 0x05, 0x05, 0x07, - 0x40, 0x7F, 0x05, 0x25, 0x3F, - 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, - 0x7F, 0x3E, 0x1C, 0x1C, 0x08, - 0x08, 0x1C, 0x1C, 0x3E, 0x7F, - 0x14, 0x22, 0x7F, 0x22, 0x14, - 0x5F, 0x5F, 0x00, 0x5F, 0x5F, - 0x06, 0x09, 0x7F, 0x01, 0x7F, - 0x00, 0x66, 0x89, 0x95, 0x6A, - 0x60, 0x60, 0x60, 0x60, 0x60, - 0x94, 0xA2, 0xFF, 0xA2, 0x94, - 0x08, 0x04, 0x7E, 0x04, 0x08, - 0x10, 0x20, 0x7E, 0x20, 0x10, - 0x08, 0x08, 0x2A, 0x1C, 0x08, - 0x08, 0x1C, 0x2A, 0x08, 0x08, - 0x1E, 0x10, 0x10, 0x10, 0x10, - 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, - 0x30, 0x38, 0x3E, 0x38, 0x30, - 0x06, 0x0E, 0x3E, 0x0E, 0x06, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x5F, 0x00, 0x00, - 0x00, 0x07, 0x00, 0x07, 0x00, - 0x14, 0x7F, 0x14, 0x7F, 0x14, - 0x24, 0x2A, 0x7F, 0x2A, 0x12, - 0x23, 0x13, 0x08, 0x64, 0x62, - 0x36, 0x49, 0x56, 0x20, 0x50, - 0x00, 0x08, 0x07, 0x03, 0x00, - 0x00, 0x1C, 0x22, 0x41, 0x00, - 0x00, 0x41, 0x22, 0x1C, 0x00, - 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, - 0x08, 0x08, 0x3E, 0x08, 0x08, - 0x00, 0x80, 0x70, 0x30, 0x00, - 0x08, 0x08, 0x08, 0x08, 0x08, - 0x00, 0x00, 0x60, 0x60, 0x00, - 0x20, 0x10, 0x08, 0x04, 0x02, - 0x3E, 0x51, 0x49, 0x45, 0x3E, - 0x00, 0x42, 0x7F, 0x40, 0x00, - 0x72, 0x49, 0x49, 0x49, 0x46, - 0x21, 0x41, 0x49, 0x4D, 0x33, - 0x18, 0x14, 0x12, 0x7F, 0x10, - 0x27, 0x45, 0x45, 0x45, 0x39, - 0x3C, 0x4A, 0x49, 0x49, 0x31, - 0x41, 0x21, 0x11, 0x09, 0x07, - 0x36, 0x49, 0x49, 0x49, 0x36, - 0x46, 0x49, 0x49, 0x29, 0x1E, - 0x00, 0x00, 0x14, 0x00, 0x00, - 0x00, 0x40, 0x34, 0x00, 0x00, - 0x00, 0x08, 0x14, 0x22, 0x41, - 0x14, 0x14, 0x14, 0x14, 0x14, - 0x00, 0x41, 0x22, 0x14, 0x08, - 0x02, 0x01, 0x59, 0x09, 0x06, - 0x3E, 0x41, 0x5D, 0x59, 0x4E, - 0x7C, 0x12, 0x11, 0x12, 0x7C, - 0x7F, 0x49, 0x49, 0x49, 0x36, - 0x3E, 0x41, 0x41, 0x41, 0x22, - 0x7F, 0x41, 0x41, 0x41, 0x3E, - 0x7F, 0x49, 0x49, 0x49, 0x41, - 0x7F, 0x09, 0x09, 0x09, 0x01, - 0x3E, 0x41, 0x41, 0x51, 0x73, - 0x7F, 0x08, 0x08, 0x08, 0x7F, - 0x00, 0x41, 0x7F, 0x41, 0x00, - 0x20, 0x40, 0x41, 0x3F, 0x01, - 0x7F, 0x08, 0x14, 0x22, 0x41, - 0x7F, 0x40, 0x40, 0x40, 0x40, - 0x7F, 0x02, 0x1C, 0x02, 0x7F, - 0x7F, 0x04, 0x08, 0x10, 0x7F, - 0x3E, 0x41, 0x41, 0x41, 0x3E, - 0x7F, 0x09, 0x09, 0x09, 0x06, - 0x3E, 0x41, 0x51, 0x21, 0x5E, - 0x7F, 0x09, 0x19, 0x29, 0x46, - 0x26, 0x49, 0x49, 0x49, 0x32, - 0x03, 0x01, 0x7F, 0x01, 0x03, - 0x3F, 0x40, 0x40, 0x40, 0x3F, - 0x1F, 0x20, 0x40, 0x20, 0x1F, - 0x3F, 0x40, 0x38, 0x40, 0x3F, - 0x63, 0x14, 0x08, 0x14, 0x63, - 0x03, 0x04, 0x78, 0x04, 0x03, - 0x61, 0x59, 0x49, 0x4D, 0x43, - 0x00, 0x7F, 0x41, 0x41, 0x41, - 0x02, 0x04, 0x08, 0x10, 0x20, - 0x00, 0x41, 0x41, 0x41, 0x7F, - 0x04, 0x02, 0x01, 0x02, 0x04, - 0x40, 0x40, 0x40, 0x40, 0x40, - 0x00, 0x03, 0x07, 0x08, 0x00, - 0x20, 0x54, 0x54, 0x78, 0x40, - 0x7F, 0x28, 0x44, 0x44, 0x38, - 0x38, 0x44, 0x44, 0x44, 0x28, - 0x38, 0x44, 0x44, 0x28, 0x7F, - 0x38, 0x54, 0x54, 0x54, 0x18, - 0x00, 0x08, 0x7E, 0x09, 0x02, - 0x18, 0xA4, 0xA4, 0x9C, 0x78, - 0x7F, 0x08, 0x04, 0x04, 0x78, - 0x00, 0x44, 0x7D, 0x40, 0x00, - 0x20, 0x40, 0x40, 0x3D, 0x00, - 0x7F, 0x10, 0x28, 0x44, 0x00, - 0x00, 0x41, 0x7F, 0x40, 0x00, - 0x7C, 0x04, 0x78, 0x04, 0x78, - 0x7C, 0x08, 0x04, 0x04, 0x78, - 0x38, 0x44, 0x44, 0x44, 0x38, - 0xFC, 0x18, 0x24, 0x24, 0x18, - 0x18, 0x24, 0x24, 0x18, 0xFC, - 0x7C, 0x08, 0x04, 0x04, 0x08, - 0x48, 0x54, 0x54, 0x54, 0x24, - 0x04, 0x04, 0x3F, 0x44, 0x24, - 0x3C, 0x40, 0x40, 0x20, 0x7C, - 0x1C, 0x20, 0x40, 0x20, 0x1C, - 0x3C, 0x40, 0x30, 0x40, 0x3C, - 0x44, 0x28, 0x10, 0x28, 0x44, - 0x4C, 0x90, 0x90, 0x90, 0x7C, - 0x44, 0x64, 0x54, 0x4C, 0x44, - 0x00, 0x08, 0x36, 0x41, 0x00, - 0x00, 0x00, 0x77, 0x00, 0x00, - 0x00, 0x41, 0x36, 0x08, 0x00, - 0x02, 0x01, 0x02, 0x04, 0x02, - 0x3C, 0x26, 0x23, 0x26, 0x3C, - 0x1E, 0xA1, 0xA1, 0x61, 0x12, - 0x3A, 0x40, 0x40, 0x20, 0x7A, - 0x38, 0x54, 0x54, 0x55, 0x59, - 0x21, 0x55, 0x55, 0x79, 0x41, - 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut - 0x21, 0x55, 0x54, 0x78, 0x40, - 0x20, 0x54, 0x55, 0x79, 0x40, - 0x0C, 0x1E, 0x52, 0x72, 0x12, - 0x39, 0x55, 0x55, 0x55, 0x59, - 0x39, 0x54, 0x54, 0x54, 0x59, - 0x39, 0x55, 0x54, 0x54, 0x58, - 0x00, 0x00, 0x45, 0x7C, 0x41, - 0x00, 0x02, 0x45, 0x7D, 0x42, - 0x00, 0x01, 0x45, 0x7C, 0x40, - 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut - 0xF0, 0x28, 0x25, 0x28, 0xF0, - 0x7C, 0x54, 0x55, 0x45, 0x00, - 0x20, 0x54, 0x54, 0x7C, 0x54, - 0x7C, 0x0A, 0x09, 0x7F, 0x49, - 0x32, 0x49, 0x49, 0x49, 0x32, - 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut - 0x32, 0x4A, 0x48, 0x48, 0x30, - 0x3A, 0x41, 0x41, 0x21, 0x7A, - 0x3A, 0x42, 0x40, 0x20, 0x78, - 0x00, 0x9D, 0xA0, 0xA0, 0x7D, - 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut - 0x3D, 0x40, 0x40, 0x40, 0x3D, - 0x3C, 0x24, 0xFF, 0x24, 0x24, - 0x48, 0x7E, 0x49, 0x43, 0x66, - 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, - 0xFF, 0x09, 0x29, 0xF6, 0x20, - 0xC0, 0x88, 0x7E, 0x09, 0x03, - 0x20, 0x54, 0x54, 0x79, 0x41, - 0x00, 0x00, 0x44, 0x7D, 0x41, - 0x30, 0x48, 0x48, 0x4A, 0x32, - 0x38, 0x40, 0x40, 0x22, 0x7A, - 0x00, 0x7A, 0x0A, 0x0A, 0x72, - 0x7D, 0x0D, 0x19, 0x31, 0x7D, - 0x26, 0x29, 0x29, 0x2F, 0x28, - 0x26, 0x29, 0x29, 0x29, 0x26, - 0x30, 0x48, 0x4D, 0x40, 0x20, - 0x38, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x38, - 0x2F, 0x10, 0xC8, 0xAC, 0xBA, - 0x2F, 0x10, 0x28, 0x34, 0xFA, - 0x00, 0x00, 0x7B, 0x00, 0x00, - 0x08, 0x14, 0x2A, 0x14, 0x22, - 0x22, 0x14, 0x2A, 0x14, 0x08, - 0xAA, 0x00, 0x55, 0x00, 0xAA, - 0xAA, 0x55, 0xAA, 0x55, 0xAA, - 0x00, 0x00, 0x00, 0xFF, 0x00, - 0x10, 0x10, 0x10, 0xFF, 0x00, - 0x14, 0x14, 0x14, 0xFF, 0x00, - 0x10, 0x10, 0xFF, 0x00, 0xFF, - 0x10, 0x10, 0xF0, 0x10, 0xF0, - 0x14, 0x14, 0x14, 0xFC, 0x00, - 0x14, 0x14, 0xF7, 0x00, 0xFF, - 0x00, 0x00, 0xFF, 0x00, 0xFF, - 0x14, 0x14, 0xF4, 0x04, 0xFC, - 0x14, 0x14, 0x17, 0x10, 0x1F, - 0x10, 0x10, 0x1F, 0x10, 0x1F, - 0x14, 0x14, 0x14, 0x1F, 0x00, - 0x10, 0x10, 0x10, 0xF0, 0x00, - 0x00, 0x00, 0x00, 0x1F, 0x10, - 0x10, 0x10, 0x10, 0x1F, 0x10, - 0x10, 0x10, 0x10, 0xF0, 0x10, - 0x00, 0x00, 0x00, 0xFF, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0xFF, 0x10, - 0x00, 0x00, 0x00, 0xFF, 0x14, - 0x00, 0x00, 0xFF, 0x00, 0xFF, - 0x00, 0x00, 0x1F, 0x10, 0x17, - 0x00, 0x00, 0xFC, 0x04, 0xF4, - 0x14, 0x14, 0x17, 0x10, 0x17, - 0x14, 0x14, 0xF4, 0x04, 0xF4, - 0x00, 0x00, 0xFF, 0x00, 0xF7, - 0x14, 0x14, 0x14, 0x14, 0x14, - 0x14, 0x14, 0xF7, 0x00, 0xF7, - 0x14, 0x14, 0x14, 0x17, 0x14, - 0x10, 0x10, 0x1F, 0x10, 0x1F, - 0x14, 0x14, 0x14, 0xF4, 0x14, - 0x10, 0x10, 0xF0, 0x10, 0xF0, - 0x00, 0x00, 0x1F, 0x10, 0x1F, - 0x00, 0x00, 0x00, 0x1F, 0x14, - 0x00, 0x00, 0x00, 0xFC, 0x14, - 0x00, 0x00, 0xF0, 0x10, 0xF0, - 0x10, 0x10, 0xFF, 0x10, 0xFF, - 0x14, 0x14, 0x14, 0xFF, 0x14, - 0x10, 0x10, 0x10, 0x1F, 0x00, - 0x00, 0x00, 0x00, 0xF0, 0x10, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, - 0xFF, 0xFF, 0xFF, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xFF, 0xFF, - 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, - 0x38, 0x44, 0x44, 0x38, 0x44, - 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta - 0x7E, 0x02, 0x02, 0x06, 0x06, - 0x02, 0x7E, 0x02, 0x7E, 0x02, - 0x63, 0x55, 0x49, 0x41, 0x63, - 0x38, 0x44, 0x44, 0x3C, 0x04, - 0x40, 0x7E, 0x20, 0x1E, 0x20, - 0x06, 0x02, 0x7E, 0x02, 0x02, - 0x99, 0xA5, 0xE7, 0xA5, 0x99, - 0x1C, 0x2A, 0x49, 0x2A, 0x1C, - 0x4C, 0x72, 0x01, 0x72, 0x4C, - 0x30, 0x4A, 0x4D, 0x4D, 0x30, - 0x30, 0x48, 0x78, 0x48, 0x30, - 0xBC, 0x62, 0x5A, 0x46, 0x3D, - 0x3E, 0x49, 0x49, 0x49, 0x00, - 0x7E, 0x01, 0x01, 0x01, 0x7E, - 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, - 0x44, 0x44, 0x5F, 0x44, 0x44, - 0x40, 0x51, 0x4A, 0x44, 0x40, - 0x40, 0x44, 0x4A, 0x51, 0x40, - 0x00, 0x00, 0xFF, 0x01, 0x03, - 0xE0, 0x80, 0xFF, 0x00, 0x00, - 0x08, 0x08, 0x6B, 0x6B, 0x08, - 0x36, 0x12, 0x36, 0x24, 0x36, - 0x06, 0x0F, 0x09, 0x0F, 0x06, - 0x00, 0x00, 0x18, 0x18, 0x00, - 0x00, 0x00, 0x10, 0x10, 0x00, - 0x30, 0x40, 0xFF, 0x01, 0x01, - 0x00, 0x1F, 0x01, 0x01, 0x1E, - 0x00, 0x19, 0x1D, 0x17, 0x12, - 0x00, 0x3C, 0x3C, 0x3C, 0x3C, - 0x00, 0x00, 0x00, 0x00, 0x00 -}; -#endif // FONT5X7_H diff --git a/src/Adafruit_SSD1306/license.txt b/src/Adafruit_SSD1306/license.txt deleted file mode 100755 index f6a0f22b..00000000 --- a/src/Adafruit_SSD1306/license.txt +++ /dev/null @@ -1,26 +0,0 @@ -Software License Agreement (BSD License) - -Copyright (c) 2012, Adafruit Industries -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -3. Neither the name of the copyright holders nor the -names of its contributors may be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.