Hellen mcu module detector (experimental) (#3756)

* Hellen mcu module detector (experimental)

* make unit-tests happy

* make unit-tests even more happy

* move Hellen-specific stuff to hellen_common.cpp

* fix other hellen config builds

* helping non-Hellen builds too

* helping alpha2ch build

* helping build

* cleanup

* help unit-tests

Co-authored-by: Andrei <andreikagit@users.noreply.github.com>
This commit is contained in:
Andreika 2022-01-10 00:40:08 +02:00 committed by GitHub
parent 0860caa72b
commit 1b9037314a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 88 additions and 27 deletions

View File

@ -1,7 +1,8 @@
# Combine the related files for a specific platform and MCU.
# Target ECU board design
BOARDCPPSRC = $(BOARDS_DIR)/hellen/alphax-2chan/board_configuration.cpp
BOARDCPPSRC = $(BOARDS_DIR)/hellen/alphax-2chan/board_configuration.cpp \
$(BOARDS_DIR)/hellen/hellen_common.cpp
BOARDINC = $(BOARDS_DIR)/hellen/alphax-2chan
# Set this if you want a default engine type other than normal alphax-2chan

View File

@ -1,7 +1,8 @@
# Combine the related files for a specific platform and MCU.
# Target ECU board design
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen-nb1/board_configuration.cpp
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen-nb1/board_configuration.cpp \
$(BOARDS_DIR)/hellen/hellen_common.cpp
BOARDINC = $(BOARDS_DIR)/hellen/hellen-nb1
# Set this if you want a default engine type other than normal hellen-nb1

View File

@ -1,7 +1,8 @@
# Combine the related files for a specific platform and MCU.
# Target ECU board design
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen154hyundai/board_configuration.cpp
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen154hyundai/board_configuration.cpp \
$(BOARDS_DIR)/hellen/hellen_common.cpp
BOARDINC = $(BOARDS_DIR)/hellen/hellen154hyundai
# Set this if you want a default engine type other than normal hellen121nissan

View File

@ -1,7 +1,8 @@
# Combine the related files for a specific platform and MCU.
# Target ECU board design
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen64_miataNA6_94/board_configuration.cpp
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen64_miataNA6_94/board_configuration.cpp \
$(BOARDS_DIR)/hellen/hellen_common.cpp
BOARDINC = $(BOARDS_DIR)/hellen/hellen64_miataNA6_94
# Set this if you want a default engine type other than normal hellen64_miataNA6_94

View File

@ -1,7 +1,8 @@
# Combine the related files for a specific platform and MCU.
# Target ECU board design
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen81/board_configuration.cpp
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen81/board_configuration.cpp \
$(BOARDS_DIR)/hellen/hellen_common.cpp
BOARDINC = $(BOARDS_DIR)/hellen/hellen81
# Set this if you want a default engine type other than normal Hellen81

View File

@ -1,7 +1,8 @@
# Combine the related files for a specific platform and MCU.
# Target ECU board design
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen-nb1/board_configuration.cpp
BOARDCPPSRC = $(BOARDS_DIR)/hellen/hellen-nb1/board_configuration.cpp \
$(BOARDS_DIR)/hellen/hellen_common.cpp
BOARDINC = $(BOARDS_DIR)/hellen/hellen-nb1
# Set this if you want a default engine type other than normal hellen-nb1

View File

@ -1,4 +1,5 @@
#include "pch.h"
#include "hellen_meta.h"
void hellenWbo() {
engineConfiguration->enableAemXSeries = true;
@ -10,3 +11,62 @@ void setHellenDefaultVrThresholds() {
setLinearCurve(engineConfiguration->vrThreshold[i].values, 0.6, 1.2, 0.1);
}
}
void setHellen144LedPins() {
#ifdef EFI_COMMUNICATION_PIN
engineConfiguration->communicationLedPin = EFI_COMMUNICATION_PIN;
#else
engineConfiguration->communicationLedPin = GPIOE_7;
#endif /* EFI_COMMUNICATION_PIN */
engineConfiguration->runningLedPin = GPIOG_1;
engineConfiguration->warningLedPin = GPIOE_8;
}
void setHellen176LedPins() {
#ifdef EFI_COMMUNICATION_PIN
engineConfiguration->communicationLedPin = EFI_COMMUNICATION_PIN;
#else
engineConfiguration->communicationLedPin = GPIOH_10;
#endif /* EFI_COMMUNICATION_PIN */
engineConfiguration->runningLedPin = GPIOH_9; // green
engineConfiguration->warningLedPin = GPIOH_11; // yellow
}
// this should be called before setHellenXXXLedPins()
void detectHellenBoardType() {
// we test the LED1 pin because the red LED used has the smallest voltage drop,
// and thus can be detected more accurately
static const brain_pin_e led1Pins[2] = {
// LED1 pin of the 176-pin mcu module (we check it first!)
GPIOH_8,
// LED1 pin of the 144-pin mcu module
GPIOG_0,
};
int padState[2];
// check each mcu module type sequentially
for (int mcuType = 0; mcuType < 2; mcuType++) {
brain_pin_e ledPin = led1Pins[mcuType];
// set LED1 pin to output & clear the state (discharge parasitic capacitance)
palSetPadMode(getBrainPinPort(ledPin), getBrainPinIndex(ledPin), PAL_MODE_OUTPUT_PUSHPULL);
palClearPad(getBrainPinPort(ledPin), getBrainPinIndex(ledPin));
// set LED1 pin to input
palSetPadMode(getBrainPinPort(ledPin), getBrainPinIndex(ledPin), PAL_MODE_INPUT); // todo: currently we don't use PAL_MODE_INPUT_PULLDOWN - needs more testing
// wait for the pin state to settle down
chThdSleepMilliseconds(1);
// get the pin states
padState[mcuType] = 1;
for (int i = 0; i < 4; i++) {
// we get "1" only if all readings are "1"
padState[mcuType] &= palReadPad(getBrainPinPort(ledPin), getBrainPinIndex(ledPin));
}
}
efiPrintf("Hellen board pin states = %d %d", padState[0], padState[1]);
if (padState[0] && !padState[1]) {
efiPrintf("* Hellen 176-pin mcu detected!");
}
else if (!padState[0] && padState[1]) {
efiPrintf("* Hellen 144-pin mcu detected!");
} else {
efiPrintf("* Cannot detect Hellen mcu module!");
}
}

View File

@ -10,6 +10,12 @@
void hellenWbo();
void setHellenDefaultVrThresholds();
void setHellen144LedPins();
void setHellen176LedPins();
void detectHellenBoardType();
#define H144_LS_1 GPIOG_7
#define H144_LS_2 GPIOG_8
#define H144_LS_3 GPIOD_11

View File

@ -17,6 +17,7 @@
#include "fsio_impl.h"
#include "mre_meta.h"
#include "proteus_meta.h"
#include "hellen_meta.h"
#if EFI_ELECTRONIC_THROTTLE_BODY
#include "electronic_throttle.h"
@ -1052,24 +1053,11 @@ end
#endif
}
void detectBoardType() {
#if HW_HELLEN
void setHellen144LedPins() {
#ifdef EFI_COMMUNICATION_PIN
engineConfiguration->communicationLedPin = EFI_COMMUNICATION_PIN;
#else
engineConfiguration->communicationLedPin = GPIOE_7;
#endif /* EFI_COMMUNICATION_PIN */
engineConfiguration->runningLedPin = GPIOG_1;
engineConfiguration->warningLedPin = GPIOE_8;
}
void setHellen176LedPins() {
#ifdef EFI_COMMUNICATION_PIN
engineConfiguration->communicationLedPin = EFI_COMMUNICATION_PIN;
#else
engineConfiguration->communicationLedPin = GPIOH_10;
#endif /* EFI_COMMUNICATION_PIN */
engineConfiguration->runningLedPin = GPIOH_9; // green
engineConfiguration->warningLedPin = GPIOH_11; // yellow
}
#if !EFI_UNIT_TEST
detectHellenBoardType();
#endif /* EFI_UNIT_TEST */
#endif //HW_HELLEN
// todo: add board ID detection?
}

View File

@ -37,5 +37,4 @@ void setHellen72etb();
void setRotary();
void setVrThresholdTest();
void setHellen144LedPins();
void setHellen176LedPins();
void detectBoardType();

View File

@ -816,6 +816,8 @@ void loadConfiguration() {
resetConfigurationExt(engineConfiguration->engineType);
#endif /* EFI_INTERNAL_FLASH */
detectBoardType();
// Force any board configuration options that humans shouldn't be able to change
setBoardConfigOverrides();
}