From 73f4058f6b18358fbccd954bf64ba761798868d3 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 15 Oct 2019 16:56:41 +1100 Subject: [PATCH] Reenable LED indicator on the calibration routing --- platformio.ini | 3 ++- speeduino/comms.ino | 25 +++++++++++++++---------- speeduino/globals.h | 9 ++++++++- speeduino/sensors.h | 5 ----- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/platformio.ini b/platformio.ini index 4eb3d00e..a4fd0acd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -93,8 +93,9 @@ upload_protocol = sam-ba [platformio] src_dir=speeduino -default_envs = black_F407VE +default_envs = megaatmega2560 ;The following lines are for testing / experimentation only. Comment the line above to try them out +;default_envs = black_F407VE ;env_default = teensy35 ;env_default = LaunchPad_tm4c1294ncpdt ;env_default = genericSTM32F103RB diff --git a/speeduino/comms.ino b/speeduino/comms.ino index 97bf8cf3..f37ff5fa 100644 --- a/speeduino/comms.ino +++ b/speeduino/comms.ino @@ -1641,10 +1641,14 @@ void receiveCalibration(byte tableID) bool every2nd = true; int x; int counter = 0; - // stm32 board has buildin led used as fuel pump - // pinMode(LED_BUILTIN, OUTPUT); //pinMode(13, OUTPUT); + bool useLEDIndicator = false; + if (pinIsOutput(LED_BUILTIN) == false) + { + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + useLEDIndicator = true; + } - // digitalWrite(LED_BUILTIN, LOW); //digitalWrite(13, LOW); for (x = 0; x < 1024; x++) { //UNlike what is listed in the protocol documentation, the O2 sensor values are sent as bytes rather than ints @@ -1681,13 +1685,14 @@ void receiveCalibration(byte tableID) storeCalibrationValue(y, (byte)tempValue); every2nd = false; - #if defined(CORE_STM32) - digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); - #elif defined(CORE_STM32_OFFICIAL) - //Of core offical do nothing. led is reserved for fuel pump - #else - analogWrite(LED_BUILTIN, (counter % 50) ); //analogWrite(13, (counter % 50) ); - #endif + if(useLEDIndicator == true) + { + #if defined(CORE_STM32) + digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); + #else + analogWrite(LED_BUILTIN, (counter % 50) ); + #endif + } counter++; } else { diff --git a/speeduino/globals.h b/speeduino/globals.h index 5e4a1938..4584534b 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -379,6 +379,13 @@ byte resetControl = RESET_CONTROL_DISABLED; volatile byte TIMER_mask; volatile byte LOOP_TIMER; +//These functions all do checks on a pin to determine if it is already in use by another (higher importance) function +#define pinIsInjector(pin) ( ((pin) == pinInjector1) || ((pin) == pinInjector2) || ((pin) == pinInjector3) || ((pin) == pinInjector4) ) +#define pinIsIgnition(pin) ( ((pin) == pinCoil1) || ((pin) == pinCoil2) || ((pin) == pinCoil3) || ((pin) == pinCoil4) ) +#define pinIsSensor(pin) ( ((pin) == pinCLT) || ((pin) == pinIAT) || ((pin) == pinMAP) || ((pin) == pinTPS) || ((pin) == pinO2) || ((pin) == pinBat) ) +#define pinIsUsed(pin) ( pinIsInjector((pin)) || pinIsIgnition((pin)) || pinIsSensor((pin)) ) +#define pinIsOutput(pin) ( ((pin) == pinFuelPump) || ((pin) == pinFan) || ((pin) == pinVVT_1) || ((pin) == pinVVT_2) || ((pin) == pinBoost) || ((pin) == pinIdle1) || ((pin) == pinIdle2) || ((pin) == pinTachOut) ) + //The status struct contains the current values for all 'live' variables //In current version this is 64 bytes struct statuses { @@ -1022,7 +1029,7 @@ byte pinSpareLOut4; byte pinSpareLOut5; byte pinBoost; byte pinVVT_1; // vvt output 1 -byte pinVVt_2; // vvt output 2 +byte pinVVT_2; // vvt output 2 byte pinFan; // Cooling fan output byte pinStepperDir; //Direction pin for the stepper motor driver byte pinStepperStep; //Step pin for the stepper motor driver diff --git a/speeduino/sensors.h b/speeduino/sensors.h index fb77ddc7..357004f9 100644 --- a/speeduino/sensors.h +++ b/speeduino/sensors.h @@ -54,11 +54,6 @@ byte cltErrorCount = 0; * 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 -//These functions all do checks on a pin to determine if it is already in use by another (higher importance) function -#define pinIsInjector(pin) ( ((pin) == pinInjector1) || ((pin) == pinInjector2) || ((pin) == pinInjector3) || ((pin) == pinInjector4) ) -#define pinIsIgnition(pin) ( ((pin) == pinCoil1) || ((pin) == pinCoil2) || ((pin) == pinCoil3) || ((pin) == pinCoil4) ) -#define pinIsSensor(pin) ( ((pin) == pinCLT) || ((pin) == pinIAT) || ((pin) == pinMAP) || ((pin) == pinTPS) || ((pin) == pinO2) || ((pin) == pinBat) ) -#define pinIsUsed(pin) ( pinIsInjector((pin)) || pinIsIgnition((pin)) || pinIsSensor((pin)) ) static inline void instanteneousMAPReading() __attribute__((always_inline)); static inline void readMAP() __attribute__((always_inline));