diff --git a/firmware/config/engines/dodge_neon.cpp b/firmware/config/engines/dodge_neon.cpp index 21f65957a0..62f4bc9157 100644 --- a/firmware/config/engines/dodge_neon.cpp +++ b/firmware/config/engines/dodge_neon.cpp @@ -282,9 +282,6 @@ void setDodgeNeonNGCEngineConfiguration(engine_configuration_s *engineConfigurat boardConfiguration->fuelPumpPin = GPIOE_3; boardConfiguration->fuelPumpPinMode = OM_DEFAULT; - boardConfiguration->gps_rx_pin = GPIO_UNASSIGNED; - boardConfiguration->gps_tx_pin = GPIO_UNASSIGNED; - boardConfiguration->triggerInputPins[0] = GPIOA_5; boardConfiguration->triggerInputPins[1] = GPIOC_6; @@ -352,7 +349,7 @@ void setDodgeNeonNGCEngineConfiguration(engine_configuration_s *engineConfigurat engineConfiguration->map.sensor.sensorType = MT_DODGE_NEON_2003; #if EFI_PROD_CODE - setHip9011FrankensoPinout(); +// setHip9011FrankensoPinout(); #endif engineConfiguration->cylinderBore = 87.5; diff --git a/firmware/config/engines/honda_accord.cpp b/firmware/config/engines/honda_accord.cpp index ba1b713347..9c301ac052 100644 --- a/firmware/config/engines/honda_accord.cpp +++ b/firmware/config/engines/honda_accord.cpp @@ -173,9 +173,6 @@ static void setHondaAccordConfigurationCommon(engine_configuration_s *engineConf boardConfiguration->fuelPumpPin = GPIOE_3; boardConfiguration->fuelPumpPinMode = OM_DEFAULT; - boardConfiguration->gps_rx_pin = GPIO_UNASSIGNED; - boardConfiguration->gps_tx_pin = GPIO_UNASSIGNED; - setFrankenso_01_LCD(boardConfiguration); boardConfiguration->logicAnalyzerPins[1] = GPIO_UNASSIGNED; diff --git a/firmware/config/engines/mazda_miata.cpp b/firmware/config/engines/mazda_miata.cpp index 43b2790978..902346ce8f 100644 --- a/firmware/config/engines/mazda_miata.cpp +++ b/firmware/config/engines/mazda_miata.cpp @@ -130,9 +130,6 @@ static void commonMiataNa(engine_configuration_s *engineConfiguration, board_con setFuelLoadBin(engineConfiguration, 1.2, 4.4); setFuelRpmBin(engineConfiguration, 800, 7000); - boardConfiguration->gps_rx_pin = GPIO_UNASSIGNED; - boardConfiguration->gps_tx_pin = GPIO_UNASSIGNED; - boardConfiguration->idleSolenoidFrequency = 160; engineConfiguration->globalTriggerAngleOffset = 294; diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index b6d4676348..1faa120940 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -422,7 +422,7 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_ boardConfiguration->fanPin = GPIOC_15; boardConfiguration->fanPinMode = OM_DEFAULT; - boardConfiguration->idleSwitchPin = GPIOC_8; + boardConfiguration->idleSwitchPin = GPIO_UNASSIGNED; boardConfiguration->triggerSimulatorPins[0] = GPIOD_1; boardConfiguration->triggerSimulatorPins[1] = GPIOD_2; @@ -436,6 +436,7 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_ engineConfiguration->hip9011SpiDevice = SPI_DEVICE_2; + engineConfiguration->isGpsEnabled = false; boardConfiguration->gps_rx_pin = GPIOB_7; boardConfiguration->gps_tx_pin = GPIOB_6; @@ -539,11 +540,14 @@ static void setCustomEngineConfiguration(engine_configuration_s *engineConfigura // Frankenso low out #6: PE4 // Frankenso low out #7: PE1 (do not use with discovery!) // Frankenso low out #8: PE2 injector #2 - // Frankenso low out #9: PB9 + // Frankenso low out #9: PB9 Idle valve solenoid // Frankenso low out #10: PE0 (do not use with discovery!) // Frankenso low out #11: PB8 injector #3 // Frankenso low out #12: PB7 injector #4 + boardConfiguration->idleValvePin = GPIOB_9; + + boardConfiguration->injectionPins[0] = GPIO_UNASSIGNED; // #1 boardConfiguration->injectionPins[1] = GPIOE_2; // #2 boardConfiguration->injectionPins[2] = GPIOB_8; // #3 diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index a43748b1ad..baf2a30b26 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -521,6 +521,7 @@ typedef struct { bool_t canWriteEnabled : 1; // bit 8 bool_t hasVehicleSpeedSensor : 1; // bit 9 bool_t isJoystickEnabled : 1; // bit 10 + bool_t isGpsEnabled : 1; // bit 11 int unused6284; diff --git a/firmware/controllers/idle_thread.cpp b/firmware/controllers/idle_thread.cpp index 381442f9d0..61a4ad563c 100644 --- a/firmware/controllers/idle_thread.cpp +++ b/firmware/controllers/idle_thread.cpp @@ -62,7 +62,8 @@ void idleDebug(const char *msg, percent_t value) { } static void showIdleInfo(void) { - scheduleMsg(&logger, "idleMode=%s duty=%f", getIdle_mode_e(engineConfiguration->idleMode), boardConfiguration->idleSolenoidPwm); + scheduleMsg(&logger, "idleMode=%s duty=%f", getIdle_mode_e(engineConfiguration->idleMode), + boardConfiguration->idleSolenoidPwm); scheduleMsg(&logger, "idle valve freq=%d on %s", boardConfiguration->idleSolenoidFrequency, hwPortname(boardConfiguration->idleValvePin)); } @@ -95,8 +96,10 @@ static msg_t ivThread(int param) { chThdSleepMilliseconds(boardConfiguration->idleThreadPeriod); // this value is not used yet - idleSwitchState = palReadPad(getHwPort(boardConfiguration->idleSwitchPin), - getHwPin(boardConfiguration->idleSwitchPin)); + if (boardConfiguration->idleSwitchPin != GPIO_UNASSIGNED) { + idleSwitchState = palReadPad(getHwPort(boardConfiguration->idleSwitchPin), + getHwPin(boardConfiguration->idleSwitchPin)); + } if (engineConfiguration->idleMode != IM_AUTO) continue; @@ -146,7 +149,8 @@ void startIdleThread(Engine *engine) { // this is idle switch INPUT - sometimes there is a switch on the throttle pedal // this switch is not used yet - mySetPadMode2("idle switch", boardConfiguration->idleSwitchPin, PAL_MODE_INPUT); + if (boardConfiguration->idleSwitchPin != GPIO_UNASSIGNED) + mySetPadMode2("idle switch", boardConfiguration->idleSwitchPin, PAL_MODE_INPUT); addConsoleAction("idleinfo", showIdleInfo); addConsoleActionI("set_idle_rpm", setIdleRpmAction); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 96cf848491..4eba6c7df4 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -672,6 +672,8 @@ static void setSpiMode(int index, bool mode) { static void enableOrDisable(const char *param, bool isEnabled) { if (strEqualCaseInsensitive(param, "fastadc")) { boardConfiguration->isFastAdcEnabled = isEnabled; + } else if (strEqualCaseInsensitive(param, "joystick")) { + engineConfiguration->isJoystickEnabled = isEnabled; } else if (strEqualCaseInsensitive(param, "can")) { engineConfiguration->isCanEnabled = isEnabled; } else if (strEqualCaseInsensitive(param, "can_read")) { diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index a38a401c67..ef0f258157 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -31,6 +31,7 @@ #include "lcd_HD44780.h" #include "settings.h" #include "algo.h" +#include "joystick.h" #if EFI_INTERNAL_FLASH #include "flash_main.h" @@ -178,12 +179,6 @@ static void sendI2Cbyte(int addr, int data) { #endif -// this is all very lame code, just playing with EXTI for now. TODO: refactor it competely! -static int joyTotal = 0; -static int joyA = 0; -static int joyB = 0; -static int joyC = 0; - static Logging *sharedLogger; void initHardware(Logging *l, Engine *engine) { @@ -235,7 +230,7 @@ void initHardware(Logging *l, Engine *engine) { * if flash state does not look right. */ if (SHOULD_INGORE_FLASH()) { - engineConfiguration->engineType = FORD_ASPIRE_1996; + engineConfiguration->engineType = DEFAULT_ENGINE_TYPE; resetConfigurationExt(sharedLogger, engineConfiguration->engineType, engine); writeToFlash(); @@ -340,85 +335,7 @@ void initHardware(Logging *l, Engine *engine) { initVehicleSpeed(sharedLogger); + initJoystick(sharedLogger); + printMsg(sharedLogger, "initHardware() OK!"); } - -#if HAL_USE_EXT || defined(__DOXYGEN__) - -// {EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb1}, - -static void extCallback(EXTDriver *extp, expchannel_t channel) { - joyTotal++; - if (channel == 8) { - joyA++; - } else if (channel == 9) { - joyB++; - } else if (channel == 10) { - joyC++; - } -} - -static void joystickInfo(void) { - scheduleMsg(sharedLogger, "total %d a %d b %d c %d", joyTotal, joyA, joyB, - joyC); -} - -/** - * EXTI is a funny thing: you can only use same pin on one port. For example, you can use - * PA0 PB5 PE2 PD7 - * but you cannot use - * PA0 PB0 PE2 PD7 - * because pin '0' would be used on two different ports - */ - -static EXTConfig extcfg = { { -/* CH#00 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#01 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#02 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#03 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#04 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#05 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#06 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#07 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#08 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#09 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#10 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#11 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#12 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#13 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#14 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#15 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#16 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#17 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#18 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#19 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#20 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#21 */{ EXT_CH_MODE_DISABLED, NULL }, -/* CH#22 */{ EXT_CH_MODE_DISABLED, NULL } } }; - -void initExt(void) { - if (!engineConfiguration->isJoystickEnabled) - return; - - extcfg.channels[8].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART - | EXT_MODE_GPIOC; // PC8 - extcfg.channels[8].cb = extCallback; - - extcfg.channels[10].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART - | EXT_MODE_GPIOD; // PD10 - extcfg.channels[10].cb = extCallback; - - extcfg.channels[11].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART - | EXT_MODE_GPIOD; // PD11 - extcfg.channels[11].cb = extCallback; - - mySetPadMode("joy center", GPIOD, 10, PAL_MODE_INPUT_PULLUP); - mySetPadMode("joy B", GPIOC, 8, PAL_MODE_INPUT_PULLUP); - mySetPadMode("joy D", GPIOD, 11, PAL_MODE_INPUT_PULLUP); - - extStart(&EXTD1, &extcfg); - -} - -#endif - diff --git a/firmware/hw_layer/hardware.h b/firmware/hw_layer/hardware.h index 7e2ea23b7d..8ecaaedad1 100644 --- a/firmware/hw_layer/hardware.h +++ b/firmware/hw_layer/hardware.h @@ -38,7 +38,6 @@ extern "C" SPIDriver * getSpiDevice(spi_device_e spiDevice); void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin); -void initExt(void); void turnOnSpi(spi_device_e device); void lockSpi(spi_device_e device); void unlockSpi(void); diff --git a/firmware/hw_layer/hw_layer.mk b/firmware/hw_layer/hw_layer.mk index 8c27f6e2b7..c9dfed56f8 100644 --- a/firmware/hw_layer/hw_layer.mk +++ b/firmware/hw_layer/hw_layer.mk @@ -22,6 +22,7 @@ HW_LAYER_EMS_CPP = $(PROJECT_DIR)/hw_layer/hardware.cpp \ $(PROJECT_DIR)/hw_layer/HIP9011.cpp \ $(PROJECT_DIR)/hw_layer/vehicle_speed.cpp \ $(PROJECT_DIR)/hw_layer/max31855.cpp \ + $(PROJECT_DIR)/hw_layer/joystick.cpp \ $(PROJECT_DIR)/hw_layer/stepper.cpp \ $(PROJECT_DIR)/hw_layer/stm32f4/mpu_util.cpp diff --git a/firmware/hw_layer/joystick.cpp b/firmware/hw_layer/joystick.cpp new file mode 100644 index 0000000000..11935610e0 --- /dev/null +++ b/firmware/hw_layer/joystick.cpp @@ -0,0 +1,102 @@ +/** + * @file joystick.cpp + * + * @date Jan 2, 2015 + * @author Andrey Belomutskiy, (c) 2012-2014 + */ + +#include "engine_configuration.h" +#include "joystick.h" +#include "engine.h" +#include "pin_repository.h" + +#if HAL_USE_EXT || defined(__DOXYGEN__) + +EXTERN_ENGINE; + +static int joyTotal = 0; +static int joyA = 0; +static int joyB = 0; +static int joyC = 0; + +static Logging *sharedLogger; + +// {EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb1}, + +static void extCallback(EXTDriver *extp, expchannel_t channel) { + joyTotal++; + if (channel == 8) { + joyA++; + } else if (channel == 9) { + joyB++; + } else if (channel == 10) { + joyC++; + } +} + +static void joystickInfo(void) { + scheduleMsg(sharedLogger, "total %d a %d b %d c %d", joyTotal, joyA, joyB, + joyC); +} + +/** + * EXTI is a funny thing: you can only use same pin on one port. For example, you can use + * PA0 PB5 PE2 PD7 + * but you cannot use + * PA0 PB0 PE2 PD7 + * because pin '0' would be used on two different ports + */ + +static EXTConfig extcfg = { { +/* CH#00 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#01 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#02 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#03 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#04 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#05 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#06 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#07 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#08 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#09 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#10 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#11 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#12 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#13 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#14 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#15 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#16 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#17 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#18 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#19 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#20 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#21 */{ EXT_CH_MODE_DISABLED, NULL }, +/* CH#22 */{ EXT_CH_MODE_DISABLED, NULL } } }; + +void initJoystick(Logging *shared) { + if (!engineConfiguration->isJoystickEnabled) + return; + sharedLogger = shared; + + extcfg.channels[8].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART + | EXT_MODE_GPIOC; // PC8 + extcfg.channels[8].cb = extCallback; + + extcfg.channels[10].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART + | EXT_MODE_GPIOD; // PD10 + extcfg.channels[10].cb = extCallback; + + extcfg.channels[11].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART + | EXT_MODE_GPIOD; // PD11 + extcfg.channels[11].cb = extCallback; + + mySetPadMode("joy center", GPIOD, 10, PAL_MODE_INPUT_PULLUP); + mySetPadMode("joy B", GPIOC, 8, PAL_MODE_INPUT_PULLUP); + mySetPadMode("joy D", GPIOD, 11, PAL_MODE_INPUT_PULLUP); + + addConsoleAction("joystickinfo", joystickInfo); + + extStart(&EXTD1, &extcfg); + +} + +#endif diff --git a/firmware/hw_layer/joystick.h b/firmware/hw_layer/joystick.h new file mode 100644 index 0000000000..b002e983b8 --- /dev/null +++ b/firmware/hw_layer/joystick.h @@ -0,0 +1,14 @@ +/** + * @file joystick.h + * + * @date Jan 2, 2015 + * @author Andrey Belomutskiy, (c) 2012-2014 + */ +#ifndef CONTROLLERS_JOYSTICK_H_ +#define CONTROLLERS_JOYSTICK_H_ + +#include "main.h" + +void initJoystick(Logging *shared); + +#endif /* CONTROLLERS_JOYSTICK_H_ */ diff --git a/firmware/hw_layer/neo6m.c b/firmware/hw_layer/neo6m.c index c55beb9cad..63bb50095a 100644 --- a/firmware/hw_layer/neo6m.c +++ b/firmware/hw_layer/neo6m.c @@ -27,6 +27,7 @@ #include "engine_configuration.h" extern board_configuration_s *boardConfiguration; +extern engine_configuration_s *engineConfiguration; static Logging logging; @@ -46,8 +47,6 @@ float getCurrentSpeed(void) { } static void printGpsInfo(void) { - // todo: scheduleMsg() - scheduleMsg(&logging, "GPS RX %s", hwPortname(boardConfiguration->gps_rx_pin)); scheduleMsg(&logging, "GPS TX %s", hwPortname(boardConfiguration->gps_tx_pin)); @@ -84,7 +83,7 @@ static msg_t GpsThreadEntryPoint(void *arg) { int count = 0; - while (TRUE) { + while (true) { msg_t charbuf = chSequentialStreamGet(GPS_SERIAL_DEVICE); if (charbuf == 10 || count == GPS_MAX_STRING) { // if 0xD,0xA or limit if (count >= 1) @@ -106,9 +105,8 @@ static msg_t GpsThreadEntryPoint(void *arg) { } void initGps(void) { - if (boardConfiguration->gps_rx_pin == GPIO_UNASSIGNED || boardConfiguration->gps_tx_pin == GPIO_UNASSIGNED) { + if(!engineConfiguration->isGpsEnabled) return; - } initLogging(&logging, "uart gps");