rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
trigger_input.cpp
Go to the documentation of this file.
1/*
2 * @file trigger_input.cpp
3 *
4 * @date Nov 11, 2019
5 * @author Andrey Belomutskiy, (c) 2012-2021
6 */
7
8#include "pch.h"
9#include "trigger_input.h"
10
11/* TODO:
12 * - merge comparator trigger
13 */
14
15#if (EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
16
17#if (HAL_TRIGGER_USE_PAL == TRUE) || (HAL_TRIGGER_USE_ADC == TRUE)
18
19#if (HAL_TRIGGER_USE_PAL == TRUE)
20 int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft);
22#else
23 int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
24 UNUSED(msg);
25 UNUSED(index);
26 UNUSED(isTriggerShaft);
27
28 return -2;
29 }
30 #define extiTriggerTurnOffInputPin(brainPin) ((void)0)
31#endif
32
33#if (HAL_TRIGGER_USE_ADC == TRUE)
35 int adcTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft);
37#else
38 #define adcTriggerTurnOnInputPins() ((void)0)
39 int adcTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
40 UNUSED(msg);
41 UNUSED(index);
42 UNUSED(isTriggerShaft);
43
44 return -2;
45 }
46 #define adcTriggerTurnOffInputPin(brainPin) ((void)0)
47#endif
48
54
55static triggerType shaftTriggerType[TRIGGER_INPUT_PIN_COUNT];
56static triggerType camTriggerType[CAM_INPUTS_COUNT];
57
58static int turnOnTriggerInputPin(const char *msg, int index, bool isTriggerShaft) {
59 brain_pin_e brainPin = isTriggerShaft ?
61
62 if (isTriggerShaft) {
64 } else {
66 }
67
68 if (!isBrainPinValid(brainPin)) {
69 return 0;
70 }
71
72 /* ... then ADC */
73#if HAL_TRIGGER_USE_ADC
74 if (adcTriggerTurnOnInputPin(msg, index, isTriggerShaft) >= 0) {
75 if (isTriggerShaft) {
77 } else {
79 }
80 return 0;
81 }
82#endif
83
84 /* ... then EXTI */
85 if (extiTriggerTurnOnInputPin(msg, index, isTriggerShaft) >= 0) {
86 if (isTriggerShaft) {
88 } else {
90 }
91 return 0;
92 }
93
94 firmwareError(ObdCode::CUSTOM_ERR_NOT_INPUT_PIN, "%s: Not input pin %s", msg, hwPortname(brainPin));
95
96 return -1;
97}
98
99static void turnOffTriggerInputPin(int index, bool isTriggerShaft) {
100 brain_pin_e brainPin = isTriggerShaft ?
102
103 if (isTriggerShaft) {
104 if (shaftTriggerType[index] == TRIGGER_ADC) {
106 }
107
108 if (shaftTriggerType[index] == TRIGGER_EXTI) {
110 }
111
113 } else {
114 if (camTriggerType[index] == TRIGGER_ADC) {
116 }
117
118 if (camTriggerType[index] == TRIGGER_EXTI) {
120 }
121
123 }
124}
125
126/*==========================================================================*/
127/* Exported functions. */
128/*==========================================================================*/
129
131 for (int i = 0; i < TRIGGER_INPUT_PIN_COUNT; i++) {
132 if (isConfigurationChanged(triggerInputPins[i])) {
133 turnOffTriggerInputPin(i, /*isTriggerShaft*/true);
134 }
135 }
136 for (int i = 0; i < CAM_INPUTS_COUNT; i++) {
137 if (isConfigurationChanged(camInputs[i])) {
138 turnOffTriggerInputPin(i, /*isTriggerShaft*/false);
139 }
140 }
141}
142
143static const char* const camNames[] = { "cam1", "cam2", "cam3", "cam4"};
144
146 for (int i = 0; i < TRIGGER_INPUT_PIN_COUNT; i++) {
147 if (isConfigurationChanged(triggerInputPins[i])) {
148 const char * msg = (i == 0 ? "Trigger #1" : "Trigger #2");
149 turnOnTriggerInputPin(msg, i, /*isTriggerShaft*/true);
150 }
151 }
152
153 for (int i = 0; i < CAM_INPUTS_COUNT; i++) {
154 if (isConfigurationChanged(camInputs[i])) {
155 turnOnTriggerInputPin(camNames[i], i, /*isTriggerShaft*/false);
156 }
157 }
158}
159
162
163#endif /* (HAL_TRIGGER_USE_PAL == TRUE) || (HAL_TRIGGER_USE_ADC == TRUE) */
164
165#endif /* EFI_SHAFT_POSITION_INPUT */
166
168 if (hasFirmwareError()) {
169 return;
170 }
171
172#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
174 // todo: we have another 'rpmCalculator.Register' for UNIT_TEST would be great to unify
176 } else {
177 // if we do not have primary input channel maybe it's BCM mode and we inject RPM value via Lua?
179 }
180#endif /* EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT */
181}
RpmCalculator rpmCalculator
Definition engine.h:306
bool Register()
Definition sensor.cpp:131
void unregister()
Definition sensor.cpp:135
static EngineAccessor engine
Definition engine.h:413
engine_configuration_s & activeConfiguration
static constexpr engine_configuration_s * engineConfiguration
void firmwareError(ObdCode code, const char *fmt,...)
UNUSED(samplingTimeSeconds)
@ CUSTOM_ERR_NOT_INPUT_PIN
const char * hwPortname(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
static void turnOffTriggerInputPin(int index, bool isTriggerShaft)
int adcTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft)
void stopTriggerInputPins()
void adcTriggerTurnOffInputPin(brain_pin_e brainPin)
static const char *const camNames[]
void onEcuStartTriggerImplementation()
void extiTriggerTurnOffInputPin(brain_pin_e brainPin)
void onEcuStartDoSomethingTriggerInputPins()
triggerType
@ TRIGGER_EXTI
@ TRIGGER_ADC
@ TRIGGER_NONE
static triggerType shaftTriggerType[TRIGGER_INPUT_PIN_COUNT]
static int turnOnTriggerInputPin(const char *msg, int index, bool isTriggerShaft)
static triggerType camTriggerType[CAM_INPUTS_COUNT]
void startTriggerInputPins()
void adcTriggerTurnOnInputPins()
int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft)
Position sensor hardware layer.