refactoring: time to unify digital pin API
This commit is contained in:
parent
15a571fb3e
commit
f082ac48b1
|
@ -268,8 +268,7 @@ void initMapDecoder(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
|
||||||
if (engineConfiguration->hasFrequencyReportingMapSensor) {
|
if (engineConfiguration->hasFrequencyReportingMapSensor) {
|
||||||
#if HAL_USE_ICU
|
#if HAL_USE_ICU
|
||||||
digital_input_s* digitalMapInput = addWaveAnalyzerDriver("map freq", CONFIGB(frequencyReportingMapInputPin));
|
digital_input_s* digitalMapInput = startDigitalCapture("MAP freq", CONFIGB(frequencyReportingMapInputPin), true);
|
||||||
startInputDriver("MAP", digitalMapInput, true);
|
|
||||||
|
|
||||||
digitalMapInput->widthListeners.registerCallback((VoidInt) digitalMapWidthCallback, NULL);
|
digitalMapInput->widthListeners.registerCallback((VoidInt) digitalMapWidthCallback, NULL);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -104,18 +104,6 @@ static void waIcuPeriodCallback(WaveReader *reader) {
|
||||||
reader->onFallEvent();
|
reader->onFallEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setWaveModeSilent(int index, int mode) {
|
|
||||||
WaveReader *reader = &readers[index];
|
|
||||||
|
|
||||||
startInputDriver("wave", reader->hw, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
//static int getEventCounter(int index) {
|
|
||||||
// WaveReader *reader = &readers[index];
|
|
||||||
// ensureInitialized(reader);
|
|
||||||
// return reader->eventCounter;
|
|
||||||
//}
|
|
||||||
|
|
||||||
static void initWave(const char *name, int index) {
|
static void initWave(const char *name, int index) {
|
||||||
brain_pin_e brainPin = CONFIGB(logicAnalyzerPins)[index];
|
brain_pin_e brainPin = CONFIGB(logicAnalyzerPins)[index];
|
||||||
|
|
||||||
|
@ -129,7 +117,8 @@ static void initWave(const char *name, int index) {
|
||||||
WaveReader *reader = &readers[index];
|
WaveReader *reader = &readers[index];
|
||||||
reader->name = name;
|
reader->name = name;
|
||||||
|
|
||||||
reader->hw = addWaveAnalyzerDriver("wave input", brainPin);
|
reader->hw = startDigitalCapture("wave input", brainPin, mode);
|
||||||
|
|
||||||
if (reader->hw != NULL) {
|
if (reader->hw != NULL) {
|
||||||
reader->hw->widthListeners.registerCallback((VoidInt)(void*) waAnaWidthCallback, (void*) reader);
|
reader->hw->widthListeners.registerCallback((VoidInt)(void*) waAnaWidthCallback, (void*) reader);
|
||||||
|
|
||||||
|
@ -137,7 +126,6 @@ static void initWave(const char *name, int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
print("wave%d input on %s\r\n", index, hwPortname(brainPin));
|
print("wave%d input on %s\r\n", index, hwPortname(brainPin));
|
||||||
startInputDriver("wave", reader->hw, mode);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -259,7 +247,6 @@ void initWaveAnalyzer(Logging *sharedLogger) {
|
||||||
|
|
||||||
addConsoleAction("waveinfo", showWaveInfo);
|
addConsoleAction("waveinfo", showWaveInfo);
|
||||||
|
|
||||||
addConsoleActionII("set_logic_input_mode", setWaveModeSilent);
|
|
||||||
#else
|
#else
|
||||||
print("wave disabled\r\n");
|
print("wave disabled\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* @file digital_input.h
|
||||||
|
*
|
||||||
|
* @date Nov 11, 2019
|
||||||
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
#include "listener_array.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
#if HAL_USE_ICU
|
||||||
|
ICUDriver *driver;
|
||||||
|
#endif /* HAL_USE_ICU */
|
||||||
|
|
||||||
|
bool isActiveHigh = false;
|
||||||
|
volatile bool started = false;
|
||||||
|
brain_pin_e brainPin = GPIO_UNASSIGNED;
|
||||||
|
IntListenerArray<1> widthListeners;
|
||||||
|
IntListenerArray<1> periodListeners;
|
||||||
|
} digital_input_s;
|
|
@ -2,17 +2,12 @@
|
||||||
* digital_input_exti.h
|
* digital_input_exti.h
|
||||||
*
|
*
|
||||||
* Created on: Dec 18, 2018
|
* Created on: Dec 18, 2018
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2018
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HW_LAYER_DIGITAL_INPUT_EXTI_H_
|
#include "digital_input.h"
|
||||||
#define HW_LAYER_DIGITAL_INPUT_EXTI_H_
|
|
||||||
|
|
||||||
#include "global.h"
|
|
||||||
|
|
||||||
#if HAL_USE_PAL
|
#if HAL_USE_PAL
|
||||||
int efiExtiEnablePin(const char *msg, brain_pin_e pin, uint32_t mode, palcallback_t cb, void *cb_data);
|
int efiExtiEnablePin(const char *msg, brain_pin_e pin, uint32_t mode, palcallback_t cb, void *cb_data);
|
||||||
void efiExtiDisablePin(brain_pin_e brainPin);
|
void efiExtiDisablePin(brain_pin_e brainPin);
|
||||||
#endif /* HAL_USE_PAL */
|
#endif /* HAL_USE_PAL */
|
||||||
|
|
||||||
#endif /* HW_LAYER_DIGITAL_INPUT_EXTI_H_ */
|
|
||||||
|
|
|
@ -288,4 +288,10 @@ void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isA
|
||||||
hw->started = true;
|
hw->started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin, bool isActiveHigh) {
|
||||||
|
digital_input_s* input = addWaveAnalyzerDriver(msg, brainPin);
|
||||||
|
startInputDriver(msg, input, isActiveHigh);
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* EFI_ICU_INPUTS */
|
#endif /* EFI_ICU_INPUTS */
|
||||||
|
|
|
@ -2,32 +2,24 @@
|
||||||
* @file digital_input_hw.h
|
* @file digital_input_hw.h
|
||||||
*
|
*
|
||||||
* @date Jun 23, 2013
|
* @date Jun 23, 2013
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2017
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DIGITAL_INPUT_HW_H_
|
#pragma once
|
||||||
#define DIGITAL_INPUT_HW_H_
|
|
||||||
|
|
||||||
#include "global.h"
|
#include "digital_input.h"
|
||||||
|
|
||||||
#if HAL_USE_ICU
|
#if HAL_USE_ICU
|
||||||
|
|
||||||
#include "listener_array.h"
|
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin, bool isActiveHigh);
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
ICUDriver *driver;
|
|
||||||
bool isActiveHigh; // false for ICU_INPUT_ACTIVE_LOW, true for ICU_INPUT_ACTIVE_HIGH
|
|
||||||
volatile bool started;
|
|
||||||
brain_pin_e brainPin;
|
|
||||||
IntListenerArray<1> widthListeners;
|
|
||||||
IntListenerArray<1> periodListeners;
|
|
||||||
} digital_input_s;
|
|
||||||
|
|
||||||
void turnOnCapturePin(const char *msg, brain_pin_e brainPin);
|
void turnOnCapturePin(const char *msg, brain_pin_e brainPin);
|
||||||
void turnOffCapturePin(brain_pin_e brainPin);
|
void turnOffCapturePin(brain_pin_e brainPin);
|
||||||
|
|
||||||
|
// deprecated API
|
||||||
digital_input_s *addWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin);
|
digital_input_s *addWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin);
|
||||||
void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isActiveHigh);
|
void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isActiveHigh);
|
||||||
|
|
||||||
void removeWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin);
|
void removeWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin);
|
||||||
|
|
||||||
//Nullable
|
//Nullable
|
||||||
|
@ -37,4 +29,3 @@ icuchannel_t getInputCaptureChannel(brain_pin_e hwPin);
|
||||||
|
|
||||||
#endif /* HAL_USE_ICU */
|
#endif /* HAL_USE_ICU */
|
||||||
|
|
||||||
#endif /* DIGITAL_INPUT_HW_H_ */
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
void registerCallback(VoidInt handler, void *arg);
|
void registerCallback(VoidInt handler, void *arg);
|
||||||
void registerCallback(Void listener);
|
void registerCallback(Void listener);
|
||||||
void invokeJustArgCallbacks() const;
|
void invokeJustArgCallbacks() const;
|
||||||
int currentListenersCount;
|
int currentListenersCount = 0;
|
||||||
VoidInt callbacks[MAX_INT_LISTENER_COUNT];
|
VoidInt callbacks[MAX_INT_LISTENER_COUNT];
|
||||||
void * args[MAX_INT_LISTENER_COUNT];
|
void * args[MAX_INT_LISTENER_COUNT];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue