From c901748974fd48734935613e3b0b2d1b318ce6a6 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Sun, 1 Oct 2017 00:07:36 +1000 Subject: [PATCH] Allow use of Analog pins for some selectable outputs --- reference/speeduino.ini | 2 +- speeduino/globals.h | 6 +++++- speeduino/utils.ino | 26 +++++++++++++++++--------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 2eda6e8e..9bba36cc 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -289,7 +289,7 @@ page = 4 unused4-5d = bits, U08, 5,[3:3], "No", "Yes" TrigPattern= bits, U08, 5,[4:7], "Missing Tooth", "Basic Distributor", "Dual Wheel", "GM 7X", "4G63 / Miata / 3000GT", "GM 24X", "Jeep 2000", "Audi 135", "Honda D17", "Miata 99-05", "Mazda AU", "Non-360 Dual", "Nissan 360", "Subaru 6/7", "Daihatsu +1", "Harley EVO" TrigEdgeSec= bits, U08, 6,[0:0], "Leading", "Trailing" - 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" + 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", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15", "INVALID" useResync = bits, U08, 6,[7:7], "No", "Yes" sparkDur = scalar, U08, 7, "ms", 0.1, 0, 0, 25.5, 1 ; Spark duration IdleAdvRPM = scalar, U08, 8, "RPM", 100, 0, 0, 1200, 0 diff --git a/speeduino/globals.h b/speeduino/globals.h index a726d8c3..2ca43e16 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -4,17 +4,21 @@ #include "table.h" #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) - #define BOARD_NR_GPIO_PINS 54 + #define BOARD_DIGITAL_GPIO_PINS 54 + #define BOARD_NR_GPIO_PINS 62 #define LED_BUILTIN 13 #define CORE_AVR #elif defined(CORE_TEENSY) + #define BOARD_DIGITAL_GPIO_PINS 34 #define BOARD_NR_GPIO_PINS 34 #elif defined(STM32_MCU_SERIES) || defined(ARDUINO_ARCH_STM32) || defined(__STM32F1__) || defined(STM32F4) || defined(STM32) #define CORE_STM32 #if defined (STM32F1) || defined(__STM32F1__) + #define BOARD_DIGITAL_GPIO_PINS 34 #define BOARD_NR_GPIO_PINS 34 #define LED_BUILTIN 33 #elif defined(ARDUINO_BLACK_F407VE) || defined(STM32F4) + #define BOARD_DIGITAL_GPIO_PINS 80 #define BOARD_NR_GPIO_PINS 80 #define LED_BUILTIN PA7 #endif diff --git a/speeduino/utils.ino b/speeduino/utils.ino index d174f9f6..b3f6b605 100644 --- a/speeduino/utils.ino +++ b/speeduino/utils.ino @@ -40,6 +40,14 @@ uint16_t freeRam () #endif } +byte pinTranslate(byte rawPin) +{ + byte outputPin = rawPin; + if(rawPin > BOARD_DIGITAL_GPIO_PINS) { outputPin = A8 + (outputPin - BOARD_DIGITAL_GPIO_PINS); } + + return outputPin; +} + void setPinMapping(byte boardID) { switch (boardID) @@ -269,7 +277,7 @@ void setPinMapping(byte boardID) pinInjector5 = 14; //Output pin injector 5 is on pinCoil1 = 39; //Pin for coil 1 pinCoil2 = 41; //Pin for coil 2 - pinCoil3 = 35; //Pin for coil 3 + pinCoil3 = 32; //Pin for coil 3 pinCoil4 = 33; //Pin for coil 4 pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now pinTrigger = 19; //The CAS pin @@ -288,7 +296,7 @@ void setPinMapping(byte boardID) pinFuelPump = 37; //Fuel pump output pinStepperDir = 16; //Direction pin for DRV8825 driver pinStepperStep = 17; //Step pin for DRV8825 driver - pinFan = 47; //Pin for the fan output (Goes to ULN2803) + pinFan = 35; //Pin for the fan output pinLaunch = 12; //Can be overwritten below pinFlex = 3; // Flex sensor (Must be external interrupt enabled) break; @@ -433,13 +441,13 @@ void setPinMapping(byte boardID) //Setup any devices that are using selectable pins - if ( (configPage3.launchPin != 0) && (configPage3.launchPin < BOARD_NR_GPIO_PINS) ) { pinLaunch = configPage3.launchPin; } - if ( (configPage2.ignBypassPin != 0) && (configPage2.ignBypassPin < BOARD_NR_GPIO_PINS) ) { pinIgnBypass = configPage2.ignBypassPin; } - if ( (configPage1.tachoPin != 0) && (configPage1.tachoPin < BOARD_NR_GPIO_PINS) ) { pinTachOut = configPage1.tachoPin; } - if ( (configPage2.fuelPumpPin != 0) && (configPage2.fuelPumpPin < BOARD_NR_GPIO_PINS) ) { pinFuelPump = configPage2.fuelPumpPin; } - if ( (configPage3.fanPin != 0) && (configPage3.fanPin < BOARD_NR_GPIO_PINS) ) { pinFan = configPage3.fanPin; } - if ( (configPage3.boostPin != 0) && (configPage3.boostPin < BOARD_NR_GPIO_PINS) ) { pinBoost = configPage3.boostPin; } - if ( (configPage3.vvtPin != 0) && (configPage3.vvtPin < BOARD_NR_GPIO_PINS) ) { pinVVT_1 = configPage3.vvtPin; } + if ( (configPage3.launchPin != 0) && (configPage3.launchPin < BOARD_NR_GPIO_PINS) ) { pinLaunch = pinTranslate(configPage3.launchPin); } + if ( (configPage2.ignBypassPin != 0) && (configPage2.ignBypassPin < BOARD_NR_GPIO_PINS) ) { pinIgnBypass = pinTranslate(configPage2.ignBypassPin); } + if ( (configPage1.tachoPin != 0) && (configPage1.tachoPin < BOARD_NR_GPIO_PINS) ) { pinTachOut = pinTranslate(configPage1.tachoPin); } + if ( (configPage2.fuelPumpPin != 0) && (configPage2.fuelPumpPin < BOARD_NR_GPIO_PINS) ) { pinFuelPump = pinTranslate(configPage2.fuelPumpPin); } + if ( (configPage3.fanPin != 0) && (configPage3.fanPin < BOARD_NR_GPIO_PINS) ) { pinFan = pinTranslate(configPage3.fanPin); } + if ( (configPage3.boostPin != 0) && (configPage3.boostPin < BOARD_NR_GPIO_PINS) ) { pinBoost = pinTranslate(configPage3.boostPin); } + if ( (configPage3.vvtPin != 0) && (configPage3.vvtPin < BOARD_NR_GPIO_PINS) ) { pinVVT_1 = pinTranslate(configPage3.vvtPin); } if ( (configPage3.useExtBaro != 0) && (configPage3.baroPin < BOARD_NR_GPIO_PINS) ) { pinBaro = configPage3.baroPin + A0; } //Finally, set the relevant pin modes for outputs