rusEFI
The most advanced open source ECU
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"
14 #include "engine_configuration.h"
15 #include "injection_gpio.h"
16 
17 void initPrimaryPins();
18 void initMiscOutputPins();
19 
20 #if EFI_GPIO_HARDWARE
21 void turnAllPinsOff(void);
22 #else /* EFI_GPIO_HARDWARE */
23 #define turnAllPinsOff() {}
24 #endif /* EFI_GPIO_HARDWARE */
25 
27 public:
29  void setHigh() override;
30  void setLow() override;
31  void reset();
33  int8_t coilIndex;
34 };
35 
36 /**
37  * OutputPin with semi-automated init/deinit on configuration change
38  */
39 class RegisteredOutputPin : public virtual OutputPin {
40 public:
41  RegisteredOutputPin(const char *registrationName, size_t pinOffset, size_t pinModeOffset);
42  RegisteredOutputPin(const char *registrationName, size_t pinOffset);
43  void init();
44  void unregister();
46  const char* getRegistrationName() const {
47  return registrationName;
48  }
49 private:
50  const char* const registrationName;
51  const uint16_t m_pinOffset;
52  const bool m_hasPinMode;
53  const uint16_t m_pinModeOffset;
55 };
56 
58 public:
59  RegisteredNamedOutputPin(const char* name, size_t pinOffset, size_t pinModeOffset);
60  RegisteredNamedOutputPin(const char* name, size_t pinOffset);
61 };
62 
63 class EnginePins {
64 public:
65  EnginePins();
66  void startPins();
67  void reset();
68  static void debug();
69  bool stopPins();
70  void unregisterPins();
72 
74  /**
75  * High Pressure Fuel Pump valve control
76  */
78  // this one cranks engine
80  // this one prevents driver from cranking engine
82 
85 
86  // see acRelayPin
89 #if EFI_HD_ACR
92 #endif // EFI_HD_ACR
93  // todo: shall we rename this to narrowBandO2heater or even remove the whole questionable feature?
95  OutputPin luaOutputPins[LUA_PWM_COUNT];
96 
97  /**
98  * brain board RED LED by default
99  */
101  OutputPin communicationLedPin; // blue LED on brain board by default
102  OutputPin warningLedPin; // orange LED on brain board by default
103  OutputPin runningLedPin; // green LED on brain board by default
104 
110  /**
111  * this one is usually on the gauge cluster, not on the ECU
112  */
114 
118 
121 
122  InjectorOutputPin injectors[MAX_CYLINDER_COUNT];
123  InjectorOutputPin injectorsStage2[MAX_CYLINDER_COUNT];
124  IgnitionOutputPin coils[MAX_CYLINDER_COUNT];
125  IgnitionOutputPin trailingCoils[MAX_CYLINDER_COUNT];
126  NamedOutputPin auxValve[AUX_DIGITAL_VALVE_COUNT];
127  OutputPin tcuSolenoids[TCU_SOLENOID_COUNT];
132 
133 private:
134  void startInjectionPins();
135  void startIgnitionPins();
136  void startAuxValves();
137 
138  void stopInjectionPins();
139  void stopIgnitionPins();
140  void stopAuxValves();
141 };
142 
143 /**
144  * it's a macro to be sure that stack is not used
145  * @return 0 for OM_DEFAULT and OM_OPENDRAIN
146  */
147 
148 #define getElectricalValue0(mode) ((mode) == OM_INVERTED || (mode) == OM_OPENDRAIN_INVERTED)
149 
150 /**
151  * it's a macro to be sure that stack is not used
152  * @return 1 for OM_DEFAULT and OM_OPENDRAIN
153  */
154 #define getElectricalValue1(mode) ((mode) == OM_DEFAULT || (mode) == OM_OPENDRAIN)
155 
156 #define getElectricalValue(logicalValue, mode) \
157  (logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode))
158 
159 #if EFI_GPIO_HARDWARE
160 
161 ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin);
162 ioportid_t getHwPort(const char *msg, brain_pin_e brainPin);
163 const char *portname(ioportid_t GPIOx);
164 
165 #endif /* EFI_GPIO_HARDWARE */
166 
167 brain_pin_e parseBrainPin(const char *str);
168 
169 extern EnginePins enginePins;
170 
171 #ifndef LED_PIN_MODE
172 #define LED_PIN_MODE OM_DEFAULT
173 #endif /* LED_PIN_MODE */
RegisteredOutputPin harleyAcr2
Definition: efi_gpio.h:91
RegisteredNamedOutputPin harleyAcr
Definition: efi_gpio.h:90
OutputPin accelerometerCs
Definition: efi_gpio.h:120
OutputPin tcuPcSolenoid
Definition: efi_gpio.h:130
static void debug()
Definition: efi_gpio.cpp:249
void startPins()
Definition: efi_gpio.cpp:257
RegisteredOutputPin speedoOut
Definition: efi_gpio.h:117
InjectorOutputPin injectorsStage2[MAX_CYLINDER_COUNT]
Definition: efi_gpio.h:123
RegisteredOutputPin mainRelay
Definition: efi_gpio.h:73
OutputPin tcuSolenoids[TCU_SOLENOID_COUNT]
Definition: efi_gpio.h:127
NamedOutputPin auxValve[AUX_DIGITAL_VALVE_COUNT]
Definition: efi_gpio.h:126
void startAuxValves()
Definition: efi_gpio.cpp:303
void startIgnitionPins()
Definition: efi_gpio.cpp:315
OutputPin o2heater
Definition: efi_gpio.h:94
RegisteredOutputPin fanRelay
Definition: efi_gpio.h:83
IgnitionOutputPin trailingCoils[MAX_CYLINDER_COUNT]
Definition: efi_gpio.h:125
OutputPin errorLedPin
Definition: efi_gpio.h:100
RegisteredOutputPin starterControl
Definition: efi_gpio.h:79
RegisteredOutputPin triggerDecoderErrorPin
Definition: efi_gpio.h:116
OutputPin debugTriggerSync
Definition: efi_gpio.h:105
void startInjectionPins()
Definition: efi_gpio.cpp:331
RegisteredOutputPin secondIdleSolenoidPin
Definition: efi_gpio.h:108
OutputPin luaOutputPins[LUA_PWM_COUNT]
Definition: efi_gpio.h:95
OutputPin runningLedPin
Definition: efi_gpio.h:103
OutputPin tcu32Solenoid
Definition: efi_gpio.h:131
void stopInjectionPins()
Definition: efi_gpio.cpp:286
void reset()
Definition: efi_gpio.cpp:271
RegisteredOutputPin fanRelay2
Definition: efi_gpio.h:84
InjectorOutputPin injectors[MAX_CYLINDER_COUNT]
Definition: efi_gpio.h:122
void stopAuxValves()
Definition: efi_gpio.cpp:293
RegisteredOutputPin starterRelayDisable
Definition: efi_gpio.h:81
OutputPin communicationLedPin
Definition: efi_gpio.h:101
OutputPin warningLedPin
Definition: efi_gpio.h:102
RegisteredOutputPin boostPin
Definition: efi_gpio.h:106
bool stopPins()
Definition: efi_gpio.cpp:215
RegisteredOutputPin fuelPumpRelay
Definition: efi_gpio.h:88
void unregisterPins()
Definition: efi_gpio.cpp:229
RegisteredOutputPin acRelay
Definition: efi_gpio.h:87
OutputPin * getOutputPinForBenchMode(bench_mode_e idx)
Definition: efi_gpio.cpp:350
RegisteredOutputPin alternatorPin
Definition: efi_gpio.h:109
IgnitionOutputPin coils[MAX_CYLINDER_COUNT]
Definition: efi_gpio.h:124
OutputPin sdCsPin
Definition: efi_gpio.h:119
RegisteredOutputPin checkEnginePin
Definition: efi_gpio.h:113
RegisteredOutputPin idleSolenoidPin
Definition: efi_gpio.h:107
RegisteredOutputPin tachOut
Definition: efi_gpio.h:115
OutputPin tcuTccOnoffSolenoid
Definition: efi_gpio.h:128
RegisteredNamedOutputPin hpfpValve
Definition: efi_gpio.h:77
void stopIgnitionPins()
Definition: efi_gpio.cpp:279
OutputPin tcuTccPwmSolenoid
Definition: efi_gpio.h:129
void setHigh() override
Definition: efi_gpio.cpp:482
void setLow() override
Definition: efi_gpio.cpp:507
int signalFallSparkId
Definition: efi_gpio.h:32
int8_t coilIndex
Definition: efi_gpio.h:33
const char * name
Definition: efi_output.h:133
Single output pin reference and state.
Definition: efi_output.h:50
RegisteredNamedOutputPin(const char *name, size_t pinOffset, size_t pinModeOffset)
Definition: efi_gpio.cpp:66
const char *const registrationName
Definition: efi_gpio.h:50
RegisteredOutputPin(const char *registrationName, size_t pinOffset, size_t pinModeOffset)
Definition: efi_gpio.cpp:74
const uint16_t m_pinModeOffset
Definition: efi_gpio.h:53
RegisteredOutputPin *const next
Definition: efi_gpio.h:45
const bool m_hasPinMode
Definition: efi_gpio.h:52
bool isPinConfigurationChanged()
Definition: efi_gpio.cpp:97
const char * getRegistrationName() const
Definition: efi_gpio.h:46
const uint16_t m_pinOffset
Definition: efi_gpio.h:51
Gpio
void initPrimaryPins()
Definition: efi_gpio.cpp:821
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
brain_pin_e parseBrainPin(const char *str)
EnginePins enginePins
Definition: efi_gpio.cpp:24
const char * portname(ioportid_t GPIOx)
void turnAllPinsOff(void)
Definition: efi_gpio.cpp:833
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
void initMiscOutputPins()
Definition: efi_gpio.cpp:669
Main engine configuration data structure.
bench_mode_e
Definition: engine_types.h:490
uint32_t ioportmask_t
Digital I/O port sized unsigned type.
Definition: hal_pal_lld.h:78
GPIO_TypeDef * ioportid_t
Port Identifier.
Definition: hal_pal_lld.h:102
this file is about general input/output utility methods, not much EFI-specifics