rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
efi_gpio.h
Go to the documentation of this file.
1/**
2 * @file efi_gpio.h
3 * @brief EFI-related GPIO code
4 *
5 *
6 * @date Sep 26, 2014
7 * @author Andrey Belomutskiy, (c) 2012-2020
8 */
9
10#pragma once
11
12#include "global.h"
13#include "io_pins.h"
15#include "injection_gpio.h"
16
17void initPrimaryPins();
19
20#if EFI_GPIO_HARDWARE
21void turnAllPinsOff();
22#else /* EFI_GPIO_HARDWARE */
23#define turnAllPinsOff() {}
24#endif /* EFI_GPIO_HARDWARE */
25
27public:
29 void setHigh() override;
30 void setLow() override;
31 void reset();
32 // 6000 RPM is 100Hz we can fit a few years worth of sparks into 32 bits, right?
33 // 2_000_000_000 / 100 = 20_000_000 seconds = 231 days?
34 // [tag:duration_limit]
36 int8_t coilIndex;
37};
38
39/**
40 * OutputPin with semi-automated init/deinit on configuration change
41 */
42class RegisteredOutputPin : public virtual OutputPin {
43public:
44 RegisteredOutputPin(const char *registrationName, size_t pinOffset, size_t pinModeOffset);
45 RegisteredOutputPin(const char *registrationName, size_t pinOffset);
46 void init();
47 void unregister();
49 const char* getRegistrationName() const {
50 return registrationName;
51 }
52private:
53 const char* const registrationName;
54 const uint16_t m_pinOffset;
55 const bool m_hasPinMode;
56 const uint16_t m_pinModeOffset;
58};
59
61public:
62 RegisteredNamedOutputPin(const char* name, size_t pinOffset, size_t pinModeOffset);
63 RegisteredNamedOutputPin(const char* name, size_t pinOffset);
64};
65
67public:
68 EnginePins();
69 void startPins();
70 void reset();
71 static void debug();
72 bool stopPins();
73 void unregisterPins();
75
77 /**
78 * High Pressure Fuel Pump valve control
79 */
81 // this one cranks engine
83 // this one prevents driver from cranking engine
85
88
89 // see acRelayPin
94#if EFI_HD_ACR
97#endif // EFI_HD_ACR
98 // todo: shall we rename this to narrowBandO2heater or even remove the whole questionable feature?
100 OutputPin luaOutputPins[LUA_PWM_COUNT];
101
102 /**
103 * brain board RED LED by default
104 */
106 OutputPin communicationLedPin; // blue LED on brain board by default
107 OutputPin warningLedPin; // orange LED on brain board by default
108 OutputPin runningLedPin; // green LED on brain board by default
109
115 /**
116 * this one is usually on the gauge cluster, not on the ECU
117 */
119
123
126
127 InjectorOutputPin injectors[MAX_CYLINDER_COUNT];
129 IgnitionOutputPin coils[MAX_CYLINDER_COUNT];
130 IgnitionOutputPin trailingCoils[MAX_CYLINDER_COUNT];
131 NamedOutputPin auxValve[AUX_DIGITAL_VALVE_COUNT];
132 OutputPin tcuSolenoids[TCU_SOLENOID_COUNT];
137
138#ifdef EFI_UNIT_TEST
139 void resetForUnitTest();
140#endif
141
142private:
143 void startInjectionPins();
144 void startIgnitionPins();
145 void startAuxValves();
146
147 void stopInjectionPins();
148 void stopIgnitionPins();
149 void stopAuxValves();
150};
151
152/**
153 * it's a macro to be sure that stack is not used
154 * @return 0 for OM_DEFAULT and OM_OPENDRAIN
155 */
156
157#define getElectricalValue0(mode) ((mode) == OM_INVERTED || (mode) == OM_OPENDRAIN_INVERTED)
158
159/**
160 * it's a macro to be sure that stack is not used
161 * @return 1 for OM_DEFAULT and OM_OPENDRAIN
162 */
163#define getElectricalValue1(mode) ((mode) == OM_DEFAULT || (mode) == OM_OPENDRAIN)
164
165#define getElectricalValue(logicalValue, mode) \
166 (logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode))
167
168#if EFI_GPIO_HARDWARE
169
170ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin);
171ioportid_t getHwPort(const char *msg, brain_pin_e brainPin);
172/* Should return valid pointer in any case, not null, return "unknown" if argument is invalid */
173const char *portname(ioportid_t GPIOx);
174
175#endif /* EFI_GPIO_HARDWARE */
176
177brain_pin_e parseBrainPin(const char *str);
178
180
181#ifndef LED_PIN_MODE
182#define LED_PIN_MODE OM_DEFAULT
183#endif /* LED_PIN_MODE */
RegisteredOutputPin harleyAcr2
Definition efi_gpio.h:96
RegisteredNamedOutputPin harleyAcr
Definition efi_gpio.h:95
OutputPin accelerometerCs
Definition efi_gpio.h:125
OutputPin tcuPcSolenoid
Definition efi_gpio.h:135
static void debug()
Definition efi_gpio.cpp:250
void startPins()
Definition efi_gpio.cpp:258
RegisteredOutputPin speedoOut
Definition efi_gpio.h:122
InjectorOutputPin injectorsStage2[MAX_CYLINDER_COUNT]
Definition efi_gpio.h:128
RegisteredOutputPin mainRelay
Definition efi_gpio.h:76
OutputPin tcuSolenoids[TCU_SOLENOID_COUNT]
Definition efi_gpio.h:132
NamedOutputPin auxValve[AUX_DIGITAL_VALVE_COUNT]
Definition efi_gpio.h:131
void startAuxValves()
Definition efi_gpio.cpp:308
RegisteredOutputPin vvlRelay
Definition efi_gpio.h:93
void startIgnitionPins()
Definition efi_gpio.cpp:321
OutputPin o2heater
Definition efi_gpio.h:99
RegisteredOutputPin fanRelay
Definition efi_gpio.h:86
IgnitionOutputPin trailingCoils[MAX_CYLINDER_COUNT]
Definition efi_gpio.h:130
OutputPin errorLedPin
Definition efi_gpio.h:105
RegisteredOutputPin starterControl
Definition efi_gpio.h:82
RegisteredOutputPin triggerDecoderErrorPin
Definition efi_gpio.h:121
OutputPin debugTriggerSync
Definition efi_gpio.h:110
void startInjectionPins()
Definition efi_gpio.cpp:337
RegisteredOutputPin secondIdleSolenoidPin
Definition efi_gpio.h:113
RegisteredOutputPin nitrousRelay
Definition efi_gpio.h:92
OutputPin luaOutputPins[LUA_PWM_COUNT]
Definition efi_gpio.h:100
OutputPin runningLedPin
Definition efi_gpio.h:108
OutputPin tcu32Solenoid
Definition efi_gpio.h:136
void stopInjectionPins()
Definition efi_gpio.cpp:290
void reset()
Definition efi_gpio.cpp:275
RegisteredOutputPin fanRelay2
Definition efi_gpio.h:87
InjectorOutputPin injectors[MAX_CYLINDER_COUNT]
Definition efi_gpio.h:127
void stopAuxValves()
Definition efi_gpio.cpp:298
RegisteredOutputPin starterRelayDisable
Definition efi_gpio.h:84
OutputPin communicationLedPin
Definition efi_gpio.h:106
OutputPin warningLedPin
Definition efi_gpio.h:107
RegisteredOutputPin boostPin
Definition efi_gpio.h:111
bool stopPins()
Definition efi_gpio.cpp:214
void resetForUnitTest()
Definition efi_gpio.cpp:406
RegisteredOutputPin fuelPumpRelay
Definition efi_gpio.h:91
void unregisterPins()
Definition efi_gpio.cpp:228
RegisteredOutputPin acRelay
Definition efi_gpio.h:90
OutputPin * getOutputPinForBenchMode(bench_mode_e idx)
Definition efi_gpio.cpp:356
RegisteredOutputPin alternatorPin
Definition efi_gpio.h:114
IgnitionOutputPin coils[MAX_CYLINDER_COUNT]
Definition efi_gpio.h:129
OutputPin sdCsPin
Definition efi_gpio.h:124
RegisteredOutputPin checkEnginePin
Definition efi_gpio.h:118
RegisteredOutputPin idleSolenoidPin
Definition efi_gpio.h:112
RegisteredOutputPin tachOut
Definition efi_gpio.h:120
OutputPin tcuTccOnoffSolenoid
Definition efi_gpio.h:133
RegisteredNamedOutputPin hpfpValve
Definition efi_gpio.h:80
void stopIgnitionPins()
Definition efi_gpio.cpp:283
OutputPin tcuTccPwmSolenoid
Definition efi_gpio.h:134
void setHigh() override
Definition efi_gpio.cpp:505
void setLow() override
Definition efi_gpio.cpp:530
const char * name
Definition efi_output.h:132
Single output pin reference and state.
Definition efi_output.h:49
const char *const registrationName
Definition efi_gpio.h:53
const char * getRegistrationName() const
Definition efi_gpio.h:49
const uint16_t m_pinModeOffset
Definition efi_gpio.h:56
RegisteredOutputPin *const next
Definition efi_gpio.h:48
const bool m_hasPinMode
Definition efi_gpio.h:55
bool isPinConfigurationChanged()
Definition efi_gpio.cpp:97
const uint16_t m_pinOffset
Definition efi_gpio.h:54
void initPrimaryPins()
Definition efi_gpio.cpp:842
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
brain_pin_e parseBrainPin(const char *str)
void turnAllPinsOff()
Definition efi_gpio.cpp:854
EnginePins enginePins
Definition efi_gpio.cpp:24
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
const char * portname(ioportid_t GPIOx)
void initMiscOutputPins()
Definition efi_gpio.cpp:690
Main engine configuration data structure.
bench_mode_e
uint32_t ioportmask_t
Digital I/O port sized unsigned type.
Definition hal_pal_lld.h:78
GPIO_TypeDef * ioportid_t
Port Identifier.
this file is about general input/output utility methods, not much EFI-specifics