From fbbeb8a7a116d56425929c56ec32564a0f216f28 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Sun, 15 Dec 2019 09:55:46 +1100 Subject: [PATCH] Basework for new DB board --- platformio.ini | 15 ++++- speeduino/globals.h | 5 ++ speeduino/init.ino | 140 ++++++++++++++++++++++++++-------------- speeduino/scheduledIO.h | 66 ++++++++++++++++++- speeduino/scheduler.ino | 3 - 5 files changed, 174 insertions(+), 55 deletions(-) diff --git a/platformio.ini b/platformio.ini index a4fd0acd..c75aa361 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,7 @@ platform=atmelavr board=megaatmega2560 framework=arduino build_unflags = -Os -build_flags = -O3 -ffast-math -Wall -Wextra +build_flags = -O3 -ffast-math -Wall -Wextra -std=c99 lib_deps = EEPROM [env:teensy35] @@ -22,6 +22,13 @@ board=teensy35 framework=arduino lib_deps = EEPROM, FlexCAN +[env:DropBearT] +platform=teensy +board=teensy35 +framework=arduino +lib_deps = EEPROM, FlexCAN +build_flags = -DUSE_MC33810 + [env:teensy40] platform=teensy board=teensy40 @@ -91,6 +98,9 @@ upload_protocol = sam-ba ;lib_deps = EEPROM ;build_flags = -fpermissive -std=gnu++11 -DUSE_STM32GENERIC -DMENU_USB_SERIAL +[env:custom_monitor_speedrate] +monitor_speed = 115200 + [platformio] src_dir=speeduino default_envs = megaatmega2560 @@ -100,3 +110,6 @@ default_envs = megaatmega2560 ;env_default = LaunchPad_tm4c1294ncpdt ;env_default = genericSTM32F103RB ;env_default = bluepill_f103c8 +monitor_speed = 115200 + + diff --git a/speeduino/globals.h b/speeduino/globals.h index 2c3f4d8a..837bb58e 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -1064,6 +1064,11 @@ byte pinIgnBypass; //The pin used for an ignition bypass (Optional) byte pinFlex; //Pin with the flex sensor attached byte pinBaro; //Pin that an external barometric pressure sensor is attached to (If used) byte pinResetControl; // Output pin used control resetting the Arduino +#ifdef USE_MC33810 +//If the MC33810 IC\s are in use, these are the chip select pins +byte pinMC33810_1_CS; +byte pinMC33810_2_CS; +#endif /* global variables */ // from speeduino.ino extern struct statuses currentStatus; // from speeduino.ino diff --git a/speeduino/init.ino b/speeduino/init.ino index 6b5cdf75..1e49ab00 100644 --- a/speeduino/init.ino +++ b/speeduino/init.ino @@ -17,7 +17,7 @@ #include BOARD_H //Note that this is not a real file, it is defined in globals.h. void initialiseAll() -{ +{ pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); table3D_setSize(&fuelTable, 16); @@ -31,7 +31,7 @@ void initialiseAll() table3D_setSize(&trim2Table, 6); table3D_setSize(&trim3Table, 6); table3D_setSize(&trim4Table, 6); - + loadConfig(); doUpdates(); //Check if any data items need updating (Occurs with firmware updates) @@ -233,7 +233,7 @@ void initialiseAll() } else { - /* + /* * 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. * The lowest measurable sea-level pressure is found at the centers of tropical cyclones and tornadoes, with a record low of 87 kPa; @@ -878,7 +878,6 @@ void initialiseAll() setFuelSchedule4(100, (primingValue * 100 * 5)); } - initialisationComplete = true; digitalWrite(LED_BUILTIN, HIGH); } @@ -1660,6 +1659,41 @@ void setPinMapping(byte boardID) pinSpareLOut1 = 21; //low current output spare1 break; #endif + + case 55: + //Pin mappings for the DropBear + pinTrigger = 19; //The CAS pin + pinTrigger2 = 18; //The Cam Sensor pin + pinFlex = A16; // Flex sensor + pinTPS = A22; //TPS input pin + pinMAP = A1; //MAP sensor pin + pinBaro = A0; //Baro sensor pin + pinIAT = A19; //IAT sensor pin + pinCLT = A20; //CLS sensor pin + pinO2 = A21; //O2 Sensor pin + pinO2_2 = A18; //Spare 2 + pinBat = A14; //Battery reference voltage pin + pinSpareTemp1 = A17; //spare Analog input 1 + pinLaunch = A15; //Can be overwritten below + pinTachOut = 7; //Tacho output pin + pinIdle1 = 27; //Single wire idle control + pinIdle2 = 29; //2 wire idle control. Shared with Spare 1 output + pinFuelPump = 8; //Fuel pump output + pinVVT_1 = 28; //Default VVT output + pinStepperDir = 32; //Direction pin for DRV8825 driver + pinStepperStep = 31; //Step pin for DRV8825 driver + pinStepperEnable = 30; //Enable pin for DRV8825 driver + pinBoost = 24; //Boost control + pinSpareLOut1 = 29; //low current output spare1 + pinSpareLOut2 = 26; //low current output spare2 + pinSpareLOut3 = 28; //low current output spare3 + pinSpareLOut4 = 29; //low current output spare4 + pinFan = 25; //Pin for the fan output + pinResetControl = 46; //Reset control output PLACEHOLDER value for now + + pinMC33810_1_CS = 10; + pinMC33810_2_CS = 9; + break; #if defined(STM32F4) case 60: @@ -1978,25 +2012,15 @@ void setPinMapping(byte boardID) /* Reset control is a special case. If reset control is enabled, it needs its initial state set BEFORE its pinMode. If that doesn't happen and reset control is in "Serial Command" mode, the Arduino will end up in a reset loop because the control pin will go low as soon as the pinMode is set to OUTPUT. */ - if ( (configPage4.resetControl != 0) && (configPage4.resetControlPin < BOARD_NR_GPIO_PINS) ) + if ( (configPage4.resetControlConfig != 0) && (configPage4.resetControlPin < BOARD_NR_GPIO_PINS) ) { - resetControl = configPage4.resetControl; + resetControl = configPage4.resetControlConfig; pinResetControl = pinTranslate(configPage4.resetControlPin); setResetControlPinState(); pinMode(pinResetControl, OUTPUT); } //Finally, set the relevant pin modes for outputs - pinMode(pinCoil1, OUTPUT); - pinMode(pinCoil2, OUTPUT); - pinMode(pinCoil3, OUTPUT); - pinMode(pinCoil4, OUTPUT); - pinMode(pinCoil5, OUTPUT); - pinMode(pinInjector1, OUTPUT); - pinMode(pinInjector2, OUTPUT); - pinMode(pinInjector3, OUTPUT); - pinMode(pinInjector4, OUTPUT); - pinMode(pinInjector5, OUTPUT); pinMode(pinTachOut, OUTPUT); pinMode(pinIdle1, OUTPUT); pinMode(pinIdle2, OUTPUT); @@ -2012,39 +2036,59 @@ void setPinMapping(byte boardID) //This is a legacy mode option to revert the MAP reading behaviour to match what was in place prior to the 201905 firmware if(configPage2.legacyMAP > 0) { digitalWrite(pinMAP, HIGH); } - inj1_pin_port = portOutputRegister(digitalPinToPort(pinInjector1)); - inj1_pin_mask = digitalPinToBitMask(pinInjector1); - inj2_pin_port = portOutputRegister(digitalPinToPort(pinInjector2)); - inj2_pin_mask = digitalPinToBitMask(pinInjector2); - inj3_pin_port = portOutputRegister(digitalPinToPort(pinInjector3)); - inj3_pin_mask = digitalPinToBitMask(pinInjector3); - inj4_pin_port = portOutputRegister(digitalPinToPort(pinInjector4)); - inj4_pin_mask = digitalPinToBitMask(pinInjector4); - inj5_pin_port = portOutputRegister(digitalPinToPort(pinInjector5)); - inj5_pin_mask = digitalPinToBitMask(pinInjector5); - inj6_pin_port = portOutputRegister(digitalPinToPort(pinInjector6)); - inj6_pin_mask = digitalPinToBitMask(pinInjector6); - inj7_pin_port = portOutputRegister(digitalPinToPort(pinInjector7)); - inj7_pin_mask = digitalPinToBitMask(pinInjector7); - inj8_pin_port = portOutputRegister(digitalPinToPort(pinInjector8)); - inj8_pin_mask = digitalPinToBitMask(pinInjector8); + #ifndef USE_MC33810 + pinMode(pinCoil1, OUTPUT); + pinMode(pinCoil2, OUTPUT); + pinMode(pinCoil3, OUTPUT); + pinMode(pinCoil4, OUTPUT); + pinMode(pinCoil5, OUTPUT); + pinMode(pinInjector1, OUTPUT); + pinMode(pinInjector2, OUTPUT); + pinMode(pinInjector3, OUTPUT); + pinMode(pinInjector4, OUTPUT); + pinMode(pinInjector5, OUTPUT); - ign1_pin_port = portOutputRegister(digitalPinToPort(pinCoil1)); - ign1_pin_mask = digitalPinToBitMask(pinCoil1); - ign2_pin_port = portOutputRegister(digitalPinToPort(pinCoil2)); - ign2_pin_mask = digitalPinToBitMask(pinCoil2); - ign3_pin_port = portOutputRegister(digitalPinToPort(pinCoil3)); - ign3_pin_mask = digitalPinToBitMask(pinCoil3); - ign4_pin_port = portOutputRegister(digitalPinToPort(pinCoil4)); - ign4_pin_mask = digitalPinToBitMask(pinCoil4); - ign5_pin_port = portOutputRegister(digitalPinToPort(pinCoil5)); - ign5_pin_mask = digitalPinToBitMask(pinCoil5); - ign6_pin_port = portOutputRegister(digitalPinToPort(pinCoil6)); - ign6_pin_mask = digitalPinToBitMask(pinCoil6); - ign7_pin_port = portOutputRegister(digitalPinToPort(pinCoil7)); - ign7_pin_mask = digitalPinToBitMask(pinCoil7); - ign8_pin_port = portOutputRegister(digitalPinToPort(pinCoil8)); - ign8_pin_mask = digitalPinToBitMask(pinCoil8); + inj1_pin_port = portOutputRegister(digitalPinToPort(pinInjector1)); + inj1_pin_mask = digitalPinToBitMask(pinInjector1); + inj2_pin_port = portOutputRegister(digitalPinToPort(pinInjector2)); + inj2_pin_mask = digitalPinToBitMask(pinInjector2); + inj3_pin_port = portOutputRegister(digitalPinToPort(pinInjector3)); + inj3_pin_mask = digitalPinToBitMask(pinInjector3); + inj4_pin_port = portOutputRegister(digitalPinToPort(pinInjector4)); + inj4_pin_mask = digitalPinToBitMask(pinInjector4); + inj5_pin_port = portOutputRegister(digitalPinToPort(pinInjector5)); + inj5_pin_mask = digitalPinToBitMask(pinInjector5); + inj6_pin_port = portOutputRegister(digitalPinToPort(pinInjector6)); + inj6_pin_mask = digitalPinToBitMask(pinInjector6); + inj7_pin_port = portOutputRegister(digitalPinToPort(pinInjector7)); + inj7_pin_mask = digitalPinToBitMask(pinInjector7); + inj8_pin_port = portOutputRegister(digitalPinToPort(pinInjector8)); + inj8_pin_mask = digitalPinToBitMask(pinInjector8); + + ign1_pin_port = portOutputRegister(digitalPinToPort(pinCoil1)); + ign1_pin_mask = digitalPinToBitMask(pinCoil1); + ign2_pin_port = portOutputRegister(digitalPinToPort(pinCoil2)); + ign2_pin_mask = digitalPinToBitMask(pinCoil2); + ign3_pin_port = portOutputRegister(digitalPinToPort(pinCoil3)); + ign3_pin_mask = digitalPinToBitMask(pinCoil3); + ign4_pin_port = portOutputRegister(digitalPinToPort(pinCoil4)); + ign4_pin_mask = digitalPinToBitMask(pinCoil4); + ign5_pin_port = portOutputRegister(digitalPinToPort(pinCoil5)); + ign5_pin_mask = digitalPinToBitMask(pinCoil5); + ign6_pin_port = portOutputRegister(digitalPinToPort(pinCoil6)); + ign6_pin_mask = digitalPinToBitMask(pinCoil6); + ign7_pin_port = portOutputRegister(digitalPinToPort(pinCoil7)); + ign7_pin_mask = digitalPinToBitMask(pinCoil7); + ign8_pin_port = portOutputRegister(digitalPinToPort(pinCoil8)); + ign8_pin_mask = digitalPinToBitMask(pinCoil8); + #else + mc33810_1_pin_port = portOutputRegister(pinMC33810_1_CS); + mc33810_1_pin_mask = digitalPinToBitMask(pinMC33810_1_CS); + mc33810_2_pin_port = portOutputRegister(pinMC33810_2_CS); + mc33810_2_pin_mask = digitalPinToBitMask(pinMC33810_2_CS); + + initMC33810(); + #endif tach_pin_port = portOutputRegister(digitalPinToPort(pinTachOut)); tach_pin_mask = digitalPinToBitMask(pinTachOut); diff --git a/speeduino/scheduledIO.h b/speeduino/scheduledIO.h index ccc13c9c..723e9e44 100644 --- a/speeduino/scheduledIO.h +++ b/speeduino/scheduledIO.h @@ -2,7 +2,14 @@ #define SCHEDULEDIO_H //If coil inverse is on, set the output low, else set it high -//#define beginCoil1Charge() { configPage4.IgInv == 1 ? *ign1_pin_port &= ~(ign1_pin_mask); : *ign1_pin_port |= (ign1_pin_mask); } TACH_PULSE_LOW(); +//#define beginCoil1Charge() { configPage4.IgInv == 1 ? coil1Low(); : coil1High(); } tachoOutputFlag = READY; +//#define beginCoil2Charge() { configPage4.IgInv == 1 ? coil2Low(); : coil2High(); } tachoOutputFlag = READY; +//#define beginCoil3Charge() { configPage4.IgInv == 1 ? coil3Low(); : coil3High(); } tachoOutputFlag = READY; +//#define beginCoil4Charge() { configPage4.IgInv == 1 ? coil4Low(); : coil4High(); } tachoOutputFlag = READY; +//#define beginCoil5Charge() { configPage4.IgInv == 1 ? coil5Low(); : coil5High(); } tachoOutputFlag = READY; +//#define beginCoil6Charge() { configPage4.IgInv == 1 ? coil6Low(); : coil6High(); } tachoOutputFlag = READY; +//#define beginCoil7Charge() { configPage4.IgInv == 1 ? coil7Low(); : coil7High(); } tachoOutputFlag = READY; +//#define beginCoil8Charge() { configPage4.IgInv == 1 ? coil8Low(); : coil8High(); } tachoOutputFlag = READY; inline void beginCoil1Charge(); inline void endCoil1Charge(); @@ -38,8 +45,14 @@ void beginCoil1and3Charge(); void endCoil1and3Charge(); void beginCoil2and4Charge(); void endCoil2and4Charge(); +/* +#define beginCoil1and3Charge() beginCoil1Charge(); beginCoil3Charge() +#define endCoil1and3Charge() +#define beginCoil2and4Charge() beginCoil2Charge(); beginCoil4Charge() +#define endCoil2and4Charge(); +*/ - +#ifndef USE_MC33810 #define openInjector1() *inj1_pin_port |= (inj1_pin_mask); BIT_SET(currentStatus.status1, BIT_STATUS1_INJ1) #define closeInjector1() *inj1_pin_port &= ~(inj1_pin_mask); BIT_CLEAR(currentStatus.status1, BIT_STATUS1_INJ1) #define openInjector2() *inj2_pin_port |= (inj2_pin_mask); BIT_SET(currentStatus.status1, BIT_STATUS1_INJ2) @@ -50,7 +63,6 @@ void endCoil2and4Charge(); #define closeInjector4() *inj4_pin_port &= ~(inj4_pin_mask); BIT_CLEAR(currentStatus.status1, BIT_STATUS1_INJ4) #define openInjector5() *inj5_pin_port |= (inj5_pin_mask) #define closeInjector5() *inj5_pin_port &= ~(inj5_pin_mask) -//Dynamic functions below #define openInjector6() *inj6_pin_port |= (inj6_pin_mask); #define closeInjector6() *inj6_pin_port &= ~(inj6_pin_mask); #define openInjector7() *inj7_pin_port |= (inj7_pin_mask); @@ -58,6 +70,27 @@ void endCoil2and4Charge(); #define openInjector8() *inj8_pin_port |= (inj8_pin_mask); #define closeInjector8() *inj8_pin_port &= ~(inj8_pin_mask); +#else +#include "acc_mc33810.h" +#define openInjector1() openInjector1_MC33810() +#define closeInjector1() closeInjector1_MC33810() +#define openInjector2() openInjector2_MC33810() +#define closeInjector2() closeInjector2_MC33810() +#define openInjector3() openInjector3_MC33810() +#define closeInjector3() closeInjector3_MC33810() +#define openInjector4() openInjector4_MC33810() +#define closeInjector4() closeInjector4_MC33810() +#define openInjector5() openInjector5_MC33810() +#define closeInjector5() closeInjector5_MC33810() +#define openInjector6() openInjector6_MC33810() +#define closeInjector6() closeInjector6_MC33810() +#define openInjector7() openInjector7_MC33810() +#define closeInjector7() closeInjector7_MC33810() +#define openInjector8() openInjector8_MC33810() +#define closeInjector8() closeInjector8_MC33810() + +#endif + #define openInjector1and4() openInjector1(); openInjector4() #define closeInjector1and4() closeInjector1(); closeInjector4() #define openInjector2and3() openInjector2(); openInjector3() @@ -67,6 +100,7 @@ void endCoil2and4Charge(); #define openInjector3and5() openInjector3(); openInjector5() #define closeInjector3and5() closeInjector3(); closeInjector5() +#ifndef USE_MC33810 #define coil1Low() (*ign1_pin_port &= ~(ign1_pin_mask)) #define coil1High() (*ign1_pin_port |= (ign1_pin_mask)) #define coil2Low() (*ign2_pin_port &= ~(ign2_pin_mask)) @@ -75,6 +109,32 @@ void endCoil2and4Charge(); #define coil3High() (*ign3_pin_port |= (ign3_pin_mask)) #define coil4Low() (*ign4_pin_port &= ~(ign4_pin_mask)) #define coil4High() (*ign4_pin_port |= (ign4_pin_mask)) +#define coil5Low() (*ign5_pin_port &= ~(ign5_pin_mask)) +#define coil5High() (*ign5_pin_port |= (ign5_pin_mask)) +#define coil6Low() (*ign6_pin_port &= ~(ign6_pin_mask)) +#define coil6High() (*ign6_pin_port |= (ign6_pin_mask)) +#define coil7Low() (*ign7_pin_port &= ~(ign7_pin_mask)) +#define coil7High() (*ign7_pin_port |= (ign7_pin_mask)) +#define coil8Low() (*ign8_pin_port &= ~(ign8_pin_mask)) +#define coil8High() (*ign8_pin_port |= (ign8_pin_mask)) +#else +#define coil1Low() coil1Low_MC33810() +#define coil1High() coil1High_MC33810() +#define coil2Low() coil2Low_MC33810() +#define coil2High() coil2High_MC33810() +#define coil3Low() coil3Low_MC33810() +#define coil3High()coil3High_MC33810() +#define coil4Low() coil4Low_MC33810() +#define coil4High() coil4High_MC33810() +#define coil5Low() coil5Low_MC33810() +#define coil5High() coil5High_MC33810() +#define coil6Low() coil6Low_MC33810() +#define coil6High() coil6High_MC33810() +#define coil7Low() coil7Low_MC33810() +#define coil7High() coil7High_MC33810() +#define coil8Low() coil8Low_MC33810() +#define coil8High() coil8High_MC33810() +#endif void nullCallback(); diff --git a/speeduino/scheduler.ino b/speeduino/scheduler.ino index 31356ddf..0402fb93 100644 --- a/speeduino/scheduler.ino +++ b/speeduino/scheduler.ino @@ -71,9 +71,6 @@ void setFuelSchedule(struct Schedule *targetSchedule, unsigned long timeout, uns { if(targetSchedule->Status != RUNNING) //Check that we're not already part way through a schedule { - //Callbacks no longer used, but retained for now: - //fuelSchedule1.StartCallback = startCallback; - //fuelSchedule1.EndCallback = endCallback; targetSchedule->duration = duration; //Need to check that the timeout doesn't exceed the overflow