refactoring: time to unify digital pin API
This commit is contained in:
parent
f082ac48b1
commit
3c57c3d216
|
@ -14,7 +14,7 @@
|
|||
#include "engine_controller.h"
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#include "digital_input_hw.h"
|
||||
#include "digital_input_icu.h"
|
||||
#include "digital_input_exti.h"
|
||||
#include "pin_repository.h"
|
||||
#endif
|
||||
|
@ -270,7 +270,7 @@ void initMapDecoder(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
#if HAL_USE_ICU
|
||||
digital_input_s* digitalMapInput = startDigitalCapture("MAP freq", CONFIGB(frequencyReportingMapInputPin), true);
|
||||
|
||||
digitalMapInput->widthListeners.registerCallback((VoidInt) digitalMapWidthCallback, NULL);
|
||||
digitalMapInput->setWidthCallback((VoidInt) digitalMapWidthCallback, NULL);
|
||||
#else
|
||||
#if EFI_PROD_CODE
|
||||
efiExtiEnablePin(
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* this is rusEfi build-in logic analyzer
|
||||
*
|
||||
* @date Jan 7, 2013
|
||||
* @author Andrey Belomutskiy, (c) 2012-2018
|
||||
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
|
@ -35,7 +35,7 @@ EXTERN_ENGINE;
|
|||
|
||||
#if EFI_ENGINE_SNIFFER
|
||||
extern WaveChart waveChart;
|
||||
#endif
|
||||
#endif /* EFI_ENGINE_SNIFFER */
|
||||
extern bool hasFirmwareErrorFlag;
|
||||
|
||||
/**
|
||||
|
@ -54,8 +54,6 @@ static void ensureInitialized(WaveReader *reader) {
|
|||
efiAssertVoid(CUSTOM_ERR_6654, reader->hw != NULL && reader->hw->started, "wave analyzer NOT INITIALIZED");
|
||||
}
|
||||
|
||||
#if EFI_WAVE_ANALYZER
|
||||
|
||||
static void waAnaWidthCallback(WaveReader *reader) {
|
||||
efitick_t nowUs = getTimeNowUs();
|
||||
reader->riseEventCounter++;
|
||||
|
@ -92,12 +90,9 @@ void WaveReader::onFallEvent() {
|
|||
totalOnTimeAccumulatorUs = 0;
|
||||
|
||||
waveOffsetUs = nowUs - previousEngineCycleTimeUs;
|
||||
|
||||
}
|
||||
|
||||
periodEventTimeUs = nowUs;
|
||||
|
||||
// uint32_t period = engineCycleDurationUs; // local copy of volatile variable
|
||||
}
|
||||
|
||||
static void waIcuPeriodCallback(WaveReader *reader) {
|
||||
|
@ -120,14 +115,13 @@ static void initWave(const char *name, int index) {
|
|||
reader->hw = startDigitalCapture("wave input", brainPin, mode);
|
||||
|
||||
if (reader->hw != NULL) {
|
||||
reader->hw->widthListeners.registerCallback((VoidInt)(void*) waAnaWidthCallback, (void*) reader);
|
||||
reader->hw->setWidthCallback((VoidInt)(void*) waAnaWidthCallback, (void*) reader);
|
||||
|
||||
reader->hw->periodListeners.registerCallback((VoidInt)(void*) waIcuPeriodCallback, (void*) reader);
|
||||
reader->hw->setPeridoCallback((VoidInt)(void*) waIcuPeriodCallback, (void*) reader);
|
||||
}
|
||||
|
||||
print("wave%d input on %s\r\n", index, hwPortname(brainPin));
|
||||
}
|
||||
#endif
|
||||
|
||||
WaveReader::WaveReader() {
|
||||
hw = nullptr;
|
||||
|
@ -143,14 +137,6 @@ static void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index
|
|||
previousEngineCycleTimeUs = nowUs;
|
||||
}
|
||||
|
||||
/*
|
||||
static uint32_t getWaveLowWidth(int index) {
|
||||
WaveReader *reader = &readers[index];
|
||||
ensureInitialized(reader);
|
||||
return reader->last_wave_low_widthUs;
|
||||
}
|
||||
*/
|
||||
|
||||
static float getSignalOnTime(int index) {
|
||||
WaveReader *reader = &readers[index];
|
||||
ensureInitialized(reader);
|
||||
|
@ -172,12 +158,6 @@ static float getSignalPeriodMs(int index) {
|
|||
return reader->signalPeriodUs / 1000.0f;
|
||||
}
|
||||
|
||||
//static efitime_t getWidthEventTime(int index) {
|
||||
// WaveReader *reader = &readers[index];
|
||||
// ensureInitialized(reader);
|
||||
// return reader->widthEventTimeUs;
|
||||
//}
|
||||
|
||||
static void reportWave(Logging *logging, int index) {
|
||||
if (readers[index].hw == NULL) {
|
||||
return;
|
||||
|
@ -239,17 +219,16 @@ void initWaveAnalyzer(Logging *sharedLogger) {
|
|||
if (hasFirmwareError()) {
|
||||
return;
|
||||
}
|
||||
#if EFI_WAVE_ANALYZER
|
||||
|
||||
initWave(PROTOCOL_WA_CHANNEL_1, 0);
|
||||
initWave(PROTOCOL_WA_CHANNEL_2, 1);
|
||||
initWave(PROTOCOL_WA_CHANNEL_3, 2);
|
||||
initWave(PROTOCOL_WA_CHANNEL_4, 3);
|
||||
|
||||
addTriggerEventListener(waTriggerEventListener, "wave analyzer", engine);
|
||||
|
||||
addConsoleAction("waveinfo", showWaveInfo);
|
||||
|
||||
#else
|
||||
print("wave disabled\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* EFI_WAVE_ANALYZER */
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#if EFI_WAVE_ANALYZER
|
||||
|
||||
#include "digital_input_hw.h"
|
||||
#include "digital_input_icu.h"
|
||||
#include "engine_sniffer.h"
|
||||
|
||||
class WaveReader {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* @file digital_input.cpp
|
||||
*
|
||||
* @date Nov 11, 2019
|
||||
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||
*/
|
||||
|
||||
#include "digital_input.h"
|
||||
|
||||
void digital_input_s::setWidthCallback(VoidInt handler, void *arg) {
|
||||
widthListeners.registerCallback(handler, arg);
|
||||
}
|
||||
|
||||
void digital_input_s::setPeridoCallback(VoidInt handler, void *arg) {
|
||||
periodListeners.registerCallback(handler, arg);
|
||||
}
|
|
@ -20,4 +20,8 @@ typedef struct {
|
|||
brain_pin_e brainPin = GPIO_UNASSIGNED;
|
||||
IntListenerArray<1> widthListeners;
|
||||
IntListenerArray<1> periodListeners;
|
||||
|
||||
// Width/Period names are historically inherited from ICU implementation, todo: migrate to better names, high/low? rise/hall?
|
||||
void setWidthCallback(VoidInt handler, void *arg);
|
||||
void setPeridoCallback(VoidInt handler, void *arg);
|
||||
} digital_input_s;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* @file digital_input_hw.cpp
|
||||
* @file digital_input_icu.cpp
|
||||
* @brief Helper methods related to Input Capture Unit (ICU)
|
||||
*
|
||||
* There are some ChibiOS limitation or STM32 limitations or limitations of my brain
|
||||
|
@ -24,7 +24,8 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2018
|
||||
*/
|
||||
|
||||
#include "digital_input_hw.h"
|
||||
#include "digital_input_icu.h"
|
||||
|
||||
#include "fl_stack.h"
|
||||
|
||||
#if EFI_ICU_INPUTS
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file digital_input_hw.h
|
||||
* @file digital_input_icu.h
|
||||
*
|
||||
* @date Jun 23, 2013
|
||||
* @author Andrey Belomutskiy, (c) 2012-2019
|
|
@ -13,7 +13,8 @@ HW_LAYER_EMS = $(HW_LAYER_EGT) \
|
|||
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
|
||||
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/microsecond_timer.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input_hw.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input_icu.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input_exti.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/hardware.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/smart_gpio.cpp \
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* TODO: separate EXTI layer from joystick logic
|
||||
* You cannot use two pins with same index for EXTI (for instance PA5 and PE5) since these would
|
||||
* be using same EXTI line. See https://stm32f4-discovery.net/2014/08/stm32f4-external-interrupts-tutorial/
|
||||
* See also comments in digital_input_hw.cpp
|
||||
* See also comments in digital_input_icu.cpp
|
||||
*
|
||||
* @date Jan 2, 2015
|
||||
* @author Andrey Belomutskiy, (c) 2012-2018
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "hal_comp.h"
|
||||
|
||||
#include "trigger_input.h"
|
||||
#include "digital_input_hw.h"
|
||||
#include "digital_input_icu.h"
|
||||
|
||||
|
||||
extern bool hasFirmwareErrorFlag;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* todo: VVT implementation is a nasty copy-paste :(
|
||||
*
|
||||
* see digital_input_hw.cp
|
||||
* see digital_input_icu.cp
|
||||
*
|
||||
* @date Dec 30, 2012
|
||||
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
* @file trigger_input_icu.cpp
|
||||
* @brief Position sensor hardware layer - ICU version
|
||||
*
|
||||
* todo: code reuse with digital_input_hw.cpp was never finished
|
||||
* todo: code reuse with digital_input_icu.cpp was never finished
|
||||
* todo: at the moment due to half-done code reuse we already depend on EFI_ICU_INPUTS but still have custom code
|
||||
* todo: VVT implementation is a nasty copy-paste :(
|
||||
*
|
||||
* see digital_input_hw.cp
|
||||
* see digital_input_icu.cpp
|
||||
*
|
||||
* @date Dec 30, 2012
|
||||
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||
|
@ -20,7 +20,7 @@ volatile int icuWidthPeriodCounter = 0;
|
|||
#if EFI_SHAFT_POSITION_INPUT && (HAL_USE_ICU == TRUE) && (HAL_USE_COMP == FALSE)
|
||||
|
||||
#include "trigger_input.h"
|
||||
#include "digital_input_hw.h"
|
||||
#include "digital_input_icu.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#if EFI_VEHICLE_SPEED
|
||||
|
||||
#include "engine.h"
|
||||
#include "digital_input_hw.h"
|
||||
#include "digital_input_icu.h"
|
||||
#include "pin_repository.h"
|
||||
|
||||
EXTERN_ENGINE
|
||||
|
|
Loading…
Reference in New Issue