refactoring - reducing GPIO complexity
This commit is contained in:
parent
2da6e4f4a4
commit
85778e6bf2
|
@ -51,53 +51,6 @@ void initSignalExecutor(void) {
|
|||
initSignalExecutorImpl();
|
||||
}
|
||||
|
||||
void turnPinHigh(NamedOutputPin *output) {
|
||||
efiAssertVoid(output!=NULL, "NULL @ turnPinHigh");
|
||||
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
|
||||
// signal->hi_time = hTimeNow();
|
||||
#endif /* EFI_DEFAILED_LOGGING */
|
||||
|
||||
// turn the output level ACTIVE
|
||||
output->setValue(true);
|
||||
|
||||
// sleep for the needed duration
|
||||
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
|
||||
// explicit check here is a performance optimization to speed up no-chart mode
|
||||
if (ENGINE(isEngineChartEnabled)) {
|
||||
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
|
||||
const char *pinName = output->name;
|
||||
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
|
||||
|
||||
addEngineSniffferEvent(pinName, WC_UP);
|
||||
}
|
||||
#endif /* EFI_ENGINE_SNIFFER */
|
||||
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
|
||||
}
|
||||
|
||||
void turnPinLow(NamedOutputPin *output) {
|
||||
efiAssertVoid(output!=NULL, "NULL turnPinLow");
|
||||
// turn off the output
|
||||
output->setValue(false);
|
||||
|
||||
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
|
||||
systime_t after = hTimeNow();
|
||||
debugInt(&signal->logging, "a_time", after - signal->hi_time);
|
||||
scheduleLogging(&signal->logging);
|
||||
#endif /* EFI_DEFAILED_LOGGING */
|
||||
|
||||
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
|
||||
if (ENGINE(isEngineChartEnabled)) {
|
||||
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
|
||||
const char *pinName = output->name;
|
||||
|
||||
addEngineSniffferEvent(pinName, WC_DOWN);
|
||||
}
|
||||
#endif /* EFI_ENGINE_SNIFFER */
|
||||
}
|
||||
|
||||
#if FUEL_MATH_EXTREME_LOGGING
|
||||
extern LoggingWithStorage sharedLogger;
|
||||
#endif /* FUEL_MATH_EXTREME_LOGGING */
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ static void startAveraging(void *arg) {
|
|||
if (!wasLocked)
|
||||
chSysUnlockFromISR()
|
||||
;
|
||||
turnPinHigh(&mapAveragingPin);
|
||||
mapAveragingPin.setHigh();
|
||||
}
|
||||
|
||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||
|
@ -167,7 +167,7 @@ static void endAveraging(void *arg) {
|
|||
if (!wasLocked)
|
||||
chSysUnlockFromISR()
|
||||
;
|
||||
turnPinLow(&mapAveragingPin);
|
||||
mapAveragingPin.setLow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
|
||||
#include "engine_sniffer.h"
|
||||
extern WaveChart waveChart;
|
||||
#endif /* EFI_ENGINE_SNIFFER */
|
||||
|
||||
// todo: clean this mess, this should become 'static'/private
|
||||
EnginePins enginePins;
|
||||
extern LoggingWithStorage sharedLogger;
|
||||
|
@ -91,6 +96,48 @@ NamedOutputPin::NamedOutputPin(const char *name) : OutputPin() {
|
|||
this->name = name;
|
||||
}
|
||||
|
||||
void NamedOutputPin::setHigh() {
|
||||
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
|
||||
// signal->hi_time = hTimeNow();
|
||||
#endif /* EFI_DEFAILED_LOGGING */
|
||||
|
||||
// turn the output level ACTIVE
|
||||
setValue(true);
|
||||
|
||||
// sleep for the needed duration
|
||||
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
|
||||
// explicit check here is a performance optimization to speed up no-chart mode
|
||||
if (ENGINE(isEngineChartEnabled)) {
|
||||
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
|
||||
const char *pinName = name;
|
||||
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
|
||||
|
||||
addEngineSniffferEvent(pinName, WC_UP);
|
||||
}
|
||||
#endif /* EFI_ENGINE_SNIFFER */
|
||||
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
|
||||
}
|
||||
|
||||
void NamedOutputPin::setLow() {
|
||||
// turn off the output
|
||||
setValue(false);
|
||||
|
||||
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
|
||||
systime_t after = hTimeNow();
|
||||
debugInt(&signal->logging, "a_time", after - signal->hi_time);
|
||||
scheduleLogging(&signal->logging);
|
||||
#endif /* EFI_DEFAILED_LOGGING */
|
||||
|
||||
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
|
||||
if (ENGINE(isEngineChartEnabled)) {
|
||||
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
|
||||
const char *pinName = name;
|
||||
|
||||
addEngineSniffferEvent(pinName, WC_DOWN);
|
||||
}
|
||||
#endif /* EFI_ENGINE_SNIFFER */
|
||||
}
|
||||
|
||||
InjectorOutputPin::InjectorOutputPin() : NamedOutputPin() {
|
||||
reset();
|
||||
injectorIndex = -1;
|
||||
|
|
|
@ -54,6 +54,8 @@ class NamedOutputPin : public OutputPin {
|
|||
public:
|
||||
NamedOutputPin();
|
||||
NamedOutputPin(const char *name);
|
||||
void setHigh();
|
||||
void setLow();
|
||||
/**
|
||||
* @return true if pin was stopped
|
||||
*/
|
||||
|
@ -141,9 +143,6 @@ public:
|
|||
#define isPinAssigned(output) (true)
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
void turnPinHigh(NamedOutputPin *output);
|
||||
void turnPinLow(NamedOutputPin *output);
|
||||
|
||||
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
||||
|
||||
ioportmask_t getHwPin(brain_pin_e brainPin);
|
||||
|
|
|
@ -18,7 +18,7 @@ EXTERN_ENGINE;
|
|||
static scheduling_s tachTurnSignalOff;
|
||||
|
||||
static void turnTachPinLow(void) {
|
||||
turnPinLow(&enginePins.tachOut);
|
||||
enginePins.tachOut.setLow();
|
||||
}
|
||||
|
||||
static void tachSignalCallback(trigger_event_e ckpSignalType,
|
||||
|
@ -26,7 +26,7 @@ static void tachSignalCallback(trigger_event_e ckpSignalType,
|
|||
if (index != engineConfiguration->tachPulseTriggerIndex) {
|
||||
return;
|
||||
}
|
||||
turnPinHigh(&enginePins.tachOut);
|
||||
enginePins.tachOut.setHigh();
|
||||
scheduleTask(false, "tach off", &tachTurnSignalOff, (int)MS2US(engineConfiguration->tachPulseDuractionMs), (schfunc_t) &turnTachPinLow, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ static void startSimultaniousInjection(InjectionEvent *event) {
|
|||
Engine *engine = event->engine;
|
||||
#endif
|
||||
for (int i = 0; i < engine->engineConfiguration->specs.cylindersCount; i++) {
|
||||
turnPinHigh(&enginePins.injectors[i]);
|
||||
enginePins.injectors[i].setHigh();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ static void endSimultaniousInjection(InjectionEvent *event) {
|
|||
EXPAND_Engine;
|
||||
#endif
|
||||
for (int i = 0; i < engine->engineConfiguration->specs.cylindersCount; i++) {
|
||||
turnPinLow(&enginePins.injectors[i]);
|
||||
enginePins.injectors[i].setLow();
|
||||
}
|
||||
engine->injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ static void tempTurnPinHigh(InjectorOutputPin *output) {
|
|||
// getRevolutionCounter(), getTimeNowUs());
|
||||
#endif /* FUEL_MATH_EXTREME_LOGGING */
|
||||
|
||||
turnPinHigh(output);
|
||||
output->setHigh();
|
||||
}
|
||||
|
||||
// todo: make these macro? kind of a penny optimization if compiler is not smart to inline
|
||||
|
@ -178,7 +178,7 @@ static void tempTurnPinLow(InjectorOutputPin *output) {
|
|||
#endif /* FUEL_MATH_EXTREME_LOGGING */
|
||||
return;
|
||||
}
|
||||
turnPinLow(output);
|
||||
output->setLow();
|
||||
}
|
||||
|
||||
void seTurnPinLow(OutputSignalPair *pair) {
|
||||
|
|
|
@ -53,10 +53,10 @@ static void turnSparkPinLow2(IgnitionEvent *event, IgnitionOutputPin *output) {
|
|||
output->outOfOrder = true;
|
||||
}
|
||||
|
||||
turnPinLow(output);
|
||||
output->setLow();
|
||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||
if (CONFIG(dizzySparkOutputPin) != GPIO_UNASSIGNED) {
|
||||
turnPinLow(&enginePins.dizzyOutput);
|
||||
enginePins.dizzyOutput.setLow();
|
||||
}
|
||||
#endif /* EFI_PROD_CODE */
|
||||
}
|
||||
|
@ -102,10 +102,10 @@ static void turnSparkPinHigh2(IgnitionEvent *event, IgnitionOutputPin *output) {
|
|||
}
|
||||
}
|
||||
|
||||
turnPinHigh(output);
|
||||
output->setHigh();
|
||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||
if (CONFIG(dizzySparkOutputPin) != GPIO_UNASSIGNED) {
|
||||
turnPinHigh(&enginePins.dizzyOutput);
|
||||
enginePins.dizzyOutput.setHigh();
|
||||
}
|
||||
#endif /* EFI_PROD_CODE */
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ static void startIntegration(void) {
|
|||
* until we are done integrating
|
||||
*/
|
||||
state = IS_INTEGRATING;
|
||||
turnPinHigh(&intHold);
|
||||
intHold.setHigh();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ static void endIntegration(void) {
|
|||
* engine cycle
|
||||
*/
|
||||
if (state == IS_INTEGRATING) {
|
||||
turnPinLow(&intHold);
|
||||
intHold.setLow();
|
||||
state = WAITING_FOR_ADC_TO_SKIP;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue