Expand Analog pin range for fuel/oil to A22 and add proper analog translate

This commit is contained in:
Josh Stewart 2021-03-19 11:59:21 +11:00
parent f02d75bfbe
commit 324c1523e8
5 changed files with 65 additions and 12 deletions

View File

@ -1083,9 +1083,10 @@ page = 10
fuelPressureEnable = bits, U08, 135, [0:0], "Off", "On"
oilPressureEnable = bits, U08, 135, [1:1], "Off", "On"
oilPressureProtEnbl = bits, U08, 135, [2:2], "Off", "On"
oilPressurePin = bits, U08, 135, [3:7], "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A20", "A21", "A22", INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID
fuelPressurePin = bits, U08, 136, [0:3], "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15"
oilPressurePin = bits, U08, 136, [4:7], "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15"
fuelPressurePin = bits, U08, 136, [0:4], "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A20", "A21", "A22", INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID
fuelPressureMin = scalar, S08, 137, "psi", 1.0, 0.0, -100, 127, 0 ;Note signed int
fuelPressureMax = scalar, U08, 138, "psi", 1.0, 0.0, 0.0, 255, 0

View File

@ -8,6 +8,7 @@
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
#define BOARD_MAX_DIGITAL_PINS 54 //digital pins +1
#define BOARD_MAX_IO_PINS 70 //digital pins + analog channels + 1
#define BOARD_MAX_ADC_PINS 15 //Number of analog pins
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
@ -36,15 +37,18 @@
#define CORE_TEENSY35
#define BOARD_H "board_teensy35.h"
#define SD_LOGGING //SD logging enabled by default for Teensy 3.5 as it has the slot built in
#define BOARD_MAX_ADC_PINS 22 //Number of analog pins
#elif defined(__IMXRT1062__)
#define CORE_TEENSY41
#define BOARD_H "board_teensy41.h"
#define BOARD_MAX_ADC_PINS 17 //Number of analog pins
#endif
#define INJ_CHANNELS 8
#define IGN_CHANNELS 8
#elif defined(STM32_MCU_SERIES) || defined(ARDUINO_ARCH_STM32) || defined(STM32)
#define CORE_STM32
#define BOARD_MAX_ADC_PINS 15 //Number of analog pins. THIS NEEDS CONFIRMING FOR STM32!
#if defined(STM32F407xx) //F407 can do 8x8 STM32F401/STM32F411 not
#define INJ_CHANNELS 8
#define IGN_CHANNELS 8
@ -643,7 +647,7 @@ struct statuses {
int16_t ignLoad;
int16_t ignLoad2;
bool fuelPumpOn; /**< Indicator showing the current status of the fuel pump */
byte syncLossCounter;
volatile byte syncLossCounter;
byte knockRetard;
bool knockActive;
bool toothLogEnabled;
@ -1219,11 +1223,11 @@ struct config10 {
byte fuelPressureEnable : 1;
byte oilPressureEnable : 1;
byte oilPressureProtEnbl : 1;
byte unused10_135 : 5;
byte fuelPressurePin : 4;
byte oilPressurePin : 4;
byte oilPressurePin : 5;
byte fuelPressurePin : 5;
byte unused11_165 : 3;
int8_t fuelPressureMin;
byte fuelPressureMax;
int8_t oilPressureMin;

View File

@ -2397,7 +2397,6 @@ void setPinMapping(byte boardID)
#endif
break;
}
//Setup any devices that are using selectable pins
@ -2408,13 +2407,13 @@ void setPinMapping(byte boardID)
if ( (configPage6.fanPin != 0) && (configPage6.fanPin < BOARD_MAX_IO_PINS) ) { pinFan = pinTranslate(configPage6.fanPin); }
if ( (configPage6.boostPin != 0) && (configPage6.boostPin < BOARD_MAX_IO_PINS) ) { pinBoost = pinTranslate(configPage6.boostPin); }
if ( (configPage6.vvt1Pin != 0) && (configPage6.vvt1Pin < BOARD_MAX_IO_PINS) ) { pinVVT_1 = pinTranslate(configPage6.vvt1Pin); }
if ( (configPage6.useExtBaro != 0) && (configPage6.baroPin < BOARD_MAX_IO_PINS) ) { pinBaro = configPage6.baroPin + A0; }
if ( (configPage6.useEMAP != 0) && (configPage10.EMAPPin < BOARD_MAX_IO_PINS) ) { pinEMAP = configPage10.EMAPPin + A0; }
if ( (configPage6.useExtBaro != 0) && (configPage6.baroPin < BOARD_MAX_IO_PINS) ) { pinBaro = pinTranslateAnalog(configPage6.baroPin); }
if ( (configPage6.useEMAP != 0) && (configPage10.EMAPPin < BOARD_MAX_IO_PINS) ) { pinEMAP = pinTranslateAnalog(configPage10.EMAPPin); }
if ( (configPage10.fuel2InputPin != 0) && (configPage10.fuel2InputPin < BOARD_MAX_IO_PINS) ) { pinFuel2Input = pinTranslate(configPage10.fuel2InputPin); }
if ( (configPage10.spark2InputPin != 0) && (configPage10.spark2InputPin < BOARD_MAX_IO_PINS) ) { pinSpark2Input = pinTranslate(configPage10.spark2InputPin); }
if ( (configPage2.vssPin != 0) && (configPage2.vssPin < BOARD_MAX_IO_PINS) ) { pinVSS = pinTranslate(configPage2.vssPin); }
if ( (configPage10.fuelPressurePin != 0) && (configPage10.fuelPressurePin < BOARD_MAX_IO_PINS) ) { pinFuelPressure = configPage10.fuelPressurePin + A0; }
if ( (configPage10.oilPressurePin != 0) && (configPage10.oilPressurePin < BOARD_MAX_IO_PINS) ) { pinOilPressure = configPage10.oilPressurePin + A0; }
if ( (configPage10.fuelPressureEnable) && (configPage10.fuelPressurePin < BOARD_MAX_IO_PINS) ) { pinFuelPressure = pinTranslateAnalog(configPage10.fuelPressurePin); }
if ( (configPage10.oilPressureEnable) && (configPage10.oilPressurePin < BOARD_MAX_IO_PINS) ) { pinOilPressure = pinTranslateAnalog(configPage10.oilPressurePin); }
if ( (configPage10.wmiEmptyPin != 0) && (configPage10.wmiEmptyPin < BOARD_MAX_IO_PINS) ) { pinWMIEmpty = pinTranslate(configPage10.wmiEmptyPin); }
if ( (configPage10.wmiIndicatorPin != 0) && (configPage10.wmiIndicatorPin < BOARD_MAX_IO_PINS) ) { pinWMIIndicator = pinTranslate(configPage10.wmiIndicatorPin); }

View File

@ -27,6 +27,7 @@ uint8_t pinIsValid = 0;
void setResetControlPinState();
byte pinTranslate(byte);
byte pinTranslateAnalog(byte);
uint32_t calculateCRC32(byte);
void initialiseProgrammableIO();
void checkProgrammableIO();

View File

@ -23,6 +23,54 @@ byte pinTranslate(byte rawPin)
return outputPin;
}
//Translates an pin number (0 - 22) to the relevant Ax pin reference.
//This is required as some ARM chips do not have all analog pins in order (EG pin A15 != A14 + 1)
byte pinTranslateAnalog(byte rawPin)
{
byte outputPin = rawPin;
switch(rawPin)
{
case 0: outputPin = A0; break;
case 1: outputPin = A1; break;
case 2: outputPin = A2; break;
case 3: outputPin = A3; break;
case 4: outputPin = A4; break;
case 5: outputPin = A5; break;
case 6: outputPin = A6; break;
case 7: outputPin = A7; break;
case 8: outputPin = A8; break;
case 9: outputPin = A9; break;
case 10: outputPin = A10; break;
case 11: outputPin = A11; break;
case 12: outputPin = A12; break;
case 13: outputPin = A13; break;
case 14: outputPin = A14; break;
case 15: outputPin = A15; break;
#if BOARD_MAX_ADC_PINS >= 16
case 16: outputPin = A16; break;
#endif
#if BOARD_MAX_ADC_PINS >= 17
case 17: outputPin = A17; break;
#endif
#if BOARD_MAX_ADC_PINS >= 18
case 18: outputPin = A18; break;
#endif
#if BOARD_MAX_ADC_PINS >= 19
case 19: outputPin = A19; break;
#endif
#if BOARD_MAX_ADC_PINS >= 20
case 20: outputPin = A20; break;
#endif
#if BOARD_MAX_ADC_PINS >= 21
case 21: outputPin = A21; break;
#endif
#if BOARD_MAX_ADC_PINS >= 22
case 22: outputPin = A22; break;
#endif
}
return outputPin;
}
void setResetControlPinState()