From 693a224c321558fee3e467587f401d34eac8da80 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Thu, 25 Sep 2014 22:06:56 -0500 Subject: [PATCH] auto-sync --- firmware/controllers/algo/enum_strings.cpp | 13 ++++ firmware/controllers/algo/enum_strings.h | 1 + firmware/controllers/settings.cpp | 2 +- firmware/hw_layer/hardware.cpp | 78 ++++++++++++++-------- firmware/hw_layer/hardware.h | 1 + 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/firmware/controllers/algo/enum_strings.cpp b/firmware/controllers/algo/enum_strings.cpp index a7d36b92eb..9a5450e764 100644 --- a/firmware/controllers/algo/enum_strings.cpp +++ b/firmware/controllers/algo/enum_strings.cpp @@ -68,6 +68,19 @@ const char* getConfigurationName(engine_type_e engineType) { } } +const char * ignitionModeToString(ignition_mode_e mode) { + switch (mode) { + case IM_ONE_COIL: + return "single"; + case IM_INDIVIDUAL_COILS: + return "individual"; + case IM_WASTED_SPARK: + return "wasted"; + default: + return "unexpected"; + } +} + const char * pinModeToString(pin_output_mode_e mode) { switch (mode) { case OM_DEFAULT: diff --git a/firmware/controllers/algo/enum_strings.h b/firmware/controllers/algo/enum_strings.h index 237f2e527e..53f01c2df1 100644 --- a/firmware/controllers/algo/enum_strings.h +++ b/firmware/controllers/algo/enum_strings.h @@ -12,6 +12,7 @@ const char* getConfigurationName(engine_type_e engineType); const char * pinModeToString(pin_output_mode_e mode); +const char * ignitionModeToString(ignition_mode_e mode); const char * algorithmToString(engine_load_mode_e mode); #endif /* ENUM_STRINGS_H_ */ diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 14dcb49805..11b76d85d3 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -99,7 +99,7 @@ void printConfiguration(engine_configuration_s *engineConfiguration, engine_conf scheduleMsg(&logger, "tpsMin: %d/tpsMax: %d", engineConfiguration->tpsMin, engineConfiguration->tpsMax); - scheduleMsg(&logger, "ignitionMode: %d/enabled=%s", engineConfiguration->ignitionMode, + scheduleMsg(&logger, "ignitionMode: %s/enabled=%s", ignitionModeToString(engineConfiguration->ignitionMode), boolToString(engineConfiguration->isIgnitionEnabled)); scheduleMsg(&logger, "timingMode: %d", engineConfiguration->timingMode); scheduleMsg(&logger, "fixedModeTiming: %d", (int) engineConfiguration->fixedModeTiming); diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index cac95704e9..91db2d8645 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -133,6 +133,12 @@ static void sendI2Cbyte(int addr, int data) { // i2cReleaseBus(&I2CD1); } +// 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; + void initHardware(Logging *logger, Engine *engine) { engine_configuration_s *engineConfiguration = engine->engineConfiguration; efiAssertVoid(engineConfiguration!=NULL, "engineConfiguration"); @@ -304,36 +310,52 @@ void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) { // {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++; + } } +/** + * 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 const EXTConfig extcfg = { - { - {EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extCallback}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL} - } -}; +static EXTConfig extcfg = { { { EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { + EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { + EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { + EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { + EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { + EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { + EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { + EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL }, { EXT_CH_MODE_DISABLED, NULL } } }; + +void initExt(void) { + +// if (1 == 1) { +// return; +// } + + extcfg.channels[8].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOD; // PD8 + extcfg.channels[8].cb = extCallback; + extcfg.channels[9].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOD; // PD9 + extcfg.channels[9].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 A", GPIOD, 8, PAL_MODE_INPUT_PULLUP); + mySetPadMode("joy A", GPIOD, 9, PAL_MODE_INPUT_PULLUP); + mySetPadMode("joy A", GPIOD, 10, PAL_MODE_INPUT_PULLUP); + mySetPadMode("joy A", GPIOD, 11, PAL_MODE_INPUT_PULLUP); +} + diff --git a/firmware/hw_layer/hardware.h b/firmware/hw_layer/hardware.h index 823f6e2919..d19041130f 100644 --- a/firmware/hw_layer/hardware.h +++ b/firmware/hw_layer/hardware.h @@ -36,6 +36,7 @@ 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);