From 3f75f55bddb769a7aefa821ad4c2a5ad5c87b032 Mon Sep 17 00:00:00 2001 From: dynfer <102673508+dynfer@users.noreply.github.com> Date: Sun, 4 Feb 2024 11:34:29 +0100 Subject: [PATCH] Add support for RusEFI CAN Wideband based on STM32F042 (#1146) * CAN WBO Support * fix typo * Change data handling * add source repo information * Added heater functionality and fixed value handling * Missed 0 * Better condition handling and minor fixes to multiplication * Remove code duplication * fix * Error fixing and correct address of controller for outgoing frames * Page layout adjustment * fix * Second WBO added to be used in TS / MLV * Add extended flag to out frame * Functional test and fixes * typo * CAN WBO Support fix typo Change data handling add source repo information Added heater functionality and fixed value handling Missed 0 Better condition handling and minor fixes to multiplication Remove code duplication fix Error fixing and correct address of controller for outgoing frames Page layout adjustment fix Second WBO added to be used in TS / MLV Add extended flag to out frame Add support for BlitzBox hardware in speeduino firmware (#1148) * Add support for BlitzBox in init.cpp added case 42 for BlitzBox support * Added support for Blitzbox to speeduino.ini Added support for Blitzbox to speeduino.ini to get an ECU entry in Tunerstudio * Enabled spare pins in pin layout Functional test and fixes typo Fix issue with LED indicator not working when MC33810 was in use Resolve issue with Teensy not sending CAN msgs Fix regression on MC33810 units from af2815d818668d45d7fc271c195c03f0d9c7582e Added check for AFR greater than 25.5 Added overflow check of O2 value Code clean up Bump actions/upload-artifact from 3 to 4 (#1149) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Spelling and typo correction missing space * Fix possible overflow * Allow for future CAN based WBO modules to be added * rusEFI case as requested. * fix * CAN WBO Support * fix typo * Change data handling * add source repo information * Added heater functionality and fixed value handling * Missed 0 * Better condition handling and minor fixes to multiplication * Remove code duplication * fix * Error fixing and correct address of controller for outgoing frames * Page layout adjustment * fix * Second WBO added to be used in TS / MLV * Add extended flag to out frame * Functional test and fixes * typo * Allow for future CAN based WBO modules to be added * CAN WBO Support fix typo Change data handling add source repo information Added heater functionality and fixed value handling Missed 0 Better condition handling and minor fixes to multiplication Remove code duplication fix Error fixing and correct address of controller for outgoing frames Page layout adjustment fix Second WBO added to be used in TS / MLV Add extended flag to out frame Add support for BlitzBox hardware in speeduino firmware (#1148) * Add support for BlitzBox in init.cpp added case 42 for BlitzBox support * Added support for Blitzbox to speeduino.ini Added support for Blitzbox to speeduino.ini to get an ECU entry in Tunerstudio * Enabled spare pins in pin layout Functional test and fixes typo Fix issue with LED indicator not working when MC33810 was in use Resolve issue with Teensy not sending CAN msgs Fix regression on MC33810 units from af2815d818668d45d7fc271c195c03f0d9c7582e Added check for AFR greater than 25.5 Added overflow check of O2 value Code clean up Bump actions/upload-artifact from 3 to 4 (#1149) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Spelling and typo correction missing space * rusEFI case as requested. * Revert "Merge branch 'master' of https://github.com/dynfer/speeduino" This reverts commit 49dc0eab0814cd9e55435178ab0cbb74741b473a, reversing changes made to 56abc790086ba1b5f0d2efdbc7947c60c6b34f9a. * fix merge * fixes * Added overflow prevention * Final --------- Co-authored-by: Josh Stewart --- reference/speeduino.ini | 24 +++++++++---------- speeduino/comms_CAN.cpp | 51 ++++++++++++++++++++++++++++++++++++++++- speeduino/comms_CAN.h | 3 +++ speeduino/globals.h | 7 +++--- speeduino/speeduino.ino | 9 +++++--- speeduino/updates.cpp | 3 +++ 6 files changed, 76 insertions(+), 21 deletions(-) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index f50922c8..93790d2b 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -477,10 +477,8 @@ page = 1 canBMWCluster = bits, U08, 126, [0:0], "Off", "On" canVAGCluster = bits, U08, 126, [1:1], "Off", "On" ;These are reserved for future use, in case of more CAN broadcasting features are added - enable1Cluster = bits, U08, 126, [2:2], "Off", "On" - enable2Cluster = bits, U08, 126, [3:3], "Off", "On" + canWBO = bits, U08, 126, [2:3], "Off", "rusEFI WBO", "INVALID", "INVALID" vssAuxCh = bits, U08, 126, [4:7], "Aux0", "Aux1", "Aux2", "Aux3", "Aux4", "Aux5", "Aux6", "Aux7", "Aux8", "Aux9", "Aux10", "Aux11", "Aux12", "Aux13", "Aux14", "Aux15" - decelAmount = scalar, U08, 127, "%", 1.0, 0.0, 0.0, 150.0, 0 ;Page 2 is the fuel map and axis bins only @@ -1476,10 +1474,9 @@ page = 15 airConIdleUpRPMAdder = scalar, U08, 96, "Added Target RPM", 10.0, 0.0, 0.0, 250.0, 0 airConPwmFanMinDuty = scalar, U08, 97, "%", 0.5, 0.0, 0.0, 100.0, 1 - rollingProtRPMDelta = array, S08, 98, [4], "RPM", 10.0, 0, -1000, 0, 0 - rollingProtCutPercent = array, U08, 102, [4], "%", 1.0, 0, 0, 100, 0 - - Unused15_98_255 = array, U08, 98, [150], "%", 1.0, 0.0, 0.0, 255, 0 + rollingProtRPMDelta = array, S08, 98, [4], "RPM", 10.0, 0, -1000, 0, 0 + rollingProtCutPercent = array, U08, 102, [4], "%", 1.0, 0, 0, 100, 0 + Unused15_106_255 = array, U08, 106, [150], "%", 1.0, 0.0, 0.0, 255, 0 ;------------------------------------------------------------------------------- @@ -2427,6 +2424,7 @@ menuDialog = main tachoMode = "The output mode for the tacho pulse. Fixed timing will produce a pulse that is always of the same duration, which works better with mode modern digital tachos. Dwell based output creates a pulse that is matched to the coil/s dwell time. If enabled the tacho pulse duration and timing is same as coil dwell and the number of pulses is same as number of ignition events. This can work better on some styles of tacho but note that the pulse duration might become problem on higher cylinder number engines." canBMWCluster = "Enables CAN broadcasting for BMW E46, E39 and E38 instrument clusters with message ID's 0x316, 0x329 and 0x545" canVAGCluster = "Enables CAN broadcasting for VAG instrument clusters with message ID's 0x280 and 0x5A0" + canWBO = "Enables to recive AFR via CAN for supported controllers" caninputEndianess= "Byte ordering for values with two bytes." boostControlEnable = "Set the trigger to enable/disable the closedloop boost controller. When set to: \n 'fixed': if the fuel load exceeds the threshold closedloop boost controller is enbaled.\n 'baro': if the fuel load exceeds the baro the controller is enabled (legacy) " @@ -3564,14 +3562,14 @@ menuDialog = main dialog = CanBcast, "CAN Broadcasting menu" field = "BMW Instrument Cluster Broadcast", canBMWCluster field = "VAG Instrument Cluster Broadcast", canVAGCluster + field = "WBO over CAN", canWBO dialog = Auxin_north - displayOnlyField = #"Secondary Serial ENABLED", blankfield, {enable_secondarySerial},{enable_secondarySerial} - displayOnlyField = !"Secondary Serial DISABLED", blankfield, {enable_secondarySerial == 0},{enable_secondarySerial == 0} - displayOnlyField = #"Internal CANBUS ENABLED", blankfield, {enable_intcan && intcan_available},{enable_intcan && intcan_available} - displayOnlyField = !"Internal CANBUS DISABLED", blankfield, {enable_intcan == 0 && intcan_available},{enable_intcan == 0 && intcan_available} - displayOnlyField = !"Internal CANBUS NOT AVAILABLE to MCU", blankfield, {enable_intcan == 1 && intcan_available == 0},{enable_intcan == 1 && intcan_available == 0} - displayOnlyField = !"Internal CANBUS NOT AVAILABLE to MCU", blankfield, {enable_intcan == 0 && intcan_available == 0},{enable_intcan == 0 && intcan_available == 0} + displayOnlyField = !"Secondary Serial DISABLED", blankfield, {enable_secondarySerial == 0},{enable_secondarySerial == 0} + displayOnlyField = #"Internal CANBUS ENABLED", blankfield, {enable_intcan && intcan_available},{enable_intcan && intcan_available} + displayOnlyField = !"Internal CANBUS DISABLED", blankfield, {enable_intcan == 0 && intcan_available},{enable_intcan == 0 && intcan_available} + displayOnlyField = !"Internal CANBUS NOT AVAILABLE to MCU", blankfield, {enable_intcan == 1 && intcan_available == 0},{enable_intcan == 1 && intcan_available == 0} + displayOnlyField = !"Internal CANBUS NOT AVAILABLE to MCU", blankfield, {enable_intcan == 0 && intcan_available == 0},{enable_intcan == 0 && intcan_available == 0} field = " If Secondary Serial or Internal CANBUS is DISABLED then any input channel assigned to that external source will NOT function" dialog = selectionOfEdianness. , "Endianness", yAxis diff --git a/speeduino/comms_CAN.cpp b/speeduino/comms_CAN.cpp index 730beb43..4bb17788 100644 --- a/speeduino/comms_CAN.cpp +++ b/speeduino/comms_CAN.cpp @@ -24,6 +24,14 @@ CAN_message_t outMsg; FlexCAN_T4 Can1; #endif +//These are declared locally for Teensy due to this issue: https://github.com/tonton81/FlexCAN_T4/issues/67 +#if defined(CORE_TEENSY35) // use for Teensy 3.5 only + FlexCAN_T4 Can0; +#elif defined(CORE_TEENSY41) // use for Teensy 3.6 only + FlexCAN_T4 Can0; + FlexCAN_T4 Can1; +#endif + // Forward declare void DashMessage(uint16_t DashMessageID); @@ -75,7 +83,48 @@ void sendVAGCluster() DashMessage(CAN_VAG_VSS); Can0.write(outMsg); } +void receiveCANwbo() +{ + // Currently only RusEFI CAN Wideband supported: https://github.com/mck1117/wideband + if(configPage2.canWBO == CAN_WBO_RUSEFI) + { + outMsg.id = 0xEF50000; + outMsg.flags.extended = 1; + outMsg.len = 2; + outMsg.buf[0] = currentStatus.battery10; // We don't do any conversion since factor is 0.1 and speeduino value is x10 + outMsg.buf[1] = 0x1; // Enable heater + Can0.write(outMsg); + if ((inMsg.id == 0x190 || inMsg.id == 0x192)) + { + uint32_t inLambda; + inLambda = (word(inMsg.buf[3], inMsg.buf[2])); // Combining 2 bytes of data into single variable factor is 0.0001 so lambda 1 comes in as 10K + if(inMsg.buf[1] == 0x1) // Checking if lambda is valid + { + switch(inMsg.id) + { + case 0x190: + if ((inLambda * configPage2.stoich / 10000) > 250) { //Check if we dont overflow the 8bit O2 variable + currentStatus.O2 = 250; + break; + } + currentStatus.O2 = (unsigned int)(inLambda * configPage2.stoich / 10000); // Multiplying lambda by stoich ratio to get AFR and dividing it by 10000 to get correct value + break; + case 0x192: + if ((inLambda * configPage2.stoich / 10000) > 250) { //Check if we dont overflow the 8bit O2 variable + currentStatus.O2 = 250; + break; + } + currentStatus.O2_2 = (unsigned int)(inLambda * configPage2.stoich / 10000); // Multiplying lambda by stoich ratio to get AFR and dividing it by 10000 to get correct value + break; + + default: + break; + } + } + } + } +} // switch case for gathering all data to message based on CAN Id. void DashMessage(uint16_t DashMessageID) { @@ -577,4 +626,4 @@ void readAuxCanBus() } } } -#endif +#endif \ No newline at end of file diff --git a/speeduino/comms_CAN.h b/speeduino/comms_CAN.h index b24338bc..06a75562 100644 --- a/speeduino/comms_CAN.h +++ b/speeduino/comms_CAN.h @@ -14,6 +14,8 @@ #define CAN_VAG_RPM 0x280 #define CAN_VAG_VSS 0x5A0 +#define CAN_WBO_RUSEFI 1 + #define TS_CAN_OFFSET 0x100 void initCAN(); @@ -21,6 +23,7 @@ int CAN_read(); void CAN_write(); void sendBMWCluster(); void sendVAGCluster(); +void receiveCANwbo(); void DashMessages(uint16_t DashMessageID); void can_Command(void); void obd_response(uint8_t therequestedPID , uint8_t therequestedPIDlow, uint8_t therequestedPIDhigh); diff --git a/speeduino/globals.h b/speeduino/globals.h index cf043243..859aa5b8 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -861,8 +861,7 @@ struct config2 { byte canBMWCluster : 1; byte canVAGCluster : 1; - byte enableCluster1 : 1; - byte enableCluster2 : 1; + byte canWBO : 2 ; byte vssAuxCh : 4; byte decelAmount; @@ -1442,8 +1441,8 @@ struct config15 { int8_t rollingProtRPMDelta[4]; // Signed RPM value representing how much below the RPM limit. Divided by 10 byte rollingProtCutPercent[4]; - //Bytes 98-255 - byte Unused15_98_255[150]; + //Bytes 106-255 + byte Unused15_106_255[150]; #if defined(CORE_AVR) }; diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index e5ad09d8..c251f62c 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -126,6 +126,7 @@ void loop(void) { can_Command(); readAuxCanBus(); + if (configPage2.canWBO > 0) { receiveCANwbo(); } } } #endif @@ -260,9 +261,11 @@ void loop(void) #if TPS_READ_FREQUENCY == 30 readTPS(); #endif - readO2(); - readO2_2(); - + if (configPage2.canWBO == 0) + { + readO2(); + readO2_2(); + } #ifdef SD_LOGGING if(configPage13.onboard_log_file_rate == LOGGER_RATE_30HZ) { writeSDLogEntry(); } #endif diff --git a/speeduino/updates.cpp b/speeduino/updates.cpp index 0ff5198b..8b9253a9 100644 --- a/speeduino/updates.cpp +++ b/speeduino/updates.cpp @@ -745,6 +745,9 @@ void doUpdates(void) configPage9.egoMAPMax = 255, // 255 will be 510 kpa configPage9.egoMAPMin = 0, // 0 will be 0 kpa + //rusEFI CAN Wideband + configPage2.canWBO = 0; + writeAllConfig(); storeEEPROMVersion(23); }